blob: 21f633011b3b0fc794b1b5b06b5f3c06f09c6233 [file] [log] [blame]
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001/*
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
Jerry Zhangf5e319a2018-05-04 11:24:10 -070017#include "recovery.h"
Tao Bao6d99d4b2018-04-25 16:47:04 -070018
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080019#include <ctype.h>
Doug Zongker7c3ae452013-05-14 11:03:02 -070020#include <dirent.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080021#include <errno.h>
22#include <fcntl.h>
23#include <getopt.h>
Tao Bao862a4c12016-06-02 11:16:50 -070024#include <inttypes.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080025#include <limits.h>
Tao Bao862a4c12016-06-02 11:16:50 -070026#include <linux/fs.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080027#include <linux/input.h>
Doug Zongker7c3ae452013-05-14 11:03:02 -070028#include <stdarg.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080029#include <stdio.h>
30#include <stdlib.h>
31#include <string.h>
Doug Zongker23ceeea2010-07-08 17:27:55 -070032#include <sys/stat.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080033#include <sys/types.h>
Tao Baocdcf28f2016-01-13 15:05:20 -080034#include <sys/wait.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080035#include <unistd.h>
36
Tao Baoc4a18ef2017-02-10 00:13:30 -080037#include <algorithm>
Tao Bao3aec6962018-04-20 09:24:58 -070038#include <functional>
Tao Baoc4a18ef2017-02-10 00:13:30 -080039#include <memory>
Tao Bao862a4c12016-06-02 11:16:50 -070040#include <string>
41#include <vector>
Tao Bao04ca4262015-09-10 15:32:24 -070042
Elliott Hughes4b166f02015-12-04 15:30:20 -080043#include <android-base/file.h>
Tianjie Xu7b0ad9c2016-08-05 18:00:04 -070044#include <android-base/logging.h>
Tianjie Xu3c62b672016-02-05 18:25:58 -080045#include <android-base/parseint.h>
Elliott Hughescb220402016-09-23 15:30:55 -070046#include <android-base/properties.h>
Elliott Hughes4b166f02015-12-04 15:30:20 -080047#include <android-base/stringprintf.h>
Tao Bao862a4c12016-06-02 11:16:50 -070048#include <android-base/strings.h>
49#include <android-base/unique_fd.h>
Yabin Cui8b309f62016-06-24 18:22:02 -070050#include <bootloader_message/bootloader_message.h>
Elliott Hughescb220402016-09-23 15:30:55 -070051#include <cutils/properties.h> /* for property_list */
Elliott Hughes4bbd5bf2016-04-01 18:24:39 -070052#include <healthd/BatteryMonitor.h>
Tianjie Xu8cf5c8f2016-09-08 20:10:11 -070053#include <ziparchive/zip_archive.h>
Yabin Cui99281df2016-02-17 12:21:52 -080054
Tao Bao75238632015-05-27 14:46:17 -070055#include "adb_install.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080056#include "common.h"
Tao Bao75238632015-05-27 14:46:17 -070057#include "device.h"
58#include "fuse_sdcard_provider.h"
59#include "fuse_sideload.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080060#include "install.h"
Jerry Zhang152933a2018-05-02 16:56:00 -070061#include "logging.h"
Tao Bao17054c02018-05-03 22:41:23 -070062#include "otautil/dirutil.h"
Tao Bao1fc5bf32017-10-06 07:43:41 -070063#include "otautil/error_code.h"
Tao Bao641fa972018-04-25 18:59:40 -070064#include "otautil/paths.h"
Tao Bao2c526392018-05-03 23:01:13 -070065#include "otautil/sysutil.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080066#include "roots.h"
Doug Zongker211aebc2011-10-28 15:13:10 -070067#include "screen_ui.h"
Tianjie Xue113e4d2016-10-21 17:46:13 -070068#include "ui.h"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080069
Tao Baoaac9d9f2018-04-29 23:38:59 -070070static constexpr const char* CACHE_LOG_DIR = "/cache/recovery";
71static constexpr const char* COMMAND_FILE = "/cache/recovery/command";
Tao Baoaac9d9f2018-04-29 23:38:59 -070072static constexpr const char* LAST_KMSG_FILE = "/cache/recovery/last_kmsg";
73static constexpr const char* LAST_LOG_FILE = "/cache/recovery/last_log";
74static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale";
Tianjie Xu06e57ac2016-07-11 14:04:08 -070075
Tao Baoaac9d9f2018-04-29 23:38:59 -070076static constexpr const char* CACHE_ROOT = "/cache";
77static constexpr const char* DATA_ROOT = "/data";
78static constexpr const char* METADATA_ROOT = "/metadata";
79static constexpr const char* SDCARD_ROOT = "/sdcard";
Nick Kralevicha9ad0322014-10-22 18:38:48 -070080
Tao Baobd0ddcd2017-05-04 13:03:18 -070081// We define RECOVERY_API_VERSION in Android.mk, which will be picked up by build system and packed
82// into target_files.zip. Assert the version defined in code and in Android.mk are consistent.
83static_assert(kRecoveryApiVersion == RECOVERY_API_VERSION, "Mismatching recovery API versions.");
84
Tao Baoac9d94d2016-11-03 11:37:15 -070085bool modified_flash = false;
Tao Baoa8d72bc2016-12-25 18:46:50 -080086std::string stage;
Tao Baoac9d94d2016-11-03 11:37:15 -070087const char* reason = nullptr;
Tao Baoac9d94d2016-11-03 11:37:15 -070088
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080089/*
90 * The recovery tool communicates with the main system through /cache files.
91 * /cache/recovery/command - INPUT - command line for tool, one arg per line
92 * /cache/recovery/log - OUTPUT - combined log file from recovery run(s)
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080093 *
94 * The arguments which may be supplied in the recovery.command file:
Doug Zongkerd4208f92010-09-20 12:16:13 -070095 * --update_package=path - verify install an OTA package file
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080096 * --wipe_data - erase user data (and cache), then reboot
Tao Baof9f17342018-04-27 10:44:04 -070097 * --prompt_and_wipe_data - prompt the user that data is corrupt, with their consent erase user
98 * data (and cache), then reboot
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080099 * --wipe_cache - wipe cache (but not user data), then reboot
Tao Baof9f17342018-04-27 10:44:04 -0700100 * --show_text - show the recovery text menu, used by some bootloader (e.g. http://b/36872519).
Oscar Montemayor05231562009-11-30 08:40:57 -0800101 * --set_encrypted_filesystem=on|off - enables / diasables encrypted fs
Doug Zongkere5d5ac72012-04-12 11:01:22 -0700102 * --just_exit - do nothing; exit and reboot
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800103 *
104 * After completing, we remove /cache/recovery/command and reboot.
105 * Arguments may also be supplied in the bootloader control block (BCB).
106 * These important scenarios must be safely restartable at any point:
107 *
108 * FACTORY RESET
109 * 1. user selects "factory reset"
110 * 2. main system writes "--wipe_data" to /cache/recovery/command
111 * 3. main system reboots into recovery
112 * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data"
113 * -- after this, rebooting will restart the erase --
Doug Zongkerd4208f92010-09-20 12:16:13 -0700114 * 5. erase_volume() reformats /data
115 * 6. erase_volume() reformats /cache
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800116 * 7. finish_recovery() erases BCB
117 * -- after this, rebooting will restart the main system --
118 * 8. main() calls reboot() to boot main system
119 *
120 * OTA INSTALL
121 * 1. main system downloads OTA package to /cache/some-filename.zip
Doug Zongker9b125b02010-09-22 12:01:37 -0700122 * 2. main system writes "--update_package=/cache/some-filename.zip"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800123 * 3. main system reboots into recovery
124 * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..."
125 * -- after this, rebooting will attempt to reinstall the update --
126 * 5. install_package() attempts to install the update
127 * NOTE: the package install must itself be restartable from any point
128 * 6. finish_recovery() erases BCB
129 * -- after this, rebooting will (try to) restart the main system --
130 * 7. ** if install failed **
131 * 7a. prompt_and_wait() shows an error icon and waits for the user
Tao Baoc0336392016-12-13 22:29:49 -0800132 * 7b. the user reboots (pulling the battery, etc) into the main system
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800133 */
134
Elliott Hughesf14af802015-02-10 14:46:14 -0800135bool is_ro_debuggable() {
Elliott Hughescb220402016-09-23 15:30:55 -0700136 return android::base::GetBoolProperty("ro.debuggable", false);
Elliott Hughesf14af802015-02-10 14:46:14 -0800137}
138
Tao Bao2292db82016-12-13 21:53:31 -0800139// Set the BCB to reboot back into recovery (it won't resume the install from
140// sdcard though).
141static void set_sdcard_update_bootloader_message() {
142 std::vector<std::string> options;
143 std::string err;
144 if (!update_bootloader_message(options, &err)) {
145 LOG(ERROR) << "Failed to set BCB message: " << err;
146 }
Doug Zongker34c98df2009-08-18 12:05:45 -0700147}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800148
Tao Baoec579032017-07-21 12:13:15 -0700149// Clear the recovery command and prepare to boot a (hopefully working) system,
Tianjie Xuc14d95d2016-03-24 11:50:34 -0700150// copy our log file to cache as well (for the system to read). This function is
151// idempotent: call it as many times as you like.
Tao Bao551d2c32018-05-09 20:53:13 -0700152static void finish_recovery() {
153 std::string locale = ui->GetLocale();
Tao Baoec579032017-07-21 12:13:15 -0700154 // Save the locale to cache, so if recovery is next started up without a '--locale' argument
155 // (e.g., directly from the bootloader) it will use the last-known locale.
156 if (!locale.empty() && has_cache) {
157 LOG(INFO) << "Saving locale \"" << locale << "\"";
158 if (ensure_path_mounted(LOCALE_FILE) != 0) {
159 LOG(ERROR) << "Failed to mount " << LOCALE_FILE;
160 } else if (!android::base::WriteStringToFile(locale, LOCALE_FILE)) {
161 PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE;
Doug Zongker4f33e552012-08-23 13:16:12 -0700162 }
Tao Baoec579032017-07-21 12:13:15 -0700163 }
Doug Zongker4f33e552012-08-23 13:16:12 -0700164
Jerry Zhang152933a2018-05-02 16:56:00 -0700165 copy_logs(modified_flash, has_cache);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800166
Tao Baoec579032017-07-21 12:13:15 -0700167 // Reset to normal system boot so recovery won't cycle indefinitely.
168 std::string err;
169 if (!clear_bootloader_message(&err)) {
170 LOG(ERROR) << "Failed to clear BCB message: " << err;
171 }
172
173 // Remove the command file, so recovery won't repeat indefinitely.
174 if (has_cache) {
175 if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) {
176 LOG(WARNING) << "Can't unlink " << COMMAND_FILE;
Yabin Cui8b309f62016-06-24 18:22:02 -0700177 }
Tao Baoec579032017-07-21 12:13:15 -0700178 ensure_path_unmounted(CACHE_ROOT);
179 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800180
Tao Baoec579032017-07-21 12:13:15 -0700181 sync(); // For good measure.
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800182}
183
Tao Bao3f5a3822016-12-13 11:14:37 -0800184struct saved_log_file {
185 std::string name;
186 struct stat sb;
187 std::string data;
188};
Doug Zongker6d0d7ac2013-07-09 13:34:55 -0700189
Elliott Hughes945548e2015-06-05 17:59:56 -0700190static bool erase_volume(const char* volume) {
Tao Bao3f5a3822016-12-13 11:14:37 -0800191 bool is_cache = (strcmp(volume, CACHE_ROOT) == 0);
192 bool is_data = (strcmp(volume, DATA_ROOT) == 0);
Doug Zongker6d0d7ac2013-07-09 13:34:55 -0700193
Tao Bao3f5a3822016-12-13 11:14:37 -0800194 ui->SetBackground(RecoveryUI::ERASING);
195 ui->SetProgressType(RecoveryUI::INDETERMINATE);
Doug Zongker6d0d7ac2013-07-09 13:34:55 -0700196
Tao Bao3f5a3822016-12-13 11:14:37 -0800197 std::vector<saved_log_file> log_files;
Doug Zongker6d0d7ac2013-07-09 13:34:55 -0700198
Tao Bao3f5a3822016-12-13 11:14:37 -0800199 if (is_cache) {
200 // If we're reformatting /cache, we load any past logs
201 // (i.e. "/cache/recovery/last_*") and the current log
202 // ("/cache/recovery/log") into memory, so we can restore them after
203 // the reformat.
Doug Zongker6d0d7ac2013-07-09 13:34:55 -0700204
Tao Bao3f5a3822016-12-13 11:14:37 -0800205 ensure_path_mounted(volume);
Doug Zongker6d0d7ac2013-07-09 13:34:55 -0700206
Tao Bao3f5a3822016-12-13 11:14:37 -0800207 struct dirent* de;
208 std::unique_ptr<DIR, decltype(&closedir)> d(opendir(CACHE_LOG_DIR), closedir);
209 if (d) {
210 while ((de = readdir(d.get())) != nullptr) {
211 if (strncmp(de->d_name, "last_", 5) == 0 || strcmp(de->d_name, "log") == 0) {
212 std::string path = android::base::StringPrintf("%s/%s", CACHE_LOG_DIR, de->d_name);
213
214 struct stat sb;
215 if (stat(path.c_str(), &sb) == 0) {
216 // truncate files to 512kb
217 if (sb.st_size > (1 << 19)) {
218 sb.st_size = 1 << 19;
Doug Zongker6d0d7ac2013-07-09 13:34:55 -0700219 }
Tao Bao3f5a3822016-12-13 11:14:37 -0800220
221 std::string data(sb.st_size, '\0');
Tianjie Xude6735e2017-07-10 15:13:33 -0700222 FILE* f = fopen(path.c_str(), "rbe");
Tao Bao3f5a3822016-12-13 11:14:37 -0800223 fread(&data[0], 1, data.size(), f);
224 fclose(f);
225
226 log_files.emplace_back(saved_log_file{ path, sb, data });
227 }
Doug Zongker6d0d7ac2013-07-09 13:34:55 -0700228 }
Tao Bao3f5a3822016-12-13 11:14:37 -0800229 }
Paul Lawrenced0db3372015-11-05 13:38:40 -0800230 } else {
Tao Bao3f5a3822016-12-13 11:14:37 -0800231 if (errno != ENOENT) {
232 PLOG(ERROR) << "Failed to opendir " << CACHE_LOG_DIR;
233 }
Paul Lawrenced0db3372015-11-05 13:38:40 -0800234 }
Tao Bao3f5a3822016-12-13 11:14:37 -0800235 }
Doug Zongkerd0181b82011-10-19 10:51:12 -0700236
Tao Bao3f5a3822016-12-13 11:14:37 -0800237 ui->Print("Formatting %s...\n", volume);
238
239 ensure_path_unmounted(volume);
240
241 int result;
Tao Bao3f5a3822016-12-13 11:14:37 -0800242 if (is_data && reason && strcmp(reason, "convert_fbe") == 0) {
Tao Bao406a6ff2018-04-30 10:05:57 -0700243 static constexpr const char* CONVERT_FBE_DIR = "/tmp/convert_fbe";
244 static constexpr const char* CONVERT_FBE_FILE = "/tmp/convert_fbe/convert_fbe";
245 // Create convert_fbe breadcrumb file to signal init to convert to file based encryption, not
246 // full disk encryption.
Tao Bao3f5a3822016-12-13 11:14:37 -0800247 if (mkdir(CONVERT_FBE_DIR, 0700) != 0) {
Tao Bao406a6ff2018-04-30 10:05:57 -0700248 PLOG(ERROR) << "Failed to mkdir " << CONVERT_FBE_DIR;
249 return false;
Tao Bao3f5a3822016-12-13 11:14:37 -0800250 }
Tianjie Xude6735e2017-07-10 15:13:33 -0700251 FILE* f = fopen(CONVERT_FBE_FILE, "wbe");
Tao Bao3f5a3822016-12-13 11:14:37 -0800252 if (!f) {
Tao Bao406a6ff2018-04-30 10:05:57 -0700253 PLOG(ERROR) << "Failed to convert to file encryption";
254 return false;
Tao Bao3f5a3822016-12-13 11:14:37 -0800255 }
256 fclose(f);
257 result = format_volume(volume, CONVERT_FBE_DIR);
258 remove(CONVERT_FBE_FILE);
259 rmdir(CONVERT_FBE_DIR);
260 } else {
261 result = format_volume(volume);
262 }
263
264 if (is_cache) {
265 // Re-create the log dir and write back the log entries.
266 if (ensure_path_mounted(CACHE_LOG_DIR) == 0 &&
Tao Baoac3d1ed2017-07-23 00:01:02 -0700267 mkdir_recursively(CACHE_LOG_DIR, 0777, false, sehandle) == 0) {
Tao Bao3f5a3822016-12-13 11:14:37 -0800268 for (const auto& log : log_files) {
269 if (!android::base::WriteStringToFile(log.data, log.name, log.sb.st_mode, log.sb.st_uid,
270 log.sb.st_gid)) {
271 PLOG(ERROR) << "Failed to write to " << log.name;
Doug Zongker6d0d7ac2013-07-09 13:34:55 -0700272 }
Tao Bao3f5a3822016-12-13 11:14:37 -0800273 }
274 } else {
275 PLOG(ERROR) << "Failed to mount / create " << CACHE_LOG_DIR;
Doug Zongker2c3539e2010-09-29 13:21:30 -0700276 }
277
Tao Bao3f5a3822016-12-13 11:14:37 -0800278 // Any part of the log we'd copied to cache is now gone.
279 // Reset the pointer so we copy from the beginning of the temp
280 // log.
Jerry Zhang152933a2018-05-02 16:56:00 -0700281 reset_tmplog_offset();
282 copy_logs(modified_flash, has_cache);
Tao Bao3f5a3822016-12-13 11:14:37 -0800283 }
284
285 return (result == 0);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800286}
287
Tao Baoc4a18ef2017-02-10 00:13:30 -0800288// Returns the selected filename, or an empty string.
289static std::string browse_directory(const std::string& path, Device* device) {
290 ensure_path_mounted(path.c_str());
Doug Zongker8674a722010-09-15 11:08:23 -0700291
Tao Baoc4a18ef2017-02-10 00:13:30 -0800292 std::unique_ptr<DIR, decltype(&closedir)> d(opendir(path.c_str()), closedir);
293 if (!d) {
294 PLOG(ERROR) << "error opening " << path;
295 return "";
296 }
Doug Zongkerc18eeb82010-09-21 16:49:26 -0700297
Tao Baoc4a18ef2017-02-10 00:13:30 -0800298 std::vector<std::string> dirs;
Tao Bao1fe1afe2018-05-01 15:56:05 -0700299 std::vector<std::string> entries{ "../" }; // "../" is always the first entry.
Tao Baoc4a18ef2017-02-10 00:13:30 -0800300
301 dirent* de;
302 while ((de = readdir(d.get())) != nullptr) {
303 std::string name(de->d_name);
304
305 if (de->d_type == DT_DIR) {
306 // Skip "." and ".." entries.
307 if (name == "." || name == "..") continue;
308 dirs.push_back(name + "/");
309 } else if (de->d_type == DT_REG && android::base::EndsWithIgnoreCase(name, ".zip")) {
Tao Bao1fe1afe2018-05-01 15:56:05 -0700310 entries.push_back(name);
Tao Baoc4a18ef2017-02-10 00:13:30 -0800311 }
312 }
313
314 std::sort(dirs.begin(), dirs.end());
Tao Bao1fe1afe2018-05-01 15:56:05 -0700315 std::sort(entries.begin(), entries.end());
Tao Baoc4a18ef2017-02-10 00:13:30 -0800316
Tao Bao1fe1afe2018-05-01 15:56:05 -0700317 // Append dirs to the entries list.
318 entries.insert(entries.end(), dirs.begin(), dirs.end());
Tao Baoc4a18ef2017-02-10 00:13:30 -0800319
Tao Bao1fe1afe2018-05-01 15:56:05 -0700320 std::vector<std::string> headers{ "Choose a package to install:", path };
Tao Baoc4a18ef2017-02-10 00:13:30 -0800321
Tao Bao1fe1afe2018-05-01 15:56:05 -0700322 size_t chosen_item = 0;
Tao Baoc4a18ef2017-02-10 00:13:30 -0800323 while (true) {
Tao Bao3aec6962018-04-20 09:24:58 -0700324 chosen_item = ui->ShowMenu(
325 headers, entries, chosen_item, true,
326 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
Tao Baoc4a18ef2017-02-10 00:13:30 -0800327
Tao Bao1fe1afe2018-05-01 15:56:05 -0700328 const std::string& item = entries[chosen_item];
Tao Baoc4a18ef2017-02-10 00:13:30 -0800329 if (chosen_item == 0) {
330 // Go up but continue browsing (if the caller is browse_directory).
331 return "";
Doug Zongker8674a722010-09-15 11:08:23 -0700332 }
333
Tao Baoc4a18ef2017-02-10 00:13:30 -0800334 std::string new_path = path + "/" + item;
335 if (new_path.back() == '/') {
336 // Recurse down into a subdirectory.
337 new_path.pop_back();
338 std::string result = browse_directory(new_path, device);
339 if (!result.empty()) return result;
340 } else {
341 // Selected a zip file: return the path to the caller.
342 return new_path;
Doug Zongker8674a722010-09-15 11:08:23 -0700343 }
Tao Baoc4a18ef2017-02-10 00:13:30 -0800344 }
Doug Zongker8674a722010-09-15 11:08:23 -0700345
Tao Baoc4a18ef2017-02-10 00:13:30 -0800346 // Unreachable.
Doug Zongker8674a722010-09-15 11:08:23 -0700347}
348
Elliott Hughes30694c92015-03-25 15:16:51 -0700349static bool yes_no(Device* device, const char* question1, const char* question2) {
Tao Bao1fe1afe2018-05-01 15:56:05 -0700350 std::vector<std::string> headers{ question1, question2 };
351 std::vector<std::string> items{ " No", " Yes" };
Doug Zongkerddd6a282009-06-09 12:22:33 -0700352
Tao Bao1fe1afe2018-05-01 15:56:05 -0700353 size_t chosen_item = ui->ShowMenu(
Tao Bao3aec6962018-04-20 09:24:58 -0700354 headers, items, 0, true,
355 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
356 return (chosen_item == 1);
Elliott Hughes30694c92015-03-25 15:16:51 -0700357}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800358
Paul Crowley08404b42016-12-19 13:04:23 -0800359static bool ask_to_wipe_data(Device* device) {
Tao Bao3aec6962018-04-20 09:24:58 -0700360 return yes_no(device, "Wipe all user data?", " THIS CAN NOT BE UNDONE!");
Paul Crowley08404b42016-12-19 13:04:23 -0800361}
Doug Zongker1066d2c2009-04-01 13:57:40 -0700362
Paul Crowley08404b42016-12-19 13:04:23 -0800363// Return true on success.
364static bool wipe_data(Device* device) {
Tao Bao682c34b2015-04-07 17:16:35 -0700365 modified_flash = true;
366
Doug Zongker211aebc2011-10-28 15:13:10 -0700367 ui->Print("\n-- Wiping data...\n");
Paul Crowley3b4d5162016-06-08 13:51:41 -0700368 bool success = device->PreWipeData();
369 if (success) {
370 success &= erase_volume(DATA_ROOT);
371 if (has_cache) {
372 success &= erase_volume(CACHE_ROOT);
373 }
374 if (volume_for_mount_point(METADATA_ROOT) != nullptr) {
375 success &= erase_volume(METADATA_ROOT);
376 }
377 }
378 if (success) {
379 success &= device->PostWipeData();
380 }
Elliott Hughes945548e2015-06-05 17:59:56 -0700381 ui->Print("Data wipe %s.\n", success ? "complete" : "failed");
382 return success;
Doug Zongkerf93d8162009-09-22 15:16:02 -0700383}
384
Paul Crowley08404b42016-12-19 13:04:23 -0800385static bool prompt_and_wipe_data(Device* device) {
Tao Bao2bbc6d62017-08-13 23:48:55 -0700386 // Use a single string and let ScreenRecoveryUI handles the wrapping.
Tao Bao1fe1afe2018-05-01 15:56:05 -0700387 std::vector<std::string> headers{
Tao Bao2bbc6d62017-08-13 23:48:55 -0700388 "Can't load Android system. Your data may be corrupt. "
389 "If you continue to get this message, you may need to "
390 "perform a factory data reset and erase all user data "
Paul Crowley31ac0c62017-03-23 12:32:40 -0700391 "stored on this device.",
Tao Baofc5499f2017-02-23 19:06:53 -0800392 };
Tao Bao1fe1afe2018-05-01 15:56:05 -0700393 // clang-format off
394 std::vector<std::string> items {
Paul Crowley31ac0c62017-03-23 12:32:40 -0700395 "Try again",
396 "Factory data reset",
Tao Baofc5499f2017-02-23 19:06:53 -0800397 };
Tao Bao1fe1afe2018-05-01 15:56:05 -0700398 // clang-format on
Tao Baofc5499f2017-02-23 19:06:53 -0800399 for (;;) {
Tao Bao1fe1afe2018-05-01 15:56:05 -0700400 size_t chosen_item = ui->ShowMenu(
Tao Bao3aec6962018-04-20 09:24:58 -0700401 headers, items, 0, true,
402 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
Tao Baofc5499f2017-02-23 19:06:53 -0800403 if (chosen_item != 1) {
404 return true; // Just reboot, no wipe; not a failure, user asked for it
Paul Crowley08404b42016-12-19 13:04:23 -0800405 }
Tao Baofc5499f2017-02-23 19:06:53 -0800406 if (ask_to_wipe_data(device)) {
407 return wipe_data(device);
408 }
409 }
Paul Crowley08404b42016-12-19 13:04:23 -0800410}
411
Tao Baoe39a9bc2015-03-31 12:19:05 -0700412// Return true on success.
413static bool wipe_cache(bool should_confirm, Device* device) {
Tao Bao26112e52016-02-25 12:29:40 -0800414 if (!has_cache) {
415 ui->Print("No /cache partition found.\n");
416 return false;
417 }
418
Elliott Hughes30694c92015-03-25 15:16:51 -0700419 if (should_confirm && !yes_no(device, "Wipe cache?", " THIS CAN NOT BE UNDONE!")) {
Tao Baoe39a9bc2015-03-31 12:19:05 -0700420 return false;
Elliott Hughes30694c92015-03-25 15:16:51 -0700421 }
422
Tao Bao682c34b2015-04-07 17:16:35 -0700423 modified_flash = true;
424
Elliott Hughes30694c92015-03-25 15:16:51 -0700425 ui->Print("\n-- Wiping cache...\n");
Elliott Hughes945548e2015-06-05 17:59:56 -0700426 bool success = erase_volume("/cache");
427 ui->Print("Cache wipe %s.\n", success ? "complete" : "failed");
428 return success;
Elliott Hughes30694c92015-03-25 15:16:51 -0700429}
430
Tao Bao1b2a98b2017-03-24 10:45:34 -0700431// Secure-wipe a given partition. It uses BLKSECDISCARD, if supported. Otherwise, it goes with
432// BLKDISCARD (if device supports BLKDISCARDZEROES) or BLKZEROOUT.
Tao Bao862a4c12016-06-02 11:16:50 -0700433static bool secure_wipe_partition(const std::string& partition) {
Tao Bao1b2a98b2017-03-24 10:45:34 -0700434 android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(partition.c_str(), O_WRONLY)));
435 if (fd == -1) {
436 PLOG(ERROR) << "Failed to open \"" << partition << "\"";
437 return false;
438 }
439
440 uint64_t range[2] = { 0, 0 };
441 if (ioctl(fd, BLKGETSIZE64, &range[1]) == -1 || range[1] == 0) {
442 PLOG(ERROR) << "Failed to get partition size";
443 return false;
444 }
445 LOG(INFO) << "Secure-wiping \"" << partition << "\" from " << range[0] << " to " << range[1];
446
447 LOG(INFO) << " Trying BLKSECDISCARD...";
448 if (ioctl(fd, BLKSECDISCARD, &range) == -1) {
449 PLOG(WARNING) << " Failed";
450
451 // Use BLKDISCARD if it zeroes out blocks, otherwise use BLKZEROOUT.
452 unsigned int zeroes;
453 if (ioctl(fd, BLKDISCARDZEROES, &zeroes) == 0 && zeroes != 0) {
454 LOG(INFO) << " Trying BLKDISCARD...";
455 if (ioctl(fd, BLKDISCARD, &range) == -1) {
456 PLOG(ERROR) << " Failed";
Tao Bao862a4c12016-06-02 11:16:50 -0700457 return false;
Tao Bao1b2a98b2017-03-24 10:45:34 -0700458 }
459 } else {
460 LOG(INFO) << " Trying BLKZEROOUT...";
461 if (ioctl(fd, BLKZEROOUT, &range) == -1) {
462 PLOG(ERROR) << " Failed";
Tao Bao862a4c12016-06-02 11:16:50 -0700463 return false;
Tao Bao1b2a98b2017-03-24 10:45:34 -0700464 }
Tao Bao862a4c12016-06-02 11:16:50 -0700465 }
Tao Bao1b2a98b2017-03-24 10:45:34 -0700466 }
Tao Bao862a4c12016-06-02 11:16:50 -0700467
Tao Bao1b2a98b2017-03-24 10:45:34 -0700468 LOG(INFO) << " Done";
469 return true;
Tao Bao862a4c12016-06-02 11:16:50 -0700470}
471
Yabin Cuifd99a312016-06-09 14:09:39 -0700472// Check if the wipe package matches expectation:
473// 1. verify the package.
474// 2. check metadata (ota-type, pre-device and serial number if having one).
475static bool check_wipe_package(size_t wipe_package_size) {
476 if (wipe_package_size == 0) {
477 LOG(ERROR) << "wipe_package_size is zero";
478 return false;
479 }
480 std::string wipe_package;
481 std::string err_str;
482 if (!read_wipe_package(&wipe_package, wipe_package_size, &err_str)) {
483 PLOG(ERROR) << "Failed to read wipe package";
484 return false;
485 }
486 if (!verify_package(reinterpret_cast<const unsigned char*>(wipe_package.data()),
487 wipe_package.size())) {
488 LOG(ERROR) << "Failed to verify package";
489 return false;
490 }
491
492 // Extract metadata
493 ZipArchiveHandle zip;
Tao Baoefc35592017-01-08 22:45:47 -0800494 int err = OpenArchiveFromMemory(static_cast<void*>(&wipe_package[0]), wipe_package.size(),
495 "wipe_package", &zip);
Yabin Cuifd99a312016-06-09 14:09:39 -0700496 if (err != 0) {
497 LOG(ERROR) << "Can't open wipe package : " << ErrorCodeString(err);
498 return false;
499 }
500 std::string metadata;
Tao Bao1b2a98b2017-03-24 10:45:34 -0700501 if (!read_metadata_from_package(zip, &metadata)) {
Yabin Cuifd99a312016-06-09 14:09:39 -0700502 CloseArchive(zip);
503 return false;
504 }
505 CloseArchive(zip);
506
507 // Check metadata
508 std::vector<std::string> lines = android::base::Split(metadata, "\n");
509 bool ota_type_matched = false;
510 bool device_type_matched = false;
511 bool has_serial_number = false;
512 bool serial_number_matched = false;
513 for (const auto& line : lines) {
514 if (line == "ota-type=BRICK") {
515 ota_type_matched = true;
516 } else if (android::base::StartsWith(line, "pre-device=")) {
517 std::string device_type = line.substr(strlen("pre-device="));
Tao Baoefc35592017-01-08 22:45:47 -0800518 std::string real_device_type = android::base::GetProperty("ro.build.product", "");
Yabin Cuifd99a312016-06-09 14:09:39 -0700519 device_type_matched = (device_type == real_device_type);
520 } else if (android::base::StartsWith(line, "serialno=")) {
521 std::string serial_no = line.substr(strlen("serialno="));
Tao Baoefc35592017-01-08 22:45:47 -0800522 std::string real_serial_no = android::base::GetProperty("ro.serialno", "");
Yabin Cuifd99a312016-06-09 14:09:39 -0700523 has_serial_number = true;
524 serial_number_matched = (serial_no == real_serial_no);
525 }
526 }
527 return ota_type_matched && device_type_matched && (!has_serial_number || serial_number_matched);
528}
529
Tao Baoaac9d9f2018-04-29 23:38:59 -0700530// Wipes the current A/B device, with a secure wipe of all the partitions in RECOVERY_WIPE.
Yabin Cuifd99a312016-06-09 14:09:39 -0700531static bool wipe_ab_device(size_t wipe_package_size) {
Tao Baoaac9d9f2018-04-29 23:38:59 -0700532 ui->SetBackground(RecoveryUI::ERASING);
533 ui->SetProgressType(RecoveryUI::INDETERMINATE);
Tao Bao862a4c12016-06-02 11:16:50 -0700534
Tao Baoaac9d9f2018-04-29 23:38:59 -0700535 if (!check_wipe_package(wipe_package_size)) {
536 LOG(ERROR) << "Failed to verify wipe package";
537 return false;
538 }
539 static constexpr const char* RECOVERY_WIPE = "/etc/recovery.wipe";
540 std::string partition_list;
541 if (!android::base::ReadFileToString(RECOVERY_WIPE, &partition_list)) {
542 LOG(ERROR) << "failed to read \"" << RECOVERY_WIPE << "\"";
543 return false;
544 }
545
546 std::vector<std::string> lines = android::base::Split(partition_list, "\n");
547 for (const std::string& line : lines) {
548 std::string partition = android::base::Trim(line);
549 // Ignore '#' comment or empty lines.
550 if (android::base::StartsWith(partition, "#") || partition.empty()) {
551 continue;
Tao Bao862a4c12016-06-02 11:16:50 -0700552 }
553
Tao Baoaac9d9f2018-04-29 23:38:59 -0700554 // Proceed anyway even if it fails to wipe some partition.
555 secure_wipe_partition(partition);
556 }
557 return true;
Tao Bao862a4c12016-06-02 11:16:50 -0700558}
559
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700560static void choose_recovery_file(Device* device) {
Tao Bao08fc6be2017-03-07 00:56:27 -0800561 std::vector<std::string> entries;
562 if (has_cache) {
563 for (int i = 0; i < KEEP_LOG_COUNT; i++) {
564 auto add_to_entries = [&](const char* filename) {
565 std::string log_file(filename);
566 if (i > 0) {
567 log_file += "." + std::to_string(i);
Tao Baobef39712015-05-04 18:50:27 -0700568 }
Tao Bao08fc6be2017-03-07 00:56:27 -0800569
570 if (ensure_path_mounted(log_file.c_str()) == 0 && access(log_file.c_str(), R_OK) == 0) {
571 entries.push_back(std::move(log_file));
572 }
573 };
574
575 // Add LAST_LOG_FILE + LAST_LOG_FILE.x
576 add_to_entries(LAST_LOG_FILE);
577
578 // Add LAST_KMSG_FILE + LAST_KMSG_FILE.x
579 add_to_entries(LAST_KMSG_FILE);
580 }
581 } else {
582 // If cache partition is not found, view /tmp/recovery.log instead.
Tao Bao641fa972018-04-25 18:59:40 -0700583 if (access(Paths::Get().temporary_log_file().c_str(), R_OK) == -1) {
Tao Bao08fc6be2017-03-07 00:56:27 -0800584 return;
Tianjie Xua54f75e2016-08-17 12:02:46 -0700585 } else {
Tao Bao641fa972018-04-25 18:59:40 -0700586 entries.push_back(Paths::Get().temporary_log_file());
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700587 }
Tao Bao08fc6be2017-03-07 00:56:27 -0800588 }
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700589
Tao Bao08fc6be2017-03-07 00:56:27 -0800590 entries.push_back("Back");
Elliott Hughesc0491632015-05-06 12:40:05 -0700591
Tao Bao1fe1afe2018-05-01 15:56:05 -0700592 std::vector<std::string> headers{ "Select file to view" };
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700593
Tao Bao1fe1afe2018-05-01 15:56:05 -0700594 size_t chosen_item = 0;
Tao Bao08fc6be2017-03-07 00:56:27 -0800595 while (true) {
Tao Bao3aec6962018-04-20 09:24:58 -0700596 chosen_item = ui->ShowMenu(
Tao Bao1fe1afe2018-05-01 15:56:05 -0700597 headers, entries, chosen_item, true,
Tao Bao3aec6962018-04-20 09:24:58 -0700598 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
Tao Bao08fc6be2017-03-07 00:56:27 -0800599 if (entries[chosen_item] == "Back") break;
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700600
Tao Bao1d156b92018-05-02 12:43:18 -0700601 ui->ShowFile(entries[chosen_item]);
Tao Bao08fc6be2017-03-07 00:56:27 -0800602 }
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700603}
604
Tao Baodb7e8982017-03-06 23:53:16 -0800605static void run_graphics_test() {
606 // Switch to graphics screen.
607 ui->ShowText(false);
Elliott Hughes498cda62016-04-14 16:49:04 -0700608
Tao Baodb7e8982017-03-06 23:53:16 -0800609 ui->SetProgressType(RecoveryUI::INDETERMINATE);
610 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
611 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700612
Tao Baodb7e8982017-03-06 23:53:16 -0800613 ui->SetBackground(RecoveryUI::ERROR);
614 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700615
Tao Baodb7e8982017-03-06 23:53:16 -0800616 ui->SetBackground(RecoveryUI::NO_COMMAND);
617 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700618
Tao Baodb7e8982017-03-06 23:53:16 -0800619 ui->SetBackground(RecoveryUI::ERASING);
620 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700621
Tao Baodb7e8982017-03-06 23:53:16 -0800622 // Calling SetBackground() after SetStage() to trigger a redraw.
623 ui->SetStage(1, 3);
624 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
625 sleep(1);
626 ui->SetStage(2, 3);
627 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
628 sleep(1);
629 ui->SetStage(3, 3);
630 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
631 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700632
Tao Baodb7e8982017-03-06 23:53:16 -0800633 ui->SetStage(-1, -1);
634 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
Elliott Hughes498cda62016-04-14 16:49:04 -0700635
Tao Baodb7e8982017-03-06 23:53:16 -0800636 ui->SetProgressType(RecoveryUI::DETERMINATE);
637 ui->ShowProgress(1.0, 10.0);
638 float fraction = 0.0;
639 for (size_t i = 0; i < 100; ++i) {
640 fraction += .01;
641 ui->SetProgress(fraction);
642 usleep(100000);
643 }
644
645 ui->ShowText(true);
Elliott Hughes498cda62016-04-14 16:49:04 -0700646}
647
Tao Baocdcf28f2016-01-13 15:05:20 -0800648// How long (in seconds) we wait for the fuse-provided package file to
649// appear, before timing out.
650#define SDCARD_INSTALL_TIMEOUT 10
651
Tao Bao145d8612015-03-25 15:51:15 -0700652static int apply_from_sdcard(Device* device, bool* wipe_cache) {
Tao Bao682c34b2015-04-07 17:16:35 -0700653 modified_flash = true;
654
Christian Poetzsch4ec58a42015-02-19 10:42:39 +0000655 if (ensure_path_mounted(SDCARD_ROOT) != 0) {
656 ui->Print("\n-- Couldn't mount %s.\n", SDCARD_ROOT);
657 return INSTALL_ERROR;
658 }
659
Tao Baoc4a18ef2017-02-10 00:13:30 -0800660 std::string path = browse_directory(SDCARD_ROOT, device);
661 if (path.empty()) {
Elliott Hughes018ed312015-04-08 16:51:36 -0700662 ui->Print("\n-- No package file selected.\n");
caozhiyuanb4effb92015-06-10 16:46:38 +0800663 ensure_path_unmounted(SDCARD_ROOT);
Christian Poetzsch4ec58a42015-02-19 10:42:39 +0000664 return INSTALL_ERROR;
665 }
666
Tao Baoc4a18ef2017-02-10 00:13:30 -0800667 ui->Print("\n-- Install %s ...\n", path.c_str());
Christian Poetzsch4ec58a42015-02-19 10:42:39 +0000668 set_sdcard_update_bootloader_message();
Christian Poetzsch4ec58a42015-02-19 10:42:39 +0000669
Tao Baocdcf28f2016-01-13 15:05:20 -0800670 // We used to use fuse in a thread as opposed to a process. Since accessing
671 // through fuse involves going from kernel to userspace to kernel, it leads
672 // to deadlock when a page fault occurs. (Bug: 26313124)
673 pid_t child;
674 if ((child = fork()) == 0) {
Tao Baoc4a18ef2017-02-10 00:13:30 -0800675 bool status = start_sdcard_fuse(path.c_str());
Tao Baocdcf28f2016-01-13 15:05:20 -0800676
677 _exit(status ? EXIT_SUCCESS : EXIT_FAILURE);
678 }
679
680 // FUSE_SIDELOAD_HOST_PATHNAME will start to exist once the fuse in child
681 // process is ready.
682 int result = INSTALL_ERROR;
683 int status;
684 bool waited = false;
685 for (int i = 0; i < SDCARD_INSTALL_TIMEOUT; ++i) {
686 if (waitpid(child, &status, WNOHANG) == -1) {
687 result = INSTALL_ERROR;
688 waited = true;
689 break;
690 }
691
692 struct stat sb;
693 if (stat(FUSE_SIDELOAD_HOST_PATHNAME, &sb) == -1) {
694 if (errno == ENOENT && i < SDCARD_INSTALL_TIMEOUT-1) {
695 sleep(1);
696 continue;
697 } else {
Tianjie Xu7b0ad9c2016-08-05 18:00:04 -0700698 LOG(ERROR) << "Timed out waiting for the fuse-provided package.";
Tao Baocdcf28f2016-01-13 15:05:20 -0800699 result = INSTALL_ERROR;
700 kill(child, SIGKILL);
701 break;
702 }
703 }
704
Tao Bao641fa972018-04-25 18:59:40 -0700705 result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, false, 0 /*retry_count*/);
Tao Baocdcf28f2016-01-13 15:05:20 -0800706 break;
707 }
Christian Poetzsch4ec58a42015-02-19 10:42:39 +0000708
Tao Baocdcf28f2016-01-13 15:05:20 -0800709 if (!waited) {
710 // Calling stat() on this magic filename signals the fuse
711 // filesystem to shut down.
712 struct stat sb;
713 stat(FUSE_SIDELOAD_HOST_EXIT_PATHNAME, &sb);
714
715 waitpid(child, &status, 0);
716 }
717
718 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
Tianjie Xu7b0ad9c2016-08-05 18:00:04 -0700719 LOG(ERROR) << "Error exit from the fuse process: " << WEXITSTATUS(status);
Tao Baocdcf28f2016-01-13 15:05:20 -0800720 }
721
Christian Poetzsch4ec58a42015-02-19 10:42:39 +0000722 ensure_path_unmounted(SDCARD_ROOT);
Tao Baocdcf28f2016-01-13 15:05:20 -0800723 return result;
Christian Poetzsch4ec58a42015-02-19 10:42:39 +0000724}
725
Tao Bao50dd5322017-03-07 14:57:04 -0800726// Returns REBOOT, SHUTDOWN, or REBOOT_BOOTLOADER. Returning NO_ACTION means to take the default,
727// which is to reboot or shutdown depending on if the --shutdown_after flag was passed to recovery.
728static Device::BuiltinAction prompt_and_wait(Device* device, int status) {
729 for (;;) {
Tao Bao551d2c32018-05-09 20:53:13 -0700730 finish_recovery();
Tao Bao50dd5322017-03-07 14:57:04 -0800731 switch (status) {
732 case INSTALL_SUCCESS:
733 case INSTALL_NONE:
734 ui->SetBackground(RecoveryUI::NO_COMMAND);
735 break;
Doug Zongker6c8553d2012-09-24 10:40:47 -0700736
Tao Bao50dd5322017-03-07 14:57:04 -0800737 case INSTALL_ERROR:
738 case INSTALL_CORRUPT:
739 ui->SetBackground(RecoveryUI::ERROR);
740 break;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800741 }
Tao Bao50dd5322017-03-07 14:57:04 -0800742 ui->SetProgressType(RecoveryUI::EMPTY);
743
Tao Bao1fe1afe2018-05-01 15:56:05 -0700744 size_t chosen_item = ui->ShowMenu(
745 {}, device->GetMenuItems(), 0, false,
Tao Bao3aec6962018-04-20 09:24:58 -0700746 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
Tao Bao50dd5322017-03-07 14:57:04 -0800747
748 // Device-specific code may take some action here. It may return one of the core actions
749 // handled in the switch statement below.
Tao Bao1fe1afe2018-05-01 15:56:05 -0700750 Device::BuiltinAction chosen_action = (chosen_item == static_cast<size_t>(-1))
751 ? Device::REBOOT
752 : device->InvokeMenuItem(chosen_item);
Tao Bao50dd5322017-03-07 14:57:04 -0800753
754 bool should_wipe_cache = false;
755 switch (chosen_action) {
756 case Device::NO_ACTION:
757 break;
758
759 case Device::REBOOT:
760 case Device::SHUTDOWN:
761 case Device::REBOOT_BOOTLOADER:
762 return chosen_action;
763
764 case Device::WIPE_DATA:
765 if (ui->IsTextVisible()) {
766 if (ask_to_wipe_data(device)) {
767 wipe_data(device);
768 }
769 } else {
770 wipe_data(device);
771 return Device::NO_ACTION;
772 }
773 break;
774
775 case Device::WIPE_CACHE:
776 wipe_cache(ui->IsTextVisible(), device);
777 if (!ui->IsTextVisible()) return Device::NO_ACTION;
778 break;
779
780 case Device::APPLY_ADB_SIDELOAD:
781 case Device::APPLY_SDCARD:
782 {
783 bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD);
784 if (adb) {
Tao Bao641fa972018-04-25 18:59:40 -0700785 status = apply_from_adb(&should_wipe_cache);
Tao Bao50dd5322017-03-07 14:57:04 -0800786 } else {
787 status = apply_from_sdcard(device, &should_wipe_cache);
788 }
789
790 if (status == INSTALL_SUCCESS && should_wipe_cache) {
791 if (!wipe_cache(false, device)) {
792 status = INSTALL_ERROR;
793 }
794 }
795
796 if (status != INSTALL_SUCCESS) {
797 ui->SetBackground(RecoveryUI::ERROR);
798 ui->Print("Installation aborted.\n");
Jerry Zhang152933a2018-05-02 16:56:00 -0700799 copy_logs(modified_flash, has_cache);
Tao Bao50dd5322017-03-07 14:57:04 -0800800 } else if (!ui->IsTextVisible()) {
801 return Device::NO_ACTION; // reboot if logs aren't visible
802 } else {
803 ui->Print("\nInstall from %s complete.\n", adb ? "ADB" : "SD card");
804 }
805 }
806 break;
807
808 case Device::VIEW_RECOVERY_LOGS:
809 choose_recovery_file(device);
810 break;
811
812 case Device::RUN_GRAPHICS_TEST:
813 run_graphics_test();
814 break;
815
Tianjie Xu29d55752017-09-20 17:53:46 -0700816 case Device::RUN_LOCALE_TEST: {
817 ScreenRecoveryUI* screen_ui = static_cast<ScreenRecoveryUI*>(ui);
Tao Bao39c49182018-05-07 22:50:33 -0700818 screen_ui->CheckBackgroundTextImages();
Tianjie Xu29d55752017-09-20 17:53:46 -0700819 break;
820 }
Tao Bao50dd5322017-03-07 14:57:04 -0800821 case Device::MOUNT_SYSTEM:
822 // For a system image built with the root directory (i.e. system_root_image == "true"), we
823 // mount it to /system_root, and symlink /system to /system_root/system to make adb shell
824 // work (the symlink is created through the build system). (Bug: 22855115)
825 if (android::base::GetBoolProperty("ro.build.system_root_image", false)) {
826 if (ensure_path_mounted_at("/", "/system_root") != -1) {
827 ui->Print("Mounted /system.\n");
828 }
829 } else {
830 if (ensure_path_mounted("/system") != -1) {
831 ui->Print("Mounted /system.\n");
832 }
833 }
834 break;
835 }
836 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800837}
838
Tao Bao99f0d9e2016-10-13 12:46:38 -0700839static void print_property(const char* key, const char* name, void* /* cookie */) {
840 printf("%s=%s\n", key, name);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800841}
842
Tao Baoac9d94d2016-11-03 11:37:15 -0700843void ui_print(const char* format, ...) {
844 std::string buffer;
Doug Zongker7c3ae452013-05-14 11:03:02 -0700845 va_list ap;
846 va_start(ap, format);
Tao Baoac9d94d2016-11-03 11:37:15 -0700847 android::base::StringAppendV(&buffer, format, ap);
Doug Zongker7c3ae452013-05-14 11:03:02 -0700848 va_end(ap);
849
Tao Baoac9d94d2016-11-03 11:37:15 -0700850 if (ui != nullptr) {
851 ui->Print("%s", buffer.c_str());
Doug Zongker7c3ae452013-05-14 11:03:02 -0700852 } else {
Tao Baoac9d94d2016-11-03 11:37:15 -0700853 fputs(buffer.c_str(), stdout);
Doug Zongker7c3ae452013-05-14 11:03:02 -0700854 }
855}
856
Tao Baof2ea6d72018-04-26 10:40:36 -0700857static bool is_battery_ok(int* required_battery_level) {
858 struct healthd_config healthd_config = {
859 .batteryStatusPath = android::String8(android::String8::kEmptyString),
860 .batteryHealthPath = android::String8(android::String8::kEmptyString),
861 .batteryPresentPath = android::String8(android::String8::kEmptyString),
862 .batteryCapacityPath = android::String8(android::String8::kEmptyString),
863 .batteryVoltagePath = android::String8(android::String8::kEmptyString),
864 .batteryTemperaturePath = android::String8(android::String8::kEmptyString),
865 .batteryTechnologyPath = android::String8(android::String8::kEmptyString),
866 .batteryCurrentNowPath = android::String8(android::String8::kEmptyString),
867 .batteryCurrentAvgPath = android::String8(android::String8::kEmptyString),
868 .batteryChargeCounterPath = android::String8(android::String8::kEmptyString),
869 .batteryFullChargePath = android::String8(android::String8::kEmptyString),
870 .batteryCycleCountPath = android::String8(android::String8::kEmptyString),
871 .energyCounter = nullptr,
872 .boot_min_cap = 0,
873 .screen_on = nullptr
874 };
875 healthd_board_init(&healthd_config);
Yabin Cui99281df2016-02-17 12:21:52 -0800876
Tao Baof2ea6d72018-04-26 10:40:36 -0700877 android::BatteryMonitor monitor;
878 monitor.init(&healthd_config);
Yabin Cui99281df2016-02-17 12:21:52 -0800879
Tao Baof2ea6d72018-04-26 10:40:36 -0700880 static constexpr int BATTERY_READ_TIMEOUT_IN_SEC = 10;
881 int wait_second = 0;
882 while (true) {
883 int charge_status = monitor.getChargeStatus();
884 // Treat unknown status as charged.
885 bool charged = (charge_status != android::BATTERY_STATUS_DISCHARGING &&
886 charge_status != android::BATTERY_STATUS_NOT_CHARGING);
887 android::BatteryProperty capacity;
888 android::status_t status = monitor.getProperty(android::BATTERY_PROP_CAPACITY, &capacity);
889 ui_print("charge_status %d, charged %d, status %d, capacity %" PRId64 "\n", charge_status,
890 charged, status, capacity.valueInt64);
891 // At startup, the battery drivers in devices like N5X/N6P take some time to load
892 // the battery profile. Before the load finishes, it reports value 50 as a fake
893 // capacity. BATTERY_READ_TIMEOUT_IN_SEC is set that the battery drivers are expected
894 // to finish loading the battery profile earlier than 10 seconds after kernel startup.
895 if (status == 0 && capacity.valueInt64 == 50) {
896 if (wait_second < BATTERY_READ_TIMEOUT_IN_SEC) {
897 sleep(1);
898 wait_second++;
899 continue;
900 }
Yabin Cui99281df2016-02-17 12:21:52 -0800901 }
Tao Baof2ea6d72018-04-26 10:40:36 -0700902 // If we can't read battery percentage, it may be a device without battery. In this situation,
903 // use 100 as a fake battery percentage.
904 if (status != 0) {
905 capacity.valueInt64 = 100;
906 }
907
908 // GmsCore enters recovery mode to install package when having enough battery percentage.
909 // Normally, the threshold is 40% without charger and 20% with charger. So we should check
910 // battery with a slightly lower limitation.
911 static constexpr int BATTERY_OK_PERCENTAGE = 20;
912 static constexpr int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15;
913 *required_battery_level = charged ? BATTERY_WITH_CHARGER_OK_PERCENTAGE : BATTERY_OK_PERCENTAGE;
914 return capacity.valueInt64 >= *required_battery_level;
915 }
Yabin Cui99281df2016-02-17 12:21:52 -0800916}
917
Tianjie Xu99b73be2017-11-28 17:23:06 -0800918// Set the retry count to |retry_count| in BCB.
Tianjie Xu72449c92017-05-16 18:07:31 -0700919static void set_retry_bootloader_message(int retry_count, const std::vector<std::string>& args) {
920 std::vector<std::string> options;
921 for (const auto& arg : args) {
922 if (!android::base::StartsWith(arg, "--retry_count")) {
923 options.push_back(arg);
Tianjie Xu3c62b672016-02-05 18:25:58 -0800924 }
Tianjie Xu72449c92017-05-16 18:07:31 -0700925 }
Tianjie Xu3c62b672016-02-05 18:25:58 -0800926
Tianjie Xu99b73be2017-11-28 17:23:06 -0800927 // Update the retry counter in BCB.
928 options.push_back(android::base::StringPrintf("--retry_count=%d", retry_count));
Tianjie Xu72449c92017-05-16 18:07:31 -0700929 std::string err;
930 if (!update_bootloader_message(options, &err)) {
931 LOG(ERROR) << err;
932 }
Tianjie Xu3c62b672016-02-05 18:25:58 -0800933}
934
Tianjie Xu06e57ac2016-07-11 14:04:08 -0700935static bool bootreason_in_blacklist() {
Tao Baoefc35592017-01-08 22:45:47 -0800936 std::string bootreason = android::base::GetProperty("ro.boot.bootreason", "");
937 if (!bootreason.empty()) {
Tao Baoaac9d9f2018-04-29 23:38:59 -0700938 // More bootreasons can be found in "system/core/bootstat/bootstat.cpp".
939 static const std::vector<std::string> kBootreasonBlacklist{
940 "kernel_panic",
941 "Panic",
942 };
943 for (const auto& str : kBootreasonBlacklist) {
944 if (android::base::EqualsIgnoreCase(str, bootreason)) return true;
Tianjie Xu06e57ac2016-07-11 14:04:08 -0700945 }
Tao Baoefc35592017-01-08 22:45:47 -0800946 }
947 return false;
Tianjie Xu06e57ac2016-07-11 14:04:08 -0700948}
949
Tao Bao641fa972018-04-25 18:59:40 -0700950static void log_failure_code(ErrorCode code, const std::string& update_package) {
951 std::vector<std::string> log_buffer = {
952 update_package,
953 "0", // install result
954 "error: " + std::to_string(code),
955 };
956 std::string log_content = android::base::Join(log_buffer, "\n");
957 const std::string& install_file = Paths::Get().temporary_install_file();
958 if (!android::base::WriteStringToFile(log_content, install_file)) {
959 PLOG(ERROR) << "Failed to write " << install_file;
960 }
Tianjie Xu06e57ac2016-07-11 14:04:08 -0700961
Tao Bao641fa972018-04-25 18:59:40 -0700962 // Also write the info into last_log.
963 LOG(INFO) << log_content;
Tianjie Xu06e57ac2016-07-11 14:04:08 -0700964}
965
Jerry Zhangf5e319a2018-05-04 11:24:10 -0700966Device::BuiltinAction start_recovery(Device* device, const std::vector<std::string>& args) {
Tianjie Xu99b73be2017-11-28 17:23:06 -0800967 std::vector<char*> args_to_parse(args.size());
968 std::transform(args.cbegin(), args.cend(), args_to_parse.begin(),
969 [](const std::string& arg) { return const_cast<char*>(arg.c_str()); });
970
Tao Baof9f17342018-04-27 10:44:04 -0700971 static constexpr struct option OPTIONS[] = {
972 { "just_exit", no_argument, nullptr, 'x' },
973 { "locale", required_argument, nullptr, 0 },
974 { "prompt_and_wipe_data", no_argument, nullptr, 0 },
975 { "reason", required_argument, nullptr, 0 },
976 { "retry_count", required_argument, nullptr, 0 },
977 { "security", no_argument, nullptr, 0 },
978 { "show_text", no_argument, nullptr, 't' },
979 { "shutdown_after", no_argument, nullptr, 0 },
980 { "sideload", no_argument, nullptr, 0 },
981 { "sideload_auto_reboot", no_argument, nullptr, 0 },
982 { "update_package", required_argument, nullptr, 0 },
983 { "wipe_ab", no_argument, nullptr, 0 },
984 { "wipe_cache", no_argument, nullptr, 0 },
985 { "wipe_data", no_argument, nullptr, 0 },
986 { "wipe_package_size", required_argument, nullptr, 0 },
987 { nullptr, 0, nullptr, 0 },
988 };
989
Tianjie Xu99b73be2017-11-28 17:23:06 -0800990 const char* update_package = nullptr;
991 bool should_wipe_data = false;
992 bool should_prompt_and_wipe_data = false;
993 bool should_wipe_cache = false;
994 bool should_wipe_ab = false;
995 size_t wipe_package_size = 0;
Tianjie Xu99b73be2017-11-28 17:23:06 -0800996 bool sideload = false;
997 bool sideload_auto_reboot = false;
998 bool just_exit = false;
999 bool shutdown_after = false;
1000 int retry_count = 0;
1001 bool security_update = false;
Jerry Zhang2dea53e2018-05-02 17:15:03 -07001002 std::string locale;
Tianjie Xu99b73be2017-11-28 17:23:06 -08001003
1004 int arg;
1005 int option_index;
1006 while ((arg = getopt_long(args_to_parse.size(), args_to_parse.data(), "", OPTIONS,
1007 &option_index)) != -1) {
1008 switch (arg) {
Tianjie Xu99b73be2017-11-28 17:23:06 -08001009 case 't':
Jerry Zhangf5e319a2018-05-04 11:24:10 -07001010 // Handled in recovery_main.cpp
Tianjie Xu99b73be2017-11-28 17:23:06 -08001011 break;
Tianjie Xu99b73be2017-11-28 17:23:06 -08001012 case 'x':
1013 just_exit = true;
1014 break;
Tianjie Xu99b73be2017-11-28 17:23:06 -08001015 case 0: {
1016 std::string option = OPTIONS[option_index].name;
Tao Baof9f17342018-04-27 10:44:04 -07001017 if (option == "locale") {
Jerry Zhangf5e319a2018-05-04 11:24:10 -07001018 // Handled in recovery_main.cpp
Tianjie Xu99b73be2017-11-28 17:23:06 -08001019 } else if (option == "prompt_and_wipe_data") {
1020 should_prompt_and_wipe_data = true;
Tao Baof9f17342018-04-27 10:44:04 -07001021 } else if (option == "reason") {
1022 reason = optarg;
1023 } else if (option == "retry_count") {
1024 android::base::ParseInt(optarg, &retry_count, 0);
1025 } else if (option == "security") {
1026 security_update = true;
1027 } else if (option == "sideload") {
1028 sideload = true;
1029 } else if (option == "sideload_auto_reboot") {
1030 sideload = true;
1031 sideload_auto_reboot = true;
1032 } else if (option == "shutdown_after") {
1033 shutdown_after = true;
1034 } else if (option == "update_package") {
1035 update_package = optarg;
1036 } else if (option == "wipe_ab") {
1037 should_wipe_ab = true;
1038 } else if (option == "wipe_cache") {
1039 should_wipe_cache = true;
1040 } else if (option == "wipe_data") {
1041 should_wipe_data = true;
1042 } else if (option == "wipe_package_size") {
1043 android::base::ParseUint(optarg, &wipe_package_size);
Tianjie Xu99b73be2017-11-28 17:23:06 -08001044 }
1045 break;
1046 }
1047 case '?':
1048 LOG(ERROR) << "Invalid command argument";
1049 continue;
Doug Zongker9270a202012-01-09 15:16:13 -08001050 }
Tianjie Xu99b73be2017-11-28 17:23:06 -08001051 }
Jerry Zhang49fd5d22018-05-17 12:54:41 -07001052 optind = 1;
Doug Zongker9270a202012-01-09 15:16:13 -08001053
Tianjie Xu99b73be2017-11-28 17:23:06 -08001054 printf("stage is [%s]\n", stage.c_str());
1055 printf("reason is [%s]\n", reason);
Doug Zongker02ec6b82012-08-22 17:26:40 -07001056
Tianjie Xu99b73be2017-11-28 17:23:06 -08001057 // Set background string to "installing security update" for security update,
1058 // otherwise set it to "installing system update".
1059 ui->SetSystemUpdateText(security_update);
1060
1061 int st_cur, st_max;
1062 if (!stage.empty() && sscanf(stage.c_str(), "%d/%d", &st_cur, &st_max) == 2) {
1063 ui->SetStage(st_cur, st_max);
1064 }
1065
Tianjie Xu99b73be2017-11-28 17:23:06 -08001066 device->StartRecovery();
1067
1068 printf("Command:");
1069 for (const auto& arg : args) {
1070 printf(" \"%s\"", arg.c_str());
1071 }
1072 printf("\n\n");
1073
1074 property_list(print_property, nullptr);
1075 printf("\n");
1076
1077 ui->Print("Supported API: %d\n", kRecoveryApiVersion);
1078
1079 int status = INSTALL_SUCCESS;
1080
1081 if (update_package != nullptr) {
1082 // It's not entirely true that we will modify the flash. But we want
1083 // to log the update attempt since update_package is non-NULL.
1084 modified_flash = true;
1085
Tao Baof2ea6d72018-04-26 10:40:36 -07001086 int required_battery_level;
1087 if (retry_count == 0 && !is_battery_ok(&required_battery_level)) {
1088 ui->Print("battery capacity is not enough for installing package: %d%% needed\n",
1089 required_battery_level);
Tianjie Xu99b73be2017-11-28 17:23:06 -08001090 // Log the error code to last_install when installation skips due to
1091 // low battery.
1092 log_failure_code(kLowBattery, update_package);
1093 status = INSTALL_SKIPPED;
Tianjie Xua6f49bd2018-03-26 14:32:11 -07001094 } else if (retry_count == 0 && bootreason_in_blacklist()) {
Tianjie Xu99b73be2017-11-28 17:23:06 -08001095 // Skip update-on-reboot when bootreason is kernel_panic or similar
1096 ui->Print("bootreason is in the blacklist; skip OTA installation\n");
1097 log_failure_code(kBootreasonInBlacklist, update_package);
1098 status = INSTALL_SKIPPED;
Dmitri Plotnikov8706a982017-04-18 08:28:26 -07001099 } else {
Tianjie Xu99b73be2017-11-28 17:23:06 -08001100 // It's a fresh update. Initialize the retry_count in the BCB to 1; therefore we can later
1101 // identify the interrupted update due to unexpected reboots.
1102 if (retry_count == 0) {
1103 set_retry_bootloader_message(retry_count + 1, args);
Tao Bao7022f332017-07-25 09:52:36 -07001104 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001105
Tao Bao641fa972018-04-25 18:59:40 -07001106 status = install_package(update_package, &should_wipe_cache, true, retry_count);
Tianjie Xu99b73be2017-11-28 17:23:06 -08001107 if (status == INSTALL_SUCCESS && should_wipe_cache) {
1108 wipe_cache(false, device);
1109 }
1110 if (status != INSTALL_SUCCESS) {
1111 ui->Print("Installation aborted.\n");
Tao Baoaac9d9f2018-04-29 23:38:59 -07001112
1113 // When I/O error or bspatch/imgpatch error happens, reboot and retry installation
1114 // RETRY_LIMIT times before we abandon this OTA update.
1115 static constexpr int RETRY_LIMIT = 4;
Tianjie Xu99b73be2017-11-28 17:23:06 -08001116 if (status == INSTALL_RETRY && retry_count < RETRY_LIMIT) {
Jerry Zhang152933a2018-05-02 16:56:00 -07001117 copy_logs(modified_flash, has_cache);
Tianjie Xu99b73be2017-11-28 17:23:06 -08001118 retry_count += 1;
1119 set_retry_bootloader_message(retry_count, args);
1120 // Print retry count on screen.
1121 ui->Print("Retry attempt %d\n", retry_count);
1122
1123 // Reboot and retry the update
1124 if (!reboot("reboot,recovery")) {
1125 ui->Print("Reboot failed\n");
1126 } else {
1127 while (true) {
1128 pause();
1129 }
1130 }
Tianjie Xud9d16292017-04-20 18:08:21 -07001131 }
Tianjie Xu99b73be2017-11-28 17:23:06 -08001132 // If this is an eng or userdebug build, then automatically
1133 // turn the text display on if the script fails so the error
1134 // message is visible.
1135 if (is_ro_debuggable()) {
1136 ui->ShowText(true);
Tao Baoc679f932015-03-30 09:43:49 -07001137 }
Tianjie Xu99b73be2017-11-28 17:23:06 -08001138 }
Doug Zongker8674a722010-09-15 11:08:23 -07001139 }
Tianjie Xu99b73be2017-11-28 17:23:06 -08001140 } else if (should_wipe_data) {
1141 if (!wipe_data(device)) {
1142 status = INSTALL_ERROR;
Doug Zongkerb1d12632014-03-18 10:32:12 -07001143 }
Tianjie Xu99b73be2017-11-28 17:23:06 -08001144 } else if (should_prompt_and_wipe_data) {
1145 ui->ShowText(true);
1146 ui->SetBackground(RecoveryUI::ERROR);
1147 if (!prompt_and_wipe_data(device)) {
1148 status = INSTALL_ERROR;
Tao Bao75238632015-05-27 14:46:17 -07001149 }
Tianjie Xu99b73be2017-11-28 17:23:06 -08001150 ui->ShowText(false);
1151 } else if (should_wipe_cache) {
1152 if (!wipe_cache(false, device)) {
1153 status = INSTALL_ERROR;
1154 }
1155 } else if (should_wipe_ab) {
1156 if (!wipe_ab_device(wipe_package_size)) {
1157 status = INSTALL_ERROR;
1158 }
1159 } else if (sideload) {
1160 // 'adb reboot sideload' acts the same as user presses key combinations
1161 // to enter the sideload mode. When 'sideload-auto-reboot' is used, text
1162 // display will NOT be turned on by default. And it will reboot after
1163 // sideload finishes even if there are errors. Unless one turns on the
1164 // text display during the installation. This is to enable automated
1165 // testing.
1166 if (!sideload_auto_reboot) {
1167 ui->ShowText(true);
1168 }
Tao Bao641fa972018-04-25 18:59:40 -07001169 status = apply_from_adb(&should_wipe_cache);
Tianjie Xu99b73be2017-11-28 17:23:06 -08001170 if (status == INSTALL_SUCCESS && should_wipe_cache) {
1171 if (!wipe_cache(false, device)) {
1172 status = INSTALL_ERROR;
1173 }
1174 }
1175 ui->Print("\nInstall from ADB complete (status: %d).\n", status);
1176 if (sideload_auto_reboot) {
1177 ui->Print("Rebooting automatically.\n");
1178 }
1179 } else if (!just_exit) {
1180 // If this is an eng or userdebug build, automatically turn on the text display if no command
1181 // is specified. Note that this should be called before setting the background to avoid
1182 // flickering the background image.
1183 if (is_ro_debuggable()) {
1184 ui->ShowText(true);
1185 }
1186 status = INSTALL_NONE; // No command specified
1187 ui->SetBackground(RecoveryUI::NO_COMMAND);
1188 }
1189
1190 if (status == INSTALL_ERROR || status == INSTALL_CORRUPT) {
1191 ui->SetBackground(RecoveryUI::ERROR);
1192 if (!ui->IsTextVisible()) {
1193 sleep(5);
1194 }
1195 }
1196
1197 Device::BuiltinAction after = shutdown_after ? Device::SHUTDOWN : Device::REBOOT;
1198 // 1. If the recovery menu is visible, prompt and wait for commands.
1199 // 2. If the state is INSTALL_NONE, wait for commands. (i.e. In user build, manually reboot into
1200 // recovery to sideload a package.)
1201 // 3. sideload_auto_reboot is an option only available in user-debug build, reboot the device
1202 // without waiting.
1203 // 4. In all other cases, reboot the device. Therefore, normal users will observe the device
1204 // reboot after it shows the "error" screen for 5s.
1205 if ((status == INSTALL_NONE && !sideload_auto_reboot) || ui->IsTextVisible()) {
1206 Device::BuiltinAction temp = prompt_and_wait(device, status);
1207 if (temp != Device::NO_ACTION) {
1208 after = temp;
1209 }
1210 }
1211
1212 // Save logs and clean up before rebooting or shutting down.
Tao Bao551d2c32018-05-09 20:53:13 -07001213 finish_recovery();
Tianjie Xu99b73be2017-11-28 17:23:06 -08001214
Jerry Zhangf5e319a2018-05-04 11:24:10 -07001215 return after;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001216}