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

Commit 018d6bcb authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam Committed by Automerger Merge Worker
Browse files

Merge "Test apexd behaves correctly when not in fs-checkpoint mode" into...

Merge "Test apexd behaves correctly when not in fs-checkpoint mode" into sc-dev am: b713ec62 am: 1d508e58

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15302099

Change-Id: If3fc3715d1b336aa8475cc5a73fd52c10ed1c291
parents a2ac52dc 1d508e58
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
@@ -195,6 +195,47 @@ public class StagedInstallInternalTest {
        assertSessionFailedWithMessage(sessionId, "has unexpected SHA512 hash");
    }

    @Test
    public void testActiveApexIsRevertedOnCheckpointRollback_Prepare() throws Exception {
        int sessionId = Install.single(TestApp.Apex2).setStaged().commit();
        assertSessionReady(sessionId);
        storeSessionId(sessionId);
    }

    @Test
    public void testActiveApexIsRevertedOnCheckpointRollback_Commit() throws Exception {
        // Verify apex installed during preparation was successful
        int sessionId = retrieveLastSessionId();
        assertSessionApplied(sessionId);
        assertThat(InstallUtils.getInstalledVersion(SHIM_APEX_PACKAGE_NAME)).isEqualTo(2);
        // Commit a new staged session
        sessionId = Install.single(TestApp.Apex3).setStaged().commit();
        assertSessionReady(sessionId);
        storeSessionId(sessionId);
    }

    @Test
    public void testActiveApexIsRevertedOnCheckpointRollback_VerifyPostReboot() throws Exception {
        int sessionId = retrieveLastSessionId();
        assertSessionFailed(sessionId);
        assertThat(InstallUtils.getInstalledVersion(SHIM_APEX_PACKAGE_NAME)).isEqualTo(2);
    }

    @Test
    public void testApexIsNotActivatedIfNotInCheckpointMode_Commit() throws Exception {
        int sessionId = Install.single(TestApp.Apex2).setStaged().commit();
        assertSessionReady(sessionId);
        storeSessionId(sessionId);
        assertThat(InstallUtils.getInstalledVersion(SHIM_APEX_PACKAGE_NAME)).isEqualTo(1);
    }

    @Test
    public void testApexIsNotActivatedIfNotInCheckpointMode_VerifyPostReboot() throws Exception {
        int sessionId = retrieveLastSessionId();
        assertSessionFailed(sessionId);
        assertThat(InstallUtils.getInstalledVersion(SHIM_APEX_PACKAGE_NAME)).isEqualTo(1);
    }

    @Test
    public void testRebootlessUpdates() throws Exception {
        InstallUtils.dropShellPermissionIdentity();
@@ -257,6 +298,18 @@ public class StagedInstallInternalTest {
        }
    }

    private static void assertSessionApplied(int sessionId) {
        assertSessionState(sessionId, (session) -> {
            assertThat(session.isStagedSessionApplied()).isTrue();
        });
    }

    private static void assertSessionFailed(int sessionId) {
        assertSessionState(sessionId, (session) -> {
            assertThat(session.isStagedSessionFailed()).isTrue();
        });
    }

    private static void assertSessionFailedWithMessage(int sessionId, String msg) {
        assertSessionState(sessionId, (session) -> {
            assertThat(session.isStagedSessionFailed()).isTrue();
+43 −0
Original line number Diff line number Diff line
@@ -345,6 +345,49 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        runPhase("testApexActivationFailureIsCapturedInSession_Verify");
    }

    @Test
    public void testActiveApexIsRevertedOnCheckpointRollback() throws Exception {
        assumeTrue("Device does not support updating APEX",
                mHostUtils.isApexUpdateSupported());
        assumeTrue("Device does not support file-system checkpoint",
                mHostUtils.isCheckpointSupported());

        // Install something so that /data/apex/active is not empty
        runPhase("testActiveApexIsRevertedOnCheckpointRollback_Prepare");
        getDevice().reboot();

        // Stage another session which will be installed during fs-rollback mode
        runPhase("testActiveApexIsRevertedOnCheckpointRollback_Commit");

        // Set checkpoint to 0 so that we enter fs-rollback mode immediately on reboot
        getDevice().enableAdbRoot();
        getDevice().executeShellCommand("vdc checkpoint startCheckpoint 0");
        getDevice().disableAdbRoot();
        getDevice().reboot();

        // Verify that session was reverted and we have fallen back to
        // apex installed during preparation stage.
        runPhase("testActiveApexIsRevertedOnCheckpointRollback_VerifyPostReboot");
    }

    @Test
    public void testApexIsNotActivatedIfNotInCheckpointMode() throws Exception {
        assumeTrue("Device does not support updating APEX",
                mHostUtils.isApexUpdateSupported());
        assumeTrue("Device does not support file-system checkpoint",
                mHostUtils.isCheckpointSupported());

        runPhase("testApexIsNotActivatedIfNotInCheckpointMode_Commit");
        // Delete checkpoint file in /metadata so that device thinks
        // fs-checkpointing was never activated
        getDevice().enableAdbRoot();
        getDevice().executeShellCommand("rm /metadata/vold/checkpoint");
        getDevice().disableAdbRoot();
        getDevice().reboot();
        // Verify that session was not installed when not in fs-checkpoint mode
        runPhase("testApexIsNotActivatedIfNotInCheckpointMode_VerifyPostReboot");
    }

    @Test
    public void testRebootlessUpdates() throws Exception {
        pushTestApex("test.rebootless_apex_v1.apex");