Register connect callback when the service is up
Re-register connection callback when the service is up.
This could enable callbacks to work even when they're
registered before the service is up.
Tag: #feature
Bug: 274812502
Test: atest BluetoothInstrumentationTests
Change-Id: I49500cb71e816256427f56d5a3319022140fd9cc
diff --git a/framework/java/android/bluetooth/BluetoothAdapter.java b/framework/java/android/bluetooth/BluetoothAdapter.java
index dc3648c..05a3151 100644
--- a/framework/java/android/bluetooth/BluetoothAdapter.java
+++ b/framework/java/android/bluetooth/BluetoothAdapter.java
@@ -3983,6 +3983,22 @@
}
}
}
+ synchronized (mBluetoothConnectionCallbackExecutorMap) {
+ if (!mBluetoothConnectionCallbackExecutorMap.isEmpty()) {
+ try {
+ final SynchronousResultReceiver recv =
+ SynchronousResultReceiver.get();
+ mService.registerBluetoothConnectionCallback(
+ mConnectionCallback,
+ mAttributionSource, recv);
+ recv.awaitResultNoInterrupt(getSyncTimeout())
+ .getValue(null);
+ } catch (RemoteException | TimeoutException e) {
+ Log.e(TAG, "onBluetoothServiceUp: Failed to register "
+ + "bluetooth connection callback", e);
+ }
+ }
+ }
} finally {
mServiceLock.readLock().unlock();
}