diff options
3 files changed, 74 insertions, 31 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java index b4578e97eda2..11a16a427c6b 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialog.java @@ -261,7 +261,10 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog { mMediaOutputController.registerLeBroadcastAssistantServiceCallback(mExecutor, mBroadcastAssistantCallback); } - connectBroadcastWithActiveDevice(); + /* Add local source broadcast to connected capable devices that may be possible receivers + * of stream. + */ + startBroadcastWithConnectedDevices(); } @Override @@ -394,30 +397,26 @@ public class MediaOutputBroadcastDialog extends MediaOutputBaseDialog { } } - void connectBroadcastWithActiveDevice() { + void startBroadcastWithConnectedDevices() { //get the Metadata, and convert to BT QR code format. BluetoothLeBroadcastMetadata broadcastMetadata = getBroadcastMetadata(); if (broadcastMetadata == null) { Log.e(TAG, "Error: There is no broadcastMetadata."); return; } - MediaDevice mediaDevice = mMediaOutputController.getCurrentConnectedMediaDevice(); - if (mediaDevice == null || !(mediaDevice instanceof BluetoothMediaDevice) - || !mediaDevice.isBLEDevice()) { - Log.e(TAG, "Error: There is no active BT LE device."); - return; - } - BluetoothDevice sink = ((BluetoothMediaDevice) mediaDevice).getCachedDevice().getDevice(); - Log.d(TAG, "The broadcastMetadata broadcastId: " + broadcastMetadata.getBroadcastId() - + ", the device: " + sink.getAnonymizedAddress()); - if (mMediaOutputController.isThereAnyBroadcastSourceIntoSinkDevice(sink)) { - Log.d(TAG, "The sink device has the broadcast source now."); - return; - } - if (!mMediaOutputController.addSourceIntoSinkDeviceWithBluetoothLeAssistant(sink, - broadcastMetadata, /*isGroupOp=*/ true)) { - Log.e(TAG, "Error: Source add failed"); + for (BluetoothDevice sink : mMediaOutputController.getConnectedBroadcastSinkDevices()) { + Log.d(TAG, "The broadcastMetadata broadcastId: " + broadcastMetadata.getBroadcastId() + + ", the device: " + sink.getAnonymizedAddress()); + + if (mMediaOutputController.isThereAnyBroadcastSourceIntoSinkDevice(sink)) { + Log.d(TAG, "The sink device has the broadcast source now."); + return; + } + if (!mMediaOutputController.addSourceIntoSinkDeviceWithBluetoothLeAssistant(sink, + broadcastMetadata, /*isGroupOp=*/ false)) { + Log.e(TAG, "Error: Source add failed"); + } } } diff --git a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java index be42569db7b2..2a22cfb7592e 100644 --- a/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +++ b/packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java @@ -1087,6 +1087,17 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback, broadcast.unregisterServiceCallBack(callback); } + List<BluetoothDevice> getConnectedBroadcastSinkDevices() { + LocalBluetoothLeBroadcastAssistant assistant = + mLocalBluetoothManager.getProfileManager().getLeAudioBroadcastAssistantProfile(); + if (assistant == null) { + Log.d(TAG, "The broadcast assistant profile is null"); + return null; + } + + return assistant.getConnectedDevices(); + } + boolean isThereAnyBroadcastSourceIntoSinkDevice(BluetoothDevice sink) { LocalBluetoothLeBroadcastAssistant assistant = mLocalBluetoothManager.getProfileManager().getLeAudioBroadcastAssistantProfile(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java index 45e8e270c3de..f25454c19ac9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/media/dialog/MediaOutputBroadcastDialogTest.java @@ -98,7 +98,8 @@ public class MediaOutputBroadcastDialogTest extends SysuiTestCase { private final BroadcastSender mBroadcastSender = mock(BroadcastSender.class); private final LocalMediaManager mLocalMediaManager = mock(LocalMediaManager.class); private final MediaDevice mBluetoothMediaDevice = mock(BluetoothMediaDevice.class); - private final BluetoothDevice mBluetoothDevice = mock(BluetoothDevice.class); + private final BluetoothDevice mBluetoothFirstDevice = mock(BluetoothDevice.class); + private final BluetoothDevice mBluetoothSecondDevice = mock(BluetoothDevice.class); private final CachedBluetoothDevice mCachedBluetoothDevice = mock(CachedBluetoothDevice.class); private final CommonNotifCollection mNotifCollection = mock(CommonNotifCollection.class); private final DialogLaunchAnimator mDialogLaunchAnimator = mock(DialogLaunchAnimator.class); @@ -142,20 +143,20 @@ public class MediaOutputBroadcastDialogTest extends SysuiTestCase { } @Test - public void connectBroadcastWithActiveDevice_noBroadcastMetadata_failToAddSource() { + public void startBroadcastWithConnectedDevices_noBroadcastMetadata_failToAddSource() { when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( mLocalBluetoothLeBroadcast); when(mLocalBluetoothLeBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn(null); when(mLocalBluetoothProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn( mLocalBluetoothLeBroadcastAssistant); - mMediaOutputBroadcastDialog.connectBroadcastWithActiveDevice(); + mMediaOutputBroadcastDialog.startBroadcastWithConnectedDevices(); verify(mLocalBluetoothLeBroadcastAssistant, never()).addSource(any(), any(), anyBoolean()); } @Test - public void connectBroadcastWithActiveDevice_noConnectedMediaDevice_failToAddSource() { + public void startBroadcastWithConnectedDevices_noConnectedMediaDevice_failToAddSource() { when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( mLocalBluetoothLeBroadcast); when(mLocalBluetoothLeBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn( @@ -164,13 +165,13 @@ public class MediaOutputBroadcastDialogTest extends SysuiTestCase { mLocalBluetoothLeBroadcastAssistant); when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(null); - mMediaOutputBroadcastDialog.connectBroadcastWithActiveDevice(); + mMediaOutputBroadcastDialog.startBroadcastWithConnectedDevices(); verify(mLocalBluetoothLeBroadcastAssistant, never()).addSource(any(), any(), anyBoolean()); } @Test - public void connectBroadcastWithActiveDevice_hasBroadcastSource_failToAddSource() { + public void startBroadcastWithConnectedDevices_hasBroadcastSource_failToAddSource() { when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( mLocalBluetoothLeBroadcast); when(mLocalBluetoothLeBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn( @@ -180,19 +181,19 @@ public class MediaOutputBroadcastDialogTest extends SysuiTestCase { when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mBluetoothMediaDevice); when(((BluetoothMediaDevice) mBluetoothMediaDevice).getCachedDevice()) .thenReturn(mCachedBluetoothDevice); - when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothFirstDevice); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); sourceList.add(mBluetoothLeBroadcastReceiveState); - when(mLocalBluetoothLeBroadcastAssistant.getAllSources(mBluetoothDevice)).thenReturn( + when(mLocalBluetoothLeBroadcastAssistant.getAllSources(mBluetoothFirstDevice)).thenReturn( sourceList); - mMediaOutputBroadcastDialog.connectBroadcastWithActiveDevice(); + mMediaOutputBroadcastDialog.startBroadcastWithConnectedDevices(); verify(mLocalBluetoothLeBroadcastAssistant, never()).addSource(any(), any(), anyBoolean()); } @Test - public void connectBroadcastWithActiveDevice_noBroadcastSource_failToAddSource() { + public void startBroadcastWithConnectedDevices_noBroadcastSource_failToAddSource() { when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( mLocalBluetoothLeBroadcast); when(mLocalBluetoothProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn( @@ -203,12 +204,16 @@ public class MediaOutputBroadcastDialogTest extends SysuiTestCase { when(mBluetoothMediaDevice.isBLEDevice()).thenReturn(true); when(((BluetoothMediaDevice) mBluetoothMediaDevice).getCachedDevice()).thenReturn( mCachedBluetoothDevice); - when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothFirstDevice); List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); - when(mLocalBluetoothLeBroadcastAssistant.getAllSources(mBluetoothDevice)).thenReturn( + when(mLocalBluetoothLeBroadcastAssistant.getAllSources(mBluetoothFirstDevice)).thenReturn( sourceList); + List<BluetoothDevice> connectedDevicesList = new ArrayList<>(); + connectedDevicesList.add(mBluetoothFirstDevice); + when(mLocalBluetoothLeBroadcastAssistant.getConnectedDevices()).thenReturn( + connectedDevicesList); - mMediaOutputBroadcastDialog.connectBroadcastWithActiveDevice(); + mMediaOutputBroadcastDialog.startBroadcastWithConnectedDevices(); verify(mLocalBluetoothLeBroadcastAssistant, times(1)).addSource(any(), any(), anyBoolean()); } @@ -360,4 +365,32 @@ public class MediaOutputBroadcastDialogTest extends SysuiTestCase { assertThat(broadcastErrorMessage.getVisibility()).isEqualTo(View.VISIBLE); } + + @Test + public void addSourceToAllConnectedDevices() { + when(mLocalBluetoothProfileManager.getLeAudioBroadcastProfile()).thenReturn( + mLocalBluetoothLeBroadcast); + when(mLocalBluetoothProfileManager.getLeAudioBroadcastAssistantProfile()).thenReturn( + mLocalBluetoothLeBroadcastAssistant); + when(mLocalBluetoothLeBroadcast.getLatestBluetoothLeBroadcastMetadata()).thenReturn( + mBluetoothLeBroadcastMetadata); + when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(mBluetoothMediaDevice); + when(mBluetoothMediaDevice.isBLEDevice()).thenReturn(true); + when(((BluetoothMediaDevice) mBluetoothMediaDevice).getCachedDevice()) + .thenReturn(mCachedBluetoothDevice); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothFirstDevice); + List<BluetoothLeBroadcastReceiveState> sourceList = new ArrayList<>(); + when(mLocalBluetoothLeBroadcastAssistant.getAllSources(mBluetoothFirstDevice)).thenReturn( + sourceList); + List<BluetoothDevice> connectedDevicesList = new ArrayList<>(); + connectedDevicesList.add(mBluetoothFirstDevice); + connectedDevicesList.add(mBluetoothSecondDevice); + when(mLocalBluetoothLeBroadcastAssistant.getConnectedDevices()).thenReturn( + connectedDevicesList); + + mMediaOutputBroadcastDialog.startBroadcastWithConnectedDevices(); + + verify(mLocalBluetoothLeBroadcastAssistant, times(2)).addSource(any(), any(), anyBoolean()); + } + } |