diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2020-12-21 20:56:26 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-12-21 20:56:26 +0000 |
| commit | 0aa6ab7887f7ef273a0dcacdba27fe0dd528e867 (patch) | |
| tree | 539d1439b85f611206461586428ca04e2624046f /core/java | |
| parent | cabef01cb3112c9e4eec8208f0fa6bd2602586af (diff) | |
| parent | 9fc40b34c31c8acf03e6f9c7f706ba36bf4565ce (diff) | |
Merge "Register the service-to-app callback whenever the service comes up for BluetoothConnectionCallback. This ensures that if the bluetooth process dies, the callbacks will be re-established once it comes back up."
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/bluetooth/BluetoothAdapter.java | 40 |
1 files changed, 25 insertions, 15 deletions
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java index 2dfbb3ae81e4..e4b2d7075d47 100644 --- a/core/java/android/bluetooth/BluetoothAdapter.java +++ b/core/java/android/bluetooth/BluetoothAdapter.java @@ -2933,6 +2933,16 @@ public final class BluetoothAdapter { } }); } + synchronized (mBluetoothConnectionCallbackExecutorMap) { + if (!mBluetoothConnectionCallbackExecutorMap.isEmpty()) { + try { + mService.registerBluetoothConnectionCallback(mConnectionCallback); + } catch (RemoteException e) { + Log.e(TAG, "onBluetoothServiceUp: Failed to register bluetooth" + + "connection callback", e); + } + } + } } public void onBluetoothServiceDown() { @@ -3582,25 +3592,25 @@ public final class BluetoothAdapter { return false; } - // If the callback map is empty, we register the service-to-app callback - if (mBluetoothConnectionCallbackExecutorMap.isEmpty()) { - try { - mServiceLock.readLock().lock(); - if (mService != null) { - if (!mService.registerBluetoothConnectionCallback(mConnectionCallback)) { - return false; + synchronized (mBluetoothConnectionCallbackExecutorMap) { + // If the callback map is empty, we register the service-to-app callback + if (mBluetoothConnectionCallbackExecutorMap.isEmpty()) { + try { + mServiceLock.readLock().lock(); + if (mService != null) { + if (!mService.registerBluetoothConnectionCallback(mConnectionCallback)) { + return false; + } } + } catch (RemoteException e) { + Log.e(TAG, "", e); + mBluetoothConnectionCallbackExecutorMap.remove(callback); + } finally { + mServiceLock.readLock().unlock(); } - } catch (RemoteException e) { - Log.e(TAG, "", e); - mBluetoothConnectionCallbackExecutorMap.remove(callback); - } finally { - mServiceLock.readLock().unlock(); } - } - // Adds the passed in callback to our map of callbacks to executors - synchronized (mBluetoothConnectionCallbackExecutorMap) { + // Adds the passed in callback to our map of callbacks to executors if (mBluetoothConnectionCallbackExecutorMap.containsKey(callback)) { throw new IllegalArgumentException("This callback has already been registered"); } |
