Android 8.0 慢充和快充提示語(yǔ)的實(shí)現(xiàn)原理
1. 慢充和快充提示語(yǔ)
\frameworks\base\packages\SystemUI\res-keyguard\values-zh-rCN
中文提示語(yǔ)
<string name="keyguard_plugged_in" msgid="89308975354638682">"正在充電"</string> <string name="keyguard_plugged_in_charging_fast" msgid="8869226755413795173">"正在快速充電"</string> <string name="keyguard_plugged_in_charging_slowly" msgid="6637043106038550407">"正在慢速充電"</string>
英文提示語(yǔ)
\frameworks\base\packages\SystemUI\res-keyguard\values
1.快充充電器充電-顯示快速充電字符串
<!-- When the lock screen is showing and the phone plugged in, and the battery is not fully charged, and it's plugged into a fast charger, say that it's charging fast. --> <string name="keyguard_plugged_in_charging_fast">Charging rapidly</string>
2.普通充電電器-顯示充電,該同7.0及其以前特性
<!-- When the lock screen is showing and the phone plugged in, and the battery is not fully charged, say that it's charging. --> <string name="keyguard_plugged_in">Charging</string>
3.電腦端或者筆記本端顯示-緩慢充電
<!-- When the lock screen is showing and the phone plugged in, and the battery is not fully charged, and it's plugged into a slow charger, say that it's charging slowly. --> <string name="keyguard_plugged_in_charging_slowly">Charging slowly</string>
2. 原理
根據(jù)當(dāng)前的最大電壓和電流計(jì)算出電流速度,并進(jìn)行分類為慢速充電,充電,快速充電
2.1 源代碼中的原始數(shù)據(jù)
•public static final String EXTRA_MAX_CHARGING_CURRENT = “max_charging_current”; •public static final String EXTRA_MAX_CHARGING_VOLTAGE = “max_charging_voltage”;
發(fā)送“電池廣播”位置將最大電流和電壓上發(fā)應(yīng)用層,這里主要一些8.1以上新增的數(shù)據(jù),7.0以前有這個(gè)數(shù)據(jù)但是framework層沒(méi)有使用
frameworks/base/services/core/java/com/android/server/BatteryService.java // 發(fā)送電池廣播事件 private void sendIntentLocked() { // Pack up the values and broadcast them to everyone final Intent intent = new Intent(Intent.ACTION_BATTERY_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY | Intent.FLAG_RECEIVER_REPLACE_PENDING); ....... intent.putExtra(BatteryManager.EXTRA_MAX_CHARGING_CURRENT, mBatteryProps.maxChargingCurrent); intent.putExtra(BatteryManager.EXTRA_MAX_CHARGING_VOLTAGE, mBatteryProps.maxChargingVoltage);
2.2 adb shell 查看linux的文件節(jié)點(diǎn)
•獲取當(dāng)前的電流
adb shell cat /sys/class/power_supply/battery/current_max adb shell cat /sys/class/power_supply/battery/current_max 30000001
•獲取當(dāng)前的電壓
adb shell cat /sys/class/power_supply/battery/voltage_max adb shell cat /sys/class/power_supply/battery/voltage_max 50000001
•具體源碼
system/core/healthd/BatteryMonitor.cpp #define POWER_SUPPLY_SYSFS_PATH "/sys/class/" POWER_SUPPLY_SUBSYSTEM path.appendFormat("%s/%s/voltage_max", POWER_SUPPLY_SYSFS_PATH,mChargerNames[i].string());
2.3 上層接收廣播
frameworks/base/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java
重點(diǎn)看 maxChargingMicroAmp 和 maxChargingMicroVolt 的算法規(guī)則
private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { .... } else if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { final int status = intent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN); final int plugged = intent.getIntExtra(EXTRA_PLUGGED, 0); final int level = intent.getIntExtra(EXTRA_LEVEL, 0); final int health = intent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN); final int maxChargingMicroAmp = intent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1); int maxChargingMicroVolt = intent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1); final int maxChargingMicroWatt; if (maxChargingMicroVolt <= 0) { maxChargingMicroVolt = DEFAULT_CHARGING_VOLTAGE_MICRO_VOLT; } if (maxChargingMicroAmp > 0) { // Calculating muW = muA * muV / (10^6 mu^2 / mu); splitting up the divisor // to maintain precision equally on both factors. maxChargingMicroWatt = (maxChargingMicroAmp / 1000) * (maxChargingMicroVolt / 1000); } else { maxChargingMicroWatt = -1; } final Message msg = mHandler.obtainMessage( MSG_BATTERY_UPDATE, new BatteryStatus(status, level, plugged, health, maxChargingMicroWatt)); mHandler.sendMessage(msg);
2.4 顯示字符串
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java
事件接收
protected class BaseKeyguardCallback extends KeyguardUpdateMonitorCallback { public static final int HIDE_DELAY_MS = 5000; private int mLastSuccessiveErrorMessage = -1; @Override public void onRefreshBatteryInfo(KeyguardUpdateMonitor.BatteryStatus status) { boolean isChargingOrFull = status.status == BatteryManager.BATTERY_STATUS_CHARGING || status.status == BatteryManager.BATTERY_STATUS_FULL; boolean wasPluggedIn = mPowerPluggedIn; mPowerPluggedIn = status.isPluggedIn() && isChargingOrFull; mPowerCharged = status.isCharged(); mChargingWattage = status.maxChargingWattage; mChargingSpeed = status.getChargingSpeed(mSlowThreshold, mFastThreshold); updateIndication(); if (mDozing) { if (!wasPluggedIn && mPowerPluggedIn) { showTransientIndication(computePowerIndication()); hideTransientIndicationDelayed(HIDE_DELAY_MS); } else if (wasPluggedIn && !mPowerPluggedIn) { hideTransientIndication(); } } } ===================================================================================================== public static class BatteryStatus { public static final int CHARGING_UNKNOWN = -1; public static final int CHARGING_SLOWLY = 0; public static final int CHARGING_REGULAR = 1; public static final int CHARGING_FAST = 2; public final int status; public final int level; public final int plugged; public final int health; public final int maxChargingWattage; public BatteryStatus(int status, int level, int plugged, int health, int maxChargingWattage) { this.status = status; this.level = level; this.plugged = plugged; this.health = health; this.maxChargingWattage = maxChargingWattage; } public final int getChargingSpeed(int slowThreshold, int fastThreshold) { return maxChargingWattage <= 0 ? CHARGING_UNKNOWN : maxChargingWattage < slowThreshold ? CHARGING_SLOWLY : maxChargingWattage > fastThreshold ? CHARGING_FAST : CHARGING_REGULAR; }
顯示字符串
frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java int chargingId; switch (mChargingSpeed) { case KeyguardUpdateMonitor.BatteryStatus.CHARGING_FAST: chargingId = hasChargingTime ? R.string.keyguard_indication_charging_time_fast : R.string.keyguard_plugged_in_charging_fast; break; case KeyguardUpdateMonitor.BatteryStatus.CHARGING_SLOWLY: chargingId = hasChargingTime ? R.string.keyguard_indication_charging_time_slowly : R.string.keyguard_plugged_in_charging_slowly; break; default: chargingId = hasChargingTime ? R.string.keyguard_indication_charging_time : R.string.keyguard_plugged_in; break; }
總結(jié)
以上所述是小編給大家介紹的Android 8.0 慢充和快充提示語(yǔ)的實(shí)現(xiàn)原理,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
android圖片文件的路徑地址與Uri的相互轉(zhuǎn)換方法
下面小編就為大家?guī)?lái)一篇android圖片文件的路徑地址與Uri的相互轉(zhuǎn)換方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-04-04Android ListView UI組件使用說(shuō)明
這篇文章主要介紹了Android ListView UI組件使用說(shuō)明,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04Flutter學(xué)習(xí)之實(shí)現(xiàn)自定義themes詳解
一般情況下我們?cè)趂lutter中搭建的app基本上都是用的是MaterialApp這種設(shè)計(jì)模式,MaterialApp中為我們接下來(lái)使用的按鈕,菜單等提供了統(tǒng)一的樣式,那么這種樣式能不能進(jìn)行修改或者自定義呢?答案是肯定的,一起來(lái)看看吧2023-03-03Android編程之界面跳動(dòng)提示動(dòng)畫(huà)效果實(shí)現(xiàn)方法
這篇文章主要介紹了Android編程之界面跳動(dòng)提示動(dòng)畫(huà)效果實(shí)現(xiàn)方法,實(shí)例分析了Android動(dòng)畫(huà)效果的布局及功能相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11viewpager實(shí)現(xiàn)自動(dòng)循環(huán)輪播圖
這篇文章主要為大家詳細(xì)介紹了viewpager實(shí)現(xiàn)自動(dòng)循環(huán)輪播圖,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-01-01Android簡(jiǎn)單記錄和恢復(fù)ListView滾動(dòng)位置的方法
這篇文章主要介紹了Android簡(jiǎn)單記錄和恢復(fù)ListView滾動(dòng)位置的方法,涉及Android針對(duì)ListView位置屬性的相關(guān)操作技巧,需要的朋友可以參考下2016-08-08react native中的聊天氣泡及timer封裝成的發(fā)送驗(yàn)證碼倒計(jì)時(shí)
這篇文章主要介紹了react native中的聊天氣泡及timer封裝成的發(fā)送驗(yàn)證碼倒計(jì)時(shí)的相關(guān)資料,需要的朋友可以參考下2017-08-08Android實(shí)現(xiàn)編程修改手機(jī)靜態(tài)IP的方法
這篇文章主要介紹了Android實(shí)現(xiàn)編程修改手機(jī)靜態(tài)IP的方法,涉及Android編程實(shí)現(xiàn)對(duì)系統(tǒng)底層信息修改的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10