Skip to content

Commit b45ebca

Browse files
committed
Revert "[pm] remove old stage dirs on low storage"
This reverts commit 3b6af31. Reason for revert: Missed a change to allow system to abandon sessions Change-Id: Ie2ab28b4830508eddc67095aac8efabb265eca4f
1 parent 3b6af31 commit b45ebca

File tree

2 files changed

+9
-47
lines changed

2 files changed

+9
-47
lines changed

services/core/java/com/android/server/pm/PackageInstallerService.java

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
135135
private static final long MAX_ACTIVE_SESSIONS_NO_PERMISSION = 50;
136136
/** Upper bound on number of historical sessions for a UID */
137137
private static final long MAX_HISTORICAL_SESSIONS = 1048576;
138-
/** Destroy sessions older than this on storage free request */
139-
private static final long MAX_SESSION_AGE_ON_LOW_STORAGE_MILLIS = 8 * DateUtils.HOUR_IN_MILLIS;
140138

141139
/**
142140
* Allow verification-skipping if it's a development app installed through ADB with
@@ -341,28 +339,22 @@ && getSession(stagedSession.getParentSessionId()) == null) {
341339

342340
@GuardedBy("mSessions")
343341
private void reconcileStagesLocked(String volumeUuid) {
344-
final ArraySet<File> unclaimedStages = getStagingDirsOnVolume(volumeUuid);
342+
final File stagingDir = getTmpSessionDir(volumeUuid);
343+
final ArraySet<File> unclaimedStages = newArraySet(
344+
stagingDir.listFiles(sStageFilter));
345+
346+
// We also need to clean up orphaned staging directory for staged sessions
347+
final File stagedSessionStagingDir = Environment.getDataStagingDirectory(volumeUuid);
348+
unclaimedStages.addAll(newArraySet(stagedSessionStagingDir.listFiles()));
349+
345350
// Ignore stages claimed by active sessions
346351
for (int i = 0; i < mSessions.size(); i++) {
347352
final PackageInstallerSession session = mSessions.valueAt(i);
348353
unclaimedStages.remove(session.stageDir);
349354
}
350-
removeStagingDirs(unclaimedStages);
351-
}
352-
353-
private ArraySet<File> getStagingDirsOnVolume(String volumeUuid) {
354-
final File stagingDir = getTmpSessionDir(volumeUuid);
355-
final ArraySet<File> stagingDirs = newArraySet(stagingDir.listFiles(sStageFilter));
356-
357-
// We also need to clean up orphaned staging directory for staged sessions
358-
final File stagedSessionStagingDir = Environment.getDataStagingDirectory(volumeUuid);
359-
stagingDirs.addAll(newArraySet(stagedSessionStagingDir.listFiles()));
360-
return stagingDirs;
361-
}
362355

363-
private void removeStagingDirs(ArraySet<File> stagingDirsToRemove) {
364356
// Clean up orphaned staging directories
365-
for (File stage : stagingDirsToRemove) {
357+
for (File stage : unclaimedStages) {
366358
Slog.w(TAG, "Deleting orphan stage " + stage);
367359
synchronized (mPm.mInstallLock) {
368360
mPm.removeCodePathLI(stage);
@@ -376,33 +368,6 @@ public void onPrivateVolumeMounted(String volumeUuid) {
376368
}
377369
}
378370

379-
/**
380-
* Called to free up some storage space from obsolete installation files
381-
*/
382-
public void freeStageDirs(String volumeUuid) {
383-
final ArraySet<File> unclaimedStagingDirsOnVolume = getStagingDirsOnVolume(volumeUuid);
384-
final long currentTimeMillis = System.currentTimeMillis();
385-
synchronized (mSessions) {
386-
for (int i = 0; i < mSessions.size(); i++) {
387-
final PackageInstallerSession session = mSessions.valueAt(i);
388-
if (!unclaimedStagingDirsOnVolume.contains(session.stageDir)) {
389-
// Only handles sessions stored on the target volume
390-
continue;
391-
}
392-
final long age = currentTimeMillis - session.createdMillis;
393-
if (age >= MAX_SESSION_AGE_ON_LOW_STORAGE_MILLIS) {
394-
// Aggressively close old sessions because we are running low on storage
395-
// Their staging dirs will be removed too
396-
session.abandon();
397-
} else {
398-
// Session is new enough, so it deserves to be kept even on low storage
399-
unclaimedStagingDirsOnVolume.remove(session.stageDir);
400-
}
401-
}
402-
}
403-
removeStagingDirs(unclaimedStagingDirsOnVolume);
404-
}
405-
406371
public static boolean isStageName(String name) {
407372
final boolean isFile = name.startsWith("vmdl") && name.endsWith(".tmp");
408373
final boolean isContainer = name.startsWith("smdl") && name.endsWith(".tmp");

services/core/java/com/android/server/pm/PackageManagerService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8004,9 +8004,6 @@ public void freeStorage(String volumeUuid, long bytes, int storageFlags) throws
80048004
if (freeBytesRequired > 0) {
80058005
smInternal.freeCache(volumeUuid, freeBytesRequired);
80068006
}
8007-
8008-
// 12. Clear temp install session files
8009-
mInstallerService.freeStageDirs(volumeUuid);
80108007
} else {
80118008
try {
80128009
mInstaller.freeCache(volumeUuid, bytes, 0, 0);

0 commit comments

Comments
 (0)