Revoke permission on non-runtime -> runtime upgrade

Not only on normal -> runtime.

Test: cts-tradefed run cts-dev -m CtsAppSecurityHostTestCases --test android.appsecurity.cts.PermissionsHostTest#testNoPermissionEscalationAfterReboot
Bug: 154505240, 168319670
Change-Id: If3b420067b4d7111dcf67ae6f98e42176158b679
Merged-In: If3b420067b4d7111dcf67ae6f98e42176158b679
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index fd9c4bb..a2607e1 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -11612,7 +11612,7 @@
                     permissionMap.put(p.info.name, bp);
                 }
 
-                boolean wasNormal = bp.type == BasePermission.TYPE_NORMAL;
+                boolean wasNonRuntime = !bp.isRuntime();
                 if (bp.perm == null) {
                     if (bp.sourcePackage == null
                             || bp.sourcePackage.equals(p.info.packageName)) {
@@ -11656,7 +11656,7 @@
                     bp.protectionLevel = p.info.protectionLevel;
                 }
 
-                if (bp.isRuntime() && (ownerChanged || wasNormal)) {
+                if (bp.isRuntime() && (ownerChanged || wasNonRuntime)) {
                     // If this is a runtime permission and the owner has changed, or this was a normal
                     // permission, then permission state should be cleaned up
                     bp.setPermissionDefinitionChanged(true);