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

Commit 8aab7c65 authored by Lei Yu's avatar Lei Yu Committed by Android (Google) Code Review
Browse files

Merge "Hide app if it shares uid with whitelisted app" into pi-dev

parents 297a3e27 ae768653
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settingslib.fuelgauge;

import android.content.pm.PackageManager;
import android.os.IDeviceIdleController;
import android.os.RemoteException;
import android.os.ServiceManager;
@@ -24,6 +25,8 @@ import android.support.annotation.VisibleForTesting;
import android.util.ArraySet;
import android.util.Log;

import com.android.internal.util.ArrayUtils;

/**
 * Handles getting/changing the whitelist for the exceptions to battery saving features.
 */
@@ -68,6 +71,19 @@ public class PowerWhitelistBackend {
        return mSysWhitelistedAppsExceptIdle.contains(pkg);
    }

    public boolean isSysWhitelistedExceptIdle(String[] pkgs) {
        if (ArrayUtils.isEmpty(pkgs)) {
            return false;
        }
        for (String pkg : pkgs) {
            if (isSysWhitelistedExceptIdle(pkg)) {
                return true;
            }
        }

        return false;
    }

    public void addApp(String pkg) {
        try {
            mDeviceIdleService.addPowerSaveWhitelistApp(pkg);
+14 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ public class PowerWhitelistBackendTest {
    }

    @Test
    public void testIsSystemWhitelistedExceptIdle() throws Exception {
    public void testIsSystemWhitelistedExceptIdle_onePackage() throws Exception {
        doReturn(new String[]{PACKAGE_TWO}).when(
                mDeviceIdleService).getSystemPowerWhitelistExceptIdle();
        mPowerWhitelistBackend.refreshList();
@@ -100,4 +100,17 @@ public class PowerWhitelistBackendTest {
        assertThat(mPowerWhitelistBackend.isSysWhitelistedExceptIdle(PACKAGE_ONE)).isFalse();
        assertThat(mPowerWhitelistBackend.isSysWhitelistedExceptIdle(PACKAGE_TWO)).isTrue();
    }

    @Test
    public void testIsSystemWhitelistedExceptIdle_packageArray() throws Exception {
        doReturn(new String[]{PACKAGE_TWO}).when(
                mDeviceIdleService).getSystemPowerWhitelistExceptIdle();
        mPowerWhitelistBackend.refreshList();

        final String[] idlePackages = {PACKAGE_ONE, PACKAGE_TWO};
        final String[] normalPackages = {PACKAGE_ONE};

        assertThat(mPowerWhitelistBackend.isSysWhitelistedExceptIdle(normalPackages)).isFalse();
        assertThat(mPowerWhitelistBackend.isSysWhitelistedExceptIdle(idlePackages)).isTrue();
    }
}