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