[Battery usage U] [UI] Add a threshold to filter out very small battery usage items in the app list

Bug: 264840285
Fix: 264840285
Test: manual
Change-Id: I36a6c0dc284d09efcf82316db1541d289c37b16f
This commit is contained in:
Zaiyue Xue
2023-01-10 15:21:50 +08:00
parent 6b47dd97dd
commit 4ecf42f1bb
4 changed files with 39 additions and 20 deletions

View File

@@ -35,6 +35,11 @@ public interface PowerUsageFeatureProvider {
*/
boolean isBatteryUsageEnabled();
/**
* Returns a threshold (mA) for the minimal comsume power in battery usage list
*/
double getBatteryUsageListConsumePowerThreshold();
/**
* Returns an allowlist of app names combined into the system-apps item
*/
@@ -46,7 +51,7 @@ public interface PowerUsageFeatureProvider {
boolean isLocationSettingEnabled(String[] packages);
/**
* Gets an {@link Intent} to show additional battery info.
* Gets an {@link Intent} to show additional battery info
*/
Intent getAdditionalBatteryInfoIntent();
@@ -61,37 +66,37 @@ public interface PowerUsageFeatureProvider {
boolean isTypeSystem(int uid, String[] packages);
/**
* Returns an improved prediction for battery time remaining.
* Returns an improved prediction for battery time remaining
*/
Estimate getEnhancedBatteryPrediction(Context context);
/**
* Returns an improved projection curve for future battery level.
* Returns an improved projection curve for future battery level
*
* @param zeroTime timestamps (array keys) are shifted by this amount
*/
SparseIntArray getEnhancedBatteryPredictionCurve(Context context, long zeroTime);
/**
* Checks whether the toggle for enhanced battery predictions is enabled.
* Checks whether the toggle for enhanced battery predictions is enabled
*/
boolean isEnhancedBatteryPredictionEnabled(Context context);
/**
* Checks whether debugging should be enabled for battery estimates.
* Checks whether debugging should be enabled for battery estimates
*/
boolean isEstimateDebugEnabled();
/**
* Converts the provided string containing the remaining time into a debug string for enhanced
* estimates.
* estimates
*
* @return A string containing the estimate and a label indicating it is an enhanced estimate
*/
String getEnhancedEstimateDebugString(String timeRemaining);
/**
* Converts the provided string containing the remaining time into a debug string.
* Converts the provided string containing the remaining time into a debug string
*
* @return A string containing the estimate and a label indicating it is a normal estimate
*/
@@ -103,7 +108,7 @@ public interface PowerUsageFeatureProvider {
boolean isSmartBatterySupported();
/**
* Checks whether we should show usage information by slots or not.
* Checks whether we should show usage information by slots or not
*/
boolean isChartGraphSlotsEnabled(Context context);
@@ -123,7 +128,7 @@ public interface PowerUsageFeatureProvider {
boolean isExtraDefend();
/**
* Returns {@code true} if delay the hourly job when device is booting.
* Returns {@code true} if delay the hourly job when device is booting
*/
boolean delayHourlyJobWhenBooting();
@@ -133,27 +138,27 @@ public interface PowerUsageFeatureProvider {
Intent getResumeChargeIntent(boolean isDockDefender);
/**
* Returns {@link Set} for the system component ids which are combined into others.
* Returns {@link Set} for the system component ids which are combined into others
*/
Set<Integer> getOthersSystemComponentSet();
/**
* Returns {@link Set} for hiding system component ids in the usage screen.
* Returns {@link Set} for hiding system component ids in the usage screen
*/
Set<Integer> getHideSystemComponentSet();
/**
* Returns {@link Set} for hiding application package names in the usage screen.
* Returns {@link Set} for hiding application package names in the usage screen
*/
Set<String> getHideApplicationSet();
/**
* Returns {@link Set} for hiding applications background usage time.
* Returns {@link Set} for hiding applications background usage time
*/
Set<String> getHideBackgroundUsageTimeSet();
/**
* Returns {@link Set} for ignoring task root class names for screen on time.
* Returns {@link Set} for ignoring task root class names for screen on time
*/
Set<String> getIgnoreScreenOnTimeTaskRootSet();
}

View File

@@ -71,6 +71,11 @@ public class PowerUsageFeatureProviderImpl implements PowerUsageFeatureProvider
return true;
}
@Override
public double getBatteryUsageListConsumePowerThreshold() {
return 0.0;
}
@Override
public List<String> getSystemAppsAllowlist() {
return null;

View File

@@ -48,7 +48,7 @@ public class BatteryDiffData {
if (!isAccumulated) {
final PowerUsageFeatureProvider featureProvider =
FeatureFactory.getFactory(context).getPowerUsageFeatureProvider(context);
purgeFakeAndHiddenPackages(featureProvider);
purgeBatteryDiffData(featureProvider);
combineBatteryDiffEntry(context, featureProvider);
}
@@ -65,9 +65,9 @@ public class BatteryDiffData {
}
/** Removes fake usage data and hidden packages. */
private void purgeFakeAndHiddenPackages(final PowerUsageFeatureProvider featureProvider) {
purgeFakeAndHiddenPackages(featureProvider, mAppEntries);
purgeFakeAndHiddenPackages(featureProvider, mSystemEntries);
private void purgeBatteryDiffData(final PowerUsageFeatureProvider featureProvider) {
purgeBatteryDiffData(featureProvider, mAppEntries);
purgeBatteryDiffData(featureProvider, mSystemEntries);
}
/** Combines into SystemAppsBatteryDiffEntry and OthersBatteryDiffEntry. */
@@ -89,9 +89,11 @@ public class BatteryDiffData {
Collections.sort(mSystemEntries, BatteryDiffEntry.COMPARATOR);
}
private static void purgeFakeAndHiddenPackages(
private static void purgeBatteryDiffData(
final PowerUsageFeatureProvider featureProvider,
final List<BatteryDiffEntry> entries) {
final double consumePowerThreshold =
featureProvider.getBatteryUsageListConsumePowerThreshold();
final Set<Integer> hideSystemComponentSet = featureProvider.getHideSystemComponentSet();
final Set<String> hideBackgroundUsageTimeSet =
featureProvider.getHideBackgroundUsageTimeSet();
@@ -99,9 +101,11 @@ public class BatteryDiffData {
final Iterator<BatteryDiffEntry> iterator = entries.iterator();
while (iterator.hasNext()) {
final BatteryDiffEntry entry = iterator.next();
final double comsumePower = entry.mConsumePower;
final String packageName = entry.getPackageName();
final Integer componentId = entry.mBatteryHistEntry.mDrainType;
if (ConvertUtils.FAKE_PACKAGE_NAME.equals(packageName)
if (comsumePower < consumePowerThreshold
|| ConvertUtils.FAKE_PACKAGE_NAME.equals(packageName)
|| hideSystemComponentSet.contains(componentId)
|| (packageName != null && hideApplicationSet.contains(packageName))) {
iterator.remove();

View File

@@ -67,6 +67,11 @@ public class PowerUsageFeatureProviderImplTest {
assertThat(mPowerFeatureProvider.isBatteryUsageEnabled()).isTrue();
}
@Test
public void testGetBatteryUsageListConsumePowerThreshold_return0() {
assertThat(mPowerFeatureProvider.getBatteryUsageListConsumePowerThreshold()).isEqualTo(0.0);
}
@Test
public void testIsTypeSystem_uidRoot_returnTrue() {
assertThat(mPowerFeatureProvider.isTypeSystem(Process.ROOT_UID, null)).isTrue();