Merge "Move getTargetSdk to common location" am: 9be6c4500f
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1521058 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I99cdadfca70857e4330743516cf4739725add765
This commit is contained in:
@@ -651,4 +651,23 @@ public final class TelephonyPermissions {
|
|||||||
|
|
||||||
throw new SecurityException(message + ": Only shell user can call it");
|
throw new SecurityException(message + ": Only shell user can call it");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the target SDK version number for a given package name.
|
||||||
|
*
|
||||||
|
* This call MUST be invoked before clearing the calling UID.
|
||||||
|
*
|
||||||
|
* @return target SDK if the package is found or INT_MAX.
|
||||||
|
*/
|
||||||
|
public static int getTargetSdk(Context c, String packageName) {
|
||||||
|
try {
|
||||||
|
final ApplicationInfo ai = c.getPackageManager().getApplicationInfoAsUser(
|
||||||
|
packageName, 0, UserHandle.getUserHandleForUid(Binder.getCallingUid()));
|
||||||
|
if (ai != null) return ai.targetSdkVersion;
|
||||||
|
} catch (PackageManager.NameNotFoundException unexpected) {
|
||||||
|
Log.e(LOG_TAG, "Failed to get package info for pkg="
|
||||||
|
+ packageName + ", uid=" + Binder.getCallingUid());
|
||||||
|
}
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user