手机电池内部带有ntc电阻,该电阻随电池温度变化而变化,根据ntc的这一特性,便可推算出电池温度,从而定制化手机行为。
ntc电路如下,R6106默认不贴,把电池扣上去后,形成了一个简易的分压电路,假设电池ntc电阻为R,则BAT_TEMP_ADC的电压为1.85*R/(R+47K),BAT_TEMP_ADC的电压可以通过cpu内部的adc电路测量出来,进入反算出电阻ntc阻值R,再根据电池ntc表,推算出电池温度。
电池高温关机
mShutdownBatteryTemperature = mContext.getResources().getInteger(
com.android.internal.R.integer.config_shutdownBatteryTemperature);
private void shutdownIfOverTempLocked() {
// shut down gracefully if temperature is too high (> 68.0C by default)
// wait until the system has booted before attempting to display the
// shutdown dialog.
if (mHealthInfo.batteryTemperature > mShutdownBatteryTemperature) {
mHandler.post(new Runnable() {
@Override
public void run() {
if (mActivityManagerInternal.isSystemReady()) {
Intent intent = new Intent(Intent.ACTION_REQUEST_SHUTDOWN);
intent.putExtra(Intent.EXTRA_KEY_CONFIRM, false);
intent.putExtra(Intent.EXTRA_REASON,
PowerManager.SHUTDOWN_BATTERY_THERMAL_STATE);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivityAsUser(intent, UserHandle.CURRENT);
}
}
});
}
}
http://aospxref.com/android-11.0.0_r21/xref/frameworks/base/core/res/res/values/config.xml
<integer name="config_shutdownBatteryTemperature">680</integer>
温度过高或者过低停止充电
以展讯平台为例,高于80°c或者低于-20°c都停止充电
cm-battery-cold = <200>;
cm-battery-cold-in-minus;
cm-battery-hot = <800>;
cm-battery-temp-diff = <100>
static int cm_check_thermal_status(struct charger_manager *cm)
{
struct charger_desc *desc = cm->desc;
int temp, upper_limit, lower_limit;
int ret = 0;
ret = cm_get_battery_temperature(cm, &temp);
if (ret) {
/* FIXME:
* No information of battery temperature might
* occur hazadous result. We have to handle it
* depending on battery type.
*/
dev_err(cm->dev, "Failed to get battery temperature\n");
return 0;
}
upper_limit = desc->temp_max;
lower_limit = desc->temp_min;
if (cm->emergency_stop) {
upper_limit -= desc->temp_diff;
lower_limit += desc->temp_diff;
}
if (temp > upper_limit)
ret = CM_EVENT_BATT_OVERHEAT;
else if (temp < lower_limit)
ret = CM_EVENT_BATT_COLD;
return ret;
}
static bool _cm_monitor(struct charger_manager *cm)
{
...
temp_alrt = cm_check_thermal_status(cm);
if (temp_alrt) {
cm->emergency_stop = temp_alrt;
dev_info(cm->dev,
"Temperature is out of range normal state, stop charging\n");
if (!try_charger_enable(cm, false))
uevent_notify(cm, default_event_names[temp_alrt]);
}
...
}