Skip to content

Commit

Permalink
Check for null callerPackage in getStorageEncryptionStatus
Browse files Browse the repository at this point in the history
* This function assumes that callerPackage is always valid,
  even though the parameter is annotated nullable. Check
  and assume the function was called by the system if the
  callerPackage was null.

Change-Id: Ie936d401f666ac8022635fb49d9ab2adfb5916c4
Signed-off-by: Akhil Narang <[email protected]>
  • Loading branch information
intervigilium authored and sagarrokade006 committed Sep 25, 2020
1 parent 21cca08 commit 8e70e9d
Showing 1 changed file with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7866,20 +7866,24 @@ public int getStorageEncryptionStatus(@Nullable String callerPackage, int userHa
}
enforceFullCrossUsersPermission(userHandle);

// It's not critical here, but let's make sure the package name is correct, in case
// we start using it for different purposes.
ensureCallerPackage(callerPackage);

final ApplicationInfo ai;
try {
ai = mIPackageManager.getApplicationInfo(callerPackage, 0, userHandle);
} catch (RemoteException e) {
throw new SecurityException(e);
}

boolean legacyApp = false;
if (ai.targetSdkVersion <= Build.VERSION_CODES.M) {
legacyApp = true;
// callerPackage can only be null if we were called from within the system,
// which means that we are not a legacy app.
if (callerPackage != null) {
// It's not critical here, but let's make sure the package name is correct, in case
// we start using it for different purposes.
ensureCallerPackage(callerPackage);

final ApplicationInfo ai;
try {
ai = mIPackageManager.getApplicationInfo(callerPackage, 0, userHandle);
} catch (RemoteException e) {
throw new SecurityException(e);
}

if (ai.targetSdkVersion <= Build.VERSION_CODES.M) {
legacyApp = true;
}
}

final int rawStatus = getEncryptionStatus();
Expand Down

0 comments on commit 8e70e9d

Please sign in to comment.