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