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

Commit 7015cd0d authored by ykhung's avatar ykhung
Browse files

Hide running time for "Android System" in the optimization page

Hide the running time information for "Android System" entry, since this
entry will combine multiple system components together. It will provide
incorrect running time information. The getRealUid() method maps many
UIDs to Process.SYSTEM_UID(1000), which results in combining all of
those UIDs into one "Android System" entry. This is the expected behavior.

Bug: 220717612
Test: make RunSettingsRoboTests -j56 ROBOTEST_FILTER="com.android.settings.fuelgauge"
Change-Id: I9d44fe8490ad5c684419b8ebf8d7d5576a42788a
parent c880114d
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -525,20 +525,24 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
        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 int uid = bundle.getInt(EXTRA_UID, 0);
        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());
        final boolean isChartGraphEnabled = FeatureFactory.getFactory(getContext())
                .getPowerUsageFeatureProvider(getContext()).isChartGraphEnabled(getContext());

        if (!isChartGraphEnabled && BatteryEntry.isSystemUid(uid)) {
            return null;
        }
        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())
            usageTimeSummary = getText(isChartGraphEnabled
                    ? 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())
            usageTimeSummary = isChartGraphEnabled
                    ? getAppPast24HrActiveSummary(foregroundTimeMs, backgroundTimeMs, totalTimeMs)
                    : getAppFullChargeActiveSummary(
                            foregroundTimeMs, backgroundTimeMs, totalTimeMs);
+1 −1
Original line number Diff line number Diff line
@@ -434,7 +434,7 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro

    @VisibleForTesting
    void setUsageSummary(Preference preference, BatteryEntry entry) {
        if (entry.getUid() == Process.SYSTEM_UID) {
        if (BatteryEntry.isSystemUid(entry.getUid())) {
            return;
        }
        String packageName = entry.getDefaultPackageName();
+1 −1
Original line number Diff line number Diff line
@@ -612,7 +612,7 @@ public class BatteryEntry {
        return new NameAndIcon(name, null /* icon */, iconId);
    }

    private static boolean isSystemUid(int uid) {
    static boolean isSystemUid(int uid) {
        return uid == Process.SYSTEM_UID;
    }
}
+39 −4
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.os.BatteryStats;
import android.os.Bundle;
import android.os.Process;
import android.os.UserHandle;
import android.util.Pair;

@@ -548,6 +549,7 @@ public class AdvancedPowerUsageDetailTest {
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeFourMinute);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
        when(mFragment.getArguments()).thenReturn(bundle);

        mFragment.initHeader();

        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
@@ -560,7 +562,7 @@ public class AdvancedPowerUsageDetailTest {
    public void testInitHeader_totalUsageLessThanAMinWithSlotTime_hasCorrectSummary() {
        final long backgroundTimeLessThanHalfMinute = 20000;
        final long foregroundTimeLessThanHalfMinute = 20000;
        Bundle bundle = new Bundle(2);
        Bundle bundle = new Bundle(3);
        bundle.putLong(
                AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeLessThanHalfMinute);
        bundle.putLong(
@@ -580,7 +582,7 @@ public class AdvancedPowerUsageDetailTest {
    public void testInitHeader_TotalAMinBackgroundLessThanAMinWithSlotTime_hasCorrectSummary() {
        final long backgroundTimeZero = 59999;
        final long foregroundTimeTwoMinutes = 1;
        Bundle bundle = new Bundle(2);
        Bundle bundle = new Bundle(3);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeZero);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
@@ -598,7 +600,7 @@ public class AdvancedPowerUsageDetailTest {
    public void testInitHeader_TotalAMinBackgroundZeroWithSlotTime_hasCorrectSummary() {
        final long backgroundTimeZero = 0;
        final long foregroundTimeAMinutes = 60000;
        Bundle bundle = new Bundle(2);
        Bundle bundle = new Bundle(3);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeZero);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeAMinutes);
        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
@@ -616,11 +618,12 @@ public class AdvancedPowerUsageDetailTest {
    public void testInitHeader_foregroundTwoMinBackgroundFourMinWithSlotTime_hasCorrectSummary() {
        final long backgroundTimeFourMinute = 240000;
        final long foregroundTimeTwoMinutes = 120000;
        Bundle bundle = new Bundle(2);
        Bundle bundle = new Bundle(3);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, backgroundTimeFourMinute);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, foregroundTimeTwoMinutes);
        bundle.putString(AdvancedPowerUsageDetail.EXTRA_SLOT_TIME, SLOT_TIME);
        when(mFragment.getArguments()).thenReturn(bundle);

        mFragment.initHeader();

        ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
@@ -629,6 +632,38 @@ public class AdvancedPowerUsageDetailTest {
                .isEqualTo("6 min total • 4 min background\nfor 12 am-2 am");
    }

    @Test
    public void testInitHeader_systemUidWithChartIsDisabled_nullSummary() {
        Bundle bundle = new Bundle(3);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, 240000);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, 120000);
        bundle.putInt(AdvancedPowerUsageDetail.EXTRA_UID, Process.SYSTEM_UID);
        when(mFragment.getArguments()).thenReturn(bundle);
        when(mFeatureFactory.powerUsageFeatureProvider.isChartGraphEnabled(mContext))
                .thenReturn(false);

        mFragment.initHeader();

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

    @Test
    public void testInitHeader_systemUidWithChartIsEnabled_notNullSummary() {
        Bundle bundle = new Bundle(3);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_BACKGROUND_TIME, 240000);
        bundle.putLong(AdvancedPowerUsageDetail.EXTRA_FOREGROUND_TIME, 120000);
        bundle.putInt(AdvancedPowerUsageDetail.EXTRA_UID, Process.SYSTEM_UID);
        when(mFragment.getArguments()).thenReturn(bundle);

        mFragment.initHeader();

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

    @Test
    public void testStartBatteryDetailPage_hasBasicData() {
        AdvancedPowerUsageDetail.startBatteryDetailPage(mActivity, mFragment,