手机电池内部带有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);
}
}
});
}
}

最低0.47元/天 解锁文章
1383





