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

Commit c5f504a7 authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Don't throw exception in AppOpsManager.checkOp

In Q we handled the case where the op does not match the package name by
returning the default state. NoteOp and StartOp returned errored.

Fix up these scenarios.

Test: - atest CtsAppOpsTestCases
      - backported new test to Q to verify the behavior is the same in Q
        and master
Bug: 132885449
Change-Id: I5b94e92af759580f2d2644ece49f159bd006b31c
parent f06c2266
Loading
Loading
Loading
Loading
+12 −5
Original line number Diff line number Diff line
@@ -1749,7 +1749,14 @@ public class AppOpsService extends IAppOpsService.Stub {
     */
    private @Mode int checkOperationUnchecked(int code, int uid, @NonNull String packageName,
                boolean raw) {
        boolean isPrivileged = verifyAndGetIsPrivileged(uid, packageName);
        boolean isPrivileged;

        try {
            isPrivileged = verifyAndGetIsPrivileged(uid, packageName);
        } catch (SecurityException e) {
            Slog.e(TAG, "checkOperation", e);
            return AppOpsManager.opToDefaultMode(code);
        }

        synchronized (this) {
            if (isOpRestrictedLocked(uid, code, packageName, isPrivileged)) {
@@ -1939,8 +1946,8 @@ public class AppOpsService extends IAppOpsService.Stub {
        try {
            isPrivileged = verifyAndGetIsPrivileged(uid, packageName);
        } catch (SecurityException e) {
            Slog.e(TAG, "Cannot startOperation", e);
            return AppOpsManager.MODE_IGNORED;
            Slog.e(TAG, "noteOperation", e);
            return AppOpsManager.MODE_ERRORED;
        }

        synchronized (this) {
@@ -2117,8 +2124,8 @@ public class AppOpsService extends IAppOpsService.Stub {
        try {
            isPrivileged = verifyAndGetIsPrivileged(uid, packageName);
        } catch (SecurityException e) {
            Slog.e(TAG, "Cannot startOperation", e);
            return AppOpsManager.MODE_IGNORED;
            Slog.e(TAG, "startOperation", e);
            return AppOpsManager.MODE_ERRORED;
        }

        synchronized (this) {