[Battery usage U] Add an item "Others" in the app list to group small usage apps. This will make the total percetage 100%, which is easy to understand for users.

Bug: 258124173
Fix: 258124173
Test: manual
Change-Id: I5965eeb73a2071c4a9994655e4ed24ec3adf64e8
This commit is contained in:
Zaiyue Xue
2023-01-04 17:09:09 +08:00
parent 1c8455dfea
commit 7c987c9d98
5 changed files with 81 additions and 0 deletions

View File

@@ -1719,6 +1719,7 @@ public final class DataProcessor {
batteryDiffData.setTotalConsumePower();
batteryDiffData.sortEntries();
combineIntoSystemApps(context, batteryDiffData);
combineSystemItemsIntoOthers(context, batteryDiffData);
});
});
}
@@ -1744,6 +1745,33 @@ public final class DataProcessor {
}
}
private static void combineSystemItemsIntoOthers(
final Context context, final BatteryDiffData batteryDiffData) {
final Set<Integer> othersSystemComponentSet =
FeatureFactory.getFactory(context)
.getPowerUsageFeatureProvider(context)
.getOthersSystemComponentSet(context);
BatteryDiffEntry.OthersBatteryDiffEntry othersDiffEntry = null;
final Iterator<BatteryDiffEntry> systemListIterator =
batteryDiffData.getSystemDiffEntryList().iterator();
while (systemListIterator.hasNext()) {
final BatteryDiffEntry batteryDiffEntry = systemListIterator.next();
if (othersSystemComponentSet.contains(batteryDiffEntry.mBatteryHistEntry.mDrainType)) {
if (othersDiffEntry == null) {
othersDiffEntry = new BatteryDiffEntry.OthersBatteryDiffEntry(context);
}
othersDiffEntry.mConsumePower += batteryDiffEntry.mConsumePower;
othersDiffEntry.setTotalConsumePower(
batteryDiffEntry.getTotalConsumePower());
systemListIterator.remove();
}
}
if (othersDiffEntry != null) {
batteryDiffData.getSystemDiffEntryList().add(othersDiffEntry);
}
}
private static void combineIntoSystemApps(
final Context context, final BatteryDiffData batteryDiffData) {
final List<String> systemAppsAllowlist =