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

Commit 3f91f939 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

Remove thread delegation when checking grants.

This code was leftover from previous attempts at avoiding deadlock,
and itself was causing deadlocks with the latest strategy.

Reproduced deadlock in linked bugs, and confirmed that this CL fixes
the underlying deadlock.

Bug: 115619667, 157863128
Test: atest CtsAppSecurityHostTestCases:android.appsecurity.cts.AppSecurityTests#testPermissionDiffCert
Change-Id: I9a8e5828090adebae1bfc306219c4b42d0c97432
parent 20534dcc
Loading
Loading
Loading
Loading
+2 −24
Original line number Diff line number Diff line
@@ -18900,30 +18900,8 @@ public class ActivityManagerService extends IActivityManager.Stub
        @Override
        public int checkContentProviderUriPermission(Uri uri, int userId,
                int callingUid, int modeFlags) {
            // We can find ourselves needing to check Uri permissions while
            // already holding the WM lock, which means reaching back here for
            // the AM lock would cause an inversion. The WM team has requested
            // that we use the strategy below instead of shifting where Uri
            // grants are calculated.
            // Since we could also arrive here while holding the AM lock, we
            // can't always delegate the call through the handler, and we need
            // to delicately dance between the deadlocks.
            if (Thread.currentThread().holdsLock(ActivityManagerService.this)) {
            return ActivityManagerService.this.checkContentProviderUriPermission(uri,
                    userId, callingUid, modeFlags);
            } else {
                final CompletableFuture<Integer> res = new CompletableFuture<>();
                mHandler.post(() -> {
                    res.complete(ActivityManagerService.this.checkContentProviderUriPermission(uri,
                            userId, callingUid, modeFlags));
                });
                try {
                    return res.get();
                } catch (InterruptedException | ExecutionException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        @Override