summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2021-09-09 09:47:04 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-09-09 09:47:04 +0000
commita38a7d1597ee9a16d4e848933043da9330719b29 (patch)
treee4e0a09d731794f712630b9226e9fd9844f3b535
parent9bcef368277cb3a780042232049bb646b2345117 (diff)
parent42672c961714d2254c1b505784226dc6b162c18c (diff)
Merge "RotationHelper: use FoldStateListener to get folded info" into sc-v2-dev
-rw-r--r--services/core/java/com/android/server/audio/RotationHelper.java38
1 files changed, 25 insertions, 13 deletions
diff --git a/services/core/java/com/android/server/audio/RotationHelper.java b/services/core/java/com/android/server/audio/RotationHelper.java
index 872b1feb2d72..d4f4245f19c5 100644
--- a/services/core/java/com/android/server/audio/RotationHelper.java
+++ b/services/core/java/com/android/server/audio/RotationHelper.java
@@ -17,24 +17,26 @@
package com.android.server.audio;
import android.content.Context;
+import android.hardware.devicestate.DeviceStateManager;
+import android.hardware.devicestate.DeviceStateManager.FoldStateListener;
import android.hardware.display.DisplayManager;
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 android.view.WindowManager;
/**
* Class to handle device rotation events for AudioService, and forward device rotation
- * and current active ID to the audio HALs through AudioSystem.
+ * and folded state 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.
+ * Another role of this class is to track device folded state changes. In case of a
+ * change, send the new folded state 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
@@ -47,11 +49,12 @@ class RotationHelper {
private static final String TAG = "AudioService.RotationHelper";
private static AudioDisplayListener sDisplayListener;
+ private static FoldStateListener sFoldStateListener;
private static final Object sRotationLock = new Object();
- private static final Object sActiveDisplayLock = new Object();
+ private static final Object sFoldStateLock = 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 boolean sDeviceFold = true; // R/W synchronized on sFoldStateLock
private static Context sContext;
private static Handler sHandler;
@@ -75,11 +78,17 @@ class RotationHelper {
((DisplayManager) sContext.getSystemService(Context.DISPLAY_SERVICE))
.registerDisplayListener(sDisplayListener, sHandler);
updateOrientation();
+
+ sFoldStateListener = new FoldStateListener(sContext, folded -> updateFoldState(folded));
+ sContext.getSystemService(DeviceStateManager.class)
+ .registerCallback(new HandlerExecutor(sHandler), sFoldStateListener);
}
static void disable() {
((DisplayManager) sContext.getSystemService(Context.DISPLAY_SERVICE))
.unregisterDisplayListener(sDisplayListener);
+ sContext.getSystemService(DeviceStateManager.class)
+ .unregisterCallback(sFoldStateListener);
}
/**
@@ -120,13 +129,17 @@ class RotationHelper {
}
/**
- * Query current display active id and publish the change if any.
+ * publish the change of device folded state if any.
*/
- static void updateActiveDisplayId(int displayId) {
- synchronized (sActiveDisplayLock) {
- if (displayId != Display.DEFAULT_DISPLAY && sDisplayId != displayId) {
- sDisplayId = displayId;
- AudioSystem.setParameters("active_displayId=" + sDisplayId);
+ static void updateFoldState(boolean newFolded) {
+ synchronized (sFoldStateLock) {
+ if (sDeviceFold != newFolded) {
+ sDeviceFold = newFolded;
+ if (newFolded) {
+ AudioSystem.setParameters("device_folded=on");
+ } else {
+ AudioSystem.setParameters("device_folded=off");
+ }
}
}
}
@@ -146,7 +159,6 @@ class RotationHelper {
@Override
public void onDisplayChanged(int displayId) {
- updateActiveDisplayId(displayId);
updateOrientation();
}
}