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

Commit 9be6c450 authored by Nathan Harold's avatar Nathan Harold Committed by Gerrit Code Review
Browse files

Merge "Move getTargetSdk to common location"

parents 634c55be 6ab80ad6
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;
    }
}