Use corresponding profile to get active bluetooth device

- Do not use streamType to decide which active device should return.
  Base on b/80453878 comment#6, the steamType intent will only be sent
  if an action is made on stream volume or a media route is changed:
  For instance when a call to setStreamVolume() or getDeviceForStream() is made.
  It is not broadcast on actual routing changes.
  It should not be used as an indicator that the route changed during a call.
  There is no callback API and the only option is polling with getDeviceForStream().
- Use corresponding profile to get active bluetooth device
  instead of streamType
- Add test to verify the result of findActiveDevice()
  eg:
  1. A2dp device active, hearing aid device not active : return a2dp device
  2. A2dp device not active, hearing aid device not active : return null
  3. hfp device active, hearing aid device not active : return hfp device
  4. hfp device not active, hearing aid device not active : return null

Bug: 80453878
Test: make -j42 RunSettingsRoboTests
Change-Id: I5bd94899a5d508e60ce911da9689b727ad1fc20c
This commit is contained in:
hughchen
2018-07-05 14:59:57 +08:00
committed by Hugh Chen
parent 2061c2bda8
commit 244c7586f9
6 changed files with 94 additions and 130 deletions

View File

@@ -18,7 +18,6 @@ package com.android.settings.sound;
import static android.media.AudioSystem.DEVICE_OUT_BLUETOOTH_SCO;
import static android.media.AudioSystem.DEVICE_OUT_HEARING_AID;
import static android.media.AudioSystem.DEVICE_OUT_USB_HEADSET;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
@@ -286,12 +285,10 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
@Test
public void updateState_withAvailableDevicesWiredHeadsetActivated_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_USB_HEADSET);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mHeadsetProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
when(mHeadsetProfile.getActiveDevice()).thenReturn(
mBluetoothDevice); // BT device is still activated in this case
when(mHeadsetProfile.getActiveDevice()).thenReturn(null);
mController.updateState(mPreference);
@@ -463,4 +460,20 @@ public class HandsFreeProfileOutputPreferenceControllerTest {
assertThat(mController.mConnectedDevices).containsExactly(mBluetoothDevice,
mLeftBluetoothHapDevice, mRightBluetoothHapDevice);
}
@Test
public void findActiveDevice_onlyHeadsetDeviceActive_returnHeadsetDevice() {
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
when(mHeadsetProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
assertThat(mController.findActiveDevice()).isEqualTo(mBluetoothDevice);
}
@Test
public void findActiveDevice_allDevicesNotActive_returnNull() {
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
when(mHeadsetProfile.getActiveDevice()).thenReturn(null);
assertThat(mController.findActiveDevice()).isNull();
}
}