Merge "csip: seamless pair with the coordinated set" am: 90ba3faab4 am: ad6a3dacb3
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1829332 Change-Id: I2e85fbbb8cafbb11e67790fae69ff90e812ec05a
This commit is contained in:
@@ -127,6 +127,9 @@ public class BluetoothEventManager {
|
|||||||
addHandler(BluetoothDevice.ACTION_ACL_CONNECTED, new AclStateChangedHandler());
|
addHandler(BluetoothDevice.ACTION_ACL_CONNECTED, new AclStateChangedHandler());
|
||||||
addHandler(BluetoothDevice.ACTION_ACL_DISCONNECTED, new AclStateChangedHandler());
|
addHandler(BluetoothDevice.ACTION_ACL_DISCONNECTED, new AclStateChangedHandler());
|
||||||
|
|
||||||
|
addHandler(BluetoothCsipSetCoordinator.ACTION_CSIS_SET_MEMBER_AVAILABLE,
|
||||||
|
new SetMemberAvailableHandler());
|
||||||
|
|
||||||
registerAdapterIntentReceiver();
|
registerAdapterIntentReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -340,6 +343,12 @@ public class BluetoothEventManager {
|
|||||||
}
|
}
|
||||||
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
|
int bondState = intent.getIntExtra(BluetoothDevice.EXTRA_BOND_STATE,
|
||||||
BluetoothDevice.ERROR);
|
BluetoothDevice.ERROR);
|
||||||
|
|
||||||
|
if (mDeviceManager.onBondStateChangedIfProcess(device, bondState)) {
|
||||||
|
Log.d(TAG, "Should not update UI for the set member");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
|
CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
|
||||||
if (cachedDevice == null) {
|
if (cachedDevice == null) {
|
||||||
Log.w(TAG, "Got bonding state changed for " + device +
|
Log.w(TAG, "Got bonding state changed for " + device +
|
||||||
@@ -506,4 +515,29 @@ public class BluetoothEventManager {
|
|||||||
dispatchAudioModeChanged();
|
dispatchAudioModeChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SetMemberAvailableHandler implements Handler {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent, BluetoothDevice device) {
|
||||||
|
final String action = intent.getAction();
|
||||||
|
if (device == null) {
|
||||||
|
Log.e(TAG, "SetMemberAvailableHandler: device is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == null) {
|
||||||
|
Log.e(TAG, "SetMemberAvailableHandler: action is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int groupId = intent.getIntExtra(BluetoothCsipSetCoordinator.EXTRA_CSIS_GROUP_ID,
|
||||||
|
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||||
|
if (groupId == BluetoothCsipSetCoordinator.GROUP_ID_INVALID) {
|
||||||
|
Log.e(TAG, "SetMemberAvailableHandler: Invalid group id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mDeviceManager.onSetMemberAppear(device, groupId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ public class CachedBluetoothDeviceManager {
|
|||||||
HearingAidDeviceManager mHearingAidDeviceManager;
|
HearingAidDeviceManager mHearingAidDeviceManager;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
CsipDeviceManager mCsipDeviceManager;
|
CsipDeviceManager mCsipDeviceManager;
|
||||||
|
BluetoothDevice mOngoingSetMemberPair;
|
||||||
|
|
||||||
CachedBluetoothDeviceManager(Context context, LocalBluetoothManager localBtManager) {
|
CachedBluetoothDeviceManager(Context context, LocalBluetoothManager localBtManager) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -337,6 +338,74 @@ public class CachedBluetoothDeviceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when we found a set member of a group. The function will check the {@code groupId} if
|
||||||
|
* it exists and if there is a ongoing pair, the device would be ignored.
|
||||||
|
*
|
||||||
|
* @param device The found device
|
||||||
|
* @param groupId The group id of the found device
|
||||||
|
*/
|
||||||
|
public synchronized void onSetMemberAppear(BluetoothDevice device, int groupId) {
|
||||||
|
Log.d(TAG, "onSetMemberAppear, groupId: " + groupId + " device: " + device.toString());
|
||||||
|
|
||||||
|
if (mOngoingSetMemberPair != null) {
|
||||||
|
Log.d(TAG, "Ongoing set memberPairing in process, drop it!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mCsipDeviceManager.onSetMemberAppear(device, groupId)) {
|
||||||
|
mOngoingSetMemberPair = device;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the bond state change. If the bond state change is related with the
|
||||||
|
* ongoing set member pair, the cachedBluetoothDevice will be created but the UI
|
||||||
|
* would not be updated. For the other case, return {@code false} to go through the normal
|
||||||
|
* flow.
|
||||||
|
*
|
||||||
|
* @param device The device
|
||||||
|
* @param bondState The new bond state
|
||||||
|
*
|
||||||
|
* @return {@code true}, if the bond state change for the device is handled inside this
|
||||||
|
* function, and would not like to update the UI. If not, return {@code false}.
|
||||||
|
*/
|
||||||
|
public synchronized boolean onBondStateChangedIfProcess(BluetoothDevice device, int bondState) {
|
||||||
|
if (mOngoingSetMemberPair == null || !mOngoingSetMemberPair.equals(device)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bondState == BluetoothDevice.BOND_BONDING) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
mOngoingSetMemberPair = null;
|
||||||
|
if (bondState != BluetoothDevice.BOND_NONE) {
|
||||||
|
if (findDevice(device) == null) {
|
||||||
|
final LocalBluetoothProfileManager profileManager = mBtManager.getProfileManager();
|
||||||
|
CachedBluetoothDevice newDevice =
|
||||||
|
new CachedBluetoothDevice(mContext, profileManager, device);
|
||||||
|
mCachedDevices.add(newDevice);
|
||||||
|
findDevice(device).connect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the device is the one which is initial paired locally by CSIP. The setting
|
||||||
|
* would depned on it to accept the pairing request automatically
|
||||||
|
*
|
||||||
|
* @param device The device
|
||||||
|
*
|
||||||
|
* @return {@code true}, if the device is ongoing pair by CSIP. Otherwise, return
|
||||||
|
* {@code false}.
|
||||||
|
*/
|
||||||
|
public boolean isOngoingPairByCsip(BluetoothDevice device) {
|
||||||
|
return !(mOngoingSetMemberPair == null) && mOngoingSetMemberPair.equals(device);
|
||||||
|
}
|
||||||
|
|
||||||
private void log(String msg) {
|
private void log(String msg) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, msg);
|
Log.d(TAG, msg);
|
||||||
|
|||||||
@@ -239,6 +239,29 @@ public class CsipDeviceManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when we found a set member of a group. The function will check bond state, and
|
||||||
|
* the {@code groupId} if it exists, and then create the bond.
|
||||||
|
*
|
||||||
|
* @param device The found device
|
||||||
|
* @param groupId The group id of the found device
|
||||||
|
*
|
||||||
|
* @return {@code true}, if the we create bond with the device. Otherwise, return
|
||||||
|
* {@code false}.
|
||||||
|
*/
|
||||||
|
public boolean onSetMemberAppear(BluetoothDevice device, int groupId) {
|
||||||
|
if (device.getBondState() != BluetoothDevice.BOND_NONE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getCachedDevice(groupId) != null) {
|
||||||
|
device.createBond(BluetoothDevice.TRANSPORT_LE);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void log(String msg) {
|
private void log(String msg) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, msg);
|
Log.d(TAG, msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user