diff options
author | Todd Poynor <toddpoynor@google.com> | 2013-09-06 15:14:24 -0700 |
---|---|---|
committer | Todd Poynor <toddpoynor@google.com> | 2013-09-17 11:18:36 -0700 |
commit | 7b27f27d3de9e39d0de86c6e592d49bd4cc89158 (patch) | |
tree | 52c8fb62ebcd0c458a1ad86a8f5d410a7d6be1e4 /healthd | |
parent | c2c5a2410a2d7861d3c4f07f039eb8c471741cfa (diff) | |
download | system_core-7b27f27d3de9e39d0de86c6e592d49bd4cc89158.zip system_core-7b27f27d3de9e39d0de86c6e592d49bd4cc89158.tar.gz system_core-7b27f27d3de9e39d0de86c6e592d49bd4cc89158.tar.bz2 |
healthd: break link between BatteryMonitor and BatteryPropertiesRegistrar
Make it easier to later separate out binder-related code.
Add helper functions healthd_battery_update(), healthd_get_property() to
allow these operations without needing references to the BatteryMonitor
object.
Change-Id: Ie584bf53e5178ce0a098d0d940d6c311fdff62d4
Diffstat (limited to 'healthd')
-rw-r--r-- | healthd/BatteryMonitor.cpp | 2 | ||||
-rw-r--r-- | healthd/BatteryPropertiesRegistrar.cpp | 10 | ||||
-rw-r--r-- | healthd/BatteryPropertiesRegistrar.h | 6 | ||||
-rw-r--r-- | healthd/healthd.cpp | 11 | ||||
-rw-r--r-- | healthd/healthd.h | 7 |
5 files changed, 20 insertions, 16 deletions
diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index 5b3cac6..424d180 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -469,7 +469,7 @@ void BatteryMonitor::init(struct healthd_config *hc, bool nosvcmgr) { KLOG_WARNING(LOG_TAG, "BatteryTechnologyPath not found\n"); if (nosvcmgr == false) { - mBatteryPropertiesRegistrar = new BatteryPropertiesRegistrar(this); + mBatteryPropertiesRegistrar = new BatteryPropertiesRegistrar(); mBatteryPropertiesRegistrar->publish(); } } diff --git a/healthd/BatteryPropertiesRegistrar.cpp b/healthd/BatteryPropertiesRegistrar.cpp index 3e06866..f2edee4 100644 --- a/healthd/BatteryPropertiesRegistrar.cpp +++ b/healthd/BatteryPropertiesRegistrar.cpp @@ -23,11 +23,9 @@ #include <utils/Mutex.h> #include <utils/String16.h> -namespace android { +#include "healthd.h" -BatteryPropertiesRegistrar::BatteryPropertiesRegistrar(BatteryMonitor* monitor) { - mBatteryMonitor = monitor; -} +namespace android { void BatteryPropertiesRegistrar::publish() { defaultServiceManager()->addService(String16("batterypropreg"), this); @@ -53,7 +51,7 @@ void BatteryPropertiesRegistrar::registerListener(const sp<IBatteryPropertiesLis mListeners.add(listener); listener->asBinder()->linkToDeath(this); } - mBatteryMonitor->update(); + healthd_battery_update(); } void BatteryPropertiesRegistrar::unregisterListener(const sp<IBatteryPropertiesListener>& listener) { @@ -68,7 +66,7 @@ void BatteryPropertiesRegistrar::unregisterListener(const sp<IBatteryPropertiesL } status_t BatteryPropertiesRegistrar::getProperty(int id, struct BatteryProperty *val) { - return mBatteryMonitor->getProperty(id, val); + return healthd_get_property(id, val); } void BatteryPropertiesRegistrar::binderDied(const wp<IBinder>& who) { diff --git a/healthd/BatteryPropertiesRegistrar.h b/healthd/BatteryPropertiesRegistrar.h index 0ce6c04..3e86fdf 100644 --- a/healthd/BatteryPropertiesRegistrar.h +++ b/healthd/BatteryPropertiesRegistrar.h @@ -17,8 +17,6 @@ #ifndef HEALTHD_BATTERYPROPERTIES_REGISTRAR_H #define HEALTHD_BATTERYPROPERTIES_REGISTRAR_H -#include "BatteryMonitor.h" - #include <binder/IBinder.h> #include <utils/Mutex.h> #include <utils/Vector.h> @@ -28,17 +26,13 @@ namespace android { -class BatteryMonitor; - class BatteryPropertiesRegistrar : public BnBatteryPropertiesRegistrar, public IBinder::DeathRecipient { public: - BatteryPropertiesRegistrar(BatteryMonitor* monitor); void publish(); void notifyListeners(struct BatteryProperties props); private: - BatteryMonitor* mBatteryMonitor; Mutex mRegistrationLock; Vector<sp<IBatteryPropertiesListener> > mListeners; diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp index 900cc42..62f4d11 100644 --- a/healthd/healthd.cpp +++ b/healthd/healthd.cpp @@ -31,6 +31,7 @@ #include <cutils/uevent.h> #include <sys/epoll.h> #include <sys/timerfd.h> +#include <utils/Errors.h> using namespace android; @@ -90,7 +91,11 @@ static void wakealarm_set_interval(int interval) { KLOG_ERROR(LOG_TAG, "wakealarm_set_interval: timerfd_settime failed\n"); } -static void battery_update(void) { +status_t healthd_get_property(int id, struct BatteryProperty *val) { + return gBatteryMonitor->getProperty(id, val); +} + +void healthd_battery_update(void) { // Fast wake interval when on charger (watch for overheat); // slow wake interval when on battery (watch for drained battery). @@ -115,7 +120,7 @@ static void battery_update(void) { } static void periodic_chores() { - battery_update(); + healthd_battery_update(); } static void uevent_init(void) { @@ -145,7 +150,7 @@ static void uevent_event(void) { while (*cp) { if (!strcmp(cp, "SUBSYSTEM=" POWER_SUPPLY_SUBSYSTEM)) { - battery_update(); + healthd_battery_update(); break; } diff --git a/healthd/healthd.h b/healthd/healthd.h index 5a1ad18..dc3f67e 100644 --- a/healthd/healthd.h +++ b/healthd/healthd.h @@ -18,6 +18,7 @@ #define _HEALTHD_H_ #include <batteryservice/BatteryService.h> +#include <utils/Errors.h> #include <utils/String8.h> // periodic_chores_interval_fast, periodic_chores_interval_slow: intervals at @@ -65,6 +66,12 @@ struct healthd_config { android::String8 batteryChargeCounterPath; }; +// Global helper functions + +void healthd_battery_update(); +android::status_t healthd_get_property(int id, + struct android::BatteryProperty *val); + // The following are implemented in libhealthd_board to handle board-specific // behavior. // |