Merge changes from topic "add-hearing-aid-device-in-audio-switch" into pi-dev am: 7e31e22f57

am: 82db752ef0

Change-Id: I7e9a40b08afebedb7b44a6345cda8b2564db315d
This commit is contained in:
ryanywlin
2018-05-09 20:46:27 -07:00
committed by android-build-merger
7 changed files with 976 additions and 134 deletions

View File

@@ -16,6 +16,7 @@
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;
@@ -27,13 +28,12 @@ import android.content.Context;
import android.media.AudioManager;
import androidx.preference.Preference;
import com.android.internal.util.ArrayUtils;
import com.android.settings.R;
import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.HearingAidProfile;
/**
* This class which allows switching between a2dp-connected BT devices.
* This class which allows switching between A2dp-connected & HAP-connected BT devices.
* A few conditions will disable this switcher:
* - No available BT device(s)
* - Media stream captured by cast device
@@ -67,18 +67,14 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
return;
}
mConnectedDevices.clear();
// Otherwise, list all of the A2DP connected device and display the active device.
mConnectedDevices = null;
BluetoothDevice activeDevice = null;
if (mAudioManager.getMode() == AudioManager.MODE_NORMAL) {
final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
if (a2dpProfile != null) {
mConnectedDevices = a2dpProfile.getConnectedDevices();
activeDevice = a2dpProfile.getActiveDevice();
}
mConnectedDevices.addAll(getConnectedA2dpDevices());
mConnectedDevices.addAll(getConnectedHearingAidDevices());
}
final int numDevices = ArrayUtils.size(mConnectedDevices);
final int numDevices = mConnectedDevices.size();
if (numDevices == 0) {
// Disable switch entry if there is no connected devices.
mPreference.setVisible(false);
@@ -91,7 +87,7 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
CharSequence[] mediaValues = new CharSequence[numDevices + 1];
// Setup devices entries, select active connected device
setupPreferenceEntries(mediaOutputs, mediaValues, activeDevice);
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.
@@ -104,8 +100,21 @@ public class MediaOutputPreferenceController extends AudioSwitchPreferenceContro
@Override
public void setActiveBluetoothDevice(BluetoothDevice device) {
if (mAudioManager.getMode() == AudioManager.MODE_NORMAL) {
mProfileManager.getA2dpProfile().setActiveDevice(device);
if (mAudioManager.getMode() != AudioManager.MODE_NORMAL) {
return;
}
final HearingAidProfile hapProfile = mProfileManager.getHearingAidProfile();
final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
if (hapProfile != null && a2dpProfile != null && device == null) {
hapProfile.setActiveDevice(null);
a2dpProfile.setActiveDevice(null);
return;
}
if (hapProfile != null && hapProfile.getHiSyncId(device) != HI_SYNC_ID_INVALID) {
hapProfile.setActiveDevice(device);
}
if (a2dpProfile != null) {
a2dpProfile.setActiveDevice(device);
}
}
}