Clean up staged session data on validation failure

Bug: 173132101
Test: atest StagedInstallInternalTest#testStagedInstallationShouldCleanUpOnValidationFailure
Test: atest StagedInstallInternalTest#testStagedInstallationShouldCleanUpOnValidationFailureMultiPackage
Change-Id: Idd6597cd0d2dda34a8a7626b585401eeee39c31f
This commit is contained in:
Mohammad Samiul Islam
2020-11-13 17:32:05 +00:00
parent 6b8918abae
commit b6dde00d03
3 changed files with 39 additions and 1 deletions

View File

@@ -1676,6 +1676,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub {
destroyInternal();
// Dispatch message to remove session from PackageInstallerService.
dispatchSessionFinished(error, detailMessage, null);
// TODO(b/173194203): clean up staged session in destroyInternal() call instead
if (isStaged() && stageDir != null) {
cleanStageDir();
}
}
private void onSessionVerificationFailure(int error, String msg) {

View File

@@ -127,6 +127,19 @@ public class StagedInstallInternalTest {
InstallUtils.getPackageInstaller().abandonSession(id4);
}
@Test
public void testStagedInstallationShouldCleanUpOnValidationFailure() throws Exception {
InstallUtils.commitExpectingFailure(AssertionError.class, "INSTALL_FAILED_INVALID_APK",
Install.single(TestApp.AIncompleteSplit).setStaged());
}
@Test
public void testStagedInstallationShouldCleanUpOnValidationFailureMultiPackage()
throws Exception {
InstallUtils.commitExpectingFailure(AssertionError.class, "INSTALL_FAILED_INVALID_APK",
Install.multi(TestApp.AIncompleteSplit, TestApp.B1, TestApp.Apex1).setStaged());
}
private static void assertSessionReady(int sessionId) {
assertSessionState(sessionId,
(session) -> assertThat(session.isStagedSessionReady()).isTrue());

View File

@@ -30,6 +30,7 @@ import com.android.compatibility.common.tradefed.build.CompatibilityBuildHelper;
import com.android.ddmlib.Log;
import com.android.tests.rollback.host.AbandonSessionsRule;
import com.android.tests.util.ModuleTestUtils;
import com.android.tradefed.device.DeviceNotAvailableException;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import com.android.tradefed.testtype.junit4.BaseHostJUnit4Test;
import com.android.tradefed.util.CommandResult;
@@ -250,9 +251,27 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
assertThat(after).isEqualTo(before);
}
private List<String> getStagingDirectories() {
@Test
public void testStagedInstallationShouldCleanUpOnValidationFailure() throws Exception {
List<String> before = getStagingDirectories();
runPhase("testStagedInstallationShouldCleanUpOnValidationFailure");
List<String> after = getStagingDirectories();
assertThat(after).isEqualTo(before);
}
@Test
public void testStagedInstallationShouldCleanUpOnValidationFailureMultiPackage()
throws Exception {
List<String> before = getStagingDirectories();
runPhase("testStagedInstallationShouldCleanUpOnValidationFailureMultiPackage");
List<String> after = getStagingDirectories();
assertThat(after).isEqualTo(before);
}
private List<String> getStagingDirectories() throws DeviceNotAvailableException {
String baseDir = "/data/app-staging";
try {
getDevice().enableAdbRoot();
return getDevice().getFileEntry(baseDir).getChildren(false)
.stream().filter(entry -> entry.getName().matches("session_\\d+"))
.map(entry -> entry.getName())
@@ -260,6 +279,8 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
} catch (Exception e) {
// Return an empty list if any error
return Collections.EMPTY_LIST;
} finally {
getDevice().disableAdbRoot();
}
}