From 9bc3b0986f96c9ca5f532d6f1f39d9aac2a558f2 Mon Sep 17 00:00:00 2001 From: Jean-Michel Trivi Date: Fri, 1 Apr 2022 10:42:40 -0700 Subject: [PATCH] AudioService: SA feature enabled doesn't rely on global setting Unlike Android S, there is no more global toggle for spatial audio, whether the feature is enabled has become contextual based on the current routing. The fix consists in ignoring the persisted value for the feature (Settings.Secure.SPATIAL_AUDIO_ENABLED) and only rely on the effect availability for enabling the feature or not. Bug: 227774516 Test: adb shell dumpsys audio | grep -A 20 "Spatial audio" Change-Id: I4fb7b65b3bdc5cbefefcbc027e385917e2586e0f --- .../android/server/audio/AudioService.java | 45 +++---------------- .../server/audio/SpatializerHelper.java | 11 ++--- 2 files changed, 12 insertions(+), 44 deletions(-) diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index 517ff82d9fd28..1786bc5793854 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -340,7 +340,8 @@ public class AudioService extends IAudioService.Stub private static final int MSG_DISPATCH_AUDIO_MODE = 40; private static final int MSG_ROUTING_UPDATED = 41; private static final int MSG_INIT_HEADTRACKING_SENSORS = 42; - private static final int MSG_PERSIST_SPATIAL_AUDIO_ENABLED = 43; + // commented out for now, will be reused for other SA persisting + //private static final int MSG_PERSIST_SPATIAL_AUDIO_ENABLED = 43; private static final int MSG_ADD_ASSISTANT_SERVICE_UID = 44; private static final int MSG_REMOVE_ASSISTANT_SERVICE_UID = 45; private static final int MSG_UPDATE_ACTIVE_ASSISTANT_SERVICE_UID = 46; @@ -1543,9 +1544,7 @@ public class AudioService extends IAudioService.Stub } } - if (mHasSpatializerEffect) { - mSpatializerHelper.reset(/* featureEnabled */ isSpatialAudioEnabled()); - } + mSpatializerHelper.reset(/* featureEnabled */ mHasSpatializerEffect); onIndicateSystemReady(); // indicate the end of reconfiguration phase to audio HAL @@ -8114,9 +8113,7 @@ public class AudioService extends IAudioService.Stub case MSG_INIT_SPATIALIZER: mSpatializerHelper.init(/*effectExpected*/ mHasSpatializerEffect); - if (mHasSpatializerEffect) { - mSpatializerHelper.setFeatureEnabled(isSpatialAudioEnabled()); - } + mSpatializerHelper.setFeatureEnabled(mHasSpatializerEffect); mAudioEventWakeLock.release(); break; @@ -8257,10 +8254,6 @@ public class AudioService extends IAudioService.Stub onRoutingUpdatedFromAudioThread(); break; - case MSG_PERSIST_SPATIAL_AUDIO_ENABLED: - onPersistSpatialAudioEnabled(msg.arg1 == 1); - break; - case MSG_ADD_ASSISTANT_SERVICE_UID: onAddAssistantServiceUids(new int[]{msg.arg1}); break; @@ -8864,31 +8857,6 @@ public class AudioService extends IAudioService.Stub */ private static final boolean SPATIAL_AUDIO_ENABLED_DEFAULT = true; - /** - * persist in user settings whether the feature is enabled. - * Can change when {@link Spatializer#setEnabled(boolean)} is called and successfully - * changes the state of the feature - * @param featureEnabled - */ - void persistSpatialAudioEnabled(boolean featureEnabled) { - sendMsg(mAudioHandler, - MSG_PERSIST_SPATIAL_AUDIO_ENABLED, - SENDMSG_REPLACE, featureEnabled ? 1 : 0, 0, null, - /*delay ms*/ 100); - } - - void onPersistSpatialAudioEnabled(boolean enabled) { - mSettings.putSecureIntForUser(mContentResolver, - Settings.Secure.SPATIAL_AUDIO_ENABLED, enabled ? 1 : 0, - UserHandle.USER_CURRENT); - } - - boolean isSpatialAudioEnabled() { - return mSettings.getSecureIntForUser(mContentResolver, - Settings.Secure.SPATIAL_AUDIO_ENABLED, SPATIAL_AUDIO_ENABLED_DEFAULT ? 1 : 0, - UserHandle.USER_CURRENT) == 1; - } - private void enforceModifyDefaultAudioEffectsPermission() { if (mContext.checkCallingOrSelfPermission( android.Manifest.permission.MODIFY_DEFAULT_AUDIO_EFFECTS) @@ -9906,9 +9874,8 @@ public class AudioService extends IAudioService.Stub pw.println("\n"); pw.println("\nSpatial audio:"); - pw.println("mHasSpatializerEffect:" + mHasSpatializerEffect); - pw.println("isSpatializerEnabled:" + isSpatializerEnabled()); - pw.println("isSpatialAudioEnabled:" + isSpatialAudioEnabled()); + pw.println("mHasSpatializerEffect:" + mHasSpatializerEffect + " (effect present)"); + pw.println("isSpatializerEnabled:" + isSpatializerEnabled() + " (routing dependent)"); mSpatializerHelper.dump(pw); mAudioSystem.dump(pw); diff --git a/services/core/java/com/android/server/audio/SpatializerHelper.java b/services/core/java/com/android/server/audio/SpatializerHelper.java index 40a63504fb6bf..b027d72ab4dac 100644 --- a/services/core/java/com/android/server/audio/SpatializerHelper.java +++ b/services/core/java/com/android/server/audio/SpatializerHelper.java @@ -445,6 +445,7 @@ public class SpatializerHelper { synchronized void addCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada) { // TODO add log + Log.i(TAG, "addCompatibleAudioDevice: dev=" + ada); final int deviceType = ada.getType(); final boolean wireless = isWireless(deviceType); boolean updateRouting = false; @@ -468,13 +469,14 @@ public class SpatializerHelper { mSADevices.add(dev); updateRouting = true; } - if (updateRouting) { + //if (updateRouting) { onRoutingUpdated(); - } + //} } synchronized void removeCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada) { // TODO add log + Log.i(TAG, "removeCompatibleAudioDevice: dev=" + ada); final int deviceType = ada.getType(); final boolean wireless = isWireless(deviceType); boolean updateRouting = false; @@ -489,9 +491,9 @@ public class SpatializerHelper { break; } } - if (updateRouting) { + //###if (updateRouting) { onRoutingUpdated(); - } + //###} } /** @@ -747,7 +749,6 @@ public class SpatializerHelper { } } mStateCallbacks.finishBroadcast(); - mAudioService.persistSpatialAudioEnabled(featureEnabled); } private synchronized void setDispatchAvailableState(boolean available) {