blob: 849b3adad780c9d1f98ca62f661f40076cfdb406 [file] [log] [blame]
Dees Troy3be70a82013-10-22 14:25:12 +00001/*
bigbiff bigbiff19fb79c2016-09-05 21:04:51 -04002 Copyright 2012 to 2017 bigbiff/Dees_Troy TeamWin
Dees Troy3be70a82013-10-22 14:25:12 +00003 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_Troy32c8eb82012-09-11 15:28:06 -040018
nkk71b4c35912017-10-11 23:39:10 +030019
20#ifndef _GNU_SOURCE
21#define _GNU_SOURCE
22#endif
23
Dees_Troy32c8eb82012-09-11 15:28:06 -040024#include <ctype.h>
25#include <errno.h>
26#include <fcntl.h>
27#include <limits.h>
nkk71b4c35912017-10-11 23:39:10 +030028#include <sys/mman.h>
Dees_Troy32c8eb82012-09-11 15:28:06 -040029#include <sys/stat.h>
30#include <sys/wait.h>
31#include <unistd.h>
32
33#include <string.h>
34#include <stdio.h>
Ethan Yonker193befe2019-04-02 16:01:31 -050035#include <cutils/properties.h>
Dees_Troy32c8eb82012-09-11 15:28:06 -040036
bigbiff1f9e4842020-10-31 11:33:15 -040037#include <android-base/unique_fd.h>
38
Dees_Troy2673cec2013-04-02 20:22:16 +000039#include "twcommon.h"
Ethan Yonker75bf0412014-11-21 13:54:27 -060040#include "mtdutils/mounts.h"
41#include "mtdutils/mtdutils.h"
Ethan Yonker8373cfe2017-09-08 06:50:54 -050042
bigbiffd58ba182020-03-23 10:02:29 -040043#include "otautil/sysutil.h"
Ethan Yonker8373cfe2017-09-08 06:50:54 -050044#include <ziparchive/zip_archive.h>
bigbiff1f9e4842020-10-31 11:33:15 -040045#include "twinstall/install.h"
46#include "twinstall/verifier.h"
Dees_Troy32c8eb82012-09-11 15:28:06 -040047#include "variables.h"
48#include "data.hpp"
49#include "partitions.hpp"
bigbiff bigbiff56cf5642016-08-19 17:43:45 -040050#include "twrpDigestDriver.hpp"
51#include "twrpDigest/twrpDigest.hpp"
52#include "twrpDigest/twrpMD5.hpp"
Dees_Troy38bd7602012-09-14 13:33:53 -040053#include "twrp-functions.hpp"
Ethan Yonker74db1572015-10-28 12:44:49 -050054#include "gui/gui.hpp"
Ethan Yonker20eb0bc2016-03-22 14:23:28 -050055#include "gui/pages.hpp"
Ethan Yonker941a8992016-12-05 09:04:30 -060056#include "twinstall.h"
57#include "installcommand.h"
nebrassyac29e692021-05-20 13:03:30 +020058#include "../twrpRepacker.hpp"
Dees_Troy2673cec2013-04-02 20:22:16 +000059extern "C" {
60 #include "gui/gui.h"
that7e303cf2014-03-06 07:57:43 +010061}
62
Ethan Yonker941a8992016-12-05 09:04:30 -060063#define AB_OTA "payload_properties.txt"
64
Ethan Yonker941a8992016-12-05 09:04:30 -060065enum zip_type {
66 UNKNOWN_ZIP_TYPE = 0,
67 UPDATE_BINARY_ZIP_TYPE,
68 AB_OTA_ZIP_TYPE,
69 TWRP_THEME_ZIP_TYPE
70};
71
bigbiff1f9e4842020-10-31 11:33:15 -040072static int Install_Theme(const char* path, ZipArchiveHandle Zip) {
Ethan Yonker20eb0bc2016-03-22 14:23:28 -050073#ifdef TW_OEM_BUILD // We don't do custom themes in OEM builds
bigbiff1f9e4842020-10-31 11:33:15 -040074 CloseArchive(Zip);
Ethan Yonker20eb0bc2016-03-22 14:23:28 -050075 return INSTALL_CORRUPT;
76#else
bigbiff673c7ae2020-12-02 19:44:56 -050077 std::string binary_name("ui.xml");
bigbiff1f9e4842020-10-31 11:33:15 -040078 ZipEntry binary_entry;
79 if (FindEntry(Zip, binary_name, &binary_entry) != 0) {
80 CloseArchive(Zip);
Ethan Yonker20eb0bc2016-03-22 14:23:28 -050081 return INSTALL_CORRUPT;
82 }
83 if (!PartitionManager.Mount_Settings_Storage(true))
84 return INSTALL_ERROR;
85 string theme_path = DataManager::GetSettingsStoragePath();
86 theme_path += "/TWRP/theme";
87 if (!TWFunc::Path_Exists(theme_path)) {
88 if (!TWFunc::Recursive_Mkdir(theme_path)) {
89 return INSTALL_ERROR;
90 }
91 }
92 theme_path += "/ui.zip";
93 if (TWFunc::copy_file(path, theme_path, 0644) != 0) {
94 return INSTALL_ERROR;
95 }
96 LOGINFO("Installing custom theme '%s' to '%s'\n", path, theme_path.c_str());
97 PageManager::RequestReload();
98 return INSTALL_SUCCESS;
99#endif
100}
101
bigbiff1f9e4842020-10-31 11:33:15 -0400102static int Prepare_Update_Binary(ZipArchiveHandle Zip) {
Ethan Yonker193befe2019-04-02 16:01:31 -0500103 char arches[PATH_MAX];
Ethan Yonker193befe2019-04-02 16:01:31 -0500104 property_get("ro.product.cpu.abilist", arches, "error");
105 if (strcmp(arches, "error") == 0)
106 property_get("ro.product.cpu.abi", arches, "error");
107 vector<string> split = TWFunc::split_string(arches, ',', true);
108 std::vector<string>::iterator arch;
bigbiff1f9e4842020-10-31 11:33:15 -0400109 std::string base_name = UPDATE_BINARY_NAME;
Ethan Yonker193befe2019-04-02 16:01:31 -0500110 base_name += "-";
bigbiff1f9e4842020-10-31 11:33:15 -0400111 ZipEntry binary_entry;
bigbiff673c7ae2020-12-02 19:44:56 -0500112 std::string update_binary_string(UPDATE_BINARY_NAME);
bigbiff1f9e4842020-10-31 11:33:15 -0400113 if (FindEntry(Zip, update_binary_string, &binary_entry) != 0) {
114 for (arch = split.begin(); arch != split.end(); arch++) {
115 std::string temp = base_name + *arch;
bigbiff673c7ae2020-12-02 19:44:56 -0500116 std::string binary_name(temp.c_str());
bigbiff1f9e4842020-10-31 11:33:15 -0400117 if (FindEntry(Zip, binary_name, &binary_entry) != 0) {
bigbiff673c7ae2020-12-02 19:44:56 -0500118 std::string binary_name(temp.c_str());
bigbiff1f9e4842020-10-31 11:33:15 -0400119 break;
120 }
Ethan Yonker193befe2019-04-02 16:01:31 -0500121 }
122 }
bigbiff1f9e4842020-10-31 11:33:15 -0400123 LOGINFO("Extracting updater binary '%s'\n", UPDATE_BINARY_NAME);
124 unlink(TMP_UPDATER_BINARY_PATH);
125 android::base::unique_fd fd(
126 open(TMP_UPDATER_BINARY_PATH, O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 0755));
127 if (fd == -1) {
128 return INSTALL_ERROR;
129 }
130 int32_t err = ExtractEntryToFile(Zip, &binary_entry, fd);
131 if (err != 0) {
132 CloseArchive(Zip);
133 LOGERR("Could not extract '%s'\n", UPDATE_BINARY_NAME);
Dees_Troy2673cec2013-04-02 20:22:16 +0000134 return INSTALL_ERROR;
135 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400136
Dees_Troy512376c2013-09-03 19:39:41 +0000137 // If exists, extract file_contexts from the zip file
bigbiff673c7ae2020-12-02 19:44:56 -0500138 std::string file_contexts("file_contexts");
bigbiff1f9e4842020-10-31 11:33:15 -0400139 ZipEntry file_contexts_entry;
140 if (FindEntry(Zip, file_contexts, &file_contexts_entry) != 0) {
Dees_Troy512376c2013-09-03 19:39:41 +0000141 LOGINFO("Zip does not contain SELinux file_contexts file in its root.\n");
142 } else {
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500143 const string output_filename = "/file_contexts";
Dees_Troy512376c2013-09-03 19:39:41 +0000144 LOGINFO("Zip contains SELinux file_contexts file in its root. Extracting to %s\n", output_filename.c_str());
bigbiff1f9e4842020-10-31 11:33:15 -0400145 android::base::unique_fd fd(
146 open(output_filename.c_str(), O_CREAT | O_WRONLY | O_TRUNC | O_CLOEXEC, 0644));
147 if (fd == -1) {
148 return INSTALL_ERROR;
149 }
150 if (ExtractEntryToFile(Zip, &file_contexts_entry, fd)) {
151 CloseArchive(Zip);
that50640482015-08-30 12:08:05 +0200152 LOGERR("Could not extract '%s'\n", output_filename.c_str());
Dees_Troy512376c2013-09-03 19:39:41 +0000153 return INSTALL_ERROR;
154 }
155 }
Ethan Yonker941a8992016-12-05 09:04:30 -0600156 return INSTALL_SUCCESS;
157}
158
nkk71b4c35912017-10-11 23:39:10 +0300159
bigbiff1f9e4842020-10-31 11:33:15 -0400160static int Run_Update_Binary(const char *path, int* wipe_cache, zip_type ztype) {
Ethan Yonker941a8992016-12-05 09:04:30 -0600161 int ret_val, pipe_fd[2], status, zip_verify;
162 char buffer[1024];
163 FILE* child_data;
Dees_Troy2673cec2013-04-02 20:22:16 +0000164 pipe(pipe_fd);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400165
Ethan Yonker941a8992016-12-05 09:04:30 -0600166 std::vector<std::string> args;
167 if (ztype == UPDATE_BINARY_ZIP_TYPE) {
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500168 ret_val = update_binary_command(path, 0, pipe_fd[1], &args);
Ethan Yonker941a8992016-12-05 09:04:30 -0600169 } else if (ztype == AB_OTA_ZIP_TYPE) {
bigbiff1f9e4842020-10-31 11:33:15 -0400170 ret_val = abupdate_binary_command(path, 0, pipe_fd[1], &args);
Ethan Yonker941a8992016-12-05 09:04:30 -0600171 } else {
172 LOGERR("Unknown zip type %i\n", ztype);
173 ret_val = INSTALL_CORRUPT;
174 }
175 if (ret_val) {
176 close(pipe_fd[0]);
177 close(pipe_fd[1]);
178 return ret_val;
179 }
180
181 // Convert the vector to a NULL-terminated char* array suitable for execv.
182 const char* chr_args[args.size() + 1];
183 chr_args[args.size()] = NULL;
184 for (size_t i = 0; i < args.size(); i++)
185 chr_args[i] = args[i].c_str();
Dees_Troy32c8eb82012-09-11 15:28:06 -0400186
Dees_Troy2673cec2013-04-02 20:22:16 +0000187 pid_t pid = fork();
188 if (pid == 0) {
189 close(pipe_fd[0]);
Ethan Yonker941a8992016-12-05 09:04:30 -0600190 execve(chr_args[0], const_cast<char**>(chr_args), environ);
191 printf("E:Can't execute '%s': %s\n", chr_args[0], strerror(errno));
Dees_Troy2673cec2013-04-02 20:22:16 +0000192 _exit(-1);
193 }
194 close(pipe_fd[1]);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400195
Dees_Troy2673cec2013-04-02 20:22:16 +0000196 *wipe_cache = 0;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400197
Dees_Troy2673cec2013-04-02 20:22:16 +0000198 DataManager::GetValue(TW_SIGNED_ZIP_VERIFY_VAR, zip_verify);
199 child_data = fdopen(pipe_fd[0], "r");
200 while (fgets(buffer, sizeof(buffer), child_data) != NULL) {
201 char* command = strtok(buffer, " \n");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200202 if (command == NULL) {
203 continue;
204 } else if (strcmp(command, "progress") == 0) {
205 char* fraction_char = strtok(NULL, " \n");
206 char* seconds_char = strtok(NULL, " \n");
Dees_Troy32c8eb82012-09-11 15:28:06 -0400207
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200208 float fraction_float = strtof(fraction_char, NULL);
209 int seconds_float = strtol(seconds_char, NULL, 10);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400210
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200211 if (zip_verify)
bigbiff1f9e4842020-10-31 11:33:15 -0400212 DataManager::ShowProgress(fraction_float * (1 - VERIFICATION_PROGRESS_FRACTION), seconds_float);
Dees_Troy2673cec2013-04-02 20:22:16 +0000213 else
214 DataManager::ShowProgress(fraction_float, seconds_float);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200215 } else if (strcmp(command, "set_progress") == 0) {
216 char* fraction_char = strtok(NULL, " \n");
217 float fraction_float = strtof(fraction_char, NULL);
Chaosmasterd5364a02020-02-03 15:38:02 +0100218 DataManager::_SetProgress(fraction_float);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200219 } else if (strcmp(command, "ui_print") == 0) {
220 char* display_value = strtok(NULL, "\n");
221 if (display_value) {
222 gui_print("%s", display_value);
223 } else {
224 gui_print("\n");
225 }
226 } else if (strcmp(command, "wipe_cache") == 0) {
227 *wipe_cache = 1;
228 } else if (strcmp(command, "clear_display") == 0) {
229 // Do nothing, not supported by TWRP
Ethan Yonker072c8d82016-08-26 22:22:24 -0500230 } else if (strcmp(command, "log") == 0) {
231 printf("%s\n", strtok(NULL, "\n"));
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200232 } else {
233 LOGERR("unknown command [%s]\n", command);
234 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000235 }
236 fclose(child_data);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400237
that50640482015-08-30 12:08:05 +0200238 int waitrc = TWFunc::Wait_For_Child(pid, &status, "Updater");
that50640482015-08-30 12:08:05 +0200239 if (waitrc != 0)
Dees_Troy2673cec2013-04-02 20:22:16 +0000240 return INSTALL_ERROR;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400241
Dees_Troy2673cec2013-04-02 20:22:16 +0000242 return INSTALL_SUCCESS;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400243}
244
epicX9d80efa2021-03-12 18:14:23 +0530245int TWinstall_zip(const char* path, int* wipe_cache, bool check_for_digest) {
nebrassyac29e692021-05-20 13:03:30 +0200246 int ret_val, zip_verify = 1, unmount_system = 1, reflashtwrp = 0;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400247
Ethan Yonker74db1572015-10-28 12:44:49 -0500248 gui_msg(Msg("installing_zip=Installing zip file '{1}'")(path));
Ethan Yonker24813422014-11-07 17:19:07 -0600249 if (strlen(path) < 9 || strncmp(path, "/sideload", 9) != 0) {
bigbiff bigbiff56cf5642016-08-19 17:43:45 -0400250 string digest_str;
251 string Full_Filename = path;
bigbiff bigbiff56cf5642016-08-19 17:43:45 -0400252
epicX9d80efa2021-03-12 18:14:23 +0530253 if (check_for_digest) {
254 gui_msg("check_for_digest=Checking for Digest file...");
255 if (*path != '@' && !twrpDigestDriver::Check_File_Digest(Full_Filename)) {
256 LOGERR("Aborting zip install: Digest verification failed\n");
257 return INSTALL_CORRUPT;
258 }
Ethan Yonker24813422014-11-07 17:19:07 -0600259 }
260 }
261
Chaosmasterff4f9582020-01-26 15:38:11 +0100262 DataManager::GetValue(TW_UNMOUNT_SYSTEM, unmount_system);
263
Ethan Yonkerd5801c52014-04-14 08:59:35 -0500264#ifndef TW_OEM_BUILD
Dees_Troy32c8eb82012-09-11 15:28:06 -0400265 DataManager::GetValue(TW_SIGNED_ZIP_VERIFY_VAR, zip_verify);
Ethan Yonkerd5801c52014-04-14 08:59:35 -0500266#endif
Dees_Troy2673cec2013-04-02 20:22:16 +0000267 DataManager::SetProgress(0);
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600268
bigbiff1f9e4842020-10-31 11:33:15 -0400269 auto package = Package::CreateMemoryPackage(path);
270 if (!package) {
271 return INSTALL_CORRUPT;
that50640482015-08-30 12:08:05 +0200272 }
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600273
Dees_Troy32c8eb82012-09-11 15:28:06 -0400274 if (zip_verify) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500275 gui_msg("verify_zip_sig=Verifying zip signature...");
bigbiff1f9e4842020-10-31 11:33:15 -0400276 static constexpr const char* CERTIFICATE_ZIP_FILE = "/system/etc/security/otacerts.zip";
277 std::vector<Certificate> loaded_keys = LoadKeysFromZipfile(CERTIFICATE_ZIP_FILE);
278 if (loaded_keys.empty()) {
279 LOGERR("Failed to load keys\n");
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500280 return -1;
281 }
bigbiff1f9e4842020-10-31 11:33:15 -0400282 LOGINFO("%zu key(s) loaded from %s\n", loaded_keys.size(), CERTIFICATE_ZIP_FILE);
283
284 ret_val = verify_file(package.get(), loaded_keys, std::bind(&DataManager::SetProgress, std::placeholders::_1));
Dees_Troy2673cec2013-04-02 20:22:16 +0000285 if (ret_val != VERIFY_SUCCESS) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500286 LOGINFO("Zip signature verification failed: %i\n", ret_val);
287 gui_err("verify_zip_fail=Zip signature verification failed!");
Ethan Yonkerecbd3e82017-12-14 14:43:59 -0600288#ifdef USE_MINZIP
Ethan Yonkerf9796a42014-11-08 07:28:03 -0600289 sysReleaseMap(&map);
Ethan Yonkerecbd3e82017-12-14 14:43:59 -0600290#endif
Dees_Troy32c8eb82012-09-11 15:28:06 -0400291 return -1;
Ethan Yonker738be7a2014-12-10 11:40:43 -0600292 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500293 gui_msg("verify_zip_done=Zip signature verified successfully.");
Dees_Troy32c8eb82012-09-11 15:28:06 -0400294 }
295 }
bigbiff1f9e4842020-10-31 11:33:15 -0400296
297 ZipArchiveHandle Zip = package->GetZipArchiveHandle();
298 if (!Zip) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000299 return INSTALL_CORRUPT;
300 }
Ethan Yonker941a8992016-12-05 09:04:30 -0600301
Chaosmasterff4f9582020-01-26 15:38:11 +0100302 if (unmount_system) {
303 gui_msg("unmount_system=Unmounting System...");
304 if(!PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), true)) {
305 gui_err("unmount_system_err=Failed unmounting System");
306 return -1;
307 }
Chaosmaster4ee7cbd2020-06-05 17:38:08 +0200308 unlink("/system");
309 mkdir("/system", 0755);
Chaosmasterff4f9582020-01-26 15:38:11 +0100310 }
311
Ethan Yonker072c8d82016-08-26 22:22:24 -0500312 time_t start, stop;
313 time(&start);
bigbiff1f9e4842020-10-31 11:33:15 -0400314
bigbiff673c7ae2020-12-02 19:44:56 -0500315 std::string update_binary_name(UPDATE_BINARY_NAME);
bigbiff1f9e4842020-10-31 11:33:15 -0400316 ZipEntry update_binary_entry;
317 if (FindEntry(Zip, update_binary_name, &update_binary_entry) == 0) {
Ethan Yonker941a8992016-12-05 09:04:30 -0600318 LOGINFO("Update binary zip\n");
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500319 // Additionally verify the compatibility of the package.
bigbiff1f9e4842020-10-31 11:33:15 -0400320 if (!verify_package_compatibility(Zip)) {
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500321 gui_err("zip_compatible_err=Zip Treble compatibility error!");
bigbiff1f9e4842020-10-31 11:33:15 -0400322 CloseArchive(Zip);
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500323 ret_val = INSTALL_CORRUPT;
324 } else {
bigbiff1f9e4842020-10-31 11:33:15 -0400325 ret_val = Prepare_Update_Binary(Zip);
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500326 if (ret_val == INSTALL_SUCCESS)
bigbiff1f9e4842020-10-31 11:33:15 -0400327 ret_val = Run_Update_Binary(path, wipe_cache, UPDATE_BINARY_ZIP_TYPE);
Ethan Yonker8373cfe2017-09-08 06:50:54 -0500328 }
Ethan Yonker941a8992016-12-05 09:04:30 -0600329 } else {
bigbiff673c7ae2020-12-02 19:44:56 -0500330 std::string ab_binary_name(AB_OTA);
bigbiff1f9e4842020-10-31 11:33:15 -0400331 ZipEntry ab_binary_entry;
332 if (FindEntry(Zip, ab_binary_name, &ab_binary_entry) == 0) {
Ethan Yonker941a8992016-12-05 09:04:30 -0600333 LOGINFO("AB zip\n");
Chaosmastera6da6562020-02-07 19:58:10 +0100334 gui_msg(Msg(msg::kHighlight, "flash_ab_inactive=Flashing A/B zip to inactive slot: {1}")(PartitionManager.Get_Active_Slot_Display()=="A"?"B":"A"));
Chaosmaster6c1477d2020-02-03 15:54:32 +0100335 // We need this so backuptool can do its magic
336 bool system_mount_state = PartitionManager.Is_Mounted_By_Path(PartitionManager.Get_Android_Root_Path());
337 bool vendor_mount_state = PartitionManager.Is_Mounted_By_Path("/vendor");
bigbiffcfa875c2021-06-20 16:20:27 -0400338 PartitionManager.Mount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
339 PartitionManager.Mount_By_Path("/vendor", false);
bigbiff1f9e4842020-10-31 11:33:15 -0400340 TWFunc::copy_file("/system/bin/sh", "/tmp/sh", 0755);
Chaosmaster6c1477d2020-02-03 15:54:32 +0100341 mount("/tmp/sh", "/system/bin/sh", "auto", MS_BIND, NULL);
bigbiff1f9e4842020-10-31 11:33:15 -0400342 ret_val = Run_Update_Binary(path, wipe_cache, AB_OTA_ZIP_TYPE);
Chaosmaster6c1477d2020-02-03 15:54:32 +0100343 umount("/system/bin/sh");
344 unlink("/tmp/sh");
345 if (!vendor_mount_state)
bigbiffcfa875c2021-06-20 16:20:27 -0400346 PartitionManager.UnMount_By_Path("/vendor", false);
Chaosmaster6c1477d2020-02-03 15:54:32 +0100347 if (!system_mount_state)
bigbiffcfa875c2021-06-20 16:20:27 -0400348 PartitionManager.UnMount_By_Path(PartitionManager.Get_Android_Root_Path(), false);
bigbiffab76bd72021-10-11 10:17:48 -0400349 if (android::base::GetBoolProperty("ro.virtual_ab.enabled", false)) {
bigbiffcfa875c2021-06-20 16:20:27 -0400350 PartitionManager.Prepare_All_Super_Volumes();
351 gui_warn("mount_vab_partitions=Devices on super may not mount until rebooting recovery.");
352 }
Chaosmastera6da6562020-02-07 19:58:10 +0100353 gui_warn("flash_ab_reboot=To flash additional zips, please reboot recovery to switch to the updated slot.");
nebrassyac29e692021-05-20 13:03:30 +0200354 DataManager::GetValue(TW_AUTO_REFLASHTWRP_VAR, reflashtwrp);
355 if (reflashtwrp) {
356 twrpRepacker repacker;
357 repacker.Flash_Current_Twrp();
358 }
Ethan Yonker941a8992016-12-05 09:04:30 -0600359 } else {
bigbiff673c7ae2020-12-02 19:44:56 -0500360 std::string binary_name("ui.xml");
bigbiff1f9e4842020-10-31 11:33:15 -0400361 ZipEntry binary_entry;
362 if (FindEntry(Zip, binary_name, &binary_entry) != 0) {
Ethan Yonker941a8992016-12-05 09:04:30 -0600363 LOGINFO("TWRP theme zip\n");
bigbiff1f9e4842020-10-31 11:33:15 -0400364 ret_val = Install_Theme(path, Zip);
Ethan Yonker941a8992016-12-05 09:04:30 -0600365 } else {
bigbiff1f9e4842020-10-31 11:33:15 -0400366 CloseArchive(Zip);
Ethan Yonker941a8992016-12-05 09:04:30 -0600367 ret_val = INSTALL_CORRUPT;
368 }
369 }
370 }
Ethan Yonker072c8d82016-08-26 22:22:24 -0500371 time(&stop);
372 int total_time = (int) difftime(stop, start);
Ethan Yonker20eb0bc2016-03-22 14:23:28 -0500373 if (ret_val == INSTALL_CORRUPT) {
Ethan Yonker941a8992016-12-05 09:04:30 -0600374 gui_err("invalid_zip_format=Invalid zip file format!");
Ethan Yonker072c8d82016-08-26 22:22:24 -0500375 } else {
376 LOGINFO("Install took %i second(s).\n", total_time);
Ethan Yonker20eb0bc2016-03-22 14:23:28 -0500377 }
Ethan Yonkerf9796a42014-11-08 07:28:03 -0600378 return ret_val;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400379}