Merge changes from topic "am-a9fb4bc9-c859-4914-9d39-3a285e071026" into r-keystone-qcom-dev
* changes:
[automerger] Bluetooth: Serialize sending sendBluetoothServiceUpCallback am: d6e7208119
Bluetooth: Serialize sending sendBluetoothServiceUpCallback
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index 13f52b9..9938fb8 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -116,6 +116,7 @@
private static final int MESSAGE_DISABLE = 2;
private static final int MESSAGE_REGISTER_ADAPTER = 20;
private static final int MESSAGE_UNREGISTER_ADAPTER = 21;
+ private static final int MESSAGE_INFORM_ADAPTER_SERVICE_UP = 22;
private static final int MESSAGE_REGISTER_STATE_CHANGE_CALLBACK = 30;
private static final int MESSAGE_UNREGISTER_STATE_CHANGE_CALLBACK = 31;
private static final int MESSAGE_BLUETOOTH_SERVICE_CONNECTED = 40;
@@ -1570,6 +1571,7 @@
*/
private void sendBluetoothServiceUpCallback() {
try {
+ mBluetoothLock.writeLock().lock();
int n = mCallbacks.beginBroadcast();
Slog.d(TAG, "Broadcasting onBluetoothServiceUp() to " + n + " receivers.");
for (int i = 0; i < n; i++) {
@@ -1581,6 +1583,7 @@
}
} finally {
mCallbacks.finishBroadcast();
+ mBluetoothLock.writeLock().unlock();
}
}
@@ -1905,15 +1908,22 @@
break;
case MESSAGE_REGISTER_ADAPTER: {
+ if (DBG) Slog.d(TAG,"MESSAGE_REGISTER_ADAPTER");
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
mCallbacks.register(callback);
break;
}
case MESSAGE_UNREGISTER_ADAPTER: {
+ if (DBG) Slog.d(TAG,"MESSAGE_UNREGISTER_ADAPTER");
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
mCallbacks.unregister(callback);
break;
}
+ case MESSAGE_INFORM_ADAPTER_SERVICE_UP: {
+ if (DBG) Slog.d(TAG,"MESSAGE_INFORM_ADAPTER_SERVICE_UP");
+ sendBluetoothServiceUpCallback();
+ break;
+ }
case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK: {
IBluetoothStateChangeCallback callback =
(IBluetoothStateChangeCallback) msg.obj;
@@ -1982,7 +1992,9 @@
Slog.e(TAG, "Unable to register BluetoothCallback", re);
}
//Inform BluetoothAdapter instances that service is up
- sendBluetoothServiceUpCallback();
+ Message informMsg =
+ mHandler.obtainMessage(MESSAGE_INFORM_ADAPTER_SERVICE_UP);
+ mHandler.sendMessage(informMsg);
//Do enable request
try {