2 * Copyright (C) 2018 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings.sound;
20 import static android.media.AudioManager.DEVICE_OUT_BLUETOOTH_SCO;
21 import static android.media.AudioManager.STREAM_RING;
22 import static android.media.AudioManager.STREAM_VOICE_CALL;
23 import static android.media.AudioSystem.DEVICE_OUT_ALL_SCO;
24 import static android.media.AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP;
25 import static android.media.AudioSystem.DEVICE_OUT_BLUETOOTH_SCO_HEADSET;
26 import static android.media.AudioSystem.DEVICE_OUT_HEARING_AID;
27 import static android.media.AudioSystem.STREAM_MUSIC;
29 import static com.android.settings.core.BasePreferenceController.AVAILABLE;
30 import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
32 import static com.google.common.truth.Truth.assertThat;
34 import static org.mockito.ArgumentMatchers.any;
35 import static org.mockito.Mockito.mock;
36 import static org.mockito.Mockito.spy;
37 import static org.mockito.Mockito.verify;
38 import static org.mockito.Mockito.when;
40 import static org.robolectric.Shadows.shadowOf;
42 import android.bluetooth.BluetoothAdapter;
43 import android.bluetooth.BluetoothDevice;
44 import android.bluetooth.BluetoothManager;
45 import android.content.pm.PackageManager;
46 import android.content.BroadcastReceiver;
47 import android.content.Context;
48 import android.content.IntentFilter;
49 import android.support.v7.preference.ListPreference;
50 import android.support.v7.preference.PreferenceManager;
51 import android.support.v7.preference.PreferenceScreen;
52 import android.util.FeatureFlagUtils;
54 import com.android.settings.R;
55 import com.android.settings.core.FeatureFlags;
56 import com.android.settings.testutils.SettingsRobolectricTestRunner;
57 import com.android.settings.testutils.shadow.ShadowAudioManager;
58 import com.android.settings.testutils.shadow.ShadowBluetoothUtils;
59 import com.android.settings.testutils.shadow.ShadowMediaRouter;
60 import com.android.settingslib.bluetooth.A2dpProfile;
61 import com.android.settingslib.bluetooth.BluetoothCallback;
62 import com.android.settingslib.bluetooth.BluetoothEventManager;
63 import com.android.settingslib.bluetooth.HeadsetProfile;
64 import com.android.settingslib.bluetooth.HearingAidProfile;
65 import com.android.settingslib.bluetooth.LocalBluetoothManager;
66 import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
68 import org.junit.After;
69 import org.junit.Before;
70 import org.junit.Test;
71 import org.junit.runner.RunWith;
72 import org.mockito.Mock;
73 import org.mockito.MockitoAnnotations;
74 import org.robolectric.RuntimeEnvironment;
75 import org.robolectric.annotation.Config;
76 import org.robolectric.shadow.api.Shadow;
77 import org.robolectric.shadows.ShadowBluetoothDevice;
78 import org.robolectric.shadows.ShadowPackageManager;
80 import java.util.ArrayList;
81 import java.util.List;
83 @RunWith(SettingsRobolectricTestRunner.class)
85 ShadowAudioManager.class,
86 ShadowMediaRouter.class,
87 ShadowBluetoothUtils.class,
88 ShadowBluetoothDevice.class}
90 public class AudioOutputSwitchPreferenceControllerTest {
91 private static final String TEST_KEY = "Test_Key";
92 private static final String TEST_DEVICE_NAME_1 = "Test_A2DP_BT_Device_NAME_1";
93 private static final String TEST_DEVICE_NAME_2 = "Test_A2DP_BT_Device_NAME_2";
94 private static final String TEST_DEVICE_ADDRESS_1 = "00:A1:A1:A1:A1:A1";
95 private static final String TEST_DEVICE_ADDRESS_2 = "00:B2:B2:B2:B2:B2";
96 private static final String TEST_DEVICE_ADDRESS_3 = "00:C3:C3:C3:C3:C3";
97 private final static long HISYNCID1 = 10;
98 private final static long HISYNCID2 = 11;
101 private LocalBluetoothManager mLocalManager;
103 private BluetoothEventManager mBluetoothEventManager;
105 private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
107 private A2dpProfile mA2dpProfile;
109 private HeadsetProfile mHeadsetProfile;
111 private HearingAidProfile mHearingAidProfile;
113 private Context mContext;
114 private PreferenceScreen mScreen;
115 private ListPreference mPreference;
116 private ShadowAudioManager mShadowAudioManager;
117 private ShadowMediaRouter mShadowMediaRouter;
118 private BluetoothManager mBluetoothManager;
119 private BluetoothAdapter mBluetoothAdapter;
120 private BluetoothDevice mBluetoothDevice;
121 private BluetoothDevice mLeftBluetoothHapDevice;
122 private BluetoothDevice mRightBluetoothHapDevice;
123 private LocalBluetoothManager mLocalBluetoothManager;
124 private AudioSwitchPreferenceController mController;
125 private List<BluetoothDevice> mProfileConnectedDevices;
126 private List<BluetoothDevice> mHearingAidActiveDevices;
127 private List<BluetoothDevice> mEmptyDevices;
128 private ShadowPackageManager mPackageManager;
131 public void setUp() {
132 MockitoAnnotations.initMocks(this);
133 mContext = spy(RuntimeEnvironment.application);
135 mShadowAudioManager = ShadowAudioManager.getShadow();
136 mShadowMediaRouter = ShadowMediaRouter.getShadow();
138 ShadowBluetoothUtils.sLocalBluetoothManager = mLocalManager;
139 mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
141 when(mLocalBluetoothManager.getEventManager()).thenReturn(mBluetoothEventManager);
142 when(mLocalBluetoothManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
143 when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
144 when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(mHearingAidProfile);
145 when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
146 mPackageManager = Shadow.extract(mContext.getPackageManager());
147 mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
149 mBluetoothManager = new BluetoothManager(mContext);
150 mBluetoothAdapter = mBluetoothManager.getAdapter();
152 mBluetoothDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_1));
153 when(mBluetoothDevice.getName()).thenReturn(TEST_DEVICE_NAME_1);
154 when(mBluetoothDevice.isConnected()).thenReturn(true);
156 mLeftBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2));
157 when(mLeftBluetoothHapDevice.isConnected()).thenReturn(true);
158 mRightBluetoothHapDevice = spy(mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_3));
159 when(mRightBluetoothHapDevice.isConnected()).thenReturn(true);
161 mController = new AudioSwitchPreferenceControllerTestable(mContext, TEST_KEY);
162 mScreen = spy(new PreferenceScreen(mContext, null));
163 mPreference = new ListPreference(mContext);
164 mProfileConnectedDevices = new ArrayList<>();
165 mHearingAidActiveDevices = new ArrayList<>(2);
166 mEmptyDevices = new ArrayList<>(2);
168 when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
169 when(mScreen.getContext()).thenReturn(mContext);
170 when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
171 mScreen.addPreference(mPreference);
172 mController.displayPreference(mScreen);
176 public void tearDown() {
177 mShadowAudioManager.reset();
178 mShadowMediaRouter.reset();
179 ShadowBluetoothUtils.reset();
183 public void constructor_notSupportBluetooth_shouldReturnBeforeUsingLocalBluetoothManager() {
184 ShadowBluetoothUtils.reset();
185 mLocalBluetoothManager = ShadowBluetoothUtils.getLocalBtManager(mContext);
187 AudioSwitchPreferenceController controller = new AudioSwitchPreferenceControllerTestable(
190 assertThat(mLocalBluetoothManager).isNull();
194 public void getAvailabilityStatus_disableFlagNoBluetoothFeature_returnUnavailable() {
195 FeatureFlagUtils.setEnabled(mContext, FeatureFlags.AUDIO_SWITCHER_SETTINGS, false);
196 mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, false);
198 assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
202 public void getAvailabilityStatus_disableFlagWithBluetoothFeature_returnUnavailable() {
203 FeatureFlagUtils.setEnabled(mContext, FeatureFlags.AUDIO_SWITCHER_SETTINGS, false);
204 mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
207 assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
211 public void getAvailabilityStatus_enableFlagWithBluetoothFeature_returnAvailable() {
212 FeatureFlagUtils.setEnabled(mContext, FeatureFlags.AUDIO_SWITCHER_SETTINGS, true);
213 mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
215 assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
219 public void getAvailabilityStatus_enableFlagNoBluetoothFeature_returnUnavailable() {
220 FeatureFlagUtils.setEnabled(mContext, FeatureFlags.AUDIO_SWITCHER_SETTINGS, true);
221 mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, false);
223 assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
227 public void onStart_shouldRegisterCallbackAndRegisterReceiver() {
228 mController.onStart();
230 verify(mLocalBluetoothManager.getEventManager()).registerCallback(
231 any(BluetoothCallback.class));
232 verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
236 public void onStop_shouldUnregisterCallbackAndUnregisterReceiver() {
237 mController.onStart();
238 mController.onStop();
240 verify(mLocalBluetoothManager.getEventManager()).unregisterCallback(
241 any(BluetoothCallback.class));
242 verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
246 public void onPreferenceChange_toThisDevice_shouldSetDefaultSummary() {
247 mController.mConnectedDevices.clear();
248 mController.mConnectedDevices.add(mBluetoothDevice);
250 mController.onPreferenceChange(mPreference,
251 mContext.getText(R.string.media_output_default_summary));
253 assertThat(mPreference.getSummary()).isEqualTo(
254 mContext.getText(R.string.media_output_default_summary));
258 * One Bluetooth devices are available, and select the device.
259 * Preference summary should be device name.
262 public void onPreferenceChange_toBtDevice_shouldSetBtDeviceName() {
263 mController.mConnectedDevices.clear();
264 mController.mConnectedDevices.add(mBluetoothDevice);
266 mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_1);
268 assertThat(mPreference.getSummary()).isEqualTo(TEST_DEVICE_NAME_1);
272 * More than one Bluetooth devices are available, and select second device.
273 * Preference summary should be second device name.
276 public void onPreferenceChange_toBtDevices_shouldSetSecondBtDeviceName() {
277 ShadowBluetoothDevice shadowBluetoothDevice;
278 BluetoothDevice secondBluetoothDevice;
279 secondBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2);
280 shadowBluetoothDevice = shadowOf(secondBluetoothDevice);
281 shadowBluetoothDevice.setName(TEST_DEVICE_NAME_2);
282 mController.mConnectedDevices.clear();
283 mController.mConnectedDevices.add(mBluetoothDevice);
284 mController.mConnectedDevices.add(secondBluetoothDevice);
286 mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_2);
288 assertThat(mPreference.getSummary()).isEqualTo(TEST_DEVICE_NAME_2);
292 * mConnectedDevices is empty.
293 * onPreferenceChange should return false.
296 public void onPreferenceChange_connectedDeviceIsNull_shouldReturnFalse() {
297 mController.mConnectedDevices.clear();
299 assertThat(mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_1)).isFalse();
303 * Audio stream output to bluetooth sco headset which is the subset of all sco device.
304 * isStreamFromOutputDevice should return true.
307 public void isStreamFromOutputDevice_outputDeviceIsBtScoHeadset_shouldReturnTrue() {
308 mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO_HEADSET);
310 assertThat(mController.isStreamFromOutputDevice(STREAM_MUSIC, DEVICE_OUT_ALL_SCO)).isTrue();
314 * Audio stream is not STREAM_MUSIC or STREAM_VOICE_CALL.
315 * findActiveDevice should return null.
318 public void findActiveDevice_streamIsRing_shouldReturnNull() {
319 assertThat(mController.findActiveDevice(STREAM_RING)).isNull();
323 * Audio stream is STREAM_MUSIC and output device is A2dp bluetooth device.
324 * findActiveDevice should return A2dp active device.
327 public void findActiveDevice_streamMusicToA2dpDevice_shouldReturnActiveA2dpDevice() {
328 mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
329 mHearingAidActiveDevices.clear();
330 mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
331 when(mHeadsetProfile.getActiveDevice()).thenReturn(mLeftBluetoothHapDevice);
332 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
333 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
335 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isEqualTo(mBluetoothDevice);
339 * Audio stream is STREAM_VOICE_CALL and output device is Hands free profile bluetooth device.
340 * findActiveDevice should return Hands free profile active device.
343 public void findActiveDevice_streamVoiceCallToHfpDevice_shouldReturnActiveHfpDevice() {
344 mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
345 mHearingAidActiveDevices.clear();
346 mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
347 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
348 when(mA2dpProfile.getActiveDevice()).thenReturn(mLeftBluetoothHapDevice);
349 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
351 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isEqualTo(mBluetoothDevice);
355 * Audio stream is STREAM_MUSIC or STREAM_VOICE_CALL and output device is hearing aid profile
356 * bluetooth device. And left side of HAP device is active.
357 * findActiveDevice should return hearing aid device active device.
360 public void findActiveDevice_streamToHapDeviceLeftActiveDevice_shouldReturnActiveHapDevice() {
361 mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
362 mController.mConnectedDevices.clear();
363 mController.mConnectedDevices.add(mBluetoothDevice);
364 mController.mConnectedDevices.add(mLeftBluetoothHapDevice);
365 mHearingAidActiveDevices.clear();
366 mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
367 mHearingAidActiveDevices.add(null);
368 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
369 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
370 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
372 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isEqualTo(mLeftBluetoothHapDevice);
373 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isEqualTo(
374 mLeftBluetoothHapDevice);
378 * Audio stream is STREAM_MUSIC or STREAM_VOICE_CALL and output device is hearing aid profile
379 * bluetooth device. And right side of HAP device is active.
380 * findActiveDevice should return hearing aid device active device.
383 public void findActiveDevice_streamToHapDeviceRightActiveDevice_shouldReturnActiveHapDevice() {
384 mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
385 mController.mConnectedDevices.clear();
386 mController.mConnectedDevices.add(mBluetoothDevice);
387 mController.mConnectedDevices.add(mRightBluetoothHapDevice);
388 mHearingAidActiveDevices.clear();
389 mHearingAidActiveDevices.add(null);
390 mHearingAidActiveDevices.add(mRightBluetoothHapDevice);
391 mHearingAidActiveDevices.add(mRightBluetoothHapDevice);
392 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
393 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
394 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
396 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isEqualTo(mRightBluetoothHapDevice);
397 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isEqualTo(
398 mRightBluetoothHapDevice);
402 * Audio stream is STREAM_MUSIC or STREAM_VOICE_CALL and output device is hearing aid
403 * profile bluetooth device. And both are active device.
404 * findActiveDevice should return only return the active device in mConnectedDevices.
407 public void findActiveDevice_streamToHapDeviceTwoActiveDevice_shouldReturnActiveHapDevice() {
408 mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
409 mController.mConnectedDevices.clear();
410 mController.mConnectedDevices.add(mBluetoothDevice);
411 mController.mConnectedDevices.add(mRightBluetoothHapDevice);
412 mHearingAidActiveDevices.clear();
413 mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
414 mHearingAidActiveDevices.add(mRightBluetoothHapDevice);
415 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
416 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
417 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
419 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isEqualTo(mRightBluetoothHapDevice);
420 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isEqualTo(
421 mRightBluetoothHapDevice);
425 * Audio stream is STREAM_MUSIC or STREAM_VOICE_CALL and output device is hearing aid
426 * profile bluetooth device. And none of them are active.
427 * findActiveDevice should return null.
430 public void findActiveDevice_streamToOtherDevice_shouldReturnActiveHapDevice() {
431 mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
432 mController.mConnectedDevices.clear();
433 mController.mConnectedDevices.add(mBluetoothDevice);
434 mController.mConnectedDevices.add(mLeftBluetoothHapDevice);
435 mHearingAidActiveDevices.clear();
436 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
437 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
438 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
440 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isNull();
441 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isNull();
445 * Two hearing aid devices with different HisyncId
446 * getConnectedHearingAidDevices should add both device to list.
449 public void getConnectedHearingAidDevices_deviceHisyncIdIsDifferent_shouldAddBothToList() {
450 mEmptyDevices.clear();
451 mProfileConnectedDevices.clear();
452 mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
453 mProfileConnectedDevices.add(mRightBluetoothHapDevice);
454 when(mHearingAidProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
455 when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
456 when(mHearingAidProfile.getHiSyncId(mRightBluetoothHapDevice)).thenReturn(HISYNCID2);
458 mEmptyDevices.addAll(mController.getConnectedHearingAidDevices());
460 assertThat(mEmptyDevices).containsExactly(mLeftBluetoothHapDevice,
461 mRightBluetoothHapDevice);
465 * Two hearing aid devices with same HisyncId
466 * getConnectedHearingAidDevices should only add first device to list.
469 public void getConnectedHearingAidDevices_deviceHisyncIdIsSame_shouldAddOneToList() {
470 mEmptyDevices.clear();
471 mProfileConnectedDevices.clear();
472 mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
473 mProfileConnectedDevices.add(mRightBluetoothHapDevice);
474 when(mHearingAidProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
475 when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
476 when(mHearingAidProfile.getHiSyncId(mRightBluetoothHapDevice)).thenReturn(HISYNCID1);
478 mEmptyDevices.addAll(mController.getConnectedHearingAidDevices());
480 assertThat(mEmptyDevices).containsExactly(mLeftBluetoothHapDevice);
484 * One A2dp device is connected.
485 * getConnectedA2dpDevices should add this device to list.
488 public void getConnectedA2dpDevices_oneConnectedA2dpDevice_shouldAddDeviceToList() {
489 mEmptyDevices.clear();
490 mProfileConnectedDevices.clear();
491 mProfileConnectedDevices.add(mBluetoothDevice);
492 when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
494 mEmptyDevices.addAll(mController.getConnectedA2dpDevices());
496 assertThat(mEmptyDevices).containsExactly(mBluetoothDevice);
500 * More than one A2dp devices are connected.
501 * getConnectedA2dpDevices should add all devices to list.
504 public void getConnectedA2dpDevices_moreThanOneConnectedA2dpDevice_shouldAddDeviceToList() {
505 mEmptyDevices.clear();
506 mProfileConnectedDevices.clear();
507 mProfileConnectedDevices.add(mBluetoothDevice);
508 mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
509 when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
511 mEmptyDevices.addAll(mController.getConnectedA2dpDevices());
513 assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, mLeftBluetoothHapDevice);
517 * One hands free profile device is connected.
518 * getConnectedA2dpDevices should add this device to list.
521 public void getConnectedHfpDevices_oneConnectedHfpDevice_shouldAddDeviceToList() {
522 mEmptyDevices.clear();
523 mProfileConnectedDevices.clear();
524 mProfileConnectedDevices.add(mBluetoothDevice);
525 when(mHeadsetProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
527 mEmptyDevices.addAll(mController.getConnectedHfpDevices());
529 assertThat(mEmptyDevices).containsExactly(mBluetoothDevice);
533 * More than one hands free profile devices are connected.
534 * getConnectedA2dpDevices should add all devices to list.
537 public void getConnectedHfpDevices_moreThanOneConnectedHfpDevice_shouldAddDeviceToList() {
538 mEmptyDevices.clear();
539 mProfileConnectedDevices.clear();
540 mProfileConnectedDevices.add(mBluetoothDevice);
541 mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
542 when(mHeadsetProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
544 mEmptyDevices.addAll(mController.getConnectedHfpDevices());
546 assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, mLeftBluetoothHapDevice);
549 private class AudioSwitchPreferenceControllerTestable extends
550 AudioSwitchPreferenceController {
551 AudioSwitchPreferenceControllerTestable(Context context, String key) {
556 public void setActiveBluetoothDevice(BluetoothDevice device) {
560 public String getPreferenceKey() {