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

Commit 1abe9396 authored by JW Wang's avatar JW Wang Committed by Android (Google) Code Review
Browse files

Merge "Revert "Add session cleanup tests for multi-package sessions (2/n)""

parents 44cc52ba 14c77f21
Loading
Loading
Loading
Loading
+15 −23
Original line number Diff line number Diff line
@@ -558,7 +558,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                Slog.d(TAG, "Marking session " + sessionId + " as failed: " + errorMessage);
                childSessions = getChildSessionsLocked();
            }
            destroy();
            destroyInternal();
            for (PackageInstallerSession child : childSessions) {
                child.destroyInternal();
            }
            mCallback.onStagedSessionChanged(PackageInstallerSession.this);
        }

@@ -576,7 +579,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
                Slog.d(TAG, "Marking session " + sessionId + " as applied");
                childSessions = getChildSessionsLocked();
            }
            destroy();
            destroyInternal();
            for (PackageInstallerSession child : childSessions) {
                child.destroyInternal();
            }
            mCallback.onStagedSessionChanged(PackageInstallerSession.this);
        }

@@ -2105,14 +2111,18 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
    private void onSessionVerificationFailure(int error, String msg) {
        final String msgWithErrorCode = PackageManager.installStatusToString(error, msg);
        Slog.e(TAG, "Failed to verify session " + sessionId + " [" + msgWithErrorCode + "]");
        // Session is sealed and committed but could not be verified, we need to destroy it.
        destroyInternal();
        if (isMultiPackage()) {
            for (PackageInstallerSession childSession : getChildSessions()) {
                childSession.destroyInternal();
            }
        }
        if (isStaged()) {
            // This will clean up the session when it reaches the terminal state
            mStagedSession.setSessionFailed(
                    SessionInfo.STAGED_SESSION_VERIFICATION_FAILED, msgWithErrorCode);
            mStagedSession.notifyEndPreRebootVerification();
        } else {
            // Session is sealed and committed but could not be verified, we need to destroy it.
            destroy();
            // Dispatch message to remove session from PackageInstallerService.
            dispatchSessionFinished(error, msg, null);
        }
@@ -4255,24 +4265,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
        return params.isStaged ? mStagedSession.getSessionErrorMessage() : "";
    }

    /**
     * Free up storage used by this session and its children.
     * Must not be called on a child session.
     */
    private void destroy() {
        // TODO(b/173194203): destroyInternal() should be used by destroy() only.
        //  For the sake of consistency, a session should be destroyed as a whole. The caller
        //  should always call destroy() for cleanup without knowing it has child sessions or not.
        assertNotChild("destroy");
        destroyInternal();
        for (PackageInstallerSession child : getChildSessions()) {
            child.destroyInternal();
        }
    }

    /**
     * Free up storage used by this session.
     */
    private void destroyInternal() {
        final IncrementalFileStorages incrementalFileStorages;
        synchronized (mLock) {
+0 −16
Original line number Diff line number Diff line
@@ -157,18 +157,8 @@ public class StagedInstallInternalTest {

    @Test
    public void testStagedSessionShouldCleanUpOnVerificationFailure() throws Exception {
        // APEX verification
        InstallUtils.commitExpectingFailure(AssertionError.class, "apexd verification failed",
                Install.single(APEX_WRONG_SHA_V2).setStaged());
        InstallUtils.commitExpectingFailure(AssertionError.class, "apexd verification failed",
                Install.multi(APEX_WRONG_SHA_V2, TestApp.A1).setStaged());
        // APK verification
        Install.single(TestApp.A2).commit();
        assertThat(InstallUtils.getInstalledVersion(TestApp.A)).isEqualTo(2);
        InstallUtils.commitExpectingFailure(AssertionError.class, "Downgrade detected",
                Install.single(TestApp.A1).setStaged());
        InstallUtils.commitExpectingFailure(AssertionError.class, "Downgrade detected",
                Install.multi(TestApp.A1, TestApp.B1).setStaged());
    }

    @Test
@@ -185,12 +175,6 @@ public class StagedInstallInternalTest {
        assertThat(info.isStagedSessionApplied()).isTrue();
    }

    @Test
    public void testStagedSessionShouldCleanUpOnOnSuccessMultiPackage_Commit() throws Exception {
        int sessionId = Install.multi(TestApp.A1, TestApp.Apex2).setStaged().commit();
        storeSessionId(sessionId);
    }

    @Test
    public void testStagedInstallationShouldCleanUpOnValidationFailure() throws Exception {
        InstallUtils.commitExpectingFailure(AssertionError.class, "INSTALL_FAILED_INVALID_APK",
+0 −12
Original line number Diff line number Diff line
@@ -300,18 +300,6 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        assertThat(after).isEqualTo(before);
    }

    @Test
    @LargeTest
    public void testStagedSessionShouldCleanUpOnOnSuccessMultiPackage() throws Exception {
        List<String> before = getStagingDirectories();
        runPhase("testStagedSessionShouldCleanUpOnOnSuccessMultiPackage_Commit");
        assertThat(getStagingDirectories()).isNotEqualTo(before);
        getDevice().reboot();
        runPhase("testStagedSessionShouldCleanUpOnOnSuccess_Verify");
        List<String> after = getStagingDirectories();
        assertThat(after).isEqualTo(before);
    }

    @Test
    public void testStagedInstallationShouldCleanUpOnValidationFailure() throws Exception {
        List<String> before = getStagingDirectories();