Populate new fields foreground_service_usage_time_in_ms,
foreground_usage_consume_power, foreground_service_usage_consume_power, background_usage_consume_power and cached_usage_consume_power into database and pass them to UI. Test: make RunSettingsRoboTests + manual Bug: 256123455 Bug: 258124768 Change-Id: Ic46032f67eff5898f9d4182c517bbebe478eca01
This commit is contained in:
@@ -87,9 +87,6 @@ public final class DataProcessor {
|
||||
@VisibleForTesting
|
||||
static final int SELECTED_INDEX_ALL = BatteryChartViewModel.SELECTED_INDEX_ALL;
|
||||
|
||||
/** A fake package name to represent no BatteryEntry data. */
|
||||
public static final String FAKE_PACKAGE_NAME = "fake_package";
|
||||
|
||||
/** A callback listener when battery usage loading async task is executed. */
|
||||
public interface UsageMapAsyncResponse {
|
||||
/** The callback function when batteryUsageMap is loaded. */
|
||||
@@ -174,7 +171,11 @@ public final class DataProcessor {
|
||||
@Nullable
|
||||
public static BatteryUsageStats getBatteryUsageStats(final Context context) {
|
||||
final BatteryUsageStatsQuery batteryUsageStatsQuery =
|
||||
new BatteryUsageStatsQuery.Builder().includeBatteryHistory().build();
|
||||
new BatteryUsageStatsQuery
|
||||
.Builder()
|
||||
.includeBatteryHistory()
|
||||
.includeProcessStateData()
|
||||
.build();
|
||||
return context.getSystemService(BatteryStatsManager.class)
|
||||
.getBatteryUsageStats(batteryUsageStatsQuery);
|
||||
}
|
||||
@@ -478,8 +479,13 @@ public final class DataProcessor {
|
||||
final BatteryDiffEntry currentBatteryDiffEntry = new BatteryDiffEntry(
|
||||
context,
|
||||
entry.mForegroundUsageTimeInMs,
|
||||
entry.mForegroundServiceUsageTimeInMs,
|
||||
entry.mBackgroundUsageTimeInMs,
|
||||
entry.mConsumePower,
|
||||
entry.mForegroundUsageConsumePower,
|
||||
entry.mForegroundServiceUsageConsumePower,
|
||||
entry.mBackgroundUsageConsumePower,
|
||||
entry.mCachedUsageConsumePower,
|
||||
entry);
|
||||
if (currentBatteryDiffEntry.isSystemEntry()) {
|
||||
systemEntries.add(currentBatteryDiffEntry);
|
||||
@@ -567,10 +573,12 @@ public final class DataProcessor {
|
||||
return batteryEntryList.stream()
|
||||
.filter(entry -> {
|
||||
final long foregroundMs = entry.getTimeInForegroundMs();
|
||||
final long foregroundServiceMs = entry.getTimeInForegroundServiceMs();
|
||||
final long backgroundMs = entry.getTimeInBackgroundMs();
|
||||
return entry.getConsumedPower() > 0
|
||||
|| (entry.getConsumedPower() == 0
|
||||
&& (foregroundMs != 0 || backgroundMs != 0));
|
||||
&& (foregroundMs != 0 || foregroundServiceMs != 0
|
||||
|| backgroundMs != 0));
|
||||
})
|
||||
.map(entry -> ConvertUtils.convertToBatteryHistEntry(
|
||||
entry,
|
||||
@@ -691,9 +699,14 @@ public final class DataProcessor {
|
||||
if (lowerEntry != null) {
|
||||
final boolean invalidForegroundUsageTime =
|
||||
lowerEntry.mForegroundUsageTimeInMs > upperEntry.mForegroundUsageTimeInMs;
|
||||
final boolean invalidForegroundServiceUsageTime =
|
||||
lowerEntry.mForegroundServiceUsageTimeInMs
|
||||
> upperEntry.mForegroundServiceUsageTimeInMs;
|
||||
final boolean invalidBackgroundUsageTime =
|
||||
lowerEntry.mBackgroundUsageTimeInMs > upperEntry.mBackgroundUsageTimeInMs;
|
||||
if (invalidForegroundUsageTime || invalidBackgroundUsageTime) {
|
||||
if (invalidForegroundUsageTime
|
||||
|| invalidForegroundServiceUsageTime
|
||||
|| invalidBackgroundUsageTime) {
|
||||
newHistEntryMap.put(entryKey, upperEntry);
|
||||
log(context, "abnormal reset condition is found", currentSlot, upperEntry);
|
||||
continue;
|
||||
@@ -924,6 +937,11 @@ public final class DataProcessor {
|
||||
currentEntry.mForegroundUsageTimeInMs,
|
||||
nextEntry.mForegroundUsageTimeInMs,
|
||||
nextTwoEntry.mForegroundUsageTimeInMs);
|
||||
long foregroundServiceUsageTimeInMs =
|
||||
getDiffValue(
|
||||
currentEntry.mForegroundServiceUsageTimeInMs,
|
||||
nextEntry.mForegroundServiceUsageTimeInMs,
|
||||
nextTwoEntry.mForegroundServiceUsageTimeInMs);
|
||||
long backgroundUsageTimeInMs =
|
||||
getDiffValue(
|
||||
currentEntry.mBackgroundUsageTimeInMs,
|
||||
@@ -934,8 +952,29 @@ public final class DataProcessor {
|
||||
currentEntry.mConsumePower,
|
||||
nextEntry.mConsumePower,
|
||||
nextTwoEntry.mConsumePower);
|
||||
double foregroundUsageConsumePower =
|
||||
getDiffValue(
|
||||
currentEntry.mForegroundUsageConsumePower,
|
||||
nextEntry.mForegroundUsageConsumePower,
|
||||
nextTwoEntry.mForegroundUsageConsumePower);
|
||||
double foregroundServiceUsageConsumePower =
|
||||
getDiffValue(
|
||||
currentEntry.mForegroundServiceUsageConsumePower,
|
||||
nextEntry.mForegroundServiceUsageConsumePower,
|
||||
nextTwoEntry.mForegroundServiceUsageConsumePower);
|
||||
double backgroundUsageConsumePower =
|
||||
getDiffValue(
|
||||
currentEntry.mBackgroundUsageConsumePower,
|
||||
nextEntry.mBackgroundUsageConsumePower,
|
||||
nextTwoEntry.mBackgroundUsageConsumePower);
|
||||
double cachedUsageConsumePower =
|
||||
getDiffValue(
|
||||
currentEntry.mCachedUsageConsumePower,
|
||||
nextEntry.mCachedUsageConsumePower,
|
||||
nextTwoEntry.mCachedUsageConsumePower);
|
||||
// Excludes entry since we don't have enough data to calculate.
|
||||
if (foregroundUsageTimeInMs == 0
|
||||
&& foregroundServiceUsageTimeInMs == 0
|
||||
&& backgroundUsageTimeInMs == 0
|
||||
&& consumePower == 0) {
|
||||
continue;
|
||||
@@ -947,6 +986,7 @@ public final class DataProcessor {
|
||||
}
|
||||
// Forces refine the cumulative value since it may introduce deviation error since we
|
||||
// will apply the interpolation arithmetic.
|
||||
// TODO: update this value after the new API for foreground service is completed.
|
||||
final float totalUsageTimeInMs =
|
||||
foregroundUsageTimeInMs + backgroundUsageTimeInMs;
|
||||
if (totalUsageTimeInMs > TOTAL_HOURLY_TIME_THRESHOLD) {
|
||||
@@ -959,9 +999,15 @@ public final class DataProcessor {
|
||||
}
|
||||
foregroundUsageTimeInMs =
|
||||
Math.round(foregroundUsageTimeInMs * ratio);
|
||||
foregroundServiceUsageTimeInMs =
|
||||
Math.round(foregroundServiceUsageTimeInMs * ratio);
|
||||
backgroundUsageTimeInMs =
|
||||
Math.round(backgroundUsageTimeInMs * ratio);
|
||||
consumePower = consumePower * ratio;
|
||||
foregroundUsageConsumePower = foregroundUsageConsumePower * ratio;
|
||||
foregroundServiceUsageConsumePower = foregroundServiceUsageConsumePower * ratio;
|
||||
backgroundUsageConsumePower = backgroundUsageConsumePower * ratio;
|
||||
cachedUsageConsumePower = cachedUsageConsumePower * ratio;
|
||||
}
|
||||
totalConsumePower += consumePower;
|
||||
|
||||
@@ -973,8 +1019,13 @@ public final class DataProcessor {
|
||||
final BatteryDiffEntry currentBatteryDiffEntry = new BatteryDiffEntry(
|
||||
context,
|
||||
foregroundUsageTimeInMs,
|
||||
foregroundServiceUsageTimeInMs,
|
||||
backgroundUsageTimeInMs,
|
||||
consumePower,
|
||||
foregroundUsageConsumePower,
|
||||
foregroundServiceUsageConsumePower,
|
||||
backgroundUsageConsumePower,
|
||||
cachedUsageConsumePower,
|
||||
selectedBatteryEntry);
|
||||
if (currentBatteryDiffEntry.isSystemEntry()) {
|
||||
systemEntries.add(currentBatteryDiffEntry);
|
||||
@@ -1054,9 +1105,16 @@ public final class DataProcessor {
|
||||
// Sums up some field data into the existing one.
|
||||
oldBatteryDiffEntry.mForegroundUsageTimeInMs +=
|
||||
entry.mForegroundUsageTimeInMs;
|
||||
oldBatteryDiffEntry.mForegroundServiceUsageTimeInMs +=
|
||||
entry.mForegroundServiceUsageTimeInMs;
|
||||
oldBatteryDiffEntry.mBackgroundUsageTimeInMs +=
|
||||
entry.mBackgroundUsageTimeInMs;
|
||||
oldBatteryDiffEntry.mConsumePower += entry.mConsumePower;
|
||||
oldBatteryDiffEntry.mForegroundUsageConsumePower += entry.mForegroundUsageConsumePower;
|
||||
oldBatteryDiffEntry.mForegroundServiceUsageConsumePower
|
||||
+= entry.mForegroundServiceUsageConsumePower;
|
||||
oldBatteryDiffEntry.mBackgroundUsageConsumePower += entry.mBackgroundUsageConsumePower;
|
||||
oldBatteryDiffEntry.mCachedUsageConsumePower += entry.mCachedUsageConsumePower;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1097,7 +1155,7 @@ public final class DataProcessor {
|
||||
final BatteryDiffEntry entry = iterator.next();
|
||||
final String packageName = entry.getPackageName();
|
||||
if (entry.getPercentOfTotal() < PERCENTAGE_OF_TOTAL_THRESHOLD
|
||||
|| FAKE_PACKAGE_NAME.equals(packageName)
|
||||
|| ConvertUtils.FAKE_PACKAGE_NAME.equals(packageName)
|
||||
|| contains(packageName, notAllowShowEntryPackages)) {
|
||||
iterator.remove();
|
||||
}
|
||||
@@ -1346,8 +1404,13 @@ public final class DataProcessor {
|
||||
final BatteryDiffEntry batteryDiffEntry = new BatteryDiffEntry(
|
||||
context,
|
||||
/*foregroundUsageTimeInMs=*/ 0,
|
||||
/*foregroundServiceUsageTimeInMs=*/ 0,
|
||||
/*backgroundUsageTimeInMs=*/ 0,
|
||||
consumePower,
|
||||
/*foregroundUsageConsumePower=*/ 0,
|
||||
/*foregroundServiceUsageConsumePower=*/ 0,
|
||||
/*backgroundUsageConsumePower=*/ 0,
|
||||
/*cachedUsageConsumePower=*/ 0,
|
||||
new BatteryHistEntry(values));
|
||||
return batteryDiffEntry;
|
||||
}
|
||||
|
Reference in New Issue
Block a user