From 184c7592ccb35b64f5752cf62e487e56444b4e4b Mon Sep 17 00:00:00 2001 From: Sergey Nikolaienkov Date: Thu, 2 Dec 2021 10:09:17 +0000 Subject: [PATCH] Revert "Finish child sessions when verification/setPermission fa..." Revert submission 16345090-bug207814969 Bug: 208767113 Reason for revert: DroidMonitor-triggered revert due to breakage b/208767113. Reverted Changes: I76a2dc48d:Finish child sessions when verification/setPermiss... I1f9b5f905:Add session cleanup tests for multi-package sessio... Change-Id: I7366ee43c546c1055c6f85ae291e0820c2fd1636 --- .../server/pm/PackageInstallerSession.java | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index 28204eadd394c..55a0c96eea9ed 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -706,10 +706,9 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { if (mCommitted.get()) { mStagingManager.abortCommittedSession(this); } - destroy(); + destroyInternal(); dispatchSessionFinished(INSTALL_FAILED_ABORTED, "Session was abandoned", null); - maybeFinishChildSessions(INSTALL_FAILED_ABORTED, - "Session was abandoned because the parent session is abandoned"); + maybeCleanUpChildSessions(); }; if (mStageDirInUse) { // Pre-reboot verification is ongoing, not safe to clean up the session yet. @@ -2132,7 +2131,6 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { destroy(); // Dispatch message to remove session from PackageInstallerService. dispatchSessionFinished(error, msg, null); - maybeFinishChildSessions(error, msg); } } @@ -3648,19 +3646,20 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { throw new SecurityException("Must be sealed to accept permissions"); } - PackageInstallerSession root = hasParentSessionId() - ? mSessionProvider.getSession(getParentSessionId()) : this; - if (accepted) { // Mark and kick off another install pass synchronized (mLock) { mPermissionsManuallyAccepted = true; } + + PackageInstallerSession root = + (hasParentSessionId()) + ? mSessionProvider.getSession(getParentSessionId()) + : this; root.mHandler.obtainMessage(MSG_INSTALL).sendToTarget(); } else { - root.destroy(); - root.dispatchSessionFinished(INSTALL_FAILED_ABORTED, "User rejected permissions", null); - root.maybeFinishChildSessions(INSTALL_FAILED_ABORTED, "User rejected permissions"); + destroyInternal(); + dispatchSessionFinished(INSTALL_FAILED_ABORTED, "User rejected permissions", null); } } @@ -3711,12 +3710,27 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } /** - * Calls dispatchSessionFinished() on all child sessions with the given error code and - * error message to prevent orphaned child sessions. + * Cleans up the relevant stored files and information of all child sessions. + *

Cleaning up the stored files and session information is necessary for + * preventing the orphan children sessions. + *

    + *
  1. To call {@link #destroyInternal()} cleans up the stored files.
  2. + *
  3. To call {@link #dispatchSessionFinished(int, String, Bundle)} to trigger the + * procedure to clean up the information in PackageInstallerService.
  4. + *

*/ - private void maybeFinishChildSessions(int returnCode, String msg) { - for (PackageInstallerSession child : getChildSessions()) { - child.dispatchSessionFinished(returnCode, msg, null); + private void maybeCleanUpChildSessions() { + if (!isMultiPackage()) { + return; + } + + final List childSessions = getChildSessions(); + final int size = childSessions.size(); + for (int i = 0; i < size; ++i) { + final PackageInstallerSession session = childSessions.get(i); + session.destroyInternal(); + session.dispatchSessionFinished(INSTALL_FAILED_ABORTED, "Session was abandoned" + + " because the parent session is abandoned", null); } } @@ -3728,12 +3742,10 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { if (LOGD) Slog.d(TAG, "Ignoring abandon for staging files are in use"); return; } - mDestroyed = true; + destroyInternal(); } - destroy(); dispatchSessionFinished(INSTALL_FAILED_ABORTED, "Session was abandoned", null); - maybeFinishChildSessions(INSTALL_FAILED_ABORTED, - "Session was abandoned because the parent session is abandoned"); + maybeCleanUpChildSessions(); } private void assertNotChild(String cookie) {