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

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

Merge "Check for isInstalled when checking if an app is actually archived." into main

parents 8c464b95 4added4d
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -1700,7 +1700,9 @@ public class ComputerEngine implements Computer {
                if (!listApex && ps.getPkg() != null && ps.getPkg().isApex()) {
                    continue;
                }
                if (listArchivedOnly && !isArchived(ps.getUserStateOrDefault(userId))) {
                PackageUserStateInternal userState = ps.getUserStateOrDefault(userId);
                if (listArchivedOnly && !userState.isInstalled()
                        && userState.getArchiveState() == null) {
                    continue;
                }
                if (filterSharedLibPackage(ps, callingUid, userId, flags)) {
@@ -1746,13 +1748,6 @@ 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();
+7 −2
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.server.pm.pkg.ArchiveState;
import com.android.server.pm.pkg.ArchiveState.ArchiveActivityInfo;
import com.android.server.pm.pkg.PackageStateInternal;
import com.android.server.pm.pkg.PackageUserState;
import com.android.server.pm.pkg.PackageUserStateInternal;

import java.io.ByteArrayOutputStream;
@@ -101,6 +102,11 @@ public class PackageArchiver {
        this.mPm = mPm;
    }

    /** Returns whether a package is archived for a user. */
    public static boolean isArchived(PackageUserState userState) {
        return userState.getArchiveState() != null && !userState.isInstalled();
    }

    void requestArchive(
            @NonNull String packageName,
            @NonNull String callerPackageName,
@@ -354,8 +360,7 @@ public class PackageArchiver {
    private void verifyArchived(PackageStateInternal ps, int userId)
            throws PackageManager.NameNotFoundException {
        PackageUserStateInternal userState = ps.getUserStateOrDefault(userId);
        // TODO(b/288142708) Check for isInstalled false here too.
        if (userState.getArchiveState() == null) {
        if (!isArchived(userState)) {
            throw new PackageManager.NameNotFoundException(
                    TextUtils.formatSimple("Package %s is not currently archived.",
                            ps.getPackageName()));
+2 −8
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ArrayUtils;
import com.android.server.SystemConfig;
import com.android.server.pm.PackageArchiver;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.parsing.pkg.PackageImpl;
import com.android.server.pm.pkg.AndroidPackage;
@@ -401,14 +402,7 @@ public class PackageInfoUtils {
            ai.resourceDirs = overlayPaths.getResourceDirs().toArray(new String[0]);
            ai.overlayPaths = overlayPaths.getOverlayPaths().toArray(new String[0]);
        }
        ai.isArchived = isArchived(state);
    }

    // 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(PackageUserState userState) {
        return userState.getArchiveState() != null;
        ai.isArchived = PackageArchiver.isArchived(state);
    }

    @Nullable
+16 −2
Original line number Diff line number Diff line
@@ -315,7 +315,8 @@ public class PackageArchiverTest {
    }

    @Test
    public void unarchiveApp_notArchived() {
    public void unarchiveApp_notArchived_missingArchiveState() {
        mUserState.setInstalled(false);
        Exception e = assertThrows(
                ParcelableException.class,
                () -> mArchiveManager.requestUnarchive(PACKAGE, CALLER_PACKAGE,
@@ -326,8 +327,21 @@ public class PackageArchiverTest {
    }

    @Test
    public void unarchiveApp_noInstallerFound() {
    public void unarchiveApp_notArchived_stillInstalled() {
        mUserState.setArchiveState(createArchiveState());
        Exception e = assertThrows(
                ParcelableException.class,
                () -> mArchiveManager.requestUnarchive(PACKAGE, CALLER_PACKAGE,
                        UserHandle.CURRENT));
        assertThat(e.getCause()).isInstanceOf(PackageManager.NameNotFoundException.class);
        assertThat(e.getCause()).hasMessageThat().isEqualTo(
                String.format("Package %s is not currently archived.", PACKAGE));
    }


    @Test
    public void unarchiveApp_noInstallerFound() {
        mUserState.setArchiveState(createArchiveState()).setInstalled(false);
        InstallSource otherInstallSource =
                InstallSource.create(
                        CALLER_PACKAGE,