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

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

Merge "Make sure unsafeCheckOpRaw ops check raw ops"

parents 9916497f 9d528a11
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3078,7 +3078,7 @@ public class AppOpsManager {
     */
    public int unsafeCheckOpRaw(String op, int uid, String packageName) {
        try {
            return mService.checkOperation(strOpToOp(op), uid, packageName);
            return mService.checkOperationRaw(strOpToOp(op), uid, packageName);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+3 −2
Original line number Diff line number Diff line
@@ -37,10 +37,11 @@ public abstract class AppOpsManagerInternal {
         * @param uid The UID for which to check.
         * @param packageName The package for which to check.
         * @param superImpl The super implementation.
         * @param raw Whether to check the raw op i.e. not interpret the mode based on UID state.
         * @return The app op check result.
         */
        int checkOperation(int code, int uid, String packageName,
                TriFunction<Integer, Integer, String, Integer> superImpl);
        int checkOperation(int code, int uid, String packageName, boolean raw,
                QuadFunction<Integer, Integer, String, Boolean, Integer> superImpl);

        /**
         * Allows overriding check audio operation behavior.
+2 −0
Original line number Diff line number Diff line
@@ -65,4 +65,6 @@ interface IAppOpsService {

    void startWatchingNoted(in int[] ops, IAppOpsNotedCallback callback);
    void stopWatchingNoted(IAppOpsNotedCallback callback);

    int checkOperationRaw(int code, int uid, String packageName);
}
+18 −7
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import android.os.ServiceManager;
import android.os.ShellCallback;
import android.os.ShellCommand;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.storage.StorageManager;
@@ -1645,30 +1644,41 @@ public class AppOpsService extends IAppOpsService.Stub {
        }
    }

    @Override
    public int checkOperationRaw(int code, int uid, String packageName) {
        return checkOperationInternal(code, uid, packageName, true /*raw*/);
    }

    @Override
    public int checkOperation(int code, int uid, String packageName) {
        return checkOperationInternal(code, uid, packageName, false /*raw*/);
    }

    private int checkOperationInternal(int code, int uid, String packageName, boolean raw) {
        final CheckOpsDelegate delegate;
        synchronized (this) {
            delegate = mCheckOpsDelegate;
        }
        if (delegate == null) {
            return checkOperationImpl(code, uid, packageName);
            return checkOperationImpl(code, uid, packageName, raw);
        }
        return delegate.checkOperation(code, uid, packageName,
        return delegate.checkOperation(code, uid, packageName, raw,
                    AppOpsService.this::checkOperationImpl);
    }

    private int checkOperationImpl(int code, int uid, String packageName) {
    private int checkOperationImpl(int code, int uid, String packageName,
                boolean raw) {
        verifyIncomingUid(uid);
        verifyIncomingOp(code);
        String resolvedPackageName = resolvePackageName(uid, packageName);
        if (resolvedPackageName == null) {
            return AppOpsManager.MODE_IGNORED;
        }
        return checkOperationUnchecked(code, uid, resolvedPackageName);
        return checkOperationUnchecked(code, uid, resolvedPackageName, raw);
    }

    private int checkOperationUnchecked(int code, int uid, String packageName) {
    private int checkOperationUnchecked(int code, int uid, String packageName,
                boolean raw) {
        synchronized (this) {
            if (isOpRestrictedLocked(uid, code, packageName)) {
                return AppOpsManager.MODE_IGNORED;
@@ -1677,7 +1687,8 @@ public class AppOpsService extends IAppOpsService.Stub {
            UidState uidState = getUidStateLocked(uid, false);
            if (uidState != null && uidState.opModes != null
                    && uidState.opModes.indexOfKey(code) >= 0) {
                return uidState.evalMode(uidState.opModes.get(code));
                final int rawMode = uidState.opModes.get(code);
                return raw ? rawMode : uidState.evalMode(rawMode);
            }
            Op op = getOpLocked(code, uid, packageName, false, true, false);
            if (op == null) {
+4 −4
Original line number Diff line number Diff line
@@ -20117,18 +20117,18 @@ public class ActivityManagerService extends IActivityManager.Stub
        }
        @Override
        public int checkOperation(int code, int uid, String packageName,
                TriFunction<Integer, Integer, String, Integer> superImpl) {
        public int checkOperation(int code, int uid, String packageName, boolean raw,
                QuadFunction<Integer, Integer, String, Boolean, Integer> superImpl) {
            if (uid == mTargetUid && isTargetOp(code)) {
                final long identity = Binder.clearCallingIdentity();
                try {
                    return superImpl.apply(code, Process.SHELL_UID,
                            "com.android.shell");
                            "com.android.shell", raw);
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }
            }
            return superImpl.apply(code, uid, packageName);
            return superImpl.apply(code, uid, packageName, raw);
        }
        @Override