diff options
author | Jeff Sharkey <jsharkey@android.com> | 2012-04-13 16:03:40 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2012-04-13 19:46:33 -0700 |
commit | 854b2b1670bda1eeb87a14b7ac3d222024f0aad6 (patch) | |
tree | 86991bce25cb49406daf069ea1d5c9496d532790 | |
parent | a94afeb5b3c3c95c6d2cf0cd4d69587aba569cfb (diff) | |
download | frameworks_base-854b2b1670bda1eeb87a14b7ac3d222024f0aad6.zip frameworks_base-854b2b1670bda1eeb87a14b7ac3d222024f0aad6.tar.gz frameworks_base-854b2b1670bda1eeb87a14b7ac3d222024f0aad6.tar.bz2 |
Surface list of apps with given network policy.
Bug: 6007276
Change-Id: I0f0e939ee6481496480c4afaa108c99eb158547c
5 files changed, 67 insertions, 38 deletions
diff --git a/core/java/android/net/INetworkPolicyManager.aidl b/core/java/android/net/INetworkPolicyManager.aidl index 89c9c36..35e8e47 100644 --- a/core/java/android/net/INetworkPolicyManager.aidl +++ b/core/java/android/net/INetworkPolicyManager.aidl @@ -32,6 +32,7 @@ interface INetworkPolicyManager { /** Control UID policies. */ void setAppPolicy(int appId, int policy); int getAppPolicy(int appId); + int[] getAppsWithPolicy(int policy); boolean isUidForeground(int uid); diff --git a/core/java/android/net/NetworkPolicyManager.java b/core/java/android/net/NetworkPolicyManager.java index 2b36131..07bfd4b 100644 --- a/core/java/android/net/NetworkPolicyManager.java +++ b/core/java/android/net/NetworkPolicyManager.java @@ -92,6 +92,14 @@ public class NetworkPolicyManager { } } + public int[] getAppsWithPolicy(int policy) { + try { + return mService.getAppsWithPolicy(policy); + } catch (RemoteException e) { + return new int[0]; + } + } + public void registerListener(INetworkPolicyListener listener) { try { mService.registerListener(listener); diff --git a/core/java/com/android/internal/util/ArrayUtils.java b/core/java/com/android/internal/util/ArrayUtils.java index d1aa1ce..dbf6c8e 100644 --- a/core/java/com/android/internal/util/ArrayUtils.java +++ b/core/java/com/android/internal/util/ArrayUtils.java @@ -201,4 +201,40 @@ public class ArrayUtils } return array; } + + public static int[] appendInt(int[] cur, int val) { + if (cur == null) { + return new int[] { val }; + } + final int N = cur.length; + for (int i = 0; i < N; i++) { + if (cur[i] == val) { + return cur; + } + } + int[] ret = new int[N + 1]; + System.arraycopy(cur, 0, ret, 0, N); + ret[N] = val; + return ret; + } + + public static int[] removeInt(int[] cur, int val) { + if (cur == null) { + return null; + } + final int N = cur.length; + for (int i = 0; i < N; i++) { + if (cur[i] == val) { + int[] ret = new int[N - 1]; + if (i > 0) { + System.arraycopy(cur, 0, ret, 0, i); + } + if (i < (N - 1)) { + System.arraycopy(cur, i + 1, ret, i, N - i - 1); + } + return ret; + } + } + return cur; + } } diff --git a/services/java/com/android/server/net/NetworkPolicyManagerService.java b/services/java/com/android/server/net/NetworkPolicyManagerService.java index fa62e49..5408c42 100644 --- a/services/java/com/android/server/net/NetworkPolicyManagerService.java +++ b/services/java/com/android/server/net/NetworkPolicyManagerService.java @@ -50,6 +50,7 @@ import static android.net.NetworkTemplate.buildTemplateMobileAll; import static android.net.TrafficStats.MB_IN_BYTES; import static android.telephony.TelephonyManager.SIM_STATE_READY; import static android.text.format.DateUtils.DAY_IN_MILLIS; +import static com.android.internal.util.ArrayUtils.appendInt; import static com.android.internal.util.Preconditions.checkNotNull; import static com.android.server.NetworkManagementService.LIMIT_GLOBAL_ALERT; import static com.android.server.net.NetworkPolicyManagerService.XmlUtils.readBooleanAttribute; @@ -1216,6 +1217,23 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub { } @Override + public int[] getAppsWithPolicy(int policy) { + mContext.enforceCallingOrSelfPermission(MANAGE_NETWORK_POLICY, TAG); + + int[] appIds = new int[0]; + synchronized (mRulesLock) { + for (int i = 0; i < mAppPolicy.size(); i++) { + final int appId = mAppPolicy.keyAt(i); + final int appPolicy = mAppPolicy.valueAt(i); + if (appPolicy == policy) { + appIds = appendInt(appIds, appId); + } + } + } + return appIds; + } + + @Override public void registerListener(INetworkPolicyListener listener) { // TODO: create permission for observing network policy mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG); diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java index 1d02b7a3..0dbf3a5 100644 --- a/services/java/com/android/server/pm/PackageManagerService.java +++ b/services/java/com/android/server/pm/PackageManagerService.java @@ -16,12 +16,14 @@ package com.android.server.pm; +import static android.Manifest.permission.GRANT_REVOKE_PERMISSIONS; +import static android.Manifest.permission.READ_EXTERNAL_STORAGE; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DEFAULT; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER; import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED; -import static android.Manifest.permission.READ_EXTERNAL_STORAGE; -import static android.Manifest.permission.GRANT_REVOKE_PERMISSIONS; +import static com.android.internal.util.ArrayUtils.appendInt; +import static com.android.internal.util.ArrayUtils.removeInt; import static libcore.io.OsConstants.S_ISLNK; import com.android.internal.app.IMediaContainerService; @@ -1451,22 +1453,6 @@ public class PackageManagerService extends IPackageManager.Stub { } } - static int[] appendInt(int[] cur, int val) { - if (cur == null) { - return new int[] { val }; - } - final int N = cur.length; - for (int i=0; i<N; i++) { - if (cur[i] == val) { - return cur; - } - } - int[] ret = new int[N+1]; - System.arraycopy(cur, 0, ret, 0, N); - ret[N] = val; - return ret; - } - static int[] appendInts(int[] cur, int[] add) { if (add == null) return cur; if (cur == null) return add; @@ -1477,26 +1463,6 @@ public class PackageManagerService extends IPackageManager.Stub { return cur; } - static int[] removeInt(int[] cur, int val) { - if (cur == null) { - return null; - } - final int N = cur.length; - for (int i=0; i<N; i++) { - if (cur[i] == val) { - int[] ret = new int[N-1]; - if (i > 0) { - System.arraycopy(cur, 0, ret, 0, i); - } - if (i < (N-1)) { - System.arraycopy(cur, i + 1, ret, i, N - i - 1); - } - return ret; - } - } - return cur; - } - static int[] removeInts(int[] cur, int[] rem) { if (rem == null) return cur; if (cur == null) return cur; |