Loading android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +11 −1 Original line number Diff line number Diff line Loading @@ -2414,9 +2414,17 @@ public class LeAudioService extends ProfileService { connectionPolicy)) { return false; } if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED) { // Authorizes LEA GATT server services if already assigned to a group int groupId = getGroupId(device); if (groupId != LE_AUDIO_GROUP_ID_INVALID) { setAuthorizationForRelatedProfiles(device, true); } connect(device); } else if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { // Remove authorization for LEA GATT server services setAuthorizationForRelatedProfiles(device, false); disconnect(device); } return true; Loading Loading @@ -2556,9 +2564,11 @@ public class LeAudioService extends ProfileService { synchronized (mGroupLock) { for (BluetoothDevice device : mDeviceDescriptors.keySet()) { if (getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { setAuthorizationForRelatedProfiles(device, true); } } } startAudioServersBackgroundScan(/* retry = */ false); } Loading android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +42 −0 Original line number Diff line number Diff line Loading @@ -1748,6 +1748,48 @@ public class LeAudioServiceTest { verify(mMcpService, times(1)).setDeviceAuthorized(mRightDevice, false); } /** * Test verifying that when the LE Audio connection policy of a device is set to * {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN}, we unauthorize McpService and * TbsService. When the LE Audio connection policy is set to * {@link BluetoothProfile#CONNECTION_POLICY_ALLOWED}, we will authorize these services. */ @Test public void testMcsAndTbsAuthorizationWithConnectionPolicy() { int groupId = 1; mService.handleBluetoothEnabled(); doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class)); doReturn(true).when(mNativeInterface).disconnectLeAudio(any(BluetoothDevice.class)); doReturn(true).when(mDatabaseManager).setProfileConnectionPolicy(any(BluetoothDevice.class), anyInt(), anyInt()); when(mDatabaseManager.getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_UNKNOWN); // Ensures GATT server services are not authorized when the device does not have a group assertThat(mService.setConnectionPolicy(mSingleDevice, BluetoothProfile.CONNECTION_POLICY_ALLOWED)).isTrue(); verify(mMcpService, never()).setDeviceAuthorized(mSingleDevice, false); verify(mTbsService, never()).setDeviceAuthorized(mSingleDevice, false); // Connects the test device and verifies GATT server services are authorized connectTestDevice(mSingleDevice, groupId); verify(mMcpService, times(1)).setDeviceAuthorized(mSingleDevice, true); verify(mTbsService, times(1)).setDeviceAuthorized(mSingleDevice, true); // Ensure that disconnecting unauthorizes GATT server services assertThat(mService.setConnectionPolicy(mSingleDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN)).isTrue(); verify(mMcpService, times(1)).setDeviceAuthorized(mSingleDevice, false); verify(mTbsService, times(1)).setDeviceAuthorized(mSingleDevice, false); // Connecting a device that has a group re-authorizes the GATT server services assertThat(mService.setConnectionPolicy(mSingleDevice, BluetoothProfile.CONNECTION_POLICY_ALLOWED)).isTrue(); verify(mMcpService, times(2)).setDeviceAuthorized(mSingleDevice, true); verify(mTbsService, times(2)).setDeviceAuthorized(mSingleDevice, true); } @Test public void testGetGroupDevices() { int firstGroupId = 1; Loading Loading
android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +11 −1 Original line number Diff line number Diff line Loading @@ -2414,9 +2414,17 @@ public class LeAudioService extends ProfileService { connectionPolicy)) { return false; } if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED) { // Authorizes LEA GATT server services if already assigned to a group int groupId = getGroupId(device); if (groupId != LE_AUDIO_GROUP_ID_INVALID) { setAuthorizationForRelatedProfiles(device, true); } connect(device); } else if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { // Remove authorization for LEA GATT server services setAuthorizationForRelatedProfiles(device, false); disconnect(device); } return true; Loading Loading @@ -2556,9 +2564,11 @@ public class LeAudioService extends ProfileService { synchronized (mGroupLock) { for (BluetoothDevice device : mDeviceDescriptors.keySet()) { if (getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { setAuthorizationForRelatedProfiles(device, true); } } } startAudioServersBackgroundScan(/* retry = */ false); } Loading
android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +42 −0 Original line number Diff line number Diff line Loading @@ -1748,6 +1748,48 @@ public class LeAudioServiceTest { verify(mMcpService, times(1)).setDeviceAuthorized(mRightDevice, false); } /** * Test verifying that when the LE Audio connection policy of a device is set to * {@link BluetoothProfile#CONNECTION_POLICY_FORBIDDEN}, we unauthorize McpService and * TbsService. When the LE Audio connection policy is set to * {@link BluetoothProfile#CONNECTION_POLICY_ALLOWED}, we will authorize these services. */ @Test public void testMcsAndTbsAuthorizationWithConnectionPolicy() { int groupId = 1; mService.handleBluetoothEnabled(); doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class)); doReturn(true).when(mNativeInterface).disconnectLeAudio(any(BluetoothDevice.class)); doReturn(true).when(mDatabaseManager).setProfileConnectionPolicy(any(BluetoothDevice.class), anyInt(), anyInt()); when(mDatabaseManager.getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_UNKNOWN); // Ensures GATT server services are not authorized when the device does not have a group assertThat(mService.setConnectionPolicy(mSingleDevice, BluetoothProfile.CONNECTION_POLICY_ALLOWED)).isTrue(); verify(mMcpService, never()).setDeviceAuthorized(mSingleDevice, false); verify(mTbsService, never()).setDeviceAuthorized(mSingleDevice, false); // Connects the test device and verifies GATT server services are authorized connectTestDevice(mSingleDevice, groupId); verify(mMcpService, times(1)).setDeviceAuthorized(mSingleDevice, true); verify(mTbsService, times(1)).setDeviceAuthorized(mSingleDevice, true); // Ensure that disconnecting unauthorizes GATT server services assertThat(mService.setConnectionPolicy(mSingleDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN)).isTrue(); verify(mMcpService, times(1)).setDeviceAuthorized(mSingleDevice, false); verify(mTbsService, times(1)).setDeviceAuthorized(mSingleDevice, false); // Connecting a device that has a group re-authorizes the GATT server services assertThat(mService.setConnectionPolicy(mSingleDevice, BluetoothProfile.CONNECTION_POLICY_ALLOWED)).isTrue(); verify(mMcpService, times(2)).setDeviceAuthorized(mSingleDevice, true); verify(mTbsService, times(2)).setDeviceAuthorized(mSingleDevice, true); } @Test public void testGetGroupDevices() { int firstGroupId = 1; Loading