The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 17 | #include <ctype.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 18 | #include <errno.h> |
| 19 | #include <fcntl.h> |
| 20 | #include <limits.h> |
Elliott Hughes | 26dbad2 | 2015-01-28 12:09:05 -0800 | [diff] [blame] | 21 | #include <string.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 22 | #include <sys/stat.h> |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 23 | #include <sys/wait.h> |
| 24 | #include <unistd.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 25 | |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 26 | #include <chrono> |
Tao Bao | 71e3e09 | 2016-02-02 14:02:27 -0800 | [diff] [blame] | 27 | #include <vector> |
| 28 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 29 | #include "common.h" |
| 30 | #include "install.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 31 | #include "minui/minui.h" |
| 32 | #include "minzip/SysUtil.h" |
| 33 | #include "minzip/Zip.h" |
| 34 | #include "mtdutils/mounts.h" |
| 35 | #include "mtdutils/mtdutils.h" |
| 36 | #include "roots.h" |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 37 | #include "ui.h" |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 38 | #include "verifier.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 39 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 40 | extern RecoveryUI* ui; |
| 41 | |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 42 | #define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary" |
Doug Zongker | d1b19b9 | 2009-04-01 15:48:46 -0700 | [diff] [blame] | 43 | #define PUBLIC_KEYS_FILE "/res/keys" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 44 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 45 | // Default allocation of progress bar segments to operations |
| 46 | static const int VERIFICATION_PROGRESS_TIME = 60; |
| 47 | static const float VERIFICATION_PROGRESS_FRACTION = 0.25; |
| 48 | static const float DEFAULT_FILES_PROGRESS_FRACTION = 0.4; |
| 49 | static const float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1; |
| 50 | |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 51 | // If the package contains an update binary, extract it and run it. |
| 52 | static int |
Tao Bao | 145d861 | 2015-03-25 15:51:15 -0700 | [diff] [blame] | 53 | try_update_binary(const char* path, ZipArchive* zip, bool* wipe_cache) { |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 54 | const ZipEntry* binary_entry = |
| 55 | mzFindZipEntry(zip, ASSUMED_UPDATE_BINARY_NAME); |
| 56 | if (binary_entry == NULL) { |
Doug Zongker | 8e5e4da | 2010-09-14 18:06:55 -0700 | [diff] [blame] | 57 | mzCloseZipArchive(zip); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 58 | return INSTALL_CORRUPT; |
| 59 | } |
| 60 | |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 61 | const char* binary = "/tmp/update_binary"; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 62 | unlink(binary); |
| 63 | int fd = creat(binary, 0755); |
| 64 | if (fd < 0) { |
Doug Zongker | 8e5e4da | 2010-09-14 18:06:55 -0700 | [diff] [blame] | 65 | mzCloseZipArchive(zip); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 66 | LOGE("Can't make %s\n", binary); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 67 | return INSTALL_ERROR; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 68 | } |
| 69 | bool ok = mzExtractZipEntryToFile(zip, binary_entry, fd); |
| 70 | close(fd); |
Doug Zongker | 8e5e4da | 2010-09-14 18:06:55 -0700 | [diff] [blame] | 71 | mzCloseZipArchive(zip); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 72 | |
| 73 | if (!ok) { |
| 74 | LOGE("Can't copy %s\n", ASSUMED_UPDATE_BINARY_NAME); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 75 | return INSTALL_ERROR; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | int pipefd[2]; |
| 79 | pipe(pipefd); |
| 80 | |
| 81 | // When executing the update binary contained in the package, the |
| 82 | // arguments passed are: |
| 83 | // |
Doug Zongker | fb2e3af | 2009-06-17 17:29:40 -0700 | [diff] [blame] | 84 | // - the version number for this interface |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 85 | // |
| 86 | // - an fd to which the program can write in order to update the |
| 87 | // progress bar. The program can write single-line commands: |
| 88 | // |
| 89 | // progress <frac> <secs> |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 90 | // fill up the next <frac> part of of the progress bar |
| 91 | // over <secs> seconds. If <secs> is zero, use |
| 92 | // set_progress commands to manually control the |
Tao Bao | b07e1f3 | 2015-04-10 16:14:52 -0700 | [diff] [blame] | 93 | // progress of this segment of the bar. |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 94 | // |
| 95 | // set_progress <frac> |
| 96 | // <frac> should be between 0.0 and 1.0; sets the |
| 97 | // progress bar within the segment defined by the most |
| 98 | // recent progress command. |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 99 | // |
| 100 | // firmware <"hboot"|"radio"> <filename> |
| 101 | // arrange to install the contents of <filename> in the |
Doug Zongker | e08991e | 2010-02-02 13:09:52 -0800 | [diff] [blame] | 102 | // given partition on reboot. |
| 103 | // |
| 104 | // (API v2: <filename> may start with "PACKAGE:" to |
| 105 | // indicate taking a file from the OTA package.) |
| 106 | // |
| 107 | // (API v3: this command no longer exists.) |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 108 | // |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 109 | // ui_print <string> |
| 110 | // display <string> on the screen. |
| 111 | // |
Tao Bao | b07e1f3 | 2015-04-10 16:14:52 -0700 | [diff] [blame] | 112 | // wipe_cache |
| 113 | // a wipe of cache will be performed following a successful |
| 114 | // installation. |
| 115 | // |
| 116 | // clear_display |
| 117 | // turn off the text display. |
| 118 | // |
| 119 | // enable_reboot |
| 120 | // packages can explicitly request that they want the user |
| 121 | // to be able to reboot during installation (useful for |
| 122 | // debugging packages that don't exit). |
| 123 | // |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 124 | // - the name of the package zip file. |
| 125 | // |
| 126 | |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 127 | const char** args = (const char**)malloc(sizeof(char*) * 5); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 128 | args[0] = binary; |
Doug Zongker | fb2e3af | 2009-06-17 17:29:40 -0700 | [diff] [blame] | 129 | args[1] = EXPAND(RECOVERY_API_VERSION); // defined in Android.mk |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 130 | char* temp = (char*)malloc(10); |
| 131 | sprintf(temp, "%d", pipefd[1]); |
| 132 | args[2] = temp; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 133 | args[3] = (char*)path; |
| 134 | args[4] = NULL; |
| 135 | |
| 136 | pid_t pid = fork(); |
| 137 | if (pid == 0) { |
Alistair Strachan | 027429a | 2013-07-17 10:41:49 -0700 | [diff] [blame] | 138 | umask(022); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 139 | close(pipefd[0]); |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 140 | execv(binary, (char* const*)args); |
Doug Zongker | 56c5105 | 2010-07-01 09:18:44 -0700 | [diff] [blame] | 141 | fprintf(stdout, "E:Can't run %s (%s)\n", binary, strerror(errno)); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 142 | _exit(-1); |
| 143 | } |
| 144 | close(pipefd[1]); |
| 145 | |
Tao Bao | 145d861 | 2015-03-25 15:51:15 -0700 | [diff] [blame] | 146 | *wipe_cache = false; |
Tianjie Xu | fa12b97 | 2016-02-05 18:25:58 -0800 | [diff] [blame] | 147 | bool retry_update = false; |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 148 | |
Doug Zongker | 64893cc | 2009-07-14 16:31:56 -0700 | [diff] [blame] | 149 | char buffer[1024]; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 150 | FILE* from_child = fdopen(pipefd[0], "r"); |
| 151 | while (fgets(buffer, sizeof(buffer), from_child) != NULL) { |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 152 | char* command = strtok(buffer, " \n"); |
| 153 | if (command == NULL) { |
| 154 | continue; |
| 155 | } else if (strcmp(command, "progress") == 0) { |
| 156 | char* fraction_s = strtok(NULL, " \n"); |
| 157 | char* seconds_s = strtok(NULL, " \n"); |
| 158 | |
| 159 | float fraction = strtof(fraction_s, NULL); |
| 160 | int seconds = strtol(seconds_s, NULL, 10); |
| 161 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 162 | ui->ShowProgress(fraction * (1-VERIFICATION_PROGRESS_FRACTION), seconds); |
Doug Zongker | fbf3c10 | 2009-06-24 09:36:20 -0700 | [diff] [blame] | 163 | } else if (strcmp(command, "set_progress") == 0) { |
| 164 | char* fraction_s = strtok(NULL, " \n"); |
| 165 | float fraction = strtof(fraction_s, NULL); |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 166 | ui->SetProgress(fraction); |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 167 | } else if (strcmp(command, "ui_print") == 0) { |
| 168 | char* str = strtok(NULL, "\n"); |
| 169 | if (str) { |
Tao Bao | b6918c7 | 2015-05-19 17:02:16 -0700 | [diff] [blame] | 170 | ui->PrintOnScreenOnly("%s", str); |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 171 | } else { |
Tao Bao | b6918c7 | 2015-05-19 17:02:16 -0700 | [diff] [blame] | 172 | ui->PrintOnScreenOnly("\n"); |
Doug Zongker | d9c9d10 | 2009-06-12 12:24:39 -0700 | [diff] [blame] | 173 | } |
Doug Zongker | fafc85b | 2013-07-09 12:29:45 -0700 | [diff] [blame] | 174 | fflush(stdout); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 175 | } else if (strcmp(command, "wipe_cache") == 0) { |
Tao Bao | 145d861 | 2015-03-25 15:51:15 -0700 | [diff] [blame] | 176 | *wipe_cache = true; |
Doug Zongker | e5d5ac7 | 2012-04-12 11:01:22 -0700 | [diff] [blame] | 177 | } else if (strcmp(command, "clear_display") == 0) { |
| 178 | ui->SetBackground(RecoveryUI::NONE); |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 179 | } else if (strcmp(command, "enable_reboot") == 0) { |
| 180 | // packages can explicitly request that they want the user |
| 181 | // to be able to reboot during installation (useful for |
| 182 | // debugging packages that don't exit). |
| 183 | ui->SetEnableReboot(true); |
Tianjie Xu | fa12b97 | 2016-02-05 18:25:58 -0800 | [diff] [blame] | 184 | } else if (strcmp(command, "retry_update") == 0) { |
| 185 | retry_update = true; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 186 | } else { |
| 187 | LOGE("unknown command [%s]\n", command); |
| 188 | } |
| 189 | } |
| 190 | fclose(from_child); |
| 191 | |
| 192 | int status; |
| 193 | waitpid(pid, &status, 0); |
Tianjie Xu | fa12b97 | 2016-02-05 18:25:58 -0800 | [diff] [blame] | 194 | if (retry_update) { |
| 195 | return INSTALL_RETRY; |
| 196 | } |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 197 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
Doug Zongker | 9931f7f | 2009-06-10 14:11:53 -0700 | [diff] [blame] | 198 | LOGE("Error in %s\n(Status %d)\n", path, WEXITSTATUS(status)); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 199 | return INSTALL_ERROR; |
| 200 | } |
| 201 | |
Doug Zongker | e08991e | 2010-02-02 13:09:52 -0800 | [diff] [blame] | 202 | return INSTALL_SUCCESS; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 203 | } |
| 204 | |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 205 | static int |
Tao Bao | 145d861 | 2015-03-25 15:51:15 -0700 | [diff] [blame] | 206 | really_install_package(const char *path, bool* wipe_cache, bool needs_mount) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 207 | { |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 208 | ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 209 | ui->Print("Finding update package...\n"); |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 210 | // Give verification half the progress bar... |
| 211 | ui->SetProgressType(RecoveryUI::DETERMINATE); |
| 212 | ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); |
Doug Zongker | cc8cd3f | 2010-09-20 12:16:13 -0700 | [diff] [blame] | 213 | LOGI("Update location: %s\n", path); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 214 | |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 215 | // Map the update package into memory. |
| 216 | ui->Print("Opening update package...\n"); |
| 217 | |
Doug Zongker | 075ad80 | 2014-06-26 15:35:51 -0700 | [diff] [blame] | 218 | if (path && needs_mount) { |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 219 | if (path[0] == '@') { |
| 220 | ensure_path_mounted(path+1); |
| 221 | } else { |
| 222 | ensure_path_mounted(path); |
| 223 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 224 | } |
| 225 | |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 226 | MemMapping map; |
| 227 | if (sysMapFile(path, &map) != 0) { |
| 228 | LOGE("failed to map file\n"); |
| 229 | return INSTALL_CORRUPT; |
| 230 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 231 | |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 232 | // Load keys. |
Tao Bao | 71e3e09 | 2016-02-02 14:02:27 -0800 | [diff] [blame] | 233 | std::vector<Certificate> loadedKeys; |
| 234 | if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { |
Doug Zongker | d1b19b9 | 2009-04-01 15:48:46 -0700 | [diff] [blame] | 235 | LOGE("Failed to load keys\n"); |
| 236 | return INSTALL_CORRUPT; |
| 237 | } |
Tao Bao | 71e3e09 | 2016-02-02 14:02:27 -0800 | [diff] [blame] | 238 | LOGI("%zu key(s) loaded from %s\n", loadedKeys.size(), PUBLIC_KEYS_FILE); |
Doug Zongker | d1b19b9 | 2009-04-01 15:48:46 -0700 | [diff] [blame] | 239 | |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 240 | // Verify package. |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 241 | ui->Print("Verifying update package...\n"); |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 242 | auto t0 = std::chrono::system_clock::now(); |
Tao Bao | 71e3e09 | 2016-02-02 14:02:27 -0800 | [diff] [blame] | 243 | int err = verify_file(map.addr, map.length, loadedKeys); |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 244 | std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0; |
| 245 | ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err); |
Doug Zongker | 60151a2 | 2009-08-12 18:30:03 -0700 | [diff] [blame] | 246 | if (err != VERIFY_SUCCESS) { |
| 247 | LOGE("signature verification failed\n"); |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 248 | sysReleaseMap(&map); |
Doug Zongker | 60151a2 | 2009-08-12 18:30:03 -0700 | [diff] [blame] | 249 | return INSTALL_CORRUPT; |
| 250 | } |
| 251 | |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 252 | // Try to open the package. |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 253 | ZipArchive zip; |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 254 | err = mzOpenZipArchive(map.addr, map.length, &zip); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 255 | if (err != 0) { |
| 256 | LOGE("Can't open %s\n(%s)\n", path, err != -1 ? strerror(err) : "bad"); |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 257 | sysReleaseMap(&map); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 258 | return INSTALL_CORRUPT; |
| 259 | } |
| 260 | |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 261 | // Verify and install the contents of the package. |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 262 | ui->Print("Installing update...\n"); |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 263 | ui->SetEnableReboot(false); |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 264 | int result = try_update_binary(path, &zip, wipe_cache); |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 265 | ui->SetEnableReboot(true); |
Doug Zongker | 075ad80 | 2014-06-26 15:35:51 -0700 | [diff] [blame] | 266 | ui->Print("\n"); |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 267 | |
| 268 | sysReleaseMap(&map); |
| 269 | |
| 270 | return result; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 271 | } |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 272 | |
| 273 | int |
Tao Bao | 145d861 | 2015-03-25 15:51:15 -0700 | [diff] [blame] | 274 | install_package(const char* path, bool* wipe_cache, const char* install_file, |
Doug Zongker | 075ad80 | 2014-06-26 15:35:51 -0700 | [diff] [blame] | 275 | bool needs_mount) |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 276 | { |
Tao Bao | 682c34b | 2015-04-07 17:16:35 -0700 | [diff] [blame] | 277 | modified_flash = true; |
| 278 | |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 279 | FILE* install_log = fopen_path(install_file, "w"); |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 280 | if (install_log) { |
| 281 | fputs(path, install_log); |
| 282 | fputc('\n', install_log); |
| 283 | } else { |
| 284 | LOGE("failed to open last_install: %s\n", strerror(errno)); |
| 285 | } |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 286 | int result; |
| 287 | if (setup_install_mounts() != 0) { |
| 288 | LOGE("failed to set up expected mounts for install; aborting\n"); |
| 289 | result = INSTALL_ERROR; |
| 290 | } else { |
Doug Zongker | 075ad80 | 2014-06-26 15:35:51 -0700 | [diff] [blame] | 291 | result = really_install_package(path, wipe_cache, needs_mount); |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 292 | } |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 293 | if (install_log) { |
| 294 | fputc(result == INSTALL_SUCCESS ? '1' : '0', install_log); |
| 295 | fputc('\n', install_log); |
| 296 | fclose(install_log); |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 297 | } |
| 298 | return result; |
| 299 | } |