Merge "[LE unicast] member device add PhonebookAccessPermission" into tm-qpr-dev am: 9db30ad544 am: 3ffc2dae60
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20176285 Change-Id: Ic3e9f51e47869efec0f2e221dba301865c9705e7 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -356,7 +356,7 @@ public class CachedBluetoothDeviceManager {
|
||||
* @return {@code true}, if the device should pair automatically; Otherwise, return
|
||||
* {@code false}.
|
||||
*/
|
||||
public synchronized boolean shouldPairByCsip(BluetoothDevice device, int groupId) {
|
||||
private synchronized boolean shouldPairByCsip(BluetoothDevice device, int groupId) {
|
||||
boolean isOngoingSetMemberPair = mOngoingSetMemberPair != null;
|
||||
int bondState = device.getBondState();
|
||||
if (isOngoingSetMemberPair || bondState != BluetoothDevice.BOND_NONE
|
||||
@@ -365,12 +365,46 @@ public class CachedBluetoothDeviceManager {
|
||||
+ " , device.getBondState: " + bondState);
|
||||
return false;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Bond " + device.getName() + " by CSIP");
|
||||
mOngoingSetMemberPair = device;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when we found a set member of a group. The function will check the {@code groupId} if
|
||||
* it exists and the bond state of the device is BOND_NONE, and if there isn't any ongoing pair
|
||||
* , and then pair the device automatically.
|
||||
*
|
||||
* @param device The found device
|
||||
* @param groupId The group id of the found device
|
||||
*/
|
||||
public synchronized void pairDeviceByCsip(BluetoothDevice device, int groupId) {
|
||||
if (!shouldPairByCsip(device, groupId)) {
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "Bond " + device.getAnonymizedAddress() + " by CSIP");
|
||||
mOngoingSetMemberPair = device;
|
||||
syncConfigFromMainDevice(device, groupId);
|
||||
device.createBond(BluetoothDevice.TRANSPORT_LE);
|
||||
}
|
||||
|
||||
private void syncConfigFromMainDevice(BluetoothDevice device, int groupId) {
|
||||
if (!isOngoingPairByCsip(device)) {
|
||||
return;
|
||||
}
|
||||
CachedBluetoothDevice memberDevice = findDevice(device);
|
||||
CachedBluetoothDevice mainDevice = mCsipDeviceManager.findMainDevice(memberDevice);
|
||||
if (mainDevice == null) {
|
||||
mainDevice = mCsipDeviceManager.getCachedDevice(groupId);
|
||||
}
|
||||
|
||||
if (mainDevice == null || mainDevice.equals(memberDevice)) {
|
||||
Log.d(TAG, "no mainDevice");
|
||||
return;
|
||||
}
|
||||
|
||||
// The memberDevice set PhonebookAccessPermission
|
||||
device.setPhonebookAccessPermission(mainDevice.getDevice().getPhonebookAccessPermission());
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -101,7 +101,14 @@ public class CsipDeviceManager {
|
||||
return groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID;
|
||||
}
|
||||
|
||||
private CachedBluetoothDevice getCachedDevice(int groupId) {
|
||||
/**
|
||||
* To find the device with {@code groupId}.
|
||||
*
|
||||
* @param groupId The group id
|
||||
* @return if we could find a device with this {@code groupId} return this device. Otherwise,
|
||||
* return null.
|
||||
*/
|
||||
public CachedBluetoothDevice getCachedDevice(int groupId) {
|
||||
log("getCachedDevice: groupId: " + groupId);
|
||||
for (int i = mCachedDevices.size() - 1; i >= 0; i--) {
|
||||
CachedBluetoothDevice cachedDevice = mCachedDevices.get(i);
|
||||
|
||||
@@ -582,4 +582,24 @@ public class CachedBluetoothDeviceManagerTest {
|
||||
assertThat(mCachedDeviceManager.isSubDevice(mDevice2)).isTrue();
|
||||
assertThat(mCachedDeviceManager.isSubDevice(mDevice3)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pairDeviceByCsip_device2AndCapGroup1_device2StartsPairing() {
|
||||
doReturn(CAP_GROUP1).when(mCsipSetCoordinatorProfile).getGroupUuidMapByDevice(mDevice1);
|
||||
when(mDevice1.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED);
|
||||
when(mDevice1.getPhonebookAccessPermission()).thenReturn(BluetoothDevice.ACCESS_ALLOWED);
|
||||
CachedBluetoothDevice cachedDevice1 = mCachedDeviceManager.addDevice(mDevice1);
|
||||
assertThat(cachedDevice1).isNotNull();
|
||||
when(mDevice2.getBondState()).thenReturn(BluetoothDevice.BOND_NONE);
|
||||
CachedBluetoothDevice cachedDevice2 = mCachedDeviceManager.addDevice(mDevice2);
|
||||
assertThat(cachedDevice2).isNotNull();
|
||||
|
||||
int groupId = CAP_GROUP1.keySet().stream().findFirst().orElse(
|
||||
BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||
assertThat(groupId).isNotEqualTo(BluetoothCsipSetCoordinator.GROUP_ID_INVALID);
|
||||
mCachedDeviceManager.pairDeviceByCsip(mDevice2, groupId);
|
||||
|
||||
verify(mDevice2).setPhonebookAccessPermission(BluetoothDevice.ACCESS_ALLOWED);
|
||||
verify(mDevice2).createBond(BluetoothDevice.TRANSPORT_LE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user