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