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

Commit adc30d31 authored by lpeter's avatar lpeter
Browse files

Update the API for getting AndroidManifest.xml info

Bug: 313822882
Test: atest PackageManagerTest
Change-Id: Id988856d05b0dd2f143f19746796643451151ed0
parent 89d2237e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -12815,7 +12815,7 @@ package android.content.pm {
    method public boolean isPackageSuspended();
    method @CheckResult public abstract boolean isPermissionRevokedByPolicy(@NonNull String, @NonNull String);
    method public abstract boolean isSafeMode();
    method @FlaggedApi("android.content.pm.get_package_info") @WorkerThread public <T> T parseAndroidManifest(@NonNull String, @NonNull java.util.function.Function<android.content.res.XmlResourceParser,T>) throws java.io.IOException;
    method @FlaggedApi("android.content.pm.get_package_info") @WorkerThread public <T> T parseAndroidManifest(@NonNull java.io.File, @NonNull java.util.function.Function<android.content.res.XmlResourceParser,T>) throws java.io.IOException;
    method @NonNull public java.util.List<android.content.pm.PackageManager.Property> queryActivityProperty(@NonNull String);
    method @NonNull public java.util.List<android.content.pm.PackageManager.Property> queryApplicationProperty(@NonNull String);
    method @NonNull public abstract java.util.List<android.content.pm.ResolveInfo> queryBroadcastReceivers(@NonNull android.content.Intent, int);
+6 −5
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ import dalvik.system.VMRuntime;

import libcore.util.EmptyArray;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
@@ -4038,11 +4039,11 @@ public class ApplicationPackageManager extends PackageManager {
    }

    @Override
    public <T> T parseAndroidManifest(@NonNull String apkFilePath,
    public <T> T parseAndroidManifest(@NonNull File apkFile,
            @NonNull Function<XmlResourceParser, T> parserFunction) throws IOException {
        Objects.requireNonNull(apkFilePath, "apkFilePath cannot be null");
        Objects.requireNonNull(apkFile, "apkFile cannot be null");
        Objects.requireNonNull(parserFunction, "parserFunction cannot be null");
        try (XmlResourceParser xmlResourceParser = getAndroidManifestParser(apkFilePath)) {
        try (XmlResourceParser xmlResourceParser = getAndroidManifestParser(apkFile)) {
            return parserFunction.apply(xmlResourceParser);
        } catch (IOException e) {
            Log.w(TAG, "Failed to get the android manifest parser", e);
@@ -4050,11 +4051,11 @@ public class ApplicationPackageManager extends PackageManager {
        }
    }

    private static XmlResourceParser getAndroidManifestParser(@NonNull String apkFilePath)
    private static XmlResourceParser getAndroidManifestParser(@NonNull File apkFile)
            throws IOException {
        ApkAssets apkAssets = null;
        try {
            apkAssets = ApkAssets.loadFromPath(apkFilePath);
            apkAssets = ApkAssets.loadFromPath(apkFile.getAbsolutePath());
            return apkAssets.openXml(ApkLiteParseUtils.ANDROID_MANIFEST_FILENAME);
        } finally {
            if (apkAssets != null) {
+6 −5
Original line number Diff line number Diff line
@@ -11534,14 +11534,14 @@ public abstract class PackageManager {
    }

    /**
     * Retrieve AndroidManifest.xml information for the given application apk path.
     * Retrieve AndroidManifest.xml information for the given application apk file.
     *
     * <p>Example:
     *
     * <pre><code>
     * Bundle result;
     * try {
     *     result = getContext().getPackageManager().parseAndroidManifest(apkFilePath,
     *     result = getContext().getPackageManager().parseAndroidManifest(apkFile,
     *             xmlResourceParser -> {
     *                 Bundle bundle = new Bundle();
     *                 // Search the start tag
@@ -11570,9 +11570,10 @@ public abstract class PackageManager {
     *
     * Note: When the parserFunction is invoked, the client can read the AndroidManifest.xml
     * information by the XmlResourceParser object. After leaving the parserFunction, the
     * XmlResourceParser object will be closed.
     * XmlResourceParser object will be closed. The caller should also handle the exception for
     * calling this method.
     *
     * @param apkFilePath The path of an application apk file.
     * @param apkFile The file of an application apk.
     * @param parserFunction The parserFunction will be invoked with the XmlResourceParser object
     *        after getting the AndroidManifest.xml of an application package.
     *
@@ -11583,7 +11584,7 @@ public abstract class PackageManager {
     */
    @FlaggedApi(android.content.pm.Flags.FLAG_GET_PACKAGE_INFO)
    @WorkerThread
    public <T> T parseAndroidManifest(@NonNull String apkFilePath,
    public <T> T parseAndroidManifest(@NonNull File apkFile,
            @NonNull Function<XmlResourceParser, T> parserFunction) throws IOException {
        throw new UnsupportedOperationException(
                "parseAndroidManifest not implemented in subclass");