Loading android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +31 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -148,6 +149,9 @@ public class LeAudioService extends ProfileService { @VisibleForTesting VolumeControlService mVolumeControlService; @VisibleForTesting CsipSetCoordinatorService mCsipSetCoordinatorService; @VisibleForTesting RemoteCallbackList<IBluetoothLeBroadcastCallback> mBroadcastCallbacks; Loading Loading @@ -441,6 +445,7 @@ public class LeAudioService extends ProfileService { mMcpService = null; mTbsService = null; mVolumeControlService = null; mCsipSetCoordinatorService = null; return true; } Loading Loading @@ -2427,9 +2432,35 @@ public class LeAudioService extends ProfileService { setAuthorizationForRelatedProfiles(device, false); 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. * Loading android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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); Loading Loading @@ -919,12 +922,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); Loading @@ -949,6 +960,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); Loading Loading
android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +31 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -148,6 +149,9 @@ public class LeAudioService extends ProfileService { @VisibleForTesting VolumeControlService mVolumeControlService; @VisibleForTesting CsipSetCoordinatorService mCsipSetCoordinatorService; @VisibleForTesting RemoteCallbackList<IBluetoothLeBroadcastCallback> mBroadcastCallbacks; Loading Loading @@ -441,6 +445,7 @@ public class LeAudioService extends ProfileService { mMcpService = null; mTbsService = null; mVolumeControlService = null; mCsipSetCoordinatorService = null; return true; } Loading Loading @@ -2427,9 +2432,35 @@ public class LeAudioService extends ProfileService { setAuthorizationForRelatedProfiles(device, false); 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. * Loading
android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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(); Loading Loading @@ -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); Loading Loading @@ -919,12 +922,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); Loading @@ -949,6 +960,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); Loading