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

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

Merge "Hide summary for Google app in battery usage"

parents 978f7b00 cb8dbbea
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1436,4 +1436,10 @@
        <item>@string/enhanced_4g_lte_mode_summary_4g_calling</item>
    </string-array>

    <!-- A whitelist which packages won't show summary in battery usage screen.  [CHAR LIMIT=NONE] -->
    <string-array name="whitelist_hide_summary_in_battery_usage" translatable="false">
        <!-- Google -->
        <item>"com.google.android.googlequicksearchbox"</item>
    </string-array>

</resources>
+14 −1
Original line number Diff line number Diff line
@@ -338,7 +338,7 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
    void setUsageSummary(Preference preference, BatterySipper sipper) {
        // Only show summary when usage time is longer than one minute
        final long usageTimeMs = sipper.usageTimeMs;
        if (usageTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
        if (shouldShowSummary(sipper) && usageTimeMs >= DateUtils.MINUTE_IN_MILLIS) {
            final CharSequence timeSequence =
                    StringUtil.formatElapsedTime(mContext, usageTimeMs, false);
            preference.setSummary(
@@ -390,6 +390,19 @@ public class BatteryAppListPreferenceController extends AbstractPreferenceContro
        }
    }

    private boolean shouldShowSummary(BatterySipper sipper) {
        final CharSequence[] whitelistPackages = mContext.getResources()
                .getTextArray(R.array.whitelist_hide_summary_in_battery_usage);
        final String target = sipper.packageWithHighestDrain;

        for (CharSequence packageName: whitelistPackages) {
            if (TextUtils.equals(target, packageName)) {
                return false;
            }
        }
        return true;
    }

    private static boolean isSharedGid(int uid) {
        return UserHandle.getAppIdFromSharedAppGid(uid) > 0;
    }
+13 −6
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.content.pm.ModuleInfo;
import android.content.pm.PackageManager;
import android.os.BatteryStats;
import android.os.UserManager;
@@ -40,7 +39,6 @@ import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settingslib.applications.ApplicationsState;

import org.junit.Before;
import org.junit.Test;
@@ -49,10 +47,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;

import java.util.ArrayList;
import java.util.List;

@RunWith(RobolectricTestRunner.class)
public class BatteryAppListPreferenceControllerTest {
@@ -161,6 +155,19 @@ public class BatteryAppListPreferenceControllerTest {
        assertThat(mPreference.getSummary().toString()).isEqualTo("Used for 2 min");
    }

    @Test
    public void testSetUsageSummary_timeMoreThanOneMinute_GoogleApp_shouldNotSetScreenSummary() {
        mNormalBatterySipper.usageTimeMs = 2 * DateUtils.MINUTE_IN_MILLIS;
        mNormalBatterySipper.packageWithHighestDrain = "com.google.android.googlequicksearchbox";
        doReturn(mContext.getText(R.string.battery_used_for)).when(mFragment).getText(
                R.string.battery_used_for);
        doReturn(mContext).when(mFragment).getContext();

        mPreferenceController.setUsageSummary(mPreference, mNormalBatterySipper);

        assertThat(mPreference.getSummary()).isNull();
    }

    @Test
    public void testSetUsageSummary_timeMoreThanOneMinute_hiddenApp_setUsedSummary() {
        mNormalBatterySipper.usageTimeMs = 2 * DateUtils.MINUTE_IN_MILLIS;