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

Commit 6642c963 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android (Google) Code Review
Browse files

Merge "Grab lock when accessing mutable state" into nyc-mr1-dev

parents 9a236066 442ed57e
Loading
Loading
Loading
Loading
+31 −21
Original line number Diff line number Diff line
@@ -875,7 +875,7 @@ public class AppOpsService extends IAppOpsService.Stub {
            return AppOpsManager.MODE_IGNORED;
        }
        synchronized (this) {
            if (isOpRestricted(uid, code, resolvedPackageName)) {
            if (isOpRestrictedLocked(uid, code, resolvedPackageName)) {
                return AppOpsManager.MODE_IGNORED;
            }
            code = AppOpsManager.opToSwitch(code);
@@ -1024,7 +1024,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                return AppOpsManager.MODE_ERRORED;
            }
            Op op = getOpLocked(ops, code, true);
            if (isOpRestricted(uid, code, packageName)) {
            if (isOpRestrictedLocked(uid, code, packageName)) {
                return AppOpsManager.MODE_IGNORED;
            }
            if (op.duration == -1) {
@@ -1082,7 +1082,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                return AppOpsManager.MODE_ERRORED;
            }
            Op op = getOpLocked(ops, code, true);
            if (isOpRestricted(uid, code, resolvedPackageName)) {
            if (isOpRestrictedLocked(uid, code, resolvedPackageName)) {
                return AppOpsManager.MODE_IGNORED;
            }
            final int switchCode = AppOpsManager.opToSwitch(code);
@@ -1308,7 +1308,7 @@ public class AppOpsService extends IAppOpsService.Stub {
        return op;
    }

    private boolean isOpRestricted(int uid, int code, String packageName) {
    private boolean isOpRestrictedLocked(int uid, int code, String packageName) {
        int userHandle = UserHandle.getUserId(uid);
        final int restrictionSetCount = mOpUserRestrictions.size();

@@ -2210,6 +2210,9 @@ public class AppOpsService extends IAppOpsService.Stub {

    private void setUserRestrictionNoCheck(int code, boolean restricted, IBinder token,
            int userHandle, String[] exceptionPackages) {
        boolean notifyChange = false;

        synchronized (AppOpsService.this) {
            ClientRestrictionState restrictionState = mOpUserRestrictions.get(token);

            if (restrictionState == null) {
@@ -2222,7 +2225,7 @@ public class AppOpsService extends IAppOpsService.Stub {
            }

            if (restrictionState.setRestriction(code, restricted, exceptionPackages, userHandle)) {
            notifyWatchersOfChange(code);
                notifyChange = true;
            }

            if (restrictionState.isDefault()) {
@@ -2231,6 +2234,11 @@ public class AppOpsService extends IAppOpsService.Stub {
            }
        }

        if (notifyChange) {
            notifyWatchersOfChange(code);
        }
    }

    private void notifyWatchersOfChange(int code) {
        final ArrayList<Callback> clonedCallbacks;
        synchronized (this) {
@@ -2263,12 +2271,14 @@ public class AppOpsService extends IAppOpsService.Stub {
    @Override
    public void removeUser(int userHandle) throws RemoteException {
        checkSystemUid("removeUser");
        synchronized (AppOpsService.this) {
            final int tokenCount = mOpUserRestrictions.size();
            for (int i = tokenCount - 1; i >= 0; i--) {
                ClientRestrictionState opRestrictions = mOpUserRestrictions.valueAt(i);
                opRestrictions.removeUser(userHandle);
            }
        }
    }

    private void checkSystemUid(String function) {
        int uid = Binder.getCallingUid();