Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ecb67474 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Don't hide 1% battery usage apps but show percentage "-" instead."

parents 97b7731f 1bf57958
Loading
Loading
Loading
Loading
+7 −10
Original line number Diff line number Diff line
@@ -83,8 +83,6 @@ public final class DataProcessor {
    private static final BatteryHistEntry EMPTY_BATTERY_HIST_ENTRY =
            new BatteryHistEntry(new ContentValues());

    @VisibleForTesting
    static final double PERCENTAGE_OF_TOTAL_THRESHOLD = 1f;
    @VisibleForTesting
    static final int SELECTED_INDEX_ALL = BatteryChartViewModel.SELECTED_INDEX_ALL;
    @VisibleForTesting
@@ -441,7 +439,7 @@ public final class DataProcessor {
        insertAllUsageDiffData(resultMap);
        // Compute the apps number before purge. Must put before purgeLowPercentageAndFakeData.
        final int countOfAppBeforePurge = getCountOfApps(resultMap);
        purgeLowPercentageAndFakeData(context, resultMap);
        purgeFakeAndHiddenPackages(context, resultMap);
        // Compute the apps number after purge. Must put after purgeLowPercentageAndFakeData.
        final int countOfAppAfterPurge = getCountOfApps(resultMap);
        if (!isUsageMapValid(resultMap, hourlyBatteryLevelsPerDay)) {
@@ -536,7 +534,7 @@ public final class DataProcessor {

        // Compute the apps number before purge. Must put before purgeLowPercentageAndFakeData.
        final int countOfAppBeforePurge = getCountOfApps(resultMap);
        purgeLowPercentageAndFakeData(context, resultMap);
        purgeFakeAndHiddenPackages(context, resultMap);
        // Compute the apps number after purge. Must put after purgeLowPercentageAndFakeData.
        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.
    private static void purgeLowPercentageAndFakeData(
    private static void purgeFakeAndHiddenPackages(
            final Context context,
            final Map<Integer, Map<Integer, BatteryDiffData>> resultMap) {
        final Set<CharSequence> backgroundUsageTimeHideList =
@@ -1139,17 +1137,17 @@ public final class DataProcessor {
                if (diffEntryLists == null) {
                    return;
                }
                purgeLowPercentageAndFakeData(
                purgeFakeAndHiddenPackages(
                        diffEntryLists.getAppDiffEntryList(), backgroundUsageTimeHideList,
                        notAllowShowEntryPackages);
                purgeLowPercentageAndFakeData(
                purgeFakeAndHiddenPackages(
                        diffEntryLists.getSystemDiffEntryList(), backgroundUsageTimeHideList,
                        notAllowShowEntryPackages);
            });
        });
    }

    private static void purgeLowPercentageAndFakeData(
    private static void purgeFakeAndHiddenPackages(
            final List<BatteryDiffEntry> entries,
            final Set<CharSequence> backgroundUsageTimeHideList,
            final CharSequence[] notAllowShowEntryPackages) {
@@ -1157,8 +1155,7 @@ public final class DataProcessor {
        while (iterator.hasNext()) {
            final BatteryDiffEntry entry = iterator.next();
            final String packageName = entry.getPackageName();
            if (entry.getPercentOfTotal() < PERCENTAGE_OF_TOTAL_THRESHOLD
                    || ConvertUtils.FAKE_PACKAGE_NAME.equals(packageName)
            if (ConvertUtils.FAKE_PACKAGE_NAME.equals(packageName)
                    || contains(packageName, notAllowShowEntryPackages)) {
                iterator.remove();
            }
+4 −1
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ import com.android.settingslib.widget.AppPreference;
 */
public class PowerGaugePreference extends AppPreference {

    private static final double PERCENTAGE_TO_SHOW_THRESHOLD = 1f;

    private BatteryEntry mInfo;
    private BatteryDiffEntry mBatteryDiffEntry;
    private CharSequence mContentDescription;
@@ -75,7 +77,8 @@ public class PowerGaugePreference extends AppPreference {

    /** Sets the percent of total. */
    public void setPercent(double percentOfTotal) {
        mProgress = Utils.formatPercentage(percentOfTotal, true);
        mProgress = percentOfTotal < PERCENTAGE_TO_SHOW_THRESHOLD
                ? "-" : Utils.formatPercentage(percentOfTotal, true);
        notifyChanged();
    }

+14 −0
Original line number Diff line number Diff line
@@ -104,4 +104,18 @@ public class PowerGaugePreferenceTest {
        assertThat(mPreferenceViewHolder.findViewById(android.R.id.title).getContentDescription())
                .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("-");
    }
}