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