From bcdfc62ae3ac3809e883fc0b4c71ab52a0cdacf8 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Thu, 6 Mar 2014 19:13:04 -0800 Subject: Add config_supportAutoRotation. On some products, it may not make sense to use the accelerometer to perform auto-rotation. In that case, the product's config.xml framework resource overlay should set config_supportAutoRotation to false. Setting this to false also disables auto-rotation settings. Bug: 13211999 Change-Id: If9d7d72f2a2c576b14a4ff0afb61ea52c42c3357 --- .../com/android/internal/view/RotationPolicy.java | 6 +++-- core/res/res/values/config.xml | 9 ++++++++ core/res/res/values/symbols.xml | 1 + .../internal/policy/impl/PhoneWindowManager.java | 26 +++++++++++++++------- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/core/java/com/android/internal/view/RotationPolicy.java b/core/java/com/android/internal/view/RotationPolicy.java index 70e2bfc6fd11..6295314d201c 100644 --- a/core/java/com/android/internal/view/RotationPolicy.java +++ b/core/java/com/android/internal/view/RotationPolicy.java @@ -21,7 +21,6 @@ import android.content.pm.PackageManager; import android.database.ContentObserver; import android.net.Uri; import android.os.AsyncTask; -import android.os.Build; import android.os.Handler; import android.os.RemoteException; import android.os.UserHandle; @@ -52,7 +51,9 @@ public final class RotationPolicy { PackageManager pm = context.getPackageManager(); return pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_ACCELEROMETER) && pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_PORTRAIT) - && pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE); + && pm.hasSystemFeature(PackageManager.FEATURE_SCREEN_LANDSCAPE) + && context.getResources().getBoolean( + com.android.internal.R.bool.config_supportAutoRotation); } /** @@ -176,6 +177,7 @@ public final class RotationPolicy { */ public static abstract class RotationPolicyListener { final ContentObserver mObserver = new ContentObserver(new Handler()) { + @Override public void onChange(boolean selfChange, Uri uri) { RotationPolicyListener.this.onChange(); } diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index 38c43fa16ea7..932f00012a29 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -372,6 +372,15 @@ + + true + false diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index ab3546c03e90..5c3c57125ca3 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1307,6 +1307,7 @@ + diff --git a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java index 6ad6e1524d4e..541fb13e689b 100644 --- a/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +++ b/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java @@ -283,6 +283,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { int mUserRotation = Surface.ROTATION_0; boolean mAccelerometerDefault; + boolean mSupportAutoRotation; int mAllowAllRotations = -1; boolean mCarDockEnablesAccelerometer; boolean mDeskDockEnablesAccelerometer; @@ -590,13 +591,15 @@ public class PhoneWindowManager implements WindowManagerPolicy { * screen is switched off. */ boolean needSensorRunningLp() { - if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR - || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR - || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT - || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { - // If the application has explicitly requested to follow the - // orientation, then we need to turn the sensor or. - return true; + if (mSupportAutoRotation) { + if (mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR + || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR + || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT + || mCurrentAppOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) { + // If the application has explicitly requested to follow the + // orientation, then we need to turn the sensor on. + return true; + } } if ((mCarDockEnablesAccelerometer && mDockMode == Intent.EXTRA_DOCK_STATE_CAR) || (mDeskDockEnablesAccelerometer && (mDockMode == Intent.EXTRA_DOCK_STATE_DESK @@ -617,7 +620,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { // still be turned off when the screen is off.) return false; } - return true; + return mSupportAutoRotation; } /* @@ -882,6 +885,8 @@ public class PhoneWindowManager implements WindowManagerPolicy { mBroadcastWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "PhoneWindowManager.mBroadcastWakeLock"); mEnableShiftMenuBugReports = "1".equals(SystemProperties.get("ro.debuggable")); + mSupportAutoRotation = mContext.getResources().getBoolean( + com.android.internal.R.bool.config_supportAutoRotation); mLidOpenRotation = readRotation( com.android.internal.R.integer.config_lidOpenRotation); mCarDockRotation = readRotation( @@ -4478,6 +4483,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { } else if (orientation == ActivityInfo.SCREEN_ORIENTATION_LOCKED) { // Application just wants to remain locked in the last rotation. preferredRotation = lastRotation; + } else if (!mSupportAutoRotation) { + // If we don't support auto-rotation then bail out here and ignore + // the sensor and any rotation lock settings. + preferredRotation = -1; } else if ((mUserRotationMode == WindowManagerPolicy.USER_ROTATION_FREE && (orientation == ActivityInfo.SCREEN_ORIENTATION_USER || orientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED @@ -5287,6 +5296,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { pw.print(prefix); pw.print("mLastFocusNeedsMenu="); pw.println(mLastFocusNeedsMenu); } + pw.print(prefix); pw.print("mSupportAutoRotation="); pw.println(mSupportAutoRotation); pw.print(prefix); pw.print("mUiMode="); pw.print(mUiMode); pw.print(" mDockMode="); pw.print(mDockMode); pw.print(" mCarDockRotation="); pw.print(mCarDockRotation); -- cgit v1.2.3-59-g8ed1b