Loading android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +4 −1 Original line number Diff line number Diff line Loading @@ -4671,9 +4671,12 @@ public class LeAudioService extends ProfileService { return; } for (BluetoothDevice device : mDeviceDescriptors.keySet()) { if (getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { int connection_policy = getConnectionPolicy(device); if (connection_policy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { setAuthorizationForRelatedProfiles(device, true); } setEnabledState( device, connection_policy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); } } finally { mGroupReadLock.unlock(); Loading android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -72,8 +72,10 @@ import com.android.bluetooth.btservice.ServiceFactory; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.csip.CsipSetCoordinatorService; import com.android.bluetooth.flags.Flags; import com.android.bluetooth.gatt.GattService; import com.android.bluetooth.hap.HapClientService; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.le_scan.TransitionalScanHelper; import com.android.bluetooth.mcp.McpService; import com.android.bluetooth.tbs.TbsService; import com.android.bluetooth.vc.VolumeControlService; Loading Loading @@ -133,6 +135,8 @@ public class LeAudioServiceTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Mock private AdapterService mAdapterService; @Mock private GattService mGattService; @Mock private TransitionalScanHelper mTransitionalScanHelper; @Mock private ActiveDeviceManager mActiveDeviceManager; @Mock private AudioManager mAudioManager; @Mock private DatabaseManager mDatabaseManager; Loading Loading @@ -220,6 +224,8 @@ public class LeAudioServiceTest { doAnswer(invocation -> mBondedDevices.toArray(new BluetoothDevice[] {})) .when(mAdapterService) .getBondedDevices(); doReturn(mGattService).when(mAdapterService).getBluetoothGattService(); doReturn(mTransitionalScanHelper).when(mGattService).getTransitionalScanHelper(); LeAudioBroadcasterNativeInterface.setInstance(mLeAudioBroadcasterNativeInterface); LeAudioNativeInterface.setInstance(mNativeInterface); Loading Loading @@ -386,6 +392,26 @@ public class LeAudioServiceTest { assertThat(mService).isEqualTo(LeAudioService.getLeAudioService()); } /** Test enabling disabling device autoconnections when connection policy is set */ @Test public void testEnableDisableProfile() { // Make sure the device is known to the service and is not forbidden to connect mService.createDeviceDescriptor(mSingleDevice, true); when(mDatabaseManager.getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_UNKNOWN); // Verify the device is enabled in the service when policy is not FORBIDDEN during BT Enable mService.handleBluetoothEnabled(); verify(mNativeInterface).setEnableState(eq(mSingleDevice), eq(true)); // Verify the device is disabled in the service when policy is set to FORBIDDEN when(mDatabaseManager.setProfileConnectionPolicy( eq(mSingleDevice), eq(BluetoothProfile.LE_AUDIO), anyInt())) .thenReturn(true); mService.setConnectionPolicy(mSingleDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); verify(mNativeInterface).setEnableState(eq(mSingleDevice), eq(false)); } /** Test stop LeAudio Service */ @Test public void testStopLeAudioService() { Loading Loading
android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +4 −1 Original line number Diff line number Diff line Loading @@ -4671,9 +4671,12 @@ public class LeAudioService extends ProfileService { return; } for (BluetoothDevice device : mDeviceDescriptors.keySet()) { if (getConnectionPolicy(device) != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { int connection_policy = getConnectionPolicy(device); if (connection_policy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN) { setAuthorizationForRelatedProfiles(device, true); } setEnabledState( device, connection_policy != BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); } } finally { mGroupReadLock.unlock(); Loading
android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +26 −0 Original line number Diff line number Diff line Loading @@ -72,8 +72,10 @@ import com.android.bluetooth.btservice.ServiceFactory; import com.android.bluetooth.btservice.storage.DatabaseManager; import com.android.bluetooth.csip.CsipSetCoordinatorService; import com.android.bluetooth.flags.Flags; import com.android.bluetooth.gatt.GattService; import com.android.bluetooth.hap.HapClientService; import com.android.bluetooth.hfp.HeadsetService; import com.android.bluetooth.le_scan.TransitionalScanHelper; import com.android.bluetooth.mcp.McpService; import com.android.bluetooth.tbs.TbsService; import com.android.bluetooth.vc.VolumeControlService; Loading Loading @@ -133,6 +135,8 @@ public class LeAudioServiceTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Mock private AdapterService mAdapterService; @Mock private GattService mGattService; @Mock private TransitionalScanHelper mTransitionalScanHelper; @Mock private ActiveDeviceManager mActiveDeviceManager; @Mock private AudioManager mAudioManager; @Mock private DatabaseManager mDatabaseManager; Loading Loading @@ -220,6 +224,8 @@ public class LeAudioServiceTest { doAnswer(invocation -> mBondedDevices.toArray(new BluetoothDevice[] {})) .when(mAdapterService) .getBondedDevices(); doReturn(mGattService).when(mAdapterService).getBluetoothGattService(); doReturn(mTransitionalScanHelper).when(mGattService).getTransitionalScanHelper(); LeAudioBroadcasterNativeInterface.setInstance(mLeAudioBroadcasterNativeInterface); LeAudioNativeInterface.setInstance(mNativeInterface); Loading Loading @@ -386,6 +392,26 @@ public class LeAudioServiceTest { assertThat(mService).isEqualTo(LeAudioService.getLeAudioService()); } /** Test enabling disabling device autoconnections when connection policy is set */ @Test public void testEnableDisableProfile() { // Make sure the device is known to the service and is not forbidden to connect mService.createDeviceDescriptor(mSingleDevice, true); when(mDatabaseManager.getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_UNKNOWN); // Verify the device is enabled in the service when policy is not FORBIDDEN during BT Enable mService.handleBluetoothEnabled(); verify(mNativeInterface).setEnableState(eq(mSingleDevice), eq(true)); // Verify the device is disabled in the service when policy is set to FORBIDDEN when(mDatabaseManager.setProfileConnectionPolicy( eq(mSingleDevice), eq(BluetoothProfile.LE_AUDIO), anyInt())) .thenReturn(true); mService.setConnectionPolicy(mSingleDevice, BluetoothProfile.CONNECTION_POLICY_FORBIDDEN); verify(mNativeInterface).setEnableState(eq(mSingleDevice), eq(false)); } /** Test stop LeAudio Service */ @Test public void testStopLeAudioService() { Loading