Loading services/core/java/com/android/server/wm/DisplayRotation.java +7 −4 Original line number Diff line number Diff line Loading @@ -249,11 +249,13 @@ public class DisplayRotation { mDeskDockRotation = readRotation(R.integer.config_deskDockRotation); mUndockedHdmiRotation = readRotation(R.integer.config_undockedHdmiRotation); mRotation = readDefaultDisplayRotation(displayAddress); int defaultRotation = readDefaultDisplayRotation(displayAddress); mRotation = defaultRotation; if (isDefaultDisplay) { final Handler uiHandler = UiThread.getHandler(); mOrientationListener = new OrientationListener(mContext, uiHandler); mOrientationListener = new OrientationListener(mContext, uiHandler, defaultRotation); mOrientationListener.setCurrentRotation(mRotation); mSettingsObserver = new SettingsObserver(uiHandler); mSettingsObserver.observe(); Loading Loading @@ -1735,8 +1737,9 @@ public class DisplayRotation { private class OrientationListener extends WindowOrientationListener implements Runnable { transient boolean mEnabled; OrientationListener(Context context, Handler handler) { super(context, handler); OrientationListener(Context context, Handler handler, @Surface.Rotation int defaultRotation) { super(context, handler, defaultRotation); } @Override Loading services/core/java/com/android/server/wm/WindowOrientationListener.java +12 −6 Original line number Diff line number Diff line Loading @@ -88,14 +88,19 @@ public abstract class WindowOrientationListener { private final Object mLock = new Object(); @Surface.Rotation private final int mDefaultRotation; /** * Creates a new WindowOrientationListener. * * @param context for the WindowOrientationListener. * @param handler Provides the Looper for receiving sensor updates. * @param defaultRotation Default rotation of the display. */ public WindowOrientationListener(Context context, Handler handler) { this(context, handler, SensorManager.SENSOR_DELAY_UI); public WindowOrientationListener(Context context, Handler handler, @Surface.Rotation int defaultRotation) { this(context, handler, defaultRotation, SensorManager.SENSOR_DELAY_UI); } /** Loading @@ -103,7 +108,7 @@ public abstract class WindowOrientationListener { * * @param context for the WindowOrientationListener. * @param handler Provides the Looper for receiving sensor updates. * @param wmService WindowManagerService to read the device config from. * @param defaultRotation Default rotation of the display. * @param rate at which sensor events are processed (see also * {@link android.hardware.SensorManager SensorManager}). Use the default * value of {@link android.hardware.SensorManager#SENSOR_DELAY_NORMAL Loading @@ -111,10 +116,11 @@ public abstract class WindowOrientationListener { * * This constructor is private since no one uses it. */ private WindowOrientationListener( Context context, Handler handler, int rate) { private WindowOrientationListener(Context context, Handler handler, @Surface.Rotation int defaultRotation, int rate) { mContext = context; mHandler = handler; mDefaultRotation = defaultRotation; mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); mRate = rate; List<Sensor> l = mSensorManager.getSensorList(Sensor.TYPE_DEVICE_ORIENTATION); Loading Loading @@ -1159,7 +1165,7 @@ public abstract class WindowOrientationListener { "Reusing the last rotation resolution: " + mLastRotationResolution); finalizeRotation(mLastRotationResolution); } else { finalizeRotation(Surface.ROTATION_0); finalizeRotation(mDefaultRotation); } return; } Loading services/tests/servicestests/src/com/android/server/wm/WindowOrientationListenerTest.java +19 −10 Original line number Diff line number Diff line Loading @@ -132,6 +132,19 @@ public class WindowOrientationListenerTest { assertThat(mFinalizedRotation).isEqualTo(DEFAULT_SENSOR_ROTATION); } @Test public void testOnSensorChanged_screenLocked_doNotCallRotationResolverReturnDefaultRotation() { mWindowOrientationListener = new TestableWindowOrientationListener(mMockContext, mHandler, /* defaultRotation */ Surface.ROTATION_180); mWindowOrientationListener.mRotationResolverService = mFakeRotationResolverInternal; mWindowOrientationListener.mIsScreenLocked = true; mWindowOrientationListener.mOrientationJudge.onSensorChanged(mFakeSensorEvent); assertThat(mWindowOrientationListener.mIsOnProposedRotationChangedCalled).isFalse(); assertThat(mFinalizedRotation).isEqualTo(Surface.ROTATION_180); } static final class TestableRotationResolver extends RotationResolverInternal { @Surface.Rotation RotationResolverCallbackInternal mCallback; Loading Loading @@ -166,21 +179,17 @@ 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 { private boolean mIsOnProposedRotationChangedCalled = false; private boolean mIsScreenLocked; TestableWindowOrientationListener(Context context, Handler handler) { super(context, handler); this(context, handler, Surface.ROTATION_0); } TestableWindowOrientationListener(Context context, Handler handler, @Surface.Rotation int defaultRotation) { super(context, handler, defaultRotation); this.mOrientationJudge = new OrientationSensorJudge(); } Loading Loading
services/core/java/com/android/server/wm/DisplayRotation.java +7 −4 Original line number Diff line number Diff line Loading @@ -249,11 +249,13 @@ public class DisplayRotation { mDeskDockRotation = readRotation(R.integer.config_deskDockRotation); mUndockedHdmiRotation = readRotation(R.integer.config_undockedHdmiRotation); mRotation = readDefaultDisplayRotation(displayAddress); int defaultRotation = readDefaultDisplayRotation(displayAddress); mRotation = defaultRotation; if (isDefaultDisplay) { final Handler uiHandler = UiThread.getHandler(); mOrientationListener = new OrientationListener(mContext, uiHandler); mOrientationListener = new OrientationListener(mContext, uiHandler, defaultRotation); mOrientationListener.setCurrentRotation(mRotation); mSettingsObserver = new SettingsObserver(uiHandler); mSettingsObserver.observe(); Loading Loading @@ -1735,8 +1737,9 @@ public class DisplayRotation { private class OrientationListener extends WindowOrientationListener implements Runnable { transient boolean mEnabled; OrientationListener(Context context, Handler handler) { super(context, handler); OrientationListener(Context context, Handler handler, @Surface.Rotation int defaultRotation) { super(context, handler, defaultRotation); } @Override Loading
services/core/java/com/android/server/wm/WindowOrientationListener.java +12 −6 Original line number Diff line number Diff line Loading @@ -88,14 +88,19 @@ public abstract class WindowOrientationListener { private final Object mLock = new Object(); @Surface.Rotation private final int mDefaultRotation; /** * Creates a new WindowOrientationListener. * * @param context for the WindowOrientationListener. * @param handler Provides the Looper for receiving sensor updates. * @param defaultRotation Default rotation of the display. */ public WindowOrientationListener(Context context, Handler handler) { this(context, handler, SensorManager.SENSOR_DELAY_UI); public WindowOrientationListener(Context context, Handler handler, @Surface.Rotation int defaultRotation) { this(context, handler, defaultRotation, SensorManager.SENSOR_DELAY_UI); } /** Loading @@ -103,7 +108,7 @@ public abstract class WindowOrientationListener { * * @param context for the WindowOrientationListener. * @param handler Provides the Looper for receiving sensor updates. * @param wmService WindowManagerService to read the device config from. * @param defaultRotation Default rotation of the display. * @param rate at which sensor events are processed (see also * {@link android.hardware.SensorManager SensorManager}). Use the default * value of {@link android.hardware.SensorManager#SENSOR_DELAY_NORMAL Loading @@ -111,10 +116,11 @@ public abstract class WindowOrientationListener { * * This constructor is private since no one uses it. */ private WindowOrientationListener( Context context, Handler handler, int rate) { private WindowOrientationListener(Context context, Handler handler, @Surface.Rotation int defaultRotation, int rate) { mContext = context; mHandler = handler; mDefaultRotation = defaultRotation; mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); mRate = rate; List<Sensor> l = mSensorManager.getSensorList(Sensor.TYPE_DEVICE_ORIENTATION); Loading Loading @@ -1159,7 +1165,7 @@ public abstract class WindowOrientationListener { "Reusing the last rotation resolution: " + mLastRotationResolution); finalizeRotation(mLastRotationResolution); } else { finalizeRotation(Surface.ROTATION_0); finalizeRotation(mDefaultRotation); } return; } Loading
services/tests/servicestests/src/com/android/server/wm/WindowOrientationListenerTest.java +19 −10 Original line number Diff line number Diff line Loading @@ -132,6 +132,19 @@ public class WindowOrientationListenerTest { assertThat(mFinalizedRotation).isEqualTo(DEFAULT_SENSOR_ROTATION); } @Test public void testOnSensorChanged_screenLocked_doNotCallRotationResolverReturnDefaultRotation() { mWindowOrientationListener = new TestableWindowOrientationListener(mMockContext, mHandler, /* defaultRotation */ Surface.ROTATION_180); mWindowOrientationListener.mRotationResolverService = mFakeRotationResolverInternal; mWindowOrientationListener.mIsScreenLocked = true; mWindowOrientationListener.mOrientationJudge.onSensorChanged(mFakeSensorEvent); assertThat(mWindowOrientationListener.mIsOnProposedRotationChangedCalled).isFalse(); assertThat(mFinalizedRotation).isEqualTo(Surface.ROTATION_180); } static final class TestableRotationResolver extends RotationResolverInternal { @Surface.Rotation RotationResolverCallbackInternal mCallback; Loading Loading @@ -166,21 +179,17 @@ 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 { private boolean mIsOnProposedRotationChangedCalled = false; private boolean mIsScreenLocked; TestableWindowOrientationListener(Context context, Handler handler) { super(context, handler); this(context, handler, Surface.ROTATION_0); } TestableWindowOrientationListener(Context context, Handler handler, @Surface.Rotation int defaultRotation) { super(context, handler, defaultRotation); this.mOrientationJudge = new OrientationSensorJudge(); } Loading