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