Merge "Disables Smart AutoRotate in lock screen." into sc-dev

This commit is contained in:
Alex Salo
2021-05-27 23:33:17 +00:00
committed by Android (Google) Code Review
3 changed files with 58 additions and 3 deletions

View File

@@ -1552,6 +1552,11 @@ public class DisplayRotation {
} }
} }
@Override
public boolean isKeyguardLocked() {
return mService.isKeyguardLocked();
}
@Override @Override
public boolean isRotationResolverEnabled() { public boolean isRotationResolverEnabled() {
return mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE return mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE

View File

@@ -65,7 +65,10 @@ public abstract class WindowOrientationListener {
private static final boolean USE_GRAVITY_SENSOR = false; private static final boolean USE_GRAVITY_SENSOR = false;
private static final int DEFAULT_BATCH_LATENCY = 100000; private static final int DEFAULT_BATCH_LATENCY = 100000;
private static final String KEY_ROTATION_RESOLVER_TIMEOUT = "rotation_resolver_timeout_millis"; private static final String KEY_ROTATION_RESOLVER_TIMEOUT = "rotation_resolver_timeout_millis";
private static final String KEY_ROTATION_MEMORIZATION_TIMEOUT =
"rotation_memorization_timeout_millis";
private static final long DEFAULT_ROTATION_RESOLVER_TIMEOUT_MILLIS = 700L; private static final long DEFAULT_ROTATION_RESOLVER_TIMEOUT_MILLIS = 700L;
private static final long DEFAULT_ROTATION_MEMORIZATION_TIMEOUT_MILLIS = 300_000L; // 5 minutes
private Handler mHandler; private Handler mHandler;
private SensorManager mSensorManager; private SensorManager mSensorManager;
@@ -291,6 +294,12 @@ public abstract class WindowOrientationListener {
*/ */
public abstract void onProposedRotationChanged(int rotation); public abstract void onProposedRotationChanged(int rotation);
/**
* Whether the device is in the lock screen.
* @return returns true if the screen is locked. Otherwise, returns false.
*/
public abstract boolean isKeyguardLocked();
public void dumpDebug(ProtoOutputStream proto, long fieldId) { public void dumpDebug(ProtoOutputStream proto, long fieldId) {
final long token = proto.start(fieldId); final long token = proto.start(fieldId);
synchronized (mLock) { synchronized (mLock) {
@@ -1062,13 +1071,17 @@ public abstract class WindowOrientationListener {
} }
final class OrientationSensorJudge extends OrientationJudge { final class OrientationSensorJudge extends OrientationJudge {
private static final int ROTATION_UNSET = -1;
private boolean mTouching; private boolean mTouching;
private long mTouchEndedTimestampNanos = Long.MIN_VALUE; private long mTouchEndedTimestampNanos = Long.MIN_VALUE;
private int mProposedRotation = -1; private int mProposedRotation = -1;
private int mDesiredRotation = -1; private int mDesiredRotation = -1;
private boolean mRotationEvaluationScheduled; private boolean mRotationEvaluationScheduled;
private long mRotationResolverTimeoutMillis; private long mRotationResolverTimeoutMillis;
private long mRotationMemorizationTimeoutMillis;
private final ActivityTaskManagerInternal mActivityTaskManagerInternal; private final ActivityTaskManagerInternal mActivityTaskManagerInternal;
private long mLastRotationResolutionTimeStamp;
private int mLastRotationResolution = ROTATION_UNSET;
private int mCurrentCallbackId = 0; private int mCurrentCallbackId = 0;
private Runnable mCancelRotationResolverRequest; private Runnable mCancelRotationResolverRequest;
@@ -1084,7 +1097,8 @@ public abstract class WindowOrientationListener {
DeviceConfig.addOnPropertiesChangedListener(NAMESPACE_WINDOW_MANAGER, DeviceConfig.addOnPropertiesChangedListener(NAMESPACE_WINDOW_MANAGER,
ActivityThread.currentApplication().getMainExecutor(), (properties) -> { ActivityThread.currentApplication().getMainExecutor(), (properties) -> {
final Set<String> keys = properties.getKeyset(); final Set<String> keys = properties.getKeyset();
if (keys.contains(KEY_ROTATION_RESOLVER_TIMEOUT)) { if (keys.contains(KEY_ROTATION_RESOLVER_TIMEOUT)
|| keys.contains(KEY_ROTATION_MEMORIZATION_TIMEOUT)) {
readRotationResolverParameters(); readRotationResolverParameters();
} }
}); });
@@ -1093,9 +1107,13 @@ public abstract class WindowOrientationListener {
private void readRotationResolverParameters() { private void readRotationResolverParameters() {
mRotationResolverTimeoutMillis = DeviceConfig.getLong( mRotationResolverTimeoutMillis = DeviceConfig.getLong(
DeviceConfig.NAMESPACE_WINDOW_MANAGER, NAMESPACE_WINDOW_MANAGER,
KEY_ROTATION_RESOLVER_TIMEOUT, KEY_ROTATION_RESOLVER_TIMEOUT,
DEFAULT_ROTATION_RESOLVER_TIMEOUT_MILLIS); DEFAULT_ROTATION_RESOLVER_TIMEOUT_MILLIS);
mRotationMemorizationTimeoutMillis = DeviceConfig.getLong(
NAMESPACE_WINDOW_MANAGER,
KEY_ROTATION_MEMORIZATION_TIMEOUT,
DEFAULT_ROTATION_MEMORIZATION_TIMEOUT_MILLIS);
} }
@Override @Override
@@ -1133,6 +1151,19 @@ public abstract class WindowOrientationListener {
FrameworkStatsLog.DEVICE_ROTATED__ROTATION_EVENT_TYPE__ACTUAL_EVENT); FrameworkStatsLog.DEVICE_ROTATED__ROTATION_EVENT_TYPE__ACTUAL_EVENT);
if (isRotationResolverEnabled()) { if (isRotationResolverEnabled()) {
if (isKeyguardLocked()) {
if (mLastRotationResolution != ROTATION_UNSET
&& SystemClock.uptimeMillis() - mLastRotationResolutionTimeStamp
< mRotationMemorizationTimeoutMillis) {
Slog.d(TAG,
"Reusing the last rotation resolution: " + mLastRotationResolution);
finalizeRotation(mLastRotationResolution);
} else {
finalizeRotation(Surface.ROTATION_0);
}
return;
}
if (mRotationResolverService == null) { if (mRotationResolverService == null) {
mRotationResolverService = LocalServices.getService( mRotationResolverService = LocalServices.getService(
RotationResolverInternal.class); RotationResolverInternal.class);
@@ -1207,6 +1238,7 @@ public abstract class WindowOrientationListener {
+ Surface.rotationToString(mProposedRotation)); + Surface.rotationToString(mProposedRotation));
pw.println(prefix + "mTouching=" + mTouching); pw.println(prefix + "mTouching=" + mTouching);
pw.println(prefix + "mTouchEndedTimestampNanos=" + mTouchEndedTimestampNanos); pw.println(prefix + "mTouchEndedTimestampNanos=" + mTouchEndedTimestampNanos);
pw.println(prefix + "mLastRotationResolution=" + mLastRotationResolution);
} }
@Override @Override
@@ -1242,6 +1274,8 @@ public abstract class WindowOrientationListener {
newRotation = evaluateRotationChangeLocked(); newRotation = evaluateRotationChangeLocked();
} }
if (newRotation >= 0) { if (newRotation >= 0) {
mLastRotationResolution = newRotation;
mLastRotationResolutionTimeStamp = SystemClock.uptimeMillis();
onProposedRotationChanged(newRotation); onProposedRotationChanged(newRotation);
} }
} }

View File

@@ -70,6 +70,7 @@ public class WindowOrientationListenerTest {
mWindowOrientationListener = new TestableWindowOrientationListener(mMockContext, mWindowOrientationListener = new TestableWindowOrientationListener(mMockContext,
mHandler); mHandler);
mWindowOrientationListener.mRotationResolverService = mFakeRotationResolverInternal; mWindowOrientationListener.mRotationResolverService = mFakeRotationResolverInternal;
mWindowOrientationListener.mIsScreenLocked = false;
mFakeSensor = new Sensor(mMockInputSensorInfo); mFakeSensor = new Sensor(mMockInputSensorInfo);
mFakeSensorEvent = new SensorEvent(mFakeSensor, /* accuracy */ 1, /* timestamp */ 1L, mFakeSensorEvent = new SensorEvent(mFakeSensor, /* accuracy */ 1, /* timestamp */ 1L,
@@ -156,14 +157,29 @@ public class WindowOrientationListenerTest {
} }
} }
@Test
public void testOnSensorChanged_inLockScreen_doNotCallRotationResolver() {
mWindowOrientationListener.mIsScreenLocked = true;
mWindowOrientationListener.mOrientationJudge.onSensorChanged(mFakeSensorEvent);
assertThat(mWindowOrientationListener.mIsOnProposedRotationChangedCalled).isFalse();
}
final class TestableWindowOrientationListener extends WindowOrientationListener { final class TestableWindowOrientationListener extends WindowOrientationListener {
boolean mIsOnProposedRotationChangedCalled = false; private boolean mIsOnProposedRotationChangedCalled = false;
private boolean mIsScreenLocked;
TestableWindowOrientationListener(Context context, Handler handler) { TestableWindowOrientationListener(Context context, Handler handler) {
super(context, handler); super(context, handler);
this.mOrientationJudge = new OrientationSensorJudge(); this.mOrientationJudge = new OrientationSensorJudge();
} }
@Override
public boolean isKeyguardLocked() {
return mIsScreenLocked;
}
@Override @Override
public void onProposedRotationChanged(int rotation) { public void onProposedRotationChanged(int rotation) {
mFinalizedRotation = rotation; mFinalizedRotation = rotation;