diff options
| author | Hui Peng <phui@google.com> | 2022-09-02 21:19:21 +0000 |
|---|---|---|
| committer | Cherrypicker Worker <android-build-cherrypicker-worker@google.com> | 2022-09-09 16:35:57 +0000 |
| commit | 340bc09ae7d906f6bce99694d1db47174397913b (patch) | |
| tree | cfaec0d0bd9e2fc3009d245c56588af19c5f396d /framework/java/android/bluetooth/BluetoothAdapter.java | |
| parent | 900f91246c870c955be9e4405031268eb712b89e (diff) | |
Fix a deadlock bug in Bluetooth Framework
Both BluetoothDevice and BluetoothAdapter maintain a reference to a
IBluetooth proxy object (sService) and each class uses a lock object
to serialize access to their own reference. These references are updated
by BluetoothManagerService with registered callbacks (IBlueoothManagerCallback).
In the current implentaion, when an app thread uses BluetoothDevice#getService
to access its reference to service proxy, with the BluetoothManager updating it
at the same time, as the order of taking the locks is different, deadlock is possible
under certain circumstances (triggered in bug 241212710).
This patch fixes the deadlock issue by removing the reference to service
proxy object in BluetoothDevice class, and accesses are via
the reference in BluetoothAdapter class instead.
Test: existing unit tests
Bug: 241212710
Tag: #stability
Change-Id: I15cd2707acf5caa04d97c6ede3bd5bedd6475c65
(cherry picked from commit 83c6281b616f597ceacdcf84e20d14368e190875)
Merged-In: I15cd2707acf5caa04d97c6ede3bd5bedd6475c65
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothAdapter.java')
| -rw-r--r-- | framework/java/android/bluetooth/BluetoothAdapter.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java index 0cd9254618..0cdbd79b5f 100644 --- a/framework/java/android/bluetooth/BluetoothAdapter.java +++ b/framework/java/android/bluetooth/BluetoothAdapter.java @@ -4233,14 +4233,18 @@ public final class BluetoothAdapter { /*package*/ IBluetooth getBluetoothService() { synchronized (sServiceLock) { - if (sProxyServiceStateCallbacks.isEmpty()) { - throw new IllegalStateException( - "Anonymous service access requires at least one lifecycle in process"); - } return sService; } } + /** + * Registers a IBluetoothManagerCallback and returns the cached + * Bluetooth service proxy object. + * + * TODO: rename this API to registerBlueoothManagerCallback or something? + * the current name does not match what it does very well. + * + * / @UnsupportedAppUsage /*package*/ IBluetooth getBluetoothService(IBluetoothManagerCallback cb) { Objects.requireNonNull(cb); |
