Merge cherrypicks of [4902728, 4902589, 4902590] into oc-m7-release

Change-Id: I5407f09b1990560b4908fd78be454f3e57d7a363
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 287bce5..d6b5728 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -624,8 +624,6 @@
      */
     private static final boolean DEFAULT_PACKAGE_PARSER_CACHE_ENABLED = true;
 
-    private static final int PROTECTION_MASK_BASE = 0xf;
-
     final ServiceThread mHandlerThread;
 
     final PackageHandler mHandler;
@@ -5763,12 +5761,11 @@
 
     @Override
     public void revokeRuntimePermission(String packageName, String name, int userId) {
-        revokeRuntimePermission(packageName, name, userId, false /* Only if not fixed by policy */,
-                mSettings.getPermission(name));
+        revokeRuntimePermission(packageName, name, userId, false /* Only if not fixed by policy */);
     }
 
     private void revokeRuntimePermission(String packageName, String name, int userId,
-            boolean overridePolicy, BasePermission bp) {
+            boolean overridePolicy) {
         if (!sUserManager.exists(userId)) {
             Log.e(TAG, "No such user:" + userId);
             return;
@@ -5794,6 +5791,7 @@
                     || filterAppAccessLPr(ps, Binder.getCallingUid(), userId)) {
                 throw new IllegalArgumentException("Unknown package: " + packageName);
             }
+            final BasePermission bp = mSettings.mPermissions.get(name);
             if (bp == null) {
                 throw new IllegalArgumentException("Unknown permission: " + name);
             }
@@ -5915,7 +5913,7 @@
 
                                 try {
                                     revokeRuntimePermission(packageName, permissionName, userId,
-                                           false, mSettings.getPermission(permissionName));
+                                           false);
                                 } catch (IllegalArgumentException e) {
                                     Slog.e(TAG, "Could not revoke " + permissionName + " from "
                                             + packageName, e);
@@ -12794,10 +12792,7 @@
             if (DEBUG_REMOVE) Log.d(TAG, "  Activities: " + r);
         }
 
-        final ArrayList<String> allPackageNames = new ArrayList<>(mPackages.keySet());
-
         N = pkg.permissions.size();
-        List<BasePermission> bps = new ArrayList<BasePermission>(N);
         r = null;
         for (i=0; i<N; i++) {
             PackageParser.Permission p = pkg.permissions.get(i);
@@ -12806,10 +12801,6 @@
                 bp = mSettings.mPermissionTrees.get(p.info.name);
             }
             if (bp != null && bp.perm == p) {
-                if (((p.info.protectionLevel & PROTECTION_MASK_BASE) &
-                        PermissionInfo.PROTECTION_DANGEROUS) != 0) {
-                    bps.add(bp);
-                }
                 bp.perm = null;
                 if (DEBUG_REMOVE && chatty) {
                     if (r == null) {
@@ -12827,45 +12818,6 @@
                 }
             }
         }
-
-        AsyncTask.execute(() -> {
-            final int numRemovedPermissions = bps.size();
-            for (int permissionNum = 0; permissionNum < numRemovedPermissions; permissionNum++) {
-                final int[] userIds = mUserManagerInternal.getUserIds();
-                final int numUserIds = userIds.length;
-
-                final int numPackages = allPackageNames.size();
-                for (int packageNum = 0; packageNum < numPackages; packageNum++) {
-                    final String packageName = allPackageNames.get(packageNum);
-                    final PackageManagerInternal packageManagerInt =
-                            LocalServices.getService(PackageManagerInternal.class);
-                    final ApplicationInfo applicationInfo = packageManagerInt.getApplicationInfo(
-                            packageName, 0, Process.SYSTEM_UID, UserHandle.USER_SYSTEM);
-                    if (applicationInfo != null
-                            && applicationInfo.targetSdkVersion < Build.VERSION_CODES.M) {
-                        continue;
-                    }
-                    for (int userIdNum = 0; userIdNum < numUserIds; userIdNum++) {
-                        final int userId = userIds[userIdNum];
-                        final String permissionName = bps.get(permissionNum).name;
-                        if (checkPermission(permissionName, packageName,
-                                userId) == PackageManager.PERMISSION_GRANTED) {
-                            try {
-                                revokeRuntimePermission(packageName,
-                                        permissionName,
-                                        userId,
-                                        false,
-                                        bps.get(permissionNum));
-                            } catch (IllegalArgumentException e) {
-                                Slog.e(TAG, "Could not revoke " + permissionName + " from "
-                                        + packageName, e);
-                            }
-                        }
-                    }
-                }
-            }
-        });
-
         if (r != null) {
             if (DEBUG_REMOVE) Log.d(TAG, "  Permissions: " + r);
         }
@@ -25573,7 +25525,7 @@
         public void revokeRuntimePermission(String packageName, String name, int userId,
                 boolean overridePolicy) {
             PackageManagerService.this.revokeRuntimePermission(packageName, name, userId,
-                    overridePolicy, mSettings.getPermission(name));
+                    overridePolicy);
         }
 
         @Override
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index c116d83..56835f6 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -449,17 +449,6 @@
         mBackupStoppedPackagesFilename = new File(mSystemDir, "packages-stopped-backup.xml");
     }
 
-    public @Nullable BasePermission getPermission(@NonNull String permName) {
-        synchronized (mLock) {
-            return getPermissionLocked(permName);
-        }
-    }
-
-    @GuardedBy("mLock")
-    @Nullable BasePermission getPermissionLocked(@NonNull String permName) {
-        return mPermissions.get(permName);
-    }
-
     PackageSetting getPackageLPr(String pkgName) {
         return mPackages.get(pkgName);
     }