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