MediaOutputController: Broadcast to connected capable devices
Broadcast local stream to connected capable delegator devices. Tag: #feature Bug: 286599762 Test: manual Broadcast with two connected pair of LE Audio devices Change-Id: I8ec37403a35c198dfe70327ffdb679ed0bb0c9da
This commit is contained in:
committed by
Grzegorz Kolodziejczyk
parent
4a58ebcc75
commit
601f974215
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1093,6 +1093,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();
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user