DO NOT MERGE 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
Bug: 146463528
Bug: 146590200
Change-Id: I5b94e92af759580f2d2644ece49f159bd006b31c
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index b97b7f1..d45bc72a 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -1814,7 +1814,14 @@
             return AppOpsManager.MODE_IGNORED;
         }
 
-        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)) {
@@ -2004,8 +2011,8 @@
         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) {
@@ -2182,8 +2189,8 @@
         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) {