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
This commit is contained in:
Todd Poynor 2013-09-06 15:14:24 -07:00
parent c2c5a2410a
commit 7b27f27d3d
5 changed files with 20 additions and 16 deletions

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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;

View File

@ -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;
}

View File

@ -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.
//