Loading services/core/java/com/android/server/audio/AudioService.java +29 −1 Original line number Diff line number Diff line Loading @@ -346,6 +346,8 @@ public class AudioService extends IAudioService.Stub private static final int MSG_REMOVE_ASSISTANT_SERVICE_UID = 45; private static final int MSG_UPDATE_ACTIVE_ASSISTANT_SERVICE_UID = 46; private static final int MSG_DISPATCH_DEVICE_VOLUME_BEHAVIOR = 47; private static final int MSG_ROTATION_UPDATE = 48; private static final int MSG_FOLD_UPDATE = 49; // start of messages handled under wakelock // these messages can only be queued, i.e. sent with queueMsgUnderWakeLock(), Loading Loading @@ -1214,7 +1216,9 @@ public class AudioService extends IAudioService.Stub intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); if (mMonitorRotation) { RotationHelper.init(mContext, mAudioHandler); RotationHelper.init(mContext, mAudioHandler, rotationParam -> onRotationUpdate(rotationParam), foldParam -> onFoldUpdate(foldParam)); } intentFilter.addAction(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); Loading Loading @@ -1360,6 +1364,20 @@ public class AudioService extends IAudioService.Stub checkMuteAwaitConnection(); } //----------------------------------------------------------------- // rotation/fold updates coming from RotationHelper void onRotationUpdate(String rotationParameter) { // use REPLACE as only the last rotation matters sendMsg(mAudioHandler, MSG_ROTATION_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0, /*obj*/ rotationParameter, /*delay*/ 0); } void onFoldUpdate(String foldParameter) { // use REPLACE as only the last fold state matters sendMsg(mAudioHandler, MSG_FOLD_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0, /*obj*/ foldParameter, /*delay*/ 0); } //----------------------------------------------------------------- // monitoring requests for volume range initialization @Override // AudioSystemAdapter.OnVolRangeInitRequestListener Loading Loading @@ -8280,6 +8298,16 @@ public class AudioService extends IAudioService.Stub case MSG_DISPATCH_DEVICE_VOLUME_BEHAVIOR: dispatchDeviceVolumeBehavior((AudioDeviceAttributes) msg.obj, msg.arg1); break; case MSG_ROTATION_UPDATE: // rotation parameter format: "rotation=x" where x is one of 0, 90, 180, 270 mAudioSystem.setParameters((String) msg.obj); break; case MSG_FOLD_UPDATE: // fold parameter format: "device_folded=x" where x is one of on, off mAudioSystem.setParameters((String) msg.obj); break; } } } Loading services/core/java/com/android/server/audio/RotationHelper.java +23 −8 Original line number Diff line number Diff line Loading @@ -21,13 +21,14 @@ import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateManager.FoldStateListener; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManagerGlobal; import android.media.AudioSystem; import android.os.Handler; import android.os.HandlerExecutor; import android.util.Log; import android.view.Display; import android.view.Surface; import java.util.function.Consumer; /** * Class to handle device rotation events for AudioService, and forward device rotation * and folded state to the audio HALs through AudioSystem. Loading @@ -53,6 +54,10 @@ class RotationHelper { private static AudioDisplayListener sDisplayListener; private static FoldStateListener sFoldStateListener; /** callback to send rotation updates to AudioSystem */ private static Consumer<String> sRotationUpdateCb; /** callback to send folded state updates to AudioSystem */ private static Consumer<String> sFoldUpdateCb; private static final Object sRotationLock = new Object(); private static final Object sFoldStateLock = new Object(); Loading @@ -67,13 +72,16 @@ class RotationHelper { * - sDisplayListener != null * - sContext != null */ static void init(Context context, Handler handler) { static void init(Context context, Handler handler, Consumer<String> rotationUpdateCb, Consumer<String> foldUpdateCb) { if (context == null) { throw new IllegalArgumentException("Invalid null context"); } sContext = context; sHandler = handler; sDisplayListener = new AudioDisplayListener(); sRotationUpdateCb = rotationUpdateCb; sFoldUpdateCb = foldUpdateCb; enable(); } Loading Loading @@ -115,21 +123,26 @@ class RotationHelper { if (DEBUG_ROTATION) { Log.i(TAG, "publishing device rotation =" + rotation + " (x90deg)"); } String rotationParam; switch (rotation) { case Surface.ROTATION_0: AudioSystem.setParameters("rotation=0"); rotationParam = "rotation=0"; break; case Surface.ROTATION_90: AudioSystem.setParameters("rotation=90"); rotationParam = "rotation=90"; break; case Surface.ROTATION_180: AudioSystem.setParameters("rotation=180"); rotationParam = "rotation=180"; break; case Surface.ROTATION_270: AudioSystem.setParameters("rotation=270"); rotationParam = "rotation=270"; break; default: Log.e(TAG, "Unknown device rotation"); rotationParam = null; } if (rotationParam != null) { sRotationUpdateCb.accept(rotationParam); } } Loading @@ -140,11 +153,13 @@ class RotationHelper { synchronized (sFoldStateLock) { if (sDeviceFold != newFolded) { sDeviceFold = newFolded; String foldParam; if (newFolded) { AudioSystem.setParameters("device_folded=on"); foldParam = "device_folded=on"; } else { AudioSystem.setParameters("device_folded=off"); foldParam = "device_folded=off"; } sFoldUpdateCb.accept(foldParam); } } } Loading Loading
services/core/java/com/android/server/audio/AudioService.java +29 −1 Original line number Diff line number Diff line Loading @@ -346,6 +346,8 @@ public class AudioService extends IAudioService.Stub private static final int MSG_REMOVE_ASSISTANT_SERVICE_UID = 45; private static final int MSG_UPDATE_ACTIVE_ASSISTANT_SERVICE_UID = 46; private static final int MSG_DISPATCH_DEVICE_VOLUME_BEHAVIOR = 47; private static final int MSG_ROTATION_UPDATE = 48; private static final int MSG_FOLD_UPDATE = 49; // start of messages handled under wakelock // these messages can only be queued, i.e. sent with queueMsgUnderWakeLock(), Loading Loading @@ -1214,7 +1216,9 @@ public class AudioService extends IAudioService.Stub intentFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); if (mMonitorRotation) { RotationHelper.init(mContext, mAudioHandler); RotationHelper.init(mContext, mAudioHandler, rotationParam -> onRotationUpdate(rotationParam), foldParam -> onFoldUpdate(foldParam)); } intentFilter.addAction(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); Loading Loading @@ -1360,6 +1364,20 @@ public class AudioService extends IAudioService.Stub checkMuteAwaitConnection(); } //----------------------------------------------------------------- // rotation/fold updates coming from RotationHelper void onRotationUpdate(String rotationParameter) { // use REPLACE as only the last rotation matters sendMsg(mAudioHandler, MSG_ROTATION_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0, /*obj*/ rotationParameter, /*delay*/ 0); } void onFoldUpdate(String foldParameter) { // use REPLACE as only the last fold state matters sendMsg(mAudioHandler, MSG_FOLD_UPDATE, SENDMSG_REPLACE, /*arg1*/ 0, /*arg2*/ 0, /*obj*/ foldParameter, /*delay*/ 0); } //----------------------------------------------------------------- // monitoring requests for volume range initialization @Override // AudioSystemAdapter.OnVolRangeInitRequestListener Loading Loading @@ -8280,6 +8298,16 @@ public class AudioService extends IAudioService.Stub case MSG_DISPATCH_DEVICE_VOLUME_BEHAVIOR: dispatchDeviceVolumeBehavior((AudioDeviceAttributes) msg.obj, msg.arg1); break; case MSG_ROTATION_UPDATE: // rotation parameter format: "rotation=x" where x is one of 0, 90, 180, 270 mAudioSystem.setParameters((String) msg.obj); break; case MSG_FOLD_UPDATE: // fold parameter format: "device_folded=x" where x is one of on, off mAudioSystem.setParameters((String) msg.obj); break; } } } Loading
services/core/java/com/android/server/audio/RotationHelper.java +23 −8 Original line number Diff line number Diff line Loading @@ -21,13 +21,14 @@ import android.hardware.devicestate.DeviceStateManager; import android.hardware.devicestate.DeviceStateManager.FoldStateListener; import android.hardware.display.DisplayManager; import android.hardware.display.DisplayManagerGlobal; import android.media.AudioSystem; import android.os.Handler; import android.os.HandlerExecutor; import android.util.Log; import android.view.Display; import android.view.Surface; import java.util.function.Consumer; /** * Class to handle device rotation events for AudioService, and forward device rotation * and folded state to the audio HALs through AudioSystem. Loading @@ -53,6 +54,10 @@ class RotationHelper { private static AudioDisplayListener sDisplayListener; private static FoldStateListener sFoldStateListener; /** callback to send rotation updates to AudioSystem */ private static Consumer<String> sRotationUpdateCb; /** callback to send folded state updates to AudioSystem */ private static Consumer<String> sFoldUpdateCb; private static final Object sRotationLock = new Object(); private static final Object sFoldStateLock = new Object(); Loading @@ -67,13 +72,16 @@ class RotationHelper { * - sDisplayListener != null * - sContext != null */ static void init(Context context, Handler handler) { static void init(Context context, Handler handler, Consumer<String> rotationUpdateCb, Consumer<String> foldUpdateCb) { if (context == null) { throw new IllegalArgumentException("Invalid null context"); } sContext = context; sHandler = handler; sDisplayListener = new AudioDisplayListener(); sRotationUpdateCb = rotationUpdateCb; sFoldUpdateCb = foldUpdateCb; enable(); } Loading Loading @@ -115,21 +123,26 @@ class RotationHelper { if (DEBUG_ROTATION) { Log.i(TAG, "publishing device rotation =" + rotation + " (x90deg)"); } String rotationParam; switch (rotation) { case Surface.ROTATION_0: AudioSystem.setParameters("rotation=0"); rotationParam = "rotation=0"; break; case Surface.ROTATION_90: AudioSystem.setParameters("rotation=90"); rotationParam = "rotation=90"; break; case Surface.ROTATION_180: AudioSystem.setParameters("rotation=180"); rotationParam = "rotation=180"; break; case Surface.ROTATION_270: AudioSystem.setParameters("rotation=270"); rotationParam = "rotation=270"; break; default: Log.e(TAG, "Unknown device rotation"); rotationParam = null; } if (rotationParam != null) { sRotationUpdateCb.accept(rotationParam); } } Loading @@ -140,11 +153,13 @@ class RotationHelper { synchronized (sFoldStateLock) { if (sDeviceFold != newFolded) { sDeviceFold = newFolded; String foldParam; if (newFolded) { AudioSystem.setParameters("device_folded=on"); foldParam = "device_folded=on"; } else { AudioSystem.setParameters("device_folded=off"); foldParam = "device_folded=off"; } sFoldUpdateCb.accept(foldParam); } } } Loading