Merge "Add zero state in output switcher" into rvc-dev am: ddd8a8fa92 am: 3e73d0f92c am: d5bdc55390 am: 18d42df80b

Change-Id: Ibc58e2b8ada042754503d4b336dbcb5bb14c2395
This commit is contained in:
tim peng
2020-03-30 18:08:25 +00:00
committed by Automerger Merge Worker
6 changed files with 126 additions and 91 deletions

View File

@@ -123,7 +123,6 @@ public class MediaOutputIndicatorSliceTest {
@Test
public void getSlice_withConnectedDevice_verifyMetadata() {
mDevices.add(mDevice1);
mDevices.add(mDevice2);
when(sMediaOutputIndicatorWorker.getMediaDevices()).thenReturn(mDevices);
doReturn(mDevice1).when(sMediaOutputIndicatorWorker).getCurrentConnectedMediaDevice();
mAudioManager.setMode(AudioManager.MODE_NORMAL);

View File

@@ -410,6 +410,69 @@ public class MediaOutputSliceTest {
R.string.media_output_switch_error_text))).isNotEqualTo(-1);
}
@Test
public void getSlice_zeroState_containPairingText() {
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_PHONE_DEVICE);
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
mSelectedDevices.add(device);
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
mDevices.add(device);
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
final Slice mediaSlice = mMediaOutputSlice.getSlice();
String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
null).toString();
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(
R.string.bluetooth_pairing_pref_title))).isNotEqualTo(-1);
}
@Test
public void getSlice_twoConnectedDevices_notContainPairingText() {
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(true);
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();
String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
null).toString();
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(
R.string.bluetooth_pairing_pref_title))).isEqualTo(-1);
}
@Test
public void onNotifyChange_foundMediaDevice_connect() {
mDevices.clear();

View File

@@ -166,47 +166,6 @@ public class MediaOutputPreferenceControllerTest {
ShadowBluetoothUtils.reset();
}
/**
* A2DP Bluetooth device(s) are not connected nor previously connected
* Preference should be invisible
*/
@Test
public void updateState_withoutConnectedBtDevice_preferenceInvisible() {
mShadowAudioManager.setOutputDevice(DEVICE_OUT_EARPIECE);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mProfileConnectedDevices.clear();
when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
mPreference.setVisible(true);
assertThat(mPreference.isVisible()).isTrue();
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isFalse();
}
/**
* A2DP Bluetooth device(s) are connected, no matter active or inactive
* Preference should be visible
*/
@Test
public void updateState_withConnectedBtDevice_preferenceVisible() {
mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
assertThat(mPreference.isVisible()).isFalse();
// Without Active Bluetooth Device
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isTrue();
// With Active Bluetooth Device
when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isTrue();
}
/**
* A2DP Bluetooth device(s) are connected, but no device is set as activated
* Preference summary should be "This device"
@@ -247,30 +206,6 @@ public class MediaOutputPreferenceControllerTest {
assertThat(mPreference.getSummary()).isEqualTo(TEST_DEVICE_NAME_1);
}
/**
* Hearing Aid device(s) are connected, no matter active or inactive
* Preference should be visible
*/
@Test
public void updateState_withConnectedHADevice_preferenceVisible() {
mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mHearingAidActiveDevices.clear();
mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
when(mHearingAidProfile.getConnectedDevices()).thenReturn(mHearingAidActiveDevices);
assertThat(mPreference.isVisible()).isFalse();
// Without Active Hearing Aid Device
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isTrue();
// With Active Hearing Aid Device
when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isTrue();
}
/**
* Hearing Aid device(s) are connected and active
* Preference summary should be device's name
@@ -310,12 +245,12 @@ public class MediaOutputPreferenceControllerTest {
* Summary should be default summary
*/
@Test
public void updateState_shouldSetSummary() {
public void updateState_notInCall_preferenceVisible() {
mAudioManager.setMode(AudioManager.MODE_NORMAL);
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isFalse();
assertThat(mPreference.getSummary()).isEqualTo(
mContext.getText(R.string.media_output_default_summary));
assertThat(mPreference.isVisible()).isTrue();
}
/**
@@ -324,14 +259,12 @@ public class MediaOutputPreferenceControllerTest {
* Default string should be "Unavailable during calls"
*/
@Test
public void updateState_duringACall_shouldSetDefaultSummary() {
public void updateState_inCall_preferenceInvisible() {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mController.updateState(mPreference);
assertThat(mPreference.isVisible()).isFalse();
assertThat(mPreference.getSummary()).isEqualTo(
mContext.getText(R.string.media_out_summary_ongoing_call_state));
}
@Test