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

Commit 2795a10c authored by Rahul Sabnis's avatar Rahul Sabnis
Browse files

Control VCP and CSIP through the LEA connection policy

Bug: 279990836
Test: atest LeAudioServiceTest#testSetConnectionPolicy
Change-Id: Ida439be27181de66d9a34831c92d292d2bf757e0
parent 3693e36e
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.hfp.HeadsetService;
import com.android.bluetooth.mcp.McpService;
import com.android.bluetooth.tbs.TbsGatt;
@@ -148,6 +149,9 @@ public class LeAudioService extends ProfileService {
    @VisibleForTesting
    VolumeControlService mVolumeControlService;

    @VisibleForTesting
    CsipSetCoordinatorService mCsipSetCoordinatorService;

    @VisibleForTesting
    RemoteCallbackList<IBluetoothLeBroadcastCallback> mBroadcastCallbacks;

@@ -440,6 +444,7 @@ public class LeAudioService extends ProfileService {
        mMcpService = null;
        mTbsService = null;
        mVolumeControlService = null;
        mCsipSetCoordinatorService = null;

        return true;
    }
@@ -2418,9 +2423,35 @@ public class LeAudioService extends ProfileService {
        } else if (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) {
            disconnect(device);
        }
        setLeAudioGattClientProfilesPolicy(device, connectionPolicy);
        return true;
    }

    /**
     * Sets the connection policy for LE Audio GATT client profiles
     * @param device is the remote device
     * @param connectionPolicy is the connection policy we wish to set
     */
    private void setLeAudioGattClientProfilesPolicy(BluetoothDevice device, int connectionPolicy) {
        if (DBG) {
            Log.d(TAG, "setLeAudioGattClientProfilesPolicy for device " + device + " to policy="
                    + connectionPolicy);
        }
        if (mVolumeControlService == null) {
            mVolumeControlService = mServiceFactory.getVolumeControlService();
        }
        if (mVolumeControlService != null) {
            mVolumeControlService.setConnectionPolicy(device, connectionPolicy);
        }

        if (mCsipSetCoordinatorService == null) {
            mCsipSetCoordinatorService = mServiceFactory.getCsipSetCoordinatorService();
        }
        if (mCsipSetCoordinatorService != null) {
            mCsipSetCoordinatorService.setConnectionPolicy(device, connectionPolicy);
        }
    }

    /**
     * Get the connection policy of the profile.
     *
+17 −0
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import com.android.bluetooth.TestUtils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.btservice.ServiceFactory;
import com.android.bluetooth.btservice.storage.DatabaseManager;
import com.android.bluetooth.csip.CsipSetCoordinatorService;
import com.android.bluetooth.hfp.HeadsetService;
import com.android.bluetooth.mcp.McpService;
import com.android.bluetooth.tbs.TbsService;
@@ -115,6 +116,7 @@ public class LeAudioServiceTest {
    @Mock private McpService mMcpService;
    @Mock private TbsService mTbsService;
    @Mock private VolumeControlService mVolumeControlService;
    @Mock private CsipSetCoordinatorService mCsipSetCoordinatorService;
    @Spy private LeAudioObjectsFactory mObjectsFactory = LeAudioObjectsFactory.getInstance();
    @Spy private ServiceFactory mServiceFactory = new ServiceFactory();

@@ -184,6 +186,7 @@ public class LeAudioServiceTest {
        mService.mTbsService = mTbsService;
        mService.mServiceFactory = mServiceFactory;
        when(mServiceFactory.getVolumeControlService()).thenReturn(mVolumeControlService);
        when(mServiceFactory.getCsipSetCoordinatorService()).thenReturn(mCsipSetCoordinatorService);

        LeAudioStackEvent stackEvent =
        new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_NATIVE_INITIALIZED);
@@ -918,12 +921,20 @@ public class LeAudioServiceTest {
        doReturn(true).when(mNativeInterface).disconnectLeAudio(any(BluetoothDevice.class));
        doReturn(true).when(mDatabaseManager).setProfileConnectionPolicy(any(BluetoothDevice.class),
                anyInt(), anyInt());
        when(mVolumeControlService.setConnectionPolicy(any(), anyInt())).thenReturn(true);
        when(mCsipSetCoordinatorService.setConnectionPolicy(any(), anyInt())).thenReturn(true);
        when(mDatabaseManager.getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO))
                .thenReturn(BluetoothProfile.CONNECTION_POLICY_UNKNOWN);

        assertThat(mService.setConnectionPolicy(mSingleDevice,
                BluetoothProfile.CONNECTION_POLICY_ALLOWED)).isTrue();

        // Verify connection policy for CSIP and VCP are also set
        verify(mVolumeControlService, times(1)).setConnectionPolicy(
                mSingleDevice, BluetoothProfile.CONNECTION_POLICY_ALLOWED);
        verify(mCsipSetCoordinatorService, times(1)).setConnectionPolicy(
                mSingleDevice, BluetoothProfile.CONNECTION_POLICY_ALLOWED);

        // Verify the connection state broadcast, and that we are in Connecting state
        verifyConnectionStateIntent(TIMEOUT_MS, mSingleDevice, BluetoothProfile.STATE_CONNECTING,
                BluetoothProfile.STATE_DISCONNECTED);
@@ -948,6 +959,12 @@ public class LeAudioServiceTest {
        assertThat(mService.setConnectionPolicy(mSingleDevice,
                BluetoothProfile.CONNECTION_POLICY_FORBIDDEN)).isTrue();

        // Verify connection policy for CSIP and VCP are also set
        verify(mVolumeControlService, times(1)).setConnectionPolicy(
                mSingleDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);
        verify(mCsipSetCoordinatorService, times(1)).setConnectionPolicy(
                mSingleDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN);

        // Verify the connection state broadcast, and that we are in Connecting state
        verifyConnectionStateIntent(TIMEOUT_MS, mSingleDevice, BluetoothProfile.STATE_DISCONNECTING,
                BluetoothProfile.STATE_CONNECTED);