Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a2025ff0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Tie TBS and MCS authorization to the LEA connection policy" am:...

Merge "Tie TBS and MCS authorization to the LEA connection policy" am: 74ee0447 am: 28a18697 am: 7c509c7b

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2575450



Change-Id: Ia33043e590bf5daf53068405531eaa6d75768f17
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f1217370 7c509c7b
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -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;
@@ -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);
    }
+42 −0
Original line number Diff line number Diff line
@@ -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;