diff options
| author | 2022-07-28 02:41:29 +0000 | |
|---|---|---|
| committer | 2022-07-28 02:41:29 +0000 | |
| commit | b0df01220db6eaff69f79b33bda5c6b39ce5e594 (patch) | |
| tree | 9ee037fa11685635f4d0abeea322bee447380d9c | |
| parent | 799777249003ddacb7432168e5c6f1a263eafa84 (diff) | |
| parent | 1d7f570eaa4115133e65905f1aa56a3a9d9377a5 (diff) | |
Merge "[Output Switcher] Fix LocalMediaManagerTest" into tm-qpr-dev am: 1d7f570eaa
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19378987
Change-Id: I138adf7be5d8f9f47026546dcd0638d5c21822f1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java | 3 | ||||
| -rw-r--r-- | packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java | 88 |
2 files changed, 17 insertions, 74 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java index 281501e6043c..f4355c39819f 100644 --- a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java +++ b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java @@ -84,7 +84,8 @@ public class LocalMediaManager implements BluetoothCallback { private InfoMediaManager mInfoMediaManager; private String mPackageName; private MediaDevice mOnTransferBluetoothDevice; - private AudioManager mAudioManager; + @VisibleForTesting + AudioManager mAudioManager; @VisibleForTesting List<MediaDevice> mMediaDevices = new CopyOnWriteArrayList<>(); diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java index 8e850b25159c..24bb1bc9ac67 100644 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/media/LocalMediaManagerTest.java @@ -16,7 +16,6 @@ package com.android.settingslib.media; -import static android.bluetooth.BluetoothClass.Device.AUDIO_VIDEO_HEADPHONES; import static android.media.MediaRoute2ProviderService.REASON_UNKNOWN_ERROR; import static com.google.common.truth.Truth.assertThat; @@ -29,10 +28,12 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothClass; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothProfile; import android.content.Context; +import android.media.AudioDeviceAttributes; +import android.media.AudioManager; +import android.media.AudioSystem; import android.media.MediaRoute2Info; import android.media.MediaRouter2Manager; import android.media.RoutingSessionInfo; @@ -71,6 +72,7 @@ public class LocalMediaManagerTest { private static final String TEST_CURRENT_DEVICE_ID = "currentDevice_id"; private static final String TEST_PACKAGE_NAME = "com.test.playmusic"; private static final String TEST_SESSION_ID = "session_id"; + private static final String TEST_ADDRESS = "00:01:02:03:04:05"; @Mock private InfoMediaManager mInfoMediaManager; @@ -90,6 +92,8 @@ public class LocalMediaManagerTest { private MediaRoute2Info mRouteInfo1; @Mock private MediaRoute2Info mRouteInfo2; + @Mock + private AudioManager mAudioManager; private Context mContext; private LocalMediaManager mLocalMediaManager; @@ -118,6 +122,7 @@ public class LocalMediaManagerTest { TEST_PACKAGE_NAME); mLocalMediaManager = new LocalMediaManager(mContext, mLocalBluetoothManager, mInfoMediaManager, "com.test.packagename"); + mLocalMediaManager.mAudioManager = mAudioManager; } @Test @@ -551,16 +556,12 @@ public class LocalMediaManagerTest { } @Test - public void onDeviceListAdded_haveDisconnectedDevice_addDisconnectedDevice() { + public void onDeviceListAdded_haveMutingExpectedDevice_addMutingExpectedDevice() { final List<MediaDevice> devices = new ArrayList<>(); final MediaDevice device1 = mock(MediaDevice.class); - final MediaDevice device2 = mock(MediaDevice.class); - final MediaDevice device3 = mock(MediaDevice.class); mLocalMediaManager.mPhoneDevice = mock(PhoneMediaDevice.class); devices.add(device1); - devices.add(device2); - mLocalMediaManager.mMediaDevices.add(device3); - mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice); + devices.add(mLocalMediaManager.mPhoneDevice); final List<LocalBluetoothProfile> profiles = new ArrayList<>(); final A2dpProfile a2dpProfile = mock(A2dpProfile.class); @@ -573,22 +574,25 @@ public class LocalMediaManagerTest { bluetoothDevices.add(bluetoothDevice); mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(bluetoothDevices); + AudioDeviceAttributes audioDeviceAttributes = new AudioDeviceAttributes( + AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP, TEST_ADDRESS); + + when(mAudioManager.getMutingExpectedDevice()).thenReturn(audioDeviceAttributes); when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(cachedManager); when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice); when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); when(cachedDevice.isConnected()).thenReturn(false); when(cachedDevice.getConnectableProfiles()).thenReturn(profiles); when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); + when(cachedDevice.getAddress()).thenReturn(TEST_ADDRESS); when(mA2dpProfile.getActiveDevice()).thenReturn(bluetoothDevice); when(mHapProfile.getActiveDevices()).thenReturn(new ArrayList<>()); when(device1.getId()).thenReturn(TEST_DEVICE_ID_1); - when(device2.getId()).thenReturn(TEST_DEVICE_ID_2); - when(device3.getId()).thenReturn(TEST_DEVICE_ID_3); when(device1.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE); when(mLocalMediaManager.mPhoneDevice.getId()).thenReturn("test_phone_id"); - assertThat(mLocalMediaManager.mMediaDevices).hasSize(2); + assertThat(mLocalMediaManager.mMediaDevices).hasSize(0); mLocalMediaManager.registerCallback(mCallback); mLocalMediaManager.mMediaDeviceCallback.onDeviceListAdded(devices); @@ -634,68 +638,6 @@ public class LocalMediaManagerTest { } @Test - public void onDeviceListAdded_haveDisconnectedDevice_list5DisconnectedDevice() { - final List<MediaDevice> devices = new ArrayList<>(); - final MediaDevice device1 = mock(MediaDevice.class); - final MediaDevice device2 = mock(MediaDevice.class); - final MediaDevice device3 = mock(MediaDevice.class); - mLocalMediaManager.mPhoneDevice = mock(PhoneMediaDevice.class); - devices.add(device1); - devices.add(device2); - mLocalMediaManager.mMediaDevices.add(device3); - mLocalMediaManager.mMediaDevices.add(mLocalMediaManager.mPhoneDevice); - - final List<LocalBluetoothProfile> profiles = new ArrayList<>(); - final A2dpProfile a2dpProfile = mock(A2dpProfile.class); - profiles.add(a2dpProfile); - - final List<BluetoothDevice> bluetoothDevices = new ArrayList<>(); - final BluetoothDevice bluetoothDevice = mock(BluetoothDevice.class); - final BluetoothDevice bluetoothDevice2 = mock(BluetoothDevice.class); - final BluetoothDevice bluetoothDevice3 = mock(BluetoothDevice.class); - final BluetoothDevice bluetoothDevice4 = mock(BluetoothDevice.class); - final BluetoothDevice bluetoothDevice5 = mock(BluetoothDevice.class); - final BluetoothDevice bluetoothDevice6 = mock(BluetoothDevice.class); - final BluetoothClass bluetoothClass = mock(BluetoothClass.class); - final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class); - final CachedBluetoothDeviceManager cachedManager = mock(CachedBluetoothDeviceManager.class); - bluetoothDevices.add(bluetoothDevice); - bluetoothDevices.add(bluetoothDevice2); - bluetoothDevices.add(bluetoothDevice3); - bluetoothDevices.add(bluetoothDevice4); - bluetoothDevices.add(bluetoothDevice5); - bluetoothDevices.add(bluetoothDevice6); - mShadowBluetoothAdapter.setMostRecentlyConnectedDevices(bluetoothDevices); - - when(mLocalBluetoothManager.getCachedDeviceManager()).thenReturn(cachedManager); - when(cachedManager.findDevice(bluetoothDevice)).thenReturn(cachedDevice); - when(cachedManager.findDevice(bluetoothDevice2)).thenReturn(cachedDevice); - when(cachedManager.findDevice(bluetoothDevice3)).thenReturn(cachedDevice); - when(cachedManager.findDevice(bluetoothDevice4)).thenReturn(cachedDevice); - when(cachedManager.findDevice(bluetoothDevice5)).thenReturn(cachedDevice); - when(cachedManager.findDevice(bluetoothDevice6)).thenReturn(cachedDevice); - when(cachedDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); - when(cachedDevice.isConnected()).thenReturn(false); - when(cachedDevice.getDevice()).thenReturn(bluetoothDevice); - when(cachedDevice.getConnectableProfiles()).thenReturn(profiles); - when(bluetoothDevice.getBluetoothClass()).thenReturn(bluetoothClass); - when(bluetoothClass.getDeviceClass()).thenReturn(AUDIO_VIDEO_HEADPHONES); - - when(device1.getId()).thenReturn(TEST_DEVICE_ID_1); - when(device2.getId()).thenReturn(TEST_DEVICE_ID_2); - when(device3.getId()).thenReturn(TEST_DEVICE_ID_3); - when(device1.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE); - when(mLocalMediaManager.mPhoneDevice.getId()).thenReturn("test_phone_id"); - - assertThat(mLocalMediaManager.mMediaDevices).hasSize(2); - mLocalMediaManager.registerCallback(mCallback); - mLocalMediaManager.mMediaDeviceCallback.onDeviceListAdded(devices); - - assertThat(mLocalMediaManager.mMediaDevices).hasSize(7); - verify(mCallback).onDeviceListUpdate(any()); - } - - @Test public void onDeviceListAdded_bluetoothAdapterIsNull_noDisconnectedDeviceAdded() { final List<MediaDevice> devices = new ArrayList<>(); final MediaDevice device1 = mock(MediaDevice.class); |