From a4d5841eb188a639d43b70134dcaf600416111b5 Mon Sep 17 00:00:00 2001 From: Jasmine Cha Date: Fri, 20 Aug 2021 11:59:04 +0800 Subject: [PATCH] RotationHelper: send active displayId to audio HAL Send active displayId to audio HAL can improve sound quality in different postures for foldable devices. Bug: 197196724 Test: check parameters when folded/unfolded device Change-Id: I255122c93ccc93257848af61336026305b5a0d25 --- .../android/server/audio/RotationHelper.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/audio/RotationHelper.java b/services/core/java/com/android/server/audio/RotationHelper.java index ad7216600e616..872b1feb2d727 100644 --- a/services/core/java/com/android/server/audio/RotationHelper.java +++ b/services/core/java/com/android/server/audio/RotationHelper.java @@ -21,20 +21,26 @@ import android.hardware.display.DisplayManager; import android.media.AudioSystem; import android.os.Handler; import android.util.Log; +import android.view.Display; import android.view.Surface; import android.view.WindowManager; /** * Class to handle device rotation events for AudioService, and forward device rotation - * to the audio HALs through AudioSystem. + * and current active ID to the audio HALs through AudioSystem. * * The role of this class is to monitor device orientation changes, and upon rotation, * verify the UI orientation. In case of a change, send the new orientation, in increments * of 90deg, through AudioSystem. * + * Another role of this class is to track current active display ID changes. In case of a + * change, send the new active display ID through AudioSystem. + * * Note that even though we're responding to device orientation events, we always * query the display rotation so audio stays in sync with video/dialogs. This is * done with .getDefaultDisplay().getRotation() from WINDOW_SERVICE. + * + * We also monitor current display ID and audio is able to know which display is active. */ class RotationHelper { @@ -43,7 +49,9 @@ class RotationHelper { private static AudioDisplayListener sDisplayListener; private static final Object sRotationLock = new Object(); + private static final Object sActiveDisplayLock = new Object(); private static int sDeviceRotation = Surface.ROTATION_0; // R/W synchronized on sRotationLock + private static int sDisplayId = Display.DEFAULT_DISPLAY; // synchronized on sActiveDisplayLock private static Context sContext; private static Handler sHandler; @@ -111,6 +119,18 @@ class RotationHelper { } } + /** + * Query current display active id and publish the change if any. + */ + static void updateActiveDisplayId(int displayId) { + synchronized (sActiveDisplayLock) { + if (displayId != Display.DEFAULT_DISPLAY && sDisplayId != displayId) { + sDisplayId = displayId; + AudioSystem.setParameters("active_displayId=" + sDisplayId); + } + } + } + /** * Uses android.hardware.display.DisplayManager.DisplayListener */ @@ -126,6 +146,7 @@ class RotationHelper { @Override public void onDisplayChanged(int displayId) { + updateActiveDisplayId(displayId); updateOrientation(); } }