blob: 752957638b013b211135dedbd139b1b4fe15d060 [file] [log] [blame]
Dees Troy3be70a82013-10-22 14:25:12 +00001/*
Ethan Yonker20eb0bc2016-03-22 14:23:28 -05002 Copyright 2012 to 2016 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
19#include <ctype.h>
20#include <errno.h>
21#include <fcntl.h>
22#include <limits.h>
23#include <sys/stat.h>
24#include <sys/wait.h>
25#include <unistd.h>
26
27#include <string.h>
28#include <stdio.h>
29
Dees_Troy2673cec2013-04-02 20:22:16 +000030#include "twcommon.h"
Ethan Yonker75bf0412014-11-21 13:54:27 -060031#include "mtdutils/mounts.h"
32#include "mtdutils/mtdutils.h"
Dees_Troy32c8eb82012-09-11 15:28:06 -040033#include "minzip/SysUtil.h"
34#include "minzip/Zip.h"
Ethan Yonkerf1179622016-08-25 15:32:21 -050035#ifdef USE_OLD_VERIFIER
Ethan Yonker4bf259f2016-08-29 11:50:34 -050036#include "verifier24/verifier.h"
Ethan Yonkerf1179622016-08-25 15:32:21 -050037#else
Ethan Yonker75bf0412014-11-21 13:54:27 -060038#include "verifier.h"
Ethan Yonkerf1179622016-08-25 15:32:21 -050039#endif
Dees_Troy32c8eb82012-09-11 15:28:06 -040040#include "variables.h"
41#include "data.hpp"
42#include "partitions.hpp"
bigbiff bigbiff56cf5642016-08-19 17:43:45 -040043#include "twrpDigestDriver.hpp"
44#include "twrpDigest/twrpDigest.hpp"
45#include "twrpDigest/twrpMD5.hpp"
Dees_Troy38bd7602012-09-14 13:33:53 -040046#include "twrp-functions.hpp"
Ethan Yonker74db1572015-10-28 12:44:49 -050047#include "gui/gui.hpp"
Ethan Yonker20eb0bc2016-03-22 14:23:28 -050048#include "gui/pages.hpp"
Ethan Yonkerf1179622016-08-25 15:32:21 -050049#include "legacy_property_service.h"
Ethan Yonker941a8992016-12-05 09:04:30 -060050#include "twinstall.h"
51#include "installcommand.h"
Dees_Troy2673cec2013-04-02 20:22:16 +000052extern "C" {
53 #include "gui/gui.h"
that7e303cf2014-03-06 07:57:43 +010054}
55
Ethan Yonker941a8992016-12-05 09:04:30 -060056#define AB_OTA "payload_properties.txt"
57
that7e303cf2014-03-06 07:57:43 +010058static const char* properties_path = "/dev/__properties__";
59static const char* properties_path_renamed = "/dev/__properties_kk__";
Matt Mowercdd3b332014-03-27 14:38:48 -050060static bool legacy_props_env_initd = false;
61static bool legacy_props_path_modified = false;
that7e303cf2014-03-06 07:57:43 +010062
Ethan Yonker941a8992016-12-05 09:04:30 -060063enum zip_type {
64 UNKNOWN_ZIP_TYPE = 0,
65 UPDATE_BINARY_ZIP_TYPE,
66 AB_OTA_ZIP_TYPE,
67 TWRP_THEME_ZIP_TYPE
68};
69
that50640482015-08-30 12:08:05 +020070// to support pre-KitKat update-binaries that expect properties in the legacy format
Matt Mowercdd3b332014-03-27 14:38:48 -050071static int switch_to_legacy_properties()
that7e303cf2014-03-06 07:57:43 +010072{
Matt Mowercdd3b332014-03-27 14:38:48 -050073 if (!legacy_props_env_initd) {
74 if (legacy_properties_init() != 0)
75 return -1;
76
77 char tmp[32];
78 int propfd, propsz;
79 legacy_get_property_workspace(&propfd, &propsz);
80 sprintf(tmp, "%d,%d", dup(propfd), propsz);
81 setenv("ANDROID_PROPERTY_WORKSPACE", tmp, 1);
82 legacy_props_env_initd = true;
83 }
that7e303cf2014-03-06 07:57:43 +010084
85 if (TWFunc::Path_Exists(properties_path)) {
86 // hide real properties so that the updater uses the envvar to find the legacy format properties
Matt Mowercdd3b332014-03-27 14:38:48 -050087 if (rename(properties_path, properties_path_renamed) != 0) {
88 LOGERR("Renaming %s failed: %s\n", properties_path, strerror(errno));
89 return -1;
90 } else {
91 legacy_props_path_modified = true;
92 }
that7e303cf2014-03-06 07:57:43 +010093 }
Matt Mowercdd3b332014-03-27 14:38:48 -050094
95 return 0;
that7e303cf2014-03-06 07:57:43 +010096}
97
Matt Mowercdd3b332014-03-27 14:38:48 -050098static int switch_to_new_properties()
that7e303cf2014-03-06 07:57:43 +010099{
100 if (TWFunc::Path_Exists(properties_path_renamed)) {
Matt Mowercdd3b332014-03-27 14:38:48 -0500101 if (rename(properties_path_renamed, properties_path) != 0) {
102 LOGERR("Renaming %s failed: %s\n", properties_path_renamed, strerror(errno));
103 return -1;
104 } else {
105 legacy_props_path_modified = false;
106 }
that7e303cf2014-03-06 07:57:43 +0100107 }
Matt Mowercdd3b332014-03-27 14:38:48 -0500108
109 return 0;
Dees_Troy2673cec2013-04-02 20:22:16 +0000110}
Dees_Troy32c8eb82012-09-11 15:28:06 -0400111
Ethan Yonker20eb0bc2016-03-22 14:23:28 -0500112static int Install_Theme(const char* path, ZipArchive *Zip) {
113#ifdef TW_OEM_BUILD // We don't do custom themes in OEM builds
114 mzCloseZipArchive(Zip);
115 return INSTALL_CORRUPT;
116#else
117 const ZipEntry* xml_location = mzFindZipEntry(Zip, "ui.xml");
118
119 mzCloseZipArchive(Zip);
120 if (xml_location == NULL) {
121 return INSTALL_CORRUPT;
122 }
123 if (!PartitionManager.Mount_Settings_Storage(true))
124 return INSTALL_ERROR;
125 string theme_path = DataManager::GetSettingsStoragePath();
126 theme_path += "/TWRP/theme";
127 if (!TWFunc::Path_Exists(theme_path)) {
128 if (!TWFunc::Recursive_Mkdir(theme_path)) {
129 return INSTALL_ERROR;
130 }
131 }
132 theme_path += "/ui.zip";
133 if (TWFunc::copy_file(path, theme_path, 0644) != 0) {
134 return INSTALL_ERROR;
135 }
136 LOGINFO("Installing custom theme '%s' to '%s'\n", path, theme_path.c_str());
137 PageManager::RequestReload();
138 return INSTALL_SUCCESS;
139#endif
140}
141
Ethan Yonker941a8992016-12-05 09:04:30 -0600142static int Prepare_Update_Binary(const char *path, ZipArchive *Zip, int* wipe_cache) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000143 const ZipEntry* binary_location = mzFindZipEntry(Zip, ASSUMED_UPDATE_BINARY_NAME);
Ethan Yonker941a8992016-12-05 09:04:30 -0600144 int binary_fd, ret_val;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400145
Dees_Troy2673cec2013-04-02 20:22:16 +0000146 if (binary_location == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000147 return INSTALL_CORRUPT;
148 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400149
Dees_Troy2673cec2013-04-02 20:22:16 +0000150 // Delete any existing updater
Ethan Yonker941a8992016-12-05 09:04:30 -0600151 if (TWFunc::Path_Exists(TMP_UPDATER_BINARY_PATH) && unlink(TMP_UPDATER_BINARY_PATH) != 0) {
152 LOGINFO("Unable to unlink '%s': %s\n", TMP_UPDATER_BINARY_PATH, strerror(errno));
Dees_Troy2673cec2013-04-02 20:22:16 +0000153 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400154
Ethan Yonker941a8992016-12-05 09:04:30 -0600155 binary_fd = creat(TMP_UPDATER_BINARY_PATH, 0755);
Dees_Troy2673cec2013-04-02 20:22:16 +0000156 if (binary_fd < 0) {
Ethan Yonker941a8992016-12-05 09:04:30 -0600157 LOGERR("Could not create file for updater extract in '%s': %s\n", TMP_UPDATER_BINARY_PATH, strerror(errno));
Dees_Troy2673cec2013-04-02 20:22:16 +0000158 mzCloseZipArchive(Zip);
Dees_Troy2673cec2013-04-02 20:22:16 +0000159 return INSTALL_ERROR;
160 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400161
Dees_Troy2673cec2013-04-02 20:22:16 +0000162 ret_val = mzExtractZipEntryToFile(Zip, binary_location, binary_fd);
163 close(binary_fd);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400164
Dees_Troy2673cec2013-04-02 20:22:16 +0000165 if (!ret_val) {
Dees_Troy512376c2013-09-03 19:39:41 +0000166 mzCloseZipArchive(Zip);
Dees_Troy2673cec2013-04-02 20:22:16 +0000167 LOGERR("Could not extract '%s'\n", ASSUMED_UPDATE_BINARY_NAME);
168 return INSTALL_ERROR;
169 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400170
Dees_Troy512376c2013-09-03 19:39:41 +0000171 // If exists, extract file_contexts from the zip file
172 const ZipEntry* selinx_contexts = mzFindZipEntry(Zip, "file_contexts");
173 if (selinx_contexts == NULL) {
174 mzCloseZipArchive(Zip);
175 LOGINFO("Zip does not contain SELinux file_contexts file in its root.\n");
176 } else {
177 string output_filename = "/file_contexts";
178 LOGINFO("Zip contains SELinux file_contexts file in its root. Extracting to %s\n", output_filename.c_str());
179 // Delete any file_contexts
180 if (TWFunc::Path_Exists(output_filename) && unlink(output_filename.c_str()) != 0) {
that50640482015-08-30 12:08:05 +0200181 LOGINFO("Unable to unlink '%s': %s\n", output_filename.c_str(), strerror(errno));
Dees_Troy512376c2013-09-03 19:39:41 +0000182 }
183
184 int file_contexts_fd = creat(output_filename.c_str(), 0644);
185 if (file_contexts_fd < 0) {
that50640482015-08-30 12:08:05 +0200186 LOGERR("Could not extract to '%s': %s\n", output_filename.c_str(), strerror(errno));
Dees_Troy512376c2013-09-03 19:39:41 +0000187 mzCloseZipArchive(Zip);
Dees_Troy512376c2013-09-03 19:39:41 +0000188 return INSTALL_ERROR;
189 }
190
191 ret_val = mzExtractZipEntryToFile(Zip, selinx_contexts, file_contexts_fd);
192 close(file_contexts_fd);
193
194 if (!ret_val) {
195 mzCloseZipArchive(Zip);
that50640482015-08-30 12:08:05 +0200196 LOGERR("Could not extract '%s'\n", output_filename.c_str());
Dees_Troy512376c2013-09-03 19:39:41 +0000197 return INSTALL_ERROR;
198 }
199 }
200 mzCloseZipArchive(Zip);
Ethan Yonker941a8992016-12-05 09:04:30 -0600201 return INSTALL_SUCCESS;
202}
203
204static int Run_Update_Binary(const char *path, ZipArchive *Zip, int* wipe_cache, zip_type ztype) {
205 int ret_val, pipe_fd[2], status, zip_verify;
206 char buffer[1024];
207 FILE* child_data;
Dees_Troy512376c2013-09-03 19:39:41 +0000208
Matt Mower6883d732014-03-20 17:28:13 -0500209#ifndef TW_NO_LEGACY_PROPS
Matt Mowercdd3b332014-03-27 14:38:48 -0500210 /* Set legacy properties */
211 if (switch_to_legacy_properties() != 0) {
212 LOGERR("Legacy property environment did not initialize successfully. Properties may not be detected.\n");
213 } else {
214 LOGINFO("Legacy property environment initialized.\n");
215 }
Matt Mower6883d732014-03-20 17:28:13 -0500216#endif
Matt Mowercdd3b332014-03-27 14:38:48 -0500217
Dees_Troy2673cec2013-04-02 20:22:16 +0000218 pipe(pipe_fd);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400219
Ethan Yonker941a8992016-12-05 09:04:30 -0600220 std::vector<std::string> args;
221 if (ztype == UPDATE_BINARY_ZIP_TYPE) {
222 ret_val = update_binary_command(path, Zip, 0, pipe_fd[1], &args);
223 } else if (ztype == AB_OTA_ZIP_TYPE) {
224 ret_val = abupdate_binary_command(path, Zip, 0, pipe_fd[1], &args);
225 } else {
226 LOGERR("Unknown zip type %i\n", ztype);
227 ret_val = INSTALL_CORRUPT;
228 }
229 if (ret_val) {
230 close(pipe_fd[0]);
231 close(pipe_fd[1]);
232 return ret_val;
233 }
234
235 // Convert the vector to a NULL-terminated char* array suitable for execv.
236 const char* chr_args[args.size() + 1];
237 chr_args[args.size()] = NULL;
238 for (size_t i = 0; i < args.size(); i++)
239 chr_args[i] = args[i].c_str();
Dees_Troy32c8eb82012-09-11 15:28:06 -0400240
Dees_Troy2673cec2013-04-02 20:22:16 +0000241 pid_t pid = fork();
242 if (pid == 0) {
243 close(pipe_fd[0]);
Ethan Yonker941a8992016-12-05 09:04:30 -0600244 execve(chr_args[0], const_cast<char**>(chr_args), environ);
245 printf("E:Can't execute '%s': %s\n", chr_args[0], strerror(errno));
Dees_Troy2673cec2013-04-02 20:22:16 +0000246 _exit(-1);
247 }
248 close(pipe_fd[1]);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400249
Dees_Troy2673cec2013-04-02 20:22:16 +0000250 *wipe_cache = 0;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400251
Dees_Troy2673cec2013-04-02 20:22:16 +0000252 DataManager::GetValue(TW_SIGNED_ZIP_VERIFY_VAR, zip_verify);
253 child_data = fdopen(pipe_fd[0], "r");
254 while (fgets(buffer, sizeof(buffer), child_data) != NULL) {
255 char* command = strtok(buffer, " \n");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200256 if (command == NULL) {
257 continue;
258 } else if (strcmp(command, "progress") == 0) {
259 char* fraction_char = strtok(NULL, " \n");
260 char* seconds_char = strtok(NULL, " \n");
Dees_Troy32c8eb82012-09-11 15:28:06 -0400261
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200262 float fraction_float = strtof(fraction_char, NULL);
263 int seconds_float = strtol(seconds_char, NULL, 10);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400264
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200265 if (zip_verify)
Dees_Troy2673cec2013-04-02 20:22:16 +0000266 DataManager::ShowProgress(fraction_float * (1 - VERIFICATION_PROGRESS_FRACTION), seconds_float);
267 else
268 DataManager::ShowProgress(fraction_float, seconds_float);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200269 } else if (strcmp(command, "set_progress") == 0) {
270 char* fraction_char = strtok(NULL, " \n");
271 float fraction_float = strtof(fraction_char, NULL);
272 DataManager::SetProgress(fraction_float);
273 } else if (strcmp(command, "ui_print") == 0) {
274 char* display_value = strtok(NULL, "\n");
275 if (display_value) {
276 gui_print("%s", display_value);
277 } else {
278 gui_print("\n");
279 }
280 } else if (strcmp(command, "wipe_cache") == 0) {
281 *wipe_cache = 1;
282 } else if (strcmp(command, "clear_display") == 0) {
283 // Do nothing, not supported by TWRP
Ethan Yonker072c8d82016-08-26 22:22:24 -0500284 } else if (strcmp(command, "log") == 0) {
285 printf("%s\n", strtok(NULL, "\n"));
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200286 } else {
287 LOGERR("unknown command [%s]\n", command);
288 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000289 }
290 fclose(child_data);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400291
that50640482015-08-30 12:08:05 +0200292 int waitrc = TWFunc::Wait_For_Child(pid, &status, "Updater");
Matt Mowercdd3b332014-03-27 14:38:48 -0500293
Matt Mower6883d732014-03-20 17:28:13 -0500294#ifndef TW_NO_LEGACY_PROPS
Matt Mowercdd3b332014-03-27 14:38:48 -0500295 /* Unset legacy properties */
296 if (legacy_props_path_modified) {
297 if (switch_to_new_properties() != 0) {
298 LOGERR("Legacy property environment did not disable successfully. Legacy properties may still be in use.\n");
299 } else {
300 LOGINFO("Legacy property environment disabled.\n");
301 }
302 }
Matt Mower6883d732014-03-20 17:28:13 -0500303#endif
Matt Mowercdd3b332014-03-27 14:38:48 -0500304
that50640482015-08-30 12:08:05 +0200305 if (waitrc != 0)
Dees_Troy2673cec2013-04-02 20:22:16 +0000306 return INSTALL_ERROR;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400307
Dees_Troy2673cec2013-04-02 20:22:16 +0000308 return INSTALL_SUCCESS;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400309}
310
Dees_Troy32c8eb82012-09-11 15:28:06 -0400311extern "C" int TWinstall_zip(const char* path, int* wipe_cache) {
that50640482015-08-30 12:08:05 +0200312 int ret_val, zip_verify = 1;
Dees_Troy2673cec2013-04-02 20:22:16 +0000313 ZipArchive Zip;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400314
Ethan Yonker24813422014-11-07 17:19:07 -0600315 if (strcmp(path, "error") == 0) {
316 LOGERR("Failed to get adb sideload file: '%s'\n", path);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400317 return INSTALL_CORRUPT;
Matt Mowerd5c1a922014-04-15 12:50:58 -0500318 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400319
Ethan Yonker74db1572015-10-28 12:44:49 -0500320 gui_msg(Msg("installing_zip=Installing zip file '{1}'")(path));
Ethan Yonker24813422014-11-07 17:19:07 -0600321 if (strlen(path) < 9 || strncmp(path, "/sideload", 9) != 0) {
bigbiff bigbiff56cf5642016-08-19 17:43:45 -0400322 string digest_str;
323 string Full_Filename = path;
324 string digest_file = path;
325 digest_file += ".md5";
326
327 gui_msg("check_for_digest=Checking for Digest file...");
328 if (!TWFunc::Path_Exists(digest_file)) {
329 gui_msg("no_digest=Skipping Digest check: no Digest file found");
330 }
331 else {
332 if (TWFunc::read_file(digest_file, digest_str) != 0) {
333 LOGERR("Skipping MD5 check: MD5 file unreadable\n");
334 }
335 else {
336 twrpDigest *digest = new twrpMD5();
337 if (!twrpDigestDriver::stream_file_to_digest(Full_Filename, digest)) {
338 delete digest;
339 return INSTALL_CORRUPT;
340 }
341 string digest_check = digest->return_digest_string();
342 if (digest_str == digest_check) {
343 gui_msg(Msg("digest_matched=Digest matched for '{1}'.")(path));
344 }
345 else {
346 LOGERR("Aborting zip install: Digest verification failed\n");
347 delete digest;
348 return INSTALL_CORRUPT;
349 }
350 delete digest;
351 }
Ethan Yonker24813422014-11-07 17:19:07 -0600352 }
353 }
354
Ethan Yonkerd5801c52014-04-14 08:59:35 -0500355#ifndef TW_OEM_BUILD
Dees_Troy32c8eb82012-09-11 15:28:06 -0400356 DataManager::GetValue(TW_SIGNED_ZIP_VERIFY_VAR, zip_verify);
Ethan Yonkerd5801c52014-04-14 08:59:35 -0500357#endif
Dees_Troy2673cec2013-04-02 20:22:16 +0000358 DataManager::SetProgress(0);
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600359
360 MemMapping map;
361 if (sysMapFile(path, &map) != 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500362 gui_msg(Msg(msg::kError, "fail_sysmap=Failed to map file '{1}'")(path));
that50640482015-08-30 12:08:05 +0200363 return -1;
364 }
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600365
Dees_Troy32c8eb82012-09-11 15:28:06 -0400366 if (zip_verify) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500367 gui_msg("verify_zip_sig=Verifying zip signature...");
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600368 ret_val = verify_file(map.addr, map.length);
Dees_Troy2673cec2013-04-02 20:22:16 +0000369 if (ret_val != VERIFY_SUCCESS) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500370 LOGINFO("Zip signature verification failed: %i\n", ret_val);
371 gui_err("verify_zip_fail=Zip signature verification failed!");
Ethan Yonkerf9796a42014-11-08 07:28:03 -0600372 sysReleaseMap(&map);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400373 return -1;
Ethan Yonker738be7a2014-12-10 11:40:43 -0600374 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500375 gui_msg("verify_zip_done=Zip signature verified successfully.");
Dees_Troy32c8eb82012-09-11 15:28:06 -0400376 }
377 }
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600378 ret_val = mzOpenZipArchive(map.addr, map.length, &Zip);
Dees_Troy2673cec2013-04-02 20:22:16 +0000379 if (ret_val != 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500380 gui_err("zip_corrupt=Zip file is corrupt!");
Ethan Yonkerf9796a42014-11-08 07:28:03 -0600381 sysReleaseMap(&map);
Dees_Troy2673cec2013-04-02 20:22:16 +0000382 return INSTALL_CORRUPT;
383 }
Ethan Yonker941a8992016-12-05 09:04:30 -0600384
Ethan Yonker072c8d82016-08-26 22:22:24 -0500385 time_t start, stop;
386 time(&start);
Ethan Yonker941a8992016-12-05 09:04:30 -0600387 const ZipEntry* file_location = mzFindZipEntry(&Zip, ASSUMED_UPDATE_BINARY_NAME);
388 if (file_location != NULL) {
389 LOGINFO("Update binary zip\n");
390 ret_val = Prepare_Update_Binary(path, &Zip, wipe_cache);
391 if (ret_val == INSTALL_SUCCESS)
392 ret_val = Run_Update_Binary(path, &Zip, wipe_cache, UPDATE_BINARY_ZIP_TYPE);
393 } else {
394 file_location = mzFindZipEntry(&Zip, AB_OTA);
395 if (file_location != NULL) {
396 LOGINFO("AB zip\n");
397 ret_val = Run_Update_Binary(path, &Zip, wipe_cache, AB_OTA_ZIP_TYPE);
398 } else {
399 file_location = mzFindZipEntry(&Zip, "ui.xml");
400 if (file_location != NULL) {
401 LOGINFO("TWRP theme zip\n");
402 ret_val = Install_Theme(path, &Zip);
403 } else {
404 mzCloseZipArchive(&Zip);
405 ret_val = INSTALL_CORRUPT;
406 }
407 }
408 }
Ethan Yonker072c8d82016-08-26 22:22:24 -0500409 time(&stop);
410 int total_time = (int) difftime(stop, start);
Ethan Yonker20eb0bc2016-03-22 14:23:28 -0500411 if (ret_val == INSTALL_CORRUPT) {
Ethan Yonker941a8992016-12-05 09:04:30 -0600412 gui_err("invalid_zip_format=Invalid zip file format!");
Ethan Yonker072c8d82016-08-26 22:22:24 -0500413 } else {
414 LOGINFO("Install took %i second(s).\n", total_time);
Ethan Yonker20eb0bc2016-03-22 14:23:28 -0500415 }
Ethan Yonkerf9796a42014-11-08 07:28:03 -0600416 sysReleaseMap(&map);
417 return ret_val;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400418}