From e55356486fb16aa74f3b85242ec281ee7dec3fac Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Tue, 5 Jan 2016 19:41:34 -0800 Subject: [PATCH] healthd: BatteryPropertiesRegistrar binder service ref count fixup Call addService using a reference to a strong pointer to the service object, such that the proper IBinder object is ref counted, instead of passing the object's this pointer. Bug: None Change-Id: I72cac08c835a17b8cc263b2dc34864420b7a2841 --- healthd/BatteryPropertiesRegistrar.cpp | 5 +++-- healthd/BatteryPropertiesRegistrar.h | 2 +- healthd/healthd_mode_android.cpp | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/healthd/BatteryPropertiesRegistrar.cpp b/healthd/BatteryPropertiesRegistrar.cpp index 09667a1ad..d3a89d731 100644 --- a/healthd/BatteryPropertiesRegistrar.cpp +++ b/healthd/BatteryPropertiesRegistrar.cpp @@ -30,8 +30,9 @@ namespace android { -void BatteryPropertiesRegistrar::publish() { - defaultServiceManager()->addService(String16("batteryproperties"), this); +void BatteryPropertiesRegistrar::publish( + const sp& service) { + defaultServiceManager()->addService(String16("batteryproperties"), service); } void BatteryPropertiesRegistrar::notifyListeners(struct BatteryProperties props) { diff --git a/healthd/BatteryPropertiesRegistrar.h b/healthd/BatteryPropertiesRegistrar.h index 88538744d..d17e4a327 100644 --- a/healthd/BatteryPropertiesRegistrar.h +++ b/healthd/BatteryPropertiesRegistrar.h @@ -30,7 +30,7 @@ namespace android { class BatteryPropertiesRegistrar : public BnBatteryPropertiesRegistrar, public IBinder::DeathRecipient { public: - void publish(); + void publish(const sp& service); void notifyListeners(struct BatteryProperties props); private: diff --git a/healthd/healthd_mode_android.cpp b/healthd/healthd_mode_android.cpp index fd153a260..0a64099c3 100644 --- a/healthd/healthd_mode_android.cpp +++ b/healthd/healthd_mode_android.cpp @@ -58,5 +58,5 @@ void healthd_mode_android_init(struct healthd_config* /*config*/) { } gBatteryPropertiesRegistrar = new BatteryPropertiesRegistrar(); - gBatteryPropertiesRegistrar->publish(); + gBatteryPropertiesRegistrar->publish(gBatteryPropertiesRegistrar); }