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

@@ -19,7 +19,6 @@ package com.android.settings.sound;
import static android.bluetooth.IBluetoothHearingAid.HI_SYNC_ID_INVALID;
import static android.media.AudioManager.STREAM_MUSIC;
import static android.media.AudioSystem.DEVICE_OUT_REMOTE_SUBMIX;
import static android.media.AudioSystem.DEVICE_OUT_USB_HEADSET;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
@@ -91,12 +90,7 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
CharSequence[] mediaValues = new CharSequence[numDevices + 1];
// Setup devices entries, select active connected device
setupPreferenceEntries(mediaOutputs, mediaValues, findActiveDevice(STREAM_MUSIC));
if (isStreamFromOutputDevice(STREAM_MUSIC, DEVICE_OUT_USB_HEADSET)) {
// If wired headset is plugged in and active, select to default device.
mSelectedIndex = getDefaultDeviceIndex();
}
setupPreferenceEntries(mediaOutputs, mediaValues, findActiveDevice());
// Display connected devices, default device and show the active device
setPreference(mediaOutputs, mediaValues, preference);
@@ -121,4 +115,15 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
a2dpProfile.setActiveDevice(device);
}
}
@Override
public BluetoothDevice findActiveDevice() {
BluetoothDevice activeDevice = findActiveHearingAidDevice();
final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
if (activeDevice == null && a2dpProfile != null) {
activeDevice = a2dpProfile.getActiveDevice();
}
return activeDevice;
}
}