Merge "Synchronize adapter registration with mCallbacks" am: a37b682ee4 am: 599bfbca4a
Change-Id: I9a9f5627475155ee7ae78219edcaece38766a167
This commit is contained in:
@@ -119,8 +119,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
private static final int MESSAGE_DISABLE = 2;
|
private static final int MESSAGE_DISABLE = 2;
|
||||||
private static final int MESSAGE_HANDLE_ENABLE_DELAYED = 3;
|
private static final int MESSAGE_HANDLE_ENABLE_DELAYED = 3;
|
||||||
private static final int MESSAGE_HANDLE_DISABLE_DELAYED = 4;
|
private static final int MESSAGE_HANDLE_DISABLE_DELAYED = 4;
|
||||||
private static final int MESSAGE_REGISTER_ADAPTER = 20;
|
|
||||||
private static final int MESSAGE_UNREGISTER_ADAPTER = 21;
|
|
||||||
private static final int MESSAGE_REGISTER_STATE_CHANGE_CALLBACK = 30;
|
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_UNREGISTER_STATE_CHANGE_CALLBACK = 31;
|
||||||
private static final int MESSAGE_BLUETOOTH_SERVICE_CONNECTED = 40;
|
private static final int MESSAGE_BLUETOOTH_SERVICE_CONNECTED = 40;
|
||||||
@@ -642,10 +640,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
Slog.w(TAG, "Callback is null in registerAdapter");
|
Slog.w(TAG, "Callback is null in registerAdapter");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Message msg = mHandler.obtainMessage(MESSAGE_REGISTER_ADAPTER);
|
synchronized (mCallbacks) {
|
||||||
msg.obj = callback;
|
mCallbacks.register(callback);
|
||||||
mHandler.sendMessage(msg);
|
}
|
||||||
|
|
||||||
return mBluetooth;
|
return mBluetooth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -655,9 +652,9 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
||||||
Message msg = mHandler.obtainMessage(MESSAGE_UNREGISTER_ADAPTER);
|
synchronized (mCallbacks) {
|
||||||
msg.obj = callback;
|
mCallbacks.unregister(callback);
|
||||||
mHandler.sendMessage(msg);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerStateChangeCallback(IBluetoothStateChangeCallback callback) {
|
public void registerStateChangeCallback(IBluetoothStateChangeCallback callback) {
|
||||||
@@ -1559,6 +1556,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
* Inform BluetoothAdapter instances that Adapter service is up
|
* Inform BluetoothAdapter instances that Adapter service is up
|
||||||
*/
|
*/
|
||||||
private void sendBluetoothServiceUpCallback() {
|
private void sendBluetoothServiceUpCallback() {
|
||||||
|
synchronized (mCallbacks) {
|
||||||
try {
|
try {
|
||||||
int n = mCallbacks.beginBroadcast();
|
int n = mCallbacks.beginBroadcast();
|
||||||
Slog.d(TAG, "Broadcasting onBluetoothServiceUp() to " + n + " receivers.");
|
Slog.d(TAG, "Broadcasting onBluetoothServiceUp() to " + n + " receivers.");
|
||||||
@@ -1573,11 +1571,13 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
mCallbacks.finishBroadcast();
|
mCallbacks.finishBroadcast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inform BluetoothAdapter instances that Adapter service is down
|
* Inform BluetoothAdapter instances that Adapter service is down
|
||||||
*/
|
*/
|
||||||
private void sendBluetoothServiceDownCallback() {
|
private void sendBluetoothServiceDownCallback() {
|
||||||
|
synchronized (mCallbacks) {
|
||||||
try {
|
try {
|
||||||
int n = mCallbacks.beginBroadcast();
|
int n = mCallbacks.beginBroadcast();
|
||||||
Slog.d(TAG, "Broadcasting onBluetoothServiceDown() to " + n + " receivers.");
|
Slog.d(TAG, "Broadcasting onBluetoothServiceDown() to " + n + " receivers.");
|
||||||
@@ -1592,6 +1592,7 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
mCallbacks.finishBroadcast();
|
mCallbacks.finishBroadcast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
mContext.enforceCallingOrSelfPermission(BLUETOOTH_PERM, "Need BLUETOOTH permission");
|
||||||
@@ -1917,17 +1918,6 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
|
|||||||
mContext.getPackageName());
|
mContext.getPackageName());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MESSAGE_REGISTER_ADAPTER: {
|
|
||||||
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
|
|
||||||
mCallbacks.register(callback);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MESSAGE_UNREGISTER_ADAPTER: {
|
|
||||||
IBluetoothManagerCallback callback = (IBluetoothManagerCallback) msg.obj;
|
|
||||||
mCallbacks.unregister(callback);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK: {
|
case MESSAGE_REGISTER_STATE_CHANGE_CALLBACK: {
|
||||||
IBluetoothStateChangeCallback callback =
|
IBluetoothStateChangeCallback callback =
|
||||||
(IBluetoothStateChangeCallback) msg.obj;
|
(IBluetoothStateChangeCallback) msg.obj;
|
||||||
|
|||||||
Reference in New Issue
Block a user