summaryrefslogtreecommitdiffstats
path: root/healthd
diff options
context:
space:
mode:
authorTodd Poynor <toddpoynor@google.com>2013-09-18 20:09:33 -0700
committerTodd Poynor <toddpoynor@google.com>2013-10-22 16:32:54 -0700
commit020369d8724eff2b87350e54e157a609846166e4 (patch)
tree57eed3999a23125cfc1666b4c1c6305b36f10bb3 /healthd
parent6dcc45ed6dd455d82ecfb3addf247125846f3019 (diff)
downloadsystem_core-020369d8724eff2b87350e54e157a609846166e4.tar.gz
system_core-020369d8724eff2b87350e54e157a609846166e4.tar.bz2
system_core-020369d8724eff2b87350e54e157a609846166e4.zip
healthd: BatteryService dumpstate support
Change-Id: Ia6938b7126751801310632c995af0f96e41f5f64
Diffstat (limited to 'healthd')
-rw-r--r--healthd/BatteryMonitor.cpp40
-rw-r--r--healthd/BatteryMonitor.h2
-rw-r--r--healthd/BatteryPropertiesRegistrar.cpp16
-rw-r--r--healthd/BatteryPropertiesRegistrar.h2
-rw-r--r--healthd/healthd.cpp5
-rw-r--r--healthd/healthd.h1
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<String8> 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 <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);
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 <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);
};
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);