summaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothAdapter.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2020-12-21 20:56:26 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2020-12-21 20:56:26 +0000
commit931df24293ad9f0b074a29670de38f3dac9274da (patch)
tree185ef24f9714c03885a419e4c0beb298e9fd531e /framework/java/android/bluetooth/BluetoothAdapter.java
parentc97c16748d6736c337da862369fcf2c897e00255 (diff)
parent00040ba31b89439603026638acd511ade955e543 (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 'framework/java/android/bluetooth/BluetoothAdapter.java')
-rw-r--r--framework/java/android/bluetooth/BluetoothAdapter.java40
1 files changed, 25 insertions, 15 deletions
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index 2dfbb3ae81..e4b2d7075d 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/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");
}