healthd: move global gHealth service pointer
... to class implementation::Health. Expose APIs
InitInstance(), GetImplmentation()
for its setter and getter.
Clients that statically links to android.hardware
.health@2.0-impl (e.g. charger, recovery)
should use InitInstance().
Test: health VTS tests
Bug: 63702641
Change-Id: I51b9b976d0b723dac1a03e5113d5d9e84300c0e9
diff --git a/healthd/HealthServiceCommon.cpp b/healthd/HealthServiceCommon.cpp
index 260ca78..68ff526 100644
--- a/healthd/HealthServiceCommon.cpp
+++ b/healthd/HealthServiceCommon.cpp
@@ -33,9 +33,6 @@
using android::hardware::health::V2_0::IHealth;
using android::hardware::health::V2_0::implementation::Health;
-// see healthd_common.cpp
-android::sp<IHealth> gHealth;
-
extern int healthd_main(void);
static void binder_event(uint32_t /*epevents*/) {
@@ -63,8 +60,8 @@
// TODO(b/68724651): healthd_board_* functions should be removed in health@2.0
healthd_board_init(config);
- gHealth = new ::android::hardware::health::V2_0::implementation::Health(config);
- CHECK_EQ(gHealth->registerAsService(HEALTH_INSTANCE_NAME), android::OK)
+ android::sp<IHealth> service = Health::initInstance(config);
+ CHECK_EQ(service->registerAsService(HEALTH_INSTANCE_NAME), android::OK)
<< LOG_TAG << ": Failed to register HAL";
LOG(INFO) << LOG_TAG << ": Hal init done";
@@ -85,7 +82,7 @@
HealthInfo info;
convertToHealthInfo(prop, info);
- static_cast<Health*>(gHealth.get())->notifyListeners(info);
+ Health::getImplementation()->notifyListeners(info);
}
static struct healthd_mode_ops healthd_mode_service_2_0_ops = {