summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jean-Michel Trivi <jmtrivi@google.com> 2022-04-29 22:21:48 +0000
committer Jean-Michel Trivi <jmtrivi@google.com> 2022-04-30 02:35:48 +0000
commit2ec2ec5a6bc247ededb6a22904a1b761c29a73ed (patch)
treee87ef8b5806e1fb6918923aed24b577d3525c985
parent0423dff207367d6920e012cf68c3df8648f77fbe (diff)
SpatializerHelper: fix init of compatibility for attached devices
SpatializerHelper.init() is called when AudioService starts, but also after each audioserver restart. After evaluating the transaural/binaural capabilities of the spatializer effect, the associated devices were added to the list of compatible devices regardless of whether they were already present, this was causing duplicated entries in the list. Also avoid always setting the enabled field in the list of compatible devices to true if the device was already in the list. Bug: 230871496 Test: repro in bug Change-Id: If76658677b44d22414fa393208b69d8ec82592fd
-rw-r--r--services/core/java/com/android/server/audio/SpatializerHelper.java40
1 files changed, 30 insertions, 10 deletions
diff --git a/services/core/java/com/android/server/audio/SpatializerHelper.java b/services/core/java/com/android/server/audio/SpatializerHelper.java
index 04fcda7835fa..122a950e4fd3 100644
--- a/services/core/java/com/android/server/audio/SpatializerHelper.java
+++ b/services/core/java/com/android/server/audio/SpatializerHelper.java
@@ -242,15 +242,19 @@ public class SpatializerHelper {
mSACapableDeviceTypes.add(SPAT_MODE_FOR_DEVICE_TYPE.keyAt(i));
}
}
+ // for both transaural / binaural, we are not forcing enablement as the init() method
+ // could have been called another time after boot in case of audioserver restart
if (mTransauralSupported) {
// TODO deal with persisted values
- mSADevices.add(
- new SADeviceState(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, null));
+ addCompatibleAudioDevice(
+ new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_SPEAKER, ""),
+ false /*forceEnable*/);
}
if (mBinauralSupported) {
// TODO deal with persisted values
- mSADevices.add(
- new SADeviceState(AudioDeviceInfo.TYPE_WIRED_HEADPHONES, null));
+ addCompatibleAudioDevice(
+ new AudioDeviceAttributes(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE, ""),
+ false /*forceEnable*/);
}
// TODO read persisted states
} catch (RemoteException e) {
@@ -461,6 +465,20 @@ public class SpatializerHelper {
}
synchronized void addCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada) {
+ addCompatibleAudioDevice(ada, true /*forceEnable*/);
+ }
+
+ /**
+ * Add the given device to the list of devices for which spatial audio will be available
+ * (== possible).
+ * @param ada the compatible device
+ * @param forceEnable if true, spatial audio is enabled for this device, regardless of whether
+ * this device was already in the list. If false, the enabled field is only
+ * set to true if the device is added to the list, otherwise, if already
+ * present, the setting is left untouched.
+ */
+ private void addCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada,
+ boolean forceEnable) {
loglogi("addCompatibleAudioDevice: dev=" + ada);
final int deviceType = ada.getType();
final boolean wireless = isWireless(deviceType);
@@ -471,7 +489,9 @@ public class SpatializerHelper {
&& (wireless && ada.getAddress().equals(deviceState.mDeviceAddress))
|| !wireless) {
isInList = true;
- deviceState.mEnabled = true;
+ if (forceEnable) {
+ deviceState.mEnabled = true;
+ }
break;
}
}
@@ -508,7 +528,7 @@ public class SpatializerHelper {
private synchronized Pair<Boolean, Boolean> evaluateState(AudioDeviceAttributes ada) {
// if not a wireless device, this value will be overwritten to map the type
// to TYPE_BUILTIN_SPEAKER or TYPE_WIRED_HEADPHONES
- int deviceType = ada.getType();
+ @AudioDeviceInfo.AudioDeviceType int deviceType = ada.getType();
final boolean wireless = isWireless(deviceType);
// if not a wireless device: find if media device is in the speaker, wired headphones
@@ -1468,13 +1488,13 @@ public class SpatializerHelper {
}
private static final class SADeviceState {
- final int mDeviceType;
+ final @AudioDeviceInfo.AudioDeviceType int mDeviceType;
final @Nullable String mDeviceAddress; // non-null for wireless devices
boolean mEnabled = true; // by default, SA is enabled on any device
boolean mHasHeadTracker = false;
boolean mHeadTrackerEnabled = true; // by default, if head tracker is present, use it
- SADeviceState(int deviceType, @Nullable String address) {
+ SADeviceState(@AudioDeviceInfo.AudioDeviceType int deviceType, @Nullable String address) {
mDeviceType = deviceType;
mDeviceAddress = address;
}
@@ -1505,7 +1525,7 @@ public class SpatializerHelper {
}
}
- private static boolean isWireless(int deviceType) {
+ private static boolean isWireless(@AudioDeviceInfo.AudioDeviceType int deviceType) {
for (int type : WIRELESS_TYPES) {
if (type == deviceType) {
return true;
@@ -1514,7 +1534,7 @@ public class SpatializerHelper {
return false;
}
- private static boolean isWirelessSpeaker(int deviceType) {
+ private static boolean isWirelessSpeaker(@AudioDeviceInfo.AudioDeviceType int deviceType) {
for (int type : WIRELESS_SPEAKER_TYPES) {
if (type == deviceType) {
return true;