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