@@ -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" );
0 commit comments