Ethan Yonker | 6e8c27a | 2016-12-22 17:55:57 -0600 | [diff] [blame] | 1 | /* |
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> |
Matt Mower | 0c88b84 | 2017-01-15 16:00:49 -0600 | [diff] [blame] | 35 | #include <private/android_filesystem_config.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" |
bigbiff | 56b02eb | 2020-07-06 20:24:34 -0400 | [diff] [blame] | 41 | #include "../twrpRepacker.hpp" |
Dees_Troy | 812660f | 2012-09-20 09:55:17 -0400 | [diff] [blame] | 42 | #include "../openrecoveryscript.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 43 | |
Dees_Troy | 43d8b00 | 2012-09-17 16:00:01 -0400 | [diff] [blame] | 44 | #include "../adb_install.h" |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 45 | #include "../fuse_sideload.h" |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 46 | #include "blanktimer.hpp" |
Ethan Yonker | 8373cfe | 2017-09-08 06:50:54 -0500 | [diff] [blame] | 47 | #include "../twinstall.h" |
Ethan Yonker | fbb4353 | 2015-12-28 21:54:50 +0100 | [diff] [blame] | 48 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 49 | extern "C" { |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 50 | #include "../twcommon.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 51 | #include "../variables.h" |
Dees_Troy | 2673cec | 2013-04-02 20:22:16 +0000 | [diff] [blame] | 52 | #include "cutils/properties.h" |
Ethan Yonker | 2481342 | 2014-11-07 17:19:07 -0600 | [diff] [blame] | 53 | #include "../adb_install.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 54 | }; |
Ethan Yonker | f117962 | 2016-08-25 15:32:21 -0500 | [diff] [blame] | 55 | #include "../set_metadata.h" |
Ethan Yonker | fbb4353 | 2015-12-28 21:54:50 +0100 | [diff] [blame] | 56 | #include "../minuitwrp/minui.h" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 57 | |
| 58 | #include "rapidxml.hpp" |
| 59 | #include "objects.hpp" |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 60 | #include "../tw_atomic.hpp" |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 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; |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 66 | pid_t sideload_child_pid; |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 67 | extern std::vector<users_struct> Users_List; |
Mohd Faraz | 3c25ab3 | 2020-08-12 12:29:42 +0000 | [diff] [blame] | 68 | extern GUITerminal* term; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 69 | |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 70 | static void *ActionThread_work_wrapper(void *data); |
| 71 | |
| 72 | class ActionThread |
| 73 | { |
| 74 | public: |
| 75 | ActionThread(); |
| 76 | ~ActionThread(); |
| 77 | |
| 78 | void threadActions(GUIAction *act); |
| 79 | void run(void *data); |
| 80 | private: |
| 81 | friend void *ActionThread_work_wrapper(void*); |
| 82 | struct ThreadData |
| 83 | { |
| 84 | ActionThread *this_; |
| 85 | GUIAction *act; |
| 86 | ThreadData(ActionThread *this_, GUIAction *act) : this_(this_), act(act) {} |
| 87 | }; |
| 88 | |
| 89 | pthread_t m_thread; |
| 90 | bool m_thread_running; |
| 91 | pthread_mutex_t m_act_lock; |
| 92 | }; |
| 93 | |
| 94 | static ActionThread action_thread; // for all kinds of longer running actions |
| 95 | static ActionThread cancel_thread; // for longer running "cancel" actions |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 96 | |
| 97 | static void *ActionThread_work_wrapper(void *data) |
| 98 | { |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 99 | static_cast<ActionThread::ThreadData*>(data)->this_->run(data); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 100 | return NULL; |
| 101 | } |
| 102 | |
| 103 | ActionThread::ActionThread() |
| 104 | { |
| 105 | m_thread_running = false; |
| 106 | pthread_mutex_init(&m_act_lock, NULL); |
| 107 | } |
| 108 | |
| 109 | ActionThread::~ActionThread() |
| 110 | { |
| 111 | pthread_mutex_lock(&m_act_lock); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 112 | if (m_thread_running) { |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 113 | pthread_mutex_unlock(&m_act_lock); |
| 114 | pthread_join(m_thread, NULL); |
| 115 | } else { |
| 116 | pthread_mutex_unlock(&m_act_lock); |
| 117 | } |
| 118 | pthread_mutex_destroy(&m_act_lock); |
| 119 | } |
| 120 | |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 121 | void ActionThread::threadActions(GUIAction *act) |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 122 | { |
| 123 | pthread_mutex_lock(&m_act_lock); |
| 124 | if (m_thread_running) { |
| 125 | pthread_mutex_unlock(&m_act_lock); |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 126 | LOGERR("Another threaded action is already running -- not running %u actions starting with '%s'\n", |
| 127 | act->mActions.size(), act->mActions[0].mFunction.c_str()); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 128 | } else { |
| 129 | m_thread_running = true; |
| 130 | pthread_mutex_unlock(&m_act_lock); |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 131 | ThreadData *d = new ThreadData(this, act); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 132 | pthread_create(&m_thread, NULL, &ActionThread_work_wrapper, d); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | void ActionThread::run(void *data) |
| 137 | { |
| 138 | ThreadData *d = (ThreadData*)data; |
| 139 | GUIAction* act = d->act; |
| 140 | |
| 141 | std::vector<GUIAction::Action>::iterator it; |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 142 | for (it = act->mActions.begin(); it != act->mActions.end(); ++it) |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 143 | act->doAction(*it); |
| 144 | |
| 145 | pthread_mutex_lock(&m_act_lock); |
| 146 | m_thread_running = false; |
| 147 | pthread_mutex_unlock(&m_act_lock); |
| 148 | delete d; |
| 149 | } |
| 150 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 151 | GUIAction::GUIAction(xml_node<>* node) |
Vojtech Bocek | ede51c5 | 2014-02-07 23:58:09 +0100 | [diff] [blame] | 152 | : GUIObject(node) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 153 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 154 | xml_node<>* child; |
| 155 | xml_node<>* actions; |
| 156 | xml_attribute<>* attr; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 157 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 158 | if (!node) return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 159 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 160 | if (mf.empty()) { |
Vojtech Bocek | ecd8918 | 2015-01-15 16:28:54 +0100 | [diff] [blame] | 161 | #define ADD_ACTION(n) mf[#n] = &GUIAction::n |
| 162 | #define ADD_ACTION_EX(name, func) mf[name] = &GUIAction::func |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 163 | // These actions will be run in the caller's thread |
Vojtech Bocek | ecd8918 | 2015-01-15 16:28:54 +0100 | [diff] [blame] | 164 | ADD_ACTION(reboot); |
| 165 | ADD_ACTION(home); |
| 166 | ADD_ACTION(key); |
| 167 | ADD_ACTION(page); |
| 168 | ADD_ACTION(reload); |
| 169 | ADD_ACTION(readBackup); |
| 170 | ADD_ACTION(set); |
| 171 | ADD_ACTION(clear); |
| 172 | ADD_ACTION(mount); |
| 173 | ADD_ACTION(unmount); |
| 174 | ADD_ACTION_EX("umount", unmount); |
| 175 | ADD_ACTION(restoredefaultsettings); |
| 176 | ADD_ACTION(copylog); |
| 177 | ADD_ACTION(compute); |
| 178 | ADD_ACTION_EX("addsubtract", compute); |
| 179 | ADD_ACTION(setguitimezone); |
| 180 | ADD_ACTION(overlay); |
| 181 | ADD_ACTION(queuezip); |
| 182 | ADD_ACTION(cancelzip); |
| 183 | ADD_ACTION(queueclear); |
| 184 | ADD_ACTION(sleep); |
Matt Mower | 9a2a205 | 2016-05-31 21:31:22 -0500 | [diff] [blame] | 185 | ADD_ACTION(sleepcounter); |
Vojtech Bocek | ecd8918 | 2015-01-15 16:28:54 +0100 | [diff] [blame] | 186 | ADD_ACTION(appenddatetobackupname); |
| 187 | ADD_ACTION(generatebackupname); |
| 188 | ADD_ACTION(checkpartitionlist); |
| 189 | ADD_ACTION(getpartitiondetails); |
| 190 | ADD_ACTION(screenshot); |
| 191 | ADD_ACTION(setbrightness); |
| 192 | ADD_ACTION(fileexists); |
| 193 | ADD_ACTION(killterminal); |
| 194 | ADD_ACTION(checkbackupname); |
| 195 | ADD_ACTION(adbsideloadcancel); |
| 196 | ADD_ACTION(fixsu); |
| 197 | ADD_ACTION(startmtp); |
| 198 | ADD_ACTION(stopmtp); |
| 199 | ADD_ACTION(cancelbackup); |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 200 | ADD_ACTION(checkpartitionlifetimewrites); |
| 201 | ADD_ACTION(mountsystemtoggle); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 202 | ADD_ACTION(setlanguage); |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 203 | ADD_ACTION(checkforapp); |
Matt Mower | 9472ba1 | 2016-01-20 18:12:47 -0600 | [diff] [blame] | 204 | ADD_ACTION(togglebacklight); |
Mohd Faraz | 3c25ab3 | 2020-08-12 12:29:42 +0000 | [diff] [blame] | 205 | ADD_ACTION(changeterminal); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 206 | |
| 207 | // remember actions that run in the caller thread |
| 208 | for (mapFunc::const_iterator it = mf.begin(); it != mf.end(); ++it) |
| 209 | setActionsRunningInCallerThread.insert(it->first); |
| 210 | |
| 211 | // These actions will run in a separate thread |
Vojtech Bocek | ecd8918 | 2015-01-15 16:28:54 +0100 | [diff] [blame] | 212 | ADD_ACTION(flash); |
| 213 | ADD_ACTION(wipe); |
| 214 | ADD_ACTION(refreshsizes); |
| 215 | ADD_ACTION(nandroid); |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 216 | ADD_ACTION(fixcontexts); |
Vojtech Bocek | ecd8918 | 2015-01-15 16:28:54 +0100 | [diff] [blame] | 217 | ADD_ACTION(fixpermissions); |
| 218 | ADD_ACTION(dd); |
| 219 | ADD_ACTION(partitionsd); |
| 220 | ADD_ACTION(installhtcdumlock); |
| 221 | ADD_ACTION(htcdumlockrestoreboot); |
| 222 | ADD_ACTION(htcdumlockreflashrecovery); |
| 223 | ADD_ACTION(cmd); |
| 224 | ADD_ACTION(terminalcommand); |
| 225 | ADD_ACTION(reinjecttwrp); |
| 226 | ADD_ACTION(decrypt); |
| 227 | ADD_ACTION(adbsideload); |
| 228 | ADD_ACTION(openrecoveryscript); |
| 229 | ADD_ACTION(installsu); |
| 230 | ADD_ACTION(decrypt_backup); |
| 231 | ADD_ACTION(repair); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 232 | ADD_ACTION(resize); |
Vojtech Bocek | ecd8918 | 2015-01-15 16:28:54 +0100 | [diff] [blame] | 233 | ADD_ACTION(changefilesystem); |
| 234 | ADD_ACTION(flashimage); |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 235 | ADD_ACTION(twcmd); |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 236 | ADD_ACTION(setbootslot); |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 237 | ADD_ACTION(installapp); |
Ethan Yonker | 76bbd3a | 2019-05-10 10:50:04 -0500 | [diff] [blame] | 238 | ADD_ACTION(uninstalltwrpsystemapp); |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 239 | ADD_ACTION(repackimage); |
| 240 | ADD_ACTION(fixabrecoverybootloop); |
epicX | 98053c3 | 2021-01-04 13:01:31 +0530 | [diff] [blame] | 241 | ADD_ACTION(applycustomtwrpfolder); |
Captain Throwback | 3b55610 | 2021-02-12 19:32:36 -0500 | [diff] [blame] | 242 | #ifndef TW_EXCLUDE_NANO |
| 243 | ADD_ACTION(editfile); |
| 244 | #endif |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 245 | } |
| 246 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 247 | // First, get the action |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 248 | actions = FindNode(node, "actions"); |
| 249 | if (actions) child = FindNode(actions, "action"); |
| 250 | else child = FindNode(node, "action"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 251 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 252 | if (!child) return; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 253 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 254 | while (child) |
| 255 | { |
| 256 | Action action; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 257 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 258 | attr = child->first_attribute("function"); |
| 259 | if (!attr) return; |
Matt Mower | fb1c4ff | 2014-04-16 13:43:36 -0500 | [diff] [blame] | 260 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 261 | action.mFunction = attr->value(); |
| 262 | action.mArg = child->value(); |
| 263 | mActions.push_back(action); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 264 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 265 | child = child->next_sibling("action"); |
| 266 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 267 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 268 | // Now, let's get either the key or region |
Ethan Yonker | 21ff02a | 2015-02-18 14:35:00 -0600 | [diff] [blame] | 269 | child = FindNode(node, "touch"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 270 | if (child) |
| 271 | { |
| 272 | attr = child->first_attribute("key"); |
| 273 | if (attr) |
| 274 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 275 | std::vector<std::string> keys = TWFunc::Split_String(attr->value(), "+"); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 276 | for (size_t i = 0; i < keys.size(); ++i) |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 277 | { |
| 278 | const int key = getKeyByName(keys[i]); |
| 279 | mKeys[key] = false; |
| 280 | } |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 281 | } |
| 282 | else |
| 283 | { |
| 284 | attr = child->first_attribute("x"); |
| 285 | if (!attr) return; |
| 286 | mActionX = atol(attr->value()); |
| 287 | attr = child->first_attribute("y"); |
| 288 | if (!attr) return; |
| 289 | mActionY = atol(attr->value()); |
| 290 | attr = child->first_attribute("w"); |
| 291 | if (!attr) return; |
| 292 | mActionW = atol(attr->value()); |
| 293 | attr = child->first_attribute("h"); |
| 294 | if (!attr) return; |
| 295 | mActionH = atol(attr->value()); |
| 296 | } |
| 297 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 298 | } |
| 299 | |
Matt Mower | 25036b7 | 2016-06-24 12:30:18 -0500 | [diff] [blame] | 300 | int GUIAction::NotifyTouch(TOUCH_STATE state, int x __unused, int y __unused) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 301 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 302 | if (state == TOUCH_RELEASE) |
| 303 | doActions(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 304 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 305 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 308 | int GUIAction::NotifyKey(int key, bool down) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 309 | { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 310 | std::map<int, bool>::iterator itr = mKeys.find(key); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 311 | if (itr == mKeys.end()) |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 312 | return 1; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 313 | |
| 314 | bool prevState = itr->second; |
| 315 | itr->second = down; |
| 316 | |
| 317 | // If there is only one key for this action, wait for key up so it |
| 318 | // doesn't trigger with multi-key actions. |
| 319 | // Else, check if all buttons are pressed, then consume their release events |
| 320 | // so they don't trigger one-button actions and reset mKeys pressed status |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 321 | if (mKeys.size() == 1) { |
| 322 | if (!down && prevState) { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 323 | doActions(); |
that | d4725ca | 2016-01-19 00:15:21 +0100 | [diff] [blame] | 324 | return 0; |
| 325 | } |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 326 | } else if (down) { |
| 327 | for (itr = mKeys.begin(); itr != mKeys.end(); ++itr) { |
| 328 | if (!itr->second) |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 329 | return 1; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | // Passed, all req buttons are pressed, reset them and consume release events |
| 333 | HardwareKeyboard *kb = PageManager::GetHardwareKeyboard(); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 334 | for (itr = mKeys.begin(); itr != mKeys.end(); ++itr) { |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 335 | kb->ConsumeKeyRelease(itr->first); |
| 336 | itr->second = false; |
| 337 | } |
| 338 | |
| 339 | doActions(); |
that | d4725ca | 2016-01-19 00:15:21 +0100 | [diff] [blame] | 340 | return 0; |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 341 | } |
| 342 | |
that | d4725ca | 2016-01-19 00:15:21 +0100 | [diff] [blame] | 343 | return 1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 344 | } |
| 345 | |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 346 | int GUIAction::NotifyVarChange(const std::string& varName, const std::string& value) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 347 | { |
Vojtech Bocek | 0722056 | 2014-02-08 02:05:33 +0100 | [diff] [blame] | 348 | GUIObject::NotifyVarChange(varName, value); |
| 349 | |
Vojtech Bocek | 0b7fe50 | 2014-03-13 17:36:52 +0100 | [diff] [blame] | 350 | if (varName.empty() && !isConditionValid() && mKeys.empty() && !mActionW) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 351 | doActions(); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 352 | else if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue()) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 353 | doActions(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 354 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 355 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | void GUIAction::simulate_progress_bar(void) |
| 359 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 360 | gui_msg("simulating=Simulating actions..."); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 361 | for (int i = 0; i < 5; i++) |
| 362 | { |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 363 | if (PartitionManager.stop_backup.get_value()) { |
| 364 | DataManager::SetValue("tw_cancel_backup", 1); |
Matt Mower | 3c36697 | 2015-12-25 19:28:31 -0600 | [diff] [blame] | 365 | gui_msg("backup_cancel=Backup Cancelled"); |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 366 | DataManager::SetValue("ui_progress", 0); |
| 367 | PartitionManager.stop_backup.set_value(0); |
| 368 | return; |
| 369 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 370 | usleep(500000); |
| 371 | DataManager::SetValue("ui_progress", i * 20); |
| 372 | } |
| 373 | } |
| 374 | |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 375 | int GUIAction::flash_zip(std::string filename, int* wipe_cache) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 376 | { |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 377 | int ret_val = 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 378 | |
| 379 | DataManager::SetValue("ui_progress", 0); |
Chaosmaster | ab16437 | 2020-02-03 15:38:02 +0100 | [diff] [blame] | 380 | DataManager::SetValue("ui_portion_size", 0); |
| 381 | DataManager::SetValue("ui_portion_start", 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 382 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 383 | if (filename.empty()) |
| 384 | { |
| 385 | LOGERR("No file specified.\n"); |
| 386 | return -1; |
| 387 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 388 | |
Ethan Yonker | 9598c07 | 2016-01-15 21:54:34 -0600 | [diff] [blame] | 389 | if (!TWFunc::Path_Exists(filename)) { |
| 390 | if (!PartitionManager.Mount_By_Path(filename, true)) { |
| 391 | return -1; |
| 392 | } |
| 393 | if (!TWFunc::Path_Exists(filename)) { |
| 394 | gui_msg(Msg(msg::kError, "unable_to_locate=Unable to locate {1}.")(filename)); |
| 395 | return -1; |
| 396 | } |
| 397 | } |
Dees_Troy | 657c309 | 2012-09-10 20:32:10 -0400 | [diff] [blame] | 398 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 399 | if (simulate) { |
| 400 | simulate_progress_bar(); |
| 401 | } else { |
epicX | 40b7f7a | 2021-03-20 21:58:17 +0530 | [diff] [blame] | 402 | ret_val = TWinstall_zip(filename.c_str(), wipe_cache, (bool) !DataManager::GetIntValue(TW_SKIP_DIGEST_CHECK_ZIP_VAR)); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 403 | |
| 404 | // Now, check if we need to ensure TWRP remains installed... |
| 405 | struct stat st; |
| 406 | if (stat("/sbin/installTwrp", &st) == 0) |
| 407 | { |
| 408 | DataManager::SetValue("tw_operation", "Configuring TWRP"); |
| 409 | DataManager::SetValue("tw_partition", ""); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 410 | gui_msg("config_twrp=Configuring TWRP..."); |
Vojtech Bocek | 0553420 | 2013-09-11 08:11:56 +0200 | [diff] [blame] | 411 | if (TWFunc::Exec_Cmd("/sbin/installTwrp reinstall") < 0) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 412 | { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 413 | gui_msg("config_twrp_err=Unable to configure TWRP with this kernel."); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 418 | // Done |
| 419 | DataManager::SetValue("ui_progress", 100); |
| 420 | DataManager::SetValue("ui_progress", 0); |
Chaosmaster | ab16437 | 2020-02-03 15:38:02 +0100 | [diff] [blame] | 421 | DataManager::SetValue("ui_portion_size", 0); |
| 422 | DataManager::SetValue("ui_portion_start", 0); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 423 | return ret_val; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 424 | } |
| 425 | |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 426 | GUIAction::ThreadType GUIAction::getThreadType(const GUIAction::Action& action) |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 427 | { |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 428 | string func = gui_parse_text(action.mFunction); |
| 429 | bool needsThread = setActionsRunningInCallerThread.find(func) == setActionsRunningInCallerThread.end(); |
| 430 | if (needsThread) { |
| 431 | if (func == "cancelbackup") |
| 432 | return THREAD_CANCEL; |
| 433 | else |
| 434 | return THREAD_ACTION; |
| 435 | } |
| 436 | return THREAD_NONE; |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 437 | } |
| 438 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 439 | int GUIAction::doActions() |
| 440 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 441 | if (mActions.size() < 1) |
| 442 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 443 | |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 444 | // Determine in which thread to run the actions. |
| 445 | // Do it for all actions at once before starting, so that we can cancel the whole batch if the thread is already busy. |
| 446 | ThreadType threadType = THREAD_NONE; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 447 | std::vector<Action>::iterator it; |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 448 | for (it = mActions.begin(); it != mActions.end(); ++it) { |
| 449 | ThreadType tt = getThreadType(*it); |
| 450 | if (tt == THREAD_NONE) |
| 451 | continue; |
| 452 | if (threadType == THREAD_NONE) |
| 453 | threadType = tt; |
| 454 | else if (threadType != tt) { |
| 455 | LOGERR("Can't mix normal and cancel actions in the same list.\n" |
| 456 | "Running the whole batch in the cancel thread.\n"); |
| 457 | threadType = THREAD_CANCEL; |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 458 | break; |
| 459 | } |
that | 7d3b54f | 2015-01-09 22:52:51 +0100 | [diff] [blame] | 460 | } |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 461 | |
| 462 | // Now run the actions in the desired thread. |
| 463 | switch (threadType) { |
| 464 | case THREAD_ACTION: |
| 465 | action_thread.threadActions(this); |
| 466 | break; |
| 467 | |
| 468 | case THREAD_CANCEL: |
| 469 | cancel_thread.threadActions(this); |
| 470 | break; |
| 471 | |
| 472 | default: { |
| 473 | // no iterators here because theme reloading might kill our object |
| 474 | const size_t cnt = mActions.size(); |
| 475 | for (size_t i = 0; i < cnt; ++i) |
| 476 | doAction(mActions[i]); |
| 477 | } |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 478 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 479 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 480 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 481 | } |
| 482 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 483 | int GUIAction::doAction(Action action) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 484 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 485 | DataManager::GetValue(TW_SIMULATE_ACTIONS, simulate); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 486 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 487 | std::string function = gui_parse_text(action.mFunction); |
| 488 | std::string arg = gui_parse_text(action.mArg); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 489 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 490 | // find function and execute it |
| 491 | mapFunc::const_iterator funcitr = mf.find(function); |
| 492 | if (funcitr != mf.end()) |
| 493 | return (this->*funcitr->second)(arg); |
| 494 | |
| 495 | LOGERR("Unknown action '%s'\n", function.c_str()); |
| 496 | return -1; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | void GUIAction::operation_start(const string operation_name) |
| 500 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 501 | 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] | 502 | time(&Start); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 503 | DataManager::SetValue(TW_ACTION_BUSY, 1); |
| 504 | DataManager::SetValue("ui_progress", 0); |
Chaosmaster | ab16437 | 2020-02-03 15:38:02 +0100 | [diff] [blame] | 505 | DataManager::SetValue("ui_portion_size", 0); |
| 506 | DataManager::SetValue("ui_portion_start", 0); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 507 | DataManager::SetValue("tw_operation", operation_name); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 508 | DataManager::SetValue("tw_operation_state", 0); |
Ethan Yonker | d83c9ea | 2015-01-02 15:22:31 -0600 | [diff] [blame] | 509 | DataManager::SetValue("tw_operation_status", 0); |
bigbiff | 349ea55 | 2020-06-19 16:07:38 -0400 | [diff] [blame] | 510 | bool tw_ab_device = TWFunc::get_log_dir() != CACHE_LOGS_DIR; |
bigbiff bigbiff | 19874f1 | 2019-01-08 20:06:57 -0500 | [diff] [blame] | 511 | DataManager::SetValue("tw_ab_device", tw_ab_device); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 512 | } |
| 513 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 514 | void GUIAction::operation_end(const int operation_status) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 515 | { |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 516 | time_t Stop; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 517 | int simulate_fail; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 518 | DataManager::SetValue("ui_progress", 100); |
| 519 | if (simulate) { |
| 520 | DataManager::GetValue(TW_SIMULATE_FAIL, simulate_fail); |
| 521 | if (simulate_fail != 0) |
| 522 | DataManager::SetValue("tw_operation_status", 1); |
| 523 | else |
| 524 | DataManager::SetValue("tw_operation_status", 0); |
| 525 | } else { |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 526 | if (operation_status != 0) { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 527 | DataManager::SetValue("tw_operation_status", 1); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 528 | } |
| 529 | else { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 530 | DataManager::SetValue("tw_operation_status", 0); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 531 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 532 | } |
| 533 | DataManager::SetValue("tw_operation_state", 1); |
| 534 | DataManager::SetValue(TW_ACTION_BUSY, 0); |
bigbiff bigbiff | 8a68c31 | 2013-02-10 14:28:30 -0500 | [diff] [blame] | 535 | blankTimer.resetTimerAndUnblank(); |
LuK1337 | 62326f4 | 2015-09-30 19:57:46 +0200 | [diff] [blame] | 536 | property_set("twrp.action_complete", "1"); |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 537 | time(&Stop); |
bigbiff bigbiff | 3ed778a | 2019-03-12 19:28:31 -0400 | [diff] [blame] | 538 | |
| 539 | #ifndef TW_NO_HAPTICS |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 540 | if ((int) difftime(Stop, Start) > 10) |
Ethan Yonker | 03db326 | 2014-02-05 08:02:06 -0600 | [diff] [blame] | 541 | DataManager::Vibrate("tw_action_vibrate"); |
bigbiff bigbiff | 3ed778a | 2019-03-12 19:28:31 -0400 | [diff] [blame] | 542 | #endif |
| 543 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 544 | LOGINFO("operation_end - status=%d\n", operation_status); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 545 | } |
| 546 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 547 | int GUIAction::reboot(std::string arg) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 548 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 549 | sync(); |
| 550 | DataManager::SetValue("tw_gui_done", 1); |
| 551 | DataManager::SetValue("tw_reboot_arg", arg); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 552 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 553 | return 0; |
| 554 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 555 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 556 | int GUIAction::home(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 557 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 558 | gui_changePage("main"); |
| 559 | return 0; |
| 560 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 561 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 562 | int GUIAction::key(std::string arg) |
| 563 | { |
| 564 | const int key = getKeyByName(arg); |
| 565 | PageManager::NotifyKey(key, true); |
| 566 | PageManager::NotifyKey(key, false); |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | int GUIAction::page(std::string arg) |
| 571 | { |
LuK1337 | 62326f4 | 2015-09-30 19:57:46 +0200 | [diff] [blame] | 572 | property_set("twrp.action_complete", "0"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 573 | std::string page_name = gui_parse_text(arg); |
| 574 | return gui_changePage(page_name); |
| 575 | } |
| 576 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 577 | int GUIAction::reload(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 578 | { |
Ethan Yonker | e0f1f3b | 2015-10-27 09:49:01 -0500 | [diff] [blame] | 579 | PageManager::RequestReload(); |
| 580 | // The actual reload is handled in pages.cpp in PageManager::RunReload() |
| 581 | // The reload will occur on the next Update or Render call and will |
| 582 | // be performed in the rendoer thread instead of the action thread |
| 583 | // to prevent crashing which could occur when we start deleting |
| 584 | // GUI resources in the action thread while we attempt to render |
| 585 | // with those same resources in another thread. |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 586 | return 0; |
| 587 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 588 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 589 | int GUIAction::readBackup(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 590 | { |
| 591 | string Restore_Name; |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 592 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 593 | DataManager::GetValue("tw_restore", Restore_Name); |
| 594 | PartitionManager.Set_Restore_Files(Restore_Name); |
| 595 | return 0; |
| 596 | } |
| 597 | |
| 598 | int GUIAction::set(std::string arg) |
| 599 | { |
| 600 | if (arg.find('=') != string::npos) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 601 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 602 | string varName = arg.substr(0, arg.find('=')); |
| 603 | string value = arg.substr(arg.find('=') + 1, string::npos); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 604 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 605 | DataManager::GetValue(value, value); |
| 606 | DataManager::SetValue(varName, value); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 607 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 608 | else |
| 609 | DataManager::SetValue(arg, "1"); |
| 610 | return 0; |
| 611 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 612 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 613 | int GUIAction::clear(std::string arg) |
| 614 | { |
| 615 | DataManager::SetValue(arg, "0"); |
| 616 | return 0; |
| 617 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 618 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 619 | int GUIAction::mount(std::string arg) |
| 620 | { |
| 621 | if (arg == "usb") { |
| 622 | DataManager::SetValue(TW_ACTION_BUSY, 1); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 623 | if (!simulate) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 624 | PartitionManager.usb_storage_enable(); |
| 625 | else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 626 | gui_msg("simulating=Simulating actions..."); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 627 | } else if (!simulate) { |
| 628 | PartitionManager.Mount_By_Path(arg, true); |
| 629 | PartitionManager.Add_MTP_Storage(arg); |
| 630 | } else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 631 | gui_msg("simulating=Simulating actions..."); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | int GUIAction::unmount(std::string arg) |
| 636 | { |
| 637 | if (arg == "usb") { |
| 638 | if (!simulate) |
| 639 | PartitionManager.usb_storage_disable(); |
| 640 | else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 641 | gui_msg("simulating=Simulating actions..."); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 642 | DataManager::SetValue(TW_ACTION_BUSY, 0); |
| 643 | } else if (!simulate) { |
| 644 | PartitionManager.UnMount_By_Path(arg, true); |
| 645 | } else |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 646 | gui_msg("simulating=Simulating actions..."); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 647 | return 0; |
| 648 | } |
| 649 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 650 | int GUIAction::restoredefaultsettings(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 651 | { |
| 652 | operation_start("Restore Defaults"); |
| 653 | 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] | 654 | gui_msg("simulating=Simulating actions..."); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 655 | else { |
| 656 | DataManager::ResetDefaults(); |
| 657 | PartitionManager.Update_System_Details(); |
| 658 | PartitionManager.Mount_Current_Storage(true); |
| 659 | } |
| 660 | operation_end(0); |
| 661 | return 0; |
| 662 | } |
| 663 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 664 | int GUIAction::copylog(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 665 | { |
| 666 | operation_start("Copy Log"); |
| 667 | if (!simulate) |
| 668 | { |
bigbiff bigbiff | bad332a | 2016-07-29 21:18:13 -0400 | [diff] [blame] | 669 | string dst, curr_storage; |
| 670 | int copy_kernel_log = 0; |
| 671 | |
| 672 | DataManager::GetValue("tw_include_kernel_log", copy_kernel_log); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 673 | PartitionManager.Mount_Current_Storage(true); |
bigbiff bigbiff | bad332a | 2016-07-29 21:18:13 -0400 | [diff] [blame] | 674 | curr_storage = DataManager::GetCurrentStoragePath(); |
| 675 | dst = curr_storage + "/recovery.log"; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 676 | TWFunc::copy_file("/tmp/recovery.log", dst.c_str(), 0755); |
| 677 | tw_set_default_metadata(dst.c_str()); |
bigbiff bigbiff | bad332a | 2016-07-29 21:18:13 -0400 | [diff] [blame] | 678 | if (copy_kernel_log) |
| 679 | TWFunc::copy_kernel_log(curr_storage); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 680 | sync(); |
bigbiff bigbiff | bad332a | 2016-07-29 21:18:13 -0400 | [diff] [blame] | 681 | gui_msg(Msg("copy_log=Copied recovery log to {1}")(dst)); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 682 | } else |
| 683 | simulate_progress_bar(); |
| 684 | operation_end(0); |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | |
| 689 | int GUIAction::compute(std::string arg) |
| 690 | { |
| 691 | if (arg.find("+") != string::npos) |
| 692 | { |
| 693 | string varName = arg.substr(0, arg.find('+')); |
| 694 | string string_to_add = arg.substr(arg.find('+') + 1, string::npos); |
| 695 | int amount_to_add = atoi(string_to_add.c_str()); |
| 696 | int value; |
| 697 | |
| 698 | DataManager::GetValue(varName, value); |
| 699 | DataManager::SetValue(varName, value + amount_to_add); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 700 | return 0; |
| 701 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 702 | if (arg.find("-") != string::npos) |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 703 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 704 | string varName = arg.substr(0, arg.find('-')); |
| 705 | string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos); |
| 706 | int amount_to_subtract = atoi(string_to_subtract.c_str()); |
| 707 | int value; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 708 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 709 | DataManager::GetValue(varName, value); |
| 710 | value -= amount_to_subtract; |
| 711 | if (value <= 0) |
| 712 | value = 0; |
| 713 | DataManager::SetValue(varName, value); |
| 714 | return 0; |
| 715 | } |
| 716 | if (arg.find("*") != string::npos) |
| 717 | { |
| 718 | string varName = arg.substr(0, arg.find('*')); |
| 719 | string multiply_by_str = gui_parse_text(arg.substr(arg.find('*') + 1, string::npos)); |
| 720 | int multiply_by = atoi(multiply_by_str.c_str()); |
| 721 | int value; |
| 722 | |
| 723 | DataManager::GetValue(varName, value); |
| 724 | DataManager::SetValue(varName, value*multiply_by); |
| 725 | return 0; |
| 726 | } |
| 727 | if (arg.find("/") != string::npos) |
| 728 | { |
| 729 | string varName = arg.substr(0, arg.find('/')); |
| 730 | string divide_by_str = gui_parse_text(arg.substr(arg.find('/') + 1, string::npos)); |
| 731 | int divide_by = atoi(divide_by_str.c_str()); |
| 732 | int value; |
| 733 | |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 734 | if (divide_by != 0) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 735 | { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 736 | DataManager::GetValue(varName, value); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 737 | DataManager::SetValue(varName, value/divide_by); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 738 | } |
| 739 | return 0; |
| 740 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 741 | LOGERR("Unable to perform compute '%s'\n", arg.c_str()); |
| 742 | return -1; |
| 743 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 744 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 745 | int GUIAction::setguitimezone(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 746 | { |
| 747 | string SelectedZone; |
| 748 | DataManager::GetValue(TW_TIME_ZONE_GUISEL, SelectedZone); // read the selected time zone into SelectedZone |
| 749 | string Zone = SelectedZone.substr(0, SelectedZone.find(';')); // parse to get time zone |
| 750 | string DSTZone = SelectedZone.substr(SelectedZone.find(';') + 1, string::npos); // parse to get DST component |
| 751 | |
| 752 | int dst; |
| 753 | DataManager::GetValue(TW_TIME_ZONE_GUIDST, dst); // check wether user chose to use DST |
| 754 | |
| 755 | string offset; |
| 756 | DataManager::GetValue(TW_TIME_ZONE_GUIOFFSET, offset); // pull in offset |
| 757 | |
| 758 | string NewTimeZone = Zone; |
| 759 | if (offset != "0") |
| 760 | NewTimeZone += ":" + offset; |
| 761 | |
| 762 | if (dst != 0) |
| 763 | NewTimeZone += DSTZone; |
| 764 | |
| 765 | DataManager::SetValue(TW_TIME_ZONE_VAR, NewTimeZone); |
| 766 | DataManager::update_tz_environment_variables(); |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | int GUIAction::overlay(std::string arg) |
| 771 | { |
| 772 | return gui_changeOverlay(arg); |
| 773 | } |
| 774 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 775 | int GUIAction::queuezip(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 776 | { |
| 777 | if (zip_queue_index >= 10) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 778 | gui_msg("max_queue=Maximum zip queue reached!"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 779 | return 0; |
| 780 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 781 | DataManager::GetValue("tw_filename", zip_queue[zip_queue_index]); |
| 782 | if (strlen(zip_queue[zip_queue_index].c_str()) > 0) { |
| 783 | zip_queue_index++; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 784 | DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 785 | } |
| 786 | return 0; |
| 787 | } |
| 788 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 789 | int GUIAction::cancelzip(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 790 | { |
| 791 | if (zip_queue_index <= 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 792 | gui_msg("min_queue=Minimum zip queue reached!"); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 793 | return 0; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 794 | } else { |
| 795 | zip_queue_index--; |
| 796 | DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 797 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 798 | return 0; |
| 799 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 800 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 801 | int GUIAction::queueclear(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 802 | { |
| 803 | zip_queue_index = 0; |
| 804 | DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); |
| 805 | return 0; |
| 806 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 807 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 808 | int GUIAction::sleep(std::string arg) |
| 809 | { |
| 810 | operation_start("Sleep"); |
| 811 | usleep(atoi(arg.c_str())); |
| 812 | operation_end(0); |
| 813 | return 0; |
| 814 | } |
Dees Troy | b21cc64 | 2013-09-10 17:36:41 +0000 | [diff] [blame] | 815 | |
Matt Mower | 9a2a205 | 2016-05-31 21:31:22 -0500 | [diff] [blame] | 816 | int GUIAction::sleepcounter(std::string arg) |
| 817 | { |
| 818 | operation_start("SleepCounter"); |
| 819 | // Ensure user notices countdown in case it needs to be cancelled |
| 820 | blankTimer.resetTimerAndUnblank(); |
| 821 | int total = atoi(arg.c_str()); |
| 822 | for (int t = total; t > 0; t--) { |
| 823 | int progress = (int)(((float)(total-t)/(float)total)*100.0); |
| 824 | DataManager::SetValue("ui_progress", progress); |
| 825 | ::sleep(1); |
| 826 | DataManager::SetValue("tw_sleep", t-1); |
| 827 | } |
| 828 | DataManager::SetValue("ui_progress", 100); |
| 829 | operation_end(0); |
| 830 | return 0; |
| 831 | } |
| 832 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 833 | int GUIAction::appenddatetobackupname(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 834 | { |
| 835 | operation_start("AppendDateToBackupName"); |
| 836 | string Backup_Name; |
| 837 | DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); |
| 838 | Backup_Name += TWFunc::Get_Current_Date(); |
| 839 | if (Backup_Name.size() > MAX_BACKUP_NAME_LEN) |
| 840 | Backup_Name.resize(MAX_BACKUP_NAME_LEN); |
| 841 | DataManager::SetValue(TW_BACKUP_NAME, Backup_Name); |
Matt Mower | 76b8afc | 2016-06-24 12:04:27 -0500 | [diff] [blame] | 842 | PageManager::NotifyKey(KEY_END, true); |
| 843 | PageManager::NotifyKey(KEY_END, false); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 844 | operation_end(0); |
| 845 | return 0; |
| 846 | } |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 847 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 848 | int GUIAction::generatebackupname(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 849 | { |
| 850 | operation_start("GenerateBackupName"); |
| 851 | TWFunc::Auto_Generate_Backup_Name(); |
| 852 | operation_end(0); |
| 853 | return 0; |
| 854 | } |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 855 | |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 856 | int GUIAction::checkpartitionlist(std::string arg) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 857 | { |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 858 | string List, part_path; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 859 | int count = 0; |
Ethan Yonker | 87c7bac | 2014-05-25 21:41:08 -0500 | [diff] [blame] | 860 | |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 861 | if (arg.empty()) |
| 862 | arg = "tw_wipe_list"; |
| 863 | DataManager::GetValue(arg, List); |
| 864 | LOGINFO("checkpartitionlist list '%s'\n", List.c_str()); |
| 865 | if (!List.empty()) { |
| 866 | size_t start_pos = 0, end_pos = List.find(";", start_pos); |
| 867 | while (end_pos != string::npos && start_pos < List.size()) { |
| 868 | part_path = List.substr(start_pos, end_pos - start_pos); |
| 869 | LOGINFO("checkpartitionlist part_path '%s'\n", part_path.c_str()); |
| 870 | if (part_path == "/and-sec" || part_path == "DALVIK" || part_path == "INTERNAL") { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 871 | // Do nothing |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 872 | } else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 873 | count++; |
| 874 | } |
| 875 | start_pos = end_pos + 1; |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 876 | end_pos = List.find(";", start_pos); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 877 | } |
| 878 | DataManager::SetValue("tw_check_partition_list", count); |
| 879 | } else { |
| 880 | DataManager::SetValue("tw_check_partition_list", 0); |
| 881 | } |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 882 | return 0; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 883 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 884 | |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 885 | int GUIAction::getpartitiondetails(std::string arg) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 886 | { |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 887 | string List, part_path; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 888 | |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 889 | if (arg.empty()) |
| 890 | arg = "tw_wipe_list"; |
| 891 | DataManager::GetValue(arg, List); |
| 892 | LOGINFO("getpartitiondetails list '%s'\n", List.c_str()); |
| 893 | if (!List.empty()) { |
| 894 | size_t start_pos = 0, end_pos = List.find(";", start_pos); |
| 895 | part_path = List; |
| 896 | while (end_pos != string::npos && start_pos < List.size()) { |
| 897 | part_path = List.substr(start_pos, end_pos - start_pos); |
| 898 | LOGINFO("getpartitiondetails part_path '%s'\n", part_path.c_str()); |
| 899 | if (part_path == "/and-sec" || part_path == "DALVIK" || part_path == "INTERNAL") { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 900 | // Do nothing |
| 901 | } else { |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 902 | DataManager::SetValue("tw_partition_path", part_path); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 903 | break; |
| 904 | } |
| 905 | start_pos = end_pos + 1; |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 906 | end_pos = List.find(";", start_pos); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 907 | } |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 908 | if (!part_path.empty()) { |
| 909 | TWPartition* Part = PartitionManager.Find_Partition_By_Path(part_path); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 910 | if (Part) { |
| 911 | unsigned long long mb = 1048576; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 912 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 913 | DataManager::SetValue("tw_partition_name", Part->Display_Name); |
| 914 | DataManager::SetValue("tw_partition_mount_point", Part->Mount_Point); |
| 915 | DataManager::SetValue("tw_partition_file_system", Part->Current_File_System); |
| 916 | DataManager::SetValue("tw_partition_size", Part->Size / mb); |
| 917 | DataManager::SetValue("tw_partition_used", Part->Used / mb); |
| 918 | DataManager::SetValue("tw_partition_free", Part->Free / mb); |
| 919 | DataManager::SetValue("tw_partition_backup_size", Part->Backup_Size / mb); |
| 920 | DataManager::SetValue("tw_partition_removable", Part->Removable); |
| 921 | DataManager::SetValue("tw_partition_is_present", Part->Is_Present); |
| 922 | |
| 923 | if (Part->Can_Repair()) |
| 924 | DataManager::SetValue("tw_partition_can_repair", 1); |
| 925 | else |
| 926 | DataManager::SetValue("tw_partition_can_repair", 0); |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 927 | if (Part->Can_Resize()) |
| 928 | DataManager::SetValue("tw_partition_can_resize", 1); |
| 929 | else |
| 930 | DataManager::SetValue("tw_partition_can_resize", 0); |
Matt Mower | 18794c8 | 2015-11-11 16:22:45 -0600 | [diff] [blame] | 931 | if (TWFunc::Path_Exists("/sbin/mkfs.fat")) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 932 | DataManager::SetValue("tw_partition_vfat", 1); |
| 933 | else |
| 934 | DataManager::SetValue("tw_partition_vfat", 0); |
Matt Mower | 80f7b36 | 2015-12-12 15:38:01 -0600 | [diff] [blame] | 935 | if (TWFunc::Path_Exists("/sbin/mkexfatfs")) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 936 | DataManager::SetValue("tw_partition_exfat", 1); |
| 937 | else |
| 938 | DataManager::SetValue("tw_partition_exfat", 0); |
| 939 | if (TWFunc::Path_Exists("/sbin/mkfs.f2fs")) |
| 940 | DataManager::SetValue("tw_partition_f2fs", 1); |
| 941 | else |
| 942 | DataManager::SetValue("tw_partition_f2fs", 0); |
| 943 | if (TWFunc::Path_Exists("/sbin/mke2fs")) |
| 944 | DataManager::SetValue("tw_partition_ext", 1); |
| 945 | else |
| 946 | DataManager::SetValue("tw_partition_ext", 0); |
| 947 | return 0; |
| 948 | } else { |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 949 | LOGERR("Unable to locate partition: '%s'\n", part_path.c_str()); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | } |
| 953 | DataManager::SetValue("tw_partition_name", ""); |
| 954 | DataManager::SetValue("tw_partition_file_system", ""); |
Ethan Yonker | 483e9f4 | 2016-01-11 22:21:18 -0600 | [diff] [blame] | 955 | // Set this to 0 to prevent trying to partition this device, just in case |
| 956 | DataManager::SetValue("tw_partition_removable", 0); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 957 | return 0; |
| 958 | } |
| 959 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 960 | int GUIAction::screenshot(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 961 | { |
| 962 | time_t tm; |
| 963 | char path[256]; |
| 964 | int path_len; |
Matt Mower | 0c88b84 | 2017-01-15 16:00:49 -0600 | [diff] [blame] | 965 | uid_t uid = AID_MEDIA_RW; |
| 966 | gid_t gid = AID_MEDIA_RW; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 967 | |
| 968 | const std::string storage = DataManager::GetCurrentStoragePath(); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 969 | if (PartitionManager.Is_Mounted_By_Path(storage)) { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 970 | snprintf(path, sizeof(path), "%s/Pictures/Screenshots/", storage.c_str()); |
| 971 | } else { |
| 972 | strcpy(path, "/tmp/"); |
| 973 | } |
| 974 | |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 975 | if (!TWFunc::Create_Dir_Recursive(path, 0775, uid, gid)) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 976 | return 0; |
| 977 | |
| 978 | tm = time(NULL); |
| 979 | path_len = strlen(path); |
| 980 | |
| 981 | // Screenshot_2014-01-01-18-21-38.png |
| 982 | strftime(path+path_len, sizeof(path)-path_len, "Screenshot_%Y-%m-%d-%H-%M-%S.png", localtime(&tm)); |
| 983 | |
| 984 | int res = gr_save_screenshot(path); |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 985 | if (res == 0) { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 986 | chmod(path, 0666); |
| 987 | chown(path, uid, gid); |
| 988 | |
that | 677b13f | 2015-12-26 23:57:31 +0100 | [diff] [blame] | 989 | gui_msg(Msg("screenshot_saved=Screenshot was saved to {1}")(path)); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 990 | |
VDavid003 | 2034a41 | 2019-10-18 22:43:20 +0200 | [diff] [blame] | 991 | // blink to notify that the screenshot was taken |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 992 | gr_color(255, 255, 255, 255); |
| 993 | gr_fill(0, 0, gr_fb_width(), gr_fb_height()); |
| 994 | gr_flip(); |
| 995 | gui_forceRender(); |
| 996 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 997 | gui_err("screenshot_err=Failed to take a screenshot!"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 998 | } |
| 999 | return 0; |
| 1000 | } |
| 1001 | |
| 1002 | int GUIAction::setbrightness(std::string arg) |
| 1003 | { |
| 1004 | return TWFunc::Set_Brightness(arg); |
| 1005 | } |
| 1006 | |
| 1007 | int GUIAction::fileexists(std::string arg) |
| 1008 | { |
| 1009 | struct stat st; |
| 1010 | string newpath = arg + "/."; |
| 1011 | |
| 1012 | operation_start("FileExists"); |
| 1013 | if (stat(arg.c_str(), &st) == 0 || stat(newpath.c_str(), &st) == 0) |
| 1014 | operation_end(0); |
| 1015 | else |
| 1016 | operation_end(1); |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1020 | void GUIAction::reinject_after_flash() |
| 1021 | { |
| 1022 | 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] | 1023 | gui_msg("injecttwrp=Injecting TWRP into boot image..."); |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1024 | if (simulate) { |
| 1025 | simulate_progress_bar(); |
| 1026 | } else { |
| 1027 | TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot"); |
| 1028 | if (Boot == NULL || Boot->Current_File_System != "emmc") |
| 1029 | TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash"); |
| 1030 | else { |
| 1031 | string injectcmd = "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + Boot->Actual_Block_Device; |
| 1032 | TWFunc::Exec_Cmd(injectcmd); |
| 1033 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1034 | gui_msg("done=Done."); |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | } |
| 1038 | |
mauronofrio | 0ff5984 | 2019-10-26 19:47:55 +0200 | [diff] [blame] | 1039 | int GUIAction::ozip_decrypt(string zip_path) |
| 1040 | { |
| 1041 | if (!TWFunc::Path_Exists("/sbin/ozip_decrypt")) { |
| 1042 | return 1; |
| 1043 | } |
| 1044 | gui_msg("ozip_decrypt_decryption=Starting Ozip Decryption..."); |
| 1045 | TWFunc::Exec_Cmd("ozip_decrypt " + (string)TW_OZIP_DECRYPT_KEY + " '" + zip_path + "'"); |
| 1046 | gui_msg("ozip_decrypt_finish=Ozip Decryption Finished!"); |
| 1047 | return 0; |
| 1048 | } |
| 1049 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1050 | int GUIAction::flash(std::string arg) |
| 1051 | { |
| 1052 | int i, ret_val = 0, wipe_cache = 0; |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 1053 | // We're going to jump to this page first, like a loading page |
| 1054 | gui_changePage(arg); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1055 | for (i=0; i<zip_queue_index; i++) { |
that | c7b631b | 2015-06-01 23:36:57 +0200 | [diff] [blame] | 1056 | string zip_path = zip_queue[i]; |
| 1057 | size_t slashpos = zip_path.find_last_of('/'); |
| 1058 | string zip_filename = (slashpos == string::npos) ? zip_path : zip_path.substr(slashpos + 1); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1059 | operation_start("Flashing"); |
mauronofrio | 0ff5984 | 2019-10-26 19:47:55 +0200 | [diff] [blame] | 1060 | if((zip_path.substr(zip_path.size() - 4, 4)) == "ozip") |
| 1061 | { |
| 1062 | if((ozip_decrypt(zip_path)) != 0) |
| 1063 | { |
| 1064 | LOGERR("Unable to find ozip_decrypt!"); |
| 1065 | break; |
| 1066 | } |
| 1067 | zip_filename = (zip_filename.substr(0, zip_filename.size() - 4)).append("zip"); |
| 1068 | zip_path = (zip_path.substr(0, zip_path.size() - 4)).append("zip"); |
| 1069 | if (!TWFunc::Path_Exists(zip_path)) { |
| 1070 | LOGERR("Unable to find decrypted zip"); |
| 1071 | break; |
| 1072 | } |
| 1073 | } |
that | c7b631b | 2015-06-01 23:36:57 +0200 | [diff] [blame] | 1074 | DataManager::SetValue("tw_filename", zip_path); |
| 1075 | DataManager::SetValue("tw_file", zip_filename); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1076 | DataManager::SetValue(TW_ZIP_INDEX, (i + 1)); |
| 1077 | |
| 1078 | TWFunc::SetPerformanceMode(true); |
that | c7b631b | 2015-06-01 23:36:57 +0200 | [diff] [blame] | 1079 | ret_val = flash_zip(zip_path, &wipe_cache); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1080 | TWFunc::SetPerformanceMode(false); |
| 1081 | if (ret_val != 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1082 | 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] | 1083 | ret_val = 1; |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 1084 | break; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | zip_queue_index = 0; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1088 | |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 1089 | if (wipe_cache) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1090 | 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] | 1091 | PartitionManager.Wipe_By_Path("/cache"); |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 1092 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1093 | |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1094 | reinject_after_flash(); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1095 | PartitionManager.Update_System_Details(); |
| 1096 | operation_end(ret_val); |
bigbiff | a869fc7 | 2016-03-01 19:40:36 -0500 | [diff] [blame] | 1097 | // This needs to be after the operation_end call so we change pages before we change variables that we display on the screen |
Ethan Yonker | 0d47eb5 | 2015-01-09 11:23:19 -0600 | [diff] [blame] | 1098 | DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1099 | return 0; |
| 1100 | } |
| 1101 | |
| 1102 | int GUIAction::wipe(std::string arg) |
| 1103 | { |
| 1104 | operation_start("Format"); |
| 1105 | DataManager::SetValue("tw_partition", arg); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1106 | int ret_val = false; |
| 1107 | |
| 1108 | if (simulate) { |
| 1109 | simulate_progress_bar(); |
| 1110 | } else { |
| 1111 | if (arg == "data") |
| 1112 | ret_val = PartitionManager.Factory_Reset(); |
| 1113 | else if (arg == "battery") |
| 1114 | ret_val = PartitionManager.Wipe_Battery_Stats(); |
| 1115 | else if (arg == "rotate") |
| 1116 | ret_val = PartitionManager.Wipe_Rotate_Data(); |
| 1117 | else if (arg == "dalvik") |
| 1118 | ret_val = PartitionManager.Wipe_Dalvik_Cache(); |
| 1119 | else if (arg == "DATAMEDIA") { |
| 1120 | ret_val = PartitionManager.Format_Data(); |
| 1121 | } else if (arg == "INTERNAL") { |
Matt Mower | 23d8aae | 2017-01-06 14:30:33 -0600 | [diff] [blame] | 1122 | int has_datamedia; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1123 | |
| 1124 | DataManager::GetValue(TW_HAS_DATA_MEDIA, has_datamedia); |
| 1125 | if (has_datamedia) { |
| 1126 | ret_val = PartitionManager.Wipe_Media_From_Data(); |
| 1127 | } else { |
| 1128 | ret_val = PartitionManager.Wipe_By_Path(DataManager::GetSettingsStoragePath()); |
| 1129 | } |
| 1130 | } else if (arg == "EXTERNAL") { |
| 1131 | string External_Path; |
| 1132 | |
| 1133 | DataManager::GetValue(TW_EXTERNAL_PATH, External_Path); |
| 1134 | ret_val = PartitionManager.Wipe_By_Path(External_Path); |
| 1135 | } else if (arg == "ANDROIDSECURE") { |
| 1136 | ret_val = PartitionManager.Wipe_Android_Secure(); |
| 1137 | } else if (arg == "LIST") { |
| 1138 | string Wipe_List, wipe_path; |
| 1139 | bool skip = false; |
| 1140 | ret_val = true; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1141 | |
| 1142 | DataManager::GetValue("tw_wipe_list", Wipe_List); |
| 1143 | LOGINFO("wipe list '%s'\n", Wipe_List.c_str()); |
| 1144 | if (!Wipe_List.empty()) { |
| 1145 | size_t start_pos = 0, end_pos = Wipe_List.find(";", start_pos); |
| 1146 | while (end_pos != string::npos && start_pos < Wipe_List.size()) { |
| 1147 | wipe_path = Wipe_List.substr(start_pos, end_pos - start_pos); |
| 1148 | LOGINFO("wipe_path '%s'\n", wipe_path.c_str()); |
| 1149 | if (wipe_path == "/and-sec") { |
| 1150 | if (!PartitionManager.Wipe_Android_Secure()) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1151 | gui_msg("and_sec_wipe_err=Unable to wipe android secure"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1152 | ret_val = false; |
| 1153 | break; |
| 1154 | } else { |
| 1155 | skip = true; |
| 1156 | } |
| 1157 | } else if (wipe_path == "DALVIK") { |
| 1158 | if (!PartitionManager.Wipe_Dalvik_Cache()) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1159 | gui_err("dalvik_wipe_err=Failed to wipe dalvik"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1160 | ret_val = false; |
| 1161 | break; |
| 1162 | } else { |
| 1163 | skip = true; |
| 1164 | } |
| 1165 | } else if (wipe_path == "INTERNAL") { |
| 1166 | if (!PartitionManager.Wipe_Media_From_Data()) { |
| 1167 | ret_val = false; |
| 1168 | break; |
| 1169 | } else { |
| 1170 | skip = true; |
Dees_Troy | a13d74f | 2013-03-24 08:54:55 -0500 | [diff] [blame] | 1171 | } |
| 1172 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1173 | if (!skip) { |
| 1174 | if (!PartitionManager.Wipe_By_Path(wipe_path)) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1175 | 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] | 1176 | ret_val = false; |
| 1177 | break; |
| 1178 | } else if (wipe_path == DataManager::GetSettingsStoragePath()) { |
| 1179 | arg = wipe_path; |
| 1180 | } |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1181 | } else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1182 | skip = false; |
Dees_Troy | 38bd760 | 2012-09-14 13:33:53 -0400 | [diff] [blame] | 1183 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1184 | start_pos = end_pos + 1; |
| 1185 | end_pos = Wipe_List.find(";", start_pos); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1186 | } |
| 1187 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1188 | } else |
| 1189 | ret_val = PartitionManager.Wipe_By_Path(arg); |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 1190 | #ifndef TW_OEM_BUILD |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1191 | if (arg == DataManager::GetSettingsStoragePath()) { |
| 1192 | // If we wiped the settings storage path, recreate the TWRP folder and dump the settings |
| 1193 | string Storage_Path = DataManager::GetSettingsStoragePath(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1194 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1195 | if (PartitionManager.Mount_By_Path(Storage_Path, true)) { |
| 1196 | LOGINFO("Making TWRP folder and saving settings.\n"); |
| 1197 | Storage_Path += "/TWRP"; |
| 1198 | mkdir(Storage_Path.c_str(), 0777); |
| 1199 | DataManager::Flush(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1200 | } else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1201 | LOGERR("Unable to recreate TWRP folder and save settings.\n"); |
| 1202 | } |
| 1203 | } |
| 1204 | #endif |
| 1205 | } |
| 1206 | PartitionManager.Update_System_Details(); |
| 1207 | if (ret_val) |
| 1208 | ret_val = 0; // 0 is success |
| 1209 | else |
| 1210 | ret_val = 1; // 1 is failure |
| 1211 | operation_end(ret_val); |
| 1212 | return 0; |
| 1213 | } |
Samer Diab (S.a.M.e.R_d) | 71e9b04 | 2014-01-07 20:18:47 +0000 | [diff] [blame] | 1214 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1215 | int GUIAction::refreshsizes(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1216 | { |
| 1217 | operation_start("Refreshing Sizes"); |
| 1218 | if (simulate) { |
| 1219 | simulate_progress_bar(); |
| 1220 | } else |
| 1221 | PartitionManager.Update_System_Details(); |
| 1222 | operation_end(0); |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | int GUIAction::nandroid(std::string arg) |
| 1227 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1228 | if (simulate) { |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 1229 | PartitionManager.stop_backup.set_value(0); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1230 | DataManager::SetValue("tw_partition", "Simulation"); |
| 1231 | simulate_progress_bar(); |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 1232 | operation_end(0); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1233 | } else { |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 1234 | operation_start("Nandroid"); |
| 1235 | int ret = 0; |
| 1236 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1237 | if (arg == "backup") { |
| 1238 | string Backup_Name; |
| 1239 | DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); |
Ethan Yonker | 4adc33e | 2016-01-22 16:07:11 -0600 | [diff] [blame] | 1240 | string auto_gen = gui_lookup("auto_generate", "(Auto Generate)"); |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 1241 | if (Backup_Name == auto_gen || Backup_Name == gui_lookup("curr_date", "(Current Date)") || Backup_Name == "0" || Backup_Name == "(" || PartitionManager.Check_Backup_Name(Backup_Name, true, true) == 0) { |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1242 | ret = PartitionManager.Run_Backup(false); |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 1243 | DataManager::SetValue("tw_encrypt_backup", 0); // reset value so we don't encrypt every subsequent backup |
| 1244 | if (!PartitionManager.stop_backup.get_value()) { |
| 1245 | if (ret == false) |
| 1246 | ret = 1; // 1 for failure |
| 1247 | else |
| 1248 | ret = 0; // 0 for success |
| 1249 | DataManager::SetValue("tw_cancel_backup", 0); |
| 1250 | } else { |
| 1251 | DataManager::SetValue("tw_cancel_backup", 1); |
| 1252 | gui_msg("backup_cancel=Backup Cancelled"); |
| 1253 | ret = 0; |
| 1254 | } |
bigbiff | ce8f83c | 2015-12-12 18:30:21 -0500 | [diff] [blame] | 1255 | } else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1256 | operation_end(1); |
| 1257 | return -1; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1258 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1259 | DataManager::SetValue(TW_BACKUP_NAME, auto_gen); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1260 | } else if (arg == "restore") { |
| 1261 | string Restore_Name; |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 1262 | int gui_adb_backup; |
| 1263 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1264 | DataManager::GetValue("tw_restore", Restore_Name); |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 1265 | DataManager::GetValue("tw_enable_adb_backup", gui_adb_backup); |
| 1266 | if (gui_adb_backup) { |
| 1267 | DataManager::SetValue("tw_operation_state", 1); |
| 1268 | if (TWFunc::stream_adb_backup(Restore_Name) == 0) |
| 1269 | ret = 0; // success |
| 1270 | else |
| 1271 | ret = 1; // failure |
| 1272 | DataManager::SetValue("tw_enable_adb_backup", 0); |
| 1273 | ret = 0; // assume success??? |
| 1274 | } else { |
| 1275 | if (PartitionManager.Run_Restore(Restore_Name)) |
| 1276 | ret = 0; // success |
| 1277 | else |
| 1278 | ret = 1; // failure |
| 1279 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1280 | } else { |
bigbiff bigbiff | 19fb79c | 2016-09-05 21:04:51 -0400 | [diff] [blame] | 1281 | operation_end(1); // invalid arg specified, fail |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 1282 | return -1; |
| 1283 | } |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 1284 | operation_end(ret); |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 1285 | return ret; |
| 1286 | } |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1290 | int GUIAction::cancelbackup(std::string arg __unused) { |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 1291 | if (simulate) { |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 1292 | PartitionManager.stop_backup.set_value(1); |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 1293 | } |
| 1294 | else { |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 1295 | int op_status = PartitionManager.Cancel_Backup(); |
| 1296 | if (op_status != 0) |
| 1297 | op_status = 1; // failure |
bigbiff | 7abc5fe | 2015-01-17 16:53:12 -0500 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | return 0; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1301 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1302 | |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 1303 | int GUIAction::fixcontexts(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1304 | { |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 1305 | int op_status = 0; |
| 1306 | |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 1307 | operation_start("Fix Contexts"); |
| 1308 | LOGINFO("fix contexts started!\n"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1309 | if (simulate) { |
| 1310 | simulate_progress_bar(); |
| 1311 | } else { |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 1312 | op_status = PartitionManager.Fix_Contexts(); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1313 | if (op_status != 0) |
| 1314 | op_status = 1; // failure |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1315 | } |
that | 73a5295 | 2015-01-28 23:07:34 +0100 | [diff] [blame] | 1316 | operation_end(op_status); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1317 | return 0; |
| 1318 | } |
| 1319 | |
Ethan Yonker | b5fab76 | 2016-01-28 14:03:33 -0600 | [diff] [blame] | 1320 | int GUIAction::fixpermissions(std::string arg) |
| 1321 | { |
| 1322 | return fixcontexts(arg); |
| 1323 | } |
| 1324 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1325 | int GUIAction::dd(std::string arg) |
| 1326 | { |
| 1327 | operation_start("imaging"); |
| 1328 | |
| 1329 | if (simulate) { |
| 1330 | simulate_progress_bar(); |
| 1331 | } else { |
| 1332 | string cmd = "dd " + arg; |
| 1333 | TWFunc::Exec_Cmd(cmd); |
| 1334 | } |
| 1335 | operation_end(0); |
| 1336 | return 0; |
| 1337 | } |
| 1338 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1339 | int GUIAction::partitionsd(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1340 | { |
| 1341 | operation_start("Partition SD Card"); |
| 1342 | int ret_val = 0; |
| 1343 | |
| 1344 | if (simulate) { |
| 1345 | simulate_progress_bar(); |
| 1346 | } else { |
| 1347 | int allow_partition; |
| 1348 | DataManager::GetValue(TW_ALLOW_PARTITION_SDCARD, allow_partition); |
| 1349 | if (allow_partition == 0) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1350 | 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] | 1351 | } else { |
| 1352 | if (!PartitionManager.Partition_SDCard()) |
| 1353 | ret_val = 1; // failed |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1354 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1355 | } |
| 1356 | operation_end(ret_val); |
| 1357 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1358 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1359 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1360 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1361 | int GUIAction::installhtcdumlock(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1362 | { |
| 1363 | operation_start("Install HTC Dumlock"); |
| 1364 | if (simulate) { |
| 1365 | simulate_progress_bar(); |
| 1366 | } else |
| 1367 | TWFunc::install_htc_dumlock(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1368 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1369 | operation_end(0); |
| 1370 | return 0; |
| 1371 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1372 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1373 | int GUIAction::htcdumlockrestoreboot(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1374 | { |
| 1375 | operation_start("HTC Dumlock Restore Boot"); |
| 1376 | if (simulate) { |
| 1377 | simulate_progress_bar(); |
| 1378 | } else |
| 1379 | TWFunc::htc_dumlock_restore_original_boot(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1380 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1381 | operation_end(0); |
| 1382 | return 0; |
| 1383 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1384 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1385 | int GUIAction::htcdumlockreflashrecovery(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1386 | { |
| 1387 | operation_start("HTC Dumlock Reflash Recovery"); |
| 1388 | if (simulate) { |
| 1389 | simulate_progress_bar(); |
| 1390 | } else |
| 1391 | TWFunc::htc_dumlock_reflash_recovery_to_boot(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1392 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1393 | operation_end(0); |
| 1394 | return 0; |
| 1395 | } |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1396 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1397 | int GUIAction::cmd(std::string arg) |
| 1398 | { |
| 1399 | int op_status = 0; |
| 1400 | |
| 1401 | operation_start("Command"); |
| 1402 | LOGINFO("Running command: '%s'\n", arg.c_str()); |
| 1403 | if (simulate) { |
| 1404 | simulate_progress_bar(); |
| 1405 | } else { |
| 1406 | op_status = TWFunc::Exec_Cmd(arg); |
| 1407 | if (op_status != 0) |
| 1408 | op_status = 1; |
| 1409 | } |
| 1410 | |
| 1411 | operation_end(op_status); |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | int GUIAction::terminalcommand(std::string arg) |
| 1416 | { |
| 1417 | int op_status = 0; |
| 1418 | string cmdpath, command; |
| 1419 | |
| 1420 | DataManager::GetValue("tw_terminal_location", cmdpath); |
| 1421 | operation_start("CommandOutput"); |
| 1422 | gui_print("%s # %s\n", cmdpath.c_str(), arg.c_str()); |
| 1423 | if (simulate) { |
| 1424 | simulate_progress_bar(); |
| 1425 | operation_end(op_status); |
Matt Mower | 5aa29ab | 2015-02-25 23:50:55 -0600 | [diff] [blame] | 1426 | } else if (arg == "exit") { |
| 1427 | LOGINFO("Exiting terminal\n"); |
| 1428 | operation_end(op_status); |
| 1429 | page("main"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1430 | } else { |
| 1431 | command = "cd \"" + cmdpath + "\" && " + arg + " 2>&1";; |
| 1432 | LOGINFO("Actual command is: '%s'\n", command.c_str()); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1433 | DataManager::SetValue("tw_terminal_state", 1); |
| 1434 | DataManager::SetValue("tw_background_thread_running", 1); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1435 | FILE* fp; |
| 1436 | char line[512]; |
| 1437 | |
| 1438 | fp = popen(command.c_str(), "r"); |
| 1439 | if (fp == NULL) { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1440 | LOGERR("Error opening command to run (%s).\n", strerror(errno)); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1441 | } else { |
Matt Mower | 23d8aae | 2017-01-06 14:30:33 -0600 | [diff] [blame] | 1442 | int fd = fileno(fp), has_data = 0, check = 0, keep_going = -1; |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1443 | struct timeval timeout; |
| 1444 | fd_set fdset; |
| 1445 | |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1446 | while (keep_going) |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1447 | { |
| 1448 | FD_ZERO(&fdset); |
| 1449 | FD_SET(fd, &fdset); |
| 1450 | timeout.tv_sec = 0; |
| 1451 | timeout.tv_usec = 400000; |
| 1452 | has_data = select(fd+1, &fdset, NULL, NULL, &timeout); |
| 1453 | if (has_data == 0) { |
| 1454 | // Timeout reached |
| 1455 | DataManager::GetValue("tw_terminal_state", check); |
| 1456 | if (check == 0) { |
| 1457 | keep_going = 0; |
| 1458 | } |
| 1459 | } else if (has_data < 0) { |
| 1460 | // End of execution |
| 1461 | keep_going = 0; |
| 1462 | } else { |
| 1463 | // Try to read output |
Matt Mower | a8a89d1 | 2016-12-30 18:10:37 -0600 | [diff] [blame] | 1464 | if (fgets(line, sizeof(line), fp) != NULL) |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1465 | gui_print("%s", line); // Display output |
| 1466 | else |
| 1467 | keep_going = 0; // Done executing |
| 1468 | } |
| 1469 | } |
| 1470 | fclose(fp); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1471 | } |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1472 | DataManager::SetValue("tw_operation_status", 0); |
| 1473 | DataManager::SetValue("tw_operation_state", 1); |
| 1474 | DataManager::SetValue("tw_terminal_state", 0); |
| 1475 | DataManager::SetValue("tw_background_thread_running", 0); |
| 1476 | DataManager::SetValue(TW_ACTION_BUSY, 0); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1477 | } |
| 1478 | return 0; |
| 1479 | } |
| 1480 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1481 | int GUIAction::killterminal(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1482 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1483 | LOGINFO("Sending kill command...\n"); |
| 1484 | operation_start("KillCommand"); |
| 1485 | DataManager::SetValue("tw_operation_status", 0); |
| 1486 | DataManager::SetValue("tw_operation_state", 1); |
| 1487 | DataManager::SetValue("tw_terminal_state", 0); |
| 1488 | DataManager::SetValue("tw_background_thread_running", 0); |
| 1489 | DataManager::SetValue(TW_ACTION_BUSY, 0); |
| 1490 | return 0; |
| 1491 | } |
| 1492 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1493 | int GUIAction::reinjecttwrp(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1494 | { |
| 1495 | int op_status = 0; |
| 1496 | operation_start("ReinjectTWRP"); |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1497 | gui_msg("injecttwrp=Injecting TWRP into boot image..."); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1498 | if (simulate) { |
| 1499 | simulate_progress_bar(); |
| 1500 | } else { |
| 1501 | 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] | 1502 | gui_msg("done=Done."); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | operation_end(op_status); |
| 1506 | return 0; |
| 1507 | } |
| 1508 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1509 | int GUIAction::checkbackupname(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1510 | { |
| 1511 | int op_status = 0; |
| 1512 | |
| 1513 | operation_start("CheckBackupName"); |
| 1514 | if (simulate) { |
| 1515 | simulate_progress_bar(); |
| 1516 | } else { |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 1517 | string Backup_Name; |
| 1518 | DataManager::GetValue(TW_BACKUP_NAME, Backup_Name); |
| 1519 | op_status = PartitionManager.Check_Backup_Name(Backup_Name, true, true); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1520 | if (op_status != 0) |
| 1521 | op_status = 1; |
| 1522 | } |
| 1523 | |
| 1524 | operation_end(op_status); |
| 1525 | return 0; |
| 1526 | } |
| 1527 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1528 | int GUIAction::decrypt(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1529 | { |
| 1530 | int op_status = 0; |
| 1531 | |
| 1532 | operation_start("Decrypt"); |
| 1533 | if (simulate) { |
| 1534 | simulate_progress_bar(); |
| 1535 | } else { |
| 1536 | string Password; |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 1537 | string userID; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1538 | DataManager::GetValue("tw_crypto_password", Password); |
Noah Jacobson | 5a79f67 | 2019-04-28 00:10:07 -0400 | [diff] [blame] | 1539 | |
| 1540 | if (DataManager::GetIntValue(TW_IS_FBE)) { // for FBE |
| 1541 | DataManager::GetValue("tw_crypto_user_id", userID); |
| 1542 | if (userID != "") { |
| 1543 | op_status = PartitionManager.Decrypt_Device(Password, atoi(userID.c_str())); |
| 1544 | if (userID != "0") { |
| 1545 | if (op_status != 0) |
| 1546 | op_status = 1; |
| 1547 | operation_end(op_status); |
| 1548 | return 0; |
| 1549 | } |
| 1550 | } else { |
| 1551 | LOGINFO("User ID not found\n"); |
| 1552 | op_status = 1; |
| 1553 | } |
| 1554 | ::sleep(1); |
| 1555 | } else { // for FDE |
| 1556 | op_status = PartitionManager.Decrypt_Device(Password); |
| 1557 | } |
| 1558 | |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1559 | if (op_status != 0) |
| 1560 | op_status = 1; |
| 1561 | else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1562 | DataManager::SetValue(TW_IS_ENCRYPTED, 0); |
| 1563 | |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 1564 | int has_datamedia; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1565 | |
Ethan Yonker | cf50da5 | 2015-01-12 21:59:07 -0600 | [diff] [blame] | 1566 | // Check for a custom theme and load it if exists |
| 1567 | DataManager::GetValue(TW_HAS_DATA_MEDIA, has_datamedia); |
| 1568 | if (has_datamedia != 0) { |
| 1569 | if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) { |
Ethan Yonker | d9ff3c5 | 2015-01-21 21:51:20 -0600 | [diff] [blame] | 1570 | 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] | 1571 | } else { |
| 1572 | LOGINFO("Got default contexts and file mode for storage files.\n"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1573 | } |
| 1574 | } |
Ethan Yonker | 66a1949 | 2015-12-10 10:19:45 -0600 | [diff] [blame] | 1575 | PartitionManager.Decrypt_Adopted(); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | operation_end(op_status); |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1583 | int GUIAction::adbsideload(std::string arg __unused) |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1584 | { |
| 1585 | operation_start("Sideload"); |
| 1586 | if (simulate) { |
| 1587 | simulate_progress_bar(); |
| 1588 | operation_end(0); |
| 1589 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1590 | gui_msg("start_sideload=Starting ADB sideload feature..."); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1591 | bool mtp_was_enabled = TWFunc::Toggle_MTP(false); |
| 1592 | |
| 1593 | // wait for the adb connection |
| 1594 | int ret = apply_from_adb("/", &sideload_child_pid); |
| 1595 | DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui now that the zip install is going to start |
| 1596 | |
| 1597 | if (ret != 0) { |
| 1598 | if (ret == -2) |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1599 | 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] | 1600 | ret = 1; // failure |
| 1601 | } else { |
| 1602 | int wipe_cache = 0; |
| 1603 | int wipe_dalvik = 0; |
| 1604 | DataManager::GetValue("tw_wipe_dalvik", wipe_dalvik); |
| 1605 | |
| 1606 | if (TWinstall_zip(FUSE_SIDELOAD_HOST_PATHNAME, &wipe_cache) == 0) { |
| 1607 | if (wipe_cache || DataManager::GetIntValue("tw_wipe_cache")) |
| 1608 | PartitionManager.Wipe_By_Path("/cache"); |
| 1609 | if (wipe_dalvik) |
| 1610 | PartitionManager.Wipe_Dalvik_Cache(); |
| 1611 | } else { |
| 1612 | ret = 1; // failure |
| 1613 | } |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1614 | } |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1615 | if (sideload_child_pid) { |
| 1616 | LOGINFO("Signaling child sideload process to exit.\n"); |
| 1617 | struct stat st; |
| 1618 | // Calling stat() on this magic filename signals the minadbd |
| 1619 | // subprocess to shut down. |
| 1620 | stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st); |
| 1621 | int status; |
| 1622 | LOGINFO("Waiting for child sideload process to exit.\n"); |
| 1623 | waitpid(sideload_child_pid, &status, 0); |
| 1624 | } |
Dees Troy | 28a85d2 | 2015-04-28 02:03:16 +0000 | [diff] [blame] | 1625 | property_set("ctl.start", "adbd"); |
that | c608548 | 2015-01-09 22:12:43 +0100 | [diff] [blame] | 1626 | TWFunc::Toggle_MTP(mtp_was_enabled); |
| 1627 | reinject_after_flash(); |
| 1628 | operation_end(ret); |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1629 | } |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1630 | return 0; |
| 1631 | } |
| 1632 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1633 | int GUIAction::adbsideloadcancel(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1634 | { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1635 | struct stat st; |
| 1636 | DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1637 | gui_msg("cancel_sideload=Cancelling ADB sideload..."); |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1638 | LOGINFO("Signaling child sideload process to exit.\n"); |
| 1639 | // Calling stat() on this magic filename signals the minadbd |
| 1640 | // subprocess to shut down. |
| 1641 | stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st); |
| 1642 | if (!sideload_child_pid) { |
| 1643 | LOGERR("Unable to get child ID\n"); |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1644 | return 0; |
| 1645 | } |
that | cc8ddca | 2015-01-03 01:59:36 +0100 | [diff] [blame] | 1646 | ::sleep(1); |
| 1647 | LOGINFO("Killing child sideload process.\n"); |
| 1648 | kill(sideload_child_pid, SIGTERM); |
| 1649 | int status; |
| 1650 | LOGINFO("Waiting for child sideload process to exit.\n"); |
| 1651 | waitpid(sideload_child_pid, &status, 0); |
| 1652 | sideload_child_pid = 0; |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1653 | DataManager::SetValue("tw_page_done", "1"); // For OpenRecoveryScript support |
| 1654 | return 0; |
| 1655 | } |
| 1656 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1657 | int GUIAction::openrecoveryscript(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1658 | { |
| 1659 | operation_start("OpenRecoveryScript"); |
| 1660 | if (simulate) { |
| 1661 | simulate_progress_bar(); |
Ethan Yonker | 24e7eb7 | 2015-01-03 16:13:06 -0600 | [diff] [blame] | 1662 | operation_end(0); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1663 | } else { |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 1664 | int op_status = OpenRecoveryScript::Run_OpenRecoveryScript_Action(); |
Ethan Yonker | e1abe61 | 2015-06-09 11:09:32 -0500 | [diff] [blame] | 1665 | operation_end(op_status); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1666 | } |
| 1667 | return 0; |
| 1668 | } |
| 1669 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1670 | int GUIAction::installsu(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1671 | { |
| 1672 | int op_status = 0; |
| 1673 | |
| 1674 | operation_start("Install SuperSU"); |
| 1675 | if (simulate) { |
| 1676 | simulate_progress_bar(); |
| 1677 | } else { |
Ethan Yonker | fa67cbf | 2018-07-20 12:22:33 -0500 | [diff] [blame] | 1678 | LOGERR("Installing SuperSU was deprecated from TWRP.\n"); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1679 | } |
| 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::fixsu(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("Fixing Superuser Permissions"); |
| 1690 | if (simulate) { |
| 1691 | simulate_progress_bar(); |
| 1692 | } else { |
| 1693 | LOGERR("Fixing su permissions was deprecated from TWRP.\n"); |
| 1694 | LOGERR("4.3+ ROMs with SELinux will always lose su perms.\n"); |
| 1695 | } |
| 1696 | |
| 1697 | operation_end(op_status); |
| 1698 | return 0; |
| 1699 | } |
| 1700 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1701 | int GUIAction::decrypt_backup(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1702 | { |
| 1703 | int op_status = 0; |
| 1704 | |
| 1705 | operation_start("Try Restore Decrypt"); |
| 1706 | if (simulate) { |
| 1707 | simulate_progress_bar(); |
| 1708 | } else { |
| 1709 | string Restore_Path, Filename, Password; |
| 1710 | DataManager::GetValue("tw_restore", Restore_Path); |
| 1711 | Restore_Path += "/"; |
| 1712 | DataManager::GetValue("tw_restore_password", Password); |
| 1713 | TWFunc::SetPerformanceMode(true); |
| 1714 | if (TWFunc::Try_Decrypting_Backup(Restore_Path, Password)) |
| 1715 | op_status = 0; // success |
| 1716 | else |
| 1717 | op_status = 1; // fail |
| 1718 | TWFunc::SetPerformanceMode(false); |
| 1719 | } |
| 1720 | |
| 1721 | operation_end(op_status); |
| 1722 | return 0; |
| 1723 | } |
| 1724 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1725 | int GUIAction::repair(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1726 | { |
| 1727 | int op_status = 0; |
| 1728 | |
| 1729 | operation_start("Repair Partition"); |
| 1730 | if (simulate) { |
| 1731 | simulate_progress_bar(); |
| 1732 | } else { |
| 1733 | string part_path; |
| 1734 | DataManager::GetValue("tw_partition_mount_point", part_path); |
| 1735 | if (PartitionManager.Repair_By_Path(part_path, true)) { |
| 1736 | op_status = 0; // success |
| 1737 | } else { |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1738 | op_status = 1; // fail |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | operation_end(op_status); |
| 1743 | return 0; |
| 1744 | } |
| 1745 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1746 | int GUIAction::resize(std::string arg __unused) |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1747 | { |
| 1748 | int op_status = 0; |
| 1749 | |
| 1750 | operation_start("Resize Partition"); |
| 1751 | if (simulate) { |
| 1752 | simulate_progress_bar(); |
| 1753 | } else { |
| 1754 | string part_path; |
| 1755 | DataManager::GetValue("tw_partition_mount_point", part_path); |
| 1756 | if (PartitionManager.Resize_By_Path(part_path, true)) { |
| 1757 | op_status = 0; // success |
| 1758 | } else { |
Ethan Yonker | a271915 | 2015-05-28 09:44:41 -0500 | [diff] [blame] | 1759 | op_status = 1; // fail |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | operation_end(op_status); |
| 1764 | return 0; |
| 1765 | } |
| 1766 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1767 | int GUIAction::changefilesystem(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1768 | { |
| 1769 | int op_status = 0; |
| 1770 | |
| 1771 | operation_start("Change File System"); |
| 1772 | if (simulate) { |
| 1773 | simulate_progress_bar(); |
| 1774 | } else { |
| 1775 | string part_path, file_system; |
| 1776 | DataManager::GetValue("tw_partition_mount_point", part_path); |
| 1777 | DataManager::GetValue("tw_action_new_file_system", file_system); |
| 1778 | if (PartitionManager.Wipe_By_Path(part_path, file_system)) { |
| 1779 | op_status = 0; // success |
| 1780 | } else { |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1781 | gui_err("change_fs_err=Error changing file system."); |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1782 | op_status = 1; // fail |
| 1783 | } |
| 1784 | } |
| 1785 | PartitionManager.Update_System_Details(); |
| 1786 | operation_end(op_status); |
| 1787 | return 0; |
| 1788 | } |
| 1789 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1790 | int GUIAction::startmtp(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1791 | { |
| 1792 | int op_status = 0; |
| 1793 | |
| 1794 | operation_start("Start MTP"); |
| 1795 | if (PartitionManager.Enable_MTP()) |
| 1796 | op_status = 0; // success |
| 1797 | else |
| 1798 | op_status = 1; // fail |
| 1799 | |
| 1800 | operation_end(op_status); |
| 1801 | return 0; |
| 1802 | } |
| 1803 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1804 | int GUIAction::stopmtp(std::string arg __unused) |
that | 3f7b1ac | 2014-12-30 11:30:13 +0100 | [diff] [blame] | 1805 | { |
| 1806 | int op_status = 0; |
| 1807 | |
| 1808 | operation_start("Stop MTP"); |
| 1809 | if (PartitionManager.Disable_MTP()) |
| 1810 | op_status = 0; // success |
| 1811 | else |
| 1812 | op_status = 1; // fail |
| 1813 | |
| 1814 | operation_end(op_status); |
| 1815 | return 0; |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1816 | } |
| 1817 | |
Ethan Yonker | d0514ba | 2015-10-22 14:17:47 -0500 | [diff] [blame] | 1818 | int GUIAction::flashimage(std::string arg __unused) |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 1819 | { |
| 1820 | int op_status = 0; |
epicX | b733737 | 2021-02-24 23:12:08 +0530 | [diff] [blame] | 1821 | bool flag = true; |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 1822 | |
| 1823 | operation_start("Flash Image"); |
Ethan Yonker | dcf2b67 | 2016-09-13 14:41:53 -0500 | [diff] [blame] | 1824 | string path, filename; |
| 1825 | DataManager::GetValue("tw_zip_location", path); |
| 1826 | DataManager::GetValue("tw_file", filename); |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 1827 | |
epicX | b733737 | 2021-02-24 23:12:08 +0530 | [diff] [blame] | 1828 | #ifdef AB_OTA_UPDATER |
| 1829 | string target = DataManager::GetStrValue("tw_flash_partition"); |
| 1830 | unsigned int pos = target.find_last_of(';'); |
| 1831 | string mount_point = pos != string::npos ? target.substr(0, pos) : ""; |
| 1832 | TWPartition* t_part = PartitionManager.Find_Partition_By_Path(mount_point); |
| 1833 | bool flash_in_both_slots = DataManager::GetIntValue("tw_flash_both_slots") ? true : false; |
| 1834 | |
| 1835 | if (t_part != NULL && (flash_in_both_slots && t_part->SlotSelect)) |
| 1836 | { |
| 1837 | string current_slot = PartitionManager.Get_Active_Slot_Display(); |
| 1838 | bool pre_op_status = PartitionManager.Flash_Image(path, filename); |
| 1839 | |
| 1840 | PartitionManager.Set_Active_Slot(current_slot == "A" ? "B" : "A"); |
| 1841 | op_status = (int) !(pre_op_status && PartitionManager.Flash_Image(path, filename)); |
| 1842 | PartitionManager.Set_Active_Slot(current_slot); |
| 1843 | |
| 1844 | DataManager::SetValue("tw_flash_both_slots", 0); |
| 1845 | flag = false; |
| 1846 | } |
| 1847 | #endif |
| 1848 | if (flag) |
| 1849 | { |
| 1850 | if (PartitionManager.Flash_Image(path, filename)) |
| 1851 | op_status = 0; // success |
| 1852 | else |
| 1853 | op_status = 1; // fail |
| 1854 | } |
| 1855 | |
Ethan Yonker | 96af84a | 2015-01-05 14:58:36 -0600 | [diff] [blame] | 1856 | operation_end(op_status); |
| 1857 | return 0; |
| 1858 | } |
| 1859 | |
that | 10ae24f | 2015-12-26 20:53:51 +0100 | [diff] [blame] | 1860 | int GUIAction::twcmd(std::string arg) |
| 1861 | { |
| 1862 | operation_start("TWRP CLI Command"); |
| 1863 | if (simulate) |
| 1864 | simulate_progress_bar(); |
| 1865 | else |
| 1866 | OpenRecoveryScript::Run_CLI_Command(arg.c_str()); |
| 1867 | operation_end(0); |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1871 | int GUIAction::getKeyByName(std::string key) |
| 1872 | { |
that | 8834a0f | 2016-01-05 23:29:30 +0100 | [diff] [blame] | 1873 | if (key == "home") return KEY_HOMEPAGE; // note: KEY_HOME is cursor movement (like KEY_END) |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1874 | else if (key == "menu") return KEY_MENU; |
| 1875 | else if (key == "back") return KEY_BACK; |
| 1876 | else if (key == "search") return KEY_SEARCH; |
| 1877 | else if (key == "voldown") return KEY_VOLUMEDOWN; |
| 1878 | else if (key == "volup") return KEY_VOLUMEUP; |
| 1879 | else if (key == "power") { |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1880 | int ret_val; |
| 1881 | DataManager::GetValue(TW_POWER_BUTTON, ret_val); |
| 1882 | if (!ret_val) |
| 1883 | return KEY_POWER; |
| 1884 | else |
| 1885 | return ret_val; |
| 1886 | } |
| 1887 | |
Vojtech Bocek | fafb0c5 | 2013-07-25 22:53:02 +0200 | [diff] [blame] | 1888 | return atol(key.c_str()); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1889 | } |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1890 | |
| 1891 | int GUIAction::checkpartitionlifetimewrites(std::string arg) |
| 1892 | { |
| 1893 | int op_status = 0; |
| 1894 | TWPartition* sys = PartitionManager.Find_Partition_By_Path(arg); |
| 1895 | |
| 1896 | operation_start("Check Partition Lifetime Writes"); |
| 1897 | if (sys) { |
| 1898 | if (sys->Check_Lifetime_Writes() != 0) |
| 1899 | DataManager::SetValue("tw_lifetime_writes", 1); |
| 1900 | else |
| 1901 | DataManager::SetValue("tw_lifetime_writes", 0); |
| 1902 | op_status = 0; // success |
| 1903 | } else { |
| 1904 | DataManager::SetValue("tw_lifetime_writes", 1); |
| 1905 | op_status = 1; // fail |
| 1906 | } |
| 1907 | |
| 1908 | operation_end(op_status); |
| 1909 | return 0; |
| 1910 | } |
| 1911 | |
| 1912 | int GUIAction::mountsystemtoggle(std::string arg) |
| 1913 | { |
| 1914 | int op_status = 0; |
Captain Throwback | 9d6feb5 | 2018-07-27 10:05:24 -0400 | [diff] [blame] | 1915 | bool remount_system = PartitionManager.Is_Mounted_By_Path(PartitionManager.Get_Android_Root_Path()); |
Ethan Yonker | 1673e3d | 2015-10-26 21:51:58 -0500 | [diff] [blame] | 1916 | bool remount_vendor = PartitionManager.Is_Mounted_By_Path("/vendor"); |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1917 | |
| 1918 | operation_start("Toggle System Mount"); |
Captain Throwback | 9d6feb5 | 2018-07-27 10:05:24 -0400 | [diff] [blame] | 1919 | if (!PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) { |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1920 | op_status = 1; // fail |
| 1921 | } else { |
Captain Throwback | 9d6feb5 | 2018-07-27 10:05:24 -0400 | [diff] [blame] | 1922 | TWPartition* Part = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path()); |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1923 | if (Part) { |
Ethan Yonker | d6966f4 | 2015-05-30 14:52:16 -0500 | [diff] [blame] | 1924 | if (arg == "0") { |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1925 | DataManager::SetValue("tw_mount_system_ro", 0); |
| 1926 | Part->Change_Mount_Read_Only(false); |
| 1927 | } else { |
| 1928 | DataManager::SetValue("tw_mount_system_ro", 1); |
| 1929 | Part->Change_Mount_Read_Only(true); |
| 1930 | } |
| 1931 | if (remount_system) { |
| 1932 | Part->Mount(true); |
| 1933 | } |
| 1934 | op_status = 0; // success |
| 1935 | } else { |
| 1936 | op_status = 1; // fail |
| 1937 | } |
Ethan Yonker | 1673e3d | 2015-10-26 21:51:58 -0500 | [diff] [blame] | 1938 | Part = PartitionManager.Find_Partition_By_Path("/vendor"); |
| 1939 | if (Part) { |
| 1940 | if (arg == "0") { |
| 1941 | Part->Change_Mount_Read_Only(false); |
| 1942 | } else { |
| 1943 | Part->Change_Mount_Read_Only(true); |
| 1944 | } |
| 1945 | if (remount_vendor) { |
| 1946 | Part->Mount(true); |
| 1947 | } |
| 1948 | op_status = 0; // success |
| 1949 | } else { |
| 1950 | op_status = 1; // fail |
| 1951 | } |
Ethan Yonker | eb32b1f | 2015-05-18 10:23:03 -0500 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | operation_end(op_status); |
| 1955 | return 0; |
| 1956 | } |
Ethan Yonker | 74db157 | 2015-10-28 12:44:49 -0500 | [diff] [blame] | 1957 | |
| 1958 | int GUIAction::setlanguage(std::string arg __unused) |
| 1959 | { |
| 1960 | int op_status = 0; |
| 1961 | |
| 1962 | operation_start("Set Language"); |
| 1963 | PageManager::LoadLanguage(DataManager::GetStrValue("tw_language")); |
| 1964 | PageManager::RequestReload(); |
| 1965 | op_status = 0; // success |
| 1966 | |
| 1967 | operation_end(op_status); |
| 1968 | return 0; |
| 1969 | } |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 1970 | |
Matt Mower | 9472ba1 | 2016-01-20 18:12:47 -0600 | [diff] [blame] | 1971 | int GUIAction::togglebacklight(std::string arg __unused) |
| 1972 | { |
| 1973 | blankTimer.toggleBlank(); |
| 1974 | return 0; |
| 1975 | } |
| 1976 | |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 1977 | int GUIAction::setbootslot(std::string arg) |
| 1978 | { |
| 1979 | operation_start("Set Boot Slot"); |
| 1980 | if (!simulate) |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 1981 | PartitionManager.Set_Active_Slot(arg); |
Matt Mower | 029a82d | 2017-01-08 13:12:38 -0600 | [diff] [blame] | 1982 | else |
Ethan Yonker | 1b19016 | 2016-12-05 15:25:19 -0600 | [diff] [blame] | 1983 | simulate_progress_bar(); |
| 1984 | operation_end(0); |
| 1985 | return 0; |
| 1986 | } |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 1987 | |
| 1988 | int GUIAction::checkforapp(std::string arg __unused) |
| 1989 | { |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 1990 | operation_start("Check for TWRP App"); |
| 1991 | if (!simulate) |
| 1992 | { |
epicX | 9d930a2 | 2020-12-29 00:39:36 +0530 | [diff] [blame] | 1993 | TWFunc::checkforapp(); |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 1994 | } else |
| 1995 | simulate_progress_bar(); |
epicX | 9d930a2 | 2020-12-29 00:39:36 +0530 | [diff] [blame] | 1996 | |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 1997 | operation_end(0); |
| 1998 | return 0; |
| 1999 | } |
| 2000 | |
| 2001 | int GUIAction::installapp(std::string arg __unused) |
| 2002 | { |
| 2003 | int op_status = 1; |
| 2004 | operation_start("Install TWRP App"); |
| 2005 | if (!simulate) |
| 2006 | { |
| 2007 | if (DataManager::GetIntValue("tw_mount_system_ro") > 0 || DataManager::GetIntValue("tw_app_install_system") == 0) { |
| 2008 | if (PartitionManager.Mount_By_Path("/data", true)) { |
| 2009 | string install_path = "/data/app"; |
| 2010 | string context = "u:object_r:apk_data_file:s0"; |
| 2011 | if (!TWFunc::Path_Exists(install_path)) { |
| 2012 | if (mkdir(install_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { |
| 2013 | LOGERR("Error making %s directory: %s\n", install_path.c_str(), strerror(errno)); |
| 2014 | goto exit; |
| 2015 | } |
| 2016 | if (chown(install_path.c_str(), 1000, 1000)) { |
| 2017 | LOGERR("chown %s error: %s\n", install_path.c_str(), strerror(errno)); |
| 2018 | goto exit; |
| 2019 | } |
Ethan Yonker | 4767caf | 2017-01-11 10:45:04 -0600 | [diff] [blame] | 2020 | if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) { |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 2021 | LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno)); |
| 2022 | goto exit; |
| 2023 | } |
| 2024 | } |
| 2025 | install_path += "/me.twrp.twrpapp-1"; |
| 2026 | if (mkdir(install_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { |
| 2027 | LOGERR("Error making %s directory: %s\n", install_path.c_str(), strerror(errno)); |
| 2028 | goto exit; |
| 2029 | } |
| 2030 | if (chown(install_path.c_str(), 1000, 1000)) { |
| 2031 | LOGERR("chown %s error: %s\n", install_path.c_str(), strerror(errno)); |
| 2032 | goto exit; |
| 2033 | } |
Ethan Yonker | 4767caf | 2017-01-11 10:45:04 -0600 | [diff] [blame] | 2034 | if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) { |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 2035 | LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno)); |
| 2036 | goto exit; |
| 2037 | } |
| 2038 | install_path += "/base.apk"; |
| 2039 | if (TWFunc::copy_file("/sbin/me.twrp.twrpapp.apk", install_path, 0644)) { |
| 2040 | LOGERR("Error copying apk file\n"); |
| 2041 | goto exit; |
| 2042 | } |
| 2043 | if (chown(install_path.c_str(), 1000, 1000)) { |
| 2044 | LOGERR("chown %s error: %s\n", install_path.c_str(), strerror(errno)); |
| 2045 | goto exit; |
| 2046 | } |
Ethan Yonker | 4767caf | 2017-01-11 10:45:04 -0600 | [diff] [blame] | 2047 | if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) { |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 2048 | LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno)); |
| 2049 | goto exit; |
| 2050 | } |
| 2051 | sync(); |
| 2052 | sync(); |
| 2053 | } |
| 2054 | } else { |
Captain Throwback | 9d6feb5 | 2018-07-27 10:05:24 -0400 | [diff] [blame] | 2055 | if (PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) { |
| 2056 | string base_path = PartitionManager.Get_Android_Root_Path(); |
| 2057 | if (TWFunc::Path_Exists(PartitionManager.Get_Android_Root_Path() + "/system")) |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 2058 | base_path += "/system"; // For devices with system as a root file system (e.g. Pixel) |
| 2059 | string install_path = base_path + "/priv-app"; |
| 2060 | string context = "u:object_r:system_file:s0"; |
| 2061 | if (!TWFunc::Path_Exists(install_path)) |
| 2062 | install_path = base_path + "/app"; |
| 2063 | if (TWFunc::Path_Exists(install_path)) { |
| 2064 | install_path += "/twrpapp"; |
| 2065 | LOGINFO("Installing app to '%s'\n", install_path.c_str()); |
| 2066 | if (mkdir(install_path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0) { |
Ethan Yonker | 4767caf | 2017-01-11 10:45:04 -0600 | [diff] [blame] | 2067 | if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) { |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 2068 | LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno)); |
| 2069 | goto exit; |
| 2070 | } |
| 2071 | install_path += "/me.twrp.twrpapp.apk"; |
| 2072 | if (TWFunc::copy_file("/sbin/me.twrp.twrpapp.apk", install_path, 0644)) { |
| 2073 | LOGERR("Error copying apk file\n"); |
| 2074 | goto exit; |
| 2075 | } |
Ethan Yonker | 4767caf | 2017-01-11 10:45:04 -0600 | [diff] [blame] | 2076 | if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) { |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 2077 | LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno)); |
| 2078 | goto exit; |
| 2079 | } |
Stefan Tauner | 86a4370 | 2020-01-11 22:28:53 +0100 | [diff] [blame] | 2080 | |
| 2081 | // System apps require their permissions to be pre-set via an XML file in /etc/permissions |
| 2082 | string permission_path = base_path + "/etc/permissions/privapp-permissions-twrpapp.xml"; |
| 2083 | if (TWFunc::copy_file("/sbin/privapp-permissions-twrpapp.xml", permission_path, 0644)) { |
| 2084 | LOGERR("Error copying permission file\n"); |
| 2085 | goto exit; |
| 2086 | } |
| 2087 | if (chown(permission_path.c_str(), 1000, 1000)) { |
| 2088 | LOGERR("chown %s error: %s\n", permission_path.c_str(), strerror(errno)); |
| 2089 | goto exit; |
| 2090 | } |
| 2091 | if (setfilecon(permission_path.c_str(), (security_context_t)context.c_str()) < 0) { |
| 2092 | LOGERR("setfilecon %s error: %s\n", permission_path.c_str(), strerror(errno)); |
| 2093 | goto exit; |
| 2094 | } |
| 2095 | |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 2096 | sync(); |
| 2097 | sync(); |
Captain Throwback | 9d6feb5 | 2018-07-27 10:05:24 -0400 | [diff] [blame] | 2098 | PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true); |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 2099 | op_status = 0; |
| 2100 | } else { |
| 2101 | LOGERR("Error making app directory '%s': %s\n", strerror(errno)); |
| 2102 | } |
| 2103 | } |
| 2104 | } |
| 2105 | } |
| 2106 | } else |
| 2107 | simulate_progress_bar(); |
| 2108 | exit: |
epicX | 9d930a2 | 2020-12-29 00:39:36 +0530 | [diff] [blame] | 2109 | TWFunc::checkforapp(); |
Ethan Yonker | b4bff5e | 2016-12-16 07:47:58 -0600 | [diff] [blame] | 2110 | operation_end(0); |
| 2111 | return 0; |
| 2112 | } |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 2113 | |
Ethan Yonker | 76bbd3a | 2019-05-10 10:50:04 -0500 | [diff] [blame] | 2114 | int GUIAction::uninstalltwrpsystemapp(std::string arg __unused) |
| 2115 | { |
| 2116 | int op_status = 1; |
| 2117 | operation_start("Uninstall TWRP System App"); |
| 2118 | if (!simulate) |
| 2119 | { |
| 2120 | int Mount_System_RO = DataManager::GetIntValue("tw_mount_system_ro"); |
| 2121 | TWPartition* Part = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path()); |
| 2122 | if (!Part) { |
| 2123 | LOGERR("Unabled to find system partition.\n"); |
| 2124 | goto exit; |
| 2125 | } |
| 2126 | if (!Part->UnMount(true)) { |
| 2127 | goto exit; |
| 2128 | } |
| 2129 | if (Mount_System_RO > 0) { |
| 2130 | DataManager::SetValue("tw_mount_system_ro", 0); |
| 2131 | Part->Change_Mount_Read_Only(false); |
| 2132 | } |
| 2133 | if (Part->Mount(true)) { |
| 2134 | string base_path = PartitionManager.Get_Android_Root_Path(); |
| 2135 | if (TWFunc::Path_Exists(PartitionManager.Get_Android_Root_Path() + "/system")) |
| 2136 | base_path += "/system"; // For devices with system as a root file system (e.g. Pixel) |
| 2137 | string uninstall_path = base_path + "/priv-app"; |
| 2138 | if (!TWFunc::Path_Exists(uninstall_path)) |
| 2139 | uninstall_path = base_path + "/app"; |
| 2140 | uninstall_path += "/twrpapp"; |
| 2141 | if (TWFunc::Path_Exists(uninstall_path)) { |
| 2142 | LOGINFO("Uninstalling TWRP App from '%s'\n", uninstall_path.c_str()); |
| 2143 | if (TWFunc::removeDir(uninstall_path, false) == 0) { |
| 2144 | sync(); |
| 2145 | op_status = 0; |
| 2146 | DataManager::SetValue("tw_app_installed_in_system", 0); |
| 2147 | DataManager::SetValue("tw_app_install_status", 0); |
| 2148 | } else { |
| 2149 | LOGERR("Unable to remove TWRP app from system.\n"); |
| 2150 | } |
| 2151 | } else { |
| 2152 | LOGINFO("didn't find TWRP app in '%s'\n", uninstall_path.c_str()); |
| 2153 | } |
| 2154 | } |
| 2155 | Part->UnMount(true); |
| 2156 | if (Mount_System_RO > 0) { |
| 2157 | DataManager::SetValue("tw_mount_system_ro", Mount_System_RO); |
| 2158 | Part->Change_Mount_Read_Only(true); |
| 2159 | } |
| 2160 | } else |
| 2161 | simulate_progress_bar(); |
| 2162 | exit: |
epicX | 9d930a2 | 2020-12-29 00:39:36 +0530 | [diff] [blame] | 2163 | TWFunc::checkforapp(); |
Ethan Yonker | 76bbd3a | 2019-05-10 10:50:04 -0500 | [diff] [blame] | 2164 | operation_end(0); |
| 2165 | return 0; |
| 2166 | } |
| 2167 | |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 2168 | int GUIAction::repackimage(std::string arg __unused) |
| 2169 | { |
| 2170 | int op_status = 1; |
bigbiff | 56b02eb | 2020-07-06 20:24:34 -0400 | [diff] [blame] | 2171 | twrpRepacker repacker; |
| 2172 | |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 2173 | operation_start("Repack Image"); |
| 2174 | if (!simulate) |
| 2175 | { |
| 2176 | std::string path = DataManager::GetStrValue("tw_filename"); |
| 2177 | Repack_Options_struct Repack_Options; |
| 2178 | Repack_Options.Disable_Verity = false; |
| 2179 | Repack_Options.Disable_Force_Encrypt = false; |
| 2180 | Repack_Options.Backup_First = DataManager::GetIntValue("tw_repack_backup_first") != 0; |
| 2181 | if (DataManager::GetIntValue("tw_repack_kernel") == 1) |
| 2182 | Repack_Options.Type = REPLACE_KERNEL; |
| 2183 | else |
| 2184 | Repack_Options.Type = REPLACE_RAMDISK; |
bigbiff | 56b02eb | 2020-07-06 20:24:34 -0400 | [diff] [blame] | 2185 | if (!repacker.Repack_Image_And_Flash(path, Repack_Options)) |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 2186 | goto exit; |
| 2187 | } else |
| 2188 | simulate_progress_bar(); |
| 2189 | op_status = 0; |
| 2190 | exit: |
| 2191 | operation_end(op_status); |
| 2192 | return 0; |
| 2193 | } |
| 2194 | |
| 2195 | int GUIAction::fixabrecoverybootloop(std::string arg __unused) |
| 2196 | { |
| 2197 | int op_status = 1; |
bigbiff | 56b02eb | 2020-07-06 20:24:34 -0400 | [diff] [blame] | 2198 | twrpRepacker repacker; |
| 2199 | |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 2200 | operation_start("Repack Image"); |
| 2201 | if (!simulate) |
| 2202 | { |
| 2203 | if (!TWFunc::Path_Exists("/sbin/magiskboot")) { |
| 2204 | LOGERR("Image repacking tool not present in this TWRP build!"); |
| 2205 | goto exit; |
| 2206 | } |
| 2207 | DataManager::SetProgress(0); |
| 2208 | TWPartition* part = PartitionManager.Find_Partition_By_Path("/boot"); |
| 2209 | if (part) |
| 2210 | gui_msg(Msg("unpacking_image=Unpacking {1}...")(part->Display_Name)); |
| 2211 | else { |
| 2212 | gui_msg(Msg(msg::kError, "unable_to_locate=Unable to locate {1}.")("/boot")); |
| 2213 | goto exit; |
| 2214 | } |
bigbiff | 56b02eb | 2020-07-06 20:24:34 -0400 | [diff] [blame] | 2215 | if (!repacker.Backup_Image_For_Repack(part, REPACK_ORIG_DIR, DataManager::GetIntValue("tw_repack_backup_first") != 0, gui_lookup("repack", "Repack"))) |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 2216 | goto exit; |
| 2217 | DataManager::SetProgress(.25); |
| 2218 | gui_msg("fixing_recovery_loop_patch=Patching kernel..."); |
Mohd Faraz | 5738e76 | 2020-05-10 04:18:30 +0530 | [diff] [blame] | 2219 | std::string command = "cd " REPACK_ORIG_DIR " && /sbin/magiskboot hexpatch kernel 77616E745F696E697472616D667300 736B69705F696E697472616D667300"; |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 2220 | if (TWFunc::Exec_Cmd(command) != 0) { |
| 2221 | gui_msg(Msg(msg::kError, "fix_recovery_loop_patch_error=Error patching kernel.")); |
| 2222 | goto exit; |
| 2223 | } |
| 2224 | std::string header_path = REPACK_ORIG_DIR; |
| 2225 | header_path += "header"; |
| 2226 | if (TWFunc::Path_Exists(header_path)) { |
| 2227 | command = "cd " REPACK_ORIG_DIR " && sed -i \"s|$(grep '^cmdline=' header | cut -d= -f2-)|$(grep '^cmdline=' header | cut -d= -f2- | sed -e 's/skip_override//' -e 's/ */ /g' -e 's/[ \t]*$//')|\" header"; |
| 2228 | if (TWFunc::Exec_Cmd(command) != 0) { |
| 2229 | gui_msg(Msg(msg::kError, "fix_recovery_loop_patch_error=Error patching kernel.")); |
| 2230 | goto exit; |
| 2231 | } |
| 2232 | } |
| 2233 | DataManager::SetProgress(.5); |
| 2234 | gui_msg(Msg("repacking_image=Repacking {1}...")(part->Display_Name)); |
Mohd Faraz | 5738e76 | 2020-05-10 04:18:30 +0530 | [diff] [blame] | 2235 | command = "cd " REPACK_ORIG_DIR " && /sbin/magiskboot repack " REPACK_ORIG_DIR "boot.img"; |
Ethan Yonker | 53796e7 | 2019-01-11 22:49:52 -0600 | [diff] [blame] | 2236 | if (TWFunc::Exec_Cmd(command) != 0) { |
| 2237 | gui_msg(Msg(msg::kError, "repack_error=Error repacking image.")); |
| 2238 | goto exit; |
| 2239 | } |
| 2240 | DataManager::SetProgress(.75); |
| 2241 | std::string path = REPACK_ORIG_DIR; |
| 2242 | std::string file = "new-boot.img"; |
| 2243 | DataManager::SetValue("tw_flash_partition", "/boot;"); |
| 2244 | if (!PartitionManager.Flash_Image(path, file)) { |
| 2245 | LOGINFO("Error flashing new image\n"); |
| 2246 | goto exit; |
| 2247 | } |
| 2248 | DataManager::SetProgress(1); |
| 2249 | TWFunc::removeDir(REPACK_ORIG_DIR, false); |
| 2250 | } else |
| 2251 | simulate_progress_bar(); |
| 2252 | op_status = 0; |
| 2253 | exit: |
| 2254 | operation_end(op_status); |
| 2255 | return 0; |
| 2256 | } |
Mohd Faraz | 3c25ab3 | 2020-08-12 12:29:42 +0000 | [diff] [blame] | 2257 | |
| 2258 | int GUIAction::changeterminal(std::string arg) { |
| 2259 | bool res = true; |
| 2260 | std::string resp, cmd = "cd " + arg; |
| 2261 | DataManager::GetValue("tw_terminal_location", resp); |
| 2262 | if (arg.empty() && !resp.empty()) { |
| 2263 | cmd = "cd /"; |
| 2264 | for (uint8_t iter = 0; iter < cmd.size(); iter++) |
| 2265 | term->NotifyCharInput(cmd.at(iter)); |
| 2266 | term->NotifyCharInput(13); |
| 2267 | DataManager::SetValue("tw_terminal_location", ""); |
| 2268 | return 0; |
| 2269 | } |
| 2270 | if (term != NULL && !arg.empty()) { |
| 2271 | DataManager::SetValue("tw_terminal_location", arg); |
| 2272 | if (term->status()) { |
| 2273 | for (uint8_t iter = 0; iter < cmd.size(); iter++) |
| 2274 | term->NotifyCharInput(cmd.at(iter)); |
| 2275 | term->NotifyCharInput(13); |
| 2276 | } |
| 2277 | else if (chdir(arg.c_str()) != 0) { |
| 2278 | LOGINFO("Unable to change dir to %s\n", arg.c_str()); |
| 2279 | res = false; |
| 2280 | } |
| 2281 | } |
| 2282 | else { |
| 2283 | res = false; |
| 2284 | LOGINFO("Unable to switch to Terminal\n"); |
| 2285 | } |
| 2286 | if (res) |
| 2287 | gui_changePage("terminalcommand"); |
| 2288 | return 0; |
| 2289 | } |
Captain Throwback | 3b55610 | 2021-02-12 19:32:36 -0500 | [diff] [blame] | 2290 | #ifndef TW_EXCLUDE_NANO |
| 2291 | int GUIAction::editfile(std::string arg) { |
| 2292 | if (term != NULL) { |
| 2293 | for (uint8_t iter = 0; iter < arg.size(); iter++) |
| 2294 | term->NotifyCharInput(arg.at(iter)); |
| 2295 | term->NotifyCharInput(13); |
| 2296 | } |
| 2297 | else |
| 2298 | LOGINFO("Unable to switch to Terminal\n"); |
| 2299 | return 0; |
| 2300 | } |
| 2301 | #endif |
epicX | 98053c3 | 2021-01-04 13:01:31 +0530 | [diff] [blame] | 2302 | |
| 2303 | int GUIAction::applycustomtwrpfolder(string arg __unused) |
| 2304 | { |
| 2305 | operation_start("ChangingTWRPFolder"); |
| 2306 | string storageFolder = DataManager::GetSettingsStoragePath(); |
| 2307 | string newFolder = storageFolder + '/' + arg; |
| 2308 | string newBackupFolder = newFolder + "/BACKUPS/" + DataManager::GetStrValue("device_id"); |
| 2309 | string prevFolder = storageFolder + DataManager::GetStrValue(TW_RECOVERY_FOLDER_VAR); |
| 2310 | bool ret = false; |
| 2311 | |
| 2312 | if (TWFunc::Path_Exists(newFolder)) { |
| 2313 | gui_msg(Msg(msg::kError, "tw_folder_exists=A folder with that name already exists!")); |
| 2314 | } else { |
| 2315 | ret = true; |
| 2316 | } |
| 2317 | |
| 2318 | if (newFolder != prevFolder && ret) { |
| 2319 | ret = TWFunc::Exec_Cmd("mv -f \"" + prevFolder + "\" \"" + newFolder + '\"') != 0 ? false : true; |
| 2320 | } else { |
| 2321 | gui_msg(Msg(msg::kError, "tw_folder_exists=A folder with that name already exists!")); |
| 2322 | } |
| 2323 | |
epicX | fb61038 | 2021-03-01 00:02:57 +0530 | [diff] [blame] | 2324 | if (ret) ret = TWFunc::Recursive_Mkdir(newBackupFolder) ? true : false; |
epicX | 98053c3 | 2021-01-04 13:01:31 +0530 | [diff] [blame] | 2325 | |
| 2326 | |
| 2327 | if (ret) { |
| 2328 | DataManager::SetValue(TW_RECOVERY_FOLDER_VAR, '/' + arg); |
| 2329 | DataManager::SetValue(TW_BACKUPS_FOLDER_VAR, newBackupFolder); |
| 2330 | DataManager::mBackingFile = newFolder + '/' + TW_SETTINGS_FILE; |
| 2331 | } |
| 2332 | operation_end((int)!ret); |
| 2333 | return 0; |
| 2334 | } |