healthd: BatteryService dumpstate support

Change-Id: Ia6938b7126751801310632c995af0f96e41f5f64
This commit is contained in:
Todd Poynor 2013-09-18 20:09:33 -07:00
parent 6dcc45ed6d
commit 020369d872
6 changed files with 61 additions and 5 deletions

View File

@ -170,7 +170,6 @@ int BatteryMonitor::getIntField(const String8& path) {
}
bool BatteryMonitor::update(void) {
struct BatteryProperties props;
struct BatteryExtraProperties extraProps;
bool logthis;
@ -242,10 +241,6 @@ bool BatteryMonitor::update(void) {
}
}
/* temporary while these are moved and dumpsys reworked */
props.batteryCurrentNow = extraProps.batteryCurrentNow;
props.batteryChargeCounter = extraProps.batteryChargeCounter;
logthis = !healthd_board_battery_update(&props);
if (logthis) {
@ -325,6 +320,41 @@ status_t BatteryMonitor::getProperty(int id, struct BatteryProperty *val) {
return ret;
}
void BatteryMonitor::dumpState(int fd) {
int v;
char vs[128];
snprintf(vs, sizeof(vs), "ac: %d usb: %d wireless: %d\n",
props.chargerAcOnline, props.chargerUsbOnline,
props.chargerWirelessOnline);
write(fd, vs, strlen(vs));
snprintf(vs, sizeof(vs), "status: %d health: %d present: %d\n",
props.batteryStatus, props.batteryHealth, props.batteryPresent);
write(fd, vs, strlen(vs));
snprintf(vs, sizeof(vs), "level: %d voltage: %d temp: %d\n",
props.batteryLevel, props.batteryVoltage,
props.batteryTemperature);
write(fd, vs, strlen(vs));
if (!mHealthdConfig->batteryCurrentNowPath.isEmpty()) {
v = getIntField(mHealthdConfig->batteryCurrentNowPath);
snprintf(vs, sizeof(vs), "current now: %d\n", v);
write(fd, vs, strlen(vs));
}
if (!mHealthdConfig->batteryCurrentAvgPath.isEmpty()) {
v = getIntField(mHealthdConfig->batteryCurrentAvgPath);
snprintf(vs, sizeof(vs), "current avg: %d\n", v);
write(fd, vs, strlen(vs));
}
if (!mHealthdConfig->batteryChargeCounterPath.isEmpty()) {
v = getIntField(mHealthdConfig->batteryChargeCounterPath);
snprintf(vs, sizeof(vs), "charge counter: %d\n", v);
write(fd, vs, strlen(vs));
}
}
void BatteryMonitor::init(struct healthd_config *hc) {
String8 path;

View File

@ -40,11 +40,13 @@ class BatteryMonitor {
void init(struct healthd_config *hc);
bool update(void);
status_t getProperty(int id, struct BatteryProperty *val);
void dumpState(int fd);
private:
struct healthd_config *mHealthdConfig;
Vector<String8> mChargerNames;
bool mBatteryDevicePresent;
struct BatteryProperties props;
int getBatteryStatus(const char* status);
int getBatteryHealth(const char* status);

View File

@ -18,7 +18,10 @@
#include <batteryservice/BatteryService.h>
#include <batteryservice/IBatteryPropertiesListener.h>
#include <batteryservice/IBatteryPropertiesRegistrar.h>
#include <binder/IPCThreadState.h>
#include <binder/IServiceManager.h>
#include <binder/PermissionCache.h>
#include <private/android_filesystem_config.h>
#include <utils/Errors.h>
#include <utils/Mutex.h>
#include <utils/String16.h>
@ -69,6 +72,19 @@ status_t BatteryPropertiesRegistrar::getProperty(int id, struct BatteryProperty
return healthd_get_property(id, val);
}
status_t BatteryPropertiesRegistrar::dump(int fd, const Vector<String16>& args) {
IPCThreadState* self = IPCThreadState::self();
const int pid = self->getCallingPid();
const int uid = self->getCallingUid();
if ((uid != AID_SHELL) &&
!PermissionCache::checkPermission(
String16("android.permission.DUMP"), pid, uid))
return PERMISSION_DENIED;
healthd_dump_battery_state(fd);
return OK;
}
void BatteryPropertiesRegistrar::binderDied(const wp<IBinder>& who) {
Mutex::Autolock _l(mRegistrationLock);

View File

@ -19,6 +19,7 @@
#include <binder/IBinder.h>
#include <utils/Mutex.h>
#include <utils/String16.h>
#include <utils/Vector.h>
#include <batteryservice/BatteryService.h>
#include <batteryservice/IBatteryPropertiesListener.h>
@ -39,6 +40,7 @@ private:
void registerListener(const sp<IBatteryPropertiesListener>& listener);
void unregisterListener(const sp<IBatteryPropertiesListener>& listener);
status_t getProperty(int id, struct BatteryProperty *val);
status_t dump(int fd, const Vector<String16>& args);
void binderDied(const wp<IBinder>& who);
};

View File

@ -195,6 +195,11 @@ void healthd_battery_update(void) {
-1 : healthd_config.periodic_chores_interval_fast * 1000;
}
void healthd_dump_battery_state(int fd) {
gBatteryMonitor->dumpState(fd);
fsync(fd);
}
static void periodic_chores() {
healthd_battery_update();
}

View File

@ -72,6 +72,7 @@ int healthd_register_event(int fd, void (*handler)(uint32_t));
void healthd_battery_update();
android::status_t healthd_get_property(int id,
struct android::BatteryProperty *val);
void healthd_dump_battery_state(int fd);
struct healthd_mode_ops {
void (*init)(struct healthd_config *config);