summaryrefslogtreecommitdiffstats
path: root/policy/src/com/android/internal
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2011-09-23 17:26:09 -0700
committerJeff Brown <jeffbrown@google.com>2011-09-23 17:26:09 -0700
commitc0347aa19f354a8e1ff4fcd5372b134c0c7c16ad (patch)
treeb442f6284e23f5b203538adb123e9fe2b704fd43 /policy/src/com/android/internal
parent745f1e3a06eb504c9e4465afc987854a6269220d (diff)
downloadframeworks_base-c0347aa19f354a8e1ff4fcd5372b134c0c7c16ad.zip
frameworks_base-c0347aa19f354a8e1ff4fcd5372b134c0c7c16ad.tar.gz
frameworks_base-c0347aa19f354a8e1ff4fcd5372b134c0c7c16ad.tar.bz2
Prevent unintended rotations.
Bug: 4981385 Changed the orientation listener to notify the policy whenever its proposed orientation changes, and changes the window manager to notify the orientation listener when the actual orientation changes. This allows us to better handle the case where the policy has rejected a given proposal at one time (because the current application forced orientation) but might choose to accept the same proposal at another time. It's important that the proposal always be up to date. A proposal becomes irrelevant as soon as the phone posture changes such that we can no longer determine the orientation with confidence (such as when a device is placed flat on a table). Simplified the orientation filtering. Now we just wait 200ms for the device to be still before issuing a proposal. The idea is that if the device is moving around a lot, we assume that the device is being picked up or put down or otherwise in the process of being moved. We don't want to change the rotation until that's all settled down. However, we do want to tolerate a certain amount of environmental noise. (The previous confidence algorithm was also designed along these lines but it was less direct about waiting for things to settle. Instead it simply made orientation changes take longer than usual while unsettled, but the extra delay was often too much or too little. This one should be easier to tune.) Change-Id: I09e6befea1f0994b6b15d424f3182859c0d9a530
Diffstat (limited to 'policy/src/com/android/internal')
-rwxr-xr-xpolicy/src/com/android/internal/policy/impl/PhoneWindowManager.java28
1 files changed, 18 insertions, 10 deletions
diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
index a977618..c7d204e 100755
--- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -446,9 +446,8 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
@Override
- public void onOrientationChanged(int rotation) {
- // Send updates based on orientation value
- if (localLOGV) Log.v(TAG, "onOrientationChanged, rotation changed to " +rotation);
+ public void onProposedRotationChanged(int rotation) {
+ if (localLOGV) Log.v(TAG, "onProposedRotationChanged, rotation=" + rotation);
updateRotation(false);
}
}
@@ -654,6 +653,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
mKeyguardMediator = new KeyguardViewMediator(context, this, powerManager);
mHandler = new Handler();
mOrientationListener = new MyOrientationListener(mContext);
+ try {
+ mOrientationListener.setCurrentRotation(windowManager.getRotation());
+ } catch (RemoteException ex) { }
SettingsObserver settingsObserver = new SettingsObserver(mHandler);
settingsObserver.observe();
mShortcutManager = new ShortcutManager(context, mHandler);
@@ -2882,7 +2884,10 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
synchronized (mLock) {
- int sensorRotation = mOrientationListener.getCurrentRotation(); // may be -1
+ int sensorRotation = mOrientationListener.getProposedRotation(); // may be -1
+ if (sensorRotation < 0) {
+ sensorRotation = lastRotation;
+ }
int preferredRotation = -1;
if (mHdmiPlugged) {
@@ -2892,20 +2897,18 @@ public class PhoneWindowManager implements WindowManagerPolicy {
// Ignore sensor when lid switch is open and rotation is forced.
preferredRotation = mLidOpenRotation;
} else if (mDockMode == Intent.EXTRA_DOCK_STATE_CAR
- && ((mCarDockEnablesAccelerometer && sensorRotation >= 0)
- || mCarDockRotation >= 0)) {
+ && (mCarDockEnablesAccelerometer || mCarDockRotation >= 0)) {
// Ignore sensor when in car dock unless explicitly enabled.
// This case can override the behavior of NOSENSOR, and can also
// enable 180 degree rotation while docked.
- preferredRotation = mCarDockEnablesAccelerometer && sensorRotation >= 0
+ preferredRotation = mCarDockEnablesAccelerometer
? sensorRotation : mCarDockRotation;
} else if (mDockMode == Intent.EXTRA_DOCK_STATE_DESK
- && ((mDeskDockEnablesAccelerometer && sensorRotation >= 0)
- || mDeskDockRotation >= 0)) {
+ && (mDeskDockEnablesAccelerometer || mDeskDockRotation >= 0)) {
// Ignore sensor when in desk dock unless explicitly enabled.
// This case can override the behavior of NOSENSOR, and can also
// enable 180 degree rotation while docked.
- preferredRotation = mDeskDockEnablesAccelerometer && sensorRotation >= 0
+ preferredRotation = mDeskDockEnablesAccelerometer
? sensorRotation : mDeskDockRotation;
} else if (mUserRotationMode == WindowManagerPolicy.USER_ROTATION_LOCKED) {
// Ignore sensor when user locked rotation.
@@ -3006,6 +3009,11 @@ public class PhoneWindowManager implements WindowManagerPolicy {
}
}
+ @Override
+ public void setRotationLw(int rotation) {
+ mOrientationListener.setCurrentRotation(rotation);
+ }
+
private boolean isLandscapeOrSeascape(int rotation) {
return rotation == mLandscapeRotation || rotation == mSeascapeRotation;
}