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

Commit 050de3f7 authored by Winson's avatar Winson
Browse files

Add getTargetSdkVersion without AppInfo

For quickly checking an app's targetSdkVersion without building and
returning an entire ApplicationInfo object.

Bug: 164459559

Test: atest android.content.pm.cts.PackageManagerTest#testGetInfo

Change-Id: Ibe1a3e977cd71b23e26395eb6cc73f61c1a85a0e
parent 40e1467f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -12061,6 +12061,7 @@ package android.content.pm {
    method public boolean getSyntheticAppDetailsActivityEnabled(@NonNull String);
    method @NonNull public abstract android.content.pm.FeatureInfo[] getSystemAvailableFeatures();
    method @Nullable public abstract String[] getSystemSharedLibraryNames();
    method @IntRange(from=0) public int getTargetSdkVersion(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException;
    method @Nullable public abstract CharSequence getText(@NonNull String, @StringRes int, @Nullable android.content.pm.ApplicationInfo);
    method @NonNull public abstract android.graphics.drawable.Drawable getUserBadgedDrawableForDensity(@NonNull android.graphics.drawable.Drawable, @NonNull android.os.UserHandle, @Nullable android.graphics.Rect, int);
    method @NonNull public abstract android.graphics.drawable.Drawable getUserBadgedIcon(@NonNull android.graphics.drawable.Drawable, @NonNull android.os.UserHandle);
+13 −0
Original line number Diff line number Diff line
@@ -470,6 +470,19 @@ public class ApplicationPackageManager extends PackageManager {
        return info;
    }

    @Override
    public int getTargetSdkVersion(@NonNull String packageName) throws NameNotFoundException {
        try {
            int version = mPM.getTargetSdkVersion(packageName);
            if (version != -1) {
                return version;
            }
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
        throw new PackageManager.NameNotFoundException(packageName);
    }

    @Override
    public ActivityInfo getActivityInfo(ComponentName className, int flags)
            throws NameNotFoundException {
+5 −0
Original line number Diff line number Diff line
@@ -82,6 +82,11 @@ interface IPackageManager {
    @UnsupportedAppUsage
    ApplicationInfo getApplicationInfo(String packageName, int flags ,int userId);

    /**
     * @return the target SDK for the given package name, or -1 if it cannot be retrieved
     */
    int getTargetSdkVersion(String packageName);

    @UnsupportedAppUsage
    ActivityInfo getActivityInfo(in ComponentName className, int flags, int userId);

+9 −0
Original line number Diff line number Diff line
@@ -4098,6 +4098,15 @@ public abstract class PackageManager {
        return getApplicationInfoAsUser(packageName, flags, user.getIdentifier());
    }

    /**
     * @return The target SDK version for the given package name.
     * @throws NameNotFoundException if a package with the given name cannot be found on the system.
     */
    @IntRange(from = 0)
    public int getTargetSdkVersion(@NonNull String packageName) throws NameNotFoundException {
        throw new UnsupportedOperationException();
    }

    /**
     * Retrieve all of the information we know about a particular activity
     * class.
+1 −0
Original line number Diff line number Diff line
@@ -12061,6 +12061,7 @@ package android.content.pm {
    method public boolean getSyntheticAppDetailsActivityEnabled(@NonNull String);
    method @NonNull public abstract android.content.pm.FeatureInfo[] getSystemAvailableFeatures();
    method @Nullable public abstract String[] getSystemSharedLibraryNames();
    method @IntRange(from=0) public int getTargetSdkVersion(@NonNull String) throws android.content.pm.PackageManager.NameNotFoundException;
    method @Nullable public abstract CharSequence getText(@NonNull String, @StringRes int, @Nullable android.content.pm.ApplicationInfo);
    method @NonNull public abstract android.graphics.drawable.Drawable getUserBadgedDrawableForDensity(@NonNull android.graphics.drawable.Drawable, @NonNull android.os.UserHandle, @Nullable android.graphics.Rect, int);
    method @NonNull public abstract android.graphics.drawable.Drawable getUserBadgedIcon(@NonNull android.graphics.drawable.Drawable, @NonNull android.os.UserHandle);
Loading