Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d1e7531 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Jeff Sharkey
Browse files

Relax locking for startActivityInPackage().

Both startActivityInPackage() and startActivitiesInPackage()
eventually call through to resolveActivity(), which might need to
acquire the AM lock.

The remainder of ActivityStarter.execute() already acquires the
WM lock when needed, so it should be safe to drop it from the overall
method.  Add additional guarding to ensure that this doesn't regress
in the future.

Bug: 115619667, 157863128
Test: atest WmTests:ActivityStarterTests
Test: atest FrameworksServicesTests:com.android.server.uri
Test: atest CtsAppSecurityHostTestCases:android.appsecurity.cts.AppSecurityTests#testPermissionDiffCert
Test: atest CtsWindowManagerDeviceTestCases:CrossAppDragAndDropTests
Test: atest CtsWindowManagerDeviceTestCases:ActivityStarterTests
Change-Id: Ia1693873a10d11ea61a8a7748e0558beffda8c5b
(cherry picked from commit 13a7cf70)
parent 9cf5156f
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -639,8 +639,14 @@ class ActivityStarter {
                        mRequest.intent, caller);
            }

            // Do not lock the resolving to avoid potential deadlock.
            // If the caller hasn't already resolved the activity, we're willing
            // to do so here, but because that may require acquiring the AM lock
            // as part of calculating the NeededUriGrants, we must never hold
            // the WM lock here to avoid deadlocking.
            if (mRequest.activityInfo == null) {
                if (Thread.holdsLock(mService.mGlobalLock)) {
                    Slog.wtf(TAG, new IllegalStateException("Caller must not hold WM lock"));
                }
                mRequest.resolveActivity(mSupervisor);
            }

+9 −13
Original line number Diff line number Diff line
@@ -6174,13 +6174,11 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent,
                boolean allowBackgroundActivityStart) {
            assertPackageMatchesCallingUid(callingPackage);
            synchronized (mGlobalLock) {
            return getActivityStartController().startActivitiesInPackage(uid, realCallingPid,
                    realCallingUid, callingPackage, callingFeatureId, intents, resolvedTypes,
                    resultTo, options, userId, validateIncomingUser, originatingPendingIntent,
                    allowBackgroundActivityStart);
        }
        }

        @Override
        public int startActivityInPackage(int uid, int realCallingPid, int realCallingUid,
@@ -6190,14 +6188,12 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
                boolean validateIncomingUser, PendingIntentRecord originatingPendingIntent,
                boolean allowBackgroundActivityStart) {
            assertPackageMatchesCallingUid(callingPackage);
            synchronized (mGlobalLock) {
            return getActivityStartController().startActivityInPackage(uid, realCallingPid,
                    realCallingUid, callingPackage, callingFeatureId, intent, resolvedType,
                    resultTo, resultWho, requestCode, startFlags, options, userId, inTask,
                    reason, validateIncomingUser, originatingPendingIntent,
                    allowBackgroundActivityStart);
        }
        }

        @Override
        public int startActivityAsUser(IApplicationThread caller, String callerPackage,