Merge "Update INTERNET perm state cache to use uids instead of appIds." into rvc-qpr-dev am: 467128aef5
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/12748119 Change-Id: I78222391b83a4add8e964340ec08bb8a1306e1c6
This commit is contained in:
@@ -586,7 +586,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
|
|
||||||
private final NetworkPolicyLogger mLogger = new NetworkPolicyLogger();
|
private final NetworkPolicyLogger mLogger = new NetworkPolicyLogger();
|
||||||
|
|
||||||
/** List of apps indexed by appId and whether they have the internet permission */
|
/** List of apps indexed by uid and whether they have the internet permission */
|
||||||
@GuardedBy("mUidRulesFirstLock")
|
@GuardedBy("mUidRulesFirstLock")
|
||||||
private final SparseBooleanArray mInternetPermissionMap = new SparseBooleanArray();
|
private final SparseBooleanArray mInternetPermissionMap = new SparseBooleanArray();
|
||||||
|
|
||||||
@@ -972,7 +972,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
if (LOGV) Slog.v(TAG, "ACTION_PACKAGE_ADDED for uid=" + uid);
|
if (LOGV) Slog.v(TAG, "ACTION_PACKAGE_ADDED for uid=" + uid);
|
||||||
// Clear the cache for the app
|
// Clear the cache for the app
|
||||||
synchronized (mUidRulesFirstLock) {
|
synchronized (mUidRulesFirstLock) {
|
||||||
mInternetPermissionMap.delete(UserHandle.getAppId(uid));
|
mInternetPermissionMap.delete(uid);
|
||||||
updateRestrictionRulesForUidUL(uid);
|
updateRestrictionRulesForUidUL(uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4194,16 +4194,14 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
|
|||||||
@GuardedBy("mUidRulesFirstLock")
|
@GuardedBy("mUidRulesFirstLock")
|
||||||
private boolean hasInternetPermissionUL(int uid) {
|
private boolean hasInternetPermissionUL(int uid) {
|
||||||
try {
|
try {
|
||||||
final int appId = UserHandle.getAppId(uid);
|
if (mInternetPermissionMap.get(uid)) {
|
||||||
final boolean hasPermission;
|
return true;
|
||||||
if (mInternetPermissionMap.indexOfKey(appId) < 0) {
|
|
||||||
hasPermission =
|
|
||||||
mIPm.checkUidPermission(Manifest.permission.INTERNET, uid)
|
|
||||||
== PackageManager.PERMISSION_GRANTED;
|
|
||||||
mInternetPermissionMap.put(appId, hasPermission);
|
|
||||||
} else {
|
|
||||||
hasPermission = mInternetPermissionMap.get(appId);
|
|
||||||
}
|
}
|
||||||
|
// If the cache shows that uid doesn't have internet permission,
|
||||||
|
// then always re-check with PackageManager just to be safe.
|
||||||
|
final boolean hasPermission = mIPm.checkUidPermission(Manifest.permission.INTERNET,
|
||||||
|
uid) == PackageManager.PERMISSION_GRANTED;
|
||||||
|
mInternetPermissionMap.put(uid, hasPermission);
|
||||||
return hasPermission;
|
return hasPermission;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user