Loading services/core/java/com/android/server/audio/AudioService.java +12 −5 Original line number Diff line number Diff line Loading @@ -1352,8 +1352,8 @@ public class AudioService extends IAudioService.Stub intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); if (mMonitorRotation) { RotationHelper.init(mContext, mAudioHandler, rotationParam -> onRotationUpdate(rotationParam), foldParam -> onFoldUpdate(foldParam)); rotation -> onRotationUpdate(rotation), foldState -> onFoldStateUpdate(foldState)); } intentFilter.addAction(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); Loading Loading @@ -1502,16 +1502,20 @@ public class AudioService extends IAudioService.Stub //----------------------------------------------------------------- // rotation/fold updates coming from RotationHelper void onRotationUpdate(String rotationParameter) { void onRotationUpdate(Integer rotation) { mSpatializerHelper.setDisplayOrientation((float) (rotation * Math.PI / 180.)); // use REPLACE as only the last rotation matters final String rotationParameter = "rotation=" + rotation; sendMsg(mAudioHandler, MSG_ROTATION_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0, /*obj*/ rotationParameter, /*delay*/ 0); } void onFoldUpdate(String foldParameter) { void onFoldStateUpdate(Boolean foldState) { mSpatializerHelper.setFoldState(foldState); // use REPLACE as only the last fold state matters final String foldStateParameter = "device_folded=" + (foldState ? "on" : "off"); sendMsg(mAudioHandler, MSG_FOLD_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0, /*obj*/ foldParameter, /*delay*/ 0); /*obj*/ foldStateParameter, /*delay*/ 0); } //----------------------------------------------------------------- Loading Loading @@ -1726,6 +1730,9 @@ public class AudioService extends IAudioService.Stub mSpatializerHelper.reset(/* featureEnabled */ mHasSpatializerEffect); // Restore rotation information. RotationHelper.forceUpdate(); onIndicateSystemReady(); // indicate the end of reconfiguration phase to audio HAL AudioSystem.setParameters("restarting=false"); Loading services/core/java/com/android/server/audio/RotationHelper.java +38 −29 Original line number Diff line number Diff line Loading @@ -55,14 +55,14 @@ class RotationHelper { private static AudioDisplayListener sDisplayListener; private static FoldStateListener sFoldStateListener; /** callback to send rotation updates to AudioSystem */ private static Consumer<String> sRotationUpdateCb; private static Consumer<Integer> sRotationCallback; /** callback to send folded state updates to AudioSystem */ private static Consumer<String> sFoldUpdateCb; private static Consumer<Boolean> sFoldStateCallback; private static final Object sRotationLock = new Object(); private static final Object sFoldStateLock = new Object(); private static int sDeviceRotation = Surface.ROTATION_0; // R/W synchronized on sRotationLock private static boolean sDeviceFold = true; // R/W synchronized on sFoldStateLock private static Integer sRotation = null; // R/W synchronized on sRotationLock private static Boolean sFoldState = null; // R/W synchronized on sFoldStateLock private static Context sContext; private static Handler sHandler; Loading @@ -73,15 +73,15 @@ class RotationHelper { * - sContext != null */ static void init(Context context, Handler handler, Consumer<String> rotationUpdateCb, Consumer<String> foldUpdateCb) { Consumer<Integer> rotationCallback, Consumer<Boolean> foldStateCallback) { if (context == null) { throw new IllegalArgumentException("Invalid null context"); } sContext = context; sHandler = handler; sDisplayListener = new AudioDisplayListener(); sRotationUpdateCb = rotationUpdateCb; sFoldUpdateCb = foldUpdateCb; sRotationCallback = rotationCallback; sFoldStateCallback = foldStateCallback; enable(); } Loading Loading @@ -112,9 +112,9 @@ class RotationHelper { int newRotation = DisplayManagerGlobal.getInstance() .getDisplayInfo(Display.DEFAULT_DISPLAY).rotation; synchronized(sRotationLock) { if (newRotation != sDeviceRotation) { sDeviceRotation = newRotation; publishRotation(sDeviceRotation); if (sRotation == null || sRotation != newRotation) { sRotation = newRotation; publishRotation(sRotation); } } } Loading @@ -123,43 +123,52 @@ class RotationHelper { if (DEBUG_ROTATION) { Log.i(TAG, "publishing device rotation =" + rotation + " (x90deg)"); } String rotationParam; int rotationDegrees; switch (rotation) { case Surface.ROTATION_0: rotationParam = "rotation=0"; rotationDegrees = 0; break; case Surface.ROTATION_90: rotationParam = "rotation=90"; rotationDegrees = 90; break; case Surface.ROTATION_180: rotationParam = "rotation=180"; rotationDegrees = 180; break; case Surface.ROTATION_270: rotationParam = "rotation=270"; rotationDegrees = 270; break; default: Log.e(TAG, "Unknown device rotation"); rotationParam = null; rotationDegrees = -1; } if (rotationParam != null) { sRotationUpdateCb.accept(rotationParam); if (rotationDegrees != -1) { sRotationCallback.accept(rotationDegrees); } } /** * publish the change of device folded state if any. */ static void updateFoldState(boolean newFolded) { static void updateFoldState(boolean foldState) { synchronized (sFoldStateLock) { if (sDeviceFold != newFolded) { sDeviceFold = newFolded; String foldParam; if (newFolded) { foldParam = "device_folded=on"; } else { foldParam = "device_folded=off"; } sFoldUpdateCb.accept(foldParam); if (sFoldState == null || sFoldState != foldState) { sFoldState = foldState; sFoldStateCallback.accept(foldState); } } } /** * forceUpdate is called when audioserver restarts. */ static void forceUpdate() { synchronized (sRotationLock) { sRotation = null; } updateOrientation(); // We will get at least one orientation update now. synchronized (sFoldStateLock) { if (sFoldState != null) { sFoldStateCallback.accept(sFoldState); } } } Loading services/core/java/com/android/server/audio/SpatializerHelper.java +33 −7 Original line number Diff line number Diff line Loading @@ -1063,7 +1063,7 @@ public class SpatializerHelper { if (transform.length != 6) { throw new IllegalArgumentException("invalid array size" + transform.length); } if (!checkSpatForHeadTracking("setGlobalTransform")) { if (!checkSpatializerForHeadTracking("setGlobalTransform")) { return; } try { Loading @@ -1074,7 +1074,7 @@ public class SpatializerHelper { } synchronized void recenterHeadTracker() { if (!checkSpatForHeadTracking("recenterHeadTracker")) { if (!checkSpatializerForHeadTracking("recenterHeadTracker")) { return; } try { Loading @@ -1084,8 +1084,30 @@ public class SpatializerHelper { } } synchronized void setDisplayOrientation(float displayOrientation) { if (!checkSpatializer("setDisplayOrientation")) { return; } try { mSpat.setDisplayOrientation(displayOrientation); } catch (RemoteException e) { Log.e(TAG, "Error calling setDisplayOrientation", e); } } synchronized void setFoldState(boolean folded) { if (!checkSpatializer("setFoldState")) { return; } try { mSpat.setFoldState(folded); } catch (RemoteException e) { Log.e(TAG, "Error calling setFoldState", e); } } synchronized void setDesiredHeadTrackingMode(@Spatializer.HeadTrackingModeSet int mode) { if (!checkSpatForHeadTracking("setDesiredHeadTrackingMode")) { if (!checkSpatializerForHeadTracking("setDesiredHeadTrackingMode")) { return; } if (mode != Spatializer.HEAD_TRACKING_MODE_DISABLED) { Loading Loading @@ -1178,7 +1200,7 @@ public class SpatializerHelper { return mHeadTrackerAvailable; } private boolean checkSpatForHeadTracking(String funcName) { private boolean checkSpatializer(String funcName) { switch (mState) { case STATE_UNINITIALIZED: case STATE_NOT_SUPPORTED: Loading @@ -1189,14 +1211,18 @@ public class SpatializerHelper { case STATE_ENABLED_AVAILABLE: if (mSpat == null) { // try to recover by resetting the native spatializer state Log.e(TAG, "checkSpatForHeadTracking(): " + "native spatializer should not be null in state: " + mState); Log.e(TAG, "checkSpatializer(): called from " + funcName + "(), native spatializer should not be null in state: " + mState); postReset(); return false; } break; } return mIsHeadTrackingSupported; return true; } private boolean checkSpatializerForHeadTracking(String funcName) { return checkSpatializer(funcName) && mIsHeadTrackingSupported; } private void dispatchActualHeadTrackingMode(int newMode) { Loading Loading
services/core/java/com/android/server/audio/AudioService.java +12 −5 Original line number Diff line number Diff line Loading @@ -1352,8 +1352,8 @@ public class AudioService extends IAudioService.Stub intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); if (mMonitorRotation) { RotationHelper.init(mContext, mAudioHandler, rotationParam -> onRotationUpdate(rotationParam), foldParam -> onFoldUpdate(foldParam)); rotation -> onRotationUpdate(rotation), foldState -> onFoldStateUpdate(foldState)); } intentFilter.addAction(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); Loading Loading @@ -1502,16 +1502,20 @@ public class AudioService extends IAudioService.Stub //----------------------------------------------------------------- // rotation/fold updates coming from RotationHelper void onRotationUpdate(String rotationParameter) { void onRotationUpdate(Integer rotation) { mSpatializerHelper.setDisplayOrientation((float) (rotation * Math.PI / 180.)); // use REPLACE as only the last rotation matters final String rotationParameter = "rotation=" + rotation; sendMsg(mAudioHandler, MSG_ROTATION_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0, /*obj*/ rotationParameter, /*delay*/ 0); } void onFoldUpdate(String foldParameter) { void onFoldStateUpdate(Boolean foldState) { mSpatializerHelper.setFoldState(foldState); // use REPLACE as only the last fold state matters final String foldStateParameter = "device_folded=" + (foldState ? "on" : "off"); sendMsg(mAudioHandler, MSG_FOLD_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0, /*obj*/ foldParameter, /*delay*/ 0); /*obj*/ foldStateParameter, /*delay*/ 0); } //----------------------------------------------------------------- Loading Loading @@ -1726,6 +1730,9 @@ public class AudioService extends IAudioService.Stub mSpatializerHelper.reset(/* featureEnabled */ mHasSpatializerEffect); // Restore rotation information. RotationHelper.forceUpdate(); onIndicateSystemReady(); // indicate the end of reconfiguration phase to audio HAL AudioSystem.setParameters("restarting=false"); Loading
services/core/java/com/android/server/audio/RotationHelper.java +38 −29 Original line number Diff line number Diff line Loading @@ -55,14 +55,14 @@ class RotationHelper { private static AudioDisplayListener sDisplayListener; private static FoldStateListener sFoldStateListener; /** callback to send rotation updates to AudioSystem */ private static Consumer<String> sRotationUpdateCb; private static Consumer<Integer> sRotationCallback; /** callback to send folded state updates to AudioSystem */ private static Consumer<String> sFoldUpdateCb; private static Consumer<Boolean> sFoldStateCallback; private static final Object sRotationLock = new Object(); private static final Object sFoldStateLock = new Object(); private static int sDeviceRotation = Surface.ROTATION_0; // R/W synchronized on sRotationLock private static boolean sDeviceFold = true; // R/W synchronized on sFoldStateLock private static Integer sRotation = null; // R/W synchronized on sRotationLock private static Boolean sFoldState = null; // R/W synchronized on sFoldStateLock private static Context sContext; private static Handler sHandler; Loading @@ -73,15 +73,15 @@ class RotationHelper { * - sContext != null */ static void init(Context context, Handler handler, Consumer<String> rotationUpdateCb, Consumer<String> foldUpdateCb) { Consumer<Integer> rotationCallback, Consumer<Boolean> foldStateCallback) { if (context == null) { throw new IllegalArgumentException("Invalid null context"); } sContext = context; sHandler = handler; sDisplayListener = new AudioDisplayListener(); sRotationUpdateCb = rotationUpdateCb; sFoldUpdateCb = foldUpdateCb; sRotationCallback = rotationCallback; sFoldStateCallback = foldStateCallback; enable(); } Loading Loading @@ -112,9 +112,9 @@ class RotationHelper { int newRotation = DisplayManagerGlobal.getInstance() .getDisplayInfo(Display.DEFAULT_DISPLAY).rotation; synchronized(sRotationLock) { if (newRotation != sDeviceRotation) { sDeviceRotation = newRotation; publishRotation(sDeviceRotation); if (sRotation == null || sRotation != newRotation) { sRotation = newRotation; publishRotation(sRotation); } } } Loading @@ -123,43 +123,52 @@ class RotationHelper { if (DEBUG_ROTATION) { Log.i(TAG, "publishing device rotation =" + rotation + " (x90deg)"); } String rotationParam; int rotationDegrees; switch (rotation) { case Surface.ROTATION_0: rotationParam = "rotation=0"; rotationDegrees = 0; break; case Surface.ROTATION_90: rotationParam = "rotation=90"; rotationDegrees = 90; break; case Surface.ROTATION_180: rotationParam = "rotation=180"; rotationDegrees = 180; break; case Surface.ROTATION_270: rotationParam = "rotation=270"; rotationDegrees = 270; break; default: Log.e(TAG, "Unknown device rotation"); rotationParam = null; rotationDegrees = -1; } if (rotationParam != null) { sRotationUpdateCb.accept(rotationParam); if (rotationDegrees != -1) { sRotationCallback.accept(rotationDegrees); } } /** * publish the change of device folded state if any. */ static void updateFoldState(boolean newFolded) { static void updateFoldState(boolean foldState) { synchronized (sFoldStateLock) { if (sDeviceFold != newFolded) { sDeviceFold = newFolded; String foldParam; if (newFolded) { foldParam = "device_folded=on"; } else { foldParam = "device_folded=off"; } sFoldUpdateCb.accept(foldParam); if (sFoldState == null || sFoldState != foldState) { sFoldState = foldState; sFoldStateCallback.accept(foldState); } } } /** * forceUpdate is called when audioserver restarts. */ static void forceUpdate() { synchronized (sRotationLock) { sRotation = null; } updateOrientation(); // We will get at least one orientation update now. synchronized (sFoldStateLock) { if (sFoldState != null) { sFoldStateCallback.accept(sFoldState); } } } Loading
services/core/java/com/android/server/audio/SpatializerHelper.java +33 −7 Original line number Diff line number Diff line Loading @@ -1063,7 +1063,7 @@ public class SpatializerHelper { if (transform.length != 6) { throw new IllegalArgumentException("invalid array size" + transform.length); } if (!checkSpatForHeadTracking("setGlobalTransform")) { if (!checkSpatializerForHeadTracking("setGlobalTransform")) { return; } try { Loading @@ -1074,7 +1074,7 @@ public class SpatializerHelper { } synchronized void recenterHeadTracker() { if (!checkSpatForHeadTracking("recenterHeadTracker")) { if (!checkSpatializerForHeadTracking("recenterHeadTracker")) { return; } try { Loading @@ -1084,8 +1084,30 @@ public class SpatializerHelper { } } synchronized void setDisplayOrientation(float displayOrientation) { if (!checkSpatializer("setDisplayOrientation")) { return; } try { mSpat.setDisplayOrientation(displayOrientation); } catch (RemoteException e) { Log.e(TAG, "Error calling setDisplayOrientation", e); } } synchronized void setFoldState(boolean folded) { if (!checkSpatializer("setFoldState")) { return; } try { mSpat.setFoldState(folded); } catch (RemoteException e) { Log.e(TAG, "Error calling setFoldState", e); } } synchronized void setDesiredHeadTrackingMode(@Spatializer.HeadTrackingModeSet int mode) { if (!checkSpatForHeadTracking("setDesiredHeadTrackingMode")) { if (!checkSpatializerForHeadTracking("setDesiredHeadTrackingMode")) { return; } if (mode != Spatializer.HEAD_TRACKING_MODE_DISABLED) { Loading Loading @@ -1178,7 +1200,7 @@ public class SpatializerHelper { return mHeadTrackerAvailable; } private boolean checkSpatForHeadTracking(String funcName) { private boolean checkSpatializer(String funcName) { switch (mState) { case STATE_UNINITIALIZED: case STATE_NOT_SUPPORTED: Loading @@ -1189,14 +1211,18 @@ public class SpatializerHelper { case STATE_ENABLED_AVAILABLE: if (mSpat == null) { // try to recover by resetting the native spatializer state Log.e(TAG, "checkSpatForHeadTracking(): " + "native spatializer should not be null in state: " + mState); Log.e(TAG, "checkSpatializer(): called from " + funcName + "(), native spatializer should not be null in state: " + mState); postReset(); return false; } break; } return mIsHeadTrackingSupported; return true; } private boolean checkSpatializerForHeadTracking(String funcName) { return checkSpatializer(funcName) && mIsHeadTrackingSupported; } private void dispatchActualHeadTrackingMode(int newMode) { Loading