Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9bc3b098 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

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
parent c850d2b8
Loading
Loading
Loading
Loading
+6 −39
Original line number Diff line number Diff line
@@ -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);
+6 −5
Original line number Diff line number Diff line
@@ -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) {