From 020369d8724eff2b87350e54e157a609846166e4 Mon Sep 17 00:00:00 2001 From: Todd Poynor Date: Wed, 18 Sep 2013 20:09:33 -0700 Subject: [PATCH] healthd: BatteryService dumpstate support Change-Id: Ia6938b7126751801310632c995af0f96e41f5f64 --- healthd/BatteryMonitor.cpp | 40 ++++++++++++++++++++++---- healthd/BatteryMonitor.h | 2 ++ healthd/BatteryPropertiesRegistrar.cpp | 16 +++++++++++ healthd/BatteryPropertiesRegistrar.h | 2 ++ healthd/healthd.cpp | 5 ++++ healthd/healthd.h | 1 + 6 files changed, 61 insertions(+), 5 deletions(-) diff --git a/healthd/BatteryMonitor.cpp b/healthd/BatteryMonitor.cpp index ffd1d349a..b7215537a 100644 --- a/healthd/BatteryMonitor.cpp +++ b/healthd/BatteryMonitor.cpp @@ -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; diff --git a/healthd/BatteryMonitor.h b/healthd/BatteryMonitor.h index f0e645455..4866cc2b8 100644 --- a/healthd/BatteryMonitor.h +++ b/healthd/BatteryMonitor.h @@ -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 mChargerNames; bool mBatteryDevicePresent; + struct BatteryProperties props; int getBatteryStatus(const char* status); int getBatteryHealth(const char* status); diff --git a/healthd/BatteryPropertiesRegistrar.cpp b/healthd/BatteryPropertiesRegistrar.cpp index f2edee434..7add9bc17 100644 --- a/healthd/BatteryPropertiesRegistrar.cpp +++ b/healthd/BatteryPropertiesRegistrar.cpp @@ -18,7 +18,10 @@ #include #include #include +#include #include +#include +#include #include #include #include @@ -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& 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& who) { Mutex::Autolock _l(mRegistrationLock); diff --git a/healthd/BatteryPropertiesRegistrar.h b/healthd/BatteryPropertiesRegistrar.h index 3e86fdf17..88538744d 100644 --- a/healthd/BatteryPropertiesRegistrar.h +++ b/healthd/BatteryPropertiesRegistrar.h @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -39,6 +40,7 @@ private: void registerListener(const sp& listener); void unregisterListener(const sp& listener); status_t getProperty(int id, struct BatteryProperty *val); + status_t dump(int fd, const Vector& args); void binderDied(const wp& who); }; diff --git a/healthd/healthd.cpp b/healthd/healthd.cpp index 66b961da5..095ce9dfc 100644 --- a/healthd/healthd.cpp +++ b/healthd/healthd.cpp @@ -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(); } diff --git a/healthd/healthd.h b/healthd/healthd.h index fb9504a85..23a54bf33 100644 --- a/healthd/healthd.h +++ b/healthd/healthd.h @@ -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);