Merge "Ensure system behaves properly when app-staging dir is deleted"

This commit is contained in:
Mohammad Samiul Islam
2021-01-18 16:08:56 +00:00
committed by Android (Google) Code Review
2 changed files with 30 additions and 0 deletions

View File

@@ -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());

View File

@@ -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 {