Android电池的健康状况如何确定?

时间:2012-04-11 02:13:30

标签: android power-management

我不是在谈论如何阅读价值。

相反,我对如何设置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

谢谢, 西蒙

3 个答案:

答案 0 :(得分:6)

更具体一点:电池运行状况由驱动程序(在内核中)决定。所述驱动程序通过sys文件系统导出信息(确切地说是/ sys / class / power_supply)。 Android守护程序healthd(从KK开始,4.4.x)获取此信息,并在其上实现IBatteryPropertiesRegistrar接口。它持续轮询(使用epoll_wait在超时循环中运行以进行定期更新,以及POWER子系统的netlink通知 - 例如,如果连接或断开充电器)。然后系统的BatteryStatsService注册一个带有healthd的监听器(通过binder),然后获取healthd发布的数据,

查看/ 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

通过查看文件,将显示所有详细信息。

答案 1 :(得分:5)

使用此代码,您可以获得有关电池的信息..

private BroadcastReceiver battery_receiver = new BroadcastReceiver()
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        boolean isPresent = intent.getBooleanExtra("present", false);
        String technology = intent.getStringExtra("technology");
        int plugged = intent.getIntExtra("plugged", -1);
        int scale = intent.getIntExtra("scale", -1);
        int health = intent.getIntExtra("health", 0);
        int status = intent.getIntExtra("status", 0);
        int rawlevel = intent.getIntExtra("level", -1);
        int level = 0;
        String temp=null;

        Bundle bundle = intent.getExtras();

        Log.i("BatteryLevel", bundle.toString());

        if(isPresent)
        {
            if (rawlevel >= 0 && scale > 0) {
                level = (rawlevel * 100) / scale;
            }

            String info = "Battery Level: " + level + "%\n";

            info += ("Technology: " + technology + "\n");
            info += ("Plugged: " + getPlugTypeString(plugged) + "\n");
            info += ("Health: " + getHealthString(health) + "\n");
            info += ("Status: " + getStatusString(status) + "\n");
            info += ("Temp: "+getTempStatus(temp,intent)+"\n");

            setBatteryLevelText(info + "\n\n" + bundle.toString());
        }
        else
        {
            setBatteryLevelText("Battery not present!!!");
        }
    }
};
private void registerBatteryLevelReceiver(){
    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);

    registerReceiver(battery_receiver, filter);
}

答案 2 :(得分:3)

锂离子电池具有简单的车载计算机,可跟踪和报告健康状况;状态指示器是标准化的,但触发它们由电池报告的条件由电池制造商确定。