Provide foreground_service usage time in BatteryDiffEntry.

- Fetch foreground service info through new api from UidBatteryConsumer.
- Record fgs & bg usage time separately, combine them till ui display.

Bug: 315255868
Test: make RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.fuelgauge.*"
Change-Id: Ic19844db7908a6ae6522c7a72972f44f94dcfca4
This commit is contained in:
mxyyiyi
2023-12-07 15:23:08 +08:00
parent dd2cc366a6
commit a919306d75
19 changed files with 345 additions and 158 deletions

View File

@@ -660,36 +660,39 @@ public final class DatabaseUtils {
// Creates the ContentValues list to insert them into provider.
final List<ContentValues> valuesList = new ArrayList<>();
if (batteryEntryList != null) {
batteryEntryList.stream()
.filter(
entry -> {
final long foregroundMs = entry.getTimeInForegroundMs();
final long backgroundMs = entry.getTimeInBackgroundMs();
if (entry.getConsumedPower() == 0
&& (foregroundMs != 0 || backgroundMs != 0)) {
Log.w(
TAG,
String.format(
"no consumed power but has running time for %s"
+ " time=%d|%d",
entry.getLabel(), foregroundMs, backgroundMs));
}
return entry.getConsumedPower() != 0
|| foregroundMs != 0
|| backgroundMs != 0;
})
.forEach(
entry ->
valuesList.add(
ConvertUtils.convertBatteryEntryToContentValues(
entry,
batteryUsageStats,
batteryLevel,
batteryStatus,
batteryHealth,
snapshotBootTimestamp,
snapshotTimestamp,
isFullChargeStart)));
for (BatteryEntry entry : batteryEntryList) {
final long foregroundMs = entry.getTimeInForegroundMs();
final long foregroundServiceMs = entry.getTimeInForegroundServiceMs();
final long backgroundMs = entry.getTimeInBackgroundMs();
if (entry.getConsumedPower() == 0
&& (foregroundMs != 0 || foregroundServiceMs != 0 || backgroundMs != 0)) {
Log.w(
TAG,
String.format(
"no consumed power but has running time for %s"
+ " time=%d|%d|%d",
entry.getLabel(),
foregroundMs,
foregroundServiceMs,
backgroundMs));
}
if (entry.getConsumedPower() == 0
&& foregroundMs == 0
&& foregroundServiceMs == 0
&& backgroundMs == 0) {
continue;
}
valuesList.add(
ConvertUtils.convertBatteryEntryToContentValues(
entry,
batteryUsageStats,
batteryLevel,
batteryStatus,
batteryHealth,
snapshotBootTimestamp,
snapshotTimestamp,
isFullChargeStart));
}
}
int size = 1;