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: 0aa6ab7887
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1533089 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: I100198f3f5c224c5ca08582d40ece0ef2daf4701
This commit is contained in:
@@ -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() {
|
public void onBluetoothServiceDown() {
|
||||||
@@ -3582,25 +3592,25 @@ public final class BluetoothAdapter {
|
|||||||
return false;
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} 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) {
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adds the passed in callback to our map of callbacks to executors
|
||||||
if (mBluetoothConnectionCallbackExecutorMap.containsKey(callback)) {
|
if (mBluetoothConnectionCallbackExecutorMap.containsKey(callback)) {
|
||||||
throw new IllegalArgumentException("This callback has already been registered");
|
throw new IllegalArgumentException("This callback has already been registered");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user