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

Commit 243e7ea1 authored by Winson's avatar Winson
Browse files

Deprecate PackageParser#Package

Replaces PackageParser#Package and it's related structures with
ParsingPackage, ParsedPackage, and AndroidPackage.

This is a large scoped CL, the first step in an eventual goal
to refactor how data is handled in the package parsing and install
process. It introduces as few logic changes as necessary. Mostly
migrating to interfaces and renaming, moving parsing data calls into
3 separate interfaces that outline the intended flow for parsing.

ParsingPackage is built and used during what was PackageParser, now
replaced by ApkParseUtils and it's related classes. This is almost
exactly what was parsed from the XML/files on disk.

ParsedPackage is used when the object exits PackageParser and is
adjusted by PackageManagerService to what is considered the final
"parsed" state, adjusted from literal values, but consistent given
the same APK on disk. This should eventually be moved out of PMS
and possibly collapsed into the previous interface entirely.

AndroidPackage is the final state of the package after parsing and
adjustment has completed and no more mutations should be expected.
There are a few exceptions to this, included in AndroidPackageWrite,
which will eventually be refactored into PackageSetting or another
state class.

This marks PackageParser#Package and all the old infrastructure with
@Deprecated, as none of them are used internally. All usages were
converted, and the legacy Package is only built for un-converted tests
and @UnsupportedAppUsage methods.

There are numerous TODOs still outstanding, but addressing them
in this initial CL would introduce several logic changes. They've been
marked with the bug number and will be handled in follow ups.

This is being merged with caution thrown to the wind because
testing this on devices and in development will be the best way
to debug differences introduced by the migration. Getting it merged
as early as possible gives the most amount of time to fix regressions.

Waiting for tests of all the functionality could take literal years
before covering enough to merge this with all regressions verified.

Given a sample size of 4 heap dumps and the caveat it was taken very
early in the migration, there is a memory overhead of about 200 KB
versus the legacy implementation. This should be verified more
accurately and addressed in follow ups.

This CL also kills child/parent package support, since that's
broken already, and difficult to support with the new interface
structure.

Bug: 135203078

Test: booted an emulator, works generally as expected

Specific tests which failed / failed to build were fixed, but because
not all tests are currently passing before this change, not all were
verified.

