我不是在谈论如何读取该值。
而是,我对如何设置BatteryManager.EXTRA_HEALTH的值感兴趣。
它来自固件吗?具体制造商?
是什么决定这些值?
int BATTERY_HEALTH_COLD
int BATTERY_HEALTH_DEAD
int BATTERY_HEALTH_GOOD
int BATTERY_HEALTH_OVERHEAT
int BATTERY_HEALTH_OVER_VOLTAGE
int BATTERY_HEALTH_UNKNOWN
int BATTERY_HEALTH_UNSPECIFIED_FAILURE
谢谢,
西蒙
最佳答案
更具体地说:电池运行状况由驱动程序(在内核中)确定。所述驱动程序通过sys文件系统(确切地说是/sys/class/power_supply)导出信息。运行状况良好的Android守护程序(从KK,4.4.x起)获取此信息,并在其上实现IBatteryPropertiesRegistrar接口(interface)。它连续轮询(使用epoll_wait在超时循环中运行以进行定期更新,以及POWER子系统的网络链接通知-例如,如果您连接或断开充电器)。然后,系统的BatteryStatsService向运行状况良好的用户(通过活页夹)注册一个监听器,然后获取运行状况良好的发布的数据,
查看/sys/class/power_supply,您将看到:
lrwxrwxrwx root root 1970-02-05 14:20 ac -> ../../devices/f9923000.i2c/i2c-84/84-006b/power_supply/ac
lrwxrwxrwx root root 1970-02-05 14:20 batt_therm -> ../../devices/battery_tm_ctrl.78/power_supply/batt_therm
lrwxrwxrwx root root 1970-02-05 14:20 battery -> ../../devices/f9923000.i2c/i2c-84/84-0036/power_supply/battery
lrwxrwxrwx root root 1970-02-05 14:20 touch -> ../../devices/virtual/power_supply/touch
lrwxrwxrwx root root 1970-02-05 14:20 usb -> ../../devices/msm_dwc3/power_supply/usb
lrwxrwxrwx root root 1970-02-05 14:20 wireless -> ../../devices/bq51013b_wlc.77/power_supply/wireless
然后检查“电池”
/sys/devices/f9923000.i2c/i2c-84/84-0036/power_supply/battery:
-r--r--r-- root root 4096 2014-02-26 13:26 capacity
-r--r--r-- root root 4096 2014-02-26 13:26 charge_full_design
-r--r--r-- root root 4096 2014-02-26 13:26 current_now
lrwxrwxrwx root root 2014-02-26 13:26 device -> ../../../84-0036
-r--r--r-- root root 4096 2014-02-26 13:26 health
drwxr-xr-x root root 2014-02-26 13:26 power
-r--r--r-- root root 4096 2014-02-26 13:26 present
-r--r--r-- root root 4096 2014-02-26 13:26 status
lrwxrwxrwx root root 2014-02-26 13:26 subsystem -> ../../../../../../class/power_supply
-r--r--r-- root root 4096 2014-02-26 13:26 technology
-r--r--r-- root root 4096 2014-02-26 13:26 temp
-r--r--r-- root root 4096 2014-02-26 13:26 type
-rw-r--r-- root root 4096 2014-02-26 13:26 uevent
-r--r--r-- root root 4096 2014-02-26 13:26 voltage_max_design
-r--r--r-- root root 4096 2014-02-26 13:26 voltage_min_design
-r--r--r-- root root 4096 2014-02-26 13:26 voltage_now
通过查看文件,将显示所有详细信息。