From 056538c0a9ec2bf1b641957ef7a260c465a0eb75 Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Wed, 11 Jul 2018 17:04:12 -0700 Subject: recovery uses IHealth::getService recovery is_battery_ok function uses get_health_service(), which calls IHealth::getService("default") then IHealth::getService("backup"). - An OEM can provide the default instance by installing android.hardware.health@2.0-impl-.so to recovery partition. - If that's not found, the "backup" instance is provided to the recovery partition by default. Test: call is_battery_ok() in recovery, successfully get battery information. Bug: 80132328 Change-Id: Ibfee80636325a07bc20b24d044d007a60b3dd7c2 --- Android.bp | 18 ++++++---------- recovery.cpp | 65 +++++++++++++++++++++++--------------------------------- tests/Android.mk | 13 ------------ 3 files changed, 33 insertions(+), 63 deletions(-) diff --git a/Android.bp b/Android.bp index 630c7965e..177eeb715 100644 --- a/Android.bp +++ b/Android.bp @@ -104,6 +104,7 @@ cc_defaults { ], shared_libs: [ + "android.hardware.health@2.0", "libbase", "libbootloader_message", "libcrypto", @@ -113,6 +114,8 @@ cc_defaults { "libfs_mgr", "libfusesideload", "libhidl-gen-utils", + "libhidlbase", + "libhidltransport", "liblog", "libpng", "libselinux", @@ -127,20 +130,11 @@ cc_defaults { "libminui", "libverifier", "libotautil", + + // external dependencies + "libhealthhalutils", "libvintf_recovery", "libvintf", - - // TODO(b/80132328): Remove the dependency on static health HAL. - "libhealthd.default", - "android.hardware.health@2.0-impl", - "android.hardware.health@2.0", - "android.hardware.health@1.0", - "android.hardware.health@1.0-convert", - "libhealthstoragedefault", - "libhidltransport", - "libhidlbase", - "libhwbinder_noltopgo", - "libbatterymonitor", ], } diff --git a/recovery.cpp b/recovery.cpp index cc30035df..129909549 100644 --- a/recovery.cpp +++ b/recovery.cpp @@ -49,7 +49,7 @@ #include #include #include /* for property_list */ -#include +#include #include #include "adb_install.h" @@ -877,42 +877,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 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 +907,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 diff --git a/tests/Android.mk b/tests/Android.mk index b6f5b451f..987e372e5 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -154,18 +154,6 @@ libupdater_static_libraries := \ libbrotli \ $(tune2fs_static_libraries) -health_hal_static_libraries := \ - android.hardware.health@2.0-impl \ - android.hardware.health@2.0 \ - android.hardware.health@1.0 \ - android.hardware.health@1.0-convert \ - libhealthstoragedefault \ - libhidltransport \ - libhidlbase \ - libhwbinder_noltopgo \ - libvndksupport \ - libbatterymonitor - librecovery_static_libraries := \ librecovery \ libbootloader_message \ @@ -175,7 +163,6 @@ librecovery_static_libraries := \ libminui \ libverifier \ libotautil \ - $(health_hal_static_libraries) \ libcrypto_utils \ libcrypto \ libext4_utils \ -- cgit v1.2.3