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(
189 controller.onStart();
192 assertThat(mLocalBluetoothManager).isNull();
196 public void getAvailabilityStatus_disableFlagNoBluetoothFeature_returnUnavailable() {
197 FeatureFlagUtils.setEnabled(mContext, FeatureFlags.AUDIO_SWITCHER_SETTINGS, false);
198 mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, false);
200 assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
204 public void getAvailabilityStatus_disableFlagWithBluetoothFeature_returnUnavailable() {
205 FeatureFlagUtils.setEnabled(mContext, FeatureFlags.AUDIO_SWITCHER_SETTINGS, false);
206 mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
209 assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
213 public void getAvailabilityStatus_enableFlagWithBluetoothFeature_returnAvailable() {
214 FeatureFlagUtils.setEnabled(mContext, FeatureFlags.AUDIO_SWITCHER_SETTINGS, true);
215 mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, true);
217 assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
221 public void getAvailabilityStatus_enableFlagNoBluetoothFeature_returnUnavailable() {
222 FeatureFlagUtils.setEnabled(mContext, FeatureFlags.AUDIO_SWITCHER_SETTINGS, true);
223 mPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH, false);
225 assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
229 public void onStart_shouldRegisterCallbackAndRegisterReceiver() {
230 mController.onStart();
232 verify(mLocalBluetoothManager.getEventManager()).registerCallback(
233 any(BluetoothCallback.class));
234 verify(mContext).registerReceiver(any(BroadcastReceiver.class), any(IntentFilter.class));
235 verify(mLocalBluetoothManager).setForegroundActivity(mContext);
239 public void onStop_shouldUnregisterCallbackAndUnregisterReceiver() {
240 mController.onStart();
241 mController.onStop();
243 verify(mLocalBluetoothManager.getEventManager()).unregisterCallback(
244 any(BluetoothCallback.class));
245 verify(mContext).unregisterReceiver(any(BroadcastReceiver.class));
246 verify(mLocalBluetoothManager).setForegroundActivity(null);
250 public void onPreferenceChange_toThisDevice_shouldSetDefaultSummary() {
251 mController.mConnectedDevices.clear();
252 mController.mConnectedDevices.add(mBluetoothDevice);
254 mController.onPreferenceChange(mPreference,
255 mContext.getText(R.string.media_output_default_summary));
257 assertThat(mPreference.getSummary()).isEqualTo(
258 mContext.getText(R.string.media_output_default_summary));
262 * One Bluetooth devices are available, and select the device.
263 * Preference summary should be device name.
266 public void onPreferenceChange_toBtDevice_shouldSetBtDeviceName() {
267 mController.mConnectedDevices.clear();
268 mController.mConnectedDevices.add(mBluetoothDevice);
270 mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_1);
272 assertThat(mPreference.getSummary()).isEqualTo(TEST_DEVICE_NAME_1);
276 * More than one Bluetooth devices are available, and select second device.
277 * Preference summary should be second device name.
280 public void onPreferenceChange_toBtDevices_shouldSetSecondBtDeviceName() {
281 ShadowBluetoothDevice shadowBluetoothDevice;
282 BluetoothDevice secondBluetoothDevice;
283 secondBluetoothDevice = mBluetoothAdapter.getRemoteDevice(TEST_DEVICE_ADDRESS_2);
284 shadowBluetoothDevice = shadowOf(secondBluetoothDevice);
285 shadowBluetoothDevice.setName(TEST_DEVICE_NAME_2);
286 mController.mConnectedDevices.clear();
287 mController.mConnectedDevices.add(mBluetoothDevice);
288 mController.mConnectedDevices.add(secondBluetoothDevice);
290 mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_2);
292 assertThat(mPreference.getSummary()).isEqualTo(TEST_DEVICE_NAME_2);
296 * mConnectedDevices is empty.
297 * onPreferenceChange should return false.
300 public void onPreferenceChange_connectedDeviceIsNull_shouldReturnFalse() {
301 mController.mConnectedDevices.clear();
303 assertThat(mController.onPreferenceChange(mPreference, TEST_DEVICE_ADDRESS_1)).isFalse();
307 * Audio stream output to bluetooth sco headset which is the subset of all sco device.
308 * isStreamFromOutputDevice should return true.
311 public void isStreamFromOutputDevice_outputDeviceIsBtScoHeadset_shouldReturnTrue() {
312 mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO_HEADSET);
314 assertThat(mController.isStreamFromOutputDevice(STREAM_MUSIC, DEVICE_OUT_ALL_SCO)).isTrue();
318 * Audio stream is not STREAM_MUSIC or STREAM_VOICE_CALL.
319 * findActiveDevice should return null.
322 public void findActiveDevice_streamIsRing_shouldReturnNull() {
323 assertThat(mController.findActiveDevice(STREAM_RING)).isNull();
327 * Audio stream is STREAM_MUSIC and output device is A2dp bluetooth device.
328 * findActiveDevice should return A2dp active device.
331 public void findActiveDevice_streamMusicToA2dpDevice_shouldReturnActiveA2dpDevice() {
332 mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_A2DP);
333 mHearingAidActiveDevices.clear();
334 mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
335 when(mHeadsetProfile.getActiveDevice()).thenReturn(mLeftBluetoothHapDevice);
336 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
337 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
339 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isEqualTo(mBluetoothDevice);
343 * Audio stream is STREAM_VOICE_CALL and output device is Hands free profile bluetooth device.
344 * findActiveDevice should return Hands free profile active device.
347 public void findActiveDevice_streamVoiceCallToHfpDevice_shouldReturnActiveHfpDevice() {
348 mShadowAudioManager.setOutputDevice(DEVICE_OUT_BLUETOOTH_SCO);
349 mHearingAidActiveDevices.clear();
350 mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
351 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
352 when(mA2dpProfile.getActiveDevice()).thenReturn(mLeftBluetoothHapDevice);
353 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
355 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isEqualTo(mBluetoothDevice);
359 * Audio stream is STREAM_MUSIC or STREAM_VOICE_CALL and output device is hearing aid profile
360 * bluetooth device. And left side of HAP device is active.
361 * findActiveDevice should return hearing aid device active device.
364 public void findActiveDevice_streamToHapDeviceLeftActiveDevice_shouldReturnActiveHapDevice() {
365 mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
366 mController.mConnectedDevices.clear();
367 mController.mConnectedDevices.add(mBluetoothDevice);
368 mController.mConnectedDevices.add(mLeftBluetoothHapDevice);
369 mHearingAidActiveDevices.clear();
370 mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
371 mHearingAidActiveDevices.add(null);
372 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
373 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
374 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
376 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isEqualTo(mLeftBluetoothHapDevice);
377 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isEqualTo(
378 mLeftBluetoothHapDevice);
382 * Audio stream is STREAM_MUSIC or STREAM_VOICE_CALL and output device is hearing aid profile
383 * bluetooth device. And right side of HAP device is active.
384 * findActiveDevice should return hearing aid device active device.
387 public void findActiveDevice_streamToHapDeviceRightActiveDevice_shouldReturnActiveHapDevice() {
388 mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
389 mController.mConnectedDevices.clear();
390 mController.mConnectedDevices.add(mBluetoothDevice);
391 mController.mConnectedDevices.add(mRightBluetoothHapDevice);
392 mHearingAidActiveDevices.clear();
393 mHearingAidActiveDevices.add(null);
394 mHearingAidActiveDevices.add(mRightBluetoothHapDevice);
395 mHearingAidActiveDevices.add(mRightBluetoothHapDevice);
396 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
397 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
398 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
400 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isEqualTo(mRightBluetoothHapDevice);
401 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isEqualTo(
402 mRightBluetoothHapDevice);
406 * Audio stream is STREAM_MUSIC or STREAM_VOICE_CALL and output device is hearing aid
407 * profile bluetooth device. And both are active device.
408 * findActiveDevice should return only return the active device in mConnectedDevices.
411 public void findActiveDevice_streamToHapDeviceTwoActiveDevice_shouldReturnActiveHapDevice() {
412 mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
413 mController.mConnectedDevices.clear();
414 mController.mConnectedDevices.add(mBluetoothDevice);
415 mController.mConnectedDevices.add(mRightBluetoothHapDevice);
416 mHearingAidActiveDevices.clear();
417 mHearingAidActiveDevices.add(mLeftBluetoothHapDevice);
418 mHearingAidActiveDevices.add(mRightBluetoothHapDevice);
419 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
420 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
421 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
423 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isEqualTo(mRightBluetoothHapDevice);
424 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isEqualTo(
425 mRightBluetoothHapDevice);
429 * Audio stream is STREAM_MUSIC or STREAM_VOICE_CALL and output device is hearing aid
430 * profile bluetooth device. And none of them are active.
431 * findActiveDevice should return null.
434 public void findActiveDevice_streamToOtherDevice_shouldReturnActiveHapDevice() {
435 mShadowAudioManager.setOutputDevice(DEVICE_OUT_HEARING_AID);
436 mController.mConnectedDevices.clear();
437 mController.mConnectedDevices.add(mBluetoothDevice);
438 mController.mConnectedDevices.add(mLeftBluetoothHapDevice);
439 mHearingAidActiveDevices.clear();
440 when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
441 when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
442 when(mHearingAidProfile.getActiveDevices()).thenReturn(mHearingAidActiveDevices);
444 assertThat(mController.findActiveDevice(STREAM_MUSIC)).isNull();
445 assertThat(mController.findActiveDevice(STREAM_VOICE_CALL)).isNull();
449 * Two hearing aid devices with different HisyncId
450 * getConnectedHearingAidDevices should add both device to list.
453 public void getConnectedHearingAidDevices_deviceHisyncIdIsDifferent_shouldAddBothToList() {
454 mEmptyDevices.clear();
455 mProfileConnectedDevices.clear();
456 mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
457 mProfileConnectedDevices.add(mRightBluetoothHapDevice);
458 when(mHearingAidProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
459 when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
460 when(mHearingAidProfile.getHiSyncId(mRightBluetoothHapDevice)).thenReturn(HISYNCID2);
462 mEmptyDevices.addAll(mController.getConnectedHearingAidDevices());
464 assertThat(mEmptyDevices).containsExactly(mLeftBluetoothHapDevice,
465 mRightBluetoothHapDevice);
469 * Two hearing aid devices with same HisyncId
470 * getConnectedHearingAidDevices should only add first device to list.
473 public void getConnectedHearingAidDevices_deviceHisyncIdIsSame_shouldAddOneToList() {
474 mEmptyDevices.clear();
475 mProfileConnectedDevices.clear();
476 mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
477 mProfileConnectedDevices.add(mRightBluetoothHapDevice);
478 when(mHearingAidProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
479 when(mHearingAidProfile.getHiSyncId(mLeftBluetoothHapDevice)).thenReturn(HISYNCID1);
480 when(mHearingAidProfile.getHiSyncId(mRightBluetoothHapDevice)).thenReturn(HISYNCID1);
482 mEmptyDevices.addAll(mController.getConnectedHearingAidDevices());
484 assertThat(mEmptyDevices).containsExactly(mLeftBluetoothHapDevice);
488 * One A2dp device is connected.
489 * getConnectedA2dpDevices should add this device to list.
492 public void getConnectedA2dpDevices_oneConnectedA2dpDevice_shouldAddDeviceToList() {
493 mEmptyDevices.clear();
494 mProfileConnectedDevices.clear();
495 mProfileConnectedDevices.add(mBluetoothDevice);
496 when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
498 mEmptyDevices.addAll(mController.getConnectedA2dpDevices());
500 assertThat(mEmptyDevices).containsExactly(mBluetoothDevice);
504 * More than one A2dp devices are connected.
505 * getConnectedA2dpDevices should add all devices to list.
508 public void getConnectedA2dpDevices_moreThanOneConnectedA2dpDevice_shouldAddDeviceToList() {
509 mEmptyDevices.clear();
510 mProfileConnectedDevices.clear();
511 mProfileConnectedDevices.add(mBluetoothDevice);
512 mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
513 when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
515 mEmptyDevices.addAll(mController.getConnectedA2dpDevices());
517 assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, mLeftBluetoothHapDevice);
521 * One hands free profile device is connected.
522 * getConnectedA2dpDevices should add this device to list.
525 public void getConnectedHfpDevices_oneConnectedHfpDevice_shouldAddDeviceToList() {
526 mEmptyDevices.clear();
527 mProfileConnectedDevices.clear();
528 mProfileConnectedDevices.add(mBluetoothDevice);
529 when(mHeadsetProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
531 mEmptyDevices.addAll(mController.getConnectedHfpDevices());
533 assertThat(mEmptyDevices).containsExactly(mBluetoothDevice);
537 * More than one hands free profile devices are connected.
538 * getConnectedA2dpDevices should add all devices to list.
541 public void getConnectedHfpDevices_moreThanOneConnectedHfpDevice_shouldAddDeviceToList() {
542 mEmptyDevices.clear();
543 mProfileConnectedDevices.clear();
544 mProfileConnectedDevices.add(mBluetoothDevice);
545 mProfileConnectedDevices.add(mLeftBluetoothHapDevice);
546 when(mHeadsetProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
548 mEmptyDevices.addAll(mController.getConnectedHfpDevices());
550 assertThat(mEmptyDevices).containsExactly(mBluetoothDevice, mLeftBluetoothHapDevice);
553 private class AudioSwitchPreferenceControllerTestable extends
554 AudioSwitchPreferenceController {
555 AudioSwitchPreferenceControllerTestable(Context context, String key) {
560 public void setActiveBluetoothDevice(BluetoothDevice device) {
564 public String getPreferenceKey() {