summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2011-11-01 21:14:35 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-11-01 21:14:35 -0700
commitdb0ab2e731d755f64583c5704fa406bc0e7a2af4 (patch)
treec834a4c19d2f6cba3cb6084138260b92a5fba979
parentbcf05a69090f342d328f1537d1d83406b883290b (diff)
parent6f7af03cf13f76f48e63937e13e4a1c508d100d6 (diff)
downloadbase-db0ab2e731d755f64583c5704fa406bc0e7a2af4.tar.gz
Merge "Process AMS events in NetworkPolicy handler." into ics-mr0
-rw-r--r--services/java/com/android/server/net/NetworkPolicyManagerService.java70
1 files changed, 41 insertions, 29 deletions
diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java
index e6107826aa8c..bdad82a6d8fa 100644
--- a/services/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -186,8 +186,10 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private static final long TIME_CACHE_MAX_AGE = DAY_IN_MILLIS;
- private static final int MSG_RULES_CHANGED = 0x1;
- private static final int MSG_METERED_IFACES_CHANGED = 0x2;
+ private static final int MSG_RULES_CHANGED = 1;
+ private static final int MSG_METERED_IFACES_CHANGED = 2;
+ private static final int MSG_FOREGROUND_ACTIVITIES_CHANGED = 3;
+ private static final int MSG_PROCESS_DIED = 4;
private final Context mContext;
private final IActivityManager mActivityManager;
@@ -335,37 +337,13 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
private IProcessObserver mProcessObserver = new IProcessObserver.Stub() {
@Override
public void onForegroundActivitiesChanged(int pid, int uid, boolean foregroundActivities) {
- // only someone like AMS should only be calling us
- mContext.enforceCallingOrSelfPermission(MANAGE_APP_TOKENS, TAG);
-
- synchronized (mRulesLock) {
- // because a uid can have multiple pids running inside, we need to
- // remember all pid states and summarize foreground at uid level.
-
- // record foreground for this specific pid
- SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
- if (pidForeground == null) {
- pidForeground = new SparseBooleanArray(2);
- mUidPidForeground.put(uid, pidForeground);
- }
- pidForeground.put(pid, foregroundActivities);
- computeUidForegroundLocked(uid);
- }
+ mHandler.obtainMessage(MSG_FOREGROUND_ACTIVITIES_CHANGED,
+ pid, uid, foregroundActivities).sendToTarget();
}
@Override
public void onProcessDied(int pid, int uid) {
- // only someone like AMS should only be calling us
- mContext.enforceCallingOrSelfPermission(MANAGE_APP_TOKENS, TAG);
-
- synchronized (mRulesLock) {
- // clear records and recompute, when they exist
- final SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
- if (pidForeground != null) {
- pidForeground.delete(pid);
- computeUidForegroundLocked(uid);
- }
- }
+ mHandler.obtainMessage(MSG_PROCESS_DIED, pid, uid).sendToTarget();
}
};
@@ -1469,6 +1447,40 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
mListeners.finishBroadcast();
return true;
}
+ case MSG_FOREGROUND_ACTIVITIES_CHANGED: {
+ final int pid = msg.arg1;
+ final int uid = msg.arg2;
+ final boolean foregroundActivities = (Boolean) msg.obj;
+
+ synchronized (mRulesLock) {
+ // because a uid can have multiple pids running inside, we need to
+ // remember all pid states and summarize foreground at uid level.
+
+ // record foreground for this specific pid
+ SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
+ if (pidForeground == null) {
+ pidForeground = new SparseBooleanArray(2);
+ mUidPidForeground.put(uid, pidForeground);
+ }
+ pidForeground.put(pid, foregroundActivities);
+ computeUidForegroundLocked(uid);
+ }
+ return true;
+ }
+ case MSG_PROCESS_DIED: {
+ final int pid = msg.arg1;
+ final int uid = msg.arg2;
+
+ synchronized (mRulesLock) {
+ // clear records and recompute, when they exist
+ final SparseBooleanArray pidForeground = mUidPidForeground.get(uid);
+ if (pidForeground != null) {
+ pidForeground.delete(pid);
+ computeUidForegroundLocked(uid);
+ }
+ }
+ return true;
+ }
default: {
return false;
}