Loading healthd/BatteryMonitor.cpp +35 −5 Original line number Diff line number Diff line Loading @@ -170,7 +170,6 @@ int BatteryMonitor::getIntField(const String8& path) { } bool BatteryMonitor::update(void) { struct BatteryProperties props; struct BatteryExtraProperties extraProps; bool logthis; Loading Loading @@ -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) { Loading Loading @@ -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; Loading healthd/BatteryMonitor.h +2 −0 Original line number Diff line number Diff line Loading @@ -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); Loading healthd/BatteryPropertiesRegistrar.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -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); Loading healthd/BatteryPropertiesRegistrar.h +2 −0 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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); }; Loading healthd/healthd.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -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(); } Loading Loading
healthd/BatteryMonitor.cpp +35 −5 Original line number Diff line number Diff line Loading @@ -170,7 +170,6 @@ int BatteryMonitor::getIntField(const String8& path) { } bool BatteryMonitor::update(void) { struct BatteryProperties props; struct BatteryExtraProperties extraProps; bool logthis; Loading Loading @@ -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) { Loading Loading @@ -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; Loading
healthd/BatteryMonitor.h +2 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
healthd/BatteryPropertiesRegistrar.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -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> Loading Loading @@ -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); Loading
healthd/BatteryPropertiesRegistrar.h +2 −0 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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); }; Loading
healthd/healthd.cpp +5 −0 Original line number Diff line number Diff line Loading @@ -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(); } Loading