Delete orphaned staging directories for staged session on reboot
Bug: 173132101
Test: StagedInstallInternalTest#testOrphanedStagingDirectoryGetsCleanedUpOnReboot
Change-Id: If840f35245c2d049401d0d2f6539fe8c4625151e
Merged-In: If840f35245c2d049401d0d2f6539fe8c4625151e
(cherry picked from commit bfbf960801)
This commit is contained in:
@@ -299,6 +299,10 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
|
|||||||
final ArraySet<File> unclaimedStages = newArraySet(
|
final ArraySet<File> unclaimedStages = newArraySet(
|
||||||
stagingDir.listFiles(sStageFilter));
|
stagingDir.listFiles(sStageFilter));
|
||||||
|
|
||||||
|
// We also need to clean up orphaned staging directory for staged sessions
|
||||||
|
final File stagedSessionStagingDir = Environment.getDataStagingDirectory(volumeUuid);
|
||||||
|
unclaimedStages.addAll(newArraySet(stagedSessionStagingDir.listFiles()));
|
||||||
|
|
||||||
// Ignore stages claimed by active sessions
|
// Ignore stages claimed by active sessions
|
||||||
for (int i = 0; i < mSessions.size(); i++) {
|
for (int i = 0; i < mSessions.size(); i++) {
|
||||||
final PackageInstallerSession session = mSessions.valueAt(i);
|
final PackageInstallerSession session = mSessions.valueAt(i);
|
||||||
|
|||||||
@@ -203,6 +203,19 @@ public class StagedInstallInternalTest extends BaseHostJUnit4Test {
|
|||||||
assertThat(after).isEqualTo(before);
|
assertThat(after).isEqualTo(before);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOrphanedStagingDirectoryGetsCleanedUpOnReboot() throws Exception {
|
||||||
|
//create random directories in /data/app-staging folder
|
||||||
|
getDevice().enableAdbRoot();
|
||||||
|
getDevice().executeShellCommand("mkdir /data/app-staging/session_123");
|
||||||
|
getDevice().executeShellCommand("mkdir /data/app-staging/random_name");
|
||||||
|
getDevice().disableAdbRoot();
|
||||||
|
|
||||||
|
assertThat(getStagingDirectories()).isNotEmpty();
|
||||||
|
getDevice().reboot();
|
||||||
|
assertThat(getStagingDirectories()).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private List<String> getStagingDirectories() throws DeviceNotAvailableException {
|
private List<String> getStagingDirectories() throws DeviceNotAvailableException {
|
||||||
String baseDir = "/data/app-staging";
|
String baseDir = "/data/app-staging";
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user