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