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

Commit 73281fd4 authored by Jakob Schneider's avatar Jakob Schneider Committed by Android (Google) Code Review
Browse files

Merge "Add MATCH_ARCHIVED_PACKAGES flag and field in the applicationInfo." into main

parents 14cbe937 c5a82ced
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -3797,6 +3797,10 @@ package android.content.pm {
    method @RequiresPermission(anyOf={android.Manifest.permission.DELETE_PACKAGES, android.Manifest.permission.REQUEST_DELETE_PACKAGES}) public void requestArchive(@NonNull String, @NonNull android.content.IntentSender) throws android.content.pm.PackageManager.NameNotFoundException;
  }
  public class PackageInfo implements android.os.Parcelable {
    field public boolean isArchived;
  }
  public class PackageInstaller {
    method @NonNull public android.content.pm.PackageInstaller.InstallInfo readInstallInfo(@NonNull java.io.File, int) throws android.content.pm.PackageInstaller.PackageParsingException;
    method @NonNull public android.content.pm.PackageInstaller.InstallInfo readInstallInfo(@NonNull android.os.ParcelFileDescriptor, @Nullable String, int) throws android.content.pm.PackageInstaller.PackageParsingException;
@@ -4016,6 +4020,7 @@ package android.content.pm {
    field @Deprecated public static final int INTENT_FILTER_VERIFICATION_SUCCESS = 1; // 0x1
    field @Deprecated public static final int MASK_PERMISSION_FLAGS = 255; // 0xff
    field public static final int MATCH_ANY_USER = 4194304; // 0x400000
    field public static final long MATCH_ARCHIVED_PACKAGES = 4294967296L; // 0x100000000L
    field public static final int MATCH_CLONE_PROFILE = 536870912; // 0x20000000
    field public static final int MATCH_FACTORY_ONLY = 2097152; // 0x200000
    field public static final int MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS = 536870912; // 0x20000000
+14 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.content.pm;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.os.Build;
import android.os.Parcel;
@@ -488,6 +489,17 @@ public class PackageInfo implements Parcelable {
     */
    public boolean isActiveApex;

    /**
     * Whether the package is currently in an archived state.
     *
     * <p>Packages can be archived through {@link PackageArchiver} and do not have any APKs stored
     * on the device, but do keep the data directory.
     * @hide
     */
    // TODO(b/278553670) Unhide and update @links before launch.
    @SystemApi
    public boolean isArchived;

    public PackageInfo() {
    }

@@ -575,6 +587,7 @@ public class PackageInfo implements Parcelable {
        }
        dest.writeBoolean(isApex);
        dest.writeBoolean(isActiveApex);
        dest.writeBoolean(isArchived);
        dest.restoreAllowSquashing(prevAllowSquashing);
    }

@@ -640,5 +653,6 @@ public class PackageInfo implements Parcelable {
        }
        isApex = source.readBoolean();
        isActiveApex = source.readBoolean();
        isArchived = source.readBoolean();
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -787,6 +787,7 @@ public abstract class PackageManager {
            MATCH_DEBUG_TRIAGED_MISSING,
            MATCH_INSTANT,
            MATCH_APEX,
            MATCH_ARCHIVED_PACKAGES,
            GET_DISABLED_COMPONENTS,
            GET_DISABLED_UNTIL_USED_COMPONENTS,
            GET_UNINSTALLED_PACKAGES,
@@ -811,6 +812,7 @@ public abstract class PackageManager {
            GET_UNINSTALLED_PACKAGES,
            MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS,
            MATCH_APEX,
            MATCH_ARCHIVED_PACKAGES,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ApplicationInfoFlagsBits {}
@@ -1234,6 +1236,21 @@ public abstract class PackageManager {
     */
    public static final long GET_ATTRIBUTIONS_LONG = 0x80000000L;

    /**
     * Flag parameter to also retrieve some information about archived packages.
     * Packages can be archived through {@link PackageArchiver} and do not have any APKs stored on
     * the device, but do keep the data directory.
     * <p> Note: Archived apps are a subset of apps returned by {@link #MATCH_UNINSTALLED_PACKAGES}.
     * <p> Note: this flag may cause less information about currently installed
     * applications to be returned.
     * <p> Note: use of this flag requires the android.permission.QUERY_ALL_PACKAGES
     * permission to see uninstalled packages.
     * @hide
     */
    // TODO(b/278553670) Unhide and update @links before launch.
    @SystemApi
    public static final long MATCH_ARCHIVED_PACKAGES = 1L << 32;

    /**
     * @hide
     */
+21 −6
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
import static android.content.pm.PackageManager.INTENT_FILTER_DOMAIN_VERIFICATION_STATUS_NEVER;
import static android.content.pm.PackageManager.MATCH_ANY_USER;
import static android.content.pm.PackageManager.MATCH_APEX;
import static android.content.pm.PackageManager.MATCH_ARCHIVED_PACKAGES;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS;
@@ -1507,7 +1508,7 @@ public class ComputerEngine implements Computer {
                    resolveExternalPackageName(p);

            return packageInfo;
        } else if ((flags & MATCH_UNINSTALLED_PACKAGES) != 0
        } else if ((flags & (MATCH_UNINSTALLED_PACKAGES | MATCH_ARCHIVED_PACKAGES)) != 0
                && PackageUserStateUtils.isAvailable(state, flags)) {
            PackageInfo pi = new PackageInfo();
            pi.packageName = ps.getPackageName();
@@ -1516,6 +1517,7 @@ public class ComputerEngine implements Computer {
            pi.sharedUserId = (sharedUser != null) ? sharedUser.getName() : null;
            pi.firstInstallTime = state.getFirstInstallTimeMillis();
            pi.lastUpdateTime = ps.getLastUpdateTime();
            pi.isArchived = isArchived(state);

            ApplicationInfo ai = new ApplicationInfo();
            ai.packageName = ps.getPackageName();
@@ -1614,7 +1616,7 @@ public class ComputerEngine implements Computer {

            return generatePackageInfo(ps, flags, userId);
        }
        if (!matchFactoryOnly && (flags & MATCH_KNOWN_PACKAGES) != 0) {
        if (!matchFactoryOnly && (flags & (MATCH_KNOWN_PACKAGES | MATCH_ARCHIVED_PACKAGES)) != 0) {
            final PackageStateInternal ps = mSettings.getPackage(packageName);
            if (ps == null) return null;
            if (filterSharedLibPackage(ps, filterCallingUid, userId, flags)) {
@@ -1678,9 +1680,11 @@ public class ComputerEngine implements Computer {
        final boolean listUninstalled = (flags & MATCH_KNOWN_PACKAGES) != 0;
        final boolean listApex = (flags & MATCH_APEX) != 0;
        final boolean listFactory = (flags & MATCH_FACTORY_ONLY) != 0;
        // Only list archived apps, not fully uninstalled ones. Other entries are unaffected.
        final boolean listArchivedOnly = !listUninstalled && (flags & MATCH_ARCHIVED_PACKAGES) != 0;

        ArrayList<PackageInfo> list;
        if (listUninstalled) {
        if (listUninstalled || listArchivedOnly) {
            list = new ArrayList<>(mSettings.getPackages().size());
            for (PackageStateInternal ps : mSettings.getPackages().values()) {
                if (listFactory) {
@@ -1696,6 +1700,9 @@ public class ComputerEngine implements Computer {
                if (!listApex && ps.getPkg() != null && ps.getPkg().isApex()) {
                    continue;
                }
                if (listArchivedOnly && !isArchived(ps.getUserStateOrDefault(userId))) {
                    continue;
                }
                if (filterSharedLibPackage(ps, callingUid, userId, flags)) {
                    continue;
                }
@@ -1739,6 +1746,13 @@ public class ComputerEngine implements Computer {
        return new ParceledListSlice<>(list);
    }

    // TODO(b/288142708) Check for userState.isInstalled() here once this bug is fixed.
    // If an app has isInstalled() == true - it should not be filtered above in any case, currently
    // it is.
    private static boolean isArchived(PackageUserStateInternal userState) {
        return userState.getArchiveState() != null;
    }

    public final ResolveInfo createForwardingResolveInfoUnchecked(WatchedIntentFilter filter,
            int sourceUserId, int targetUserId) {
        ResolveInfo forwardingResolveInfo = new ResolveInfo();
@@ -2612,7 +2626,7 @@ public class ComputerEngine implements Computer {
                return UserHandle.getUid(userId, p.getUid());
            }
        }
        if ((flags & MATCH_KNOWN_PACKAGES) != 0) {
        if ((flags & (MATCH_KNOWN_PACKAGES | MATCH_ARCHIVED_PACKAGES)) != 0) {
            final PackageStateInternal ps = mSettings.getPackage(packageName);
            if (ps != null && PackageStateUtils.isMatch(ps, flags)
                    && !shouldFilterApplication(ps, callingUid, userId)) {
@@ -3671,7 +3685,7 @@ public class ComputerEngine implements Computer {
                        ps.getAppId()));
            }
        }
        if ((flags & MATCH_KNOWN_PACKAGES) != 0) {
        if ((flags & (MATCH_KNOWN_PACKAGES | MATCH_ARCHIVED_PACKAGES)) != 0) {
            if (PackageStateUtils.isMatch(ps, flags)
                    && !shouldFilterApplication(ps, callingUid, userId)) {
                return mPermissionManager.getGidsForUid(
@@ -4525,7 +4539,8 @@ public class ComputerEngine implements Computer {
        flags = updateFlagsForPackage(flags, userId);
        enforceCrossUserPermission(Binder.getCallingUid(), userId, true /* requireFullPermission */,
                false /* checkShell */, "get packages holding permissions");
        final boolean listUninstalled = (flags & MATCH_KNOWN_PACKAGES) != 0;
        final boolean listUninstalled =
                (flags & (MATCH_KNOWN_PACKAGES | MATCH_ARCHIVED_PACKAGES)) != 0;

        ArrayList<PackageInfo> list = new ArrayList<>();
        boolean[] tmpBools = new boolean[permissions.length];
+10 −6
Original line number Diff line number Diff line
@@ -802,9 +802,7 @@ public class PackageInfoUtils {
        // If available for the target user, or trying to match uninstalled packages and it's
        // a system app.
        return PackageUserStateUtils.isAvailable(state, flags)
                || (pkgSetting.isSystem()
                && ((flags & PackageManager.MATCH_KNOWN_PACKAGES) != 0
                || (flags & PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS) != 0));
                || (pkgSetting.isSystem() && matchUninstalledOrHidden(flags));
    }

    private static boolean checkUseInstalledOrHidden(long flags,
@@ -819,9 +817,15 @@ public class PackageInfoUtils {
        // If available for the target user, or trying to match uninstalled packages and it's
        // a system app.
        return PackageUserStateUtils.isAvailable(state, flags)
                || (appInfo != null && appInfo.isSystemApp()
                && ((flags & PackageManager.MATCH_KNOWN_PACKAGES) != 0
                || (flags & PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS) != 0));
                || (appInfo != null && appInfo.isSystemApp() && matchUninstalledOrHidden(flags));
    }

    private static boolean matchUninstalledOrHidden(long flags) {
        return (flags
                & (PackageManager.MATCH_KNOWN_PACKAGES
                        | PackageManager.MATCH_ARCHIVED_PACKAGES
                        | PackageManager.MATCH_HIDDEN_UNTIL_INSTALLED_COMPONENTS))
                != 0;
    }

    private static void assignFieldsComponentInfoParsedMainComponent(
Loading