Hide app if it shares uid with whitelisted app
Statsd blame app based on uid, which may mapping to multiple packages. If there is one app in whitelist, then we shouldn't blame other apps in same group. Bug: 77560853 Test: RunSettingsLibTests Change-Id: Ic21fea9701f9199c016674eaca3b0382e3a80837
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user