The Android Gingerbread battery service has a JNI interface which supports a power supply class battery driver with hardcoded attributes. However, different platforms drivers may provide different attributes, so to allow for this configurability you can add platform specific system properties like:
devices/<manuf>/<platform>/system.prop
ro.power_supply.ac.online = online ro.power_supply.usb.online is not supported ro.power_supply.bat.status = status ro.power_supply.bat.health is not supported ro.power_supply.bat.present = present ro.power_supply.bat.capacity = capacity ro.power_supply.bat.voltage_now = voltage_avg ro.power_supply.bat.temperature is not supported ro.power_supply.bat.technology = technology
And then you retrive and use each of the properties, for example.
property_get("ro.power_supply.ac.online", value, ""); snprintf(path, sizeof(path), "%s/%s/%s", POWER_SUPPLY_PATH, name,value);
For the battery status to be updated by the Battery Service, it needs to receive a uevent from the Linux kernel driver. Verify that your battery driver does something like:
if( bat_status_old != bat_status.status ) power_supply_changed(&chg_device->psy); bat_status_old = bat_status.status
At least on the status and capacity update functions.
The battery data is dumped into /data/system/batterystats.bin, a binary file that can be dumped using dumpsys.
$~ adb shell dumpsys battery
Current Battery Service state:
AC powered: false
AC capacity: 500000
USB powered: true
status: 5
health: 2
present: true
level: 100
scale: 100
voltage:4201
temperature: 271
technology: Li-pol
Your app would need android.permission.DUMP to execute dumpsys.
Post a Comment