Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db696aed authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Update INTERNET perm state cache to use uids instead of appIds."

parents 87ce51b8 fa834065
Loading
Loading
Loading
Loading
+9 −11
Original line number Diff line number Diff line
@@ -587,7 +587,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {

    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")
    private final SparseBooleanArray mInternetPermissionMap = new SparseBooleanArray();

@@ -973,7 +973,7 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
                if (LOGV) Slog.v(TAG, "ACTION_PACKAGE_ADDED for uid=" + uid);
                // Clear the cache for the app
                synchronized (mUidRulesFirstLock) {
                    mInternetPermissionMap.delete(UserHandle.getAppId(uid));
                    mInternetPermissionMap.delete(uid);
                    updateRestrictionRulesForUidUL(uid);
                }
            }
@@ -4203,16 +4203,14 @@ public class NetworkPolicyManagerService extends INetworkPolicyManager.Stub {
    @GuardedBy("mUidRulesFirstLock")
    private boolean hasInternetPermissionUL(int uid) {
        try {
            final int appId = UserHandle.getAppId(uid);
            final boolean hasPermission;
            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 (mInternetPermissionMap.get(uid)) {
                return true;
            }
            // 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;
        } catch (RemoteException e) {
        }