blob: 878f980970c3f31dcd76bd2098b1b6bd03ba0b50 [file] [log] [blame]
Ethan Yonker6e8c27a2016-12-22 17:55:57 -06001/*
Dees_Troya13d74f2013-03-24 08:54:55 -05002 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_Troy51a0e822012-09-05 15:24:24 -040018
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_Troy657c3092012-09-10 20:32:10 -040033#include <sys/wait.h>
Dees_Troy83bd4832013-05-04 12:39:56 +000034#include <dirent.h>
Matt Mower0c88b842017-01-15 16:00:49 -060035#include <private/android_filesystem_config.h>
bigbiffdf8436b2020-08-30 16:22:34 -040036#include <android-base/properties.h>
Dees_Troy51a0e822012-09-05 15:24:24 -040037
38#include <string>
39#include <sstream>
40#include "../partitions.hpp"
Dees_Troy38bd7602012-09-14 13:33:53 -040041#include "../twrp-functions.hpp"
bigbiffad58e1b2020-07-06 20:24:34 -040042#include "../twrpRepacker.hpp"
Dees_Troy812660f2012-09-20 09:55:17 -040043#include "../openrecoveryscript.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040044
bigbiff1f9e4842020-10-31 11:33:15 -040045#include "twinstall/adb_install.h"
bigbiffd58ba182020-03-23 10:02:29 -040046
47#include "fuse_sideload.h"
bigbiff bigbiff8a68c312013-02-10 14:28:30 -050048#include "blanktimer.hpp"
bigbiff1f9e4842020-10-31 11:33:15 -040049#include "twinstall.h"
Ethan Yonkerfbb43532015-12-28 21:54:50 +010050
Dees_Troy51a0e822012-09-05 15:24:24 -040051extern "C" {
Dees_Troy2673cec2013-04-02 20:22:16 +000052#include "../twcommon.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040053#include "../variables.h"
Dees_Troy2673cec2013-04-02 20:22:16 +000054#include "cutils/properties.h"
bigbiff673c7ae2020-12-02 19:44:56 -050055#include "twinstall/adb_install.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040056};
bigbiffd58ba182020-03-23 10:02:29 -040057#include "set_metadata.h"
Ethan Yonkerfbb43532015-12-28 21:54:50 +010058#include "../minuitwrp/minui.h"
Dees_Troy51a0e822012-09-05 15:24:24 -040059
60#include "rapidxml.hpp"
61#include "objects.hpp"
bigbiffd58ba182020-03-23 10:02:29 -040062#include "tw_atomic.hpp"
Dees_Troy51a0e822012-09-05 15:24:24 -040063
that3f7b1ac2014-12-30 11:30:13 +010064GUIAction::mapFunc GUIAction::mf;
thatc6085482015-01-09 22:12:43 +010065std::set<string> GUIAction::setActionsRunningInCallerThread;
that3f7b1ac2014-12-30 11:30:13 +010066static string zip_queue[10];
67static int zip_queue_index;
thatcc8ddca2015-01-03 01:59:36 +010068pid_t sideload_child_pid;
Noah Jacobson81d638d2019-04-28 00:10:07 -040069extern std::vector<users_struct> Users_List;
that3f7b1ac2014-12-30 11:30:13 +010070
that73a52952015-01-28 23:07:34 +010071static void *ActionThread_work_wrapper(void *data);
72
73class ActionThread
74{
75public:
76 ActionThread();
77 ~ActionThread();
78
79 void threadActions(GUIAction *act);
80 void run(void *data);
81private:
82 friend void *ActionThread_work_wrapper(void*);
83 struct ThreadData
84 {
85 ActionThread *this_;
86 GUIAction *act;
87 ThreadData(ActionThread *this_, GUIAction *act) : this_(this_), act(act) {}
88 };
89
90 pthread_t m_thread;
91 bool m_thread_running;
92 pthread_mutex_t m_act_lock;
93};
94
95static ActionThread action_thread; // for all kinds of longer running actions
96static ActionThread cancel_thread; // for longer running "cancel" actions
thatc6085482015-01-09 22:12:43 +010097
98static void *ActionThread_work_wrapper(void *data)
99{
that73a52952015-01-28 23:07:34 +0100100 static_cast<ActionThread::ThreadData*>(data)->this_->run(data);
thatc6085482015-01-09 22:12:43 +0100101 return NULL;
102}
103
104ActionThread::ActionThread()
105{
106 m_thread_running = false;
107 pthread_mutex_init(&m_act_lock, NULL);
108}
109
110ActionThread::~ActionThread()
111{
112 pthread_mutex_lock(&m_act_lock);
Matt Mowera8a89d12016-12-30 18:10:37 -0600113 if (m_thread_running) {
thatc6085482015-01-09 22:12:43 +0100114 pthread_mutex_unlock(&m_act_lock);
115 pthread_join(m_thread, NULL);
116 } else {
117 pthread_mutex_unlock(&m_act_lock);
118 }
119 pthread_mutex_destroy(&m_act_lock);
120}
121
that7d3b54f2015-01-09 22:52:51 +0100122void ActionThread::threadActions(GUIAction *act)
thatc6085482015-01-09 22:12:43 +0100123{
124 pthread_mutex_lock(&m_act_lock);
125 if (m_thread_running) {
126 pthread_mutex_unlock(&m_act_lock);
that7d3b54f2015-01-09 22:52:51 +0100127 LOGERR("Another threaded action is already running -- not running %u actions starting with '%s'\n",
128 act->mActions.size(), act->mActions[0].mFunction.c_str());
thatc6085482015-01-09 22:12:43 +0100129 } else {
130 m_thread_running = true;
131 pthread_mutex_unlock(&m_act_lock);
that73a52952015-01-28 23:07:34 +0100132 ThreadData *d = new ThreadData(this, act);
thatc6085482015-01-09 22:12:43 +0100133 pthread_create(&m_thread, NULL, &ActionThread_work_wrapper, d);
134 }
135}
136
137void ActionThread::run(void *data)
138{
139 ThreadData *d = (ThreadData*)data;
140 GUIAction* act = d->act;
141
142 std::vector<GUIAction::Action>::iterator it;
that7d3b54f2015-01-09 22:52:51 +0100143 for (it = act->mActions.begin(); it != act->mActions.end(); ++it)
thatc6085482015-01-09 22:12:43 +0100144 act->doAction(*it);
145
146 pthread_mutex_lock(&m_act_lock);
147 m_thread_running = false;
148 pthread_mutex_unlock(&m_act_lock);
149 delete d;
150}
151
Dees_Troy51a0e822012-09-05 15:24:24 -0400152GUIAction::GUIAction(xml_node<>* node)
Vojtech Bocekede51c52014-02-07 23:58:09 +0100153 : GUIObject(node)
Dees_Troy51a0e822012-09-05 15:24:24 -0400154{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200155 xml_node<>* child;
156 xml_node<>* actions;
157 xml_attribute<>* attr;
Dees_Troy51a0e822012-09-05 15:24:24 -0400158
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200159 if (!node) return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400160
that3f7b1ac2014-12-30 11:30:13 +0100161 if (mf.empty()) {
Vojtech Bocekecd89182015-01-15 16:28:54 +0100162#define ADD_ACTION(n) mf[#n] = &GUIAction::n
163#define ADD_ACTION_EX(name, func) mf[name] = &GUIAction::func
thatc6085482015-01-09 22:12:43 +0100164 // These actions will be run in the caller's thread
Vojtech Bocekecd89182015-01-15 16:28:54 +0100165 ADD_ACTION(reboot);
166 ADD_ACTION(home);
167 ADD_ACTION(key);
168 ADD_ACTION(page);
169 ADD_ACTION(reload);
170 ADD_ACTION(readBackup);
171 ADD_ACTION(set);
172 ADD_ACTION(clear);
173 ADD_ACTION(mount);
174 ADD_ACTION(unmount);
175 ADD_ACTION_EX("umount", unmount);
176 ADD_ACTION(restoredefaultsettings);
177 ADD_ACTION(copylog);
178 ADD_ACTION(compute);
179 ADD_ACTION_EX("addsubtract", compute);
180 ADD_ACTION(setguitimezone);
181 ADD_ACTION(overlay);
182 ADD_ACTION(queuezip);
183 ADD_ACTION(cancelzip);
184 ADD_ACTION(queueclear);
185 ADD_ACTION(sleep);
Matt Mower9a2a2052016-05-31 21:31:22 -0500186 ADD_ACTION(sleepcounter);
Vojtech Bocekecd89182015-01-15 16:28:54 +0100187 ADD_ACTION(appenddatetobackupname);
188 ADD_ACTION(generatebackupname);
189 ADD_ACTION(checkpartitionlist);
190 ADD_ACTION(getpartitiondetails);
191 ADD_ACTION(screenshot);
192 ADD_ACTION(setbrightness);
193 ADD_ACTION(fileexists);
194 ADD_ACTION(killterminal);
195 ADD_ACTION(checkbackupname);
196 ADD_ACTION(adbsideloadcancel);
197 ADD_ACTION(fixsu);
198 ADD_ACTION(startmtp);
199 ADD_ACTION(stopmtp);
200 ADD_ACTION(cancelbackup);
Ethan Yonkereb32b1f2015-05-18 10:23:03 -0500201 ADD_ACTION(checkpartitionlifetimewrites);
202 ADD_ACTION(mountsystemtoggle);
Ethan Yonker74db1572015-10-28 12:44:49 -0500203 ADD_ACTION(setlanguage);
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -0600204 ADD_ACTION(checkforapp);
Matt Mower9472ba12016-01-20 18:12:47 -0600205 ADD_ACTION(togglebacklight);
bigbiffdf8436b2020-08-30 16:22:34 -0400206 ADD_ACTION(enableadb);
207 ADD_ACTION(enablefastboot);
thatc6085482015-01-09 22:12:43 +0100208
209 // remember actions that run in the caller thread
210 for (mapFunc::const_iterator it = mf.begin(); it != mf.end(); ++it)
211 setActionsRunningInCallerThread.insert(it->first);
212
213 // These actions will run in a separate thread
Vojtech Bocekecd89182015-01-15 16:28:54 +0100214 ADD_ACTION(flash);
215 ADD_ACTION(wipe);
216 ADD_ACTION(refreshsizes);
217 ADD_ACTION(nandroid);
Ethan Yonkerb5fab762016-01-28 14:03:33 -0600218 ADD_ACTION(fixcontexts);
Vojtech Bocekecd89182015-01-15 16:28:54 +0100219 ADD_ACTION(fixpermissions);
220 ADD_ACTION(dd);
221 ADD_ACTION(partitionsd);
222 ADD_ACTION(installhtcdumlock);
223 ADD_ACTION(htcdumlockrestoreboot);
224 ADD_ACTION(htcdumlockreflashrecovery);
225 ADD_ACTION(cmd);
226 ADD_ACTION(terminalcommand);
227 ADD_ACTION(reinjecttwrp);
228 ADD_ACTION(decrypt);
229 ADD_ACTION(adbsideload);
230 ADD_ACTION(openrecoveryscript);
231 ADD_ACTION(installsu);
232 ADD_ACTION(decrypt_backup);
233 ADD_ACTION(repair);
Ethan Yonkera2719152015-05-28 09:44:41 -0500234 ADD_ACTION(resize);
Vojtech Bocekecd89182015-01-15 16:28:54 +0100235 ADD_ACTION(changefilesystem);
236 ADD_ACTION(flashimage);
that10ae24f2015-12-26 20:53:51 +0100237 ADD_ACTION(twcmd);
Ethan Yonker1b190162016-12-05 15:25:19 -0600238 ADD_ACTION(setbootslot);
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -0600239 ADD_ACTION(installapp);
Ethan Yonker76bbd3a2019-05-10 10:50:04 -0500240 ADD_ACTION(uninstalltwrpsystemapp);
Ethan Yonker53796e72019-01-11 22:49:52 -0600241 ADD_ACTION(repackimage);
242 ADD_ACTION(fixabrecoverybootloop);
that3f7b1ac2014-12-30 11:30:13 +0100243 }
244
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200245 // First, get the action
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600246 actions = FindNode(node, "actions");
247 if (actions) child = FindNode(actions, "action");
248 else child = FindNode(node, "action");
Dees_Troy51a0e822012-09-05 15:24:24 -0400249
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200250 if (!child) return;
Dees_Troy51a0e822012-09-05 15:24:24 -0400251
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200252 while (child)
253 {
254 Action action;
Dees_Troy51a0e822012-09-05 15:24:24 -0400255
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200256 attr = child->first_attribute("function");
257 if (!attr) return;
Matt Mowerfb1c4ff2014-04-16 13:43:36 -0500258
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200259 action.mFunction = attr->value();
260 action.mArg = child->value();
261 mActions.push_back(action);
Dees_Troy51a0e822012-09-05 15:24:24 -0400262
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200263 child = child->next_sibling("action");
264 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400265
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200266 // Now, let's get either the key or region
Ethan Yonker21ff02a2015-02-18 14:35:00 -0600267 child = FindNode(node, "touch");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200268 if (child)
269 {
270 attr = child->first_attribute("key");
271 if (attr)
272 {
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100273 std::vector<std::string> keys = TWFunc::Split_String(attr->value(), "+");
Matt Mowera8a89d12016-12-30 18:10:37 -0600274 for (size_t i = 0; i < keys.size(); ++i)
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100275 {
276 const int key = getKeyByName(keys[i]);
277 mKeys[key] = false;
278 }
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200279 }
280 else
281 {
282 attr = child->first_attribute("x");
283 if (!attr) return;
284 mActionX = atol(attr->value());
285 attr = child->first_attribute("y");
286 if (!attr) return;
287 mActionY = atol(attr->value());
288 attr = child->first_attribute("w");
289 if (!attr) return;
290 mActionW = atol(attr->value());
291 attr = child->first_attribute("h");
292 if (!attr) return;
293 mActionH = atol(attr->value());
294 }
295 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400296}
297
Matt Mower25036b72016-06-24 12:30:18 -0500298int GUIAction::NotifyTouch(TOUCH_STATE state, int x __unused, int y __unused)
Dees_Troy51a0e822012-09-05 15:24:24 -0400299{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200300 if (state == TOUCH_RELEASE)
301 doActions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400302
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200303 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400304}
305
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100306int GUIAction::NotifyKey(int key, bool down)
Dees_Troy51a0e822012-09-05 15:24:24 -0400307{
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100308 std::map<int, bool>::iterator itr = mKeys.find(key);
Matt Mowera8a89d12016-12-30 18:10:37 -0600309 if (itr == mKeys.end())
that8834a0f2016-01-05 23:29:30 +0100310 return 1;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100311
312 bool prevState = itr->second;
313 itr->second = down;
314
315 // If there is only one key for this action, wait for key up so it
316 // doesn't trigger with multi-key actions.
317 // Else, check if all buttons are pressed, then consume their release events
318 // so they don't trigger one-button actions and reset mKeys pressed status
Matt Mowera8a89d12016-12-30 18:10:37 -0600319 if (mKeys.size() == 1) {
320 if (!down && prevState) {
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100321 doActions();
thatd4725ca2016-01-19 00:15:21 +0100322 return 0;
323 }
Matt Mowera8a89d12016-12-30 18:10:37 -0600324 } else if (down) {
325 for (itr = mKeys.begin(); itr != mKeys.end(); ++itr) {
326 if (!itr->second)
that8834a0f2016-01-05 23:29:30 +0100327 return 1;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100328 }
329
330 // Passed, all req buttons are pressed, reset them and consume release events
331 HardwareKeyboard *kb = PageManager::GetHardwareKeyboard();
Matt Mowera8a89d12016-12-30 18:10:37 -0600332 for (itr = mKeys.begin(); itr != mKeys.end(); ++itr) {
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100333 kb->ConsumeKeyRelease(itr->first);
334 itr->second = false;
335 }
336
337 doActions();
thatd4725ca2016-01-19 00:15:21 +0100338 return 0;
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100339 }
340
thatd4725ca2016-01-19 00:15:21 +0100341 return 1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400342}
343
Vojtech Bocek07220562014-02-08 02:05:33 +0100344int GUIAction::NotifyVarChange(const std::string& varName, const std::string& value)
Dees_Troy51a0e822012-09-05 15:24:24 -0400345{
Vojtech Bocek07220562014-02-08 02:05:33 +0100346 GUIObject::NotifyVarChange(varName, value);
347
Vojtech Bocek0b7fe502014-03-13 17:36:52 +0100348 if (varName.empty() && !isConditionValid() && mKeys.empty() && !mActionW)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200349 doActions();
Matt Mowera8a89d12016-12-30 18:10:37 -0600350 else if ((varName.empty() || IsConditionVariable(varName)) && isConditionValid() && isConditionTrue())
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200351 doActions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400352
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200353 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400354}
355
356void GUIAction::simulate_progress_bar(void)
357{
Ethan Yonker74db1572015-10-28 12:44:49 -0500358 gui_msg("simulating=Simulating actions...");
Dees_Troy51a0e822012-09-05 15:24:24 -0400359 for (int i = 0; i < 5; i++)
360 {
bigbiff7abc5fe2015-01-17 16:53:12 -0500361 if (PartitionManager.stop_backup.get_value()) {
362 DataManager::SetValue("tw_cancel_backup", 1);
Matt Mower3c366972015-12-25 19:28:31 -0600363 gui_msg("backup_cancel=Backup Cancelled");
bigbiff7abc5fe2015-01-17 16:53:12 -0500364 DataManager::SetValue("ui_progress", 0);
365 PartitionManager.stop_backup.set_value(0);
366 return;
367 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400368 usleep(500000);
369 DataManager::SetValue("ui_progress", i * 20);
370 }
371}
372
Ethan Yonker0d47eb52015-01-09 11:23:19 -0600373int GUIAction::flash_zip(std::string filename, int* wipe_cache)
Dees_Troy51a0e822012-09-05 15:24:24 -0400374{
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200375 int ret_val = 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400376
377 DataManager::SetValue("ui_progress", 0);
Chaosmasterd5364a02020-02-03 15:38:02 +0100378 DataManager::SetValue("ui_portion_size", 0);
379 DataManager::SetValue("ui_portion_start", 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400380
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200381 if (filename.empty())
382 {
383 LOGERR("No file specified.\n");
384 return -1;
385 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400386
Ethan Yonker9598c072016-01-15 21:54:34 -0600387 if (!TWFunc::Path_Exists(filename)) {
388 if (!PartitionManager.Mount_By_Path(filename, true)) {
389 return -1;
390 }
391 if (!TWFunc::Path_Exists(filename)) {
392 gui_msg(Msg(msg::kError, "unable_to_locate=Unable to locate {1}.")(filename));
393 return -1;
394 }
395 }
Dees_Troy657c3092012-09-10 20:32:10 -0400396
Dees_Troy51a0e822012-09-05 15:24:24 -0400397 if (simulate) {
398 simulate_progress_bar();
399 } else {
Dees_Troy657c3092012-09-10 20:32:10 -0400400 ret_val = TWinstall_zip(filename.c_str(), wipe_cache);
bigbiff1f9e4842020-10-31 11:33:15 -0400401 PartitionManager.Unlock_Block_Partitions();
Dees_Troy51a0e822012-09-05 15:24:24 -0400402
403 // Now, check if we need to ensure TWRP remains installed...
404 struct stat st;
bigbiffad58e1b2020-07-06 20:24:34 -0400405 if (stat("/system/bin/installTwrp", &st) == 0)
Dees_Troy51a0e822012-09-05 15:24:24 -0400406 {
407 DataManager::SetValue("tw_operation", "Configuring TWRP");
408 DataManager::SetValue("tw_partition", "");
Ethan Yonker74db1572015-10-28 12:44:49 -0500409 gui_msg("config_twrp=Configuring TWRP...");
bigbiffad58e1b2020-07-06 20:24:34 -0400410 if (TWFunc::Exec_Cmd("/system/bin/installTwrp reinstall") < 0)
Dees_Troy51a0e822012-09-05 15:24:24 -0400411 {
Ethan Yonker74db1572015-10-28 12:44:49 -0500412 gui_msg("config_twrp_err=Unable to configure TWRP with this kernel.");
Dees_Troy51a0e822012-09-05 15:24:24 -0400413 }
414 }
415 }
416
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200417 // Done
418 DataManager::SetValue("ui_progress", 100);
419 DataManager::SetValue("ui_progress", 0);
Chaosmasterd5364a02020-02-03 15:38:02 +0100420 DataManager::SetValue("ui_portion_size", 0);
421 DataManager::SetValue("ui_portion_start", 0);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200422 return ret_val;
Dees_Troy51a0e822012-09-05 15:24:24 -0400423}
424
that73a52952015-01-28 23:07:34 +0100425GUIAction::ThreadType GUIAction::getThreadType(const GUIAction::Action& action)
thatc6085482015-01-09 22:12:43 +0100426{
that73a52952015-01-28 23:07:34 +0100427 string func = gui_parse_text(action.mFunction);
428 bool needsThread = setActionsRunningInCallerThread.find(func) == setActionsRunningInCallerThread.end();
429 if (needsThread) {
430 if (func == "cancelbackup")
431 return THREAD_CANCEL;
432 else
433 return THREAD_ACTION;
434 }
435 return THREAD_NONE;
thatc6085482015-01-09 22:12:43 +0100436}
437
Dees_Troy51a0e822012-09-05 15:24:24 -0400438int GUIAction::doActions()
439{
that3f7b1ac2014-12-30 11:30:13 +0100440 if (mActions.size() < 1)
441 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400442
that73a52952015-01-28 23:07:34 +0100443 // Determine in which thread to run the actions.
444 // Do it for all actions at once before starting, so that we can cancel the whole batch if the thread is already busy.
445 ThreadType threadType = THREAD_NONE;
that3f7b1ac2014-12-30 11:30:13 +0100446 std::vector<Action>::iterator it;
that73a52952015-01-28 23:07:34 +0100447 for (it = mActions.begin(); it != mActions.end(); ++it) {
448 ThreadType tt = getThreadType(*it);
449 if (tt == THREAD_NONE)
450 continue;
451 if (threadType == THREAD_NONE)
452 threadType = tt;
453 else if (threadType != tt) {
454 LOGERR("Can't mix normal and cancel actions in the same list.\n"
455 "Running the whole batch in the cancel thread.\n");
456 threadType = THREAD_CANCEL;
thatc6085482015-01-09 22:12:43 +0100457 break;
458 }
that7d3b54f2015-01-09 22:52:51 +0100459 }
that73a52952015-01-28 23:07:34 +0100460
461 // Now run the actions in the desired thread.
462 switch (threadType) {
463 case THREAD_ACTION:
464 action_thread.threadActions(this);
465 break;
466
467 case THREAD_CANCEL:
468 cancel_thread.threadActions(this);
469 break;
470
471 default: {
472 // no iterators here because theme reloading might kill our object
473 const size_t cnt = mActions.size();
474 for (size_t i = 0; i < cnt; ++i)
475 doAction(mActions[i]);
476 }
thatc6085482015-01-09 22:12:43 +0100477 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400478
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200479 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -0400480}
481
that3f7b1ac2014-12-30 11:30:13 +0100482int GUIAction::doAction(Action action)
Dees_Troy51a0e822012-09-05 15:24:24 -0400483{
that3f7b1ac2014-12-30 11:30:13 +0100484 DataManager::GetValue(TW_SIMULATE_ACTIONS, simulate);
Dees_Troy51a0e822012-09-05 15:24:24 -0400485
that3f7b1ac2014-12-30 11:30:13 +0100486 std::string function = gui_parse_text(action.mFunction);
487 std::string arg = gui_parse_text(action.mArg);
Dees_Troy51a0e822012-09-05 15:24:24 -0400488
that3f7b1ac2014-12-30 11:30:13 +0100489 // find function and execute it
490 mapFunc::const_iterator funcitr = mf.find(function);
491 if (funcitr != mf.end())
492 return (this->*funcitr->second)(arg);
493
494 LOGERR("Unknown action '%s'\n", function.c_str());
495 return -1;
Dees_Troy51a0e822012-09-05 15:24:24 -0400496}
497
498void GUIAction::operation_start(const string operation_name)
499{
that3f7b1ac2014-12-30 11:30:13 +0100500 LOGINFO("operation_start: '%s'\n", operation_name.c_str());
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000501 time(&Start);
Dees_Troy51a0e822012-09-05 15:24:24 -0400502 DataManager::SetValue(TW_ACTION_BUSY, 1);
503 DataManager::SetValue("ui_progress", 0);
Chaosmasterd5364a02020-02-03 15:38:02 +0100504 DataManager::SetValue("ui_portion_size", 0);
505 DataManager::SetValue("ui_portion_start", 0);
Dees_Troy51a0e822012-09-05 15:24:24 -0400506 DataManager::SetValue("tw_operation", operation_name);
Dees_Troy51a0e822012-09-05 15:24:24 -0400507 DataManager::SetValue("tw_operation_state", 0);
Ethan Yonkerd83c9ea2015-01-02 15:22:31 -0600508 DataManager::SetValue("tw_operation_status", 0);
bigbiff25d25b92020-06-19 16:07:38 -0400509 bool tw_ab_device = TWFunc::get_log_dir() != CACHE_LOGS_DIR;
bigbiff bigbiff19874f12019-01-08 20:06:57 -0500510 DataManager::SetValue("tw_ab_device", tw_ab_device);
Dees_Troy51a0e822012-09-05 15:24:24 -0400511}
512
that3f7b1ac2014-12-30 11:30:13 +0100513void GUIAction::operation_end(const int operation_status)
Dees_Troy51a0e822012-09-05 15:24:24 -0400514{
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000515 time_t Stop;
Dees_Troy51a0e822012-09-05 15:24:24 -0400516 int simulate_fail;
Dees_Troy51a0e822012-09-05 15:24:24 -0400517 DataManager::SetValue("ui_progress", 100);
518 if (simulate) {
519 DataManager::GetValue(TW_SIMULATE_FAIL, simulate_fail);
520 if (simulate_fail != 0)
521 DataManager::SetValue("tw_operation_status", 1);
522 else
523 DataManager::SetValue("tw_operation_status", 0);
524 } else {
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500525 if (operation_status != 0) {
Dees_Troy51a0e822012-09-05 15:24:24 -0400526 DataManager::SetValue("tw_operation_status", 1);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500527 }
528 else {
Dees_Troy51a0e822012-09-05 15:24:24 -0400529 DataManager::SetValue("tw_operation_status", 0);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500530 }
Dees_Troy51a0e822012-09-05 15:24:24 -0400531 }
532 DataManager::SetValue("tw_operation_state", 1);
533 DataManager::SetValue(TW_ACTION_BUSY, 0);
bigbiff bigbiff8a68c312013-02-10 14:28:30 -0500534 blankTimer.resetTimerAndUnblank();
LuK133762326f42015-09-30 19:57:46 +0200535 property_set("twrp.action_complete", "1");
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000536 time(&Stop);
bigbiff bigbiff3ed778a2019-03-12 19:28:31 -0400537
538#ifndef TW_NO_HAPTICS
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +0000539 if ((int) difftime(Stop, Start) > 10)
Ethan Yonker03db3262014-02-05 08:02:06 -0600540 DataManager::Vibrate("tw_action_vibrate");
bigbiff bigbiff3ed778a2019-03-12 19:28:31 -0400541#endif
542
that3f7b1ac2014-12-30 11:30:13 +0100543 LOGINFO("operation_end - status=%d\n", operation_status);
Dees_Troy51a0e822012-09-05 15:24:24 -0400544}
545
that3f7b1ac2014-12-30 11:30:13 +0100546int GUIAction::reboot(std::string arg)
Dees_Troy51a0e822012-09-05 15:24:24 -0400547{
that3f7b1ac2014-12-30 11:30:13 +0100548 sync();
549 DataManager::SetValue("tw_gui_done", 1);
550 DataManager::SetValue("tw_reboot_arg", arg);
Dees_Troy51a0e822012-09-05 15:24:24 -0400551
that3f7b1ac2014-12-30 11:30:13 +0100552 return 0;
553}
Dees_Troy51a0e822012-09-05 15:24:24 -0400554
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500555int GUIAction::home(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100556{
that3f7b1ac2014-12-30 11:30:13 +0100557 gui_changePage("main");
558 return 0;
559}
Dees_Troy51a0e822012-09-05 15:24:24 -0400560
that3f7b1ac2014-12-30 11:30:13 +0100561int GUIAction::key(std::string arg)
562{
563 const int key = getKeyByName(arg);
564 PageManager::NotifyKey(key, true);
565 PageManager::NotifyKey(key, false);
566 return 0;
567}
568
569int GUIAction::page(std::string arg)
570{
LuK133762326f42015-09-30 19:57:46 +0200571 property_set("twrp.action_complete", "0");
that3f7b1ac2014-12-30 11:30:13 +0100572 std::string page_name = gui_parse_text(arg);
573 return gui_changePage(page_name);
574}
575
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500576int GUIAction::reload(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100577{
Ethan Yonkere0f1f3b2015-10-27 09:49:01 -0500578 PageManager::RequestReload();
579 // The actual reload is handled in pages.cpp in PageManager::RunReload()
580 // The reload will occur on the next Update or Render call and will
581 // be performed in the rendoer thread instead of the action thread
582 // to prevent crashing which could occur when we start deleting
583 // GUI resources in the action thread while we attempt to render
584 // with those same resources in another thread.
that3f7b1ac2014-12-30 11:30:13 +0100585 return 0;
586}
Dees_Troy51a0e822012-09-05 15:24:24 -0400587
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500588int GUIAction::readBackup(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100589{
590 string Restore_Name;
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -0400591
that3f7b1ac2014-12-30 11:30:13 +0100592 DataManager::GetValue("tw_restore", Restore_Name);
593 PartitionManager.Set_Restore_Files(Restore_Name);
594 return 0;
595}
596
597int GUIAction::set(std::string arg)
598{
599 if (arg.find('=') != string::npos)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200600 {
that3f7b1ac2014-12-30 11:30:13 +0100601 string varName = arg.substr(0, arg.find('='));
602 string value = arg.substr(arg.find('=') + 1, string::npos);
Dees_Troy51a0e822012-09-05 15:24:24 -0400603
that3f7b1ac2014-12-30 11:30:13 +0100604 DataManager::GetValue(value, value);
605 DataManager::SetValue(varName, value);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200606 }
that3f7b1ac2014-12-30 11:30:13 +0100607 else
608 DataManager::SetValue(arg, "1");
609 return 0;
610}
Dees_Troy51a0e822012-09-05 15:24:24 -0400611
that3f7b1ac2014-12-30 11:30:13 +0100612int GUIAction::clear(std::string arg)
613{
614 DataManager::SetValue(arg, "0");
615 return 0;
616}
Dees_Troy51a0e822012-09-05 15:24:24 -0400617
that3f7b1ac2014-12-30 11:30:13 +0100618int GUIAction::mount(std::string arg)
619{
620 if (arg == "usb") {
621 DataManager::SetValue(TW_ACTION_BUSY, 1);
Dees_Troy51a0e822012-09-05 15:24:24 -0400622 if (!simulate)
that3f7b1ac2014-12-30 11:30:13 +0100623 PartitionManager.usb_storage_enable();
624 else
Ethan Yonker74db1572015-10-28 12:44:49 -0500625 gui_msg("simulating=Simulating actions...");
that3f7b1ac2014-12-30 11:30:13 +0100626 } else if (!simulate) {
627 PartitionManager.Mount_By_Path(arg, true);
628 PartitionManager.Add_MTP_Storage(arg);
629 } else
Ethan Yonker74db1572015-10-28 12:44:49 -0500630 gui_msg("simulating=Simulating actions...");
that3f7b1ac2014-12-30 11:30:13 +0100631 return 0;
632}
633
634int GUIAction::unmount(std::string arg)
635{
636 if (arg == "usb") {
637 if (!simulate)
638 PartitionManager.usb_storage_disable();
639 else
Ethan Yonker74db1572015-10-28 12:44:49 -0500640 gui_msg("simulating=Simulating actions...");
that3f7b1ac2014-12-30 11:30:13 +0100641 DataManager::SetValue(TW_ACTION_BUSY, 0);
642 } else if (!simulate) {
643 PartitionManager.UnMount_By_Path(arg, true);
644 } else
Ethan Yonker74db1572015-10-28 12:44:49 -0500645 gui_msg("simulating=Simulating actions...");
that3f7b1ac2014-12-30 11:30:13 +0100646 return 0;
647}
648
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500649int GUIAction::restoredefaultsettings(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100650{
651 operation_start("Restore Defaults");
652 if (simulate) // Simulated so that people don't accidently wipe out the "simulation is on" setting
Ethan Yonker74db1572015-10-28 12:44:49 -0500653 gui_msg("simulating=Simulating actions...");
that3f7b1ac2014-12-30 11:30:13 +0100654 else {
655 DataManager::ResetDefaults();
656 PartitionManager.Update_System_Details();
657 PartitionManager.Mount_Current_Storage(true);
658 }
659 operation_end(0);
660 return 0;
661}
662
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500663int GUIAction::copylog(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100664{
665 operation_start("Copy Log");
666 if (!simulate)
667 {
bigbiff bigbiffbad332a2016-07-29 21:18:13 -0400668 string dst, curr_storage;
669 int copy_kernel_log = 0;
670
671 DataManager::GetValue("tw_include_kernel_log", copy_kernel_log);
that3f7b1ac2014-12-30 11:30:13 +0100672 PartitionManager.Mount_Current_Storage(true);
bigbiff bigbiffbad332a2016-07-29 21:18:13 -0400673 curr_storage = DataManager::GetCurrentStoragePath();
674 dst = curr_storage + "/recovery.log";
that3f7b1ac2014-12-30 11:30:13 +0100675 TWFunc::copy_file("/tmp/recovery.log", dst.c_str(), 0755);
676 tw_set_default_metadata(dst.c_str());
bigbiff bigbiffbad332a2016-07-29 21:18:13 -0400677 if (copy_kernel_log)
678 TWFunc::copy_kernel_log(curr_storage);
that3f7b1ac2014-12-30 11:30:13 +0100679 sync();
bigbiff bigbiffbad332a2016-07-29 21:18:13 -0400680 gui_msg(Msg("copy_log=Copied recovery log to {1}")(dst));
that3f7b1ac2014-12-30 11:30:13 +0100681 } else
682 simulate_progress_bar();
683 operation_end(0);
684 return 0;
685}
686
687
688int GUIAction::compute(std::string arg)
689{
690 if (arg.find("+") != string::npos)
691 {
692 string varName = arg.substr(0, arg.find('+'));
693 string string_to_add = arg.substr(arg.find('+') + 1, string::npos);
694 int amount_to_add = atoi(string_to_add.c_str());
695 int value;
696
697 DataManager::GetValue(varName, value);
698 DataManager::SetValue(varName, value + amount_to_add);
Dees_Troy51a0e822012-09-05 15:24:24 -0400699 return 0;
700 }
that3f7b1ac2014-12-30 11:30:13 +0100701 if (arg.find("-") != string::npos)
Dees_Troy51a0e822012-09-05 15:24:24 -0400702 {
that3f7b1ac2014-12-30 11:30:13 +0100703 string varName = arg.substr(0, arg.find('-'));
704 string string_to_subtract = arg.substr(arg.find('-') + 1, string::npos);
705 int amount_to_subtract = atoi(string_to_subtract.c_str());
706 int value;
Dees_Troy51a0e822012-09-05 15:24:24 -0400707
that3f7b1ac2014-12-30 11:30:13 +0100708 DataManager::GetValue(varName, value);
709 value -= amount_to_subtract;
710 if (value <= 0)
711 value = 0;
712 DataManager::SetValue(varName, value);
713 return 0;
714 }
715 if (arg.find("*") != string::npos)
716 {
717 string varName = arg.substr(0, arg.find('*'));
718 string multiply_by_str = gui_parse_text(arg.substr(arg.find('*') + 1, string::npos));
719 int multiply_by = atoi(multiply_by_str.c_str());
720 int value;
721
722 DataManager::GetValue(varName, value);
723 DataManager::SetValue(varName, value*multiply_by);
724 return 0;
725 }
726 if (arg.find("/") != string::npos)
727 {
728 string varName = arg.substr(0, arg.find('/'));
729 string divide_by_str = gui_parse_text(arg.substr(arg.find('/') + 1, string::npos));
730 int divide_by = atoi(divide_by_str.c_str());
731 int value;
732
Matt Mowera8a89d12016-12-30 18:10:37 -0600733 if (divide_by != 0)
that3f7b1ac2014-12-30 11:30:13 +0100734 {
Dees_Troy51a0e822012-09-05 15:24:24 -0400735 DataManager::GetValue(varName, value);
that3f7b1ac2014-12-30 11:30:13 +0100736 DataManager::SetValue(varName, value/divide_by);
Dees_Troy51a0e822012-09-05 15:24:24 -0400737 }
738 return 0;
739 }
that3f7b1ac2014-12-30 11:30:13 +0100740 LOGERR("Unable to perform compute '%s'\n", arg.c_str());
741 return -1;
742}
Dees_Troy51a0e822012-09-05 15:24:24 -0400743
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500744int GUIAction::setguitimezone(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100745{
746 string SelectedZone;
747 DataManager::GetValue(TW_TIME_ZONE_GUISEL, SelectedZone); // read the selected time zone into SelectedZone
748 string Zone = SelectedZone.substr(0, SelectedZone.find(';')); // parse to get time zone
749 string DSTZone = SelectedZone.substr(SelectedZone.find(';') + 1, string::npos); // parse to get DST component
750
751 int dst;
752 DataManager::GetValue(TW_TIME_ZONE_GUIDST, dst); // check wether user chose to use DST
753
754 string offset;
755 DataManager::GetValue(TW_TIME_ZONE_GUIOFFSET, offset); // pull in offset
756
757 string NewTimeZone = Zone;
758 if (offset != "0")
759 NewTimeZone += ":" + offset;
760
761 if (dst != 0)
762 NewTimeZone += DSTZone;
763
764 DataManager::SetValue(TW_TIME_ZONE_VAR, NewTimeZone);
765 DataManager::update_tz_environment_variables();
766 return 0;
767}
768
769int GUIAction::overlay(std::string arg)
770{
771 return gui_changeOverlay(arg);
772}
773
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500774int GUIAction::queuezip(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100775{
776 if (zip_queue_index >= 10) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500777 gui_msg("max_queue=Maximum zip queue reached!");
Dees_Troy51a0e822012-09-05 15:24:24 -0400778 return 0;
779 }
that3f7b1ac2014-12-30 11:30:13 +0100780 DataManager::GetValue("tw_filename", zip_queue[zip_queue_index]);
781 if (strlen(zip_queue[zip_queue_index].c_str()) > 0) {
782 zip_queue_index++;
Dees_Troy51a0e822012-09-05 15:24:24 -0400783 DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
that3f7b1ac2014-12-30 11:30:13 +0100784 }
785 return 0;
786}
787
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500788int GUIAction::cancelzip(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100789{
790 if (zip_queue_index <= 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500791 gui_msg("min_queue=Minimum zip queue reached!");
Dees_Troy51a0e822012-09-05 15:24:24 -0400792 return 0;
that3f7b1ac2014-12-30 11:30:13 +0100793 } else {
794 zip_queue_index--;
795 DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
Dees_Troy51a0e822012-09-05 15:24:24 -0400796 }
that3f7b1ac2014-12-30 11:30:13 +0100797 return 0;
798}
Dees_Troy51a0e822012-09-05 15:24:24 -0400799
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500800int GUIAction::queueclear(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100801{
802 zip_queue_index = 0;
803 DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
804 return 0;
805}
Dees_Troy51a0e822012-09-05 15:24:24 -0400806
that3f7b1ac2014-12-30 11:30:13 +0100807int GUIAction::sleep(std::string arg)
808{
809 operation_start("Sleep");
810 usleep(atoi(arg.c_str()));
811 operation_end(0);
812 return 0;
813}
Dees Troyb21cc642013-09-10 17:36:41 +0000814
Matt Mower9a2a2052016-05-31 21:31:22 -0500815int GUIAction::sleepcounter(std::string arg)
816{
817 operation_start("SleepCounter");
818 // Ensure user notices countdown in case it needs to be cancelled
819 blankTimer.resetTimerAndUnblank();
820 int total = atoi(arg.c_str());
821 for (int t = total; t > 0; t--) {
822 int progress = (int)(((float)(total-t)/(float)total)*100.0);
823 DataManager::SetValue("ui_progress", progress);
824 ::sleep(1);
825 DataManager::SetValue("tw_sleep", t-1);
826 }
827 DataManager::SetValue("ui_progress", 100);
828 operation_end(0);
829 return 0;
830}
831
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500832int GUIAction::appenddatetobackupname(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100833{
834 operation_start("AppendDateToBackupName");
835 string Backup_Name;
836 DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
837 Backup_Name += TWFunc::Get_Current_Date();
838 if (Backup_Name.size() > MAX_BACKUP_NAME_LEN)
839 Backup_Name.resize(MAX_BACKUP_NAME_LEN);
840 DataManager::SetValue(TW_BACKUP_NAME, Backup_Name);
Matt Mower76b8afc2016-06-24 12:04:27 -0500841 PageManager::NotifyKey(KEY_END, true);
842 PageManager::NotifyKey(KEY_END, false);
that3f7b1ac2014-12-30 11:30:13 +0100843 operation_end(0);
844 return 0;
845}
Ethan Yonker87c7bac2014-05-25 21:41:08 -0500846
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500847int GUIAction::generatebackupname(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100848{
849 operation_start("GenerateBackupName");
850 TWFunc::Auto_Generate_Backup_Name();
851 operation_end(0);
852 return 0;
853}
Ethan Yonker87c7bac2014-05-25 21:41:08 -0500854
Ethan Yonker483e9f42016-01-11 22:21:18 -0600855int GUIAction::checkpartitionlist(std::string arg)
that3f7b1ac2014-12-30 11:30:13 +0100856{
Ethan Yonker483e9f42016-01-11 22:21:18 -0600857 string List, part_path;
that3f7b1ac2014-12-30 11:30:13 +0100858 int count = 0;
Ethan Yonker87c7bac2014-05-25 21:41:08 -0500859
Ethan Yonker483e9f42016-01-11 22:21:18 -0600860 if (arg.empty())
861 arg = "tw_wipe_list";
862 DataManager::GetValue(arg, List);
863 LOGINFO("checkpartitionlist list '%s'\n", List.c_str());
864 if (!List.empty()) {
865 size_t start_pos = 0, end_pos = List.find(";", start_pos);
866 while (end_pos != string::npos && start_pos < List.size()) {
867 part_path = List.substr(start_pos, end_pos - start_pos);
868 LOGINFO("checkpartitionlist part_path '%s'\n", part_path.c_str());
869 if (part_path == "/and-sec" || part_path == "DALVIK" || part_path == "INTERNAL") {
that3f7b1ac2014-12-30 11:30:13 +0100870 // Do nothing
Dees_Troy51a0e822012-09-05 15:24:24 -0400871 } else {
that3f7b1ac2014-12-30 11:30:13 +0100872 count++;
873 }
874 start_pos = end_pos + 1;
Ethan Yonker483e9f42016-01-11 22:21:18 -0600875 end_pos = List.find(";", start_pos);
that3f7b1ac2014-12-30 11:30:13 +0100876 }
877 DataManager::SetValue("tw_check_partition_list", count);
878 } else {
879 DataManager::SetValue("tw_check_partition_list", 0);
880 }
Matt Mowera8a89d12016-12-30 18:10:37 -0600881 return 0;
that3f7b1ac2014-12-30 11:30:13 +0100882}
Dees_Troy51a0e822012-09-05 15:24:24 -0400883
Ethan Yonker483e9f42016-01-11 22:21:18 -0600884int GUIAction::getpartitiondetails(std::string arg)
that3f7b1ac2014-12-30 11:30:13 +0100885{
Ethan Yonker483e9f42016-01-11 22:21:18 -0600886 string List, part_path;
Dees_Troy51a0e822012-09-05 15:24:24 -0400887
Ethan Yonker483e9f42016-01-11 22:21:18 -0600888 if (arg.empty())
889 arg = "tw_wipe_list";
890 DataManager::GetValue(arg, List);
891 LOGINFO("getpartitiondetails list '%s'\n", List.c_str());
892 if (!List.empty()) {
893 size_t start_pos = 0, end_pos = List.find(";", start_pos);
894 part_path = List;
895 while (end_pos != string::npos && start_pos < List.size()) {
896 part_path = List.substr(start_pos, end_pos - start_pos);
897 LOGINFO("getpartitiondetails part_path '%s'\n", part_path.c_str());
898 if (part_path == "/and-sec" || part_path == "DALVIK" || part_path == "INTERNAL") {
that3f7b1ac2014-12-30 11:30:13 +0100899 // Do nothing
900 } else {
Ethan Yonker483e9f42016-01-11 22:21:18 -0600901 DataManager::SetValue("tw_partition_path", part_path);
that3f7b1ac2014-12-30 11:30:13 +0100902 break;
903 }
904 start_pos = end_pos + 1;
Ethan Yonker483e9f42016-01-11 22:21:18 -0600905 end_pos = List.find(";", start_pos);
that3f7b1ac2014-12-30 11:30:13 +0100906 }
Ethan Yonker483e9f42016-01-11 22:21:18 -0600907 if (!part_path.empty()) {
908 TWPartition* Part = PartitionManager.Find_Partition_By_Path(part_path);
that3f7b1ac2014-12-30 11:30:13 +0100909 if (Part) {
910 unsigned long long mb = 1048576;
Dees_Troya13d74f2013-03-24 08:54:55 -0500911
that3f7b1ac2014-12-30 11:30:13 +0100912 DataManager::SetValue("tw_partition_name", Part->Display_Name);
913 DataManager::SetValue("tw_partition_mount_point", Part->Mount_Point);
914 DataManager::SetValue("tw_partition_file_system", Part->Current_File_System);
915 DataManager::SetValue("tw_partition_size", Part->Size / mb);
916 DataManager::SetValue("tw_partition_used", Part->Used / mb);
917 DataManager::SetValue("tw_partition_free", Part->Free / mb);
918 DataManager::SetValue("tw_partition_backup_size", Part->Backup_Size / mb);
919 DataManager::SetValue("tw_partition_removable", Part->Removable);
920 DataManager::SetValue("tw_partition_is_present", Part->Is_Present);
921
922 if (Part->Can_Repair())
923 DataManager::SetValue("tw_partition_can_repair", 1);
924 else
925 DataManager::SetValue("tw_partition_can_repair", 0);
Ethan Yonkera2719152015-05-28 09:44:41 -0500926 if (Part->Can_Resize())
927 DataManager::SetValue("tw_partition_can_resize", 1);
928 else
929 DataManager::SetValue("tw_partition_can_resize", 0);
bigbiffad58e1b2020-07-06 20:24:34 -0400930 if (TWFunc::Path_Exists("/system/bin/mkfs.fat"))
that3f7b1ac2014-12-30 11:30:13 +0100931 DataManager::SetValue("tw_partition_vfat", 1);
932 else
933 DataManager::SetValue("tw_partition_vfat", 0);
bigbiffad58e1b2020-07-06 20:24:34 -0400934 if (TWFunc::Path_Exists("/system/bin/mkexfatfs"))
that3f7b1ac2014-12-30 11:30:13 +0100935 DataManager::SetValue("tw_partition_exfat", 1);
936 else
937 DataManager::SetValue("tw_partition_exfat", 0);
whylef06b1652020-11-22 00:25:18 +0100938 if (TWFunc::Path_Exists("/system/bin/mkfs.f2fs") || TWFunc::Path_Exists("/system/bin/make_f2fs"))
that3f7b1ac2014-12-30 11:30:13 +0100939 DataManager::SetValue("tw_partition_f2fs", 1);
940 else
941 DataManager::SetValue("tw_partition_f2fs", 0);
bigbiffad58e1b2020-07-06 20:24:34 -0400942 if (TWFunc::Path_Exists("/system/bin/mke2fs"))
that3f7b1ac2014-12-30 11:30:13 +0100943 DataManager::SetValue("tw_partition_ext", 1);
944 else
945 DataManager::SetValue("tw_partition_ext", 0);
946 return 0;
947 } else {
Ethan Yonker483e9f42016-01-11 22:21:18 -0600948 LOGERR("Unable to locate partition: '%s'\n", part_path.c_str());
that3f7b1ac2014-12-30 11:30:13 +0100949 }
950 }
951 }
952 DataManager::SetValue("tw_partition_name", "");
953 DataManager::SetValue("tw_partition_file_system", "");
Ethan Yonker483e9f42016-01-11 22:21:18 -0600954 // Set this to 0 to prevent trying to partition this device, just in case
955 DataManager::SetValue("tw_partition_removable", 0);
that3f7b1ac2014-12-30 11:30:13 +0100956 return 0;
957}
958
Ethan Yonkerd0514ba2015-10-22 14:17:47 -0500959int GUIAction::screenshot(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +0100960{
961 time_t tm;
962 char path[256];
963 int path_len;
Matt Mower0c88b842017-01-15 16:00:49 -0600964 uid_t uid = AID_MEDIA_RW;
965 gid_t gid = AID_MEDIA_RW;
that3f7b1ac2014-12-30 11:30:13 +0100966
967 const std::string storage = DataManager::GetCurrentStoragePath();
Matt Mowera8a89d12016-12-30 18:10:37 -0600968 if (PartitionManager.Is_Mounted_By_Path(storage)) {
that3f7b1ac2014-12-30 11:30:13 +0100969 snprintf(path, sizeof(path), "%s/Pictures/Screenshots/", storage.c_str());
970 } else {
971 strcpy(path, "/tmp/");
972 }
973
Matt Mowera8a89d12016-12-30 18:10:37 -0600974 if (!TWFunc::Create_Dir_Recursive(path, 0775, uid, gid))
that3f7b1ac2014-12-30 11:30:13 +0100975 return 0;
976
977 tm = time(NULL);
978 path_len = strlen(path);
979
980 // Screenshot_2014-01-01-18-21-38.png
981 strftime(path+path_len, sizeof(path)-path_len, "Screenshot_%Y-%m-%d-%H-%M-%S.png", localtime(&tm));
982
983 int res = gr_save_screenshot(path);
Matt Mowera8a89d12016-12-30 18:10:37 -0600984 if (res == 0) {
that3f7b1ac2014-12-30 11:30:13 +0100985 chmod(path, 0666);
986 chown(path, uid, gid);
987
that677b13f2015-12-26 23:57:31 +0100988 gui_msg(Msg("screenshot_saved=Screenshot was saved to {1}")(path));
that3f7b1ac2014-12-30 11:30:13 +0100989
VDavid0032034a412019-10-18 22:43:20 +0200990 // blink to notify that the screenshot was taken
that3f7b1ac2014-12-30 11:30:13 +0100991 gr_color(255, 255, 255, 255);
992 gr_fill(0, 0, gr_fb_width(), gr_fb_height());
993 gr_flip();
994 gui_forceRender();
995 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500996 gui_err("screenshot_err=Failed to take a screenshot!");
that3f7b1ac2014-12-30 11:30:13 +0100997 }
998 return 0;
999}
1000
1001int GUIAction::setbrightness(std::string arg)
1002{
1003 return TWFunc::Set_Brightness(arg);
1004}
1005
1006int GUIAction::fileexists(std::string arg)
1007{
1008 struct stat st;
1009 string newpath = arg + "/.";
1010
1011 operation_start("FileExists");
1012 if (stat(arg.c_str(), &st) == 0 || stat(newpath.c_str(), &st) == 0)
1013 operation_end(0);
1014 else
1015 operation_end(1);
1016 return 0;
1017}
1018
thatcc8ddca2015-01-03 01:59:36 +01001019void GUIAction::reinject_after_flash()
1020{
1021 if (DataManager::GetIntValue(TW_HAS_INJECTTWRP) == 1 && DataManager::GetIntValue(TW_INJECT_AFTER_ZIP) == 1) {
Ethan Yonker74db1572015-10-28 12:44:49 -05001022 gui_msg("injecttwrp=Injecting TWRP into boot image...");
thatcc8ddca2015-01-03 01:59:36 +01001023 if (simulate) {
1024 simulate_progress_bar();
1025 } else {
1026 TWPartition* Boot = PartitionManager.Find_Partition_By_Path("/boot");
1027 if (Boot == NULL || Boot->Current_File_System != "emmc")
1028 TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
1029 else {
1030 string injectcmd = "injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash bd=" + Boot->Actual_Block_Device;
1031 TWFunc::Exec_Cmd(injectcmd);
1032 }
Ethan Yonker74db1572015-10-28 12:44:49 -05001033 gui_msg("done=Done.");
thatcc8ddca2015-01-03 01:59:36 +01001034 }
1035 }
1036}
1037
mauronofrio6d3bf892019-10-26 19:47:55 +02001038int GUIAction::ozip_decrypt(string zip_path)
1039{
bigbiffad58e1b2020-07-06 20:24:34 -04001040 if (!TWFunc::Path_Exists("/system/bin/ozip_decrypt")) {
mauronofrio6d3bf892019-10-26 19:47:55 +02001041 return 1;
1042 }
1043 gui_msg("ozip_decrypt_decryption=Starting Ozip Decryption...");
1044 TWFunc::Exec_Cmd("ozip_decrypt " + (string)TW_OZIP_DECRYPT_KEY + " '" + zip_path + "'");
1045 gui_msg("ozip_decrypt_finish=Ozip Decryption Finished!");
1046 return 0;
1047}
1048
that3f7b1ac2014-12-30 11:30:13 +01001049int GUIAction::flash(std::string arg)
1050{
1051 int i, ret_val = 0, wipe_cache = 0;
Ethan Yonker0d47eb52015-01-09 11:23:19 -06001052 // We're going to jump to this page first, like a loading page
1053 gui_changePage(arg);
that3f7b1ac2014-12-30 11:30:13 +01001054 for (i=0; i<zip_queue_index; i++) {
thatc7b631b2015-06-01 23:36:57 +02001055 string zip_path = zip_queue[i];
1056 size_t slashpos = zip_path.find_last_of('/');
1057 string zip_filename = (slashpos == string::npos) ? zip_path : zip_path.substr(slashpos + 1);
that3f7b1ac2014-12-30 11:30:13 +01001058 operation_start("Flashing");
mauronofrio6d3bf892019-10-26 19:47:55 +02001059 if((zip_path.substr(zip_path.size() - 4, 4)) == "ozip")
1060 {
1061 if((ozip_decrypt(zip_path)) != 0)
1062 {
1063 LOGERR("Unable to find ozip_decrypt!");
1064 break;
1065 }
1066 zip_filename = (zip_filename.substr(0, zip_filename.size() - 4)).append("zip");
1067 zip_path = (zip_path.substr(0, zip_path.size() - 4)).append("zip");
1068 if (!TWFunc::Path_Exists(zip_path)) {
1069 LOGERR("Unable to find decrypted zip");
1070 break;
1071 }
1072 }
thatc7b631b2015-06-01 23:36:57 +02001073 DataManager::SetValue("tw_filename", zip_path);
1074 DataManager::SetValue("tw_file", zip_filename);
that3f7b1ac2014-12-30 11:30:13 +01001075 DataManager::SetValue(TW_ZIP_INDEX, (i + 1));
1076
1077 TWFunc::SetPerformanceMode(true);
thatc7b631b2015-06-01 23:36:57 +02001078 ret_val = flash_zip(zip_path, &wipe_cache);
that3f7b1ac2014-12-30 11:30:13 +01001079 TWFunc::SetPerformanceMode(false);
1080 if (ret_val != 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -05001081 gui_msg(Msg(msg::kError, "zip_err=Error installing zip file '{1}'")(zip_path));
that3f7b1ac2014-12-30 11:30:13 +01001082 ret_val = 1;
Ethan Yonker0d47eb52015-01-09 11:23:19 -06001083 break;
that3f7b1ac2014-12-30 11:30:13 +01001084 }
1085 }
1086 zip_queue_index = 0;
that3f7b1ac2014-12-30 11:30:13 +01001087
Ethan Yonker0d47eb52015-01-09 11:23:19 -06001088 if (wipe_cache) {
Ethan Yonker74db1572015-10-28 12:44:49 -05001089 gui_msg("zip_wipe_cache=One or more zip requested a cache wipe -- Wiping cache now.");
that3f7b1ac2014-12-30 11:30:13 +01001090 PartitionManager.Wipe_By_Path("/cache");
Ethan Yonker0d47eb52015-01-09 11:23:19 -06001091 }
that3f7b1ac2014-12-30 11:30:13 +01001092
thatcc8ddca2015-01-03 01:59:36 +01001093 reinject_after_flash();
that3f7b1ac2014-12-30 11:30:13 +01001094 PartitionManager.Update_System_Details();
1095 operation_end(ret_val);
bigbiffa869fc72016-03-01 19:40:36 -05001096 // This needs to be after the operation_end call so we change pages before we change variables that we display on the screen
Ethan Yonker0d47eb52015-01-09 11:23:19 -06001097 DataManager::SetValue(TW_ZIP_QUEUE_COUNT, zip_queue_index);
that3f7b1ac2014-12-30 11:30:13 +01001098 return 0;
1099}
1100
1101int GUIAction::wipe(std::string arg)
1102{
1103 operation_start("Format");
1104 DataManager::SetValue("tw_partition", arg);
that3f7b1ac2014-12-30 11:30:13 +01001105 int ret_val = false;
1106
1107 if (simulate) {
1108 simulate_progress_bar();
1109 } else {
1110 if (arg == "data")
1111 ret_val = PartitionManager.Factory_Reset();
1112 else if (arg == "battery")
1113 ret_val = PartitionManager.Wipe_Battery_Stats();
1114 else if (arg == "rotate")
1115 ret_val = PartitionManager.Wipe_Rotate_Data();
1116 else if (arg == "dalvik")
1117 ret_val = PartitionManager.Wipe_Dalvik_Cache();
1118 else if (arg == "DATAMEDIA") {
1119 ret_val = PartitionManager.Format_Data();
1120 } else if (arg == "INTERNAL") {
Matt Mower23d8aae2017-01-06 14:30:33 -06001121 int has_datamedia;
that3f7b1ac2014-12-30 11:30:13 +01001122
1123 DataManager::GetValue(TW_HAS_DATA_MEDIA, has_datamedia);
1124 if (has_datamedia) {
1125 ret_val = PartitionManager.Wipe_Media_From_Data();
1126 } else {
1127 ret_val = PartitionManager.Wipe_By_Path(DataManager::GetSettingsStoragePath());
1128 }
1129 } else if (arg == "EXTERNAL") {
1130 string External_Path;
1131
1132 DataManager::GetValue(TW_EXTERNAL_PATH, External_Path);
1133 ret_val = PartitionManager.Wipe_By_Path(External_Path);
1134 } else if (arg == "ANDROIDSECURE") {
1135 ret_val = PartitionManager.Wipe_Android_Secure();
1136 } else if (arg == "LIST") {
1137 string Wipe_List, wipe_path;
1138 bool skip = false;
1139 ret_val = true;
that3f7b1ac2014-12-30 11:30:13 +01001140
1141 DataManager::GetValue("tw_wipe_list", Wipe_List);
1142 LOGINFO("wipe list '%s'\n", Wipe_List.c_str());
1143 if (!Wipe_List.empty()) {
1144 size_t start_pos = 0, end_pos = Wipe_List.find(";", start_pos);
1145 while (end_pos != string::npos && start_pos < Wipe_List.size()) {
1146 wipe_path = Wipe_List.substr(start_pos, end_pos - start_pos);
1147 LOGINFO("wipe_path '%s'\n", wipe_path.c_str());
1148 if (wipe_path == "/and-sec") {
1149 if (!PartitionManager.Wipe_Android_Secure()) {
Ethan Yonker74db1572015-10-28 12:44:49 -05001150 gui_msg("and_sec_wipe_err=Unable to wipe android secure");
that3f7b1ac2014-12-30 11:30:13 +01001151 ret_val = false;
1152 break;
1153 } else {
1154 skip = true;
1155 }
1156 } else if (wipe_path == "DALVIK") {
1157 if (!PartitionManager.Wipe_Dalvik_Cache()) {
Ethan Yonker74db1572015-10-28 12:44:49 -05001158 gui_err("dalvik_wipe_err=Failed to wipe dalvik");
that3f7b1ac2014-12-30 11:30:13 +01001159 ret_val = false;
1160 break;
1161 } else {
1162 skip = true;
1163 }
1164 } else if (wipe_path == "INTERNAL") {
1165 if (!PartitionManager.Wipe_Media_From_Data()) {
1166 ret_val = false;
1167 break;
1168 } else {
1169 skip = true;
Dees_Troya13d74f2013-03-24 08:54:55 -05001170 }
1171 }
that3f7b1ac2014-12-30 11:30:13 +01001172 if (!skip) {
1173 if (!PartitionManager.Wipe_By_Path(wipe_path)) {
Ethan Yonker74db1572015-10-28 12:44:49 -05001174 gui_msg(Msg(msg::kError, "unable_to_wipe=Unable to wipe {1}.")(wipe_path));
that3f7b1ac2014-12-30 11:30:13 +01001175 ret_val = false;
1176 break;
1177 } else if (wipe_path == DataManager::GetSettingsStoragePath()) {
1178 arg = wipe_path;
1179 }
Dees_Troy38bd7602012-09-14 13:33:53 -04001180 } else {
that3f7b1ac2014-12-30 11:30:13 +01001181 skip = false;
Dees_Troy38bd7602012-09-14 13:33:53 -04001182 }
that3f7b1ac2014-12-30 11:30:13 +01001183 start_pos = end_pos + 1;
1184 end_pos = Wipe_List.find(";", start_pos);
Dees_Troy51a0e822012-09-05 15:24:24 -04001185 }
1186 }
that3f7b1ac2014-12-30 11:30:13 +01001187 } else
1188 ret_val = PartitionManager.Wipe_By_Path(arg);
that73a52952015-01-28 23:07:34 +01001189#ifndef TW_OEM_BUILD
that3f7b1ac2014-12-30 11:30:13 +01001190 if (arg == DataManager::GetSettingsStoragePath()) {
1191 // If we wiped the settings storage path, recreate the TWRP folder and dump the settings
1192 string Storage_Path = DataManager::GetSettingsStoragePath();
Dees_Troy51a0e822012-09-05 15:24:24 -04001193
that3f7b1ac2014-12-30 11:30:13 +01001194 if (PartitionManager.Mount_By_Path(Storage_Path, true)) {
1195 LOGINFO("Making TWRP folder and saving settings.\n");
1196 Storage_Path += "/TWRP";
1197 mkdir(Storage_Path.c_str(), 0777);
1198 DataManager::Flush();
Dees_Troy51a0e822012-09-05 15:24:24 -04001199 } else {
that3f7b1ac2014-12-30 11:30:13 +01001200 LOGERR("Unable to recreate TWRP folder and save settings.\n");
1201 }
1202 }
1203#endif
1204 }
1205 PartitionManager.Update_System_Details();
1206 if (ret_val)
1207 ret_val = 0; // 0 is success
1208 else
1209 ret_val = 1; // 1 is failure
1210 operation_end(ret_val);
1211 return 0;
1212}
Samer Diab (S.a.M.e.R_d)71e9b042014-01-07 20:18:47 +00001213
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001214int GUIAction::refreshsizes(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001215{
1216 operation_start("Refreshing Sizes");
1217 if (simulate) {
1218 simulate_progress_bar();
1219 } else
1220 PartitionManager.Update_System_Details();
1221 operation_end(0);
1222 return 0;
1223}
1224
1225int GUIAction::nandroid(std::string arg)
1226{
that3f7b1ac2014-12-30 11:30:13 +01001227 if (simulate) {
that73a52952015-01-28 23:07:34 +01001228 PartitionManager.stop_backup.set_value(0);
that3f7b1ac2014-12-30 11:30:13 +01001229 DataManager::SetValue("tw_partition", "Simulation");
1230 simulate_progress_bar();
that73a52952015-01-28 23:07:34 +01001231 operation_end(0);
that3f7b1ac2014-12-30 11:30:13 +01001232 } else {
bigbiff7abc5fe2015-01-17 16:53:12 -05001233 operation_start("Nandroid");
1234 int ret = 0;
1235
that3f7b1ac2014-12-30 11:30:13 +01001236 if (arg == "backup") {
1237 string Backup_Name;
1238 DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
Ethan Yonker4adc33e2016-01-22 16:07:11 -06001239 string auto_gen = gui_lookup("auto_generate", "(Auto Generate)");
Ethan Yonker53796e72019-01-11 22:49:52 -06001240 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) {
bigbiffce8f83c2015-12-12 18:30:21 -05001241 ret = PartitionManager.Run_Backup(false);
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -04001242 DataManager::SetValue("tw_encrypt_backup", 0); // reset value so we don't encrypt every subsequent backup
1243 if (!PartitionManager.stop_backup.get_value()) {
1244 if (ret == false)
1245 ret = 1; // 1 for failure
1246 else
1247 ret = 0; // 0 for success
1248 DataManager::SetValue("tw_cancel_backup", 0);
1249 } else {
1250 DataManager::SetValue("tw_cancel_backup", 1);
1251 gui_msg("backup_cancel=Backup Cancelled");
1252 ret = 0;
1253 }
bigbiffce8f83c2015-12-12 18:30:21 -05001254 } else {
that3f7b1ac2014-12-30 11:30:13 +01001255 operation_end(1);
1256 return -1;
that3f7b1ac2014-12-30 11:30:13 +01001257 }
Ethan Yonker74db1572015-10-28 12:44:49 -05001258 DataManager::SetValue(TW_BACKUP_NAME, auto_gen);
that3f7b1ac2014-12-30 11:30:13 +01001259 } else if (arg == "restore") {
1260 string Restore_Name;
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -04001261 int gui_adb_backup;
1262
that3f7b1ac2014-12-30 11:30:13 +01001263 DataManager::GetValue("tw_restore", Restore_Name);
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -04001264 DataManager::GetValue("tw_enable_adb_backup", gui_adb_backup);
1265 if (gui_adb_backup) {
1266 DataManager::SetValue("tw_operation_state", 1);
1267 if (TWFunc::stream_adb_backup(Restore_Name) == 0)
1268 ret = 0; // success
1269 else
1270 ret = 1; // failure
1271 DataManager::SetValue("tw_enable_adb_backup", 0);
1272 ret = 0; // assume success???
1273 } else {
1274 if (PartitionManager.Run_Restore(Restore_Name))
1275 ret = 0; // success
1276 else
1277 ret = 1; // failure
1278 }
that3f7b1ac2014-12-30 11:30:13 +01001279 } else {
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -04001280 operation_end(1); // invalid arg specified, fail
bigbiff7abc5fe2015-01-17 16:53:12 -05001281 return -1;
1282 }
that73a52952015-01-28 23:07:34 +01001283 operation_end(ret);
bigbiff7abc5fe2015-01-17 16:53:12 -05001284 return ret;
1285 }
1286 return 0;
1287}
1288
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001289int GUIAction::cancelbackup(std::string arg __unused) {
bigbiff7abc5fe2015-01-17 16:53:12 -05001290 if (simulate) {
bigbiff7abc5fe2015-01-17 16:53:12 -05001291 PartitionManager.stop_backup.set_value(1);
bigbiff7abc5fe2015-01-17 16:53:12 -05001292 }
1293 else {
bigbiff7abc5fe2015-01-17 16:53:12 -05001294 int op_status = PartitionManager.Cancel_Backup();
1295 if (op_status != 0)
1296 op_status = 1; // failure
bigbiff7abc5fe2015-01-17 16:53:12 -05001297 }
1298
1299 return 0;
that3f7b1ac2014-12-30 11:30:13 +01001300}
Dees_Troy51a0e822012-09-05 15:24:24 -04001301
Ethan Yonkerb5fab762016-01-28 14:03:33 -06001302int GUIAction::fixcontexts(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001303{
that73a52952015-01-28 23:07:34 +01001304 int op_status = 0;
1305
Ethan Yonkerb5fab762016-01-28 14:03:33 -06001306 operation_start("Fix Contexts");
1307 LOGINFO("fix contexts started!\n");
that3f7b1ac2014-12-30 11:30:13 +01001308 if (simulate) {
1309 simulate_progress_bar();
1310 } else {
Ethan Yonkerb5fab762016-01-28 14:03:33 -06001311 op_status = PartitionManager.Fix_Contexts();
that3f7b1ac2014-12-30 11:30:13 +01001312 if (op_status != 0)
1313 op_status = 1; // failure
that3f7b1ac2014-12-30 11:30:13 +01001314 }
that73a52952015-01-28 23:07:34 +01001315 operation_end(op_status);
that3f7b1ac2014-12-30 11:30:13 +01001316 return 0;
1317}
1318
Ethan Yonkerb5fab762016-01-28 14:03:33 -06001319int GUIAction::fixpermissions(std::string arg)
1320{
1321 return fixcontexts(arg);
1322}
1323
that3f7b1ac2014-12-30 11:30:13 +01001324int GUIAction::dd(std::string arg)
1325{
1326 operation_start("imaging");
1327
1328 if (simulate) {
1329 simulate_progress_bar();
1330 } else {
1331 string cmd = "dd " + arg;
1332 TWFunc::Exec_Cmd(cmd);
1333 }
1334 operation_end(0);
1335 return 0;
1336}
1337
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001338int GUIAction::partitionsd(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001339{
1340 operation_start("Partition SD Card");
1341 int ret_val = 0;
1342
1343 if (simulate) {
1344 simulate_progress_bar();
1345 } else {
1346 int allow_partition;
1347 DataManager::GetValue(TW_ALLOW_PARTITION_SDCARD, allow_partition);
1348 if (allow_partition == 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -05001349 gui_err("no_real_sdcard=This device does not have a real SD Card! Aborting!");
that3f7b1ac2014-12-30 11:30:13 +01001350 } else {
1351 if (!PartitionManager.Partition_SDCard())
1352 ret_val = 1; // failed
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001353 }
that3f7b1ac2014-12-30 11:30:13 +01001354 }
1355 operation_end(ret_val);
1356 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -04001357
that3f7b1ac2014-12-30 11:30:13 +01001358}
Dees_Troy51a0e822012-09-05 15:24:24 -04001359
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001360int GUIAction::installhtcdumlock(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001361{
1362 operation_start("Install HTC Dumlock");
1363 if (simulate) {
1364 simulate_progress_bar();
1365 } else
1366 TWFunc::install_htc_dumlock();
Dees_Troy51a0e822012-09-05 15:24:24 -04001367
that3f7b1ac2014-12-30 11:30:13 +01001368 operation_end(0);
1369 return 0;
1370}
Dees_Troy51a0e822012-09-05 15:24:24 -04001371
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001372int GUIAction::htcdumlockrestoreboot(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001373{
1374 operation_start("HTC Dumlock Restore Boot");
1375 if (simulate) {
1376 simulate_progress_bar();
1377 } else
1378 TWFunc::htc_dumlock_restore_original_boot();
Dees_Troy51a0e822012-09-05 15:24:24 -04001379
that3f7b1ac2014-12-30 11:30:13 +01001380 operation_end(0);
1381 return 0;
1382}
Dees_Troy51a0e822012-09-05 15:24:24 -04001383
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001384int GUIAction::htcdumlockreflashrecovery(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001385{
1386 operation_start("HTC Dumlock Reflash Recovery");
1387 if (simulate) {
1388 simulate_progress_bar();
1389 } else
1390 TWFunc::htc_dumlock_reflash_recovery_to_boot();
Dees_Troy51a0e822012-09-05 15:24:24 -04001391
that3f7b1ac2014-12-30 11:30:13 +01001392 operation_end(0);
1393 return 0;
1394}
Dees_Troy51a0e822012-09-05 15:24:24 -04001395
that3f7b1ac2014-12-30 11:30:13 +01001396int GUIAction::cmd(std::string arg)
1397{
1398 int op_status = 0;
1399
1400 operation_start("Command");
1401 LOGINFO("Running command: '%s'\n", arg.c_str());
1402 if (simulate) {
1403 simulate_progress_bar();
1404 } else {
1405 op_status = TWFunc::Exec_Cmd(arg);
1406 if (op_status != 0)
1407 op_status = 1;
1408 }
1409
1410 operation_end(op_status);
1411 return 0;
1412}
1413
1414int GUIAction::terminalcommand(std::string arg)
1415{
1416 int op_status = 0;
1417 string cmdpath, command;
1418
1419 DataManager::GetValue("tw_terminal_location", cmdpath);
1420 operation_start("CommandOutput");
1421 gui_print("%s # %s\n", cmdpath.c_str(), arg.c_str());
1422 if (simulate) {
1423 simulate_progress_bar();
1424 operation_end(op_status);
Matt Mower5aa29ab2015-02-25 23:50:55 -06001425 } else if (arg == "exit") {
1426 LOGINFO("Exiting terminal\n");
1427 operation_end(op_status);
1428 page("main");
that3f7b1ac2014-12-30 11:30:13 +01001429 } else {
1430 command = "cd \"" + cmdpath + "\" && " + arg + " 2>&1";;
1431 LOGINFO("Actual command is: '%s'\n", command.c_str());
that3f7b1ac2014-12-30 11:30:13 +01001432 DataManager::SetValue("tw_terminal_state", 1);
1433 DataManager::SetValue("tw_background_thread_running", 1);
thatc6085482015-01-09 22:12:43 +01001434 FILE* fp;
1435 char line[512];
1436
1437 fp = popen(command.c_str(), "r");
1438 if (fp == NULL) {
Ethan Yonker74db1572015-10-28 12:44:49 -05001439 LOGERR("Error opening command to run (%s).\n", strerror(errno));
thatc6085482015-01-09 22:12:43 +01001440 } else {
Matt Mower23d8aae2017-01-06 14:30:33 -06001441 int fd = fileno(fp), has_data = 0, check = 0, keep_going = -1;
thatc6085482015-01-09 22:12:43 +01001442 struct timeval timeout;
1443 fd_set fdset;
1444
Matt Mowera8a89d12016-12-30 18:10:37 -06001445 while (keep_going)
thatc6085482015-01-09 22:12:43 +01001446 {
1447 FD_ZERO(&fdset);
1448 FD_SET(fd, &fdset);
1449 timeout.tv_sec = 0;
1450 timeout.tv_usec = 400000;
1451 has_data = select(fd+1, &fdset, NULL, NULL, &timeout);
1452 if (has_data == 0) {
1453 // Timeout reached
1454 DataManager::GetValue("tw_terminal_state", check);
1455 if (check == 0) {
1456 keep_going = 0;
1457 }
1458 } else if (has_data < 0) {
1459 // End of execution
1460 keep_going = 0;
1461 } else {
1462 // Try to read output
Matt Mowera8a89d12016-12-30 18:10:37 -06001463 if (fgets(line, sizeof(line), fp) != NULL)
thatc6085482015-01-09 22:12:43 +01001464 gui_print("%s", line); // Display output
1465 else
1466 keep_going = 0; // Done executing
1467 }
1468 }
1469 fclose(fp);
Dees_Troy51a0e822012-09-05 15:24:24 -04001470 }
thatc6085482015-01-09 22:12:43 +01001471 DataManager::SetValue("tw_operation_status", 0);
1472 DataManager::SetValue("tw_operation_state", 1);
1473 DataManager::SetValue("tw_terminal_state", 0);
1474 DataManager::SetValue("tw_background_thread_running", 0);
1475 DataManager::SetValue(TW_ACTION_BUSY, 0);
that3f7b1ac2014-12-30 11:30:13 +01001476 }
1477 return 0;
1478}
1479
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001480int GUIAction::killterminal(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001481{
that3f7b1ac2014-12-30 11:30:13 +01001482 LOGINFO("Sending kill command...\n");
1483 operation_start("KillCommand");
1484 DataManager::SetValue("tw_operation_status", 0);
1485 DataManager::SetValue("tw_operation_state", 1);
1486 DataManager::SetValue("tw_terminal_state", 0);
1487 DataManager::SetValue("tw_background_thread_running", 0);
1488 DataManager::SetValue(TW_ACTION_BUSY, 0);
1489 return 0;
1490}
1491
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001492int GUIAction::reinjecttwrp(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001493{
1494 int op_status = 0;
1495 operation_start("ReinjectTWRP");
Ethan Yonker74db1572015-10-28 12:44:49 -05001496 gui_msg("injecttwrp=Injecting TWRP into boot image...");
that3f7b1ac2014-12-30 11:30:13 +01001497 if (simulate) {
1498 simulate_progress_bar();
1499 } else {
1500 TWFunc::Exec_Cmd("injecttwrp --dump /tmp/backup_recovery_ramdisk.img /tmp/injected_boot.img --flash");
Ethan Yonker74db1572015-10-28 12:44:49 -05001501 gui_msg("done=Done.");
that3f7b1ac2014-12-30 11:30:13 +01001502 }
1503
1504 operation_end(op_status);
1505 return 0;
1506}
1507
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001508int GUIAction::checkbackupname(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001509{
1510 int op_status = 0;
1511
1512 operation_start("CheckBackupName");
1513 if (simulate) {
1514 simulate_progress_bar();
1515 } else {
Ethan Yonker53796e72019-01-11 22:49:52 -06001516 string Backup_Name;
1517 DataManager::GetValue(TW_BACKUP_NAME, Backup_Name);
1518 op_status = PartitionManager.Check_Backup_Name(Backup_Name, true, true);
that3f7b1ac2014-12-30 11:30:13 +01001519 if (op_status != 0)
1520 op_status = 1;
1521 }
1522
1523 operation_end(op_status);
1524 return 0;
1525}
1526
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001527int GUIAction::decrypt(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001528{
1529 int op_status = 0;
1530
1531 operation_start("Decrypt");
1532 if (simulate) {
1533 simulate_progress_bar();
1534 } else {
1535 string Password;
Noah Jacobson81d638d2019-04-28 00:10:07 -04001536 string userID;
that3f7b1ac2014-12-30 11:30:13 +01001537 DataManager::GetValue("tw_crypto_password", Password);
Noah Jacobson81d638d2019-04-28 00:10:07 -04001538
1539 if (DataManager::GetIntValue(TW_IS_FBE)) { // for FBE
1540 DataManager::GetValue("tw_crypto_user_id", userID);
1541 if (userID != "") {
1542 op_status = PartitionManager.Decrypt_Device(Password, atoi(userID.c_str()));
1543 if (userID != "0") {
1544 if (op_status != 0)
1545 op_status = 1;
1546 operation_end(op_status);
1547 return 0;
1548 }
1549 } else {
1550 LOGINFO("User ID not found\n");
1551 op_status = 1;
1552 }
1553 ::sleep(1);
1554 } else { // for FDE
1555 op_status = PartitionManager.Decrypt_Device(Password);
1556 }
1557
that3f7b1ac2014-12-30 11:30:13 +01001558 if (op_status != 0)
1559 op_status = 1;
1560 else {
that3f7b1ac2014-12-30 11:30:13 +01001561 DataManager::SetValue(TW_IS_ENCRYPTED, 0);
1562
Ethan Yonkercf50da52015-01-12 21:59:07 -06001563 int has_datamedia;
that3f7b1ac2014-12-30 11:30:13 +01001564
Ethan Yonkercf50da52015-01-12 21:59:07 -06001565 // Check for a custom theme and load it if exists
1566 DataManager::GetValue(TW_HAS_DATA_MEDIA, has_datamedia);
1567 if (has_datamedia != 0) {
1568 if (tw_get_default_metadata(DataManager::GetSettingsStoragePath().c_str()) != 0) {
Ethan Yonkerd9ff3c52015-01-21 21:51:20 -06001569 LOGINFO("Failed to get default contexts and file mode for storage files.\n");
Ethan Yonkercf50da52015-01-12 21:59:07 -06001570 } else {
1571 LOGINFO("Got default contexts and file mode for storage files.\n");
that3f7b1ac2014-12-30 11:30:13 +01001572 }
1573 }
Ethan Yonker66a19492015-12-10 10:19:45 -06001574 PartitionManager.Decrypt_Adopted();
that3f7b1ac2014-12-30 11:30:13 +01001575 }
1576 }
1577
1578 operation_end(op_status);
1579 return 0;
1580}
1581
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001582int GUIAction::adbsideload(std::string arg __unused)
thatcc8ddca2015-01-03 01:59:36 +01001583{
1584 operation_start("Sideload");
1585 if (simulate) {
1586 simulate_progress_bar();
1587 operation_end(0);
1588 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -05001589 gui_msg("start_sideload=Starting ADB sideload feature...");
thatc6085482015-01-09 22:12:43 +01001590 bool mtp_was_enabled = TWFunc::Toggle_MTP(false);
1591
1592 // wait for the adb connection
bigbiffd58ba182020-03-23 10:02:29 -04001593 Device::BuiltinAction reboot_action = Device::REBOOT_BOOTLOADER;
bigbiff1f9e4842020-10-31 11:33:15 -04001594 int ret = twrp_sideload("/", &reboot_action);
1595 sideload_child_pid = GetMiniAdbdPid();
thatc6085482015-01-09 22:12:43 +01001596 DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui now that the zip install is going to start
1597
1598 if (ret != 0) {
1599 if (ret == -2)
Ethan Yonker74db1572015-10-28 12:44:49 -05001600 gui_msg("need_new_adb=You need adb 1.0.32 or newer to sideload to this device.");
thatc6085482015-01-09 22:12:43 +01001601 ret = 1; // failure
1602 } else {
1603 int wipe_cache = 0;
1604 int wipe_dalvik = 0;
1605 DataManager::GetValue("tw_wipe_dalvik", wipe_dalvik);
bigbiff1f9e4842020-10-31 11:33:15 -04001606 if (wipe_cache || DataManager::GetIntValue("tw_wipe_cache"))
1607 PartitionManager.Wipe_By_Path("/cache");
1608 if (wipe_dalvik)
1609 PartitionManager.Wipe_Dalvik_Cache();
thatcc8ddca2015-01-03 01:59:36 +01001610 }
thatc6085482015-01-09 22:12:43 +01001611 TWFunc::Toggle_MTP(mtp_was_enabled);
1612 reinject_after_flash();
1613 operation_end(ret);
thatcc8ddca2015-01-03 01:59:36 +01001614 }
that3f7b1ac2014-12-30 11:30:13 +01001615 return 0;
1616}
1617
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001618int GUIAction::adbsideloadcancel(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001619{
that3f7b1ac2014-12-30 11:30:13 +01001620 struct stat st;
1621 DataManager::SetValue("tw_has_cancel", 0); // Remove cancel button from gui
Ethan Yonker74db1572015-10-28 12:44:49 -05001622 gui_msg("cancel_sideload=Cancelling ADB sideload...");
thatcc8ddca2015-01-03 01:59:36 +01001623 LOGINFO("Signaling child sideload process to exit.\n");
1624 // Calling stat() on this magic filename signals the minadbd
1625 // subprocess to shut down.
1626 stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &st);
bigbiff1f9e4842020-10-31 11:33:15 -04001627 sideload_child_pid = GetMiniAdbdPid();
thatcc8ddca2015-01-03 01:59:36 +01001628 if (!sideload_child_pid) {
1629 LOGERR("Unable to get child ID\n");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001630 return 0;
1631 }
thatcc8ddca2015-01-03 01:59:36 +01001632 ::sleep(1);
1633 LOGINFO("Killing child sideload process.\n");
1634 kill(sideload_child_pid, SIGTERM);
1635 int status;
1636 LOGINFO("Waiting for child sideload process to exit.\n");
1637 waitpid(sideload_child_pid, &status, 0);
1638 sideload_child_pid = 0;
that3f7b1ac2014-12-30 11:30:13 +01001639 DataManager::SetValue("tw_page_done", "1"); // For OpenRecoveryScript support
1640 return 0;
1641}
1642
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001643int GUIAction::openrecoveryscript(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001644{
1645 operation_start("OpenRecoveryScript");
1646 if (simulate) {
1647 simulate_progress_bar();
Ethan Yonker24e7eb72015-01-03 16:13:06 -06001648 operation_end(0);
that3f7b1ac2014-12-30 11:30:13 +01001649 } else {
that10ae24f2015-12-26 20:53:51 +01001650 int op_status = OpenRecoveryScript::Run_OpenRecoveryScript_Action();
Ethan Yonkere1abe612015-06-09 11:09:32 -05001651 operation_end(op_status);
that3f7b1ac2014-12-30 11:30:13 +01001652 }
1653 return 0;
1654}
1655
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001656int GUIAction::installsu(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001657{
1658 int op_status = 0;
1659
1660 operation_start("Install SuperSU");
1661 if (simulate) {
1662 simulate_progress_bar();
1663 } else {
Ethan Yonkerfa67cbf2018-07-20 12:22:33 -05001664 LOGERR("Installing SuperSU was deprecated from TWRP.\n");
that3f7b1ac2014-12-30 11:30:13 +01001665 }
1666
1667 operation_end(op_status);
1668 return 0;
1669}
1670
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001671int GUIAction::fixsu(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001672{
1673 int op_status = 0;
1674
1675 operation_start("Fixing Superuser Permissions");
1676 if (simulate) {
1677 simulate_progress_bar();
1678 } else {
1679 LOGERR("Fixing su permissions was deprecated from TWRP.\n");
1680 LOGERR("4.3+ ROMs with SELinux will always lose su perms.\n");
1681 }
1682
1683 operation_end(op_status);
1684 return 0;
1685}
1686
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001687int GUIAction::decrypt_backup(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001688{
1689 int op_status = 0;
1690
1691 operation_start("Try Restore Decrypt");
1692 if (simulate) {
1693 simulate_progress_bar();
1694 } else {
1695 string Restore_Path, Filename, Password;
1696 DataManager::GetValue("tw_restore", Restore_Path);
1697 Restore_Path += "/";
1698 DataManager::GetValue("tw_restore_password", Password);
1699 TWFunc::SetPerformanceMode(true);
1700 if (TWFunc::Try_Decrypting_Backup(Restore_Path, Password))
1701 op_status = 0; // success
1702 else
1703 op_status = 1; // fail
1704 TWFunc::SetPerformanceMode(false);
1705 }
1706
1707 operation_end(op_status);
1708 return 0;
1709}
1710
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001711int GUIAction::repair(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001712{
1713 int op_status = 0;
1714
1715 operation_start("Repair 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.Repair_By_Path(part_path, true)) {
1722 op_status = 0; // success
1723 } else {
that3f7b1ac2014-12-30 11:30:13 +01001724 op_status = 1; // fail
1725 }
1726 }
1727
1728 operation_end(op_status);
1729 return 0;
1730}
1731
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001732int GUIAction::resize(std::string arg __unused)
Ethan Yonkera2719152015-05-28 09:44:41 -05001733{
1734 int op_status = 0;
1735
1736 operation_start("Resize Partition");
1737 if (simulate) {
1738 simulate_progress_bar();
1739 } else {
1740 string part_path;
1741 DataManager::GetValue("tw_partition_mount_point", part_path);
1742 if (PartitionManager.Resize_By_Path(part_path, true)) {
1743 op_status = 0; // success
1744 } else {
Ethan Yonkera2719152015-05-28 09:44:41 -05001745 op_status = 1; // fail
1746 }
1747 }
1748
1749 operation_end(op_status);
1750 return 0;
1751}
1752
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001753int GUIAction::changefilesystem(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001754{
1755 int op_status = 0;
1756
1757 operation_start("Change File System");
1758 if (simulate) {
1759 simulate_progress_bar();
1760 } else {
1761 string part_path, file_system;
1762 DataManager::GetValue("tw_partition_mount_point", part_path);
1763 DataManager::GetValue("tw_action_new_file_system", file_system);
1764 if (PartitionManager.Wipe_By_Path(part_path, file_system)) {
1765 op_status = 0; // success
1766 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -05001767 gui_err("change_fs_err=Error changing file system.");
that3f7b1ac2014-12-30 11:30:13 +01001768 op_status = 1; // fail
1769 }
1770 }
1771 PartitionManager.Update_System_Details();
1772 operation_end(op_status);
1773 return 0;
1774}
1775
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001776int GUIAction::startmtp(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001777{
1778 int op_status = 0;
1779
1780 operation_start("Start MTP");
1781 if (PartitionManager.Enable_MTP())
1782 op_status = 0; // success
1783 else
1784 op_status = 1; // fail
1785
1786 operation_end(op_status);
1787 return 0;
1788}
1789
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001790int GUIAction::stopmtp(std::string arg __unused)
that3f7b1ac2014-12-30 11:30:13 +01001791{
1792 int op_status = 0;
1793
1794 operation_start("Stop MTP");
1795 if (PartitionManager.Disable_MTP())
1796 op_status = 0; // success
1797 else
1798 op_status = 1; // fail
1799
1800 operation_end(op_status);
1801 return 0;
Dees_Troy51a0e822012-09-05 15:24:24 -04001802}
1803
Ethan Yonkerd0514ba2015-10-22 14:17:47 -05001804int GUIAction::flashimage(std::string arg __unused)
Ethan Yonker96af84a2015-01-05 14:58:36 -06001805{
1806 int op_status = 0;
1807
1808 operation_start("Flash Image");
Ethan Yonkerdcf2b672016-09-13 14:41:53 -05001809 string path, filename;
1810 DataManager::GetValue("tw_zip_location", path);
1811 DataManager::GetValue("tw_file", filename);
Ethan Yonkere080c1f2016-09-19 13:50:25 -05001812 if (PartitionManager.Flash_Image(path, filename))
Ethan Yonker96af84a2015-01-05 14:58:36 -06001813 op_status = 0; // success
1814 else
1815 op_status = 1; // fail
1816
1817 operation_end(op_status);
1818 return 0;
1819}
1820
that10ae24f2015-12-26 20:53:51 +01001821int GUIAction::twcmd(std::string arg)
1822{
1823 operation_start("TWRP CLI Command");
1824 if (simulate)
1825 simulate_progress_bar();
1826 else
1827 OpenRecoveryScript::Run_CLI_Command(arg.c_str());
1828 operation_end(0);
1829 return 0;
1830}
1831
Dees_Troy51a0e822012-09-05 15:24:24 -04001832int GUIAction::getKeyByName(std::string key)
1833{
that8834a0f2016-01-05 23:29:30 +01001834 if (key == "home") return KEY_HOMEPAGE; // note: KEY_HOME is cursor movement (like KEY_END)
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001835 else if (key == "menu") return KEY_MENU;
1836 else if (key == "back") return KEY_BACK;
1837 else if (key == "search") return KEY_SEARCH;
1838 else if (key == "voldown") return KEY_VOLUMEDOWN;
1839 else if (key == "volup") return KEY_VOLUMEUP;
1840 else if (key == "power") {
Dees_Troy51a0e822012-09-05 15:24:24 -04001841 int ret_val;
1842 DataManager::GetValue(TW_POWER_BUTTON, ret_val);
1843 if (!ret_val)
1844 return KEY_POWER;
1845 else
1846 return ret_val;
1847 }
1848
Vojtech Bocekfafb0c52013-07-25 22:53:02 +02001849 return atol(key.c_str());
Dees_Troy51a0e822012-09-05 15:24:24 -04001850}
Ethan Yonkereb32b1f2015-05-18 10:23:03 -05001851
1852int GUIAction::checkpartitionlifetimewrites(std::string arg)
1853{
1854 int op_status = 0;
1855 TWPartition* sys = PartitionManager.Find_Partition_By_Path(arg);
1856
1857 operation_start("Check Partition Lifetime Writes");
1858 if (sys) {
1859 if (sys->Check_Lifetime_Writes() != 0)
1860 DataManager::SetValue("tw_lifetime_writes", 1);
1861 else
1862 DataManager::SetValue("tw_lifetime_writes", 0);
1863 op_status = 0; // success
1864 } else {
1865 DataManager::SetValue("tw_lifetime_writes", 1);
1866 op_status = 1; // fail
1867 }
1868
1869 operation_end(op_status);
1870 return 0;
1871}
1872
1873int GUIAction::mountsystemtoggle(std::string arg)
1874{
1875 int op_status = 0;
Captain Throwback9d6feb52018-07-27 10:05:24 -04001876 bool remount_system = PartitionManager.Is_Mounted_By_Path(PartitionManager.Get_Android_Root_Path());
Ethan Yonker1673e3d2015-10-26 21:51:58 -05001877 bool remount_vendor = PartitionManager.Is_Mounted_By_Path("/vendor");
Ethan Yonkereb32b1f2015-05-18 10:23:03 -05001878
1879 operation_start("Toggle System Mount");
Captain Throwback9d6feb52018-07-27 10:05:24 -04001880 if (!PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) {
Ethan Yonkereb32b1f2015-05-18 10:23:03 -05001881 op_status = 1; // fail
1882 } else {
Captain Throwback9d6feb52018-07-27 10:05:24 -04001883 TWPartition* Part = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path());
Ethan Yonkereb32b1f2015-05-18 10:23:03 -05001884 if (Part) {
Ethan Yonkerd6966f42015-05-30 14:52:16 -05001885 if (arg == "0") {
Ethan Yonkereb32b1f2015-05-18 10:23:03 -05001886 DataManager::SetValue("tw_mount_system_ro", 0);
1887 Part->Change_Mount_Read_Only(false);
1888 } else {
1889 DataManager::SetValue("tw_mount_system_ro", 1);
1890 Part->Change_Mount_Read_Only(true);
1891 }
1892 if (remount_system) {
1893 Part->Mount(true);
1894 }
1895 op_status = 0; // success
1896 } else {
1897 op_status = 1; // fail
1898 }
Ethan Yonker1673e3d2015-10-26 21:51:58 -05001899 Part = PartitionManager.Find_Partition_By_Path("/vendor");
1900 if (Part) {
1901 if (arg == "0") {
1902 Part->Change_Mount_Read_Only(false);
1903 } else {
1904 Part->Change_Mount_Read_Only(true);
1905 }
1906 if (remount_vendor) {
1907 Part->Mount(true);
1908 }
1909 op_status = 0; // success
1910 } else {
1911 op_status = 1; // fail
1912 }
Ethan Yonkereb32b1f2015-05-18 10:23:03 -05001913 }
1914
1915 operation_end(op_status);
1916 return 0;
1917}
Ethan Yonker74db1572015-10-28 12:44:49 -05001918
1919int GUIAction::setlanguage(std::string arg __unused)
1920{
1921 int op_status = 0;
1922
1923 operation_start("Set Language");
1924 PageManager::LoadLanguage(DataManager::GetStrValue("tw_language"));
1925 PageManager::RequestReload();
1926 op_status = 0; // success
1927
1928 operation_end(op_status);
1929 return 0;
1930}
Ethan Yonker1b190162016-12-05 15:25:19 -06001931
Matt Mower9472ba12016-01-20 18:12:47 -06001932int GUIAction::togglebacklight(std::string arg __unused)
1933{
1934 blankTimer.toggleBlank();
1935 return 0;
1936}
1937
Ethan Yonker1b190162016-12-05 15:25:19 -06001938int GUIAction::setbootslot(std::string arg)
1939{
1940 operation_start("Set Boot Slot");
Captain Throwbackb60a2732020-10-13 17:55:43 -04001941 if (!simulate) {
1942 if (!PartitionManager.UnMount_By_Path("/vendor", false)) {
1943 // PartitionManager failed to unmount /vendor, this should not happen,
1944 // but in case it does, do a lazy unmount
1945 LOGINFO("WARNING: vendor partition could not be unmounted normally!\n");
1946 umount2("/vendor", MNT_DETACH);
1947 PartitionManager.Set_Active_Slot(arg);
1948 } else {
1949 PartitionManager.Set_Active_Slot(arg);
1950 }
1951 } else {
Ethan Yonker1b190162016-12-05 15:25:19 -06001952 simulate_progress_bar();
Captain Throwbackb60a2732020-10-13 17:55:43 -04001953 }
Ethan Yonker1b190162016-12-05 15:25:19 -06001954 operation_end(0);
1955 return 0;
1956}
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06001957
1958int GUIAction::checkforapp(std::string arg __unused)
1959{
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06001960 operation_start("Check for TWRP App");
1961 if (!simulate)
1962 {
epicX271bb3a2020-12-30 01:03:18 +05301963 TWFunc::checkforapp();
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06001964 } else
1965 simulate_progress_bar();
epicX271bb3a2020-12-30 01:03:18 +05301966
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06001967 operation_end(0);
1968 return 0;
1969}
1970
1971int GUIAction::installapp(std::string arg __unused)
1972{
1973 int op_status = 1;
1974 operation_start("Install TWRP App");
1975 if (!simulate)
1976 {
1977 if (DataManager::GetIntValue("tw_mount_system_ro") > 0 || DataManager::GetIntValue("tw_app_install_system") == 0) {
1978 if (PartitionManager.Mount_By_Path("/data", true)) {
1979 string install_path = "/data/app";
1980 string context = "u:object_r:apk_data_file:s0";
1981 if (!TWFunc::Path_Exists(install_path)) {
1982 if (mkdir(install_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
1983 LOGERR("Error making %s directory: %s\n", install_path.c_str(), strerror(errno));
1984 goto exit;
1985 }
1986 if (chown(install_path.c_str(), 1000, 1000)) {
1987 LOGERR("chown %s error: %s\n", install_path.c_str(), strerror(errno));
1988 goto exit;
1989 }
Ethan Yonker4767caf2017-01-11 10:45:04 -06001990 if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) {
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06001991 LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno));
1992 goto exit;
1993 }
1994 }
1995 install_path += "/me.twrp.twrpapp-1";
1996 if (mkdir(install_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) {
1997 LOGERR("Error making %s directory: %s\n", install_path.c_str(), strerror(errno));
1998 goto exit;
1999 }
2000 if (chown(install_path.c_str(), 1000, 1000)) {
2001 LOGERR("chown %s error: %s\n", install_path.c_str(), strerror(errno));
2002 goto exit;
2003 }
Ethan Yonker4767caf2017-01-11 10:45:04 -06002004 if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) {
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002005 LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno));
2006 goto exit;
2007 }
2008 install_path += "/base.apk";
bigbiffad58e1b2020-07-06 20:24:34 -04002009 if (TWFunc::copy_file("/system/bin/me.twrp.twrpapp.apk", install_path, 0644)) {
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002010 LOGERR("Error copying apk file\n");
2011 goto exit;
2012 }
2013 if (chown(install_path.c_str(), 1000, 1000)) {
2014 LOGERR("chown %s error: %s\n", install_path.c_str(), strerror(errno));
2015 goto exit;
2016 }
Ethan Yonker4767caf2017-01-11 10:45:04 -06002017 if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) {
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002018 LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno));
2019 goto exit;
2020 }
2021 sync();
2022 sync();
2023 }
2024 } else {
Captain Throwback9d6feb52018-07-27 10:05:24 -04002025 if (PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) {
2026 string base_path = PartitionManager.Get_Android_Root_Path();
2027 if (TWFunc::Path_Exists(PartitionManager.Get_Android_Root_Path() + "/system"))
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002028 base_path += "/system"; // For devices with system as a root file system (e.g. Pixel)
2029 string install_path = base_path + "/priv-app";
2030 string context = "u:object_r:system_file:s0";
2031 if (!TWFunc::Path_Exists(install_path))
2032 install_path = base_path + "/app";
2033 if (TWFunc::Path_Exists(install_path)) {
2034 install_path += "/twrpapp";
2035 LOGINFO("Installing app to '%s'\n", install_path.c_str());
2036 if (mkdir(install_path.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0) {
Ethan Yonker4767caf2017-01-11 10:45:04 -06002037 if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) {
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002038 LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno));
2039 goto exit;
2040 }
2041 install_path += "/me.twrp.twrpapp.apk";
bigbiffad58e1b2020-07-06 20:24:34 -04002042 if (TWFunc::copy_file("/system/bin/me.twrp.twrpapp.apk", install_path, 0644)) {
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002043 LOGERR("Error copying apk file\n");
2044 goto exit;
2045 }
Ethan Yonker4767caf2017-01-11 10:45:04 -06002046 if (setfilecon(install_path.c_str(), (security_context_t)context.c_str()) < 0) {
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002047 LOGERR("setfilecon %s error: %s\n", install_path.c_str(), strerror(errno));
2048 goto exit;
2049 }
Stefan Tauner6ad14572020-01-11 22:28:53 +01002050
2051 // System apps require their permissions to be pre-set via an XML file in /etc/permissions
2052 string permission_path = base_path + "/etc/permissions/privapp-permissions-twrpapp.xml";
bigbiffad58e1b2020-07-06 20:24:34 -04002053 if (TWFunc::copy_file("/system/bin/privapp-permissions-twrpapp.xml", permission_path, 0644)) {
Stefan Tauner6ad14572020-01-11 22:28:53 +01002054 LOGERR("Error copying permission file\n");
2055 goto exit;
2056 }
2057 if (chown(permission_path.c_str(), 1000, 1000)) {
2058 LOGERR("chown %s error: %s\n", permission_path.c_str(), strerror(errno));
2059 goto exit;
2060 }
2061 if (setfilecon(permission_path.c_str(), (security_context_t)context.c_str()) < 0) {
2062 LOGERR("setfilecon %s error: %s\n", permission_path.c_str(), strerror(errno));
2063 goto exit;
2064 }
2065
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002066 sync();
2067 sync();
Captain Throwback9d6feb52018-07-27 10:05:24 -04002068 PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true);
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002069 op_status = 0;
2070 } else {
2071 LOGERR("Error making app directory '%s': %s\n", strerror(errno));
2072 }
2073 }
2074 }
2075 }
2076 } else
2077 simulate_progress_bar();
2078exit:
epicX271bb3a2020-12-30 01:03:18 +05302079 TWFunc::checkforapp();
Ethan Yonkerb4bff5e2016-12-16 07:47:58 -06002080 operation_end(0);
2081 return 0;
2082}
Ethan Yonker53796e72019-01-11 22:49:52 -06002083
Ethan Yonker76bbd3a2019-05-10 10:50:04 -05002084int GUIAction::uninstalltwrpsystemapp(std::string arg __unused)
2085{
2086 int op_status = 1;
2087 operation_start("Uninstall TWRP System App");
2088 if (!simulate)
2089 {
2090 int Mount_System_RO = DataManager::GetIntValue("tw_mount_system_ro");
2091 TWPartition* Part = PartitionManager.Find_Partition_By_Path(PartitionManager.Get_Android_Root_Path());
2092 if (!Part) {
2093 LOGERR("Unabled to find system partition.\n");
2094 goto exit;
2095 }
2096 if (!Part->UnMount(true)) {
2097 goto exit;
2098 }
2099 if (Mount_System_RO > 0) {
2100 DataManager::SetValue("tw_mount_system_ro", 0);
2101 Part->Change_Mount_Read_Only(false);
2102 }
2103 if (Part->Mount(true)) {
2104 string base_path = PartitionManager.Get_Android_Root_Path();
2105 if (TWFunc::Path_Exists(PartitionManager.Get_Android_Root_Path() + "/system"))
2106 base_path += "/system"; // For devices with system as a root file system (e.g. Pixel)
2107 string uninstall_path = base_path + "/priv-app";
2108 if (!TWFunc::Path_Exists(uninstall_path))
2109 uninstall_path = base_path + "/app";
2110 uninstall_path += "/twrpapp";
2111 if (TWFunc::Path_Exists(uninstall_path)) {
2112 LOGINFO("Uninstalling TWRP App from '%s'\n", uninstall_path.c_str());
2113 if (TWFunc::removeDir(uninstall_path, false) == 0) {
2114 sync();
2115 op_status = 0;
2116 DataManager::SetValue("tw_app_installed_in_system", 0);
2117 DataManager::SetValue("tw_app_install_status", 0);
2118 } else {
2119 LOGERR("Unable to remove TWRP app from system.\n");
2120 }
2121 } else {
2122 LOGINFO("didn't find TWRP app in '%s'\n", uninstall_path.c_str());
2123 }
2124 }
2125 Part->UnMount(true);
2126 if (Mount_System_RO > 0) {
2127 DataManager::SetValue("tw_mount_system_ro", Mount_System_RO);
2128 Part->Change_Mount_Read_Only(true);
2129 }
2130 } else
2131 simulate_progress_bar();
2132exit:
epicX271bb3a2020-12-30 01:03:18 +05302133 TWFunc::checkforapp();
Ethan Yonker76bbd3a2019-05-10 10:50:04 -05002134 operation_end(0);
2135 return 0;
2136}
2137
Ethan Yonker53796e72019-01-11 22:49:52 -06002138int GUIAction::repackimage(std::string arg __unused)
2139{
2140 int op_status = 1;
bigbiffad58e1b2020-07-06 20:24:34 -04002141 twrpRepacker repacker;
2142
Ethan Yonker53796e72019-01-11 22:49:52 -06002143 operation_start("Repack Image");
2144 if (!simulate)
2145 {
2146 std::string path = DataManager::GetStrValue("tw_filename");
2147 Repack_Options_struct Repack_Options;
2148 Repack_Options.Disable_Verity = false;
2149 Repack_Options.Disable_Force_Encrypt = false;
2150 Repack_Options.Backup_First = DataManager::GetIntValue("tw_repack_backup_first") != 0;
2151 if (DataManager::GetIntValue("tw_repack_kernel") == 1)
2152 Repack_Options.Type = REPLACE_KERNEL;
2153 else
2154 Repack_Options.Type = REPLACE_RAMDISK;
bigbiffad58e1b2020-07-06 20:24:34 -04002155 if (!repacker.Repack_Image_And_Flash(path, Repack_Options))
Ethan Yonker53796e72019-01-11 22:49:52 -06002156 goto exit;
2157 } else
2158 simulate_progress_bar();
2159 op_status = 0;
2160exit:
2161 operation_end(op_status);
2162 return 0;
2163}
2164
2165int GUIAction::fixabrecoverybootloop(std::string arg __unused)
2166{
2167 int op_status = 1;
bigbiffad58e1b2020-07-06 20:24:34 -04002168 twrpRepacker repacker;
2169
Ethan Yonker53796e72019-01-11 22:49:52 -06002170 operation_start("Repack Image");
2171 if (!simulate)
2172 {
bigbiffad58e1b2020-07-06 20:24:34 -04002173 if (!TWFunc::Path_Exists("/system/bin/magiskboot")) {
Ethan Yonker53796e72019-01-11 22:49:52 -06002174 LOGERR("Image repacking tool not present in this TWRP build!");
2175 goto exit;
2176 }
2177 DataManager::SetProgress(0);
2178 TWPartition* part = PartitionManager.Find_Partition_By_Path("/boot");
2179 if (part)
2180 gui_msg(Msg("unpacking_image=Unpacking {1}...")(part->Display_Name));
2181 else {
2182 gui_msg(Msg(msg::kError, "unable_to_locate=Unable to locate {1}.")("/boot"));
2183 goto exit;
2184 }
bigbiffad58e1b2020-07-06 20:24:34 -04002185 if (!repacker.Backup_Image_For_Repack(part, REPACK_ORIG_DIR, DataManager::GetIntValue("tw_repack_backup_first") != 0, gui_lookup("repack", "Repack")))
Ethan Yonker53796e72019-01-11 22:49:52 -06002186 goto exit;
2187 DataManager::SetProgress(.25);
2188 gui_msg("fixing_recovery_loop_patch=Patching kernel...");
bigbiffad58e1b2020-07-06 20:24:34 -04002189 std::string command = "cd " REPACK_ORIG_DIR " && /system/bin/magiskboot hexpatch kernel 77616E745F696E697472616D667300 736B69705F696E697472616D667300";
Ethan Yonker53796e72019-01-11 22:49:52 -06002190 if (TWFunc::Exec_Cmd(command) != 0) {
2191 gui_msg(Msg(msg::kError, "fix_recovery_loop_patch_error=Error patching kernel."));
2192 goto exit;
2193 }
2194 std::string header_path = REPACK_ORIG_DIR;
2195 header_path += "header";
2196 if (TWFunc::Path_Exists(header_path)) {
2197 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";
2198 if (TWFunc::Exec_Cmd(command) != 0) {
2199 gui_msg(Msg(msg::kError, "fix_recovery_loop_patch_error=Error patching kernel."));
2200 goto exit;
2201 }
2202 }
2203 DataManager::SetProgress(.5);
2204 gui_msg(Msg("repacking_image=Repacking {1}...")(part->Display_Name));
bigbiffad58e1b2020-07-06 20:24:34 -04002205 command = "cd " REPACK_ORIG_DIR " && /system/bin/magiskboot repack " REPACK_ORIG_DIR "boot.img";
Ethan Yonker53796e72019-01-11 22:49:52 -06002206 if (TWFunc::Exec_Cmd(command) != 0) {
2207 gui_msg(Msg(msg::kError, "repack_error=Error repacking image."));
2208 goto exit;
2209 }
2210 DataManager::SetProgress(.75);
2211 std::string path = REPACK_ORIG_DIR;
2212 std::string file = "new-boot.img";
2213 DataManager::SetValue("tw_flash_partition", "/boot;");
2214 if (!PartitionManager.Flash_Image(path, file)) {
2215 LOGINFO("Error flashing new image\n");
2216 goto exit;
2217 }
2218 DataManager::SetProgress(1);
2219 TWFunc::removeDir(REPACK_ORIG_DIR, false);
2220 } else
2221 simulate_progress_bar();
2222 op_status = 0;
2223exit:
2224 operation_end(op_status);
2225 return 0;
2226}
bigbiffdf8436b2020-08-30 16:22:34 -04002227
2228
2229int GUIAction::enableadb(std::string arg __unused) {
2230 android::base::SetProperty("sys.usb.config", "none");
2231 android::base::SetProperty("sys.usb.config", "adb");
2232 return 0;
2233}
2234
2235int GUIAction::enablefastboot(std::string arg __unused) {
2236 android::base::SetProperty("sys.usb.config", "none");
2237 android::base::SetProperty("sys.usb.config", "fastboot");
2238 return 0;
2239}