blob: 75d9a489e00f2b8d15bb6700065436d108895081 [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 bigbiffcdcfee42013-02-27 21:11:26 -050043#include "twrpDigest.hpp"
Dees_Troy38bd7602012-09-14 13:33:53 -040044#include "twrp-functions.hpp"
Ethan Yonker74db1572015-10-28 12:44:49 -050045#include "gui/gui.hpp"
Ethan Yonker20eb0bc2016-03-22 14:23:28 -050046#include "gui/pages.hpp"
Ethan Yonkerf1179622016-08-25 15:32:21 -050047#include "legacy_property_service.h"
Ethan Yonker941a8992016-12-05 09:04:30 -060048#include "twinstall.h"
49#include "installcommand.h"
Dees_Troy2673cec2013-04-02 20:22:16 +000050extern "C" {
51 #include "gui/gui.h"
that7e303cf2014-03-06 07:57:43 +010052}
53
Ethan Yonker941a8992016-12-05 09:04:30 -060054#define AB_OTA "payload_properties.txt"
55
that7e303cf2014-03-06 07:57:43 +010056static const char* properties_path = "/dev/__properties__";
57static const char* properties_path_renamed = "/dev/__properties_kk__";
Matt Mowercdd3b332014-03-27 14:38:48 -050058static bool legacy_props_env_initd = false;
59static bool legacy_props_path_modified = false;
that7e303cf2014-03-06 07:57:43 +010060
Ethan Yonker941a8992016-12-05 09:04:30 -060061enum zip_type {
62 UNKNOWN_ZIP_TYPE = 0,
63 UPDATE_BINARY_ZIP_TYPE,
64 AB_OTA_ZIP_TYPE,
65 TWRP_THEME_ZIP_TYPE
66};
67
that50640482015-08-30 12:08:05 +020068// to support pre-KitKat update-binaries that expect properties in the legacy format
Matt Mowercdd3b332014-03-27 14:38:48 -050069static int switch_to_legacy_properties()
that7e303cf2014-03-06 07:57:43 +010070{
Matt Mowercdd3b332014-03-27 14:38:48 -050071 if (!legacy_props_env_initd) {
72 if (legacy_properties_init() != 0)
73 return -1;
74
75 char tmp[32];
76 int propfd, propsz;
77 legacy_get_property_workspace(&propfd, &propsz);
78 sprintf(tmp, "%d,%d", dup(propfd), propsz);
79 setenv("ANDROID_PROPERTY_WORKSPACE", tmp, 1);
80 legacy_props_env_initd = true;
81 }
that7e303cf2014-03-06 07:57:43 +010082
83 if (TWFunc::Path_Exists(properties_path)) {
84 // hide real properties so that the updater uses the envvar to find the legacy format properties
Matt Mowercdd3b332014-03-27 14:38:48 -050085 if (rename(properties_path, properties_path_renamed) != 0) {
86 LOGERR("Renaming %s failed: %s\n", properties_path, strerror(errno));
87 return -1;
88 } else {
89 legacy_props_path_modified = true;
90 }
that7e303cf2014-03-06 07:57:43 +010091 }
Matt Mowercdd3b332014-03-27 14:38:48 -050092
93 return 0;
that7e303cf2014-03-06 07:57:43 +010094}
95
Matt Mowercdd3b332014-03-27 14:38:48 -050096static int switch_to_new_properties()
that7e303cf2014-03-06 07:57:43 +010097{
98 if (TWFunc::Path_Exists(properties_path_renamed)) {
Matt Mowercdd3b332014-03-27 14:38:48 -050099 if (rename(properties_path_renamed, properties_path) != 0) {
100 LOGERR("Renaming %s failed: %s\n", properties_path_renamed, strerror(errno));
101 return -1;
102 } else {
103 legacy_props_path_modified = false;
104 }
that7e303cf2014-03-06 07:57:43 +0100105 }
Matt Mowercdd3b332014-03-27 14:38:48 -0500106
107 return 0;
Dees_Troy2673cec2013-04-02 20:22:16 +0000108}
Dees_Troy32c8eb82012-09-11 15:28:06 -0400109
Ethan Yonker20eb0bc2016-03-22 14:23:28 -0500110static int Install_Theme(const char* path, ZipArchive *Zip) {
111#ifdef TW_OEM_BUILD // We don't do custom themes in OEM builds
112 mzCloseZipArchive(Zip);
113 return INSTALL_CORRUPT;
114#else
115 const ZipEntry* xml_location = mzFindZipEntry(Zip, "ui.xml");
116
117 mzCloseZipArchive(Zip);
118 if (xml_location == NULL) {
119 return INSTALL_CORRUPT;
120 }
121 if (!PartitionManager.Mount_Settings_Storage(true))
122 return INSTALL_ERROR;
123 string theme_path = DataManager::GetSettingsStoragePath();
124 theme_path += "/TWRP/theme";
125 if (!TWFunc::Path_Exists(theme_path)) {
126 if (!TWFunc::Recursive_Mkdir(theme_path)) {
127 return INSTALL_ERROR;
128 }
129 }
130 theme_path += "/ui.zip";
131 if (TWFunc::copy_file(path, theme_path, 0644) != 0) {
132 return INSTALL_ERROR;
133 }
134 LOGINFO("Installing custom theme '%s' to '%s'\n", path, theme_path.c_str());
135 PageManager::RequestReload();
136 return INSTALL_SUCCESS;
137#endif
138}
139
Ethan Yonker941a8992016-12-05 09:04:30 -0600140static int Prepare_Update_Binary(const char *path, ZipArchive *Zip, int* wipe_cache) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000141 const ZipEntry* binary_location = mzFindZipEntry(Zip, ASSUMED_UPDATE_BINARY_NAME);
Ethan Yonker941a8992016-12-05 09:04:30 -0600142 int binary_fd, ret_val;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400143
Dees_Troy2673cec2013-04-02 20:22:16 +0000144 if (binary_location == NULL) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000145 return INSTALL_CORRUPT;
146 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400147
Dees_Troy2673cec2013-04-02 20:22:16 +0000148 // Delete any existing updater
Ethan Yonker941a8992016-12-05 09:04:30 -0600149 if (TWFunc::Path_Exists(TMP_UPDATER_BINARY_PATH) && unlink(TMP_UPDATER_BINARY_PATH) != 0) {
150 LOGINFO("Unable to unlink '%s': %s\n", TMP_UPDATER_BINARY_PATH, strerror(errno));
Dees_Troy2673cec2013-04-02 20:22:16 +0000151 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400152
Ethan Yonker941a8992016-12-05 09:04:30 -0600153 binary_fd = creat(TMP_UPDATER_BINARY_PATH, 0755);
Dees_Troy2673cec2013-04-02 20:22:16 +0000154 if (binary_fd < 0) {
Ethan Yonker941a8992016-12-05 09:04:30 -0600155 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 +0000156 mzCloseZipArchive(Zip);
Dees_Troy2673cec2013-04-02 20:22:16 +0000157 return INSTALL_ERROR;
158 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400159
Dees_Troy2673cec2013-04-02 20:22:16 +0000160 ret_val = mzExtractZipEntryToFile(Zip, binary_location, binary_fd);
161 close(binary_fd);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400162
Dees_Troy2673cec2013-04-02 20:22:16 +0000163 if (!ret_val) {
Dees_Troy512376c2013-09-03 19:39:41 +0000164 mzCloseZipArchive(Zip);
Dees_Troy2673cec2013-04-02 20:22:16 +0000165 LOGERR("Could not extract '%s'\n", ASSUMED_UPDATE_BINARY_NAME);
166 return INSTALL_ERROR;
167 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400168
Dees_Troy512376c2013-09-03 19:39:41 +0000169 // If exists, extract file_contexts from the zip file
170 const ZipEntry* selinx_contexts = mzFindZipEntry(Zip, "file_contexts");
171 if (selinx_contexts == NULL) {
172 mzCloseZipArchive(Zip);
173 LOGINFO("Zip does not contain SELinux file_contexts file in its root.\n");
174 } else {
175 string output_filename = "/file_contexts";
176 LOGINFO("Zip contains SELinux file_contexts file in its root. Extracting to %s\n", output_filename.c_str());
177 // Delete any file_contexts
178 if (TWFunc::Path_Exists(output_filename) && unlink(output_filename.c_str()) != 0) {
that50640482015-08-30 12:08:05 +0200179 LOGINFO("Unable to unlink '%s': %s\n", output_filename.c_str(), strerror(errno));
Dees_Troy512376c2013-09-03 19:39:41 +0000180 }
181
182 int file_contexts_fd = creat(output_filename.c_str(), 0644);
183 if (file_contexts_fd < 0) {
that50640482015-08-30 12:08:05 +0200184 LOGERR("Could not extract to '%s': %s\n", output_filename.c_str(), strerror(errno));
Dees_Troy512376c2013-09-03 19:39:41 +0000185 mzCloseZipArchive(Zip);
Dees_Troy512376c2013-09-03 19:39:41 +0000186 return INSTALL_ERROR;
187 }
188
189 ret_val = mzExtractZipEntryToFile(Zip, selinx_contexts, file_contexts_fd);
190 close(file_contexts_fd);
191
192 if (!ret_val) {
193 mzCloseZipArchive(Zip);
that50640482015-08-30 12:08:05 +0200194 LOGERR("Could not extract '%s'\n", output_filename.c_str());
Dees_Troy512376c2013-09-03 19:39:41 +0000195 return INSTALL_ERROR;
196 }
197 }
198 mzCloseZipArchive(Zip);
Ethan Yonker941a8992016-12-05 09:04:30 -0600199 return INSTALL_SUCCESS;
200}
201
202static int Run_Update_Binary(const char *path, ZipArchive *Zip, int* wipe_cache, zip_type ztype) {
203 int ret_val, pipe_fd[2], status, zip_verify;
204 char buffer[1024];
205 FILE* child_data;
Dees_Troy512376c2013-09-03 19:39:41 +0000206
Matt Mower6883d732014-03-20 17:28:13 -0500207#ifndef TW_NO_LEGACY_PROPS
Matt Mowercdd3b332014-03-27 14:38:48 -0500208 /* Set legacy properties */
209 if (switch_to_legacy_properties() != 0) {
210 LOGERR("Legacy property environment did not initialize successfully. Properties may not be detected.\n");
211 } else {
212 LOGINFO("Legacy property environment initialized.\n");
213 }
Matt Mower6883d732014-03-20 17:28:13 -0500214#endif
Matt Mowercdd3b332014-03-27 14:38:48 -0500215
Dees_Troy2673cec2013-04-02 20:22:16 +0000216 pipe(pipe_fd);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400217
Ethan Yonker941a8992016-12-05 09:04:30 -0600218 std::vector<std::string> args;
219 if (ztype == UPDATE_BINARY_ZIP_TYPE) {
220 ret_val = update_binary_command(path, Zip, 0, pipe_fd[1], &args);
221 } else if (ztype == AB_OTA_ZIP_TYPE) {
222 ret_val = abupdate_binary_command(path, Zip, 0, pipe_fd[1], &args);
223 } else {
224 LOGERR("Unknown zip type %i\n", ztype);
225 ret_val = INSTALL_CORRUPT;
226 }
227 if (ret_val) {
228 close(pipe_fd[0]);
229 close(pipe_fd[1]);
230 return ret_val;
231 }
232
233 // Convert the vector to a NULL-terminated char* array suitable for execv.
234 const char* chr_args[args.size() + 1];
235 chr_args[args.size()] = NULL;
236 for (size_t i = 0; i < args.size(); i++)
237 chr_args[i] = args[i].c_str();
Dees_Troy32c8eb82012-09-11 15:28:06 -0400238
Dees_Troy2673cec2013-04-02 20:22:16 +0000239 pid_t pid = fork();
240 if (pid == 0) {
241 close(pipe_fd[0]);
Ethan Yonker941a8992016-12-05 09:04:30 -0600242 execve(chr_args[0], const_cast<char**>(chr_args), environ);
243 printf("E:Can't execute '%s': %s\n", chr_args[0], strerror(errno));
Dees_Troy2673cec2013-04-02 20:22:16 +0000244 _exit(-1);
245 }
246 close(pipe_fd[1]);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400247
Dees_Troy2673cec2013-04-02 20:22:16 +0000248 *wipe_cache = 0;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400249
Dees_Troy2673cec2013-04-02 20:22:16 +0000250 DataManager::GetValue(TW_SIGNED_ZIP_VERIFY_VAR, zip_verify);
251 child_data = fdopen(pipe_fd[0], "r");
252 while (fgets(buffer, sizeof(buffer), child_data) != NULL) {
253 char* command = strtok(buffer, " \n");
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200254 if (command == NULL) {
255 continue;
256 } else if (strcmp(command, "progress") == 0) {
257 char* fraction_char = strtok(NULL, " \n");
258 char* seconds_char = strtok(NULL, " \n");
Dees_Troy32c8eb82012-09-11 15:28:06 -0400259
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200260 float fraction_float = strtof(fraction_char, NULL);
261 int seconds_float = strtol(seconds_char, NULL, 10);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400262
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200263 if (zip_verify)
Dees_Troy2673cec2013-04-02 20:22:16 +0000264 DataManager::ShowProgress(fraction_float * (1 - VERIFICATION_PROGRESS_FRACTION), seconds_float);
265 else
266 DataManager::ShowProgress(fraction_float, seconds_float);
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200267 } else if (strcmp(command, "set_progress") == 0) {
268 char* fraction_char = strtok(NULL, " \n");
269 float fraction_float = strtof(fraction_char, NULL);
270 DataManager::SetProgress(fraction_float);
271 } else if (strcmp(command, "ui_print") == 0) {
272 char* display_value = strtok(NULL, "\n");
273 if (display_value) {
274 gui_print("%s", display_value);
275 } else {
276 gui_print("\n");
277 }
278 } else if (strcmp(command, "wipe_cache") == 0) {
279 *wipe_cache = 1;
280 } else if (strcmp(command, "clear_display") == 0) {
281 // Do nothing, not supported by TWRP
Ethan Yonker072c8d82016-08-26 22:22:24 -0500282 } else if (strcmp(command, "log") == 0) {
283 printf("%s\n", strtok(NULL, "\n"));
Vojtech Bocekfafb0c52013-07-25 22:53:02 +0200284 } else {
285 LOGERR("unknown command [%s]\n", command);
286 }
Dees_Troy2673cec2013-04-02 20:22:16 +0000287 }
288 fclose(child_data);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400289
that50640482015-08-30 12:08:05 +0200290 int waitrc = TWFunc::Wait_For_Child(pid, &status, "Updater");
Matt Mowercdd3b332014-03-27 14:38:48 -0500291
Matt Mower6883d732014-03-20 17:28:13 -0500292#ifndef TW_NO_LEGACY_PROPS
Matt Mowercdd3b332014-03-27 14:38:48 -0500293 /* Unset legacy properties */
294 if (legacy_props_path_modified) {
295 if (switch_to_new_properties() != 0) {
296 LOGERR("Legacy property environment did not disable successfully. Legacy properties may still be in use.\n");
297 } else {
298 LOGINFO("Legacy property environment disabled.\n");
299 }
300 }
Matt Mower6883d732014-03-20 17:28:13 -0500301#endif
Matt Mowercdd3b332014-03-27 14:38:48 -0500302
that50640482015-08-30 12:08:05 +0200303 if (waitrc != 0)
Dees_Troy2673cec2013-04-02 20:22:16 +0000304 return INSTALL_ERROR;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400305
Dees_Troy2673cec2013-04-02 20:22:16 +0000306 return INSTALL_SUCCESS;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400307}
308
Dees_Troy32c8eb82012-09-11 15:28:06 -0400309extern "C" int TWinstall_zip(const char* path, int* wipe_cache) {
that50640482015-08-30 12:08:05 +0200310 int ret_val, zip_verify = 1;
Dees_Troy2673cec2013-04-02 20:22:16 +0000311 ZipArchive Zip;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400312
Ethan Yonker24813422014-11-07 17:19:07 -0600313 if (strcmp(path, "error") == 0) {
314 LOGERR("Failed to get adb sideload file: '%s'\n", path);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400315 return INSTALL_CORRUPT;
Matt Mowerd5c1a922014-04-15 12:50:58 -0500316 }
Dees_Troy32c8eb82012-09-11 15:28:06 -0400317
Ethan Yonker74db1572015-10-28 12:44:49 -0500318 gui_msg(Msg("installing_zip=Installing zip file '{1}'")(path));
Ethan Yonker24813422014-11-07 17:19:07 -0600319 if (strlen(path) < 9 || strncmp(path, "/sideload", 9) != 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500320 gui_msg("check_for_md5=Checking for MD5 file...");
that50640482015-08-30 12:08:05 +0200321 twrpDigest md5sum;
322 md5sum.setfn(path);
James Christopher Adduono79ae0932016-10-25 02:18:32 -0400323 switch (md5sum.verify_md5digest()) {
324 case MD5_OK:
325 gui_msg(Msg("md5_matched=MD5 matched for '{1}'.")(path));
326 break;
327 case MD5_NOT_FOUND:
328 gui_msg("no_md5=Skipping MD5 check: no MD5 file found");
329 break;
330 case MD5_FILE_UNREADABLE:
331 LOGERR("Skipping MD5 check: MD5 file unreadable\n");
332 break;
333 case MD5_MATCH_FAIL: // md5 did not match
334 LOGERR("Aborting zip install: MD5 verification failed\n");
Ethan Yonker24813422014-11-07 17:19:07 -0600335 return INSTALL_CORRUPT;
336 }
337 }
338
Ethan Yonkerd5801c52014-04-14 08:59:35 -0500339#ifndef TW_OEM_BUILD
Dees_Troy32c8eb82012-09-11 15:28:06 -0400340 DataManager::GetValue(TW_SIGNED_ZIP_VERIFY_VAR, zip_verify);
Ethan Yonkerd5801c52014-04-14 08:59:35 -0500341#endif
Dees_Troy2673cec2013-04-02 20:22:16 +0000342 DataManager::SetProgress(0);
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600343
344 MemMapping map;
345 if (sysMapFile(path, &map) != 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500346 gui_msg(Msg(msg::kError, "fail_sysmap=Failed to map file '{1}'")(path));
that50640482015-08-30 12:08:05 +0200347 return -1;
348 }
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600349
Dees_Troy32c8eb82012-09-11 15:28:06 -0400350 if (zip_verify) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500351 gui_msg("verify_zip_sig=Verifying zip signature...");
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600352 ret_val = verify_file(map.addr, map.length);
Dees_Troy2673cec2013-04-02 20:22:16 +0000353 if (ret_val != VERIFY_SUCCESS) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500354 LOGINFO("Zip signature verification failed: %i\n", ret_val);
355 gui_err("verify_zip_fail=Zip signature verification failed!");
Ethan Yonkerf9796a42014-11-08 07:28:03 -0600356 sysReleaseMap(&map);
Dees_Troy32c8eb82012-09-11 15:28:06 -0400357 return -1;
Ethan Yonker738be7a2014-12-10 11:40:43 -0600358 } else {
Ethan Yonker74db1572015-10-28 12:44:49 -0500359 gui_msg("verify_zip_done=Zip signature verified successfully.");
Dees_Troy32c8eb82012-09-11 15:28:06 -0400360 }
361 }
Ethan Yonkerf96087e2014-11-07 10:38:51 -0600362 ret_val = mzOpenZipArchive(map.addr, map.length, &Zip);
Dees_Troy2673cec2013-04-02 20:22:16 +0000363 if (ret_val != 0) {
Ethan Yonker74db1572015-10-28 12:44:49 -0500364 gui_err("zip_corrupt=Zip file is corrupt!");
Ethan Yonkerf9796a42014-11-08 07:28:03 -0600365 sysReleaseMap(&map);
Dees_Troy2673cec2013-04-02 20:22:16 +0000366 return INSTALL_CORRUPT;
367 }
Ethan Yonker941a8992016-12-05 09:04:30 -0600368
Ethan Yonker072c8d82016-08-26 22:22:24 -0500369 time_t start, stop;
370 time(&start);
Ethan Yonker941a8992016-12-05 09:04:30 -0600371 const ZipEntry* file_location = mzFindZipEntry(&Zip, ASSUMED_UPDATE_BINARY_NAME);
372 if (file_location != NULL) {
373 LOGINFO("Update binary zip\n");
374 ret_val = Prepare_Update_Binary(path, &Zip, wipe_cache);
375 if (ret_val == INSTALL_SUCCESS)
376 ret_val = Run_Update_Binary(path, &Zip, wipe_cache, UPDATE_BINARY_ZIP_TYPE);
377 } else {
378 file_location = mzFindZipEntry(&Zip, AB_OTA);
379 if (file_location != NULL) {
380 LOGINFO("AB zip\n");
381 ret_val = Run_Update_Binary(path, &Zip, wipe_cache, AB_OTA_ZIP_TYPE);
382 } else {
383 file_location = mzFindZipEntry(&Zip, "ui.xml");
384 if (file_location != NULL) {
385 LOGINFO("TWRP theme zip\n");
386 ret_val = Install_Theme(path, &Zip);
387 } else {
388 mzCloseZipArchive(&Zip);
389 ret_val = INSTALL_CORRUPT;
390 }
391 }
392 }
Ethan Yonker072c8d82016-08-26 22:22:24 -0500393 time(&stop);
394 int total_time = (int) difftime(stop, start);
Ethan Yonker20eb0bc2016-03-22 14:23:28 -0500395 if (ret_val == INSTALL_CORRUPT) {
Ethan Yonker941a8992016-12-05 09:04:30 -0600396 gui_err("invalid_zip_format=Invalid zip file format!");
Ethan Yonker072c8d82016-08-26 22:22:24 -0500397 } else {
398 LOGINFO("Install took %i second(s).\n", total_time);
Ethan Yonker20eb0bc2016-03-22 14:23:28 -0500399 }
Ethan Yonkerf9796a42014-11-08 07:28:03 -0600400 sysReleaseMap(&map);
401 return ret_val;
Dees_Troy32c8eb82012-09-11 15:28:06 -0400402}