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

Commit 37c56220 authored by Mohammad Samiul Islam's avatar Mohammad Samiul Islam
Browse files

Ensure system behaves properly when app-staging dir is deleted

/data/app-staging folder can get deleted when upgrading to S. This test
ensures we fail the staged session when that happens.

Bug: 176452293
Test: atest StagedInstallInternalTest
Change-Id: Id17777361d93eb778ccae44a283be4503822d1b3
parent 8bf124b0
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -140,6 +140,21 @@ public class StagedInstallInternalTest {
                Install.multi(TestApp.AIncompleteSplit, TestApp.B1, TestApp.Apex1).setStaged());
    }

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

    @Test
    public void testFailStagedSessionIfStagingDirectoryDeleted_Verify() throws Exception {
        int sessionId = retrieveLastSessionId();
        PackageInstaller.SessionInfo info =
                InstallUtils.getPackageInstaller().getSessionInfo(sessionId);
        assertThat(info.isStagedSessionFailed()).isTrue();
    }

    private static void assertSessionReady(int sessionId) {
        assertSessionState(sessionId,
                (session) -> assertThat(session.isStagedSessionReady()).isTrue());
+15 −0
Original line number Diff line number Diff line
@@ -279,6 +279,21 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
        assertThat(getStagingDirectories()).isEmpty();
    }

    @Test
    public void testFailStagedSessionIfStagingDirectoryDeleted() throws Exception {
        // Create a staged session
        runPhase("testFailStagedSessionIfStagingDirectoryDeleted_Commit");

        // Delete the staging directory
        getDevice().enableAdbRoot();
        getDevice().executeShellCommand("rm -r /data/app-staging");
        getDevice().disableAdbRoot();

        getDevice().reboot();

        runPhase("testFailStagedSessionIfStagingDirectoryDeleted_Verify");
    }

    private List<String> getStagingDirectories() throws DeviceNotAvailableException {
        String baseDir = "/data/app-staging";
        try {