From 5342e2b7bdae6bcd0df4c3e7a9c30d1067dfd034 Mon Sep 17 00:00:00 2001 From: Abel Tesfaye Date: Wed, 28 Apr 2021 22:45:09 +0000 Subject: [PATCH] Check for locked screen in DisplayRotation and disable rotation resolver when power save mode is enabled Disable RotationResolver when the screen is rotation locked. This fixes an issue where AiAiAutoRotate would run & print to logs when screen rotation is locked. It also prevents smart auto rotate from running when power save mode is enabled. Test: local, enabled auto rotate & camera rotate then disabled autorotate & checked AiAiAutoRotate didn't show up in logs, by enabling power save mode and face detection then checking camera rotation not working Bug: 185822472 Bug: 186690152 Change-Id: Ie312e85f5d225bcb5cc1036d53e882f01f4f07a9 --- .../android/server/wm/DisplayRotation.java | 24 +++++++++++++++++++ .../server/wm/WindowOrientationListener.java | 9 +------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayRotation.java b/services/core/java/com/android/server/wm/DisplayRotation.java index 0e73d79567483..2c969aba8b3a2 100644 --- a/services/core/java/com/android/server/wm/DisplayRotation.java +++ b/services/core/java/com/android/server/wm/DisplayRotation.java @@ -186,6 +186,10 @@ public class DisplayRotation { @Surface.Rotation private int mUserRotation = Surface.ROTATION_0; + private static final int CAMERA_ROTATION_DISABLED = 0; + private static final int CAMERA_ROTATION_ENABLED = 1; + private int mCameraRotationMode = CAMERA_ROTATION_DISABLED; + /** * Flag that indicates this is a display that may run better when fixed to user rotation. */ @@ -1462,6 +1466,14 @@ public class DisplayRotation { if (shouldUpdateOrientationListener) { updateOrientationListenerLw(); // Enable or disable the orientation listener. } + + final int cameraRotationMode = Settings.Secure.getIntForUser(resolver, + Settings.Secure.CAMERA_AUTOROTATE, 0, + UserHandle.USER_CURRENT); + if (mCameraRotationMode != cameraRotationMode) { + mCameraRotationMode = cameraRotationMode; + shouldUpdateRotation = true; + } } return shouldUpdateRotation; @@ -1491,6 +1503,7 @@ public class DisplayRotation { pw.print(prefix + " mUserRotationMode=" + WindowManagerPolicy.userRotationModeToString(mUserRotationMode)); pw.print(" mUserRotation=" + Surface.rotationToString(mUserRotation)); + pw.print(" mCameraRotationMode=" + mCameraRotationMode); pw.println(" mAllowAllRotations=" + allowAllRotationsToString(mAllowAllRotations)); pw.print(prefix + " mDemoHdmiRotation=" + Surface.rotationToString(mDemoHdmiRotation)); @@ -1539,6 +1552,13 @@ public class DisplayRotation { } } + @Override + public boolean isRotationResolverEnabled() { + return mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE + && mCameraRotationMode == CAMERA_ROTATION_ENABLED + && !mService.mPowerManager.isPowerSaveMode(); + } + @Override public void onProposedRotationChanged(int rotation) { @@ -1582,6 +1602,10 @@ public class DisplayRotation { resolver.registerContentObserver(Settings.System.getUriFor( Settings.System.USER_ROTATION), false, this, UserHandle.USER_ALL); + resolver.registerContentObserver( + Settings.Secure.getUriFor(Settings.Secure.CAMERA_AUTOROTATE), false, this, + UserHandle.USER_ALL); + updateSettings(); } diff --git a/services/core/java/com/android/server/wm/WindowOrientationListener.java b/services/core/java/com/android/server/wm/WindowOrientationListener.java index 3e099fb84f033..02ae1569bf08c 100644 --- a/services/core/java/com/android/server/wm/WindowOrientationListener.java +++ b/services/core/java/com/android/server/wm/WindowOrientationListener.java @@ -31,9 +31,7 @@ import android.os.CancellationSignal; import android.os.Handler; import android.os.SystemClock; import android.os.SystemProperties; -import android.os.UserHandle; import android.provider.DeviceConfig; -import android.provider.Settings; import android.rotationresolver.RotationResolverInternal; import android.util.Slog; import android.util.proto.ProtoOutputStream; @@ -66,7 +64,6 @@ public abstract class WindowOrientationListener { private static final boolean USE_GRAVITY_SENSOR = false; private static final int DEFAULT_BATCH_LATENCY = 100000; - private static final int DEFAULT_ROTATION_RESOLVER_ENABLED = 0; // disabled private static final String KEY_ROTATION_RESOLVER_TIMEOUT = "rotation_resolver_timeout_millis"; private static final long DEFAULT_ROTATION_RESOLVER_TIMEOUT_MILLIS = 700L; @@ -278,11 +275,7 @@ public abstract class WindowOrientationListener { * screen rotation. */ @VisibleForTesting - boolean isRotationResolverEnabled() { - return Settings.Secure.getIntForUser(mContext.getContentResolver(), - Settings.Secure.CAMERA_AUTOROTATE, DEFAULT_ROTATION_RESOLVER_ENABLED, - UserHandle.USER_CURRENT) == 1; - } + abstract boolean isRotationResolverEnabled(); /** * Called when the rotation view of the device has changed.