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

Commit 0362888f authored by Joanne Chung's avatar Joanne Chung Committed by Android (Google) Code Review
Browse files

Merge "Add APIs for optional uses-sdk-library" into main

parents 980f9739 f2322613
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13296,6 +13296,7 @@ package android.content.pm {
    method @NonNull public java.util.List<android.content.pm.VersionedPackage> getDependentPackages();
    method @IntRange(from=0xffffffff) public long getLongVersion();
    method public String getName();
    method @FlaggedApi("android.content.pm.sdk_lib_independence") @NonNull public java.util.List<android.content.pm.VersionedPackage> getOptionalDependentPackages();
    method public int getType();
    method @Deprecated @IntRange(from=0xffffffff) public int getVersion();
    method public void writeToParcel(android.os.Parcel, int);
+1 −0
Original line number Diff line number Diff line
@@ -136,6 +136,7 @@ package android.content {
package android.content.pm {

  public class ApplicationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
    method @FlaggedApi("android.content.pm.sdk_lib_independence") @NonNull public java.util.List<android.content.pm.SharedLibraryInfo> getOptionalSharedLibraryInfos();
    method @NonNull public java.util.List<android.content.pm.SharedLibraryInfo> getSharedLibraryInfos();
    field public static final int HIDDEN_API_ENFORCEMENT_DEFAULT = -1; // 0xffffffff
    field public static final int HIDDEN_API_ENFORCEMENT_DISABLED = 0; // 0x0
+37 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.content.pm;
import static android.os.Build.VERSION_CODES.DONUT;

import android.Manifest;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -1065,10 +1066,24 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
     * the structure.
     *
     * NOTE: the list also contains the result of {@link #getOptionalSharedLibraryInfos}.
     *
     * {@hide}
     */
    @Nullable
    public List<SharedLibraryInfo> sharedLibraryInfos;

    /**
     * List of all shared libraries this application is optionally linked against.
     * This field is only set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
     * PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving
     * the structure.
     *
     * @hide
     */
    @Nullable
    public List<SharedLibraryInfo> optionalSharedLibraryInfos;

    /**
     * Full path to the default directory assigned to the package for its
     * persistent data.
@@ -1937,6 +1952,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        seInfoUser = orig.seInfoUser;
        sharedLibraryFiles = orig.sharedLibraryFiles;
        sharedLibraryInfos = orig.sharedLibraryInfos;
        optionalSharedLibraryInfos = orig.optionalSharedLibraryInfos;
        dataDir = orig.dataDir;
        deviceProtectedDataDir = orig.deviceProtectedDataDir;
        credentialProtectedDataDir = orig.credentialProtectedDataDir;
@@ -2029,6 +2045,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        dest.writeString8(seInfoUser);
        dest.writeString8Array(sharedLibraryFiles);
        dest.writeTypedList(sharedLibraryInfos);
        dest.writeTypedList(optionalSharedLibraryInfos);
        dest.writeString8(dataDir);
        dest.writeString8(deviceProtectedDataDir);
        dest.writeString8(credentialProtectedDataDir);
@@ -2129,6 +2146,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        seInfoUser = source.readString8();
        sharedLibraryFiles = source.createString8Array();
        sharedLibraryInfos = source.createTypedArrayList(SharedLibraryInfo.CREATOR);
        optionalSharedLibraryInfos = source.createTypedArrayList(SharedLibraryInfo.CREATOR);
        dataDir = source.readString8();
        deviceProtectedDataDir = source.readString8();
        credentialProtectedDataDir = source.readString8();
@@ -2760,6 +2778,8 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     *  list will only be set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
     *  PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving the structure.
     *
     *  NOTE: the list also contains the result of {@link #getOptionalSharedLibraryInfos}.
     *
     * @hide
     */
    @NonNull
@@ -2771,6 +2791,23 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        return sharedLibraryInfos;
    }

    /**
     *  List of all shared libraries this application is optionally linked against. This
     *  list will only be set if the {@link PackageManager#GET_SHARED_LIBRARY_FILES
     *  PackageManager.GET_SHARED_LIBRARY_FILES} flag was used when retrieving the structure.
     *
     * @hide
     */
    @NonNull
    @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES)
    @FlaggedApi(Flags.FLAG_SDK_LIB_INDEPENDENCE)
    public List<SharedLibraryInfo> getOptionalSharedLibraryInfos() {
        if (optionalSharedLibraryInfos == null) {
            return Collections.EMPTY_LIST;
        }
        return optionalSharedLibraryInfos;
    }

    /**
     * Gets the trusted host certificate digests of apps that are allowed to embed activities of
     * this application. The digests are computed using the SHA-256 digest algorithm.
+78 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package android.content.pm;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.IntRange;
import android.annotation.NonNull;
@@ -23,6 +24,7 @@ import android.annotation.Nullable;
import android.annotation.TestApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Pair;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -99,12 +101,15 @@ public final class SharedLibraryInfo implements Parcelable {
    private final boolean mIsNative;
    private final VersionedPackage mDeclaringPackage;
    private final List<VersionedPackage> mDependentPackages;

    private final List<VersionedPackage> mOptionalDependentPackages;
    private List<SharedLibraryInfo> mDependencies;

    /**
     * Creates a new instance.
     *
     * @param codePaths For a non {@link #TYPE_BUILTIN builtin} library, the locations of jars of
     * @param codePaths         For a non {@link #TYPE_BUILTIN builtin} library, the locations of
     *                          jars of
     *                          this shared library. Null for builtin library.
     * @param name              The lib name.
     * @param version           The lib version if not builtin.
@@ -112,7 +117,6 @@ public final class SharedLibraryInfo implements Parcelable {
     * @param declaringPackage  The package that declares the library.
     * @param dependentPackages The packages that depend on the library.
     * @param isNative          indicate if this shared lib is a native lib or not (i.e. java)
     *
     * @hide
     */
    public SharedLibraryInfo(String path, String packageName, List<String> codePaths,
@@ -129,6 +133,58 @@ public final class SharedLibraryInfo implements Parcelable {
        mDependentPackages = dependentPackages;
        mDependencies = dependencies;
        mIsNative = isNative;
        mOptionalDependentPackages = null;
    }

    /**
     * Creates a new instance.
     *
     * @param codePaths For a non {@link #TYPE_BUILTIN builtin} library, the locations of jars of
     *                  this shared library. Null for builtin library.
     * @param name The lib name.
     * @param version The lib version if not builtin.
     * @param type The lib type.
     * @param declaringPackage The package that declares the library.
     * @param isNative indicate if this shared lib is a native lib or not (i.e. java)
     * @param allDependentPackages All packages that depend on the library (including the optional
     *                             sdk libraries).
     *
     * @hide
     */
    public SharedLibraryInfo(String path, String packageName, List<String> codePaths,
            String name, long version, int type,
            VersionedPackage declaringPackage,
            List<SharedLibraryInfo> dependencies, boolean isNative,
            Pair<List<VersionedPackage>, List<Boolean>> allDependentPackages) {
        mPath = path;
        mPackageName = packageName;
        mCodePaths = codePaths;
        mName = name;
        mVersion = version;
        mType = type;
        mDeclaringPackage = declaringPackage;
        mDependencies = dependencies;
        mIsNative = isNative;

        var allDependents = allDependentPackages.first;
        var usesLibOptional = allDependentPackages.second;
        mDependentPackages = allDependents;
        List<VersionedPackage> optionalDependents = null;
        if (mType == SharedLibraryInfo.TYPE_SDK_PACKAGE
                && Flags.sdkLibIndependence() && allDependents != null
                && usesLibOptional != null
                && allDependents.size() == usesLibOptional.size()) {
            for (int k = 0; k < allDependents.size(); k++) {
                VersionedPackage versionedPackage = allDependents.get(k);
                if (usesLibOptional.get(k)) {
                    if (optionalDependents == null) {
                        optionalDependents = new ArrayList<>();
                    }
                    optionalDependents.add(versionedPackage);
                }
            }
        }
        mOptionalDependentPackages = optionalDependents;
    }

    private SharedLibraryInfo(Parcel parcel) {
@@ -148,6 +204,8 @@ public final class SharedLibraryInfo implements Parcelable {
                parcel.readArrayList(null, android.content.pm.VersionedPackage.class);
        mDependencies = parcel.createTypedArrayList(SharedLibraryInfo.CREATOR);
        mIsNative = parcel.readBoolean();
        mOptionalDependentPackages = parcel.readParcelableList(new ArrayList<>(),
                VersionedPackage.class.getClassLoader(), VersionedPackage.class);
    }

    /**
@@ -324,6 +382,8 @@ public final class SharedLibraryInfo implements Parcelable {
    /**
     * Gets the packages that depend on the library.
     *
     * NOTE: the list also contains the result of {@link #getOptionalDependentPackages}.
     *
     * @return The dependent packages.
     */
    public @NonNull List<VersionedPackage> getDependentPackages() {
@@ -333,6 +393,19 @@ public final class SharedLibraryInfo implements Parcelable {
        return mDependentPackages;
    }

    /**
     * Gets the packages that optionally depend on the library.
     *
     * @return The dependent packages.
     */
    @FlaggedApi(Flags.FLAG_SDK_LIB_INDEPENDENCE)
    public @NonNull List<VersionedPackage> getOptionalDependentPackages() {
        if (mOptionalDependentPackages == null) {
            return Collections.emptyList();
        }
        return mOptionalDependentPackages;
    }

    @Override
    public int describeContents() {
        return 0;
@@ -362,6 +435,7 @@ public final class SharedLibraryInfo implements Parcelable {
        parcel.writeList(mDependentPackages);
        parcel.writeTypedList(mDependencies);
        parcel.writeBoolean(mIsNative);
        parcel.writeParcelableList(mOptionalDependentPackages, flags);
    }

    private static String typeToString(int type) {
+2 −6
Original line number Diff line number Diff line
@@ -3864,19 +3864,15 @@ public class ComputerEngine implements Computer {
                } finally {
                    Binder.restoreCallingIdentity(identity);
                }

                var usingSharedLibraryPair =
                        getPackagesUsingSharedLibrary(libInfo, flags, callingUid, userId);
                SharedLibraryInfo resLibInfo = new SharedLibraryInfo(libInfo.getPath(),
                        libInfo.getPackageName(), libInfo.getAllCodePaths(),
                        libInfo.getName(), libInfo.getLongVersion(),
                        libInfo.getType(), declaringPackage,
                        usingSharedLibraryPair.first,
                        (libInfo.getDependencies() == null
                                ? null
                                : new ArrayList<>(libInfo.getDependencies())),
                        libInfo.isNative());

                        libInfo.isNative(),
                        getPackagesUsingSharedLibrary(libInfo, flags, callingUid, userId));
                if (result == null) {
                    result = new ArrayList<>();
                }
Loading