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

@@ -16,11 +16,9 @@
package com.android.settings.sound;
import static android.media.AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP;
import static android.media.AudioSystem.DEVICE_OUT_HEARING_AID;
import static android.media.AudioSystem.DEVICE_OUT_REMOTE_SUBMIX;
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;
@@ -336,12 +334,11 @@ public class MediaOutputPreferenceControllerTest {
@Test
public void updateState_a2dpDevicesAvailableWiredHeadsetIsActivated_shouldSetDefaultSummary() {
mShadowAudioManager.setMode(AudioManager.MODE_NORMAL);
mShadowAudioManager.setOutputDevice(DEVICE_OUT_USB_HEADSET);
mProfileConnectedDevices.clear();
mProfileConnectedDevices.add(mBluetoothDevice);
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
when(mA2dpProfile.getConnectedDevices()).thenReturn(mProfileConnectedDevices);
when(mA2dpProfile.getActiveDevice()).thenReturn(
mBluetoothDevice); // BT device is still activated in this case
when(mA2dpProfile.getActiveDevice()).thenReturn(null);
mController.updateState(mPreference);
@@ -516,4 +513,20 @@ public class MediaOutputPreferenceControllerTest {
assertThat(mController.mConnectedDevices).containsExactly(mBluetoothDevice,
mLeftBluetoothHapDevice, mRightBluetoothHapDevice);
}
@Test
public void findActiveDevice_onlyA2dpDeviceActive_returnA2dpDevice() {
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
when(mA2dpProfile.getActiveDevice()).thenReturn(mBluetoothDevice);
assertThat(mController.findActiveDevice()).isEqualTo(mBluetoothDevice);
}
@Test
public void findActiveDevice_allDevicesNotActive_returnNull() {
when(mLocalBluetoothProfileManager.getHearingAidProfile()).thenReturn(null);
when(mA2dpProfile.getActiveDevice()).thenReturn(null);
assertThat(mController.findActiveDevice()).isNull();
}
}