Don't hide 1% battery usage apps but show percentage "-" instead.
Bug b/242252864 will be fixed at the same time. screen_record: https://drive.google.com/open?id=1ycEuazqQZzNWGO8E2Fh3GdgyTEd2Z9s0&authuser=0&resourcekey=0-x9BJJE6932jIv9fFoecjeQ&usp=drive_link Bug: 262187603 Bug: 242252864 Fix: 262187603 Fix: 242252864 Test: manual Change-Id: Id1a8b5291d66a38fb86f168d3115ae566e6ec079
This commit is contained in:
@@ -83,8 +83,6 @@ public final class DataProcessor {
|
|||||||
private static final BatteryHistEntry EMPTY_BATTERY_HIST_ENTRY =
|
private static final BatteryHistEntry EMPTY_BATTERY_HIST_ENTRY =
|
||||||
new BatteryHistEntry(new ContentValues());
|
new BatteryHistEntry(new ContentValues());
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
static final double PERCENTAGE_OF_TOTAL_THRESHOLD = 1f;
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int SELECTED_INDEX_ALL = BatteryChartViewModel.SELECTED_INDEX_ALL;
|
static final int SELECTED_INDEX_ALL = BatteryChartViewModel.SELECTED_INDEX_ALL;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
@@ -441,7 +439,7 @@ public final class DataProcessor {
|
|||||||
insertAllUsageDiffData(resultMap);
|
insertAllUsageDiffData(resultMap);
|
||||||
// Compute the apps number before purge. Must put before purgeLowPercentageAndFakeData.
|
// Compute the apps number before purge. Must put before purgeLowPercentageAndFakeData.
|
||||||
final int countOfAppBeforePurge = getCountOfApps(resultMap);
|
final int countOfAppBeforePurge = getCountOfApps(resultMap);
|
||||||
purgeLowPercentageAndFakeData(context, resultMap);
|
purgeFakeAndHiddenPackages(context, resultMap);
|
||||||
// Compute the apps number after purge. Must put after purgeLowPercentageAndFakeData.
|
// Compute the apps number after purge. Must put after purgeLowPercentageAndFakeData.
|
||||||
final int countOfAppAfterPurge = getCountOfApps(resultMap);
|
final int countOfAppAfterPurge = getCountOfApps(resultMap);
|
||||||
if (!isUsageMapValid(resultMap, hourlyBatteryLevelsPerDay)) {
|
if (!isUsageMapValid(resultMap, hourlyBatteryLevelsPerDay)) {
|
||||||
@@ -536,7 +534,7 @@ public final class DataProcessor {
|
|||||||
|
|
||||||
// Compute the apps number before purge. Must put before purgeLowPercentageAndFakeData.
|
// Compute the apps number before purge. Must put before purgeLowPercentageAndFakeData.
|
||||||
final int countOfAppBeforePurge = getCountOfApps(resultMap);
|
final int countOfAppBeforePurge = getCountOfApps(resultMap);
|
||||||
purgeLowPercentageAndFakeData(context, resultMap);
|
purgeFakeAndHiddenPackages(context, resultMap);
|
||||||
// Compute the apps number after purge. Must put after purgeLowPercentageAndFakeData.
|
// Compute the apps number after purge. Must put after purgeLowPercentageAndFakeData.
|
||||||
final int countOfAppAfterPurge = getCountOfApps(resultMap);
|
final int countOfAppAfterPurge = getCountOfApps(resultMap);
|
||||||
|
|
||||||
@@ -1122,7 +1120,7 @@ public final class DataProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Removes low percentage data and fake usage data, which will be zero value.
|
// Removes low percentage data and fake usage data, which will be zero value.
|
||||||
private static void purgeLowPercentageAndFakeData(
|
private static void purgeFakeAndHiddenPackages(
|
||||||
final Context context,
|
final Context context,
|
||||||
final Map<Integer, Map<Integer, BatteryDiffData>> resultMap) {
|
final Map<Integer, Map<Integer, BatteryDiffData>> resultMap) {
|
||||||
final Set<CharSequence> backgroundUsageTimeHideList =
|
final Set<CharSequence> backgroundUsageTimeHideList =
|
||||||
@@ -1139,17 +1137,17 @@ public final class DataProcessor {
|
|||||||
if (diffEntryLists == null) {
|
if (diffEntryLists == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
purgeLowPercentageAndFakeData(
|
purgeFakeAndHiddenPackages(
|
||||||
diffEntryLists.getAppDiffEntryList(), backgroundUsageTimeHideList,
|
diffEntryLists.getAppDiffEntryList(), backgroundUsageTimeHideList,
|
||||||
notAllowShowEntryPackages);
|
notAllowShowEntryPackages);
|
||||||
purgeLowPercentageAndFakeData(
|
purgeFakeAndHiddenPackages(
|
||||||
diffEntryLists.getSystemDiffEntryList(), backgroundUsageTimeHideList,
|
diffEntryLists.getSystemDiffEntryList(), backgroundUsageTimeHideList,
|
||||||
notAllowShowEntryPackages);
|
notAllowShowEntryPackages);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void purgeLowPercentageAndFakeData(
|
private static void purgeFakeAndHiddenPackages(
|
||||||
final List<BatteryDiffEntry> entries,
|
final List<BatteryDiffEntry> entries,
|
||||||
final Set<CharSequence> backgroundUsageTimeHideList,
|
final Set<CharSequence> backgroundUsageTimeHideList,
|
||||||
final CharSequence[] notAllowShowEntryPackages) {
|
final CharSequence[] notAllowShowEntryPackages) {
|
||||||
@@ -1157,8 +1155,7 @@ public final class DataProcessor {
|
|||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final BatteryDiffEntry entry = iterator.next();
|
final BatteryDiffEntry entry = iterator.next();
|
||||||
final String packageName = entry.getPackageName();
|
final String packageName = entry.getPackageName();
|
||||||
if (entry.getPercentOfTotal() < PERCENTAGE_OF_TOTAL_THRESHOLD
|
if (ConvertUtils.FAKE_PACKAGE_NAME.equals(packageName)
|
||||||
|| ConvertUtils.FAKE_PACKAGE_NAME.equals(packageName)
|
|
||||||
|| contains(packageName, notAllowShowEntryPackages)) {
|
|| contains(packageName, notAllowShowEntryPackages)) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,8 @@ import com.android.settingslib.widget.AppPreference;
|
|||||||
*/
|
*/
|
||||||
public class PowerGaugePreference extends AppPreference {
|
public class PowerGaugePreference extends AppPreference {
|
||||||
|
|
||||||
|
private static final double PERCENTAGE_TO_SHOW_THRESHOLD = 1f;
|
||||||
|
|
||||||
private BatteryEntry mInfo;
|
private BatteryEntry mInfo;
|
||||||
private BatteryDiffEntry mBatteryDiffEntry;
|
private BatteryDiffEntry mBatteryDiffEntry;
|
||||||
private CharSequence mContentDescription;
|
private CharSequence mContentDescription;
|
||||||
@@ -75,7 +77,8 @@ public class PowerGaugePreference extends AppPreference {
|
|||||||
|
|
||||||
/** Sets the percent of total. */
|
/** Sets the percent of total. */
|
||||||
public void setPercent(double percentOfTotal) {
|
public void setPercent(double percentOfTotal) {
|
||||||
mProgress = Utils.formatPercentage(percentOfTotal, true);
|
mProgress = percentOfTotal < PERCENTAGE_TO_SHOW_THRESHOLD
|
||||||
|
? "-" : Utils.formatPercentage(percentOfTotal, true);
|
||||||
notifyChanged();
|
notifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -104,4 +104,18 @@ public class PowerGaugePreferenceTest {
|
|||||||
assertThat(mPreferenceViewHolder.findViewById(android.R.id.title).getContentDescription())
|
assertThat(mPreferenceViewHolder.findViewById(android.R.id.title).getContentDescription())
|
||||||
.isEqualTo(CONTENT_DESCRIPTION);
|
.isEqualTo(CONTENT_DESCRIPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setPercent_greaterThanThreshold_showNumber() {
|
||||||
|
mPowerGaugePreference.setPercent(99.5);
|
||||||
|
|
||||||
|
assertThat(mPowerGaugePreference.getPercent()).isEqualTo("100%");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setPercent_lessThanThreshold_showBar() {
|
||||||
|
mPowerGaugePreference.setPercent(0.95);
|
||||||
|
|
||||||
|
assertThat(mPowerGaugePreference.getPercent()).isEqualTo("-");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user