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

Commit 511336f1 authored by Eric Laurent's avatar Eric Laurent
Browse files

audio: SpatializerHelper: fix exceptions when head tracking is not supported

Do not call head tracking APIs on native spatializer when it does not
support head tracking.

Bug: 224623509
Test: manual enabling/disabling of spatial audio
Change-Id: I3be6b3f05c9542404379a07f4fc734e45a75152a
Merged-In: I3be6b3f05c9542404379a07f4fc734e45a75152a
parent 7cc0fa7a
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ public class SpatializerHelper {
    private @Nullable SpatializerCallback mSpatCallback;
    private @Nullable SpatializerHeadTrackingCallback mSpatHeadTrackingCallback;
    private @Nullable HelperDynamicSensorCallback mDynSensorCallback;
    private boolean mIsHeadTrackingSupported = false;

    // default attributes and format that determine basic availability of spatialization
    private static final AudioAttributes DEFAULT_ATTRIBUTES = new AudioAttributes.Builder()
@@ -497,8 +498,9 @@ public class SpatializerHelper {
            mSpat = AudioSystem.getSpatializer(mSpatCallback);
            try {
                mSpat.setLevel((byte)  Spatializer.SPATIALIZER_IMMERSIVE_LEVEL_MULTICHANNEL);
                mIsHeadTrackingSupported = mSpat.isHeadTrackingSupported();
                //TODO: register heatracking callback only when sensors are registered
                if (mSpat.isHeadTrackingSupported()) {
                if (mIsHeadTrackingSupported) {
                    mSpat.registerHeadTrackingCallback(mSpatHeadTrackingCallback);
                }
            } catch (RemoteException e) {
@@ -516,11 +518,14 @@ public class SpatializerHelper {
        if (mSpat != null) {
            mSpatCallback = null;
            try {
                if (mIsHeadTrackingSupported) {
                    mSpat.registerHeadTrackingCallback(null);
                }
                mSpat.release();
            } catch (RemoteException e) {
                Log.e(TAG, "Can't set release spatializer cleanly", e);
            }
            mIsHeadTrackingSupported = false;
            mSpat = null;
        }
    }
@@ -687,7 +692,6 @@ public class SpatializerHelper {
                mDesiredHeadTrackingMode = mode;
                dispatchDesiredHeadTrackingMode(mode);
            }

        } catch (RemoteException e) {
            Log.e(TAG, "Error calling setDesiredHeadTrackingMode", e);
        }
@@ -708,7 +712,7 @@ public class SpatializerHelper {
                }
                break;
        }
        return true;
        return mIsHeadTrackingSupported;
    }

    private void dispatchActualHeadTrackingMode(int newMode) {
@@ -882,15 +886,10 @@ public class SpatializerHelper {
            Log.e(TAG, "not " + action + " sensors, null spatializer");
            return;
        }
        try {
            if (!mSpat.isHeadTrackingSupported()) {
        if (!mIsHeadTrackingSupported) {
            Log.e(TAG, "not " + action + " sensors, spatializer doesn't support headtracking");
            return;
        }
        } catch (RemoteException e) {
            Log.e(TAG, "not " + action + " sensors, error querying headtracking", e);
            return;
        }
        int headHandle = -1;
        int screenHandle = -1;
        if (init) {