Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 770e20a1 authored by Nathan Harold's avatar Nathan Harold Committed by Automerger Merge Worker
Browse files

Merge "Move getTargetSdk to common location" am: 9be6c450 am: 044e52ef am: 861a1687

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1521058

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I6f575db84203b210862981c65b99246f620ce23a
parents 13556045 861a1687
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -683,4 +683,23 @@ public final class TelephonyPermissions {

        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;
    }
}