blob: 8703bf191a35da801f04b9eee35cf4c642d2a341 [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 Zhang6a648042018-05-04 11:24:10 -070017#include "recovery.h"
Tao Bao2ac56af2018-04-25 16:47:04 -070018
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080019#include <ctype.h>
20#include <errno.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080021#include <getopt.h>
Tao Bao862a4c12016-06-02 11:16:50 -070022#include <inttypes.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080023#include <limits.h>
24#include <linux/input.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
Michael Bestasb357f8e2021-01-16 18:16:47 +020028#include <sys/mount.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080029#include <sys/types.h>
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080030#include <unistd.h>
31
Tao Bao3aec6962018-04-20 09:24:58 -070032#include <functional>
Tao Bao7f19d102019-04-26 22:56:56 -070033#include <iterator>
Tao Baoc4a18ef2017-02-10 00:13:30 -080034#include <memory>
Richard Hansen833c0242020-05-12 18:08:56 -040035#include <regex>
Tao Bao862a4c12016-06-02 11:16:50 -070036#include <string>
37#include <vector>
Tao Bao04ca4262015-09-10 15:32:24 -070038
Elliott Hughes4b166f02015-12-04 15:30:20 -080039#include <android-base/file.h>
Tianjie Xu7b0ad9c2016-08-05 18:00:04 -070040#include <android-base/logging.h>
Tianjie Xu3c62b672016-02-05 18:25:58 -080041#include <android-base/parseint.h>
Elliott Hughescb220402016-09-23 15:30:55 -070042#include <android-base/properties.h>
Elliott Hughes4b166f02015-12-04 15:30:20 -080043#include <android-base/stringprintf.h>
Tao Bao862a4c12016-06-02 11:16:50 -070044#include <android-base/strings.h>
Anay Wadhera1ddbbb42021-01-29 12:03:39 -080045#include <android/hardware/boot/1.0/IBootControl.h>
Elliott Hughescb220402016-09-23 15:30:55 -070046#include <cutils/properties.h> /* for property_list */
Tao Baof90d9a12019-05-10 10:40:59 -070047#include <fs_mgr/roots.h>
Tom Marshall3e101752019-01-04 14:37:31 -080048#include <volume_manager/VolumeManager.h>
Tianjie Xu8cf5c8f2016-09-08 20:10:11 -070049#include <ziparchive/zip_archive.h>
Yabin Cui99281df2016-02-17 12:21:52 -080050
Tao Bao7f19d102019-04-26 22:56:56 -070051#include "bootloader_message/bootloader_message.h"
xunchang24788852019-03-22 16:08:52 -070052#include "install/adb_install.h"
Tianjie Xuf6158eb2019-06-11 16:09:07 -070053#include "install/fuse_install.h"
xunchang24788852019-03-22 16:08:52 -070054#include "install/install.h"
Alessio Balsinia9665ce2019-12-09 09:26:05 +000055#include "install/snapshot_utils.h"
xunchang316e9712019-04-12 16:22:15 -070056#include "install/wipe_data.h"
Tao Bao7f19d102019-04-26 22:56:56 -070057#include "install/wipe_device.h"
Tianjie Xub63a2212019-07-29 14:21:49 -070058#include "otautil/boot_state.h"
Tao Bao1fc5bf32017-10-06 07:43:41 -070059#include "otautil/error_code.h"
Jacky Liu068329e2021-12-21 00:32:50 +080060#include "otautil/package.h"
Tao Bao641fa972018-04-25 18:59:40 -070061#include "otautil/paths.h"
Tao Bao2c526392018-05-03 23:01:13 -070062#include "otautil/sysutil.h"
Tianjie Xu8f397302018-08-20 13:40:47 -070063#include "recovery_ui/screen_ui.h"
64#include "recovery_ui/ui.h"
Tao Bao832c9cd2019-09-27 23:32:00 -070065#include "recovery_utils/battery_utils.h"
Tao Baoe3f09a72019-10-01 11:55:36 -070066#include "recovery_utils/logging.h"
67#include "recovery_utils/roots.h"
Tom Marshall3e101752019-01-04 14:37:31 -080068#include "volclient.h"
69
70using android::volmgr::VolumeManager;
71using android::volmgr::VolumeInfo;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080072
Anay Wadhera1ddbbb42021-01-29 12:03:39 -080073using android::sp;
Anay Wadhera32954ce2021-01-25 12:46:05 -080074using android::fs_mgr::Fstab;
Anay Wadhera1ddbbb42021-01-29 12:03:39 -080075using android::hardware::boot::V1_0::IBootControl;
76using android::hardware::boot::V1_0::CommandResult;
77using android::hardware::boot::V1_0::Slot;
Anay Wadhera32954ce2021-01-25 12:46:05 -080078
Tao Baoaac9d9f2018-04-29 23:38:59 -070079static constexpr const char* COMMAND_FILE = "/cache/recovery/command";
Tao Baoaac9d9f2018-04-29 23:38:59 -070080static constexpr const char* LAST_KMSG_FILE = "/cache/recovery/last_kmsg";
81static constexpr const char* LAST_LOG_FILE = "/cache/recovery/last_log";
82static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale";
Tianjie Xu06e57ac2016-07-11 14:04:08 -070083
Tao Baoaac9d9f2018-04-29 23:38:59 -070084static constexpr const char* CACHE_ROOT = "/cache";
Nick Kralevicha9ad0322014-10-22 18:38:48 -070085
xunchang316e9712019-04-12 16:22:15 -070086static bool save_current_log = false;
Tao Baoac9d94d2016-11-03 11:37:15 -070087
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080088/*
89 * The recovery tool communicates with the main system through /cache files.
90 * /cache/recovery/command - INPUT - command line for tool, one arg per line
91 * /cache/recovery/log - OUTPUT - combined log file from recovery run(s)
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080092 *
93 * The arguments which may be supplied in the recovery.command file:
Doug Zongkerd4208f92010-09-20 12:16:13 -070094 * --update_package=path - verify install an OTA package file
Tianjie Xue5218612019-06-25 13:59:39 -070095 * --install_with_fuse - install the update package with FUSE. This allows installation of large
96 * packages on LP32 builds. Since the mmap will otherwise fail due to out of memory.
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -080097 * --wipe_data - erase user data (and cache), then reboot
Tao Baof9f17342018-04-27 10:44:04 -070098 * --prompt_and_wipe_data - prompt the user that data is corrupt, with their consent erase user
99 * data (and cache), then reboot
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800100 * --wipe_cache - wipe cache (but not user data), then reboot
Tao Baof9f17342018-04-27 10:44:04 -0700101 * --show_text - show the recovery text menu, used by some bootloader (e.g. http://b/36872519).
Oscar Montemayor05231562009-11-30 08:40:57 -0800102 * --set_encrypted_filesystem=on|off - enables / diasables encrypted fs
Doug Zongkere5d5ac72012-04-12 11:01:22 -0700103 * --just_exit - do nothing; exit and reboot
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800104 *
105 * After completing, we remove /cache/recovery/command and reboot.
106 * Arguments may also be supplied in the bootloader control block (BCB).
107 * These important scenarios must be safely restartable at any point:
108 *
109 * FACTORY RESET
110 * 1. user selects "factory reset"
111 * 2. main system writes "--wipe_data" to /cache/recovery/command
112 * 3. main system reboots into recovery
113 * 4. get_args() writes BCB with "boot-recovery" and "--wipe_data"
114 * -- after this, rebooting will restart the erase --
Doug Zongkerd4208f92010-09-20 12:16:13 -0700115 * 5. erase_volume() reformats /data
116 * 6. erase_volume() reformats /cache
Tianjie Xu164c60a2019-05-15 13:59:39 -0700117 * 7. FinishRecovery() erases BCB
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800118 * -- after this, rebooting will restart the main system --
119 * 8. main() calls reboot() to boot main system
120 *
121 * OTA INSTALL
122 * 1. main system downloads OTA package to /cache/some-filename.zip
Doug Zongker9b125b02010-09-22 12:01:37 -0700123 * 2. main system writes "--update_package=/cache/some-filename.zip"
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800124 * 3. main system reboots into recovery
125 * 4. get_args() writes BCB with "boot-recovery" and "--update_package=..."
126 * -- after this, rebooting will attempt to reinstall the update --
Tao Baoadc99ef2019-04-29 23:48:02 -0700127 * 5. InstallPackage() attempts to install the update
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800128 * NOTE: the package install must itself be restartable from any point
Tianjie Xu164c60a2019-05-15 13:59:39 -0700129 * 6. FinishRecovery() erases BCB
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800130 * -- after this, rebooting will (try to) restart the main system --
131 * 7. ** if install failed **
Tao Baoadc99ef2019-04-29 23:48:02 -0700132 * 7a. PromptAndWait() shows an error icon and waits for the user
Tao Baoc0336392016-12-13 22:29:49 -0800133 * 7b. the user reboots (pulling the battery, etc) into the main system
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800134 */
135
Tianjie Xu164c60a2019-05-15 13:59:39 -0700136static bool IsRoDebuggable() {
137 return android::base::GetBoolProperty("ro.debuggable", false);
Elliott Hughesf14af802015-02-10 14:46:14 -0800138}
139
Tao Baoec579032017-07-21 12:13:15 -0700140// Clear the recovery command and prepare to boot a (hopefully working) system,
Tianjie Xuc14d95d2016-03-24 11:50:34 -0700141// copy our log file to cache as well (for the system to read). This function is
142// idempotent: call it as many times as you like.
Tianjie Xu164c60a2019-05-15 13:59:39 -0700143static void FinishRecovery(RecoveryUI* ui) {
Tao Bao551d2c32018-05-09 20:53:13 -0700144 std::string locale = ui->GetLocale();
Tao Baoec579032017-07-21 12:13:15 -0700145 // Save the locale to cache, so if recovery is next started up without a '--locale' argument
146 // (e.g., directly from the bootloader) it will use the last-known locale.
Tianjie Xu164c60a2019-05-15 13:59:39 -0700147 if (!locale.empty() && HasCache()) {
Tao Baoec579032017-07-21 12:13:15 -0700148 LOG(INFO) << "Saving locale \"" << locale << "\"";
149 if (ensure_path_mounted(LOCALE_FILE) != 0) {
150 LOG(ERROR) << "Failed to mount " << LOCALE_FILE;
151 } else if (!android::base::WriteStringToFile(locale, LOCALE_FILE)) {
152 PLOG(ERROR) << "Failed to save locale to " << LOCALE_FILE;
Doug Zongker4f33e552012-08-23 13:16:12 -0700153 }
Tao Baoec579032017-07-21 12:13:15 -0700154 }
Doug Zongker4f33e552012-08-23 13:16:12 -0700155
Tianjie Xu164c60a2019-05-15 13:59:39 -0700156 copy_logs(save_current_log);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800157
Tao Baoec579032017-07-21 12:13:15 -0700158 // Reset to normal system boot so recovery won't cycle indefinitely.
159 std::string err;
160 if (!clear_bootloader_message(&err)) {
161 LOG(ERROR) << "Failed to clear BCB message: " << err;
162 }
163
164 // Remove the command file, so recovery won't repeat indefinitely.
Tianjie Xu164c60a2019-05-15 13:59:39 -0700165 if (HasCache()) {
Tao Baoec579032017-07-21 12:13:15 -0700166 if (ensure_path_mounted(COMMAND_FILE) != 0 || (unlink(COMMAND_FILE) && errno != ENOENT)) {
167 LOG(WARNING) << "Can't unlink " << COMMAND_FILE;
Yabin Cui8b309f62016-06-24 18:22:02 -0700168 }
Tao Baoec579032017-07-21 12:13:15 -0700169 ensure_path_unmounted(CACHE_ROOT);
170 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800171
Tao Baoec579032017-07-21 12:13:15 -0700172 sync(); // For good measure.
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800173}
174
Elliott Hughes30694c92015-03-25 15:16:51 -0700175static bool yes_no(Device* device, const char* question1, const char* question2) {
Tao Bao1fe1afe2018-05-01 15:56:05 -0700176 std::vector<std::string> headers{ question1, question2 };
177 std::vector<std::string> items{ " No", " Yes" };
Doug Zongkerddd6a282009-06-09 12:22:33 -0700178
Tianjie Xu164c60a2019-05-15 13:59:39 -0700179 size_t chosen_item = device->GetUI()->ShowMenu(
Tao Bao3aec6962018-04-20 09:24:58 -0700180 headers, items, 0, true,
181 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
182 return (chosen_item == 1);
Elliott Hughes30694c92015-03-25 15:16:51 -0700183}
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800184
LuK1337561cd9e2023-07-29 11:16:41 +0200185bool ask_to_ab_reboot(Device* device) {
Mohammad Hasan Keramat Jfc2342e2023-08-30 20:51:57 +0000186 if (get_build_type() == "user") {
187 return false;
188 }
LuK1337561cd9e2023-07-29 11:16:41 +0200189 device->GetUI()->SetProgressType(RecoveryUI::EMPTY);
190 return yes_no(device, "To install additional packages, you need to reboot recovery first",
191 "Do you want to reboot to recovery now?");
192}
193
Tom Marshall7cb5d3e2018-06-21 00:57:24 +0200194bool ask_to_continue_unverified(Device* device) {
Christian Oder1391c802020-09-16 02:06:46 +0200195 device->GetUI()->SetProgressType(RecoveryUI::EMPTY);
196 return yes_no(device, "Signature verification failed", "Install anyway?");
Tom Marshall7cb5d3e2018-06-21 00:57:24 +0200197}
198
Alessandro Astone4d822dd2020-03-17 23:06:52 +0100199bool ask_to_continue_downgrade(Device* device) {
Christian Oder1391c802020-09-16 02:06:46 +0200200 device->GetUI()->SetProgressType(RecoveryUI::EMPTY);
201 return yes_no(device, "This package will downgrade your system", "Install anyway?");
Alessandro Astone4d822dd2020-03-17 23:06:52 +0100202}
203
Anay Wadhera25791a72021-01-01 19:40:11 -0800204std::string get_preferred_fs(Device* device) {
Anay Wadhera32954ce2021-01-25 12:46:05 -0800205 Fstab fstab;
206 auto read_fstab = ReadFstabFromFile("/etc/fstab", &fstab);
Anay Wadhera25791a72021-01-01 19:40:11 -0800207 std::vector<std::string> headers{ "Choose what filesystem you want to use on /data", "Entries here are supported by your device." };
Anay Wadhera25791a72021-01-01 19:40:11 -0800208 std::string fs = volume_for_mount_point("/data")->fs_type;
Anay Wadhera32954ce2021-01-25 12:46:05 -0800209 if (read_fstab) {
210 std::string current_filesystem = android::fs_mgr::GetEntryForPath(&fstab, "/data")->fs_type;
211 headers.emplace_back("Current filesystem: " + current_filesystem);
212 }
213 std::vector<std::string> items = get_data_fs_items();
Anay Wadhera25791a72021-01-01 19:40:11 -0800214
215 if (items.size() > 1) {
216 size_t chosen_item = device->GetUI()->ShowMenu(
217 headers, items, 0, true,
218 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
219 if (chosen_item == Device::kGoBack)
220 return "";
221 fs = items[chosen_item];
222 }
223 return fs;
224}
225
Ethan Yonker521c2c42021-01-03 23:47:09 -0800226std::string get_chosen_slot(Device* device) {
227 std::vector<std::string> headers{ "Choose which slot to boot into on next boot." };
228 std::vector<std::string> items{ "A", "B" };
229 size_t chosen_item = device->GetUI()->ShowMenu(
230 headers, items, 0, true,
231 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
232 if (chosen_item < 0)
233 return "";
234 return items[chosen_item];
235}
236
237int set_slot(Device* device) {
238 std::string slot = get_chosen_slot(device);
Anay Wadhera1ddbbb42021-01-29 12:03:39 -0800239 CommandResult ret;
240 auto cb = [&ret](CommandResult result) { ret = result; };
241 Slot sslot = (slot == "A") ? 0 : 1;
242 sp<IBootControl> module = IBootControl::getService();
243 if (!module) {
Ethan Yonker521c2c42021-01-03 23:47:09 -0800244 device->GetUI()->Print("Error getting bootctrl module.\n");
245 } else {
Anay Wadhera1ddbbb42021-01-29 12:03:39 -0800246 auto result = module->setActiveBootSlot(sslot, cb);
247 if (result.isOk() && ret.success) {
Ethan Yonker521c2c42021-01-03 23:47:09 -0800248 device->GetUI()->Print("Switched slot to %s.\n", slot.c_str());
249 device->GoHome();
Anay Wadhera1ddbbb42021-01-29 12:03:39 -0800250 } else {
251 device->GetUI()->Print("Error changing bootloader boot slot to %s", slot.c_str());
Ethan Yonker521c2c42021-01-03 23:47:09 -0800252 }
253 }
Anay Wadhera1ddbbb42021-01-29 12:03:39 -0800254 return ret.success ? 0 : 1;
Ethan Yonker521c2c42021-01-03 23:47:09 -0800255}
256
Paul Crowley08404b42016-12-19 13:04:23 -0800257static bool ask_to_wipe_data(Device* device) {
Nolen Johnsond3519ab2020-04-12 14:13:31 -0400258 std::vector<std::string> headers{ "Format user data?", "This includes internal storage.", "THIS CANNOT BE UNDONE!" };
259 std::vector<std::string> items{ " Cancel", " Format data" };
Tianjie Xu1a0a30a2018-10-25 15:22:07 -0700260
Alessandro Astonea2cbdef2020-03-09 23:17:50 +0100261 size_t chosen_item = device->GetUI()->ShowMenu(
262 headers, items, 0, true,
Tianjie Xu1a0a30a2018-10-25 15:22:07 -0700263 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
264
265 return (chosen_item == 1);
Paul Crowley08404b42016-12-19 13:04:23 -0800266}
Doug Zongker1066d2c2009-04-01 13:57:40 -0700267
Tom Marshall3e101752019-01-04 14:37:31 -0800268static InstallResult apply_update_menu(Device* device, Device::BuiltinAction* reboot_action){
269 RecoveryUI* ui = device->GetUI();
NurKeinNeidaded1b42022-05-07 11:24:50 +0200270 std::vector<std::string> headers{ "Install update" };
Tom Marshall3e101752019-01-04 14:37:31 -0800271 std::vector<std::string> items;
272
273 const int item_sideload = 0;
274 std::vector<VolumeInfo> volumes;
275
276 InstallResult status = INSTALL_NONE;
277
278 for (;;) {
279 items.clear();
NurKeinNeidaded1b42022-05-07 11:24:50 +0200280 items.push_back("ADB Sideload");
Tom Marshall3e101752019-01-04 14:37:31 -0800281 VolumeManager::Instance()->getVolumeInfo(volumes);
Tom Marshall2b16d592019-07-24 21:12:07 +0200282 for (auto vol = volumes.begin(); vol != volumes.end(); /* empty */) {
283 if (!vol->mMountable) {
284 vol = volumes.erase(vol);
285 continue;
286 }
287 items.push_back("Choose from " + vol->mLabel);
288 ++vol;
Tom Marshall3e101752019-01-04 14:37:31 -0800289 }
290
291 int chosen = ui->ShowMenu(
292 headers, items, 0, false,
293 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2),
294 true /* refreshable */);
295 if (chosen == Device::kRefresh) {
296 continue;
297 }
298 if (chosen == Device::kGoBack) {
299 break;
300 }
301 if (chosen == static_cast<size_t>(RecoveryUI::KeyError::INTERRUPTED)) {
302 return INSTALL_KEY_INTERRUPTED;
303 }
304
305 if (chosen == item_sideload) {
306 status = ApplyFromAdb(device, false /* rescue_mode */, reboot_action);
307 } else {
308 status = ApplyFromStorage(device, volumes[chosen - 1]);
309 }
Alexander Martinzd10d5ef2022-12-20 15:26:42 +0100310 break;
Tom Marshall3e101752019-01-04 14:37:31 -0800311 }
312 return status;
313}
314
Hridya Valsarajueb6f13a2018-09-12 10:25:01 -0700315static InstallResult prompt_and_wipe_data(Device* device) {
Tao Bao2bbc6d62017-08-13 23:48:55 -0700316 // Use a single string and let ScreenRecoveryUI handles the wrapping.
Tianjie Xub99e6062018-10-16 15:13:09 -0700317 std::vector<std::string> wipe_data_menu_headers{
Tao Bao2bbc6d62017-08-13 23:48:55 -0700318 "Can't load Android system. Your data may be corrupt. "
319 "If you continue to get this message, you may need to "
320 "perform a factory data reset and erase all user data "
Paul Crowley31ac0c62017-03-23 12:32:40 -0700321 "stored on this device.",
Tao Baofc5499f2017-02-23 19:06:53 -0800322 };
Tao Bao1fe1afe2018-05-01 15:56:05 -0700323 // clang-format off
Tianjie Xub99e6062018-10-16 15:13:09 -0700324 std::vector<std::string> wipe_data_menu_items {
Paul Crowley31ac0c62017-03-23 12:32:40 -0700325 "Try again",
326 "Factory data reset",
Tao Baofc5499f2017-02-23 19:06:53 -0800327 };
Tao Bao1fe1afe2018-05-01 15:56:05 -0700328 // clang-format on
Tao Baofc5499f2017-02-23 19:06:53 -0800329 for (;;) {
Tianjie Xu164c60a2019-05-15 13:59:39 -0700330 size_t chosen_item = device->GetUI()->ShowPromptWipeDataMenu(
Tianjie Xub99e6062018-10-16 15:13:09 -0700331 wipe_data_menu_headers, wipe_data_menu_items,
Tao Bao3aec6962018-04-20 09:24:58 -0700332 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
Jerry Zhangb76af932018-05-22 12:08:35 -0700333 // If ShowMenu() returned RecoveryUI::KeyError::INTERRUPTED, WaitKey() was interrupted.
334 if (chosen_item == static_cast<size_t>(RecoveryUI::KeyError::INTERRUPTED)) {
Hridya Valsarajueb6f13a2018-09-12 10:25:01 -0700335 return INSTALL_KEY_INTERRUPTED;
Jerry Zhangb76af932018-05-22 12:08:35 -0700336 }
Alessandro Astone8144be82020-12-24 11:58:17 +0100337 if (chosen_item == Device::kGoBack) {
338 return INSTALL_NONE; // Go back, show menu
339 }
340 if (chosen_item == 0) {
Hridya Valsarajueb6f13a2018-09-12 10:25:01 -0700341 return INSTALL_SUCCESS; // Just reboot, no wipe; not a failure, user asked for it
Paul Crowley08404b42016-12-19 13:04:23 -0800342 }
Tianjie Xub99e6062018-10-16 15:13:09 -0700343
Tao Baofc5499f2017-02-23 19:06:53 -0800344 if (ask_to_wipe_data(device)) {
Tianjie Xub63a2212019-07-29 14:21:49 -0700345 CHECK(device->GetReason().has_value());
Eric Biggersfde69fb2022-03-10 22:13:39 +0000346 if (WipeData(device)) {
Hridya Valsarajueb6f13a2018-09-12 10:25:01 -0700347 return INSTALL_SUCCESS;
348 } else {
349 return INSTALL_ERROR;
350 }
Tao Baofc5499f2017-02-23 19:06:53 -0800351 }
352 }
Paul Crowley08404b42016-12-19 13:04:23 -0800353}
354
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700355static void choose_recovery_file(Device* device) {
Tao Bao08fc6be2017-03-07 00:56:27 -0800356 std::vector<std::string> entries;
Tianjie Xu164c60a2019-05-15 13:59:39 -0700357 if (HasCache()) {
Tao Bao08fc6be2017-03-07 00:56:27 -0800358 for (int i = 0; i < KEEP_LOG_COUNT; i++) {
359 auto add_to_entries = [&](const char* filename) {
360 std::string log_file(filename);
361 if (i > 0) {
362 log_file += "." + std::to_string(i);
Tao Baobef39712015-05-04 18:50:27 -0700363 }
Tao Bao08fc6be2017-03-07 00:56:27 -0800364
Yifan Hongd81b8e32018-12-17 14:29:06 -0800365 if (ensure_path_mounted(log_file) == 0 && access(log_file.c_str(), R_OK) == 0) {
Tao Bao08fc6be2017-03-07 00:56:27 -0800366 entries.push_back(std::move(log_file));
367 }
368 };
369
370 // Add LAST_LOG_FILE + LAST_LOG_FILE.x
371 add_to_entries(LAST_LOG_FILE);
372
373 // Add LAST_KMSG_FILE + LAST_KMSG_FILE.x
374 add_to_entries(LAST_KMSG_FILE);
375 }
376 } else {
377 // If cache partition is not found, view /tmp/recovery.log instead.
Tao Bao641fa972018-04-25 18:59:40 -0700378 if (access(Paths::Get().temporary_log_file().c_str(), R_OK) == -1) {
Tao Bao08fc6be2017-03-07 00:56:27 -0800379 return;
Tianjie Xua54f75e2016-08-17 12:02:46 -0700380 } else {
Tao Bao641fa972018-04-25 18:59:40 -0700381 entries.push_back(Paths::Get().temporary_log_file());
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700382 }
Tao Bao08fc6be2017-03-07 00:56:27 -0800383 }
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700384
Tao Bao08fc6be2017-03-07 00:56:27 -0800385 entries.push_back("Back");
Elliott Hughesc0491632015-05-06 12:40:05 -0700386
Tao Bao1fe1afe2018-05-01 15:56:05 -0700387 std::vector<std::string> headers{ "Select file to view" };
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700388
Tao Bao1fe1afe2018-05-01 15:56:05 -0700389 size_t chosen_item = 0;
Tao Bao08fc6be2017-03-07 00:56:27 -0800390 while (true) {
Tianjie Xu164c60a2019-05-15 13:59:39 -0700391 chosen_item = device->GetUI()->ShowMenu(
Tao Bao1fe1afe2018-05-01 15:56:05 -0700392 headers, entries, chosen_item, true,
Tao Bao3aec6962018-04-20 09:24:58 -0700393 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
Jerry Zhangb76af932018-05-22 12:08:35 -0700394
395 // Handle WaitKey() interrupt.
396 if (chosen_item == static_cast<size_t>(RecoveryUI::KeyError::INTERRUPTED)) {
397 break;
398 }
Tom Marshalleb7a0812017-08-24 13:50:01 +0000399 if (chosen_item == Device::kGoHome || chosen_item == Device::kGoBack ||
400 chosen_item == entries.size() - 1) {
401 break;
402 }
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700403
Tianjie Xu164c60a2019-05-15 13:59:39 -0700404 device->GetUI()->ShowFile(entries[chosen_item]);
Tao Bao08fc6be2017-03-07 00:56:27 -0800405 }
Nick Kralevicha9ad0322014-10-22 18:38:48 -0700406}
407
Tianjie Xu164c60a2019-05-15 13:59:39 -0700408static void run_graphics_test(RecoveryUI* ui) {
Tao Baodb7e8982017-03-06 23:53:16 -0800409 // Switch to graphics screen.
410 ui->ShowText(false);
Elliott Hughes498cda62016-04-14 16:49:04 -0700411
Tao Baodb7e8982017-03-06 23:53:16 -0800412 ui->SetProgressType(RecoveryUI::INDETERMINATE);
413 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
414 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700415
Tao Baodb7e8982017-03-06 23:53:16 -0800416 ui->SetBackground(RecoveryUI::ERROR);
417 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700418
Tao Baodb7e8982017-03-06 23:53:16 -0800419 ui->SetBackground(RecoveryUI::NO_COMMAND);
420 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700421
Tao Baodb7e8982017-03-06 23:53:16 -0800422 ui->SetBackground(RecoveryUI::ERASING);
423 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700424
Tao Baodb7e8982017-03-06 23:53:16 -0800425 // Calling SetBackground() after SetStage() to trigger a redraw.
426 ui->SetStage(1, 3);
427 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
428 sleep(1);
429 ui->SetStage(2, 3);
430 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
431 sleep(1);
432 ui->SetStage(3, 3);
433 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
434 sleep(1);
Elliott Hughes498cda62016-04-14 16:49:04 -0700435
Tao Baodb7e8982017-03-06 23:53:16 -0800436 ui->SetStage(-1, -1);
437 ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
Elliott Hughes498cda62016-04-14 16:49:04 -0700438
Tao Baodb7e8982017-03-06 23:53:16 -0800439 ui->SetProgressType(RecoveryUI::DETERMINATE);
440 ui->ShowProgress(1.0, 10.0);
441 float fraction = 0.0;
442 for (size_t i = 0; i < 100; ++i) {
443 fraction += .01;
444 ui->SetProgress(fraction);
445 usleep(100000);
446 }
447
448 ui->ShowText(true);
Elliott Hughes498cda62016-04-14 16:49:04 -0700449}
450
Yifan Hong13b09962020-01-29 16:51:33 -0800451static void WriteUpdateInProgress() {
452 std::string err;
453 if (!update_bootloader_message({ "--reason=update_in_progress" }, &err)) {
454 LOG(ERROR) << "Failed to WriteUpdateInProgress: " << err;
Yifan Hongc9163fd2020-01-27 17:37:39 -0800455 }
Yifan Hong13b09962020-01-29 16:51:33 -0800456}
Yifan Hongc9163fd2020-01-27 17:37:39 -0800457
Yifan Hong13b09962020-01-29 16:51:33 -0800458static bool AskToReboot(Device* device, Device::BuiltinAction chosen_action) {
Yifan Hongc9163fd2020-01-27 17:37:39 -0800459 bool is_non_ab = android::base::GetProperty("ro.boot.slot_suffix", "").empty();
460 bool is_virtual_ab = android::base::GetBoolProperty("ro.virtual_ab.enabled", false);
461 if (!is_non_ab && !is_virtual_ab) {
462 // Only prompt for non-A/B or Virtual A/B devices.
463 return true;
464 }
465
466 std::string header_text;
467 std::string item_text;
468 switch (chosen_action) {
469 case Device::REBOOT:
470 header_text = "reboot";
NurKeinNeidaded1b42022-05-07 11:24:50 +0200471 item_text = " Reboot to system";
Yifan Hongc9163fd2020-01-27 17:37:39 -0800472 break;
473 case Device::SHUTDOWN:
474 header_text = "power off";
475 item_text = " Power off";
476 break;
477 default:
478 LOG(FATAL) << "Invalid chosen action " << chosen_action;
479 break;
480 }
481
Yifan Hong13b09962020-01-29 16:51:33 -0800482 std::vector<std::string> headers{ "WARNING: Previous installation has failed.",
Yifan Hongc9163fd2020-01-27 17:37:39 -0800483 " Your device may fail to boot if you " + header_text +
484 " now.",
485 " Confirm reboot?" };
486 std::vector<std::string> items{ " Cancel", item_text };
487
488 size_t chosen_item = device->GetUI()->ShowMenu(
489 headers, items, 0, true /* menu_only */,
490 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
491
492 return (chosen_item == 1);
493}
494
Tao Baoadc99ef2019-04-29 23:48:02 -0700495// Shows the recovery UI and waits for user input. Returns one of the device builtin actions, such
496// as REBOOT, SHUTDOWN, or REBOOT_BOOTLOADER. Returning NO_ACTION means to take the default, which
497// is to reboot or shutdown depending on if the --shutdown_after flag was passed to recovery.
498static Device::BuiltinAction PromptAndWait(Device* device, InstallResult status) {
Tianjie Xu164c60a2019-05-15 13:59:39 -0700499 auto ui = device->GetUI();
Yifan Hong13b09962020-01-29 16:51:33 -0800500 bool update_in_progress = (device->GetReason().value_or("") == "update_in_progress");
Tao Bao50dd5322017-03-07 14:57:04 -0800501 for (;;) {
Tianjie Xu164c60a2019-05-15 13:59:39 -0700502 FinishRecovery(ui);
Tao Bao50dd5322017-03-07 14:57:04 -0800503 switch (status) {
504 case INSTALL_SUCCESS:
505 case INSTALL_NONE:
Tao Baoadc99ef2019-04-29 23:48:02 -0700506 case INSTALL_SKIPPED:
507 case INSTALL_RETRY:
508 case INSTALL_KEY_INTERRUPTED:
Tao Bao50dd5322017-03-07 14:57:04 -0800509 ui->SetBackground(RecoveryUI::NO_COMMAND);
510 break;
Doug Zongker6c8553d2012-09-24 10:40:47 -0700511
Tao Bao50dd5322017-03-07 14:57:04 -0800512 case INSTALL_ERROR:
513 case INSTALL_CORRUPT:
514 ui->SetBackground(RecoveryUI::ERROR);
515 break;
Tao Baoadc99ef2019-04-29 23:48:02 -0700516
517 case INSTALL_REBOOT:
518 // All the reboots should have been handled prior to entering PromptAndWait() or immediately
519 // after installing a package.
520 LOG(FATAL) << "Invalid status code of INSTALL_REBOOT";
521 break;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800522 }
Tao Bao50dd5322017-03-07 14:57:04 -0800523 ui->SetProgressType(RecoveryUI::EMPTY);
524
Tom Marshallcb791fa2020-03-29 14:36:57 +0200525change_menu:
Tao Bao1fe1afe2018-05-01 15:56:05 -0700526 size_t chosen_item = ui->ShowMenu(
Tom Marshallcb791fa2020-03-29 14:36:57 +0200527 device->GetMenuHeaders(), device->GetMenuItems(), 0, false,
Tao Bao3aec6962018-04-20 09:24:58 -0700528 std::bind(&Device::HandleMenuKey, device, std::placeholders::_1, std::placeholders::_2));
Jerry Zhangb76af932018-05-22 12:08:35 -0700529 // Handle Interrupt key
530 if (chosen_item == static_cast<size_t>(RecoveryUI::KeyError::INTERRUPTED)) {
531 return Device::KEY_INTERRUPTED;
532 }
Tom Marshallcb791fa2020-03-29 14:36:57 +0200533
Tom Marshalleb7a0812017-08-24 13:50:01 +0000534 if (chosen_item == Device::kGoBack || chosen_item == Device::kGoHome) {
Tom Marshallcb791fa2020-03-29 14:36:57 +0200535 device->GoHome();
536 goto change_menu;
Tom Marshalleb7a0812017-08-24 13:50:01 +0000537 }
538
Tao Bao50dd5322017-03-07 14:57:04 -0800539 // Device-specific code may take some action here. It may return one of the core actions
540 // handled in the switch statement below.
Jerry Zhangb76af932018-05-22 12:08:35 -0700541 Device::BuiltinAction chosen_action =
542 (chosen_item == static_cast<size_t>(RecoveryUI::KeyError::TIMED_OUT))
543 ? Device::REBOOT
544 : device->InvokeMenuItem(chosen_item);
Tao Bao50dd5322017-03-07 14:57:04 -0800545
Tao Bao50dd5322017-03-07 14:57:04 -0800546 switch (chosen_action) {
Tom Marshallcb791fa2020-03-29 14:36:57 +0200547 case Device::MENU_BASE:
Tom Marshallcb791fa2020-03-29 14:36:57 +0200548 case Device::MENU_WIPE:
549 case Device::MENU_ADVANCED:
550 goto change_menu;
551
Mark Salyzyn488cc052019-05-20 10:36:16 -0700552 case Device::REBOOT_FROM_FASTBOOT: // Can not happen
553 case Device::SHUTDOWN_FROM_FASTBOOT: // Can not happen
Tao Bao50dd5322017-03-07 14:57:04 -0800554 case Device::NO_ACTION:
555 break;
556
Hridya Valsaraju20c81b32018-07-27 22:09:12 -0700557 case Device::ENTER_FASTBOOT:
558 case Device::ENTER_RECOVERY:
Tao Baod9cb0142019-04-23 11:46:25 -0700559 case Device::REBOOT_BOOTLOADER:
560 case Device::REBOOT_FASTBOOT:
561 case Device::REBOOT_RECOVERY:
562 case Device::REBOOT_RESCUE:
Tao Bao50dd5322017-03-07 14:57:04 -0800563 return chosen_action;
564
Yifan Hongc9163fd2020-01-27 17:37:39 -0800565 case Device::REBOOT:
566 case Device::SHUTDOWN:
Yifan Hong13b09962020-01-29 16:51:33 -0800567 if (!ui->IsTextVisible()) {
Kelvin Zhang9ebf0652020-08-13 18:15:17 -0400568 return chosen_action;
Yifan Hong13b09962020-01-29 16:51:33 -0800569 }
570 // okay to reboot; no need to ask.
571 if (!update_in_progress) {
Kelvin Zhang9ebf0652020-08-13 18:15:17 -0400572 return chosen_action;
Yifan Hong13b09962020-01-29 16:51:33 -0800573 }
574 // An update might have been failed. Ask if user really wants to reboot.
575 if (AskToReboot(device, chosen_action)) {
Kelvin Zhang9ebf0652020-08-13 18:15:17 -0400576 return chosen_action;
Yifan Hongc9163fd2020-01-27 17:37:39 -0800577 }
578 break;
579
Tao Bao50dd5322017-03-07 14:57:04 -0800580 case Device::WIPE_DATA:
xunchang316e9712019-04-12 16:22:15 -0700581 save_current_log = true;
Tao Bao50dd5322017-03-07 14:57:04 -0800582 if (ui->IsTextVisible()) {
Anay Wadhera25791a72021-01-01 19:40:11 -0800583 auto fs = get_preferred_fs(device);
584 if (fs == "")
585 break;
Tao Bao50dd5322017-03-07 14:57:04 -0800586 if (ask_to_wipe_data(device)) {
Anay Wadhera25791a72021-01-01 19:40:11 -0800587 WipeData(device, fs);
Tao Bao50dd5322017-03-07 14:57:04 -0800588 }
589 } else {
Eric Biggersfde69fb2022-03-10 22:13:39 +0000590 WipeData(device);
Tao Bao50dd5322017-03-07 14:57:04 -0800591 return Device::NO_ACTION;
592 }
593 break;
594
xunchang316e9712019-04-12 16:22:15 -0700595 case Device::WIPE_CACHE: {
596 save_current_log = true;
597 std::function<bool()> confirm_func = [&device]() {
Nolen Johnsond3519ab2020-04-12 14:13:31 -0400598 return yes_no(device, "Format cache?", " THIS CAN NOT BE UNDONE!");
xunchang316e9712019-04-12 16:22:15 -0700599 };
600 WipeCache(ui, ui->IsTextVisible() ? confirm_func : nullptr);
Tao Bao50dd5322017-03-07 14:57:04 -0800601 if (!ui->IsTextVisible()) return Device::NO_ACTION;
602 break;
xunchang316e9712019-04-12 16:22:15 -0700603 }
Tao Bao10f441a2019-04-19 15:22:15 -0700604
Michael Bestasb21efb82019-09-27 19:52:13 +0300605 case Device::WIPE_SYSTEM: {
606 save_current_log = true;
607 std::function<bool()> confirm_func = [&device]() {
Nolen Johnsond3519ab2020-04-12 14:13:31 -0400608 return yes_no(device, "Format system?", " THIS CAN NOT BE UNDONE!");
Michael Bestasb21efb82019-09-27 19:52:13 +0300609 };
610 WipeSystem(ui, ui->IsTextVisible() ? confirm_func : nullptr);
611 if (!ui->IsTextVisible()) return Device::NO_ACTION;
612 break;
613 }
614
Tom Marshall3e101752019-01-04 14:37:31 -0800615 case Device::APPLY_UPDATE:
Tao Baoc6dc3252019-04-16 14:22:25 -0700616 case Device::ENTER_RESCUE: {
xunchang316e9712019-04-12 16:22:15 -0700617 save_current_log = true;
Tao Baoc6dc3252019-04-16 14:22:25 -0700618
Yifan Hong13b09962020-01-29 16:51:33 -0800619 update_in_progress = true;
620 WriteUpdateInProgress();
621
Tao Bao10f441a2019-04-19 15:22:15 -0700622 Device::BuiltinAction reboot_action;
Tao Baoc6dc3252019-04-16 14:22:25 -0700623 if (chosen_action == Device::ENTER_RESCUE) {
624 // Switch to graphics screen.
625 ui->ShowText(false);
xunchangfedeef62019-04-22 12:18:14 -0700626 status = ApplyFromAdb(device, true /* rescue_mode */, &reboot_action);
Tom Marshall3e101752019-01-04 14:37:31 -0800627 } else if (chosen_action == Device::APPLY_UPDATE) {
628 status = apply_update_menu(device, &reboot_action);
Tao Bao50dd5322017-03-07 14:57:04 -0800629 }
xunchang3cc23d52019-03-18 15:03:33 -0700630
Tao Bao10f441a2019-04-19 15:22:15 -0700631 if (status == INSTALL_REBOOT) {
632 return reboot_action;
633 }
Alessandro Astone30a19742020-10-04 21:59:52 +0200634 if (status == INSTALL_NONE) {
635 update_in_progress = false;
636 }
Tao Bao10f441a2019-04-19 15:22:15 -0700637
Tom Marshall3e101752019-01-04 14:37:31 -0800638 ui->Print("\nInstall completed with status %d.\n", status);
Yifan Hong13b09962020-01-29 16:51:33 -0800639 if (status == INSTALL_SUCCESS) {
640 update_in_progress = false;
641 if (!ui->IsTextVisible()) {
642 return Device::NO_ACTION; // reboot if logs aren't visible
643 }
644 } else {
xunchang3cc23d52019-03-18 15:03:33 -0700645 ui->SetBackground(RecoveryUI::ERROR);
646 ui->Print("Installation aborted.\n");
Tianjie Xu164c60a2019-05-15 13:59:39 -0700647 copy_logs(save_current_log);
xunchang3cc23d52019-03-18 15:03:33 -0700648 }
Tao Bao50dd5322017-03-07 14:57:04 -0800649 break;
xunchang3cc23d52019-03-18 15:03:33 -0700650 }
Tao Bao50dd5322017-03-07 14:57:04 -0800651
652 case Device::VIEW_RECOVERY_LOGS:
653 choose_recovery_file(device);
654 break;
655
LuK133720434a92020-04-12 19:04:59 +0200656 case Device::ENABLE_ADB:
657 android::base::SetProperty("ro.adb.secure.recovery", "0");
658 android::base::SetProperty("ctl.restart", "adbd");
659 device->RemoveMenuItemForAction(Device::ENABLE_ADB);
660 device->GoHome();
661 ui->Print("Enabled ADB.\n");
662 break;
663
Ethan Yonker521c2c42021-01-03 23:47:09 -0800664 case Device::SWAP_SLOT:
665 set_slot(device);
666 break;
667
Tao Bao50dd5322017-03-07 14:57:04 -0800668 case Device::RUN_GRAPHICS_TEST:
Tianjie Xu164c60a2019-05-15 13:59:39 -0700669 run_graphics_test(ui);
Tao Bao50dd5322017-03-07 14:57:04 -0800670 break;
671
Tianjie Xu29d55752017-09-20 17:53:46 -0700672 case Device::RUN_LOCALE_TEST: {
673 ScreenRecoveryUI* screen_ui = static_cast<ScreenRecoveryUI*>(ui);
Tao Bao39c49182018-05-07 22:50:33 -0700674 screen_ui->CheckBackgroundTextImages();
Tianjie Xu29d55752017-09-20 17:53:46 -0700675 break;
676 }
Alessio Balsinia9665ce2019-12-09 09:26:05 +0000677
Michael Bestasb357f8e2021-01-16 18:16:47 +0200678 case Device::MOUNT_SYSTEM: {
679 static bool mounted = false;
680 if (!mounted) {
681 // For Virtual A/B, set up the snapshot devices (if exist).
682 if (!logical_partitions_mapped() && !CreateSnapshotPartitions()) {
683 ui->Print("Virtual A/B: snapshot partitions creation failed.\n");
684 break;
685 }
686 if (ensure_path_mounted_at(android::fs_mgr::GetSystemRoot(), "/mnt/system") != -1) {
687 ui->Print("Mounted /mnt/system.\n");
688 mounted = true;
689 }
690 } else {
691 if (umount("/mnt/system") != -1) {
Mohammad Hasan Keramat J14645732021-11-19 20:22:30 +0330692 ui->Print("Unmounted /mnt/system.\n");
Michael Bestasb357f8e2021-01-16 18:16:47 +0200693 mounted = false;
694 }
Tao Bao50dd5322017-03-07 14:57:04 -0800695 }
696 break;
Michael Bestasb357f8e2021-01-16 18:16:47 +0200697 }
Jerry Zhangb76af932018-05-22 12:08:35 -0700698
699 case Device::KEY_INTERRUPTED:
700 return Device::KEY_INTERRUPTED;
Tao Bao50dd5322017-03-07 14:57:04 -0800701 }
702 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800703}
704
Tao Bao99f0d9e2016-10-13 12:46:38 -0700705static void print_property(const char* key, const char* name, void* /* cookie */) {
706 printf("%s=%s\n", key, name);
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800707}
708
Tao Bao832c9cd2019-09-27 23:32:00 -0700709static bool IsBatteryOk(int* required_battery_level) {
710 // GmsCore enters recovery mode to install package when having enough battery percentage.
711 // Normally, the threshold is 40% without charger and 20% with charger. So we check the battery
712 // level against a slightly lower limit.
713 constexpr int BATTERY_OK_PERCENTAGE = 20;
714 constexpr int BATTERY_WITH_CHARGER_OK_PERCENTAGE = 15;
Yabin Cui99281df2016-02-17 12:21:52 -0800715
Tao Bao832c9cd2019-09-27 23:32:00 -0700716 auto battery_info = GetBatteryInfo();
717 *required_battery_level =
718 battery_info.charging ? BATTERY_WITH_CHARGER_OK_PERCENTAGE : BATTERY_OK_PERCENTAGE;
719 return battery_info.capacity >= *required_battery_level;
Yabin Cui99281df2016-02-17 12:21:52 -0800720}
721
Tianjie Xu99b73be2017-11-28 17:23:06 -0800722// Set the retry count to |retry_count| in BCB.
Tianjie Xu72449c92017-05-16 18:07:31 -0700723static void set_retry_bootloader_message(int retry_count, const std::vector<std::string>& args) {
724 std::vector<std::string> options;
725 for (const auto& arg : args) {
726 if (!android::base::StartsWith(arg, "--retry_count")) {
727 options.push_back(arg);
Tianjie Xu3c62b672016-02-05 18:25:58 -0800728 }
Tianjie Xu72449c92017-05-16 18:07:31 -0700729 }
Tianjie Xu3c62b672016-02-05 18:25:58 -0800730
Tianjie Xu99b73be2017-11-28 17:23:06 -0800731 // Update the retry counter in BCB.
732 options.push_back(android::base::StringPrintf("--retry_count=%d", retry_count));
Tianjie Xu72449c92017-05-16 18:07:31 -0700733 std::string err;
734 if (!update_bootloader_message(options, &err)) {
735 LOG(ERROR) << err;
736 }
Tianjie Xu3c62b672016-02-05 18:25:58 -0800737}
738
Tianjie1bc976a2020-07-22 17:25:11 -0700739static bool bootreason_in_blocklist() {
Tao Baoefc35592017-01-08 22:45:47 -0800740 std::string bootreason = android::base::GetProperty("ro.boot.bootreason", "");
741 if (!bootreason.empty()) {
Tao Baoaac9d9f2018-04-29 23:38:59 -0700742 // More bootreasons can be found in "system/core/bootstat/bootstat.cpp".
Tianjie1bc976a2020-07-22 17:25:11 -0700743 static const std::vector<std::string> kBootreasonBlocklist{
Tao Baoaac9d9f2018-04-29 23:38:59 -0700744 "kernel_panic",
745 "Panic",
746 };
Tianjie1bc976a2020-07-22 17:25:11 -0700747 for (const auto& str : kBootreasonBlocklist) {
Tao Baoaac9d9f2018-04-29 23:38:59 -0700748 if (android::base::EqualsIgnoreCase(str, bootreason)) return true;
Tianjie Xu06e57ac2016-07-11 14:04:08 -0700749 }
Tao Baoefc35592017-01-08 22:45:47 -0800750 }
751 return false;
Tianjie Xu06e57ac2016-07-11 14:04:08 -0700752}
753
Tao Bao641fa972018-04-25 18:59:40 -0700754static void log_failure_code(ErrorCode code, const std::string& update_package) {
755 std::vector<std::string> log_buffer = {
756 update_package,
757 "0", // install result
758 "error: " + std::to_string(code),
759 };
760 std::string log_content = android::base::Join(log_buffer, "\n");
761 const std::string& install_file = Paths::Get().temporary_install_file();
762 if (!android::base::WriteStringToFile(log_content, install_file)) {
763 PLOG(ERROR) << "Failed to write " << install_file;
764 }
Tianjie Xu06e57ac2016-07-11 14:04:08 -0700765
Tao Bao641fa972018-04-25 18:59:40 -0700766 // Also write the info into last_log.
767 LOG(INFO) << log_content;
Tianjie Xu06e57ac2016-07-11 14:04:08 -0700768}
769
Jerry Zhang6a648042018-05-04 11:24:10 -0700770Device::BuiltinAction start_recovery(Device* device, const std::vector<std::string>& args) {
Tao Baof9f17342018-04-27 10:44:04 -0700771 static constexpr struct option OPTIONS[] = {
Hridya Valsaraju20c81b32018-07-27 22:09:12 -0700772 { "fastboot", no_argument, nullptr, 0 },
Tianjie Xue5218612019-06-25 13:59:39 -0700773 { "install_with_fuse", no_argument, nullptr, 0 },
Tao Baof9f17342018-04-27 10:44:04 -0700774 { "just_exit", no_argument, nullptr, 'x' },
775 { "locale", required_argument, nullptr, 0 },
776 { "prompt_and_wipe_data", no_argument, nullptr, 0 },
777 { "reason", required_argument, nullptr, 0 },
Tao Baod9cb0142019-04-23 11:46:25 -0700778 { "rescue", no_argument, nullptr, 0 },
Tao Baof9f17342018-04-27 10:44:04 -0700779 { "retry_count", required_argument, nullptr, 0 },
780 { "security", no_argument, nullptr, 0 },
781 { "show_text", no_argument, nullptr, 't' },
782 { "shutdown_after", no_argument, nullptr, 0 },
783 { "sideload", no_argument, nullptr, 0 },
784 { "sideload_auto_reboot", no_argument, nullptr, 0 },
785 { "update_package", required_argument, nullptr, 0 },
786 { "wipe_ab", no_argument, nullptr, 0 },
787 { "wipe_cache", no_argument, nullptr, 0 },
788 { "wipe_data", no_argument, nullptr, 0 },
789 { "wipe_package_size", required_argument, nullptr, 0 },
790 { nullptr, 0, nullptr, 0 },
791 };
792
Tianjie Xu99b73be2017-11-28 17:23:06 -0800793 const char* update_package = nullptr;
Tianjie Xue5218612019-06-25 13:59:39 -0700794 bool install_with_fuse = false; // memory map the update package by default.
Tianjie Xu99b73be2017-11-28 17:23:06 -0800795 bool should_wipe_data = false;
796 bool should_prompt_and_wipe_data = false;
797 bool should_wipe_cache = false;
798 bool should_wipe_ab = false;
799 size_t wipe_package_size = 0;
Tianjie Xu99b73be2017-11-28 17:23:06 -0800800 bool sideload = false;
801 bool sideload_auto_reboot = false;
Tao Baod9cb0142019-04-23 11:46:25 -0700802 bool rescue = false;
Tianjie Xu99b73be2017-11-28 17:23:06 -0800803 bool just_exit = false;
804 bool shutdown_after = false;
805 int retry_count = 0;
806 bool security_update = false;
Jerry Zhang2dea53e2018-05-02 17:15:03 -0700807 std::string locale;
Tianjie Xu99b73be2017-11-28 17:23:06 -0800808
Tao Bao1700cc42018-07-16 22:09:59 -0700809 auto args_to_parse = StringVectorToNullTerminatedArray(args);
810
Tianjie Xu99b73be2017-11-28 17:23:06 -0800811 int arg;
812 int option_index;
Tao Bao1700cc42018-07-16 22:09:59 -0700813 // Parse everything before the last element (which must be a nullptr). getopt_long(3) expects a
814 // null-terminated char* array, but without counting null as an arg (i.e. argv[argc] should be
815 // nullptr).
816 while ((arg = getopt_long(args_to_parse.size() - 1, args_to_parse.data(), "", OPTIONS,
Tianjie Xu99b73be2017-11-28 17:23:06 -0800817 &option_index)) != -1) {
818 switch (arg) {
Tianjie Xu99b73be2017-11-28 17:23:06 -0800819 case 't':
Jerry Zhang6a648042018-05-04 11:24:10 -0700820 // Handled in recovery_main.cpp
Tianjie Xu99b73be2017-11-28 17:23:06 -0800821 break;
Tianjie Xu99b73be2017-11-28 17:23:06 -0800822 case 'x':
823 just_exit = true;
824 break;
Tianjie Xu99b73be2017-11-28 17:23:06 -0800825 case 0: {
826 std::string option = OPTIONS[option_index].name;
David Anderson969787c2020-01-27 09:29:02 -0800827 if (option == "install_with_fuse") {
Tianjie Xue5218612019-06-25 13:59:39 -0700828 install_with_fuse = true;
Tianjie Xub63a2212019-07-29 14:21:49 -0700829 } else if (option == "locale" || option == "fastboot" || option == "reason") {
Jerry Zhang6a648042018-05-04 11:24:10 -0700830 // Handled in recovery_main.cpp
Tianjie Xu99b73be2017-11-28 17:23:06 -0800831 } else if (option == "prompt_and_wipe_data") {
832 should_prompt_and_wipe_data = true;
Tao Baod9cb0142019-04-23 11:46:25 -0700833 } else if (option == "rescue") {
834 rescue = true;
Tao Baof9f17342018-04-27 10:44:04 -0700835 } else if (option == "retry_count") {
836 android::base::ParseInt(optarg, &retry_count, 0);
837 } else if (option == "security") {
838 security_update = true;
839 } else if (option == "sideload") {
840 sideload = true;
841 } else if (option == "sideload_auto_reboot") {
842 sideload = true;
843 sideload_auto_reboot = true;
844 } else if (option == "shutdown_after") {
845 shutdown_after = true;
846 } else if (option == "update_package") {
847 update_package = optarg;
848 } else if (option == "wipe_ab") {
849 should_wipe_ab = true;
850 } else if (option == "wipe_cache") {
851 should_wipe_cache = true;
852 } else if (option == "wipe_data") {
853 should_wipe_data = true;
854 } else if (option == "wipe_package_size") {
855 android::base::ParseUint(optarg, &wipe_package_size);
Tianjie Xu99b73be2017-11-28 17:23:06 -0800856 }
857 break;
858 }
859 case '?':
860 LOG(ERROR) << "Invalid command argument";
861 continue;
Doug Zongker9270a202012-01-09 15:16:13 -0800862 }
Tianjie Xu99b73be2017-11-28 17:23:06 -0800863 }
Jerry Zhang49fd5d22018-05-17 12:54:41 -0700864 optind = 1;
Doug Zongker9270a202012-01-09 15:16:13 -0800865
Tianjie Xub63a2212019-07-29 14:21:49 -0700866 printf("stage is [%s]\n", device->GetStage().value_or("").c_str());
867 printf("reason is [%s]\n", device->GetReason().value_or("").c_str());
Doug Zongker02ec6b82012-08-22 17:26:40 -0700868
Tianjie Xu164c60a2019-05-15 13:59:39 -0700869 auto ui = device->GetUI();
870
Tom Marshall3e101752019-01-04 14:37:31 -0800871 VolumeClient* volclient = new VolumeClient(device);
872 VolumeManager* volmgr = VolumeManager::Instance();
873 if (!volmgr->start(volclient)) {
874 printf("Failed to start volume manager\n");
875 }
876
Tianjie Xu99b73be2017-11-28 17:23:06 -0800877 // Set background string to "installing security update" for security update,
878 // otherwise set it to "installing system update".
879 ui->SetSystemUpdateText(security_update);
880
881 int st_cur, st_max;
Tianjie Xub63a2212019-07-29 14:21:49 -0700882 if (!device->GetStage().has_value() &&
883 sscanf(device->GetStage().value().c_str(), "%d/%d", &st_cur, &st_max) == 2) {
Tianjie Xu99b73be2017-11-28 17:23:06 -0800884 ui->SetStage(st_cur, st_max);
885 }
886
Richard Hansen833c0242020-05-12 18:08:56 -0400887 // Extract the YYYYMMDD date from the full version string. Assume
888 // the first instance of "-[0-9]{8}-" (if any) has the desired date.
889 std::string ver = android::base::GetProperty("ro.bliss.version", "");
890 std::smatch ver_date_match;
891 std::regex_search(ver, ver_date_match, std::regex("-(\\d{8})-"));
892 std::string ver_date = ver_date_match.str(1); // Empty if no match.
893
894 std::vector<std::string> title_lines = {
Jackeagle903cec72023-05-09 13:53:57 -0400895 "Version " + android::base::GetProperty("ro.bliss.build", "(unknown)"),
Richard Hansen833c0242020-05-12 18:08:56 -0400896 };
Richard Hansen1df126f2020-05-04 15:56:36 -0400897 if (android::base::GetBoolProperty("ro.build.ab_update", false)) {
898 std::string slot = android::base::GetProperty("ro.boot.slot_suffix", "");
899 if (android::base::StartsWith(slot, "_")) slot.erase(0, 1);
900 title_lines.push_back("Active slot: " + slot);
901 }
Jerry Zhang0e577ee2018-05-07 11:21:10 -0700902 ui->SetTitle(title_lines);
903
Jerry Zhangb76af932018-05-22 12:08:35 -0700904 ui->ResetKeyInterruptStatus();
Tianjie Xu99b73be2017-11-28 17:23:06 -0800905 device->StartRecovery();
906
907 printf("Command:");
908 for (const auto& arg : args) {
909 printf(" \"%s\"", arg.c_str());
910 }
911 printf("\n\n");
912
913 property_list(print_property, nullptr);
914 printf("\n");
915
Tao Baoadc99ef2019-04-29 23:48:02 -0700916 InstallResult status = INSTALL_SUCCESS;
Tao Bao10f441a2019-04-19 15:22:15 -0700917 // next_action indicates the next target to reboot into upon finishing the install. It could be
918 // overridden to a different reboot target per user request.
919 Device::BuiltinAction next_action = shutdown_after ? Device::SHUTDOWN : Device::REBOOT;
Tianjie Xu99b73be2017-11-28 17:23:06 -0800920
921 if (update_package != nullptr) {
922 // It's not entirely true that we will modify the flash. But we want
923 // to log the update attempt since update_package is non-NULL.
xunchang316e9712019-04-12 16:22:15 -0700924 save_current_log = true;
Tianjie Xu99b73be2017-11-28 17:23:06 -0800925
Tao Bao832c9cd2019-09-27 23:32:00 -0700926 if (int required_battery_level; retry_count == 0 && !IsBatteryOk(&required_battery_level)) {
Tao Bao6d90a9d2018-04-26 10:40:36 -0700927 ui->Print("battery capacity is not enough for installing package: %d%% needed\n",
928 required_battery_level);
Tao Bao832c9cd2019-09-27 23:32:00 -0700929 // Log the error code to last_install when installation skips due to low battery.
Tianjie Xu99b73be2017-11-28 17:23:06 -0800930 log_failure_code(kLowBattery, update_package);
931 status = INSTALL_SKIPPED;
Tianjie1bc976a2020-07-22 17:25:11 -0700932 } else if (retry_count == 0 && bootreason_in_blocklist()) {
Tianjie Xu99b73be2017-11-28 17:23:06 -0800933 // Skip update-on-reboot when bootreason is kernel_panic or similar
Tianjie1bc976a2020-07-22 17:25:11 -0700934 ui->Print("bootreason is in the blocklist; skip OTA installation\n");
935 log_failure_code(kBootreasonInBlocklist, update_package);
Tianjie Xu99b73be2017-11-28 17:23:06 -0800936 status = INSTALL_SKIPPED;
Dmitri Plotnikov8706a982017-04-18 08:28:26 -0700937 } else {
Tianjie Xu99b73be2017-11-28 17:23:06 -0800938 // It's a fresh update. Initialize the retry_count in the BCB to 1; therefore we can later
939 // identify the interrupted update due to unexpected reboots.
940 if (retry_count == 0) {
941 set_retry_bootloader_message(retry_count + 1, args);
Tao Bao7022f332017-07-25 09:52:36 -0700942 }
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -0800943
Tianjie Xucd8faf72019-08-06 12:32:05 -0700944 bool should_use_fuse = false;
945 if (!SetupPackageMount(update_package, &should_use_fuse)) {
946 LOG(INFO) << "Failed to set up the package access, skipping installation";
947 status = INSTALL_ERROR;
948 } else if (install_with_fuse || should_use_fuse) {
Tianjie Xue5218612019-06-25 13:59:39 -0700949 LOG(INFO) << "Installing package " << update_package << " with fuse";
Kelvin Zhanga4208b52022-02-14 18:38:06 -0800950 status = InstallWithFuseFromPath(update_package, device);
Tianjie Xue5218612019-06-25 13:59:39 -0700951 } else if (auto memory_package = Package::CreateMemoryPackage(
952 update_package,
953 std::bind(&RecoveryUI::SetProgress, ui, std::placeholders::_1));
954 memory_package != nullptr) {
955 status = InstallPackage(memory_package.get(), update_package, should_wipe_cache,
Kelvin Zhanga4208b52022-02-14 18:38:06 -0800956 retry_count, device);
Tianjie Xue5218612019-06-25 13:59:39 -0700957 } else {
958 // We may fail to memory map the package on 32 bit builds for packages with 2GiB+ size.
959 // In such cases, we will try to install the package with fuse. This is not the default
960 // installation method because it introduces a layer of indirection from the kernel space.
961 LOG(WARNING) << "Failed to memory map package " << update_package
962 << "; falling back to install with fuse";
Kelvin Zhanga4208b52022-02-14 18:38:06 -0800963 status = InstallWithFuseFromPath(update_package, device);
Tianjie Xue5218612019-06-25 13:59:39 -0700964 }
Tianjie Xu99b73be2017-11-28 17:23:06 -0800965 if (status != INSTALL_SUCCESS) {
966 ui->Print("Installation aborted.\n");
Tao Baoaac9d9f2018-04-29 23:38:59 -0700967
968 // When I/O error or bspatch/imgpatch error happens, reboot and retry installation
969 // RETRY_LIMIT times before we abandon this OTA update.
970 static constexpr int RETRY_LIMIT = 4;
Tianjie Xu99b73be2017-11-28 17:23:06 -0800971 if (status == INSTALL_RETRY && retry_count < RETRY_LIMIT) {
Tianjie Xu164c60a2019-05-15 13:59:39 -0700972 copy_logs(save_current_log);
Tianjie Xu99b73be2017-11-28 17:23:06 -0800973 retry_count += 1;
974 set_retry_bootloader_message(retry_count, args);
975 // Print retry count on screen.
976 ui->Print("Retry attempt %d\n", retry_count);
977
Tao Bao782dcc12019-04-29 11:23:16 -0700978 // Reboot back into recovery to retry the update.
Tianjie Xu00c4aba2020-03-13 14:25:02 -0700979 Reboot("recovery");
Tianjie Xud9d16292017-04-20 18:08:21 -0700980 }
Tianjie Xu99b73be2017-11-28 17:23:06 -0800981 // If this is an eng or userdebug build, then automatically
982 // turn the text display on if the script fails so the error
983 // message is visible.
Tianjie Xu164c60a2019-05-15 13:59:39 -0700984 if (IsRoDebuggable()) {
Tianjie Xu99b73be2017-11-28 17:23:06 -0800985 ui->ShowText(true);
Tao Baoc679f932015-03-30 09:43:49 -0700986 }
Tianjie Xu99b73be2017-11-28 17:23:06 -0800987 }
Doug Zongker8674a722010-09-15 11:08:23 -0700988 }
Tianjie Xu99b73be2017-11-28 17:23:06 -0800989 } else if (should_wipe_data) {
xunchang316e9712019-04-12 16:22:15 -0700990 save_current_log = true;
Tianjie Xub63a2212019-07-29 14:21:49 -0700991 CHECK(device->GetReason().has_value());
Eric Biggersfde69fb2022-03-10 22:13:39 +0000992 if (!WipeData(device)) {
Tianjie Xu99b73be2017-11-28 17:23:06 -0800993 status = INSTALL_ERROR;
Doug Zongkerb1d12632014-03-18 10:32:12 -0700994 }
Tianjie Xu99b73be2017-11-28 17:23:06 -0800995 } else if (should_prompt_and_wipe_data) {
Tao Baoa5bbcb92018-09-17 14:32:47 -0700996 // Trigger the logging to capture the cause, even if user chooses to not wipe data.
xunchang316e9712019-04-12 16:22:15 -0700997 save_current_log = true;
Tao Baoa5bbcb92018-09-17 14:32:47 -0700998
Tianjie Xu99b73be2017-11-28 17:23:06 -0800999 ui->ShowText(true);
1000 ui->SetBackground(RecoveryUI::ERROR);
Hridya Valsarajueb6f13a2018-09-12 10:25:01 -07001001 status = prompt_and_wipe_data(device);
Alessandro Astone8144be82020-12-24 11:58:17 +01001002 if (status == INSTALL_SUCCESS) {
Hridya Valsarajueb6f13a2018-09-12 10:25:01 -07001003 ui->ShowText(false);
Tao Bao75238632015-05-27 14:46:17 -07001004 }
Tianjie Xu99b73be2017-11-28 17:23:06 -08001005 } else if (should_wipe_cache) {
xunchang316e9712019-04-12 16:22:15 -07001006 save_current_log = true;
1007 if (!WipeCache(ui, nullptr)) {
Tianjie Xu99b73be2017-11-28 17:23:06 -08001008 status = INSTALL_ERROR;
1009 }
1010 } else if (should_wipe_ab) {
Tao Bao7f19d102019-04-26 22:56:56 -07001011 if (!WipeAbDevice(device, wipe_package_size)) {
Tianjie Xu99b73be2017-11-28 17:23:06 -08001012 status = INSTALL_ERROR;
1013 }
1014 } else if (sideload) {
Tao Bao10f441a2019-04-19 15:22:15 -07001015 // 'adb reboot sideload' acts the same as user presses key combinations to enter the sideload
1016 // mode. When 'sideload-auto-reboot' is used, text display will NOT be turned on by default. And
1017 // it will reboot after sideload finishes even if there are errors. This is to enable automated
Tianjie Xu99b73be2017-11-28 17:23:06 -08001018 // testing.
xunchang316e9712019-04-12 16:22:15 -07001019 save_current_log = true;
Tianjie Xu99b73be2017-11-28 17:23:06 -08001020 if (!sideload_auto_reboot) {
1021 ui->ShowText(true);
1022 }
Joseph Annareddya1cfeb22023-08-16 12:04:56 -04001023 ui->SetSideloadAutoReboot(sideload_auto_reboot);
xunchangfedeef62019-04-22 12:18:14 -07001024 status = ApplyFromAdb(device, false /* rescue_mode */, &next_action);
Tianjie Xu99b73be2017-11-28 17:23:06 -08001025 ui->Print("\nInstall from ADB complete (status: %d).\n", status);
1026 if (sideload_auto_reboot) {
Tao Bao10f441a2019-04-19 15:22:15 -07001027 status = INSTALL_REBOOT;
Tianjie Xu99b73be2017-11-28 17:23:06 -08001028 ui->Print("Rebooting automatically.\n");
1029 }
Tao Baod9cb0142019-04-23 11:46:25 -07001030 } else if (rescue) {
1031 save_current_log = true;
xunchangfedeef62019-04-22 12:18:14 -07001032 status = ApplyFromAdb(device, true /* rescue_mode */, &next_action);
Tao Baod9cb0142019-04-23 11:46:25 -07001033 ui->Print("\nInstall from ADB complete (status: %d).\n", status);
Tianjie Xu99b73be2017-11-28 17:23:06 -08001034 } else if (!just_exit) {
Pat Erley27e38d12016-01-05 16:50:02 -08001035 // Always show menu if no command is specified.
1036 // Note that this should be called before setting the background to avoid
Tianjie Xu99b73be2017-11-28 17:23:06 -08001037 // flickering the background image.
Pat Erley27e38d12016-01-05 16:50:02 -08001038 ui->ShowText(true);
Tianjie Xu99b73be2017-11-28 17:23:06 -08001039 status = INSTALL_NONE; // No command specified
1040 ui->SetBackground(RecoveryUI::NO_COMMAND);
1041 }
1042
1043 if (status == INSTALL_ERROR || status == INSTALL_CORRUPT) {
1044 ui->SetBackground(RecoveryUI::ERROR);
1045 if (!ui->IsTextVisible()) {
1046 sleep(5);
1047 }
1048 }
1049
Tao Bao10f441a2019-04-19 15:22:15 -07001050 // Determine the next action.
1051 // - If the state is INSTALL_REBOOT, device will reboot into the target as specified in
1052 // `next_action`.
1053 // - If the recovery menu is visible, prompt and wait for commands.
1054 // - If the state is INSTALL_NONE, wait for commands (e.g. in user build, one manually boots
1055 // into recovery to sideload a package or to wipe the device).
1056 // - In all other cases, reboot the device. Therefore, normal users will observe the device
1057 // rebooting a) immediately upon successful finish (INSTALL_SUCCESS); or b) an "error" screen
1058 // for 5s followed by an automatic reboot.
1059 if (status != INSTALL_REBOOT) {
1060 if (status == INSTALL_NONE || ui->IsTextVisible()) {
Tao Baoadc99ef2019-04-29 23:48:02 -07001061 auto temp = PromptAndWait(device, status);
Tao Bao10f441a2019-04-19 15:22:15 -07001062 if (temp != Device::NO_ACTION) {
1063 next_action = temp;
1064 }
Tianjie Xu99b73be2017-11-28 17:23:06 -08001065 }
1066 }
1067
1068 // Save logs and clean up before rebooting or shutting down.
Tianjie Xu164c60a2019-05-15 13:59:39 -07001069 FinishRecovery(ui);
Tianjie Xu99b73be2017-11-28 17:23:06 -08001070
Tom Marshall3e101752019-01-04 14:37:31 -08001071 volmgr->unmountAll();
1072 volmgr->stop();
1073 delete volclient;
1074
1075 sync();
1076
Tao Bao10f441a2019-04-19 15:22:15 -07001077 return next_action;
The Android Open Source Projectc24a8e62009-03-03 19:28:42 -08001078}