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

Commit 451bf4ae authored by Alex Buynytskyy's avatar Alex Buynytskyy
Browse files

Mark archived package as not installed.

+allow pkg to be present but invalid
+allow install archived apps to not have data

Fixes: 313720942
Test: atest CtsPackageManagerTestCases:android.content.pm.cts.PackageManagerTest
Change-Id: I6f2d5de3dd0f44ce37ea5303a565646d858d5628
parent 85df79c1
Loading
Loading
Loading
Loading
+8 −10
Original line number Diff line number Diff line
@@ -1500,15 +1500,14 @@ public class ComputerEngine implements Computer {
                    state.getFirstInstallTimeMillis(), ps.getLastUpdateTime(), installedPermissions,
                    grantedPermissions, state, userId, ps);

            if (packageInfo == null) {
                return null;
            }

            if (packageInfo != null) {
                packageInfo.packageName = packageInfo.applicationInfo.packageName =
                        resolveExternalPackageName(p);

                return packageInfo;
        } else if ((flags & (MATCH_UNINSTALLED_PACKAGES | MATCH_ARCHIVED_PACKAGES)) != 0
            }
        }
        // TODO(b/314808978): Set ps.setPkg to null during install-archived.
        if ((flags & (MATCH_UNINSTALLED_PACKAGES | MATCH_ARCHIVED_PACKAGES)) != 0
                && PackageUserStateUtils.isAvailable(state, flags)) {
            PackageInfo pi = new PackageInfo();
            pi.packageName = ps.getPackageName();
@@ -1540,9 +1539,8 @@ public class ComputerEngine implements Computer {
                        + ps.getPackageName() + "]. Provides a minimum info.");
            }
            return pi;
        } else {
            return null;
        }
        return null;
    }

    public final PackageInfo getPackageInfo(String packageName,
+5 −1
Original line number Diff line number Diff line
@@ -2158,7 +2158,11 @@ final class InstallPackageHelper {
                }
            }
            if (installRequest.getReturnCode() == PackageManager.INSTALL_SUCCEEDED) {
                mPm.createArchiveStateIfNeeded(ps,
                // If this is an archival installation then we'll initialize the archive status,
                // while also marking package as not installed.
                // Doing this at the very end of the install as we are using ps.getInstalled
                // to figure out which users were changed.
                mPm.markPackageAsArchivedIfNeeded(ps,
                        installRequest.getArchivedPackage(),
                        installRequest.getNewUsers());
                mPm.updateSequenceNumberLP(ps, installRequest.getNewUsers());
+3 −2
Original line number Diff line number Diff line
@@ -1518,8 +1518,8 @@ public class PackageManagerService implements PackageSender, TestUtilityService
        return archPkg;
    }

    void createArchiveStateIfNeeded(PackageSetting pkgSetting, ArchivedPackageParcel archivePackage,
            int[] userIds) {
    void markPackageAsArchivedIfNeeded(PackageSetting pkgSetting,
                                       ArchivedPackageParcel archivePackage, int[] userIds) {
        if (pkgSetting == null || archivePackage == null
                || archivePackage.archivedActivities == null || userIds == null
                || userIds.length == 0) {
@@ -1541,6 +1541,7 @@ public class PackageManagerService implements PackageSender, TestUtilityService
            }
            pkgSetting
                    .modifyUserState(userId)
                    .setInstalled(false)
                    .setArchiveState(archiveState);
        }
    }
+14 −6
Original line number Diff line number Diff line
@@ -93,8 +93,8 @@ public class PackageUserStateUtils {
     * this object exists means that the package must be installed or has data on at least one user;
     * <li> If it is not installed but still has data (i.e., it was previously uninstalled with
     * {@link PackageManager#DELETE_KEEP_DATA}), return true if the caller requested
     * {@link PackageManager#MATCH_UNINSTALLED_PACKAGES} or
     * {@link PackageManager#MATCH_ARCHIVED_PACKAGES};
     * {@link PackageManager#MATCH_UNINSTALLED_PACKAGES}.
     * Always available for {@link PackageManager#MATCH_ARCHIVED_PACKAGES}.
     * </ul><p>
     */
    public static boolean isAvailable(@NonNull PackageUserState state, long flags) {
@@ -109,11 +109,19 @@ public class PackageUserStateUtils {
        if (state.isInstalled()) {
            if (!state.isHidden()) {
                return true;
            } else return matchDataExists;
            } else {
                return matchDataExists;
            }
        }

        // not installed
            return matchDataExists && state.dataExists();
        if (matchUninstalled) {
            return state.dataExists();
        }

        // archived or installed as archived
        // TODO(b/314808978): Create data folders during install-archived.
        return matchArchived;
    }

    public static boolean reportIfDebug(boolean result, long flags) {