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

Commit b6cbebf3 authored by Vlad Popa's avatar Vlad Popa
Browse files

Filtering the compatible spatial audio devices

Before the refactoring to AdiDeviceState we were only storing the
spatial audio compatible devices in the chached list. Now we need to
filter for the ones that are compatible during lookups.

Test: atest SpatializerHelperTest
Bug: 297265575
Change-Id: Iad4b779b0b51a98009d22b0f268dec13fdf06ea6
parent 8f662891
Loading
Loading
Loading
Loading
+25 −14
Original line number Original line Diff line number Diff line
@@ -540,7 +540,7 @@ public class SpatializerHelper {
            return;
            return;
        }
        }
        loglogi("addCompatibleAudioDevice: dev=" + ada);
        loglogi("addCompatibleAudioDevice: dev=" + ada);
        final AdiDeviceState deviceState = findDeviceStateForAudioDeviceAttributes(ada);
        final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada);
        initSAState(deviceState);
        initSAState(deviceState);
        AdiDeviceState updatedDevice = null; // non-null on update.
        AdiDeviceState updatedDevice = null; // non-null on update.
        if (deviceState != null) {
        if (deviceState != null) {
@@ -610,7 +610,7 @@ public class SpatializerHelper {
    synchronized void removeCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada) {
    synchronized void removeCompatibleAudioDevice(@NonNull AudioDeviceAttributes ada) {
        loglogi("removeCompatibleAudioDevice: dev=" + ada);
        loglogi("removeCompatibleAudioDevice: dev=" + ada);


        final AdiDeviceState deviceState = findDeviceStateForAudioDeviceAttributes(ada);
        final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada);
        if (deviceState != null && deviceState.isSAEnabled()) {
        if (deviceState != null && deviceState.isSAEnabled()) {
            deviceState.setSAEnabled(false);
            deviceState.setSAEnabled(false);
            onRoutingUpdated();
            onRoutingUpdated();
@@ -637,14 +637,25 @@ public class SpatializerHelper {
    }
    }


    /**
    /**
     * Returns the Spatial Audio device state for an audio device attributes
     * Returns the audio device state for the audio device attributes in case
     * or null if it does not exist.
     * spatial audio is supported or null otherwise.
     */
     */
    @GuardedBy("this")
    @GuardedBy("this")
    @Nullable
    @Nullable
    private AdiDeviceState findDeviceStateForAudioDeviceAttributes(AudioDeviceAttributes ada) {
    private AdiDeviceState findSACompatibleDeviceStateForAudioDeviceAttributes(
        return mDeviceBroker.findDeviceStateForAudioDeviceAttributes(ada,
            AudioDeviceAttributes ada) {
        final AdiDeviceState deviceState =
                mDeviceBroker.findDeviceStateForAudioDeviceAttributes(ada,
                        getCanonicalDeviceType(ada.getType(), ada.getInternalType()));
                        getCanonicalDeviceType(ada.getType(), ada.getInternalType()));
        if (deviceState == null) {
            return null;
        }

        if (!isSADevice(deviceState)) {
            return null;
        }

        return deviceState;
    }
    }


    /**
    /**
@@ -666,7 +677,7 @@ public class SpatializerHelper {
            Log.e(TAG, "no spatialization mode found for device type:" + deviceType);
            Log.e(TAG, "no spatialization mode found for device type:" + deviceType);
            return new Pair<>(false, false);
            return new Pair<>(false, false);
        }
        }
        final AdiDeviceState deviceState = findDeviceStateForAudioDeviceAttributes(ada);
        final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada);
        if (deviceState == null) {
        if (deviceState == null) {
            // no matching device state?
            // no matching device state?
            Log.i(TAG, "no spatialization device state found for Spatial Audio device:" + ada);
            Log.i(TAG, "no spatialization device state found for Spatial Audio device:" + ada);
@@ -680,7 +691,7 @@ public class SpatializerHelper {
        if (!isDeviceCompatibleWithSpatializationModes(ada)) {
        if (!isDeviceCompatibleWithSpatializationModes(ada)) {
            return;
            return;
        }
        }
        if (findDeviceStateForAudioDeviceAttributes(ada) == null) {
        if (findSACompatibleDeviceStateForAudioDeviceAttributes(ada) == null) {
            // wireless device types should be canonical, but we translate to be sure.
            // wireless device types should be canonical, but we translate to be sure.
            final int canonicalDeviceType = getCanonicalDeviceType(ada.getType(),
            final int canonicalDeviceType = getCanonicalDeviceType(ada.getType(),
                    ada.getInternalType());
                    ada.getInternalType());
@@ -734,7 +745,7 @@ public class SpatializerHelper {
        if (ada.getRole() != AudioDeviceAttributes.ROLE_OUTPUT) {
        if (ada.getRole() != AudioDeviceAttributes.ROLE_OUTPUT) {
            return false;
            return false;
        }
        }
        return findDeviceStateForAudioDeviceAttributes(ada) != null;
        return findSACompatibleDeviceStateForAudioDeviceAttributes(ada) != null;
    }
    }


    private synchronized boolean canBeSpatializedOnDevice(@NonNull AudioAttributes attributes,
    private synchronized boolean canBeSpatializedOnDevice(@NonNull AudioAttributes attributes,
@@ -1150,7 +1161,7 @@ public class SpatializerHelper {
            Log.v(TAG, "no headtracking support, ignoring setHeadTrackerEnabled to " + enabled
            Log.v(TAG, "no headtracking support, ignoring setHeadTrackerEnabled to " + enabled
                    + " for " + ada);
                    + " for " + ada);
        }
        }
        final AdiDeviceState deviceState = findDeviceStateForAudioDeviceAttributes(ada);
        final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada);
        if (deviceState == null) return;
        if (deviceState == null) return;
        if (!deviceState.hasHeadTracker()) {
        if (!deviceState.hasHeadTracker()) {
            Log.e(TAG, "Called setHeadTrackerEnabled enabled:" + enabled
            Log.e(TAG, "Called setHeadTrackerEnabled enabled:" + enabled
@@ -1183,7 +1194,7 @@ public class SpatializerHelper {
            Log.v(TAG, "no headtracking support, hasHeadTracker always false for " + ada);
            Log.v(TAG, "no headtracking support, hasHeadTracker always false for " + ada);
            return false;
            return false;
        }
        }
        final AdiDeviceState deviceState = findDeviceStateForAudioDeviceAttributes(ada);
        final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada);
        return deviceState != null && deviceState.hasHeadTracker();
        return deviceState != null && deviceState.hasHeadTracker();
    }
    }


@@ -1197,7 +1208,7 @@ public class SpatializerHelper {
            Log.v(TAG, "no headtracking support, setHasHeadTracker always false for " + ada);
            Log.v(TAG, "no headtracking support, setHasHeadTracker always false for " + ada);
            return false;
            return false;
        }
        }
        final AdiDeviceState deviceState = findDeviceStateForAudioDeviceAttributes(ada);
        final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada);
        if (deviceState != null) {
        if (deviceState != null) {
            if (!deviceState.hasHeadTracker()) {
            if (!deviceState.hasHeadTracker()) {
                deviceState.setHasHeadTracker(true);
                deviceState.setHasHeadTracker(true);
@@ -1215,7 +1226,7 @@ public class SpatializerHelper {
            Log.v(TAG, "no headtracking support, isHeadTrackerEnabled always false for " + ada);
            Log.v(TAG, "no headtracking support, isHeadTrackerEnabled always false for " + ada);
            return false;
            return false;
        }
        }
        final AdiDeviceState deviceState = findDeviceStateForAudioDeviceAttributes(ada);
        final AdiDeviceState deviceState = findSACompatibleDeviceStateForAudioDeviceAttributes(ada);
        return deviceState != null
        return deviceState != null
                && deviceState.hasHeadTracker() && deviceState.isHeadTrackerEnabled();
                && deviceState.hasHeadTracker() && deviceState.isHeadTrackerEnabled();
    }
    }