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

Commit f63e2bd3 authored by Peter Li's avatar Peter Li Committed by Android (Google) Code Review
Browse files

Merge "Update the API for getting AndroidManifest.xml info" into main

parents d8da3a17 adc30d31
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -12817,7 +12817,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");