From 4bd149ef83c8e3e2ffb61885e71f44df9a9ccfa7 Mon Sep 17 00:00:00 2001 From: Craig Mautner Date: Fri, 3 Aug 2012 13:54:02 -0700 Subject: [PATCH] Do not use last app rotation as default. If the rotation sensor has been disabled we were substituting the last app rotation for the sensor value. This fix uses the last sensor value delivered before the sensor was disabled. Only use the last app rotation if we never have received a valid sensor value. Fixes bug 6387946. Change-Id: I50743c30ee2b4455e9848d3a619809be97eec3c8 --- .../internal/policy/impl/PhoneWindowManager.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 215f5978fbed5..718512b8a3784 100755 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -361,6 +361,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mScreenOnEarly = false; boolean mScreenOnFully = false; boolean mOrientationSensorEnabled = false; + int mLastSensorRotation = -1; int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; boolean mHasSoftInput = false; @@ -3728,7 +3729,16 @@ public class PhoneWindowManager implements WindowManagerPolicy { synchronized (mLock) { int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1 if (sensorRotation < 0) { - sensorRotation = lastRotation; + // Sensor is disabled, device probably just turned off. + if (mLastSensorRotation >= 0) { + sensorRotation = mLastSensorRotation; + } else { + // Sensor has never been enabled. Last resort is to use lastRotation. + sensorRotation = lastRotation; + } + } else { + // Valid sensor data, save it away. + mLastSensorRotation = sensorRotation; } final int preferredRotation;