Refactor processBatteryDiffData() from DataProcessor to BatteryDiffData class.

So that only hourly battery diff data needs purgeFakeAndHiddenPackages()
and combineBatteryDiffEntry(). This is also easy to set hourly threshold
in the next cl.

Bug: 264840285
Test: manual
Change-Id: Ie0bc6d53f96285285019dd83c1f39305eca79c71
This commit is contained in:
Zaiyue Xue
2023-01-09 17:04:57 +08:00
parent 7f3ff17bcf
commit f080429ddb
6 changed files with 387 additions and 276 deletions

View File

@@ -49,7 +49,7 @@ public class BatteryDiffEntry {
/** A comparator for {@link BatteryDiffEntry} based on consumed percentage. */
public static final Comparator<BatteryDiffEntry> COMPARATOR =
(a, b) -> Double.compare(b.getPercentOfTotal(), a.getPercentOfTotal());
(a, b) -> Double.compare(b.getSortingKey(), a.getSortingKey());
public long mForegroundUsageTimeInMs;
public long mBackgroundUsageTimeInMs;
@@ -121,6 +121,11 @@ public class BatteryDiffEntry {
return mPercentOfTotal;
}
/** Gets the key for sorting */
public double getSortingKey() {
return getPercentOfTotal();
}
/** Clones a new instance. */
public BatteryDiffEntry clone() {
return new BatteryDiffEntry(
@@ -265,7 +270,6 @@ public class BatteryDiffEntry {
}
}
@VisibleForTesting
String getKey() {
return mBatteryHistEntry.getKey();
}
@@ -434,6 +438,26 @@ public class BatteryDiffEntry {
public boolean isSystemEntry() {
return false;
}
@Override
public double getSortingKey() {
// Always on the bottom of the app list.
return -1;
}
@Override
public BatteryDiffEntry clone() {
SystemAppsBatteryDiffEntry newEntry = new SystemAppsBatteryDiffEntry(this.mContext);
newEntry.mForegroundUsageTimeInMs = this.mForegroundUsageTimeInMs;
newEntry.mBackgroundUsageTimeInMs = this.mBackgroundUsageTimeInMs;
newEntry.mScreenOnTimeInMs = this.mScreenOnTimeInMs;
newEntry.mConsumePower = this.mConsumePower;
newEntry.mForegroundUsageConsumePower = this.mForegroundUsageConsumePower;
newEntry.mForegroundServiceUsageConsumePower = this.mForegroundServiceUsageConsumePower;
newEntry.mBackgroundUsageConsumePower = this.mBackgroundUsageConsumePower;
newEntry.mCachedUsageConsumePower = this.mCachedUsageConsumePower;
return newEntry;
}
}
/** Specific battery diff entry for others. */
@@ -475,5 +499,25 @@ public class BatteryDiffEntry {
public boolean isSystemEntry() {
return true;
}
@Override
public double getSortingKey() {
// Always on the bottom of the system list.
return -1;
}
@Override
public BatteryDiffEntry clone() {
OthersBatteryDiffEntry newEntry = new OthersBatteryDiffEntry(this.mContext);
newEntry.mForegroundUsageTimeInMs = this.mForegroundUsageTimeInMs;
newEntry.mBackgroundUsageTimeInMs = this.mBackgroundUsageTimeInMs;
newEntry.mScreenOnTimeInMs = this.mScreenOnTimeInMs;
newEntry.mConsumePower = this.mConsumePower;
newEntry.mForegroundUsageConsumePower = this.mForegroundUsageConsumePower;
newEntry.mForegroundServiceUsageConsumePower = this.mForegroundServiceUsageConsumePower;
newEntry.mBackgroundUsageConsumePower = this.mBackgroundUsageConsumePower;
newEntry.mCachedUsageConsumePower = this.mCachedUsageConsumePower;
return newEntry;
}
}
}