From b63a2215b5e3fc9c7254aa783c7857ede79e6f4e Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Mon, 29 Jul 2019 14:21:49 -0700 Subject: Remove common.h Additionally kill the global variable: reason, stage; move them to a separate BootState class instead. Vendor specific recovery code will need to call getters from Device() class to access these variables. Bug: 137705917 Test: unit tests pass, boot sailfish into recovery, code search and no code includes common.h in vendor specific recovery. Change-Id: Ia50a5ea951212c25548562f29cc9cf78505b5e34 --- recovery.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'recovery.cpp') diff --git a/recovery.cpp b/recovery.cpp index b989b2465..4862dfccb 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -46,7 +46,6 @@ #include #include "bootloader_message/bootloader_message.h" -#include "common.h" #include "fsck_unshare_blocks.h" #include "install/adb_install.h" #include "install/fuse_install.h" @@ -54,6 +53,7 @@ #include "install/package.h" #include "install/wipe_data.h" #include "install/wipe_device.h" +#include "otautil/boot_state.h" #include "otautil/error_code.h" #include "otautil/logging.h" #include "otautil/paths.h" @@ -70,8 +70,6 @@ static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale"; static constexpr const char* CACHE_ROOT = "/cache"; static bool save_current_log = false; -std::string stage; -const char* reason = nullptr; /* * The recovery tool communicates with the main system through /cache files. @@ -208,7 +206,8 @@ static InstallResult prompt_and_wipe_data(Device* device) { } if (ask_to_wipe_data(device)) { - bool convert_fbe = reason && strcmp(reason, "convert_fbe") == 0; + CHECK(device->GetReason().has_value()); + bool convert_fbe = device->GetReason().value() == "convert_fbe"; if (WipeData(device, convert_fbe)) { return INSTALL_SUCCESS; } else { @@ -635,12 +634,10 @@ Device::BuiltinAction start_recovery(Device* device, const std::vectorGetStage().value_or("").c_str()); + printf("reason is [%s]\n", device->GetReason().value_or("").c_str()); auto ui = device->GetUI(); @@ -684,7 +681,8 @@ Device::BuiltinAction start_recovery(Device* device, const std::vectorSetSystemUpdateText(security_update); int st_cur, st_max; - if (!stage.empty() && sscanf(stage.c_str(), "%d/%d", &st_cur, &st_max) == 2) { + if (!device->GetStage().has_value() && + sscanf(device->GetStage().value().c_str(), "%d/%d", &st_cur, &st_max) == 2) { ui->SetStage(st_cur, st_max); } @@ -790,7 +788,8 @@ Device::BuiltinAction start_recovery(Device* device, const std::vectorGetReason().has_value()); + bool convert_fbe = device->GetReason().value() == "convert_fbe"; if (!WipeData(device, convert_fbe)) { status = INSTALL_ERROR; } -- cgit v1.2.3