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