From 7d279c7d4199e7f95e4e85f0d946b93e81aedbc0 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Thu, 3 Nov 2022 14:22:28 +0800 Subject: [PATCH] Prevent committing session while in progress Committing a session twice in a row will result in interleaved verification flows and break the internal states. Add a field to prevent committing again while the installation is already in progress. Bug: 256330705 Test: will add CTS Change-Id: I1f5a90acde1874b3efbe4dad55f366e991bb4a21 --- .../server/pm/PackageInstallerSession.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java index 72ec510031e2d..5d13a45e03e31 100644 --- a/services/core/java/com/android/server/pm/PackageInstallerSession.java +++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java @@ -380,6 +380,14 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { @GuardedBy("mLock") private boolean mStageDirInUse = false; + /** + * True if the installation is already in progress. This is used to prevent the caller + * from {@link #commit(IntentSender, boolean) committing} the session again while the + * installation is still in progress. + */ + @GuardedBy("mLock") + private boolean mInstallationInProgress = false; + /** Permissions have been accepted by the user (see {@link #setPermissionsResult}) */ @GuardedBy("mLock") private boolean mPermissionsManuallyAccepted = false; @@ -1692,6 +1700,14 @@ public class PackageInstallerSession extends IPackageInstallerSession.Stub { } } + synchronized (mLock) { + if (mInstallationInProgress) { + throw new IllegalStateException("Installation is already in progress. Don't " + + "commit session=" + sessionId + " again."); + } + mInstallationInProgress = true; + } + dispatchSessionSealed(); }