aboutsummaryrefslogtreecommitdiff
path: root/framework/java/android/bluetooth/BluetoothAdapter.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2020-12-22 07:04:59 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-12-22 07:04:59 +0000
commit321f1ccb514abdf06ae4d653f458380aef9fd51e (patch)
treea0b7df03deed41aba612e3fe0d49c2b78dd93875 /framework/java/android/bluetooth/BluetoothAdapter.java
parentaee193424afcba578fe9569c16fd04953467cc63 (diff)
parentbaa3bef832d7687a164abda99a7daa4208a1935b (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." am: 931df24293 am: 2f51154520 am: baa3bef832
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1533089 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ie2489c4307aa21cf42cfae55ed7024ef9109bf1a
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 1713a0c158..406fe8d502 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -2967,6 +2967,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() {
@@ -3616,25 +3626,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");
}