jrior001 | aad0311 | 2014-07-05 10:31:21 -0400 | [diff] [blame] | 1 | /*update |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 2 | Copyright 2013 bigbiff/Dees_Troy TeamWin |
| 3 | This file is part of TWRP/TeamWin Recovery Project. |
| 4 | |
| 5 | TWRP is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| 9 | |
| 10 | TWRP is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with TWRP. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 18 | |
| 19 | #include <stdarg.h> |
| 20 | #include <stdio.h> |
| 21 | #include <stdlib.h> |
| 22 | #include <string.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <sys/stat.h> |
| 25 | #include <sys/time.h> |
| 26 | #include <sys/mman.h> |
| 27 | #include <sys/types.h> |
| 28 | #include <sys/ioctl.h> |
| 29 | #include <linux/input.h> |
| 30 | #include <time.h> |
| 31 | #include <unistd.h> |
| 32 | #include <stdlib.h> |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 33 | #include <sys/wait.h> |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 34 | #include <dirent.h> |
Vojtech Bocek | 03fd6c5 | 2014-03-13 18:46:34 +0100 | [diff] [blame] | 35 | #include <pwd.h> |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 36 | |
| 37 | #include <string> |
| 38 | #include <sstream> |
| 39 | #include "../partitions.hpp" |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 40 | #include "../twrp-functions.hpp" |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 41 | #include "../openrecoveryscript.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 42 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 43 | #include "../adb_install.h" |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 44 | #include "../fuse_sideload.h" |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 45 | #include "blanktimer.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 46 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 47 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 48 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 49 | #include "../variables.h" |
Dees_Troy | 32c8eb8 | 2012-09-11 15:28:06 -0400 | [diff] [blame] | 50 | #include "../twinstall.h" |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 51 | #include "cutils/properties.h" |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 52 | #include "../minadbd/adb.h" |
Ethan Yonker | 2481342 | 2014-11-07 17:19:07 -0600 | [diff] [blame] | 53 | #include "../adb_install.h" |
Ethan Yonker | 4b94cfd | 2014-12-11 10:00:45 -0600 | [diff] [blame] | 54 | #include "../set_metadata.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | #include "rapidxml.hpp" |
| 58 | #include "objects.hpp" |
| 59 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 60 | void curtainClose(void); |
| 61 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 62 | GUIAction::mapFunc GUIAction::mf; |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 63 | std::set<string> GUIAction::setActionsRunningInCallerThread; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 64 | static string zip_queue[10]; |
| 65 | static int zip_queue_index; |
| 66 | static pthread_t terminal_command; |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 67 | pid_t sideload_child_pid; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 68 | |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 69 | static ActionThread action_thread; |
| 70 | |
| 71 | static void *ActionThread_work_wrapper(void *data) |
| 72 | { |
| 73 | action_thread.run(data); |
| 74 | return NULL; |
| 75 | } |
| 76 | |
| 77 | ActionThread::ActionThread() |
| 78 | { |
| 79 | m_thread_running = false; |
| 80 | pthread_mutex_init(&m_act_lock, NULL); |
| 81 | } |
| 82 | |
| 83 | ActionThread::~ActionThread() |
| 84 | { |
| 85 | pthread_mutex_lock(&m_act_lock); |
| 86 | if(m_thread_running) { |
| 87 | pthread_mutex_unlock(&m_act_lock); |
| 88 | pthread_join(m_thread, NULL); |
| 89 | } else { |
| 90 | pthread_mutex_unlock(&m_act_lock); |
| 91 | } |
| 92 | pthread_mutex_destroy(&m_act_lock); |
| 93 | } |
| 94 | |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 95 | void ActionThread::threadActions(GUIAction *act) |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 96 | { |
| 97 | pthread_mutex_lock(&m_act_lock); |
| 98 | if (m_thread_running) { |
| 99 | pthread_mutex_unlock(&m_act_lock); |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 100 | LOGERR("Another threaded action is already running -- not running %u actions starting with '%s'\n", |
| 101 | act->mActions.size(), act->mActions[0].mFunction.c_str()); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 102 | } else { |
| 103 | m_thread_running = true; |
| 104 | pthread_mutex_unlock(&m_act_lock); |
| 105 | ThreadData *d = new ThreadData; |
| 106 | d->act = act; |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 107 | |
| 108 | pthread_create(&m_thread, NULL, &ActionThread_work_wrapper, d); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | void ActionThread::run(void *data) |
| 113 | { |
| 114 | ThreadData *d = (ThreadData*)data; |
| 115 | GUIAction* act = d->act; |
| 116 | |
| 117 | std::vector<GUIAction::Action>::iterator it; |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 118 | for (it = act->mActions.begin(); it != act->mActions.end(); ++it) |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 119 | act->doAction(*it); |
| 120 | |
| 121 | pthread_mutex_lock(&m_act_lock); |
| 122 | m_thread_running = false; |
| 123 | pthread_mutex_unlock(&m_act_lock); |
| 124 | delete d; |
| 125 | } |
| 126 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 127 | GUIAction::GUIAction(xml_node<>* node) |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 128 | : GUIObject(node) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 129 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 130 | xml_node<>* child; |
| 131 | xml_node<>* actions; |
| 132 | xml_attribute<>* attr; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 133 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 134 | if (!node) return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 135 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 136 | if (mf.empty()) { |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 137 | // These actions will be run in the caller's thread |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 138 | mf["reboot"] = &GUIAction::reboot; |
| 139 | mf["home"] = &GUIAction::home; |
| 140 | mf["key"] = &GUIAction::key; |
| 141 | mf["page"] = &GUIAction::page; |
| 142 | mf["reload"] = &GUIAction::reload; |
| 143 | mf["readBackup"] = &GUIAction::readBackup; |
| 144 | mf["set"] = &GUIAction::set; |
| 145 | mf["clear"] = &GUIAction::clear; |
| 146 | mf["mount"] = &GUIAction::mount; |
| 147 | mf["unmount"] = &GUIAction::unmount; |
| 148 | mf["umount"] = &GUIAction::unmount; |
| 149 | mf["restoredefaultsettings"] = &GUIAction::restoredefaultsettings; |
| 150 | mf["copylog"] = &GUIAction::copylog; |
| 151 | mf["compute"] = &GUIAction::compute; |
| 152 | mf["addsubtract"] = &GUIAction::compute; |
| 153 | mf["setguitimezone"] = &GUIAction::setguitimezone; |
| 154 | mf["overlay"] = &GUIAction::overlay; |
| 155 | mf["queuezip"] = &GUIAction::queuezip; |
| 156 | mf["cancelzip"] = &GUIAction::cancelzip; |
| 157 | mf["queueclear"] = &GUIAction::queueclear; |
| 158 | mf["sleep"] = &GUIAction::sleep; |
| 159 | mf["appenddatetobackupname"] = &GUIAction::appenddatetobackupname; |
| 160 | mf["generatebackupname"] = &GUIAction::generatebackupname; |
| 161 | mf["checkpartitionlist"] = &GUIAction::checkpartitionlist; |
| 162 | mf["getpartitiondetails"] = &GUIAction::getpartitiondetails; |
| 163 | mf["screenshot"] = &GUIAction::screenshot; |
| 164 | mf["setbrightness"] = &GUIAction::setbrightness; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 165 | mf["fileexists"] = &GUIAction::fileexists; |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 166 | mf["killterminal"] = &GUIAction::killterminal; |
| 167 | mf["checkbackupname"] = &GUIAction::checkbackupname; |
| 168 | mf["adbsideloadcancel"] = &GUIAction::adbsideloadcancel; |
| 169 | mf["fixsu"] = &GUIAction::fixsu; |
| 170 | mf["startmtp"] = &GUIAction::startmtp; |
| 171 | mf["stopmtp"] = &GUIAction::stopmtp; |
| 172 | |
| 173 | // remember actions that run in the caller thread |
| 174 | for (mapFunc::const_iterator it = mf.begin(); it != mf.end(); ++it) |
| 175 | setActionsRunningInCallerThread.insert(it->first); |
| 176 | |
| 177 | // These actions will run in a separate thread |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 178 | mf["flash"] = &GUIAction::flash; |
| 179 | mf["wipe"] = &GUIAction::wipe; |
| 180 | mf["refreshsizes"] = &GUIAction::refreshsizes; |
| 181 | mf["nandroid"] = &GUIAction::nandroid; |
| 182 | mf["fixpermissions"] = &GUIAction::fixpermissions; |
| 183 | mf["dd"] = &GUIAction::dd; |
| 184 | mf["partitionsd"] = &GUIAction::partitionsd; |
| 185 | mf["installhtcdumlock"] = &GUIAction::installhtcdumlock; |
| 186 | mf["htcdumlockrestoreboot"] = &GUIAction::htcdumlockrestoreboot; |
| 187 | mf["htcdumlockreflashrecovery"] = &GUIAction::htcdumlockreflashrecovery; |
| 188 | mf["cmd"] = &GUIAction::cmd; |
| 189 | mf["terminalcommand"] = &GUIAction::terminalcommand; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 190 | mf["reinjecttwrp"] = &GUIAction::reinjecttwrp; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 191 | mf["decrypt"] = &GUIAction::decrypt; |
| 192 | mf["adbsideload"] = &GUIAction::adbsideload; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 193 | mf["openrecoveryscript"] = &GUIAction::openrecoveryscript; |
| 194 | mf["installsu"] = &GUIAction::installsu; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 195 | mf["decrypt_backup"] = &GUIAction::decrypt_backup; |
| 196 | mf["repair"] = &GUIAction::repair; |
| 197 | mf["changefilesystem"] = &GUIAction::changefilesystem; |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 198 | mf["flashimage"] = &GUIAction::flashimage; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 199 | } |
| 200 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 201 | // First, get the action |
| 202 | actions = node->first_node("actions"); |
| 203 | if (actions) child = actions->first_node("action"); |
| 204 | else child = node->first_node("action"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 205 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 206 | if (!child) return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 207 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 208 | while (child) |
| 209 | { |
| 210 | Action action; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 211 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 212 | attr = child->first_attribute("function"); |
| 213 | if (!attr) return; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 214 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 215 | action.mFunction = attr->value(); |
| 216 | action.mArg = child->value(); |
| 217 | mActions.push_back(action); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 218 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 219 | child = child->next_sibling("action"); |
| 220 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 221 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 222 | // Now, let's get either the key or region |
| 223 | child = node->first_node("touch"); |
| 224 | if (child) |
| 225 | { |
| 226 | attr = child->first_attribute("key"); |
| 227 | if (attr) |
| 228 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 229 | std::vector<std::string> keys = TWFunc::Split_String(attr->value(), "+"); |
| 230 | for(size_t i = 0; i < keys.size(); ++i) |
| 231 | { |
| 232 | const int key = getKeyByName(keys[i]); |
| 233 | mKeys[key] = false; |
| 234 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 235 | } |
| 236 | else |
| 237 | { |
| 238 | attr = child->first_attribute("x"); |
| 239 | if (!attr) return; |
| 240 | mActionX = atol(attr->value()); |
| 241 | attr = child->first_attribute("y"); |
| 242 | if (!attr) return; |
| 243 | mActionY = atol(attr->value()); |
| 244 | attr = child->first_attribute("w"); |
| 245 | if (!attr) return; |
| 246 | mActionW = atol(attr->value()); |
| 247 | attr = child->first_attribute("h"); |
| 248 | if (!attr) return; |
| 249 | mActionH = atol(attr->value()); |
| 250 | } |
| 251 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | int GUIAction::NotifyTouch(TOUCH_STATE state, int x, int y) |
| 255 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 256 | if (state == TOUCH_RELEASE) |
| 257 | doActions(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 258 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 259 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 260 | } |
| 261 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 262 | int GUIAction::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 263 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 264 | if (mKeys.empty()) |
| 265 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 266 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 267 | std::map<int, bool>::iterator itr = mKeys.find(key); |
| 268 | if(itr == mKeys.end()) |
| 269 | return 0; |
| 270 | |
| 271 | bool prevState = itr->second; |
| 272 | itr->second = down; |
| 273 | |
| 274 | // If there is only one key for this action, wait for key up so it |
| 275 | // doesn't trigger with multi-key actions. |
| 276 | // Else, check if all buttons are pressed, then consume their release events |
| 277 | // so they don't trigger one-button actions and reset mKeys pressed status |
| 278 | if(mKeys.size() == 1) { |
| 279 | if(!down && prevState) |
| 280 | doActions(); |
| 281 | } else if(down) { |
| 282 | for(itr = mKeys.begin(); itr != mKeys.end(); ++itr) { |
| 283 | if(!itr->second) |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | // Passed, all req buttons are pressed, reset them and consume release events |
| 288 | HardwareKeyboard *kb = PageManager::GetHardwareKeyboard(); |
| 289 | for(itr = mKeys.begin(); itr != mKeys.end(); ++itr) { |
| 290 | kb->ConsumeKeyRelease(itr->first); |
| 291 | itr->second = false; |
| 292 | } |
| 293 | |
| 294 | doActions(); |
| 295 | } |
| 296 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 297 | return 0; |
| 298 | } |
| 299 | |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 300 | int GUIAction::NotifyVarChange(const std::string& varName, const std::string& value) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 301 | { |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 302 | GUIObject::NotifyVarChange(varName, value); |
| 303 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 304 | if (varName.empty() && !isConditionValid() && mKeys.empty() && !mActionW) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 305 | doActions(); |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 306 | else if((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 307 | doActions(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 308 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 309 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void GUIAction::simulate_progress_bar(void) |
| 313 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 314 | gui_print("Simulating actions...\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 315 | for (int i = 0; i < 5; i++) |
| 316 | { |
| 317 | usleep(500000); |
| 318 | DataManager::SetValue("ui_progress", i * 20); |
| 319 | } |
| 320 | } |
| 321 | |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 322 | int GUIAction::flash_zip(std::string filename, int* wipe_cache) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 323 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 324 | int ret_val = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 325 | |
| 326 | DataManager::SetValue("ui_progress", 0); |
| 327 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 328 | if (filename.empty()) |
| 329 | { |
| 330 | LOGERR("No file specified.\n"); |
| 331 | return -1; |
| 332 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 333 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 334 | if (!PartitionManager.Mount_By_Path(filename, true)) |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 335 | return -1; |
| 336 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 337 | if (simulate) { |
| 338 | simulate_progress_bar(); |
| 339 | } else { |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 340 | ret_val = TWinstall_zip(filename.c_str(), wipe_cache); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 341 | |
| 342 | // Now, check if we need to ensure TWRP remains installed... |
| 343 | struct stat st; |
| 344 | if (stat("/sbin/installTwrp", &st) == 0) |
| 345 | { |
| 346 | DataManager::SetValue("tw_operation", "Configuring TWRP"); |
| 347 | DataManager::SetValue("tw_partition", ""); |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 348 | gui_print("Configuring TWRP...\n"); |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 349 | if (TWFunc::Exec_Cmd("/sbin/installTwrp reinstall") < 0) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 350 | { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 351 | gui_print("Unable to configure TWRP with this kernel.\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 356 | // Done |
| 357 | DataManager::SetValue("ui_progress", 100); |
| 358 | DataManager::SetValue("ui_progress", 0); |
| 359 | return ret_val; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 360 | } |
| 361 | |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 362 | bool GUIAction::needsToRunInSeparateThread(const GUIAction::Action& action) |
| 363 | { |
Vojtech Bocek | 85cfb7d | 2015-01-12 18:25:59 +0100 | [diff] [blame] | 364 | return setActionsRunningInCallerThread.find(gui_parse_text(action.mFunction)) == setActionsRunningInCallerThread.end(); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 367 | int GUIAction::doActions() |
| 368 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 369 | if (mActions.size() < 1) |
| 370 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 371 | |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 372 | bool needThread = false; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 373 | std::vector<Action>::iterator it; |
| 374 | for (it = mActions.begin(); it != mActions.end(); ++it) |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 375 | { |
| 376 | if (needsToRunInSeparateThread(*it)) |
| 377 | { |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 378 | needThread = true; |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 379 | break; |
| 380 | } |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 381 | } |
| 382 | if (needThread) |
| 383 | { |
| 384 | action_thread.threadActions(this); |
| 385 | } |
| 386 | else |
| 387 | { |
Vojtech Bocek | e979abd | 2015-01-12 18:29:12 +0100 | [diff] [blame] | 388 | const size_t cnt = mActions.size(); |
| 389 | for (size_t i = 0; i < cnt; ++i) |
| 390 | doAction(mActions[i]); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 391 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 392 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 393 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 394 | } |
| 395 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 396 | int GUIAction::doAction(Action action) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 397 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 398 | DataManager::GetValue(TW_SIMULATE_ACTIONS, simulate); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 399 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 400 | std::string function = gui_parse_text(action.mFunction); |
| 401 | std::string arg = gui_parse_text(action.mArg); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 402 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 403 | // find function and execute it |
| 404 | mapFunc::const_iterator funcitr = mf.find(function); |
| 405 | if (funcitr != mf.end()) |
| 406 | return (this->*funcitr->second)(arg); |
| 407 | |
| 408 | LOGERR("Unknown action '%s'\n", function.c_str()); |
| 409 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | void GUIAction::operation_start(const string operation_name) |
| 413 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 414 | LOGINFO("operation_start: '%s'\n", operation_name.c_str()); |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 415 | time(&Start); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 416 | DataManager::SetValue(TW_ACTION_BUSY, 1); |
| 417 | DataManager::SetValue("ui_progress", 0); |
| 418 | DataManager::SetValue("tw_operation", operation_name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 419 | DataManager::SetValue("tw_operation_state", 0); |
Ethan Yonker | d83c9ea | 2015-01-02 15:22:31 -0600 | [diff] [blame] | 420 | DataManager::SetValue("tw_operation_status", 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 421 | } |
| 422 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 423 | void GUIAction::operation_end(const int operation_status) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 424 | { |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 425 | time_t Stop; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 426 | int simulate_fail; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 427 | DataManager::SetValue("ui_progress", 100); |
| 428 | if (simulate) { |
| 429 | DataManager::GetValue(TW_SIMULATE_FAIL, simulate_fail); |
| 430 | if (simulate_fail != 0) |
| 431 | DataManager::SetValue("tw_operation_status", 1); |
| 432 | else |
| 433 | DataManager::SetValue("tw_operation_status", 0); |
| 434 | } else { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 435 | if (operation_status != 0) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 436 | DataManager::SetValue("tw_operation_status", 1); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 437 | } |
| 438 | else { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 439 | DataManager::SetValue("tw_operation_status", 0); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 440 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 441 | } |
| 442 | DataManager::SetValue("tw_operation_state", 1); |
| 443 | DataManager::SetValue(TW_ACTION_BUSY, 0); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 444 | blankTimer.resetTimerAndUnblank(); |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 445 | time(&Stop); |
| 446 | if ((int) difftime(Stop, Start) > 10) |
Ethan Yonker | 03db326 | 2014-02-05 08:02:06 -0600 | [diff] [blame] | 447 | DataManager::Vibrate("tw_action_vibrate"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 448 | LOGINFO("operation_end - status=%d\n", operation_status); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 449 | } |
| 450 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 451 | int GUIAction::reboot(std::string arg) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 452 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 453 | //curtainClose(); this sometimes causes a crash |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 454 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 455 | sync(); |
| 456 | DataManager::SetValue("tw_gui_done", 1); |
| 457 | DataManager::SetValue("tw_reboot_arg", arg); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 458 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 459 | return 0; |
| 460 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 461 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 462 | int GUIAction::home(std::string arg) |
| 463 | { |
| 464 | PageManager::SelectPackage("TWRP"); |
| 465 | gui_changePage("main"); |
| 466 | return 0; |
| 467 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 468 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 469 | int GUIAction::key(std::string arg) |
| 470 | { |
| 471 | const int key = getKeyByName(arg); |
| 472 | PageManager::NotifyKey(key, true); |
| 473 | PageManager::NotifyKey(key, false); |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | int GUIAction::page(std::string arg) |
| 478 | { |
| 479 | std::string page_name = gui_parse_text(arg); |
| 480 | return gui_changePage(page_name); |
| 481 | } |
| 482 | |
| 483 | int GUIAction::reload(std::string arg) |
| 484 | { |
| 485 | int check = 0, ret_val = 0; |
| 486 | std::string theme_path; |
| 487 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 488 | theme_path = DataManager::GetSettingsStoragePath(); |
| 489 | if (PartitionManager.Mount_By_Path(theme_path.c_str(), 1) < 0) { |
| 490 | LOGERR("Unable to mount %s during reload function startup.\n", theme_path.c_str()); |
| 491 | check = 1; |
| 492 | } |
| 493 | |
| 494 | theme_path += "/TWRP/theme/ui.zip"; |
| 495 | if (check != 0 || PageManager::ReloadPackage("TWRP", theme_path) != 0) |
Dees_Troy | 6ef6635 | 2013-02-21 08:26:57 -0600 | [diff] [blame] | 496 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 497 | // Loading the custom theme failed - try loading the stock theme |
| 498 | LOGINFO("Attempting to reload stock theme...\n"); |
| 499 | if (PageManager::ReloadPackage("TWRP", "/res/ui.xml")) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 500 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 501 | LOGERR("Failed to load base packages.\n"); |
| 502 | ret_val = 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 503 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 504 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 505 | return 0; |
| 506 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 507 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 508 | int GUIAction::readBackup(std::string arg) |
| 509 | { |
| 510 | string Restore_Name; |
| 511 | DataManager::GetValue("tw_restore", Restore_Name); |
| 512 | PartitionManager.Set_Restore_Files(Restore_Name); |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | int GUIAction::set(std::string arg) |
| 517 | { |
| 518 | if (arg.find('=') != string::npos) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 519 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 520 | string varName = arg.substr(0, arg.find('=')); |
| 521 | string value = arg.substr(arg.find('=') + 1, string::npos); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 522 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 523 | DataManager::GetValue(value, value); |
| 524 | DataManager::SetValue(varName, value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 525 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 526 | else |
| 527 | DataManager::SetValue(arg, "1"); |
| 528 | return 0; |
| 529 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 530 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 531 | int GUIAction::clear(std::string arg) |
| 532 | { |
| 533 | DataManager::SetValue(arg, "0"); |
| 534 | return 0; |
| 535 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 536 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 537 | int GUIAction::mount(std::string arg) |
| 538 | { |
| 539 | if (arg == "usb") { |
| 540 | DataManager::SetValue(TW_ACTION_BUSY, 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 541 | if (!simulate) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 542 | PartitionManager.usb_storage_enable(); |
| 543 | else |
| 544 | gui_print("Simulating actions...\n"); |
| 545 | } else if (!simulate) { |
| 546 | PartitionManager.Mount_By_Path(arg, true); |
| 547 | PartitionManager.Add_MTP_Storage(arg); |
| 548 | } else |
| 549 | gui_print("Simulating actions...\n"); |
| 550 | return 0; |
| 551 | } |
| 552 | |
| 553 | int GUIAction::unmount(std::string arg) |
| 554 | { |
| 555 | if (arg == "usb") { |
| 556 | if (!simulate) |
| 557 | PartitionManager.usb_storage_disable(); |
| 558 | else |
| 559 | gui_print("Simulating actions...\n"); |
| 560 | DataManager::SetValue(TW_ACTION_BUSY, 0); |
| 561 | } else if (!simulate) { |
| 562 | PartitionManager.UnMount_By_Path(arg, true); |
| 563 | } else |
| 564 | gui_print("Simulating actions...\n"); |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | int GUIAction::restoredefaultsettings(std::string arg) |
| 569 | { |
| 570 | operation_start("Restore Defaults"); |
| 571 | if (simulate) // Simulated so that people don't accidently wipe out the "simulation is on" setting |
| 572 | gui_print("Simulating actions...\n"); |
| 573 | else { |
| 574 | DataManager::ResetDefaults(); |
| 575 | PartitionManager.Update_System_Details(); |
| 576 | PartitionManager.Mount_Current_Storage(true); |
| 577 | } |
| 578 | operation_end(0); |
| 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | int GUIAction::copylog(std::string arg) |
| 583 | { |
| 584 | operation_start("Copy Log"); |
| 585 | if (!simulate) |
| 586 | { |
| 587 | string dst; |
| 588 | PartitionManager.Mount_Current_Storage(true); |
| 589 | dst = DataManager::GetCurrentStoragePath() + "/recovery.log"; |
| 590 | TWFunc::copy_file("/tmp/recovery.log", dst.c_str(), 0755); |
| 591 | tw_set_default_metadata(dst.c_str()); |
| 592 | sync(); |
| 593 | gui_print("Copied recovery log to %s.\n", DataManager::GetCurrentStoragePath().c_str()); |
| 594 | } else |
| 595 | simulate_progress_bar(); |
| 596 | operation_end(0); |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | int GUIAction::compute(std::string arg) |
| 602 | { |
| 603 | if (arg.find("+") != string::npos) |
| 604 | { |
| 605 | string varName = arg.substr(0, arg.find('+')); |
| 606 | string string_to_add = arg.substr(arg.find('+') + 1, string::npos); |
| 607 | int amount_to_add = atoi(string_to_add.c_str()); |
| 608 | int value; |
| 609 | |
| 610 | DataManager::GetValue(varName, value); |
| 611 | DataManager::SetValue(varName, value + amount_to_add); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 612 | return 0; |
| 613 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 614 | if (arg.find("-") != string::npos) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 615 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 616 | string varName = arg.substr(0, arg.find('-')); |
| 617 | string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos); |
| 618 | int amount_to_subtract = atoi(string_to_subtract.c_str()); |
| 619 | int value; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 620 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 621 | DataManager::GetValue(varName, value); |
| 622 | value -= amount_to_subtract; |
| 623 | if (value <= 0) |
| 624 | value = 0; |
| 625 | DataManager::SetValue(varName, value); |
| 626 | return 0; |
| 627 | } |
| 628 | if (arg.find("*") != string::npos) |
| 629 | { |
| 630 | string varName = arg.substr(0, arg.find('*')); |
| 631 | string multiply_by_str = gui_parse_text(arg.substr(arg.find('*') + 1, string::npos)); |
| 632 | int multiply_by = atoi(multiply_by_str.c_str()); |
| 633 | int value; |
| 634 | |
| 635 | DataManager::GetValue(varName, value); |
| 636 | DataManager::SetValue(varName, value*multiply_by); |
| 637 | return 0; |
| 638 | } |
| 639 | if (arg.find("/") != string::npos) |
| 640 | { |
| 641 | string varName = arg.substr(0, arg.find('/')); |
| 642 | string divide_by_str = gui_parse_text(arg.substr(arg.find('/') + 1, string::npos)); |
| 643 | int divide_by = atoi(divide_by_str.c_str()); |
| 644 | int value; |
| 645 | |
| 646 | if(divide_by != 0) |
| 647 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 648 | DataManager::GetValue(varName, value); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 649 | DataManager::SetValue(varName, value/divide_by); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 650 | } |
| 651 | return 0; |
| 652 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 653 | LOGERR("Unable to perform compute '%s'\n", arg.c_str()); |
| 654 | return -1; |
| 655 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 656 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 657 | int GUIAction::setguitimezone(std::string arg) |
| 658 | { |
| 659 | string SelectedZone; |
| 660 | DataManager::GetValue(TW_TIME_ZONE_GUISEL, SelectedZone); // read the selected time zone into SelectedZone |
| 661 | string Zone = SelectedZone.substr(0, SelectedZone.find(';')); // parse to get time zone |
| 662 | string DSTZone = SelectedZone.substr(SelectedZone.find(';') + 1, string::npos); // parse to get DST component |
| 663 | |
| 664 | int dst; |
| 665 | DataManager::GetValue(TW_TIME_ZONE_GUIDST, dst); // check wether user chose to use DST |
| 666 | |
| 667 | string offset; |
| 668 | DataManager::GetValue(TW_TIME_ZONE_GUIOFFSET, offset); // pull in offset |
| 669 | |
| 670 | string NewTimeZone = Zone; |
| 671 | if (offset != "0") |
| 672 | NewTimeZone += ":" + offset; |
| 673 | |
| 674 | if (dst != 0) |
| 675 | NewTimeZone += DSTZone; |
| 676 | |
| 677 | DataManager::SetValue(TW_TIME_ZONE_VAR, NewTimeZone); |
| 678 | DataManager::update_tz_environment_variables(); |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | int GUIAction::overlay(std::string arg) |
| 683 | { |
| 684 | return gui_changeOverlay(arg); |
| 685 | } |
| 686 | |
| 687 | int GUIAction::queuezip(std::string arg) |
| 688 | { |
| 689 | if (zip_queue_index >= 10) { |
| 690 | gui_print("Maximum zip queue reached!\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 691 | return 0; |
| 692 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 693 | DataManager::GetValue("tw_filename", zip_queue[zip_queue_index]); |
| 694 | if (strlen(zip_queue[zip_queue_index].c_str()) > 0) { |
| 695 | zip_queue_index++; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 696 | DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 697 | } |
| 698 | return 0; |
| 699 | } |
| 700 | |
| 701 | int GUIAction::cancelzip(std::string arg) |
| 702 | { |
| 703 | if (zip_queue_index <= 0) { |
| 704 | gui_print("Minimum zip queue reached!\n"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 705 | return 0; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 706 | } else { |
| 707 | zip_queue_index--; |
| 708 | DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 709 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 710 | return 0; |
| 711 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 712 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 713 | int GUIAction::queueclear(std::string arg) |
| 714 | { |
| 715 | zip_queue_index = 0; |
| 716 | DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); |
| 717 | return 0; |
| 718 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 719 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 720 | int GUIAction::sleep(std::string arg) |
| 721 | { |
| 722 | operation_start("Sleep"); |
| 723 | usleep(atoi(arg.c_str())); |
| 724 | operation_end(0); |
| 725 | return 0; |
| 726 | } |
Dees Troy | b21cc64 | 2013-09-10 17:36:41 +0000 | [diff] [blame] | 727 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 728 | int GUIAction::appenddatetobackupname(std::string arg) |
| 729 | { |
| 730 | operation_start("AppendDateToBackupName"); |
| 731 | string Backup_Name; |
| 732 | DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); |
| 733 | Backup_Name += TWFunc::Get_Current_Date(); |
| 734 | if (Backup_Name.size() > MAX_BACKUP_NAME_LEN) |
| 735 | Backup_Name.resize(MAX_BACKUP_NAME_LEN); |
| 736 | DataManager::SetValue(TW_BACKUP_NAME, Backup_Name); |
| 737 | operation_end(0); |
| 738 | return 0; |
| 739 | } |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 740 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 741 | int GUIAction::generatebackupname(std::string arg) |
| 742 | { |
| 743 | operation_start("GenerateBackupName"); |
| 744 | TWFunc::Auto_Generate_Backup_Name(); |
| 745 | operation_end(0); |
| 746 | return 0; |
| 747 | } |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 748 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 749 | int GUIAction::checkpartitionlist(std::string arg) |
| 750 | { |
| 751 | string Wipe_List, wipe_path; |
| 752 | int count = 0; |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 753 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 754 | DataManager::GetValue("tw_wipe_list", Wipe_List); |
| 755 | LOGINFO("checkpartitionlist list '%s'\n", Wipe_List.c_str()); |
| 756 | if (!Wipe_List.empty()) { |
| 757 | size_t start_pos = 0, end_pos = Wipe_List.find(";", start_pos); |
| 758 | while (end_pos != string::npos && start_pos < Wipe_List.size()) { |
| 759 | wipe_path = Wipe_List.substr(start_pos, end_pos - start_pos); |
| 760 | LOGINFO("checkpartitionlist wipe_path '%s'\n", wipe_path.c_str()); |
| 761 | if (wipe_path == "/and-sec" || wipe_path == "DALVIK" || wipe_path == "INTERNAL") { |
| 762 | // Do nothing |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 763 | } else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 764 | count++; |
| 765 | } |
| 766 | start_pos = end_pos + 1; |
| 767 | end_pos = Wipe_List.find(";", start_pos); |
| 768 | } |
| 769 | DataManager::SetValue("tw_check_partition_list", count); |
| 770 | } else { |
| 771 | DataManager::SetValue("tw_check_partition_list", 0); |
| 772 | } |
| 773 | return 0; |
| 774 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 775 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 776 | int GUIAction::getpartitiondetails(std::string arg) |
| 777 | { |
| 778 | string Wipe_List, wipe_path; |
| 779 | int count = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 780 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 781 | DataManager::GetValue("tw_wipe_list", Wipe_List); |
| 782 | LOGINFO("getpartitiondetails list '%s'\n", Wipe_List.c_str()); |
| 783 | if (!Wipe_List.empty()) { |
| 784 | size_t start_pos = 0, end_pos = Wipe_List.find(";", start_pos); |
| 785 | while (end_pos != string::npos && start_pos < Wipe_List.size()) { |
| 786 | wipe_path = Wipe_List.substr(start_pos, end_pos - start_pos); |
| 787 | LOGINFO("getpartitiondetails wipe_path '%s'\n", wipe_path.c_str()); |
| 788 | if (wipe_path == "/and-sec" || wipe_path == "DALVIK" || wipe_path == "INTERNAL") { |
| 789 | // Do nothing |
| 790 | } else { |
| 791 | DataManager::SetValue("tw_partition_path", wipe_path); |
| 792 | break; |
| 793 | } |
| 794 | start_pos = end_pos + 1; |
| 795 | end_pos = Wipe_List.find(";", start_pos); |
| 796 | } |
| 797 | if (!wipe_path.empty()) { |
| 798 | TWPartition* Part = PartitionManager.Find_Partition_By_Path(wipe_path); |
| 799 | if (Part) { |
| 800 | unsigned long long mb = 1048576; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 801 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 802 | DataManager::SetValue("tw_partition_name", Part->Display_Name); |
| 803 | DataManager::SetValue("tw_partition_mount_point", Part->Mount_Point); |
| 804 | DataManager::SetValue("tw_partition_file_system", Part->Current_File_System); |
| 805 | DataManager::SetValue("tw_partition_size", Part->Size / mb); |
| 806 | DataManager::SetValue("tw_partition_used", Part->Used / mb); |
| 807 | DataManager::SetValue("tw_partition_free", Part->Free / mb); |
| 808 | DataManager::SetValue("tw_partition_backup_size", Part->Backup_Size / mb); |
| 809 | DataManager::SetValue("tw_partition_removable", Part->Removable); |
| 810 | DataManager::SetValue("tw_partition_is_present", Part->Is_Present); |
| 811 | |
| 812 | if (Part->Can_Repair()) |
| 813 | DataManager::SetValue("tw_partition_can_repair", 1); |
| 814 | else |
| 815 | DataManager::SetValue("tw_partition_can_repair", 0); |
| 816 | if (TWFunc::Path_Exists("/sbin/mkdosfs")) |
| 817 | DataManager::SetValue("tw_partition_vfat", 1); |
| 818 | else |
| 819 | DataManager::SetValue("tw_partition_vfat", 0); |
| 820 | if (TWFunc::Path_Exists("/sbin/mkfs.exfat")) |
| 821 | DataManager::SetValue("tw_partition_exfat", 1); |
| 822 | else |
| 823 | DataManager::SetValue("tw_partition_exfat", 0); |
| 824 | if (TWFunc::Path_Exists("/sbin/mkfs.f2fs")) |
| 825 | DataManager::SetValue("tw_partition_f2fs", 1); |
| 826 | else |
| 827 | DataManager::SetValue("tw_partition_f2fs", 0); |
| 828 | if (TWFunc::Path_Exists("/sbin/mke2fs")) |
| 829 | DataManager::SetValue("tw_partition_ext", 1); |
| 830 | else |
| 831 | DataManager::SetValue("tw_partition_ext", 0); |
| 832 | return 0; |
| 833 | } else { |
| 834 | LOGERR("Unable to locate partition: '%s'\n", wipe_path.c_str()); |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | DataManager::SetValue("tw_partition_name", ""); |
| 839 | DataManager::SetValue("tw_partition_file_system", ""); |
| 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | int GUIAction::screenshot(std::string arg) |
| 844 | { |
| 845 | time_t tm; |
| 846 | char path[256]; |
| 847 | int path_len; |
| 848 | uid_t uid = -1; |
| 849 | gid_t gid = -1; |
| 850 | |
| 851 | struct passwd *pwd = getpwnam("media_rw"); |
| 852 | if(pwd) { |
| 853 | uid = pwd->pw_uid; |
| 854 | gid = pwd->pw_gid; |
| 855 | } |
| 856 | |
| 857 | const std::string storage = DataManager::GetCurrentStoragePath(); |
| 858 | if(PartitionManager.Is_Mounted_By_Path(storage)) { |
| 859 | snprintf(path, sizeof(path), "%s/Pictures/Screenshots/", storage.c_str()); |
| 860 | } else { |
| 861 | strcpy(path, "/tmp/"); |
| 862 | } |
| 863 | |
| 864 | if(!TWFunc::Create_Dir_Recursive(path, 0666, uid, gid)) |
| 865 | return 0; |
| 866 | |
| 867 | tm = time(NULL); |
| 868 | path_len = strlen(path); |
| 869 | |
| 870 | // Screenshot_2014-01-01-18-21-38.png |
| 871 | strftime(path+path_len, sizeof(path)-path_len, "Screenshot_%Y-%m-%d-%H-%M-%S.png", localtime(&tm)); |
| 872 | |
| 873 | int res = gr_save_screenshot(path); |
| 874 | if(res == 0) { |
| 875 | chmod(path, 0666); |
| 876 | chown(path, uid, gid); |
| 877 | |
| 878 | gui_print("Screenshot was saved to %s\n", path); |
| 879 | |
| 880 | // blink to notify that the screenshow was taken |
| 881 | gr_color(255, 255, 255, 255); |
| 882 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 883 | gr_flip(); |
| 884 | gui_forceRender(); |
| 885 | } else { |
| 886 | LOGERR("Failed to take a screenshot!\n"); |
| 887 | } |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | int GUIAction::setbrightness(std::string arg) |
| 892 | { |
| 893 | return TWFunc::Set_Brightness(arg); |
| 894 | } |
| 895 | |
| 896 | int GUIAction::fileexists(std::string arg) |
| 897 | { |
| 898 | struct stat st; |
| 899 | string newpath = arg + "/."; |
| 900 | |
| 901 | operation_start("FileExists"); |
| 902 | if (stat(arg.c_str(), &st) == 0 || stat(newpath.c_str(), &st) == 0) |
| 903 | operation_end(0); |
| 904 | else |
| 905 | operation_end(1); |
| 906 | return 0; |
| 907 | } |
| 908 | |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 909 | void GUIAction::reinject_after_flash() |
| 910 | { |
| 911 | if (DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) { |
| 912 | operation_start("ReinjectTWRP"); |
| 913 | gui_print("Injecting TWRP into boot image...\n"); |
| 914 | if (simulate) { |
| 915 | simulate_progress_bar(); |
| 916 | } else { |
| 917 | TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot"); |
| 918 | if (Boot == NULL || Boot->Current_File_System != "emmc") |
| 919 | TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash"); |
| 920 | else { |
| 921 | string injectcmd = "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + Boot->Actual_Block_Device; |
| 922 | TWFunc::Exec_Cmd(injectcmd); |
| 923 | } |
| 924 | gui_print("TWRP injection complete.\n"); |
| 925 | } |
| 926 | } |
| 927 | } |
| 928 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 929 | int GUIAction::flash(std::string arg) |
| 930 | { |
| 931 | int i, ret_val = 0, wipe_cache = 0; |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 932 | // We're going to jump to this page first, like a loading page |
| 933 | gui_changePage(arg); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 934 | for (i=0; i<zip_queue_index; i++) { |
| 935 | operation_start("Flashing"); |
| 936 | DataManager::SetValue("tw_filename", zip_queue[i]); |
| 937 | DataManager::SetValue(TW_ZIP_INDEX, (i + 1)); |
| 938 | |
| 939 | TWFunc::SetPerformanceMode(true); |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 940 | ret_val = flash_zip(zip_queue[i], &wipe_cache); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 941 | TWFunc::SetPerformanceMode(false); |
| 942 | if (ret_val != 0) { |
| 943 | gui_print("Error flashing zip '%s'\n", zip_queue[i].c_str()); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 944 | ret_val = 1; |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 945 | break; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | zip_queue_index = 0; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 949 | |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 950 | if (wipe_cache) { |
| 951 | gui_print("One or more zip requested a cache wipe\nWiping cache now.\n"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 952 | PartitionManager.Wipe_By_Path("/cache"); |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 953 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 954 | |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 955 | reinject_after_flash(); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 956 | PartitionManager.Update_System_Details(); |
| 957 | operation_end(ret_val); |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 958 | DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 959 | return 0; |
| 960 | } |
| 961 | |
| 962 | int GUIAction::wipe(std::string arg) |
| 963 | { |
| 964 | operation_start("Format"); |
| 965 | DataManager::SetValue("tw_partition", arg); |
| 966 | |
| 967 | int ret_val = false; |
| 968 | |
| 969 | if (simulate) { |
| 970 | simulate_progress_bar(); |
| 971 | } else { |
| 972 | if (arg == "data") |
| 973 | ret_val = PartitionManager.Factory_Reset(); |
| 974 | else if (arg == "battery") |
| 975 | ret_val = PartitionManager.Wipe_Battery_Stats(); |
| 976 | else if (arg == "rotate") |
| 977 | ret_val = PartitionManager.Wipe_Rotate_Data(); |
| 978 | else if (arg == "dalvik") |
| 979 | ret_val = PartitionManager.Wipe_Dalvik_Cache(); |
| 980 | else if (arg == "DATAMEDIA") { |
| 981 | ret_val = PartitionManager.Format_Data(); |
| 982 | } else if (arg == "INTERNAL") { |
| 983 | int has_datamedia, dual_storage; |
| 984 | |
| 985 | DataManager::GetValue(TW_HAS_DATA_MEDIA, has_datamedia); |
| 986 | if (has_datamedia) { |
| 987 | ret_val = PartitionManager.Wipe_Media_From_Data(); |
| 988 | } else { |
| 989 | ret_val = PartitionManager.Wipe_By_Path(DataManager::GetSettingsStoragePath()); |
| 990 | } |
| 991 | } else if (arg == "EXTERNAL") { |
| 992 | string External_Path; |
| 993 | |
| 994 | DataManager::GetValue(TW_EXTERNAL_PATH, External_Path); |
| 995 | ret_val = PartitionManager.Wipe_By_Path(External_Path); |
| 996 | } else if (arg == "ANDROIDSECURE") { |
| 997 | ret_val = PartitionManager.Wipe_Android_Secure(); |
| 998 | } else if (arg == "LIST") { |
| 999 | string Wipe_List, wipe_path; |
| 1000 | bool skip = false; |
| 1001 | ret_val = true; |
| 1002 | TWPartition* wipe_part = NULL; |
| 1003 | |
| 1004 | DataManager::GetValue("tw_wipe_list", Wipe_List); |
| 1005 | LOGINFO("wipe list '%s'\n", Wipe_List.c_str()); |
| 1006 | if (!Wipe_List.empty()) { |
| 1007 | size_t start_pos = 0, end_pos = Wipe_List.find(";", start_pos); |
| 1008 | while (end_pos != string::npos && start_pos < Wipe_List.size()) { |
| 1009 | wipe_path = Wipe_List.substr(start_pos, end_pos - start_pos); |
| 1010 | LOGINFO("wipe_path '%s'\n", wipe_path.c_str()); |
| 1011 | if (wipe_path == "/and-sec") { |
| 1012 | if (!PartitionManager.Wipe_Android_Secure()) { |
| 1013 | LOGERR("Unable to wipe android secure\n"); |
| 1014 | ret_val = false; |
| 1015 | break; |
| 1016 | } else { |
| 1017 | skip = true; |
| 1018 | } |
| 1019 | } else if (wipe_path == "DALVIK") { |
| 1020 | if (!PartitionManager.Wipe_Dalvik_Cache()) { |
| 1021 | LOGERR("Failed to wipe dalvik\n"); |
| 1022 | ret_val = false; |
| 1023 | break; |
| 1024 | } else { |
| 1025 | skip = true; |
| 1026 | } |
| 1027 | } else if (wipe_path == "INTERNAL") { |
| 1028 | if (!PartitionManager.Wipe_Media_From_Data()) { |
| 1029 | ret_val = false; |
| 1030 | break; |
| 1031 | } else { |
| 1032 | skip = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1033 | } |
| 1034 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1035 | if (!skip) { |
| 1036 | if (!PartitionManager.Wipe_By_Path(wipe_path)) { |
| 1037 | LOGERR("Unable to wipe '%s'\n", wipe_path.c_str()); |
| 1038 | ret_val = false; |
| 1039 | break; |
| 1040 | } else if (wipe_path == DataManager::GetSettingsStoragePath()) { |
| 1041 | arg = wipe_path; |
| 1042 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1043 | } else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1044 | skip = false; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1045 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1046 | start_pos = end_pos + 1; |
| 1047 | end_pos = Wipe_List.find(";", start_pos); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1048 | } |
| 1049 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1050 | } else |
| 1051 | ret_val = PartitionManager.Wipe_By_Path(arg); |
| 1052 | #ifdef TW_OEM_BUILD |
| 1053 | if (arg == DataManager::GetSettingsStoragePath()) { |
| 1054 | // If we wiped the settings storage path, recreate the TWRP folder and dump the settings |
| 1055 | string Storage_Path = DataManager::GetSettingsStoragePath(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1056 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1057 | if (PartitionManager.Mount_By_Path(Storage_Path, true)) { |
| 1058 | LOGINFO("Making TWRP folder and saving settings.\n"); |
| 1059 | Storage_Path += "/TWRP"; |
| 1060 | mkdir(Storage_Path.c_str(), 0777); |
| 1061 | DataManager::Flush(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1062 | } else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1063 | LOGERR("Unable to recreate TWRP folder and save settings.\n"); |
| 1064 | } |
| 1065 | } |
| 1066 | #endif |
| 1067 | } |
| 1068 | PartitionManager.Update_System_Details(); |
| 1069 | if (ret_val) |
| 1070 | ret_val = 0; // 0 is success |
| 1071 | else |
| 1072 | ret_val = 1; // 1 is failure |
| 1073 | operation_end(ret_val); |
| 1074 | return 0; |
| 1075 | } |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 1076 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1077 | int GUIAction::refreshsizes(std::string arg) |
| 1078 | { |
| 1079 | operation_start("Refreshing Sizes"); |
| 1080 | if (simulate) { |
| 1081 | simulate_progress_bar(); |
| 1082 | } else |
| 1083 | PartitionManager.Update_System_Details(); |
| 1084 | operation_end(0); |
| 1085 | return 0; |
| 1086 | } |
| 1087 | |
| 1088 | int GUIAction::nandroid(std::string arg) |
| 1089 | { |
| 1090 | operation_start("Nandroid"); |
| 1091 | int ret = 0; |
| 1092 | |
| 1093 | if (simulate) { |
| 1094 | DataManager::SetValue("tw_partition", "Simulation"); |
| 1095 | simulate_progress_bar(); |
| 1096 | } else { |
| 1097 | if (arg == "backup") { |
| 1098 | string Backup_Name; |
| 1099 | DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); |
| 1100 | if (Backup_Name == "(Auto Generate)" || Backup_Name == "(Current Date)" || Backup_Name == "0" || Backup_Name == "(" || PartitionManager.Check_Backup_Name(true) == 0) { |
| 1101 | ret = PartitionManager.Run_Backup(); |
| 1102 | } |
| 1103 | else { |
| 1104 | operation_end(1); |
| 1105 | return -1; |
| 1106 | |
| 1107 | } |
| 1108 | DataManager::SetValue(TW_BACKUP_NAME, "(Auto Generate)"); |
| 1109 | } else if (arg == "restore") { |
| 1110 | string Restore_Name; |
| 1111 | DataManager::GetValue("tw_restore", Restore_Name); |
| 1112 | ret = PartitionManager.Run_Restore(Restore_Name); |
| 1113 | } else { |
| 1114 | operation_end(1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1115 | return -1; |
| 1116 | } |
| 1117 | } |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1118 | DataManager::SetValue("tw_encrypt_backup", 0); |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 1119 | if (ret == false) |
| 1120 | ret = 1; // 1 for failure |
| 1121 | else |
| 1122 | ret = 0; // 0 for success |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1123 | operation_end(ret); |
Dees_Troy | 83bd483 | 2013-05-04 12:39:56 +0000 | [diff] [blame] | 1124 | return 0; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1125 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1126 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1127 | int GUIAction::fixpermissions(std::string arg) |
| 1128 | { |
| 1129 | operation_start("Fix Permissions"); |
| 1130 | LOGINFO("fix permissions started!\n"); |
| 1131 | if (simulate) { |
| 1132 | simulate_progress_bar(); |
| 1133 | } else { |
| 1134 | int op_status = PartitionManager.Fix_Permissions(); |
| 1135 | if (op_status != 0) |
| 1136 | op_status = 1; // failure |
| 1137 | operation_end(op_status); |
| 1138 | } |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
| 1142 | int GUIAction::dd(std::string arg) |
| 1143 | { |
| 1144 | operation_start("imaging"); |
| 1145 | |
| 1146 | if (simulate) { |
| 1147 | simulate_progress_bar(); |
| 1148 | } else { |
| 1149 | string cmd = "dd " + arg; |
| 1150 | TWFunc::Exec_Cmd(cmd); |
| 1151 | } |
| 1152 | operation_end(0); |
| 1153 | return 0; |
| 1154 | } |
| 1155 | |
| 1156 | int GUIAction::partitionsd(std::string arg) |
| 1157 | { |
| 1158 | operation_start("Partition SD Card"); |
| 1159 | int ret_val = 0; |
| 1160 | |
| 1161 | if (simulate) { |
| 1162 | simulate_progress_bar(); |
| 1163 | } else { |
| 1164 | int allow_partition; |
| 1165 | DataManager::GetValue(TW_ALLOW_PARTITION_SDCARD, allow_partition); |
| 1166 | if (allow_partition == 0) { |
| 1167 | gui_print("This device does not have a real SD Card!\nAborting!\n"); |
| 1168 | } else { |
| 1169 | if (!PartitionManager.Partition_SDCard()) |
| 1170 | ret_val = 1; // failed |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1171 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1172 | } |
| 1173 | operation_end(ret_val); |
| 1174 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1175 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1176 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1177 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1178 | int GUIAction::installhtcdumlock(std::string arg) |
| 1179 | { |
| 1180 | operation_start("Install HTC Dumlock"); |
| 1181 | if (simulate) { |
| 1182 | simulate_progress_bar(); |
| 1183 | } else |
| 1184 | TWFunc::install_htc_dumlock(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1185 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1186 | operation_end(0); |
| 1187 | return 0; |
| 1188 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1189 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1190 | int GUIAction::htcdumlockrestoreboot(std::string arg) |
| 1191 | { |
| 1192 | operation_start("HTC Dumlock Restore Boot"); |
| 1193 | if (simulate) { |
| 1194 | simulate_progress_bar(); |
| 1195 | } else |
| 1196 | TWFunc::htc_dumlock_restore_original_boot(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1197 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1198 | operation_end(0); |
| 1199 | return 0; |
| 1200 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1201 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1202 | int GUIAction::htcdumlockreflashrecovery(std::string arg) |
| 1203 | { |
| 1204 | operation_start("HTC Dumlock Reflash Recovery"); |
| 1205 | if (simulate) { |
| 1206 | simulate_progress_bar(); |
| 1207 | } else |
| 1208 | TWFunc::htc_dumlock_reflash_recovery_to_boot(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1209 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1210 | operation_end(0); |
| 1211 | return 0; |
| 1212 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1213 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1214 | int GUIAction::cmd(std::string arg) |
| 1215 | { |
| 1216 | int op_status = 0; |
| 1217 | |
| 1218 | operation_start("Command"); |
| 1219 | LOGINFO("Running command: '%s'\n", arg.c_str()); |
| 1220 | if (simulate) { |
| 1221 | simulate_progress_bar(); |
| 1222 | } else { |
| 1223 | op_status = TWFunc::Exec_Cmd(arg); |
| 1224 | if (op_status != 0) |
| 1225 | op_status = 1; |
| 1226 | } |
| 1227 | |
| 1228 | operation_end(op_status); |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | int GUIAction::terminalcommand(std::string arg) |
| 1233 | { |
| 1234 | int op_status = 0; |
| 1235 | string cmdpath, command; |
| 1236 | |
| 1237 | DataManager::GetValue("tw_terminal_location", cmdpath); |
| 1238 | operation_start("CommandOutput"); |
| 1239 | gui_print("%s # %s\n", cmdpath.c_str(), arg.c_str()); |
| 1240 | if (simulate) { |
| 1241 | simulate_progress_bar(); |
| 1242 | operation_end(op_status); |
| 1243 | } else { |
| 1244 | command = "cd \"" + cmdpath + "\" && " + arg + " 2>&1";; |
| 1245 | LOGINFO("Actual command is: '%s'\n", command.c_str()); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1246 | DataManager::SetValue("tw_terminal_state", 1); |
| 1247 | DataManager::SetValue("tw_background_thread_running", 1); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1248 | FILE* fp; |
| 1249 | char line[512]; |
| 1250 | |
| 1251 | fp = popen(command.c_str(), "r"); |
| 1252 | if (fp == NULL) { |
| 1253 | LOGERR("Error opening command to run.\n"); |
| 1254 | } else { |
| 1255 | int fd = fileno(fp), has_data = 0, check = 0, keep_going = -1, bytes_read = 0; |
| 1256 | struct timeval timeout; |
| 1257 | fd_set fdset; |
| 1258 | |
| 1259 | while(keep_going) |
| 1260 | { |
| 1261 | FD_ZERO(&fdset); |
| 1262 | FD_SET(fd, &fdset); |
| 1263 | timeout.tv_sec = 0; |
| 1264 | timeout.tv_usec = 400000; |
| 1265 | has_data = select(fd+1, &fdset, NULL, NULL, &timeout); |
| 1266 | if (has_data == 0) { |
| 1267 | // Timeout reached |
| 1268 | DataManager::GetValue("tw_terminal_state", check); |
| 1269 | if (check == 0) { |
| 1270 | keep_going = 0; |
| 1271 | } |
| 1272 | } else if (has_data < 0) { |
| 1273 | // End of execution |
| 1274 | keep_going = 0; |
| 1275 | } else { |
| 1276 | // Try to read output |
| 1277 | memset(line, 0, sizeof(line)); |
| 1278 | bytes_read = read(fd, line, sizeof(line)); |
| 1279 | if (bytes_read > 0) |
| 1280 | gui_print("%s", line); // Display output |
| 1281 | else |
| 1282 | keep_going = 0; // Done executing |
| 1283 | } |
| 1284 | } |
| 1285 | fclose(fp); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1286 | } |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1287 | DataManager::SetValue("tw_operation_status", 0); |
| 1288 | DataManager::SetValue("tw_operation_state", 1); |
| 1289 | DataManager::SetValue("tw_terminal_state", 0); |
| 1290 | DataManager::SetValue("tw_background_thread_running", 0); |
| 1291 | DataManager::SetValue(TW_ACTION_BUSY, 0); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1292 | } |
| 1293 | return 0; |
| 1294 | } |
| 1295 | |
| 1296 | int GUIAction::killterminal(std::string arg) |
| 1297 | { |
| 1298 | int op_status = 0; |
| 1299 | |
| 1300 | LOGINFO("Sending kill command...\n"); |
| 1301 | operation_start("KillCommand"); |
| 1302 | DataManager::SetValue("tw_operation_status", 0); |
| 1303 | DataManager::SetValue("tw_operation_state", 1); |
| 1304 | DataManager::SetValue("tw_terminal_state", 0); |
| 1305 | DataManager::SetValue("tw_background_thread_running", 0); |
| 1306 | DataManager::SetValue(TW_ACTION_BUSY, 0); |
| 1307 | return 0; |
| 1308 | } |
| 1309 | |
| 1310 | int GUIAction::reinjecttwrp(std::string arg) |
| 1311 | { |
| 1312 | int op_status = 0; |
| 1313 | operation_start("ReinjectTWRP"); |
| 1314 | gui_print("Injecting TWRP into boot image...\n"); |
| 1315 | if (simulate) { |
| 1316 | simulate_progress_bar(); |
| 1317 | } else { |
| 1318 | TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash"); |
| 1319 | gui_print("TWRP injection complete.\n"); |
| 1320 | } |
| 1321 | |
| 1322 | operation_end(op_status); |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | int GUIAction::checkbackupname(std::string arg) |
| 1327 | { |
| 1328 | int op_status = 0; |
| 1329 | |
| 1330 | operation_start("CheckBackupName"); |
| 1331 | if (simulate) { |
| 1332 | simulate_progress_bar(); |
| 1333 | } else { |
| 1334 | op_status = PartitionManager.Check_Backup_Name(true); |
| 1335 | if (op_status != 0) |
| 1336 | op_status = 1; |
| 1337 | } |
| 1338 | |
| 1339 | operation_end(op_status); |
| 1340 | return 0; |
| 1341 | } |
| 1342 | |
| 1343 | int GUIAction::decrypt(std::string arg) |
| 1344 | { |
| 1345 | int op_status = 0; |
| 1346 | |
| 1347 | operation_start("Decrypt"); |
| 1348 | if (simulate) { |
| 1349 | simulate_progress_bar(); |
| 1350 | } else { |
| 1351 | string Password; |
| 1352 | DataManager::GetValue("tw_crypto_password", Password); |
| 1353 | op_status = PartitionManager.Decrypt_Device(Password); |
| 1354 | if (op_status != 0) |
| 1355 | op_status = 1; |
| 1356 | else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1357 | |
| 1358 | DataManager::SetValue(TW_IS_ENCRYPTED, 0); |
| 1359 | |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 1360 | int has_datamedia; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1361 | |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 1362 | // Check for a custom theme and load it if exists |
| 1363 | DataManager::GetValue(TW_HAS_DATA_MEDIA, has_datamedia); |
| 1364 | if (has_datamedia != 0) { |
| 1365 | if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) { |
| 1366 | LOGERR("Failed to get default contexts and file mode for storage files.\n"); |
| 1367 | } else { |
| 1368 | LOGINFO("Got default contexts and file mode for storage files.\n"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1369 | } |
| 1370 | } |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | operation_end(op_status); |
| 1375 | return 0; |
| 1376 | } |
| 1377 | |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1378 | int GUIAction::adbsideload(std::string arg) |
| 1379 | { |
| 1380 | operation_start("Sideload"); |
| 1381 | if (simulate) { |
| 1382 | simulate_progress_bar(); |
| 1383 | operation_end(0); |
| 1384 | } else { |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1385 | gui_print("Starting ADB sideload feature...\n"); |
| 1386 | bool mtp_was_enabled = TWFunc::Toggle_MTP(false); |
| 1387 | |
| 1388 | // wait for the adb connection |
| 1389 | int ret = apply_from_adb("/", &sideload_child_pid); |
| 1390 | DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui now that the zip install is going to start |
| 1391 | |
| 1392 | if (ret != 0) { |
| 1393 | if (ret == -2) |
| 1394 | gui_print("You need adb 1.0.32 or newer to sideload to this device.\n"); |
| 1395 | ret = 1; // failure |
| 1396 | } else { |
| 1397 | int wipe_cache = 0; |
| 1398 | int wipe_dalvik = 0; |
| 1399 | DataManager::GetValue("tw_wipe_dalvik", wipe_dalvik); |
| 1400 | |
| 1401 | if (TWinstall_zip(FUSE_SIDELOAD_HOST_PATHNAME, &wipe_cache) == 0) { |
| 1402 | if (wipe_cache || DataManager::GetIntValue("tw_wipe_cache")) |
| 1403 | PartitionManager.Wipe_By_Path("/cache"); |
| 1404 | if (wipe_dalvik) |
| 1405 | PartitionManager.Wipe_Dalvik_Cache(); |
| 1406 | } else { |
| 1407 | ret = 1; // failure |
| 1408 | } |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1409 | } |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1410 | if (sideload_child_pid) { |
| 1411 | LOGINFO("Signaling child sideload process to exit.\n"); |
| 1412 | struct stat st; |
| 1413 | // Calling stat() on this magic filename signals the minadbd |
| 1414 | // subprocess to shut down. |
| 1415 | stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st); |
| 1416 | int status; |
| 1417 | LOGINFO("Waiting for child sideload process to exit.\n"); |
| 1418 | waitpid(sideload_child_pid, &status, 0); |
| 1419 | } |
| 1420 | |
| 1421 | TWFunc::Toggle_MTP(mtp_was_enabled); |
| 1422 | reinject_after_flash(); |
| 1423 | operation_end(ret); |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1424 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1425 | return 0; |
| 1426 | } |
| 1427 | |
| 1428 | int GUIAction::adbsideloadcancel(std::string arg) |
| 1429 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1430 | struct stat st; |
| 1431 | DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui |
| 1432 | gui_print("Cancelling ADB sideload...\n"); |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1433 | LOGINFO("Signaling child sideload process to exit.\n"); |
| 1434 | // Calling stat() on this magic filename signals the minadbd |
| 1435 | // subprocess to shut down. |
| 1436 | stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st); |
| 1437 | if (!sideload_child_pid) { |
| 1438 | LOGERR("Unable to get child ID\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1439 | return 0; |
| 1440 | } |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1441 | ::sleep(1); |
| 1442 | LOGINFO("Killing child sideload process.\n"); |
| 1443 | kill(sideload_child_pid, SIGTERM); |
| 1444 | int status; |
| 1445 | LOGINFO("Waiting for child sideload process to exit.\n"); |
| 1446 | waitpid(sideload_child_pid, &status, 0); |
| 1447 | sideload_child_pid = 0; |
| 1448 | operation_end(1); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1449 | DataManager::SetValue("tw_page_done", "1"); // For OpenRecoveryScript support |
| 1450 | return 0; |
| 1451 | } |
| 1452 | |
| 1453 | int GUIAction::openrecoveryscript(std::string arg) |
| 1454 | { |
| 1455 | operation_start("OpenRecoveryScript"); |
| 1456 | if (simulate) { |
| 1457 | simulate_progress_bar(); |
Ethan Yonker | 24e7eb7 | 2015-01-03 16:13:06 -0600 | [diff] [blame] | 1458 | operation_end(0); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1459 | } else { |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1460 | // Check for the SCRIPT_FILE_TMP first as these are AOSP recovery commands |
| 1461 | // that we converted to ORS commands during boot in recovery.cpp. |
| 1462 | // Run those first. |
| 1463 | int reboot = 0; |
| 1464 | if (TWFunc::Path_Exists(SCRIPT_FILE_TMP)) { |
| 1465 | gui_print("Processing AOSP recovery commands...\n"); |
| 1466 | if (OpenRecoveryScript::run_script_file() == 0) { |
| 1467 | reboot = 1; |
| 1468 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1469 | } |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1470 | // Check for the ORS file in /cache and attempt to run those commands. |
| 1471 | if (OpenRecoveryScript::check_for_script_file()) { |
| 1472 | gui_print("Processing OpenRecoveryScript file...\n"); |
| 1473 | if (OpenRecoveryScript::run_script_file() == 0) { |
| 1474 | reboot = 1; |
| 1475 | } |
| 1476 | } |
| 1477 | if (reboot) { |
| 1478 | usleep(2000000); // Sleep for 2 seconds before rebooting |
| 1479 | TWFunc::tw_reboot(rb_system); |
| 1480 | } else { |
| 1481 | DataManager::SetValue("tw_page_done", 1); |
| 1482 | } |
| 1483 | operation_end(1); |
| 1484 | return 0; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1485 | } |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
| 1489 | int GUIAction::installsu(std::string arg) |
| 1490 | { |
| 1491 | int op_status = 0; |
| 1492 | |
| 1493 | operation_start("Install SuperSU"); |
| 1494 | if (simulate) { |
| 1495 | simulate_progress_bar(); |
| 1496 | } else { |
| 1497 | if (!TWFunc::Install_SuperSU()) |
| 1498 | op_status = 1; |
| 1499 | } |
| 1500 | |
| 1501 | operation_end(op_status); |
| 1502 | return 0; |
| 1503 | } |
| 1504 | |
| 1505 | int GUIAction::fixsu(std::string arg) |
| 1506 | { |
| 1507 | int op_status = 0; |
| 1508 | |
| 1509 | operation_start("Fixing Superuser Permissions"); |
| 1510 | if (simulate) { |
| 1511 | simulate_progress_bar(); |
| 1512 | } else { |
| 1513 | LOGERR("Fixing su permissions was deprecated from TWRP.\n"); |
| 1514 | LOGERR("4.3+ ROMs with SELinux will always lose su perms.\n"); |
| 1515 | } |
| 1516 | |
| 1517 | operation_end(op_status); |
| 1518 | return 0; |
| 1519 | } |
| 1520 | |
| 1521 | int GUIAction::decrypt_backup(std::string arg) |
| 1522 | { |
| 1523 | int op_status = 0; |
| 1524 | |
| 1525 | operation_start("Try Restore Decrypt"); |
| 1526 | if (simulate) { |
| 1527 | simulate_progress_bar(); |
| 1528 | } else { |
| 1529 | string Restore_Path, Filename, Password; |
| 1530 | DataManager::GetValue("tw_restore", Restore_Path); |
| 1531 | Restore_Path += "/"; |
| 1532 | DataManager::GetValue("tw_restore_password", Password); |
| 1533 | TWFunc::SetPerformanceMode(true); |
| 1534 | if (TWFunc::Try_Decrypting_Backup(Restore_Path, Password)) |
| 1535 | op_status = 0; // success |
| 1536 | else |
| 1537 | op_status = 1; // fail |
| 1538 | TWFunc::SetPerformanceMode(false); |
| 1539 | } |
| 1540 | |
| 1541 | operation_end(op_status); |
| 1542 | return 0; |
| 1543 | } |
| 1544 | |
| 1545 | int GUIAction::repair(std::string arg) |
| 1546 | { |
| 1547 | int op_status = 0; |
| 1548 | |
| 1549 | operation_start("Repair Partition"); |
| 1550 | if (simulate) { |
| 1551 | simulate_progress_bar(); |
| 1552 | } else { |
| 1553 | string part_path; |
| 1554 | DataManager::GetValue("tw_partition_mount_point", part_path); |
| 1555 | if (PartitionManager.Repair_By_Path(part_path, true)) { |
| 1556 | op_status = 0; // success |
| 1557 | } else { |
| 1558 | LOGERR("Error repairing file system.\n"); |
| 1559 | op_status = 1; // fail |
| 1560 | } |
| 1561 | } |
| 1562 | |
| 1563 | operation_end(op_status); |
| 1564 | return 0; |
| 1565 | } |
| 1566 | |
| 1567 | int GUIAction::changefilesystem(std::string arg) |
| 1568 | { |
| 1569 | int op_status = 0; |
| 1570 | |
| 1571 | operation_start("Change File System"); |
| 1572 | if (simulate) { |
| 1573 | simulate_progress_bar(); |
| 1574 | } else { |
| 1575 | string part_path, file_system; |
| 1576 | DataManager::GetValue("tw_partition_mount_point", part_path); |
| 1577 | DataManager::GetValue("tw_action_new_file_system", file_system); |
| 1578 | if (PartitionManager.Wipe_By_Path(part_path, file_system)) { |
| 1579 | op_status = 0; // success |
| 1580 | } else { |
| 1581 | LOGERR("Error changing file system.\n"); |
| 1582 | op_status = 1; // fail |
| 1583 | } |
| 1584 | } |
| 1585 | PartitionManager.Update_System_Details(); |
| 1586 | operation_end(op_status); |
| 1587 | return 0; |
| 1588 | } |
| 1589 | |
| 1590 | int GUIAction::startmtp(std::string arg) |
| 1591 | { |
| 1592 | int op_status = 0; |
| 1593 | |
| 1594 | operation_start("Start MTP"); |
| 1595 | if (PartitionManager.Enable_MTP()) |
| 1596 | op_status = 0; // success |
| 1597 | else |
| 1598 | op_status = 1; // fail |
| 1599 | |
| 1600 | operation_end(op_status); |
| 1601 | return 0; |
| 1602 | } |
| 1603 | |
| 1604 | int GUIAction::stopmtp(std::string arg) |
| 1605 | { |
| 1606 | int op_status = 0; |
| 1607 | |
| 1608 | operation_start("Stop MTP"); |
| 1609 | if (PartitionManager.Disable_MTP()) |
| 1610 | op_status = 0; // success |
| 1611 | else |
| 1612 | op_status = 1; // fail |
| 1613 | |
| 1614 | operation_end(op_status); |
| 1615 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1616 | } |
| 1617 | |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 1618 | int GUIAction::flashimage(std::string arg) |
| 1619 | { |
| 1620 | int op_status = 0; |
| 1621 | |
| 1622 | operation_start("Flash Image"); |
| 1623 | string path, filename, full_filename; |
| 1624 | DataManager::GetValue("tw_zip_location", path); |
| 1625 | DataManager::GetValue("tw_file", filename); |
| 1626 | full_filename = path + "/" + filename; |
| 1627 | if (PartitionManager.Flash_Image(full_filename)) |
| 1628 | op_status = 0; // success |
| 1629 | else |
| 1630 | op_status = 1; // fail |
| 1631 | |
| 1632 | operation_end(op_status); |
| 1633 | return 0; |
| 1634 | } |
| 1635 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1636 | int GUIAction::getKeyByName(std::string key) |
| 1637 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1638 | if (key == "home") return KEY_HOME; |
| 1639 | else if (key == "menu") return KEY_MENU; |
| 1640 | else if (key == "back") return KEY_BACK; |
| 1641 | else if (key == "search") return KEY_SEARCH; |
| 1642 | else if (key == "voldown") return KEY_VOLUMEDOWN; |
| 1643 | else if (key == "volup") return KEY_VOLUMEUP; |
| 1644 | else if (key == "power") { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1645 | int ret_val; |
| 1646 | DataManager::GetValue(TW_POWER_BUTTON, ret_val); |
| 1647 | if (!ret_val) |
| 1648 | return KEY_POWER; |
| 1649 | else |
| 1650 | return ret_val; |
| 1651 | } |
| 1652 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1653 | return atol(key.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1654 | } |