代码路径在包/应用/设置/ SRC / COM /机器人/设置/ fuelgauge / PowerUsageSummary.java
每次进这个界面都会走refreshUi(),看里面的实现发现averagePower一直返回0.1,不管你电池用了多久。所以下面的代码都不会走,就不会显示应用程序用电量。
protected void refreshUi() {
final Context context = getContext();
if (context == null) {
return;
}
cacheRemoveAllPrefs(mAppListGroup);
mAppListGroup.setOrderingAsAdded(false);
boolean addedSome = false;
final PowerProfile powerProfile = mStatsHelper.getPowerProfile();
final BatteryStats stats = mStatsHelper.getStats();
final double averagePower = powerProfile.getAveragePower(PowerProfile.POWER_SCREEN_FULL);
final long elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000;
Intent batteryBroadcast = context.registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
BatteryInfo batteryInfo = BatteryInfo.getBatteryInfo(context, batteryBroadcast,
mStatsHelper.getStats(), elapsedRealtimeUs, false);
mBatteryHeaderPreferenceController.updateHeaderPreference(batteryInfo);
final TypedValue value = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.colorControlNormal, value, true);
final int colorControl = context.getColor(value.resourceId);
final int dischargeAmount = USE_FAKE_DATA ? 5000
: stats != null ? stats.getDischargeAmount(mStatsType) : 0;
final long lastFullChargeTime = mBatteryUtils.calculateLastFullChargeTime(mStatsHelper,
System.currentTimeMillis());
updateScreenPreference();
updateLastFullChargePreference(lastFullChargeTime);
final CharSequence timeSequence = Utils.formatElapsedTime(context, lastFullChargeTime,
false);
final int resId = mShowAllApps ? R.string.power_usage_list_summary_device
: R.string.power_usage_list_summary;
mAppListGroup.setTitle(TextUtils.expandTemplate(getText(resId), timeSequence));
if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
final List<BatterySipper> usageList = getCoalescedUsageList(
USE_FAKE_DATA ? getFakeStats() : mStatsHelper.getUsageList());