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

Commit 054f3b51 authored by YUKAI HUNG's avatar YUKAI HUNG Committed by Automerger Merge Worker
Browse files

Merge "Update app usage page power summary" into sc-v2-dev am: 8e97bdd7

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/16091765

Change-Id: Ifbe0fee50f01f00784bd65aa6124081b41b1f3c7
parents 33914ed5 8e97bdd7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6565,6 +6565,8 @@
    <string name="battery_not_usage">No usage from last full charge</string>
    <!-- Description for no any battery usage for past 24 hr [CHAR LIMIT=120] -->
    <string name="battery_not_usage_24hr">No usage for past 24 hr</string>
    <!-- Description for no usage time but have battery usage [CHAR LIMIT=120] -->
    <string name="battery_usage_without_time"></string>
    <!-- Graph subtext displayed to user when enhanced battery estimate is being used [CHAR LIMIT=120] -->
    <string name="advanced_battery_graph_subtext">Battery left estimate is based on your device usage</string>
+9 −7
Original line number Diff line number Diff line
@@ -326,10 +326,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
        }

        if (mEnableTriState) {
            final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
            final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
            final String slotTime = bundle.getString(EXTRA_SLOT_TIME, null);
            controller.setSummary(getAppActiveTime(foregroundTimeMs, backgroundTimeMs, slotTime));
            controller.setSummary(getAppActiveTime(bundle));
        }

        controller.done(context, true /* rebindActions */);
@@ -493,16 +490,21 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
        mOptimizationMode = mBatteryOptimizeUtils.getAppOptimizationMode();
    }

    private CharSequence getAppActiveTime(
            long foregroundTimeMs, long backgroundTimeMs, String slotTime) {
    private CharSequence getAppActiveTime(Bundle bundle) {
        final long foregroundTimeMs = bundle.getLong(EXTRA_FOREGROUND_TIME);
        final long backgroundTimeMs = bundle.getLong(EXTRA_BACKGROUND_TIME);
        final int consumedPower = bundle.getInt(EXTRA_POWER_USAGE_AMOUNT);
        final String slotTime = bundle.getString(EXTRA_SLOT_TIME, null);
        final long totalTimeMs = foregroundTimeMs + backgroundTimeMs;
        final CharSequence usageTimeSummary;
        final PowerUsageFeatureProvider powerFeatureProvider =
                FeatureFactory.getFactory(getContext()).getPowerUsageFeatureProvider(getContext());

        if (totalTimeMs == 0) {
            final int batteryWithoutUsageTime = consumedPower > 0
                    ? R.string.battery_usage_without_time : R.string.battery_not_usage_24hr;
            usageTimeSummary = getText(powerFeatureProvider.isChartGraphEnabled(getContext())
                    ? R.string.battery_not_usage_24hr : R.string.battery_not_usage);
                    ? batteryWithoutUsageTime : R.string.battery_not_usage);
        } else if (slotTime == null) {
            // Shows summary text with past 24 hr or full charge if slot time is null.
            usageTimeSummary = powerFeatureProvider.isChartGraphEnabled(getContext())
+15 −0
Original line number Diff line number Diff line
@@ -437,6 +437,21 @@ public class AdvancedPowerUsageDetailTest {
                .isEqualTo("No usage for past 24 hr");
    }

    @Test
    public void testInitHeader_noUsageTimeButConsumedPower_hasEmptySummary() {
        Bundle bundle = new Bundle(3);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, /* value */ 0);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, /* value */ 0);
        bundle.putInt(AdvancedPowerUsageDetail.EXTRA_POWER_USAGE_AMOUNT, /* value */ 10);
        when(mFragment.getArguments()).thenReturn(bundle);

        mFragment.initHeader();

        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
        verify(mEntityHeaderController).setSummary(captor.capture());
        assertThat(captor.getValue().toString()).isEmpty();
    }

    @Test
    public void testInitHeader_backgroundTwoMinForegroundZero_hasCorrectSummary() {
        final long backgroundTimeTwoMinutes = 120000;