Loading android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +8 −4 Original line number Diff line number Diff line Loading @@ -421,7 +421,8 @@ public class LeAudioService extends ProfileService { sLeAudioService = instance; } private int getAudioDeviceGroupVolume(int groupId) { @VisibleForTesting int getAudioDeviceGroupVolume(int groupId) { if (mVolumeControlService == null) { mVolumeControlService = mServiceFactory.getVolumeControlService(); if (mVolumeControlService == null) { Loading Loading @@ -1235,7 +1236,8 @@ public class LeAudioService extends ProfileService { } } private void handleGroupIdleDuringCall() { @VisibleForTesting void handleGroupIdleDuringCall() { if (mHfpHandoverDevice == null) { if (DBG) { Log.d(TAG, "There is no HFP handover"); Loading Loading @@ -1647,7 +1649,8 @@ public class LeAudioService extends ProfileService { } } private List<BluetoothDevice> getConnectedPeerDevices(int groupId) { @VisibleForTesting List<BluetoothDevice> getConnectedPeerDevices(int groupId) { List<BluetoothDevice> result = new ArrayList<>(); for (BluetoothDevice peerDevice : getConnectedDevices()) { if (getGroupId(peerDevice) == groupId) { Loading Loading @@ -1754,7 +1757,8 @@ public class LeAudioService extends ProfileService { } } private synchronized boolean isSilentModeEnabled() { @VisibleForTesting synchronized boolean isSilentModeEnabled() { return mStoredRingerMode != AudioManager.RINGER_MODE_NORMAL; } Loading android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +113 −23 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; Loading Loading @@ -58,7 +59,9 @@ import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.R; 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.hfp.HeadsetService; import com.android.bluetooth.vc.VolumeControlService; import org.junit.After; Loading @@ -69,6 +72,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.Spy; Loading Loading @@ -112,7 +116,7 @@ public class LeAudioServiceTest { @Mock private VolumeControlService mVolumeControlService; @Mock private LeAudioTmapGattServer mTmapGattServer; @Spy private LeAudioObjectsFactory mObjectsFactory = LeAudioObjectsFactory.getInstance(); @Spy private ServiceFactory mServiceFactory = new ServiceFactory(); @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); Loading Loading @@ -184,7 +188,8 @@ public class LeAudioServiceTest { LeAudioNativeInterface.setInstance(mNativeInterface); startService(); mService.mAudioManager = mAudioManager; mService.mVolumeControlService = mVolumeControlService; mService.mServiceFactory = mServiceFactory; when(mServiceFactory.getVolumeControlService()).thenReturn(mVolumeControlService); LeAudioStackEvent stackEvent = new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_NATIVE_INITIALIZED); Loading Loading @@ -981,24 +986,6 @@ public class LeAudioServiceTest { } } /** * Test matching connection state devices. */ @Test public void testGetDevicesMatchingConnectionState() { // Update the device priority so okToConnect() returns true doReturn(new ParcelUuid[]{BluetoothUuid.LE_AUDIO}).when(mAdapterService) .getRemoteUuids(any(BluetoothDevice.class)); doReturn(new BluetoothDevice[]{mSingleDevice}).when(mAdapterService).getBondedDevices(); when(mDatabaseManager .getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class)); doReturn(true).when(mNativeInterface).disconnectLeAudio(any(BluetoothDevice.class)); connectTestDevice(mSingleDevice, testGroupId); } /** * Test adding node */ Loading Loading @@ -1080,6 +1067,16 @@ public class LeAudioServiceTest { mService.messageFromNative(groupStatusChangedEvent); assertThat(mService.getActiveDevices().contains(mSingleDevice)).isTrue(); // Remove device from group groupStatusChangedEvent = new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_GROUP_NODE_STATUS_CHANGED); groupStatusChangedEvent.device = mSingleDevice; groupStatusChangedEvent.valueInt1 = groupId; groupStatusChangedEvent.valueInt2 = LeAudioStackEvent.GROUP_NODE_REMOVED; mService.messageFromNative(groupStatusChangedEvent); assertThat(mService.getActiveDevices().contains(mSingleDevice)).isFalse(); } private void injectGroupStatusChange(int groupId, int groupStatus) { Loading Loading @@ -1267,7 +1264,6 @@ public class LeAudioServiceTest { INPUT_SELECTABLE_CONFIG, OUTPUT_SELECTABLE_CONFIG); TestUtils.waitForLooperToFinishScheduledTask(mService.getMainLooper()); assertThat(onGroupCodecConfChangedCallbackCalled).isTrue(); Loading Loading @@ -1466,4 +1462,98 @@ public class LeAudioServiceTest { assertThat(profileInfo.getValue().getVolume()).isEqualTo(volume); } @Test public void testGetAudioDeviceGroupVolume_whenVolumeControlServiceIsNull() { mService.mVolumeControlService = null; doReturn(null).when(mServiceFactory).getVolumeControlService(); int groupId = 1; assertThat(mService.getAudioDeviceGroupVolume(groupId)).isEqualTo(-1); } @Test public void testGetAudioLocation() { assertThat(mService.getAudioLocation(null)) .isEqualTo(BluetoothLeAudio.AUDIO_LOCATION_INVALID); int sinkAudioLocation = 10; LeAudioStackEvent stackEvent = new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_SINK_AUDIO_LOCATION_AVAILABLE); stackEvent.device = mSingleDevice; stackEvent.valueInt1 = sinkAudioLocation; mService.messageFromNative(stackEvent); assertThat(mService.getAudioLocation(mSingleDevice)).isEqualTo(sinkAudioLocation); } @Test public void testGetConnectedPeerDevices() { doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class)); connectTestDevice(mLeftDevice, testGroupId); connectTestDevice(mRightDevice, testGroupId); List<BluetoothDevice> peerDevices = mService.getConnectedPeerDevices(testGroupId); assertThat(peerDevices.contains(mLeftDevice)).isTrue(); assertThat(peerDevices.contains(mRightDevice)).isTrue(); } @Test public void testGetDevicesMatchingConnectionStates() { assertThat(mService.getDevicesMatchingConnectionStates(null)).isEmpty(); int[] states = new int[] { BluetoothProfile.STATE_CONNECTED }; doReturn(null).when(mAdapterService).getBondedDevices(); assertThat(mService.getDevicesMatchingConnectionStates(states)).isEmpty(); doReturn(new BluetoothDevice[] { mSingleDevice }).when(mAdapterService).getBondedDevices(); assertThat(mService.getDevicesMatchingConnectionStates(states)).isEmpty(); } @Test public void testDefaultValuesOfSeveralGetters() { assertThat(mService.getMaximumNumberOfBroadcasts()).isEqualTo(1); assertThat(mService.isPlaying(100)).isFalse(); assertThat(mService.isValidDeviceGroup(LE_AUDIO_GROUP_ID_INVALID)).isFalse(); } @Test public void testHandleGroupIdleDuringCall() { BluetoothDevice headsetDevice = TestUtils.getTestDevice(mAdapter, 5); HeadsetService headsetService = Mockito.mock(HeadsetService.class); when(mServiceFactory.getHeadsetService()).thenReturn(headsetService); mService.mHfpHandoverDevice = null; mService.handleGroupIdleDuringCall(); verify(headsetService, never()).getActiveDevice(); mService.mHfpHandoverDevice = headsetDevice; when(headsetService.getActiveDevice()).thenReturn(headsetDevice); mService.handleGroupIdleDuringCall(); verify(headsetService).connectAudio(); assertThat(mService.mHfpHandoverDevice).isNull(); mService.mHfpHandoverDevice = headsetDevice; when(headsetService.getActiveDevice()).thenReturn(null); mService.handleGroupIdleDuringCall(); verify(headsetService).setActiveDevice(headsetDevice); assertThat(mService.mHfpHandoverDevice).isNull(); } @Test public void testDump_doesNotCrash() { doReturn(new ParcelUuid[]{BluetoothUuid.LE_AUDIO}).when(mAdapterService) .getRemoteUuids(any(BluetoothDevice.class)); doReturn(new BluetoothDevice[]{mSingleDevice}).when(mAdapterService).getBondedDevices(); when(mDatabaseManager .getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class)); doReturn(true).when(mNativeInterface).disconnectLeAudio(any(BluetoothDevice.class)); connectTestDevice(mSingleDevice, testGroupId); StringBuilder sb = new StringBuilder(); mService.dump(sb); } } Loading
android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +8 −4 Original line number Diff line number Diff line Loading @@ -421,7 +421,8 @@ public class LeAudioService extends ProfileService { sLeAudioService = instance; } private int getAudioDeviceGroupVolume(int groupId) { @VisibleForTesting int getAudioDeviceGroupVolume(int groupId) { if (mVolumeControlService == null) { mVolumeControlService = mServiceFactory.getVolumeControlService(); if (mVolumeControlService == null) { Loading Loading @@ -1235,7 +1236,8 @@ public class LeAudioService extends ProfileService { } } private void handleGroupIdleDuringCall() { @VisibleForTesting void handleGroupIdleDuringCall() { if (mHfpHandoverDevice == null) { if (DBG) { Log.d(TAG, "There is no HFP handover"); Loading Loading @@ -1647,7 +1649,8 @@ public class LeAudioService extends ProfileService { } } private List<BluetoothDevice> getConnectedPeerDevices(int groupId) { @VisibleForTesting List<BluetoothDevice> getConnectedPeerDevices(int groupId) { List<BluetoothDevice> result = new ArrayList<>(); for (BluetoothDevice peerDevice : getConnectedDevices()) { if (getGroupId(peerDevice) == groupId) { Loading Loading @@ -1754,7 +1757,8 @@ public class LeAudioService extends ProfileService { } } private synchronized boolean isSilentModeEnabled() { @VisibleForTesting synchronized boolean isSilentModeEnabled() { return mStoredRingerMode != AudioManager.RINGER_MODE_NORMAL; } Loading
android/app/tests/unit/src/com/android/bluetooth/le_audio/LeAudioServiceTest.java +113 −23 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; Loading Loading @@ -58,7 +59,9 @@ import androidx.test.runner.AndroidJUnit4; import com.android.bluetooth.R; 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.hfp.HeadsetService; import com.android.bluetooth.vc.VolumeControlService; import org.junit.After; Loading @@ -69,6 +72,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.Spy; Loading Loading @@ -112,7 +116,7 @@ public class LeAudioServiceTest { @Mock private VolumeControlService mVolumeControlService; @Mock private LeAudioTmapGattServer mTmapGattServer; @Spy private LeAudioObjectsFactory mObjectsFactory = LeAudioObjectsFactory.getInstance(); @Spy private ServiceFactory mServiceFactory = new ServiceFactory(); @Rule public final ServiceTestRule mServiceRule = new ServiceTestRule(); Loading Loading @@ -184,7 +188,8 @@ public class LeAudioServiceTest { LeAudioNativeInterface.setInstance(mNativeInterface); startService(); mService.mAudioManager = mAudioManager; mService.mVolumeControlService = mVolumeControlService; mService.mServiceFactory = mServiceFactory; when(mServiceFactory.getVolumeControlService()).thenReturn(mVolumeControlService); LeAudioStackEvent stackEvent = new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_NATIVE_INITIALIZED); Loading Loading @@ -981,24 +986,6 @@ public class LeAudioServiceTest { } } /** * Test matching connection state devices. */ @Test public void testGetDevicesMatchingConnectionState() { // Update the device priority so okToConnect() returns true doReturn(new ParcelUuid[]{BluetoothUuid.LE_AUDIO}).when(mAdapterService) .getRemoteUuids(any(BluetoothDevice.class)); doReturn(new BluetoothDevice[]{mSingleDevice}).when(mAdapterService).getBondedDevices(); when(mDatabaseManager .getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class)); doReturn(true).when(mNativeInterface).disconnectLeAudio(any(BluetoothDevice.class)); connectTestDevice(mSingleDevice, testGroupId); } /** * Test adding node */ Loading Loading @@ -1080,6 +1067,16 @@ public class LeAudioServiceTest { mService.messageFromNative(groupStatusChangedEvent); assertThat(mService.getActiveDevices().contains(mSingleDevice)).isTrue(); // Remove device from group groupStatusChangedEvent = new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_GROUP_NODE_STATUS_CHANGED); groupStatusChangedEvent.device = mSingleDevice; groupStatusChangedEvent.valueInt1 = groupId; groupStatusChangedEvent.valueInt2 = LeAudioStackEvent.GROUP_NODE_REMOVED; mService.messageFromNative(groupStatusChangedEvent); assertThat(mService.getActiveDevices().contains(mSingleDevice)).isFalse(); } private void injectGroupStatusChange(int groupId, int groupStatus) { Loading Loading @@ -1267,7 +1264,6 @@ public class LeAudioServiceTest { INPUT_SELECTABLE_CONFIG, OUTPUT_SELECTABLE_CONFIG); TestUtils.waitForLooperToFinishScheduledTask(mService.getMainLooper()); assertThat(onGroupCodecConfChangedCallbackCalled).isTrue(); Loading Loading @@ -1466,4 +1462,98 @@ public class LeAudioServiceTest { assertThat(profileInfo.getValue().getVolume()).isEqualTo(volume); } @Test public void testGetAudioDeviceGroupVolume_whenVolumeControlServiceIsNull() { mService.mVolumeControlService = null; doReturn(null).when(mServiceFactory).getVolumeControlService(); int groupId = 1; assertThat(mService.getAudioDeviceGroupVolume(groupId)).isEqualTo(-1); } @Test public void testGetAudioLocation() { assertThat(mService.getAudioLocation(null)) .isEqualTo(BluetoothLeAudio.AUDIO_LOCATION_INVALID); int sinkAudioLocation = 10; LeAudioStackEvent stackEvent = new LeAudioStackEvent(LeAudioStackEvent.EVENT_TYPE_SINK_AUDIO_LOCATION_AVAILABLE); stackEvent.device = mSingleDevice; stackEvent.valueInt1 = sinkAudioLocation; mService.messageFromNative(stackEvent); assertThat(mService.getAudioLocation(mSingleDevice)).isEqualTo(sinkAudioLocation); } @Test public void testGetConnectedPeerDevices() { doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class)); connectTestDevice(mLeftDevice, testGroupId); connectTestDevice(mRightDevice, testGroupId); List<BluetoothDevice> peerDevices = mService.getConnectedPeerDevices(testGroupId); assertThat(peerDevices.contains(mLeftDevice)).isTrue(); assertThat(peerDevices.contains(mRightDevice)).isTrue(); } @Test public void testGetDevicesMatchingConnectionStates() { assertThat(mService.getDevicesMatchingConnectionStates(null)).isEmpty(); int[] states = new int[] { BluetoothProfile.STATE_CONNECTED }; doReturn(null).when(mAdapterService).getBondedDevices(); assertThat(mService.getDevicesMatchingConnectionStates(states)).isEmpty(); doReturn(new BluetoothDevice[] { mSingleDevice }).when(mAdapterService).getBondedDevices(); assertThat(mService.getDevicesMatchingConnectionStates(states)).isEmpty(); } @Test public void testDefaultValuesOfSeveralGetters() { assertThat(mService.getMaximumNumberOfBroadcasts()).isEqualTo(1); assertThat(mService.isPlaying(100)).isFalse(); assertThat(mService.isValidDeviceGroup(LE_AUDIO_GROUP_ID_INVALID)).isFalse(); } @Test public void testHandleGroupIdleDuringCall() { BluetoothDevice headsetDevice = TestUtils.getTestDevice(mAdapter, 5); HeadsetService headsetService = Mockito.mock(HeadsetService.class); when(mServiceFactory.getHeadsetService()).thenReturn(headsetService); mService.mHfpHandoverDevice = null; mService.handleGroupIdleDuringCall(); verify(headsetService, never()).getActiveDevice(); mService.mHfpHandoverDevice = headsetDevice; when(headsetService.getActiveDevice()).thenReturn(headsetDevice); mService.handleGroupIdleDuringCall(); verify(headsetService).connectAudio(); assertThat(mService.mHfpHandoverDevice).isNull(); mService.mHfpHandoverDevice = headsetDevice; when(headsetService.getActiveDevice()).thenReturn(null); mService.handleGroupIdleDuringCall(); verify(headsetService).setActiveDevice(headsetDevice); assertThat(mService.mHfpHandoverDevice).isNull(); } @Test public void testDump_doesNotCrash() { doReturn(new ParcelUuid[]{BluetoothUuid.LE_AUDIO}).when(mAdapterService) .getRemoteUuids(any(BluetoothDevice.class)); doReturn(new BluetoothDevice[]{mSingleDevice}).when(mAdapterService).getBondedDevices(); when(mDatabaseManager .getProfileConnectionPolicy(mSingleDevice, BluetoothProfile.LE_AUDIO)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); doReturn(true).when(mNativeInterface).connectLeAudio(any(BluetoothDevice.class)); doReturn(true).when(mNativeInterface).disconnectLeAudio(any(BluetoothDevice.class)); connectTestDevice(mSingleDevice, testGroupId); StringBuilder sb = new StringBuilder(); mService.dump(sb); } }