summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/sound
diff options
context:
space:
mode:
authorryanywlin <ryanywlin@google.com>2018-04-28 07:26:46 +0800
committerryanywlin <ryanywlin@google.com>2018-05-10 10:28:20 +0800
commit8276d966e9c39c70d6a84c724ef36bf26f298025 (patch)
tree40020ed087514d481e2a69dc33a07bafd18716cf /src/com/android/settings/sound
parent9f407aba369f2699c3d2bb8d2879b2103afcb577 (diff)
downloadpackages_apps_Settings-8276d966e9c39c70d6a84c724ef36bf26f298025.tar.gz
packages_apps_Settings-8276d966e9c39c70d6a84c724ef36bf26f298025.tar.bz2
packages_apps_Settings-8276d966e9c39c70d6a84c724ef36bf26f298025.zip
Add hearing aid device in audio switch
- Add connected hearing aid device to MediaOutputPreferenceController and HandsFreeProfileOutputPreferenceController - Set active device to different profile depend on HisyncId Bug: 78142719 Test: make RunSettingsRoboTests ROBOTEST_FILTER="MediaOutputPreferenceControllerTest" -j28 Test: make RunSettingsRoboTests ROBOTEST_FILTER="HandsFreeProfileOutputPreferenceControllerTest" -j28 Test: make RunSettingsRoboTests ROBOTEST_FILTER="AudioOutputSwitchPreferenceControllerTest" -j28 Change-Id: Ib8fe4f06f8564572dffdce6fcc3f29578bf91bd9
Diffstat (limited to 'src/com/android/settings/sound')
-rw-r--r--src/com/android/settings/sound/AudioSwitchPreferenceController.java13
-rw-r--r--src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java37
-rw-r--r--src/com/android/settings/sound/MediaOutputPreferenceController.java37
3 files changed, 49 insertions, 38 deletions
diff --git a/src/com/android/settings/sound/AudioSwitchPreferenceController.java b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
index ea7e8fed76..81479c9e87 100644
--- a/src/com/android/settings/sound/AudioSwitchPreferenceController.java
+++ b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
@@ -42,7 +42,6 @@ import android.support.v7.preference.PreferenceScreen;
import android.text.TextUtils;
import android.util.FeatureFlagUtils;
-import com.android.internal.util.ArrayUtils;
import com.android.settings.R;
import com.android.settings.bluetooth.Utils;
import com.android.settings.core.BasePreferenceController;
@@ -73,12 +72,12 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
private static final int INVALID_INDEX = -1;
+ protected final List<BluetoothDevice> mConnectedDevices;
protected final AudioManager mAudioManager;
protected final MediaRouter mMediaRouter;
protected final LocalBluetoothProfileManager mProfileManager;
protected int mSelectedIndex;
protected Preference mPreference;
- protected List<BluetoothDevice> mConnectedDevices;
private final AudioManagerAudioDeviceCallback mAudioManagerAudioDeviceCallback;
private final LocalBluetoothManager mLocalBluetoothManager;
@@ -97,6 +96,7 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
mAudioManagerAudioDeviceCallback = new AudioManagerAudioDeviceCallback();
mReceiver = new WiredHeadsetBroadcastReceiver();
mMediaRouterCallback = new MediaRouterCallback();
+ mConnectedDevices = new ArrayList<>();
}
/**
@@ -206,13 +206,6 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
return (device & mAudioManager.getDevicesForStream(streamType)) != 0;
}
- protected boolean isOngoingCallStatus() {
- final int audioMode = mAudioManager.getMode();
- return audioMode == AudioManager.MODE_RINGTONE
- || audioMode == AudioManager.MODE_IN_CALL
- || audioMode == AudioManager.MODE_IN_COMMUNICATION;
- }
-
/**
* get hands free profile(HFP) connected device
*/
@@ -308,7 +301,7 @@ public abstract class AudioSwitchPreferenceController extends BasePreferenceCont
int getDefaultDeviceIndex() {
// Default device is after all connected devices.
- return ArrayUtils.size(mConnectedDevices);
+ return mConnectedDevices.size();
}
void setupPreferenceEntries(CharSequence[] mediaOutputs, CharSequence[] mediaValues,
diff --git a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
index 6907a4a2aa..2039913312 100644
--- a/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
+++ b/src/com/android/settings/sound/HandsFreeProfileOutputPreferenceController.java
@@ -16,6 +16,7 @@
package com.android.settings.sound;
+import static android.bluetooth.IBluetoothHearingAid.HI_SYNC_ID_INVALID;
import static android.media.AudioManager.STREAM_VOICE_CALL;
import static android.media.AudioSystem.DEVICE_OUT_USB_HEADSET;
@@ -25,12 +26,12 @@ import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.support.v7.preference.Preference;
-import com.android.internal.util.ArrayUtils;
import com.android.settings.R;
import com.android.settingslib.bluetooth.HeadsetProfile;
+import com.android.settingslib.bluetooth.HearingAidProfile;
/**
- * This class allows switching between HFP-connected BT devices
+ * This class allows switching between HFP-connected & HAP-connected BT devices
* while in on-call state.
*/
public class HandsFreeProfileOutputPreferenceController extends
@@ -57,16 +58,11 @@ public class HandsFreeProfileOutputPreferenceController extends
// Ongoing call status, list all the connected devices support hands free profile.
// Select current active device.
// Disable switch entry if there is no connected device.
- mConnectedDevices = null;
- BluetoothDevice activeDevice = null;
+ mConnectedDevices.clear();
+ mConnectedDevices.addAll(getConnectedHfpDevices());
+ mConnectedDevices.addAll(getConnectedHearingAidDevices());
- final HeadsetProfile headsetProfile = mProfileManager.getHeadsetProfile();
- if (headsetProfile != null) {
- mConnectedDevices = headsetProfile.getConnectedDevices();
- activeDevice = headsetProfile.getActiveDevice();
- }
-
- final int numDevices = ArrayUtils.size(mConnectedDevices);
+ final int numDevices = mConnectedDevices.size();
if (numDevices == 0) {
// No connected devices, disable switch entry.
mPreference.setVisible(false);
@@ -79,7 +75,7 @@ public class HandsFreeProfileOutputPreferenceController extends
CharSequence[] mediaValues = new CharSequence[numDevices + 1];
// Setup devices entries, select active connected device
- setupPreferenceEntries(mediaOutputs, mediaValues, activeDevice);
+ setupPreferenceEntries(mediaOutputs, mediaValues, findActiveDevice(STREAM_VOICE_CALL));
if (isStreamFromOutputDevice(STREAM_VOICE_CALL, DEVICE_OUT_USB_HEADSET)) {
// If wired headset is plugged in and active, select to default device.
@@ -92,8 +88,21 @@ public class HandsFreeProfileOutputPreferenceController extends
@Override
public void setActiveBluetoothDevice(BluetoothDevice device) {
- if (Utils.isAudioModeOngoingCall(mContext)) {
- mProfileManager.getHeadsetProfile().setActiveDevice(device);
+ if (!Utils.isAudioModeOngoingCall(mContext)) {
+ return;
+ }
+ final HearingAidProfile hapProfile = mProfileManager.getHearingAidProfile();
+ final HeadsetProfile hfpProfile = mProfileManager.getHeadsetProfile();
+ if (hapProfile != null && hfpProfile != null && device == null) {
+ hfpProfile.setActiveDevice(null);
+ hapProfile.setActiveDevice(null);
+ return;
+ }
+ if (hapProfile != null && hapProfile.getHiSyncId(device) != HI_SYNC_ID_INVALID) {
+ hapProfile.setActiveDevice(device);
+ }
+ if (hfpProfile != null) {
+ hfpProfile.setActiveDevice(device);
}
}
}
diff --git a/src/com/android/settings/sound/MediaOutputPreferenceController.java b/src/com/android/settings/sound/MediaOutputPreferenceController.java
index d0677a7e48..79f3c9d954 100644
--- a/src/com/android/settings/sound/MediaOutputPreferenceController.java
+++ b/src/com/android/settings/sound/MediaOutputPreferenceController.java
@@ -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 android.support.v7.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);
}
}
}