summaryrefslogtreecommitdiffstats
path: root/services/usage
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2015-08-06 22:19:06 -0700
committerDianne Hackborn <hackbod@google.com>2015-08-07 14:23:32 -0700
commit4a503b1ece485d44c15eb02ec2bcd464b46e6f7f (patch)
tree72a22a0708c74e5f99a8bf2f4cb68f3d6ac15cf7 /services/usage
parent1d7c32548c30c62a35c54a624f89d5f9db31b9d4 (diff)
downloadframeworks_base-4a503b1ece485d44c15eb02ec2bcd464b46e6f7f.zip
frameworks_base-4a503b1ece485d44c15eb02ec2bcd464b46e6f7f.tar.gz
frameworks_base-4a503b1ece485d44c15eb02ec2bcd464b46e6f7f.tar.bz2
Fix issue #22989030: Separate battery whitelists
We now have a new whitelist you can put apps in, which opts them out of the old battery saver mode and new app idle, but doesn't keep them from going in to doze. This is for a few special cases that we had previously whitelisted for battery saver, and inherited to the new modes... ultimately we should figure out how to get these apps out of the whitelist completely, but this will help for now. Apps in this new whitelist are not shown in the UI, because they are still significantly restricted by not being able to operate normally in doze. This also means they are still visible in the list of all apps for the user to be able to put them on/off the complete whitelist if that is what they really want. In the course of doing this, I needed to clean up code in the network policy manager to better separate management of the two firewall rules that now have different whitelists applied to them. This also hopefully just generally simplifies and cleans up that code. Hopefully! Change-Id: I92e15f2f85899571dd8b049b5e3eb1354f55f353
Diffstat (limited to 'services/usage')
-rw-r--r--services/usage/java/com/android/server/usage/UsageStatsService.java78
1 files changed, 77 insertions, 1 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index a433ec4..85f0665 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -35,6 +35,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ParceledListSlice;
@@ -65,6 +66,7 @@ import android.util.AtomicFile;
import android.util.KeyValueListParser;
import android.util.Slog;
import android.util.SparseArray;
+import android.util.SparseIntArray;
import android.util.TimeUtils;
import android.view.Display;
@@ -799,7 +801,10 @@ public class UsageStatsService extends SystemService implements
}
if (packageName.equals("android")) return false;
try {
- if (mDeviceIdleController.isPowerSaveWhitelistApp(packageName)) {
+ // We allow all whitelisted apps, including those that don't want to be whitelisted
+ // for idle mode, because app idle (aka app standby) is really not as big an issue
+ // for controlling who participates vs. doze mode.
+ if (mDeviceIdleController.isPowerSaveWhitelistExceptIdleApp(packageName)) {
return false;
}
} catch (RemoteException re) {
@@ -825,6 +830,72 @@ public class UsageStatsService extends SystemService implements
return isAppIdleUnfiltered(packageName, userService, timeNow, screenOnTime);
}
+ int[] getIdleUidsForUser(int userId) {
+ if (!mAppIdleEnabled) {
+ return new int[0];
+ }
+
+ final long timeNow;
+ final UserUsageStatsService userService;
+ final long screenOnTime;
+ synchronized (mLock) {
+ timeNow = checkAndGetTimeLocked();
+ userService = getUserDataAndInitializeIfNeededLocked(userId, timeNow);
+ screenOnTime = getScreenOnTimeLocked(timeNow);
+ }
+
+ List<ApplicationInfo> apps;
+ try {
+ ParceledListSlice<ApplicationInfo> slice
+ = AppGlobals.getPackageManager().getInstalledApplications(0, userId);
+ apps = slice.getList();
+ } catch (RemoteException e) {
+ return new int[0];
+ }
+
+ // State of each uid. Key is the uid. Value lower 16 bits is the number of apps
+ // associated with that uid, upper 16 bits is the number of those apps that is idle.
+ SparseIntArray uidStates = new SparseIntArray();
+
+ // Now resolve all app state. Iterating over all apps, keeping track of how many
+ // we find for each uid and how many of those are idle.
+ for (int i = apps.size()-1; i >= 0; i--) {
+ ApplicationInfo ai = apps.get(i);
+
+ // Check whether this app is idle.
+ boolean idle = isAppIdleFiltered(ai.packageName, userId, userService, timeNow,
+ screenOnTime);
+
+ int index = uidStates.indexOfKey(ai.uid);
+ if (index < 0) {
+ uidStates.put(ai.uid, 1 + (idle ? 1<<16 : 0));
+ } else {
+ int value = uidStates.valueAt(index);
+ uidStates.setValueAt(index, value + 1 + (idle ? 1<<16 : 0));
+ }
+ }
+
+ int numIdle = 0;
+ for (int i = uidStates.size() - 1; i >= 0; i--) {
+ int value = uidStates.valueAt(i);
+ if ((value&0x7fff) == (value>>16)) {
+ numIdle++;
+ }
+ }
+
+ int[] res = new int[numIdle];
+ numIdle = 0;
+ for (int i = uidStates.size() - 1; i >= 0; i--) {
+ int value = uidStates.valueAt(i);
+ if ((value&0x7fff) == (value>>16)) {
+ res[numIdle] = uidStates.keyAt(i);
+ numIdle++;
+ }
+ }
+
+ return res;
+ }
+
void setAppIdle(String packageName, boolean idle, int userId) {
if (packageName == null) return;
@@ -1284,6 +1355,11 @@ public class UsageStatsService extends SystemService implements
}
@Override
+ public int[] getIdleUidsForUser(int userId) {
+ return UsageStatsService.this.getIdleUidsForUser(userId);
+ }
+
+ @Override
public boolean isAppIdleParoleOn() {
return mAppIdleParoled;
}