Change-Id: I4ba050c228e6c60b8f63a9e3347b1f9a57ef794a
parent 42521834
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -305,7 +305,7 @@ java_defaults {

    exclude_srcs: [
        // See comment on framework-atb-backward-compatibility module below
        "core/java/android/content/pm/AndroidTestBaseUpdater.java",
        "core/java/android/content/pm/parsing/library/AndroidTestBaseUpdater.java",
    ],

    sdk_version: "core_platform",
@@ -435,7 +435,7 @@ java_library {
    name: "framework-atb-backward-compatibility",
    installable: true,
    srcs: [
        "core/java/android/content/pm/AndroidTestBaseUpdater.java",
        "core/java/android/content/pm/parsing/library/AndroidTestBaseUpdater.java",
    ],
}

+6 −6
Original line number Diff line number Diff line
@@ -877,7 +877,7 @@ android.content.pm.-$$Lambda$jpya2qgMDDEok2GAoKRDqPM5lIE
android.content.pm.ActivityInfo$1
android.content.pm.ActivityInfo$WindowLayout
android.content.pm.ActivityInfo
android.content.pm.AndroidHidlUpdater
android.content.pm.parsing.library.AndroidHidlUpdater
android.content.pm.ApplicationInfo$1
android.content.pm.ApplicationInfo
android.content.pm.BaseParceledListSlice
@@ -921,10 +921,10 @@ android.content.pm.LauncherApps$1
android.content.pm.LauncherApps
android.content.pm.ModuleInfo$1
android.content.pm.ModuleInfo
android.content.pm.OrgApacheHttpLegacyUpdater
android.content.pm.PackageBackwardCompatibility$AndroidTestRunnerSplitUpdater
android.content.pm.PackageBackwardCompatibility$RemoveUnnecessaryAndroidTestBaseLibrary
android.content.pm.PackageBackwardCompatibility
android.content.pm.parsing.library.OrgApacheHttpLegacyUpdater
android.content.pm.parsing.library.PackageBackwardCompatibility$AndroidTestRunnerSplitUpdater
android.content.pm.parsing.library.PackageBackwardCompatibility$RemoveUnnecessaryAndroidTestBaseLibrary
android.content.pm.parsing.library.PackageBackwardCompatibility
android.content.pm.PackageInfo$1
android.content.pm.PackageInfo
android.content.pm.PackageInstaller$Session
@@ -959,7 +959,7 @@ android.content.pm.PackageParser$SigningDetails$1
android.content.pm.PackageParser$SigningDetails
android.content.pm.PackageParser$SplitNameComparator
android.content.pm.PackageParser
android.content.pm.PackageSharedLibraryUpdater
android.content.pm.parsing.library.PackageSharedLibraryUpdater
android.content.pm.PackageStats$1
android.content.pm.PackageStats
android.content.pm.PackageUserState
+2 −1
Original line number Diff line number Diff line
@@ -1379,7 +1379,8 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
            this.minHeight = minHeight;
        }

        WindowLayout(Parcel source) {
        /** @hide */
        public WindowLayout(Parcel source) {
            width = source.readInt();
            widthFraction = source.readFloat();
            height = source.readInt();
+2 −1
Original line number Diff line number Diff line
@@ -373,8 +373,9 @@ public class PackageInfo implements Parcelable {

    /**
     * Whether the overlay is static, meaning it cannot be enabled/disabled at runtime.
     * @hide
     */
    boolean mOverlayIsStatic;
    public boolean mOverlayIsStatic;

    /**
     * The user-visible SDK version (ex. 26) of the framework against which the application claims
+21 −12
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import android.content.pm.PackageManager.ApplicationInfoFlags;
import android.content.pm.PackageManager.ComponentInfoFlags;
import android.content.pm.PackageManager.PackageInfoFlags;
import android.content.pm.PackageManager.ResolveInfoFlags;
import android.content.pm.parsing.AndroidPackage;
import android.content.pm.parsing.ComponentParseUtils;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.ArraySet;
@@ -315,7 +317,7 @@ public abstract class PackageManagerInternal {
     * @param installed the new installed state
     * @return true if the installed state changed as a result
     */
    public abstract boolean setInstalled(PackageParser.Package pkg,
    public abstract boolean setInstalled(AndroidPackage pkg,
            @UserIdInt int userId, boolean installed);

    /**
@@ -394,7 +396,7 @@ public abstract class PackageManagerInternal {
     * Returns whether or not the given package represents a legacy system application released
     * prior to runtime permissions.
     */
    public abstract boolean isLegacySystemApp(PackageParser.Package pkg);
    public abstract boolean isLegacySystemApp(AndroidPackage pkg);

    /**
     * Get all overlay packages for a user.
@@ -486,13 +488,17 @@ public abstract class PackageManagerInternal {
    /**
     * Returns a package object for the given package name.
     */
    public abstract @Nullable PackageParser.Package getPackage(@NonNull String packageName);
    public abstract @Nullable AndroidPackage getPackage(@NonNull String packageName);

    // TODO(b/135203078): PackageSetting can't be referenced directly. Should move to a server side
    //  internal PM which is aware of PS.
    public abstract @Nullable Object getPackageSetting(String packageName);

    /**
     * Returns a package for the given UID. If the UID is part of a shared user ID, one
     * of the packages will be chosen to be returned.
     */
    public abstract @Nullable PackageParser.Package getPackage(int uid);
    public abstract @Nullable AndroidPackage getPackage(int uid);

    /**
     * Returns a list without a change observer.
@@ -523,17 +529,19 @@ public abstract class PackageManagerInternal {
     */
    public abstract void removePackageListObserver(@NonNull PackageListObserver observer);

    // TODO(b/135203078): PackageSetting can't be referenced directly
    /**
     * Returns a package object for the disabled system package name.
     */
    public abstract @Nullable PackageParser.Package getDisabledSystemPackage(
            @NonNull String packageName);
    public abstract @Nullable Object getDisabledSystemPackage(@NonNull String packageName);

    /**
     * Returns the package name for the disabled system package.
     *
     * This is equivalent to
     * {@link #getDisabledSystemPackage(String)}.{@link PackageParser.Package#packageName}
     * {@link #getDisabledSystemPackage(String)}
     *     .{@link com.android.server.pm.PackageSetting#pkg}
     *     .{@link AndroidPackage#getPackageName()}
     */
    public abstract @Nullable String getDisabledSystemPackageName(@NonNull String packageName);

@@ -567,7 +575,7 @@ public abstract class PackageManagerInternal {
     * @see #canAccessInstantApps
     */
    public abstract boolean filterAppAccess(
            @NonNull PackageParser.Package pkg, int callingUid, int userId);
            @NonNull AndroidPackage pkg, int callingUid, int userId);

    /**
     * Returns whether or not access to the application should be filtered.
@@ -641,7 +649,8 @@ public abstract class PackageManagerInternal {
            throws IOException;

    /** Returns {@code true} if the specified component is enabled and matches the given flags. */
    public abstract boolean isEnabledAndMatches(@NonNull ComponentInfo info, int flags, int userId);
    public abstract boolean isEnabledAndMatches(
            @NonNull ComponentParseUtils.ParsedComponent component, int flags, int userId);

    /** Returns {@code true} if the given user requires extra badging for icons. */
    public abstract boolean userNeedsBadging(int userId);
@@ -652,14 +661,14 @@ public abstract class PackageManagerInternal {
     *
     * @param actionLocked action to be performed
     */
    public abstract void forEachPackage(Consumer<PackageParser.Package> actionLocked);
    public abstract void forEachPackage(Consumer<AndroidPackage> actionLocked);

    /**
     * Perform the given action for each installed package for a user.
     * Note that packages lock will be held while performin the actions.
     */
    public abstract void forEachInstalledPackage(
            @NonNull Consumer<PackageParser.Package> actionLocked, @UserIdInt int userId);
            @NonNull Consumer<AndroidPackage> actionLocked, @UserIdInt int userId);

    /** Returns the list of enabled components */
    public abstract ArraySet<String> getEnabledComponents(String packageName, int userId);
@@ -793,7 +802,7 @@ public abstract class PackageManagerInternal {
     * Otherwise, {@code false}.
     */
    public abstract boolean isCallerInstallerOfRecord(
            @NonNull PackageParser.Package pkg, int callingUid);
            @NonNull AndroidPackage pkg, int callingUid);

    /** Returns whether or not default runtime permissions are granted for the given user */
    public abstract boolean areDefaultRuntimePermissionsGranted(@UserIdInt int userId);
Loading