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

Commit 6ab80ad6 authored by Nathan Harold's avatar Nathan Harold
Browse files

Move getTargetSdk to common location

Bug: 148559042
Test: compilation
Change-Id: Ib5d5e3591919287de819c4e329bacbda7befe76f
parent bdcdfa7c
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -651,4 +651,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;
    }
}