diff options
| author | 2021-12-08 11:06:18 +0000 | |
|---|---|---|
| committer | 2021-12-08 11:06:18 +0000 | |
| commit | 21684a2576a3172dc80cbbb7b59dc6c52f55606c (patch) | |
| tree | d9671e3d375df768b904cc7de7d12b83e19b9500 | |
| parent | fd716d1d9aec9679ea262d78ff7b3ef1e9ce2105 (diff) | |
| parent | 1700991d90d38f645aea11c71f8d3b7c12f4e7ce (diff) | |
Merge "Expire child sessions (3/n)"
| -rw-r--r-- | services/core/java/com/android/server/pm/PackageInstallerService.java | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/services/core/java/com/android/server/pm/PackageInstallerService.java b/services/core/java/com/android/server/pm/PackageInstallerService.java index 26a5bbb094ac..356d6c93ae84 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerService.java +++ b/services/core/java/com/android/server/pm/PackageInstallerService.java @@ -286,6 +286,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements synchronized (mSessions) { readSessionsLocked(); + expireSessionsLocked(); reconcileStagesLocked(StorageManager.UUID_PRIVATE_INTERNAL); @@ -462,34 +463,7 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements Slog.e(TAG, "Could not read session", e); continue; } - - final long age = System.currentTimeMillis() - session.createdMillis; - final long timeSinceUpdate = - System.currentTimeMillis() - session.getUpdatedMillis(); - final boolean valid; - if (session.isStaged()) { - if (timeSinceUpdate >= MAX_TIME_SINCE_UPDATE_MILLIS - && session.isStagedAndInTerminalState()) { - valid = false; - } else { - valid = true; - } - } else if (age >= MAX_AGE_MILLIS) { - Slog.w(TAG, "Abandoning old session created at " - + session.createdMillis); - valid = false; - } else { - valid = true; - } - - if (valid) { - mSessions.put(session.sessionId, session); - } else { - // Since this is early during boot we don't send - // any observer events about the session, but we - // keep details around for dumpsys. - addHistoricalSessionLocked(session); - } + mSessions.put(session.sessionId, session); mAllocatedSessions.put(session.sessionId, true); } } @@ -509,6 +483,44 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements } @GuardedBy("mSessions") + private void expireSessionsLocked() { + SparseArray<PackageInstallerSession> tmp = mSessions.clone(); + final int n = tmp.size(); + for (int i = 0; i < n; ++i) { + PackageInstallerSession session = tmp.valueAt(i); + if (session.hasParentSessionId()) { + // Child sessions will be expired when handling parent sessions + continue; + } + final long age = System.currentTimeMillis() - session.createdMillis; + final long timeSinceUpdate = System.currentTimeMillis() - session.getUpdatedMillis(); + final boolean valid; + if (session.isStaged()) { + valid = !session.isStagedAndInTerminalState() + || timeSinceUpdate < MAX_TIME_SINCE_UPDATE_MILLIS; + } else if (age >= MAX_AGE_MILLIS) { + Slog.w(TAG, "Abandoning old session created at " + + session.createdMillis); + valid = false; + } else { + valid = true; + } + if (!valid) { + // Remove expired sessions as well as child sessions if any + mSessions.remove(session.sessionId); + // Since this is early during boot we don't send + // any observer events about the session, but we + // keep details around for dumpsys. + addHistoricalSessionLocked(session); + for (PackageInstallerSession child : session.getChildSessions()) { + mSessions.remove(child.sessionId); + addHistoricalSessionLocked(child); + } + } + } + } + + @GuardedBy("mSessions") private void addHistoricalSessionLocked(PackageInstallerSession session) { CharArrayWriter writer = new CharArrayWriter(); IndentingPrintWriter pw = new IndentingPrintWriter(writer, " "); |