Loading src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandler.java +12 −3 Original line number Diff line number Diff line Loading @@ -258,6 +258,8 @@ public class AudioSharingDialogHandler { boolean userTriggered) { Map<Integer, List<CachedBluetoothDevice>> groupedDevices = AudioSharingUtils.fetchConnectedDevicesByGroupId(mLocalBtManager); BluetoothDevice btDevice = cachedDevice.getDevice(); String deviceAddress = btDevice == null ? "" : btDevice.getAnonymizedAddress(); if (isBroadcasting) { // If another device within the same is already in the sharing session, add source to // the device automatically. Loading @@ -271,10 +273,10 @@ public class AudioSharingDialogHandler { Log.d( TAG, "Automatically add another device within the same group to the sharing: " + cachedDevice.getDevice().getAnonymizedAddress()); + deviceAddress); if (mAssistant != null && mBroadcast != null) { mAssistant.addSource( cachedDevice.getDevice(), btDevice, mBroadcast.getLatestBluetoothLeBroadcastMetadata(), /* isGroupOp= */ false); } Loading Loading @@ -313,6 +315,7 @@ public class AudioSharingDialogHandler { cachedDevice, listener, eventData); Log.d(TAG, "Show disconnect dialog, device = " + deviceAddress); }); } else { // Show audio sharing join dialog when the first or second eligible (LE audio) Loading Loading @@ -343,9 +346,11 @@ public class AudioSharingDialogHandler { cachedDevice, listener, eventData); Log.d(TAG, "Show join dialog, device = " + deviceAddress); }); } } else { // Build a list of AudioSharingDeviceItem for connected devices other than cachedDevice. List<AudioSharingDeviceItem> deviceItems = new ArrayList<>(); for (List<CachedBluetoothDevice> devices : groupedDevices.values()) { // Use random device in the group within the sharing session to represent the group. Loading @@ -358,7 +363,7 @@ public class AudioSharingDialogHandler { } // Show audio sharing join dialog when the second eligible (LE audio) remote // device connect and no sharing session. if (deviceItems.size() == 1) { if (groupedDevices.size() == 2 && deviceItems.size() == 1) { AudioSharingJoinDialogFragment.DialogEventListener listener = new AudioSharingJoinDialogFragment.DialogEventListener() { @Override Loading Loading @@ -396,9 +401,13 @@ public class AudioSharingDialogHandler { closeOpeningDialogsOtherThan(AudioSharingJoinDialogFragment.tag()); AudioSharingJoinDialogFragment.show( mHostFragment, deviceItems, cachedDevice, listener, eventData); Log.d(TAG, "Show start dialog, device = " + deviceAddress); }); } else if (userTriggered) { cachedDevice.setActive(); Log.d(TAG, "Set active device = " + deviceAddress); } else { Log.d(TAG, "Fail to handle LE audio device connected, device = " + deviceAddress); } } } Loading tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandlerTest.java +34 −0 Original line number Diff line number Diff line Loading @@ -248,6 +248,23 @@ public class AudioSharingDialogHandlerTest { verify(mCachedDevice1).setActive(); } @Test public void handleUserTriggeredLeaDeviceConnected_noSharingLeaDeviceInErrorState_setActive() { setUpBroadcast(false); when(mCachedDevice1.getGroupId()).thenReturn(-1); when(mLeAudioProfile.getGroupId(mDevice1)).thenReturn(-1); ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3); when(mAssistant.getDevicesMatchingConnectionStates( new int[] {BluetoothProfile.STATE_CONNECTED})) .thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments(); assertThat(childFragments).isEmpty(); verify(mCachedDevice1).setActive(); } @Test public void handleUserTriggeredLeaDeviceConnected_noSharingTwoLeaDevices_showJoinDialog() { setUpBroadcast(false); Loading Loading @@ -451,6 +468,23 @@ public class AudioSharingDialogHandlerTest { verify(mCachedDevice1, never()).setActive(); } @Test public void handleLeaDeviceConnected_noSharingLeaDeviceInErrorState_doNothing() { setUpBroadcast(false); when(mCachedDevice1.getGroupId()).thenReturn(-1); when(mLeAudioProfile.getGroupId(mDevice1)).thenReturn(-1); ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3); when(mAssistant.getDevicesMatchingConnectionStates( new int[] {BluetoothProfile.STATE_CONNECTED})) .thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments(); assertThat(childFragments).isEmpty(); verify(mCachedDevice1, never()).setActive(); } @Test public void handleLeaDeviceConnected_noSharingTwoLeaDevices_showJoinDialog() { setUpBroadcast(false); Loading Loading
src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandler.java +12 −3 Original line number Diff line number Diff line Loading @@ -258,6 +258,8 @@ public class AudioSharingDialogHandler { boolean userTriggered) { Map<Integer, List<CachedBluetoothDevice>> groupedDevices = AudioSharingUtils.fetchConnectedDevicesByGroupId(mLocalBtManager); BluetoothDevice btDevice = cachedDevice.getDevice(); String deviceAddress = btDevice == null ? "" : btDevice.getAnonymizedAddress(); if (isBroadcasting) { // If another device within the same is already in the sharing session, add source to // the device automatically. Loading @@ -271,10 +273,10 @@ public class AudioSharingDialogHandler { Log.d( TAG, "Automatically add another device within the same group to the sharing: " + cachedDevice.getDevice().getAnonymizedAddress()); + deviceAddress); if (mAssistant != null && mBroadcast != null) { mAssistant.addSource( cachedDevice.getDevice(), btDevice, mBroadcast.getLatestBluetoothLeBroadcastMetadata(), /* isGroupOp= */ false); } Loading Loading @@ -313,6 +315,7 @@ public class AudioSharingDialogHandler { cachedDevice, listener, eventData); Log.d(TAG, "Show disconnect dialog, device = " + deviceAddress); }); } else { // Show audio sharing join dialog when the first or second eligible (LE audio) Loading Loading @@ -343,9 +346,11 @@ public class AudioSharingDialogHandler { cachedDevice, listener, eventData); Log.d(TAG, "Show join dialog, device = " + deviceAddress); }); } } else { // Build a list of AudioSharingDeviceItem for connected devices other than cachedDevice. List<AudioSharingDeviceItem> deviceItems = new ArrayList<>(); for (List<CachedBluetoothDevice> devices : groupedDevices.values()) { // Use random device in the group within the sharing session to represent the group. Loading @@ -358,7 +363,7 @@ public class AudioSharingDialogHandler { } // Show audio sharing join dialog when the second eligible (LE audio) remote // device connect and no sharing session. if (deviceItems.size() == 1) { if (groupedDevices.size() == 2 && deviceItems.size() == 1) { AudioSharingJoinDialogFragment.DialogEventListener listener = new AudioSharingJoinDialogFragment.DialogEventListener() { @Override Loading Loading @@ -396,9 +401,13 @@ public class AudioSharingDialogHandler { closeOpeningDialogsOtherThan(AudioSharingJoinDialogFragment.tag()); AudioSharingJoinDialogFragment.show( mHostFragment, deviceItems, cachedDevice, listener, eventData); Log.d(TAG, "Show start dialog, device = " + deviceAddress); }); } else if (userTriggered) { cachedDevice.setActive(); Log.d(TAG, "Set active device = " + deviceAddress); } else { Log.d(TAG, "Fail to handle LE audio device connected, device = " + deviceAddress); } } } Loading
tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDialogHandlerTest.java +34 −0 Original line number Diff line number Diff line Loading @@ -248,6 +248,23 @@ public class AudioSharingDialogHandlerTest { verify(mCachedDevice1).setActive(); } @Test public void handleUserTriggeredLeaDeviceConnected_noSharingLeaDeviceInErrorState_setActive() { setUpBroadcast(false); when(mCachedDevice1.getGroupId()).thenReturn(-1); when(mLeAudioProfile.getGroupId(mDevice1)).thenReturn(-1); ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3); when(mAssistant.getDevicesMatchingConnectionStates( new int[] {BluetoothProfile.STATE_CONNECTED})) .thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ true); shadowOf(Looper.getMainLooper()).idle(); List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments(); assertThat(childFragments).isEmpty(); verify(mCachedDevice1).setActive(); } @Test public void handleUserTriggeredLeaDeviceConnected_noSharingTwoLeaDevices_showJoinDialog() { setUpBroadcast(false); Loading Loading @@ -451,6 +468,23 @@ public class AudioSharingDialogHandlerTest { verify(mCachedDevice1, never()).setActive(); } @Test public void handleLeaDeviceConnected_noSharingLeaDeviceInErrorState_doNothing() { setUpBroadcast(false); when(mCachedDevice1.getGroupId()).thenReturn(-1); when(mLeAudioProfile.getGroupId(mDevice1)).thenReturn(-1); ImmutableList<BluetoothDevice> deviceList = ImmutableList.of(mDevice1, mDevice3); when(mAssistant.getDevicesMatchingConnectionStates( new int[] {BluetoothProfile.STATE_CONNECTED})) .thenReturn(deviceList); when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); mHandler.handleDeviceConnected(mCachedDevice1, /* userTriggered= */ false); shadowOf(Looper.getMainLooper()).idle(); List<Fragment> childFragments = mParentFragment.getChildFragmentManager().getFragments(); assertThat(childFragments).isEmpty(); verify(mCachedDevice1, never()).setActive(); } @Test public void handleLeaDeviceConnected_noSharingTwoLeaDevices_showJoinDialog() { setUpBroadcast(false); Loading