diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2018-08-15 05:11:19 +0200 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2018-08-15 05:11:19 +0200 |
commit | bc563e6b2b41ede7efb89e5b566f3a83d50e71fd (patch) | |
tree | de86583ed092366d56b5f4f7ba4a6db5b03bb28d /recovery.cpp | |
parent | Snap for 4951335 from 17f5b296d1c0d4bdd6a67fbe7dfd088187c8686e to qt-release (diff) | |
parent | Merge "Add fastboot mode to recovery" am: 19a5316412 am: b0851cf8c4 (diff) | |
download | android_bootable_recovery-bc563e6b2b41ede7efb89e5b566f3a83d50e71fd.tar android_bootable_recovery-bc563e6b2b41ede7efb89e5b566f3a83d50e71fd.tar.gz android_bootable_recovery-bc563e6b2b41ede7efb89e5b566f3a83d50e71fd.tar.bz2 android_bootable_recovery-bc563e6b2b41ede7efb89e5b566f3a83d50e71fd.tar.lz android_bootable_recovery-bc563e6b2b41ede7efb89e5b566f3a83d50e71fd.tar.xz android_bootable_recovery-bc563e6b2b41ede7efb89e5b566f3a83d50e71fd.tar.zst android_bootable_recovery-bc563e6b2b41ede7efb89e5b566f3a83d50e71fd.zip |
Diffstat (limited to '')
-rw-r--r-- | recovery.cpp | 70 |
1 files changed, 31 insertions, 39 deletions
diff --git a/recovery.cpp b/recovery.cpp index cc30035df..01bd83b5e 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -49,7 +49,7 @@ #include <android-base/unique_fd.h> #include <bootloader_message/bootloader_message.h> #include <cutils/properties.h> /* for property_list */ -#include <health2/Health.h> +#include <healthhalutils/HealthHalUtils.h> #include <ziparchive/zip_archive.h> #include "adb_install.h" @@ -779,6 +779,8 @@ static Device::BuiltinAction prompt_and_wait(Device* device, int status) { case Device::REBOOT: case Device::SHUTDOWN: case Device::REBOOT_BOOTLOADER: + case Device::ENTER_FASTBOOT: + case Device::ENTER_RECOVERY: return chosen_action; case Device::WIPE_DATA: @@ -877,42 +879,29 @@ void ui_print(const char* format, ...) { static bool is_battery_ok(int* required_battery_level) { using android::hardware::health::V1_0::BatteryStatus; + using android::hardware::health::V2_0::get_health_service; + using android::hardware::health::V2_0::IHealth; using android::hardware::health::V2_0::Result; using android::hardware::health::V2_0::toString; - using android::hardware::health::V2_0::implementation::Health; - - struct healthd_config healthd_config = { - .batteryStatusPath = android::String8(android::String8::kEmptyString), - .batteryHealthPath = android::String8(android::String8::kEmptyString), - .batteryPresentPath = android::String8(android::String8::kEmptyString), - .batteryCapacityPath = android::String8(android::String8::kEmptyString), - .batteryVoltagePath = android::String8(android::String8::kEmptyString), - .batteryTemperaturePath = android::String8(android::String8::kEmptyString), - .batteryTechnologyPath = android::String8(android::String8::kEmptyString), - .batteryCurrentNowPath = android::String8(android::String8::kEmptyString), - .batteryCurrentAvgPath = android::String8(android::String8::kEmptyString), - .batteryChargeCounterPath = android::String8(android::String8::kEmptyString), - .batteryFullChargePath = android::String8(android::String8::kEmptyString), - .batteryCycleCountPath = android::String8(android::String8::kEmptyString), - .energyCounter = nullptr, - .boot_min_cap = 0, - .screen_on = nullptr - }; - auto health = - android::hardware::health::V2_0::implementation::Health::initInstance(&healthd_config); + android::sp<IHealth> health = get_health_service(); static constexpr int BATTERY_READ_TIMEOUT_IN_SEC = 10; int wait_second = 0; while (true) { auto charge_status = BatteryStatus::UNKNOWN; - health - ->getChargeStatus([&charge_status](auto res, auto out_status) { - if (res == Result::SUCCESS) { - charge_status = out_status; - } - }) - .isOk(); // should not have transport error + + if (health == nullptr) { + LOG(WARNING) << "no health implementation is found, assuming defaults"; + } else { + health + ->getChargeStatus([&charge_status](auto res, auto out_status) { + if (res == Result::SUCCESS) { + charge_status = out_status; + } + }) + .isOk(); // should not have transport error + } // Treat unknown status as charged. bool charged = (charge_status != BatteryStatus::DISCHARGING && @@ -920,15 +909,17 @@ static bool is_battery_ok(int* required_battery_level) { Result res = Result::UNKNOWN; int32_t capacity = INT32_MIN; - health - ->getCapacity([&res, &capacity](auto out_res, auto out_capacity) { - res = out_res; - capacity = out_capacity; - }) - .isOk(); // should not have transport error - - ui_print("charge_status %d, charged %d, status %s, capacity %" PRId32 "\n", charge_status, - charged, toString(res).c_str(), capacity); + if (health != nullptr) { + health + ->getCapacity([&res, &capacity](auto out_res, auto out_capacity) { + res = out_res; + capacity = out_capacity; + }) + .isOk(); // should not have transport error + } + + LOG(INFO) << "charge_status " << toString(charge_status) << ", charged " << charged + << ", status " << toString(res) << ", capacity " << capacity; // At startup, the battery drivers in devices like N5X/N6P take some time to load // the battery profile. Before the load finishes, it reports value 50 as a fake // capacity. BATTERY_READ_TIMEOUT_IN_SEC is set that the battery drivers are expected @@ -1006,6 +997,7 @@ static void log_failure_code(ErrorCode code, const std::string& update_package) Device::BuiltinAction start_recovery(Device* device, const std::vector<std::string>& args) { static constexpr struct option OPTIONS[] = { + { "fastboot", no_argument, nullptr, 0 }, { "fsck_unshare_blocks", no_argument, nullptr, 0 }, { "just_exit", no_argument, nullptr, 'x' }, { "locale", required_argument, nullptr, 0 }, @@ -1060,7 +1052,7 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri std::string option = OPTIONS[option_index].name; if (option == "fsck_unshare_blocks") { fsck_unshare_blocks = true; - } else if (option == "locale") { + } else if (option == "locale" || option == "fastboot") { // Handled in recovery_main.cpp } else if (option == "prompt_and_wipe_data") { should_prompt_and_wipe_data = true; |