Merge cherrypicks of [2624661, 2624224] into oc-release

Change-Id: I37c6e10bca102f2cea44717868c3aac4267ad02e
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index c1b98f5..ddb5832 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -4006,8 +4006,10 @@
             final BasePermission p = mSettings.mPermissions.get(name);
             // If the caller is an app that targets pre 26 SDK drop protection flags.
             final PermissionInfo permissionInfo = generatePermissionInfo(p, flags);
-            permissionInfo.protectionLevel = adjustPermissionProtectionFlagsLPr(
-                    permissionInfo.protectionLevel, packageName, callingUid);
+            if (permissionInfo != null) {
+                permissionInfo.protectionLevel = adjustPermissionProtectionFlagsLPr(
+                        permissionInfo.protectionLevel, packageName, callingUid);
+            }
             return permissionInfo;
         }
     }