OSDN Git Service

Fix deadlock between AMS and EphemeralResolverConnection
authorSnild Dolkow <snild@sony.com>
Wed, 14 Jun 2017 07:57:36 +0000 (09:57 +0200)
committerTodd Kennedy <toddke@google.com>
Tue, 1 Aug 2017 19:47:00 +0000 (12:47 -0700)
commite2612eb3f59b2586273fd52a211ee430b0ccf8c2
treee077c766ea85f093af591758c645eae7ae588ac7
parentb3d487da64b143d00755404663a3e2a645954721
Fix deadlock between AMS and EphemeralResolverConnection

The ActivityManagerService lock may be taken when calling into ERC
through ActivityStarter.startActivityMayWait().

At the same time, a PackageManagerService.getLastChosenActivity() call
could take the ERC lock and call unbindService(), requesting the AMS
lock.

Deadlock.

Solved by making sure to drop the ERC lock before calling into AMS.
This necessitated an extra state to prevent multiple callers from
clobbering the binding, so mIsBinding became mBindState.

The IDLE state means that nothing is currently binding.

The BINDING state means someone is initiating a bind, including the
wait() call thereafter.

The PENDING state means that bindService() has been called, but the
caller's timeout expired (i.e. the new caller may want to rebind).

Fixes: 63150916
Test: for x in $(seq 100); do adb shell am start  http://127.0.0.1/does-not-exist.html; adb shell input keyevent 3; done
Change-Id: I2cb5610a2277ef641f8e2d7f5ad1c4a72bb4f026
services/core/java/com/android/server/pm/EphemeralResolverConnection.java