From 70c44e7a6a77222bcd9bccf737278774fd868c9d Mon Sep 17 00:00:00 2001 From: Yifan Hong Date: Tue, 16 Jan 2018 17:50:58 -0800 Subject: [PATCH] storaged: use get_health_service Test: storaged unit tests Bug: 68388678 Change-Id: I67100a9a0ad27f9e5b8fc077ff83c442e2bebe71 --- storaged/Android.bp | 7 ++++++- storaged/storaged.cpp | 24 ++++++++---------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/storaged/Android.bp b/storaged/Android.bp index 2c7dea19e..99491e25f 100644 --- a/storaged/Android.bp +++ b/storaged/Android.bp @@ -65,6 +65,8 @@ cc_library_static { "binder/android/os/storaged/IStoragedPrivate.aidl", ], + static_libs: ["libhealthhalutils"], + logtags: ["EventLogTags.logtags"], proto: { @@ -84,7 +86,10 @@ cc_binary { srcs: ["main.cpp"], - static_libs: ["libstoraged"], + static_libs: [ + "libhealthhalutils", + "libstoraged", + ], } /* diff --git a/storaged/storaged.cpp b/storaged/storaged.cpp index ff0de29b9..ef41b5732 100644 --- a/storaged/storaged.cpp +++ b/storaged/storaged.cpp @@ -28,11 +28,12 @@ #include #include -#include #include #include +#include #include #include +#include #include #include #include @@ -62,25 +63,16 @@ constexpr ssize_t min_benchmark_size = 128 * 1024; // 128KB const uint32_t storaged_t::current_version = 4; -using android::hardware::health::V1_0::BatteryStatus; -using android::hardware::health::V1_0::toString; -using android::hardware::health::V1_0::HealthInfo; -using android::hardware::health::V2_0::IHealth; -using android::hardware::health::V2_0::Result; using android::hardware::interfacesEqual; using android::hardware::Return; +using android::hardware::health::V1_0::BatteryStatus; +using android::hardware::health::V1_0::HealthInfo; +using android::hardware::health::V1_0::toString; +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::hidl::manager::V1_0::IServiceManager; -static sp get_health_service() { - for (auto&& instanceName : {"default", "backup"}) { - auto ret = IHealth::getService(instanceName); - if (ret != nullptr) { - return ret; - } - LOG_TO(SYSTEM, INFO) << "health: storaged: cannot get " << instanceName << " service"; - } - return nullptr; -} inline charger_stat_t is_charger_on(BatteryStatus prop) { return (prop == BatteryStatus::CHARGING || prop == BatteryStatus::FULL) ?