summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@android.com>2012-09-14 16:26:37 -0700
committerJeff Sharkey <jsharkey@android.com>2012-09-14 23:00:27 -0700
commitd0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ff (patch)
tree69c90b617c99ea6030fc4a395483d0f43515ebf5 /core/java
parentee100445b7c1f8789d1c8ff7d4ae2d28656657db (diff)
downloadframeworks_base-d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ff.zip
frameworks_base-d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ff.tar.gz
frameworks_base-d0c6ccbafdebc73d03cf3cd47f02f9f6c78a69ff.tar.bz2
Move NetworkPolicy from apps to UID.
For multi-user devices, switch to storing policy per-user instead of per-app. Also watch for user added/removed broadcasts to clean up policies and apply global restrictions. Bug: 7121279 Change-Id: Ia7326bd0ebe0586fa4ec6d3a62f6313dc8814007
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/content/Intent.java4
-rw-r--r--core/java/android/net/INetworkPolicyManager.aidl6
-rw-r--r--core/java/android/net/NetworkPolicyManager.java18
-rw-r--r--core/java/android/os/UserHandle.java12
4 files changed, 22 insertions, 18 deletions
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index bca5ade..b86ac98 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -1473,7 +1473,7 @@ public class Intent implements Parcelable, Cloneable {
* Broadcast Action: A new application package has been installed on the
* device. The data contains the name of the package. Note that the
* newly installed package does <em>not</em> receive this broadcast.
- * <p>My include the following extras:
+ * <p>May include the following extras:
* <ul>
* <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
* <li> {@link #EXTRA_REPLACING} is set to true if this is following
@@ -1489,7 +1489,7 @@ public class Intent implements Parcelable, Cloneable {
* Broadcast Action: A new version of an application package has been
* installed, replacing an existing version that was previously installed.
* The data contains the name of the package.
- * <p>My include the following extras:
+ * <p>May include the following extras:
* <ul>
* <li> {@link #EXTRA_UID} containing the integer uid assigned to the new package.
* </ul>
diff --git a/core/java/android/net/INetworkPolicyManager.aidl b/core/java/android/net/INetworkPolicyManager.aidl
index 3250ae7..df6057e 100644
--- a/core/java/android/net/INetworkPolicyManager.aidl
+++ b/core/java/android/net/INetworkPolicyManager.aidl
@@ -30,9 +30,9 @@ import android.net.NetworkTemplate;
interface INetworkPolicyManager {
/** Control UID policies. */
- void setAppPolicy(int appId, int policy);
- int getAppPolicy(int appId);
- int[] getAppsWithPolicy(int policy);
+ void setUidPolicy(int uid, int policy);
+ int getUidPolicy(int uid);
+ int[] getUidsWithPolicy(int policy);
boolean isUidForeground(int uid);
diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java
index 07bfd4b..2cd1f9b 100644
--- a/core/java/android/net/NetworkPolicyManager.java
+++ b/core/java/android/net/NetworkPolicyManager.java
@@ -26,6 +26,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.RemoteException;
+import android.os.UserHandle;
import android.text.format.Time;
import com.google.android.collect.Sets;
@@ -72,29 +73,29 @@ public class NetworkPolicyManager {
}
/**
- * Set policy flags for specific application.
+ * Set policy flags for specific UID.
*
* @param policy {@link #POLICY_NONE} or combination of flags like
* {@link #POLICY_REJECT_METERED_BACKGROUND}.
*/
- public void setAppPolicy(int appId, int policy) {
+ public void setUidPolicy(int uid, int policy) {
try {
- mService.setAppPolicy(appId, policy);
+ mService.setUidPolicy(uid, policy);
} catch (RemoteException e) {
}
}
- public int getAppPolicy(int appId) {
+ public int getUidPolicy(int uid) {
try {
- return mService.getAppPolicy(appId);
+ return mService.getUidPolicy(uid);
} catch (RemoteException e) {
return POLICY_NONE;
}
}
- public int[] getAppsWithPolicy(int policy) {
+ public int[] getUidsWithPolicy(int policy) {
try {
- return mService.getAppsWithPolicy(policy);
+ return mService.getUidsWithPolicy(policy);
} catch (RemoteException e) {
return new int[0];
}
@@ -236,8 +237,7 @@ public class NetworkPolicyManager {
@Deprecated
public static boolean isUidValidForPolicy(Context context, int uid) {
// first, quick-reject non-applications
- if (uid < android.os.Process.FIRST_APPLICATION_UID
- || uid > android.os.Process.LAST_APPLICATION_UID) {
+ if (!UserHandle.isApp(uid)) {
return false;
}
diff --git a/core/java/android/os/UserHandle.java b/core/java/android/os/UserHandle.java
index 22994ff..cc96152 100644
--- a/core/java/android/os/UserHandle.java
+++ b/core/java/android/os/UserHandle.java
@@ -87,15 +87,19 @@ public final class UserHandle implements Parcelable {
/** @hide */
public static final boolean isIsolated(int uid) {
- uid = getAppId(uid);
- return uid >= Process.FIRST_ISOLATED_UID && uid <= Process.LAST_ISOLATED_UID;
+ if (uid > 0) {
+ final int appId = getAppId(uid);
+ return appId >= Process.FIRST_ISOLATED_UID && appId <= Process.LAST_ISOLATED_UID;
+ } else {
+ return false;
+ }
}
/** @hide */
public static boolean isApp(int uid) {
if (uid > 0) {
- uid = UserHandle.getAppId(uid);
- return uid >= Process.FIRST_APPLICATION_UID && uid <= Process.LAST_APPLICATION_UID;
+ final int appId = getAppId(uid);
+ return appId >= Process.FIRST_APPLICATION_UID && appId <= Process.LAST_APPLICATION_UID;
} else {
return false;
}