Merge "RotationHelper: send active displayId to audio HAL" into sc-v2-dev am: eb0b3a89a1
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15635376 Change-Id: I0f420c6a6a5090e911495e3be9803b2aff2a7bec
This commit is contained in:
@@ -21,20 +21,26 @@ import android.hardware.display.DisplayManager;
|
|||||||
import android.media.AudioSystem;
|
import android.media.AudioSystem;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Display;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to handle device rotation events for AudioService, and forward device rotation
|
* 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,
|
* 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
|
* verify the UI orientation. In case of a change, send the new orientation, in increments
|
||||||
* of 90deg, through AudioSystem.
|
* 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
|
* 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
|
* query the display rotation so audio stays in sync with video/dialogs. This is
|
||||||
* done with .getDefaultDisplay().getRotation() from WINDOW_SERVICE.
|
* 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 {
|
class RotationHelper {
|
||||||
|
|
||||||
@@ -43,7 +49,9 @@ class RotationHelper {
|
|||||||
private static AudioDisplayListener sDisplayListener;
|
private static AudioDisplayListener sDisplayListener;
|
||||||
|
|
||||||
private static final Object sRotationLock = new Object();
|
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 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 Context sContext;
|
||||||
private static Handler sHandler;
|
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
|
* Uses android.hardware.display.DisplayManager.DisplayListener
|
||||||
*/
|
*/
|
||||||
@@ -126,6 +146,7 @@ class RotationHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisplayChanged(int displayId) {
|
public void onDisplayChanged(int displayId) {
|
||||||
|
updateActiveDisplayId(displayId);
|
||||||
updateOrientation();
|
updateOrientation();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user