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

Commit 467128ae 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." into rvc-qpr-dev

parents 530bebf0 97c29c74
Loading
Loading
Loading
Loading
+9 −11
Original line number Original line Diff line number Diff line
@@ -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) {
        }
        }