Merge "Handle ransferring state in output switcher" into rvc-dev am: b669fff40c
Change-Id: Ibd5b7c7dfc2435253f969ba9f497e7a9dc1924f9
This commit is contained in:
@@ -112,6 +112,11 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
notifySliceChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestFailed(int reason) {
|
||||
notifySliceChange();
|
||||
}
|
||||
|
||||
public Collection<MediaDevice> getMediaDevices() {
|
||||
return mMediaDevices;
|
||||
}
|
||||
@@ -119,6 +124,9 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
public void connectDevice(MediaDevice device) {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
mLocalMediaManager.connectDevice(device);
|
||||
ThreadUtils.postOnMainThread(() -> {
|
||||
notifySliceChange();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -42,6 +42,7 @@ import com.android.settings.Utils;
|
||||
import com.android.settings.slices.CustomSliceable;
|
||||
import com.android.settings.slices.SliceBackgroundWorker;
|
||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||
import com.android.settingslib.media.LocalMediaManager;
|
||||
import com.android.settingslib.media.MediaDevice;
|
||||
import com.android.settingslib.media.MediaOutputSliceConstants;
|
||||
|
||||
@@ -246,6 +247,15 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
rowBuilder.setTitle(deviceName);
|
||||
rowBuilder.setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon,
|
||||
ListBuilder.ICON_IMAGE, deviceName));
|
||||
switch (device.getState()) {
|
||||
case LocalMediaManager.MediaDeviceState.STATE_CONNECTING:
|
||||
rowBuilder.setSubtitle(mContext.getText(R.string.media_output_switching));
|
||||
break;
|
||||
case LocalMediaManager.MediaDeviceState.STATE_CONNECTING_FAILED:
|
||||
rowBuilder.setSubtitle(mContext.getText(
|
||||
R.string.media_output_switch_error_text));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return rowBuilder;
|
||||
|
@@ -30,6 +30,7 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaRoute2ProviderService;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowAudioManager;
|
||||
@@ -95,7 +96,8 @@ public class MediaDeviceUpdateWorkerTest {
|
||||
|
||||
@Test
|
||||
public void onSelectedDeviceStateChanged_shouldNotifyChange() {
|
||||
mMediaDeviceUpdateWorker.onSelectedDeviceStateChanged(null, 0);
|
||||
mMediaDeviceUpdateWorker.onSelectedDeviceStateChanged(mMediaDevice1,
|
||||
LocalMediaManager.MediaDeviceState.STATE_CONNECTED);
|
||||
|
||||
verify(mResolver).notifyChange(URI, null);
|
||||
}
|
||||
@@ -155,6 +157,13 @@ public class MediaDeviceUpdateWorkerTest {
|
||||
assertThat(devices.size()).isEqualTo(newDevices.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onRequestFailed_shouldNotifyChange() {
|
||||
mMediaDeviceUpdateWorker.onRequestFailed(MediaRoute2ProviderService.REASON_UNKNOWN_ERROR);
|
||||
|
||||
verify(mResolver).notifyChange(URI, null /* observer */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onReceive_inCallState_shouldNotifyChange() {
|
||||
mMediaDeviceUpdateWorker.mLocalMediaManager = mock(LocalMediaManager.class);
|
||||
|
@@ -335,6 +335,81 @@ public class MediaOutputSliceTest {
|
||||
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(R.string.add))).isNotEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_onTransferring_containTransferringSubtitle() {
|
||||
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_CAST_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);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_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.media_output_switching)))
|
||||
.isNotEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_onTransferringFailed_containFailedSubtitle() {
|
||||
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_CAST_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_CAST_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.media_output_switch_error_text))).isNotEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_foundMediaDevice_connect() {
|
||||
mDevices.clear();
|
||||
|
Reference in New Issue
Block a user