Merge "recovery uses IHealth::getService"

am: ce2f0d85fb

Change-Id: Ic22bf13545f1261f288dc47df9ee123913ad8028
This commit is contained in:
Yifan Hong
2018-08-14 15:51:08 -07:00
committed by android-build-merger
3 changed files with 32 additions and 62 deletions
+6 -12
View File
@@ -104,6 +104,7 @@ cc_defaults {
], ],
shared_libs: [ shared_libs: [
"android.hardware.health@2.0",
"libbase", "libbase",
"libbootloader_message", "libbootloader_message",
"libcrypto", "libcrypto",
@@ -112,6 +113,8 @@ cc_defaults {
"libfs_mgr", "libfs_mgr",
"libfusesideload", "libfusesideload",
"libhidl-gen-utils", "libhidl-gen-utils",
"libhidlbase",
"libhidltransport",
"liblog", "liblog",
"libpng", "libpng",
"libselinux", "libselinux",
@@ -125,20 +128,11 @@ cc_defaults {
"libminui", "libminui",
"libverifier", "libverifier",
"libotautil", "libotautil",
// external dependencies
"libhealthhalutils",
"libvintf_recovery", "libvintf_recovery",
"libvintf", "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",
], ],
} }
+26 -37
View File
@@ -49,7 +49,7 @@
#include <android-base/unique_fd.h> #include <android-base/unique_fd.h>
#include <bootloader_message/bootloader_message.h> #include <bootloader_message/bootloader_message.h>
#include <cutils/properties.h> /* for property_list */ #include <cutils/properties.h> /* for property_list */
#include <health2/Health.h> #include <healthhalutils/HealthHalUtils.h>
#include <ziparchive/zip_archive.h> #include <ziparchive/zip_archive.h>
#include "adb_install.h" #include "adb_install.h"
@@ -877,42 +877,29 @@ void ui_print(const char* format, ...) {
static bool is_battery_ok(int* required_battery_level) { static bool is_battery_ok(int* required_battery_level) {
using android::hardware::health::V1_0::BatteryStatus; 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::Result;
using android::hardware::health::V2_0::toString; using android::hardware::health::V2_0::toString;
using android::hardware::health::V2_0::implementation::Health;
struct healthd_config healthd_config = { android::sp<IHealth> health = get_health_service();
.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);
static constexpr int BATTERY_READ_TIMEOUT_IN_SEC = 10; static constexpr int BATTERY_READ_TIMEOUT_IN_SEC = 10;
int wait_second = 0; int wait_second = 0;
while (true) { while (true) {
auto charge_status = BatteryStatus::UNKNOWN; auto charge_status = BatteryStatus::UNKNOWN;
health
->getChargeStatus([&charge_status](auto res, auto out_status) { if (health == nullptr) {
if (res == Result::SUCCESS) { LOG(WARNING) << "no health implementation is found, assuming defaults";
charge_status = out_status; } else {
} health
}) ->getChargeStatus([&charge_status](auto res, auto out_status) {
.isOk(); // should not have transport error if (res == Result::SUCCESS) {
charge_status = out_status;
}
})
.isOk(); // should not have transport error
}
// Treat unknown status as charged. // Treat unknown status as charged.
bool charged = (charge_status != BatteryStatus::DISCHARGING && bool charged = (charge_status != BatteryStatus::DISCHARGING &&
@@ -920,15 +907,17 @@ static bool is_battery_ok(int* required_battery_level) {
Result res = Result::UNKNOWN; Result res = Result::UNKNOWN;
int32_t capacity = INT32_MIN; int32_t capacity = INT32_MIN;
health if (health != nullptr) {
->getCapacity([&res, &capacity](auto out_res, auto out_capacity) { health
res = out_res; ->getCapacity([&res, &capacity](auto out_res, auto out_capacity) {
capacity = out_capacity; res = out_res;
}) capacity = out_capacity;
.isOk(); // should not have transport error })
.isOk(); // should not have transport error
}
ui_print("charge_status %d, charged %d, status %s, capacity %" PRId32 "\n", charge_status, LOG(INFO) << "charge_status " << toString(charge_status) << ", charged " << charged
charged, toString(res).c_str(), capacity); << ", status " << toString(res) << ", capacity " << capacity;
// At startup, the battery drivers in devices like N5X/N6P take some time to load // 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 // 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 // capacity. BATTERY_READ_TIMEOUT_IN_SEC is set that the battery drivers are expected
-13
View File
@@ -154,18 +154,6 @@ libupdater_static_libraries := \
libtune2fs \ libtune2fs \
$(tune2fs_static_libraries) $(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_static_libraries := \
librecovery \ librecovery \
libbootloader_message \ libbootloader_message \
@@ -175,7 +163,6 @@ librecovery_static_libraries := \
libminui \ libminui \
libverifier \ libverifier \
libotautil \ libotautil \
$(health_hal_static_libraries) \
libcrypto_utils \ libcrypto_utils \
libcrypto \ libcrypto \
libext4_utils \ libext4_utils \