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

Commit e924c723 authored by Svet Ganov's avatar Svet Ganov Committed by android-build-merger
Browse files

Grab lock when accessing mutable state am: 442ed57e am: e1790d92

am: b8e820a2

Change-Id: I01e8027dde6568d3044aad03688d98c4e4789696
parents e22c7a41 b8e820a2
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();