Use BluetoothLeBroadcastAssistant#getSourceMetadata to retrieve broadcast name.
Test: atest Bug: 381944659 Flag: com.android.settingslib.flags.enable_le_audio_sharing Change-Id: I6e4c83a0858717727066de708fbde88e4b03ed8e
This commit is contained in:
@@ -54,7 +54,7 @@ import java.util.List;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(
|
||||
shadows = {
|
||||
ShadowBluetoothAdapter.class,
|
||||
ShadowBluetoothAdapter.class,
|
||||
})
|
||||
public class AudioStreamsProgressCategoryCallbackTest {
|
||||
@Rule public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||
@@ -70,8 +70,8 @@ public class AudioStreamsProgressCategoryCallbackTest {
|
||||
@Before
|
||||
public void setUp() {
|
||||
mSetFlagsRule.disableFlags(FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
||||
ShadowBluetoothAdapter shadowBluetoothAdapter = Shadow.extract(
|
||||
BluetoothAdapter.getDefaultAdapter());
|
||||
ShadowBluetoothAdapter shadowBluetoothAdapter =
|
||||
Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
shadowBluetoothAdapter.setEnabled(true);
|
||||
shadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
|
||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
@@ -87,7 +87,7 @@ public class AudioStreamsProgressCategoryCallbackTest {
|
||||
when(mState.getBisSyncState()).thenReturn(bisSyncState);
|
||||
mCallback.onReceiveStateChanged(mDevice, /* sourceId= */ 0, mState);
|
||||
|
||||
verify(mController).handleSourceConnected(any());
|
||||
verify(mController).handleSourceConnected(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -102,7 +102,7 @@ public class AudioStreamsProgressCategoryCallbackTest {
|
||||
when(mSourceDevice.getAddress()).thenReturn(address);
|
||||
mCallback.onReceiveStateChanged(mDevice, /* sourceId= */ 0, mState);
|
||||
|
||||
verify(mController).handleSourcePresent(any());
|
||||
verify(mController).handleSourcePresent(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -32,6 +32,7 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -41,7 +42,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
@@ -93,6 +94,7 @@ import org.robolectric.shadows.androidx.fragment.FragmentController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(
|
||||
@@ -134,8 +136,8 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ShadowBluetoothAdapter shadowBluetoothAdapter = Shadow.extract(
|
||||
BluetoothAdapter.getDefaultAdapter());
|
||||
ShadowBluetoothAdapter shadowBluetoothAdapter =
|
||||
Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
shadowBluetoothAdapter.setEnabled(true);
|
||||
shadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
|
||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
@@ -143,7 +145,7 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||
ShadowAudioStreamsHelper.setUseMock(mAudioStreamsHelper);
|
||||
when(mAudioStreamsHelper.getLeBroadcastAssistant()).thenReturn(mLeBroadcastAssistant);
|
||||
when(mAudioStreamsHelper.getAllConnectedSources()).thenReturn(emptyList());
|
||||
when(mAudioStreamsHelper.getAllSourcesByDevice()).thenReturn(emptyMap());
|
||||
mSetFlagsRule.disableFlags(FLAG_AUDIO_SHARING_HYSTERESIS_MODE_FIX);
|
||||
|
||||
ShadowBluetoothUtils.sLocalBluetoothManager = mLocalBtManager;
|
||||
@@ -310,14 +312,12 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
// Setup a device
|
||||
ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected(mDevice);
|
||||
|
||||
List<BluetoothLeBroadcastReceiveState> connectedList = new ArrayList<>();
|
||||
// Empty connected device list
|
||||
when(mAudioStreamsHelper.getAllConnectedSources()).thenReturn(connectedList);
|
||||
when(mAudioStreamsHelper.getAllSourcesByDevice()).thenReturn(emptyMap());
|
||||
|
||||
mController.onStart(mLifecycleOwner);
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
|
||||
verify(mAudioStreamsHelper).getAllPresentSources();
|
||||
verify(mLeBroadcastAssistant).startSearchingForSources(any());
|
||||
|
||||
var dialog = ShadowAlertDialog.getLatestAlertDialog();
|
||||
@@ -355,7 +355,7 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnStart_handleSourceAlreadyConnected() {
|
||||
public void testOnStart_handleSourceAlreadyConnected_useNameFromMetadata() {
|
||||
// Setup a device
|
||||
ShadowAudioStreamsHelper.setCachedBluetoothDeviceInSharingOrLeConnected(mDevice);
|
||||
|
||||
@@ -363,8 +363,14 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
BluetoothLeBroadcastReceiveState connected =
|
||||
createConnectedMock(ALREADY_CONNECTED_BROADCAST_ID);
|
||||
List<BluetoothLeBroadcastReceiveState> list = new ArrayList<>();
|
||||
var data = mock(BluetoothLeAudioContentMetadata.class);
|
||||
when(connected.getSubgroupMetadata()).thenReturn(ImmutableList.of(data));
|
||||
when(data.getProgramInfo()).thenReturn(BROADCAST_NAME_1);
|
||||
list.add(connected);
|
||||
when(mAudioStreamsHelper.getAllConnectedSources()).thenReturn(list);
|
||||
when(mMetadata.getBroadcastId()).thenReturn(ALREADY_CONNECTED_BROADCAST_ID);
|
||||
when(mMetadata.getBroadcastName()).thenReturn(BROADCAST_NAME_2);
|
||||
when(mLeBroadcastAssistant.getSourceMetadata(any(), anyInt())).thenReturn(mMetadata);
|
||||
when(mAudioStreamsHelper.getAllSourcesByDevice()).thenReturn(Map.of(mSourceDevice, list));
|
||||
|
||||
// Handle already connected source in onStart
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -382,6 +388,7 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
assertThat(preference.getValue()).isNotNull();
|
||||
assertThat(preference.getValue().getAudioStreamBroadcastId())
|
||||
.isEqualTo(ALREADY_CONNECTED_BROADCAST_ID);
|
||||
assertThat(preference.getValue().getTitle()).isEqualTo(BROADCAST_NAME_2);
|
||||
assertThat(state.getValue()).isEqualTo(SOURCE_ADDED);
|
||||
}
|
||||
|
||||
@@ -409,7 +416,8 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
var data = mock(BluetoothLeAudioContentMetadata.class);
|
||||
when(connected.getSubgroupMetadata()).thenReturn(ImmutableList.of(data));
|
||||
when(data.getProgramInfo()).thenReturn(BROADCAST_NAME_1);
|
||||
when(mAudioStreamsHelper.getAllConnectedSources()).thenReturn(ImmutableList.of(connected));
|
||||
when(mAudioStreamsHelper.getAllSourcesByDevice())
|
||||
.thenReturn(Map.of(mSourceDevice, ImmutableList.of(connected)));
|
||||
|
||||
// Handle both source from qr code and already connected source in onStart
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -578,8 +586,8 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
// Setup source already connected
|
||||
BluetoothLeBroadcastReceiveState connected =
|
||||
createConnectedMock(ALREADY_CONNECTED_BROADCAST_ID);
|
||||
when(mAudioStreamsHelper.getAllConnectedSources()).thenReturn(ImmutableList.of(connected));
|
||||
|
||||
when(mAudioStreamsHelper.getAllSourcesByDevice())
|
||||
.thenReturn(Map.of(mSourceDevice, List.of(connected)));
|
||||
// Handle source already connected in onStart
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onStart(mLifecycleOwner);
|
||||
@@ -687,7 +695,8 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
// Setup already connected source
|
||||
BluetoothLeBroadcastReceiveState connected =
|
||||
createConnectedMock(ALREADY_CONNECTED_BROADCAST_ID);
|
||||
when(mAudioStreamsHelper.getAllConnectedSources()).thenReturn(ImmutableList.of(connected));
|
||||
when(mAudioStreamsHelper.getAllSourcesByDevice())
|
||||
.thenReturn(Map.of(mSourceDevice, List.of(connected)));
|
||||
|
||||
// Handle connected source in onStart
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -695,7 +704,7 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
|
||||
// The connect source is no longer connected
|
||||
when(mAudioStreamsHelper.getAllConnectedSources()).thenReturn(emptyList());
|
||||
when(mAudioStreamsHelper.getAllSourcesByDevice()).thenReturn(emptyMap());
|
||||
mController.handleSourceRemoved();
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
|
||||
@@ -728,7 +737,8 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
// Setup a connected source
|
||||
BluetoothLeBroadcastReceiveState connected =
|
||||
createConnectedMock(ALREADY_CONNECTED_BROADCAST_ID);
|
||||
when(mAudioStreamsHelper.getAllConnectedSources()).thenReturn(ImmutableList.of(connected));
|
||||
when(mAudioStreamsHelper.getAllSourcesByDevice())
|
||||
.thenReturn(Map.of(mSourceDevice, List.of(connected)));
|
||||
|
||||
// Handle connected source in onStart
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -834,7 +844,7 @@ public class AudioStreamsProgressCategoryControllerTest {
|
||||
when(receiveState.getBisSyncState()).thenReturn(bisSyncState);
|
||||
|
||||
// The new found source is identified as failed to connect
|
||||
mController.handleSourcePresent(receiveState);
|
||||
mController.handleSourcePresent(mSourceDevice, receiveState);
|
||||
shadowOf(Looper.getMainLooper()).idle();
|
||||
|
||||
ArgumentCaptor<AudioStreamPreference> preference =
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.connecteddevice.audiosharing.audiostreams.testshadows;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothLeBroadcastMetadata;
|
||||
import android.bluetooth.BluetoothLeBroadcastReceiveState;
|
||||
|
||||
@@ -31,6 +32,7 @@ import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Implements(value = AudioStreamsHelper.class, callThroughByDefault = true)
|
||||
@@ -59,6 +61,11 @@ public class ShadowAudioStreamsHelper {
|
||||
return sMockHelper.getAllConnectedSources();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public Map<BluetoothDevice, List<BluetoothLeBroadcastReceiveState>> getAllSourcesByDevice() {
|
||||
return sMockHelper.getAllSourcesByDevice();
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public List<BluetoothLeBroadcastReceiveState> getAllPresentSources() {
|
||||
return sMockHelper.getAllPresentSources();
|
||||
|
||||
Reference in New Issue
Block a user