Improve feedback when failing transferring a disconnected device

-Set "failed" string for subtitle
-Add test case

Bug: 157139936
Test: make -j42 RunSettingsRoboTests
Change-Id: I1fcd51f954a63cbc9ac0e573e5a8bb43cca6f087
This commit is contained in:
Tim Peng
2020-05-27 16:40:12 +08:00
parent 946e3adeda
commit 33914e738d
2 changed files with 45 additions and 2 deletions

View File

@@ -287,11 +287,16 @@ public class MediaOutputSlice implements CustomSliceable {
if (device.getDeviceType() == MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE if (device.getDeviceType() == MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE
&& !device.isConnected()) { && !device.isConnected()) {
if (device.getState() == LocalMediaManager.MediaDeviceState.STATE_CONNECTING) { final int state = device.getState();
if (state == LocalMediaManager.MediaDeviceState.STATE_CONNECTING
|| state == LocalMediaManager.MediaDeviceState.STATE_CONNECTING_FAILED) {
rowBuilder.setTitle(deviceName); rowBuilder.setTitle(deviceName);
rowBuilder.setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon, rowBuilder.setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon,
ListBuilder.ICON_IMAGE, deviceName)); ListBuilder.ICON_IMAGE, deviceName));
rowBuilder.setSubtitle(mContext.getText(R.string.media_output_switching)); rowBuilder.setSubtitle(
(state == LocalMediaManager.MediaDeviceState.STATE_CONNECTING)
? mContext.getText(R.string.media_output_switching)
: mContext.getText(R.string.bluetooth_connect_failed));
} else { } else {
// Append status to title only for the disconnected Bluetooth device. // Append status to title only for the disconnected Bluetooth device.
final SpannableString spannableTitle = new SpannableString( final SpannableString spannableTitle = new SpannableString(

View File

@@ -512,6 +512,44 @@ public class MediaOutputSliceTest {
.isNotEqualTo(-1); .isNotEqualTo(-1);
} }
@Test
public void getSlice_disconnectedBtOnTransferringFailed_containTransferringFailedSubtitle() {
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
mDevices.clear();
final MediaDevice device = mock(MediaDevice.class);
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
when(device.getIcon()).thenReturn(mTestDrawable);
when(device.getMaxVolume()).thenReturn(100);
when(device.isConnected()).thenReturn(true);
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE);
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
final MediaDevice device2 = mock(MediaDevice.class);
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
when(device2.getIcon()).thenReturn(mTestDrawable);
when(device2.getMaxVolume()).thenReturn(100);
when(device2.isConnected()).thenReturn(false);
when(device2.getState()).thenReturn(
LocalMediaManager.MediaDeviceState.STATE_CONNECTING_FAILED);
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE);
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
mSelectedDevices.add(device);
mSelectableDevices.add(device2);
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
mDevices.add(device);
mDevices.add(device2);
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
final Slice mediaSlice = mMediaOutputSlice.getSlice();
final String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
null).toString();
assertThat(TextUtils.indexOf(sliceInfo,
mContext.getText(R.string.bluetooth_connect_failed))).isNotEqualTo(-1);
}
@Test @Test
public void onNotifyChange_foundMediaDevice_connect() { public void onNotifyChange_foundMediaDevice_connect() {
mDevices.clear(); mDevices.clear();