Android手機提示正在慢速充電的解決方法
阿新 • • 發佈:2021-01-31
技術標籤:ANDROID
新的專案,手機充電的時候,systemui顯示慢速充電。
通過電流計測量,充電電流為1.7A,電壓5v,這個功率還挺高的,怎麼就提示慢速充電了呢。
protected String computePowerIndication() { if (mPowerCharged) { return mContext.getResources().getString(R.string.keyguard_charged); } final boolean hasChargingTime = mChargingTimeRemaining > 0; int chargingId; if (mPowerPluggedInWired) { switch (mChargingSpeed) { case BatteryStatus.CHARGING_FAST: chargingId = hasChargingTime ? R.string.keyguard_indication_charging_time_fast : R.string.keyguard_plugged_in_charging_fast; break; case 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; } } else { chargingId = hasChargingTime ? R.string.keyguard_indication_charging_time_wireless : R.string.keyguard_plugged_in_wireless; }
mChargingSpeed = status.getChargingSpeed(mContext);
public final int getChargingSpeed(Context context) { final int slowThreshold = context.getResources().getInteger( R.integer.config_chargingSlowlyThreshold); final int fastThreshold = context.getResources().getInteger( R.integer.config_chargingFastThreshold); return maxChargingWattage <= 0 ? CHARGING_UNKNOWN : maxChargingWattage < slowThreshold ? CHARGING_SLOWLY : maxChargingWattage > fastThreshold ? CHARGING_FAST : CHARGING_REGULAR; }
public BatteryStatus(Intent batteryChangedIntent) { status = batteryChangedIntent.getIntExtra(EXTRA_STATUS, BATTERY_STATUS_UNKNOWN); plugged = batteryChangedIntent.getIntExtra(EXTRA_PLUGGED, 0); level = batteryChangedIntent.getIntExtra(EXTRA_LEVEL, 0); health = batteryChangedIntent.getIntExtra(EXTRA_HEALTH, BATTERY_HEALTH_UNKNOWN); final int maxChargingMicroAmp = batteryChangedIntent.getIntExtra(EXTRA_MAX_CHARGING_CURRENT, -1); int maxChargingMicroVolt = batteryChangedIntent.getIntExtra(EXTRA_MAX_CHARGING_VOLTAGE, -1); 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. maxChargingWattage = (maxChargingMicroAmp / 1000) * (maxChargingMicroVolt / 1000); } else { maxChargingWattage = -1; } }
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Threshold in micro watts below which a charger is rated as "slow"; 1A @ 5V -->
<integer name="config_chargingSlowlyThreshold">5000000</integer>
<!-- Threshold in micro watts above which a charger is rated as "fast"; 1.5A @ 5V -->
<integer name="config_chargingFastThreshold">7500000</integer>
</resources>
也就是低於5w顯示慢速充電,高於7.5w顯示快速充電,大於5w而小於7.5w顯示正在充電。
當然分析的是Android原生程式碼,mtk應該對這一塊作了定製,要下週到公司look下原始碼了。