storaged: use get_health_service
Test: storaged unit tests
Bug: 68388678
Change-Id: I67100a9a0ad27f9e5b8fc077ff83c442e2bebe71
diff --git a/storaged/Android.bp b/storaged/Android.bp
index 2c7dea1..99491e2 100644
--- a/storaged/Android.bp
+++ b/storaged/Android.bp
@@ -65,6 +65,8 @@
"binder/android/os/storaged/IStoragedPrivate.aidl",
],
+ static_libs: ["libhealthhalutils"],
+
logtags: ["EventLogTags.logtags"],
proto: {
@@ -84,7 +86,10 @@
srcs: ["main.cpp"],
- static_libs: ["libstoraged"],
+ static_libs: [
+ "libhealthhalutils",
+ "libstoraged",
+ ],
}
/*
diff --git a/storaged/storaged.cpp b/storaged/storaged.cpp
index ff0de29..ef41b57 100644
--- a/storaged/storaged.cpp
+++ b/storaged/storaged.cpp
@@ -28,11 +28,12 @@
#include <sstream>
#include <string>
-#include <android/hidl/manager/1.0/IServiceManager.h>
#include <android-base/file.h>
#include <android-base/logging.h>
+#include <android/hidl/manager/1.0/IServiceManager.h>
#include <batteryservice/BatteryServiceConstants.h>
#include <cutils/properties.h>
+#include <healthhalutils/HealthHalUtils.h>
#include <hidl/HidlTransportSupport.h>
#include <hwbinder/IPCThreadState.h>
#include <log/log.h>
@@ -62,25 +63,16 @@
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<IHealth> 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) ?