Merge "[LE unicast] member device add PhonebookAccessPermission" into tm-qpr-dev am: 9db30ad544

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/20176285

Change-Id: I055716122f28835d0e3afb8f042ea5296b5ab6ce
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
SongFerng Wang
2022-10-19 07:04:20 +00:00
committed by Automerger Merge Worker
3 changed files with 66 additions and 5 deletions

View File

@@ -356,7 +356,7 @@ public class CachedBluetoothDeviceManager {
* @return {@code true}, if the device should pair automatically; Otherwise, return * @return {@code true}, if the device should pair automatically; Otherwise, return
* {@code false}. * {@code false}.
*/ */
public synchronized boolean shouldPairByCsip(BluetoothDevice device, int groupId) { private synchronized boolean shouldPairByCsip(BluetoothDevice device, int groupId) {
boolean isOngoingSetMemberPair = mOngoingSetMemberPair != null; boolean isOngoingSetMemberPair = mOngoingSetMemberPair != null;
int bondState = device.getBondState(); int bondState = device.getBondState();
if (isOngoingSetMemberPair || bondState != BluetoothDevice.BOND_NONE if (isOngoingSetMemberPair || bondState != BluetoothDevice.BOND_NONE
@@ -365,12 +365,46 @@ public class CachedBluetoothDeviceManager {
+ " , device.getBondState: " + bondState); + " , device.getBondState: " + bondState);
return false; return false;
} }
Log.d(TAG, "Bond " + device.getName() + " by CSIP");
mOngoingSetMemberPair = device;
return true; 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 * 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 * ongoing set member pair, the cachedBluetoothDevice will be created but the UI

View File

@@ -101,7 +101,14 @@ public class CsipDeviceManager {
return groupId != BluetoothCsipSetCoordinator.GROUP_ID_INVALID; 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); log("getCachedDevice: groupId: " + groupId);
for (int i = mCachedDevices.size() - 1; i >= 0; i--) { for (int i = mCachedDevices.size() - 1; i >= 0; i--) {
CachedBluetoothDevice cachedDevice = mCachedDevices.get(i); CachedBluetoothDevice cachedDevice = mCachedDevices.get(i);

View File

@@ -582,4 +582,24 @@ public class CachedBluetoothDeviceManagerTest {
assertThat(mCachedDeviceManager.isSubDevice(mDevice2)).isTrue(); assertThat(mCachedDeviceManager.isSubDevice(mDevice2)).isTrue();
assertThat(mCachedDeviceManager.isSubDevice(mDevice3)).isFalse(); 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);
}
} }