Merge "Fix data race" into nyc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
838dfe60f0
@@ -40,7 +40,6 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
|
|||||||
private static final String TAG = "BluetoothController";
|
private static final String TAG = "BluetoothController";
|
||||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
|
||||||
private final ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
|
|
||||||
private final LocalBluetoothManager mLocalBluetoothManager;
|
private final LocalBluetoothManager mLocalBluetoothManager;
|
||||||
private final UserManager mUserManager;
|
private final UserManager mUserManager;
|
||||||
private final int mCurrentUser;
|
private final int mCurrentUser;
|
||||||
@@ -78,7 +77,7 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
|
|||||||
pw.print(" mEnabled="); pw.println(mEnabled);
|
pw.print(" mEnabled="); pw.println(mEnabled);
|
||||||
pw.print(" mConnectionState="); pw.println(stateToString(mConnectionState));
|
pw.print(" mConnectionState="); pw.println(stateToString(mConnectionState));
|
||||||
pw.print(" mLastDevice="); pw.println(mLastDevice);
|
pw.print(" mLastDevice="); pw.println(mLastDevice);
|
||||||
pw.print(" mCallbacks.size="); pw.println(mCallbacks.size());
|
pw.print(" mCallbacks.size="); pw.println(mHandler.mCallbacks.size());
|
||||||
pw.println(" Bluetooth Devices:");
|
pw.println(" Bluetooth Devices:");
|
||||||
for (CachedBluetoothDevice device :
|
for (CachedBluetoothDevice device :
|
||||||
mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy()) {
|
mLocalBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy()) {
|
||||||
@@ -106,13 +105,13 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addStateChangedCallback(Callback cb) {
|
public void addStateChangedCallback(Callback cb) {
|
||||||
mCallbacks.add(cb);
|
mHandler.obtainMessage(H.MSG_ADD_CALLBACK, cb).sendToTarget();
|
||||||
mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
|
mHandler.sendEmptyMessage(H.MSG_STATE_CHANGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeStateChangedCallback(Callback cb) {
|
public void removeStateChangedCallback(Callback cb) {
|
||||||
mCallbacks.remove(cb);
|
mHandler.obtainMessage(H.MSG_REMOVE_CALLBACK, cb).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -236,8 +235,12 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final class H extends Handler {
|
private final class H extends Handler {
|
||||||
|
private final ArrayList<BluetoothController.Callback> mCallbacks = new ArrayList<>();
|
||||||
|
|
||||||
private static final int MSG_PAIRED_DEVICES_CHANGED = 1;
|
private static final int MSG_PAIRED_DEVICES_CHANGED = 1;
|
||||||
private static final int MSG_STATE_CHANGED = 2;
|
private static final int MSG_STATE_CHANGED = 2;
|
||||||
|
private static final int MSG_ADD_CALLBACK = 3;
|
||||||
|
private static final int MSG_REMOVE_CALLBACK = 4;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
@@ -248,6 +251,12 @@ public class BluetoothControllerImpl implements BluetoothController, BluetoothCa
|
|||||||
case MSG_STATE_CHANGED:
|
case MSG_STATE_CHANGED:
|
||||||
fireStateChange();
|
fireStateChange();
|
||||||
break;
|
break;
|
||||||
|
case MSG_ADD_CALLBACK:
|
||||||
|
mCallbacks.add((BluetoothController.Callback) msg.obj);
|
||||||
|
break;
|
||||||
|
case MSG_REMOVE_CALLBACK:
|
||||||
|
mCallbacks.remove((BluetoothController.Callback) msg.obj);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user