From e0c02b16e19f7279e49ba63140484513d87b807a Mon Sep 17 00:00:00 2001 From: Oliver Wang Date: Wed, 2 Oct 2013 20:01:50 +0800 Subject: [PATCH] Sensor: Enable the motion accelerometer for screen orientation change The screen orientation can be detected by the motion accelerometer instead of generic accelerometer to save power. Change-Id: Iaeb3e5958d2ef7cc33080d7091ed8a5462695c67 --- core/java/android/hardware/Sensor.java | 14 ++++++++++++++ core/res/res/values/config.xml | 4 ++++ core/res/res/values/symbols.xml | 1 + .../policy/impl/WindowOrientationListener.java | 13 +++++++++++-- 4 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/java/android/hardware/Sensor.java b/core/java/android/hardware/Sensor.java index f514e428e5253..afd2d0b908bae 100644 --- a/core/java/android/hardware/Sensor.java +++ b/core/java/android/hardware/Sensor.java @@ -502,6 +502,20 @@ public final class Sensor { */ public static final String STRING_TYPE_PICK_UP_GESTURE = "android.sensor.pick_up_gesture"; + /** + * A constant describing the motion accelerometer sensor. + *

+ * This sensor is similar to the accelerometer sensor, however it only + * streams data when the device is in motion, and stops streaming data + * when the device is stationary. + * Generally this kind of sensor would consume less power than the generic + * accelerometer sensor, and hence can be used in applications that do not + * require accelerometer streaming when device is stationary, such as the + * screen auto-rotation. + * {@hide} + */ + public static final int TYPE_MOTION_ACCEL = 33171011; + /** * A constant describing all sensor types. */ diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index b1c00549ab6f7..443161a1e3ba9 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -1895,4 +1895,8 @@ true + + + false + diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 6f7823caeec0f..c839fbb04c0f4 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2101,6 +2101,7 @@ + diff --git a/policy/src/com/android/internal/policy/impl/WindowOrientationListener.java b/policy/src/com/android/internal/policy/impl/WindowOrientationListener.java index 704da33a650ab..32772fdf4e5df 100644 --- a/policy/src/com/android/internal/policy/impl/WindowOrientationListener.java +++ b/policy/src/com/android/internal/policy/impl/WindowOrientationListener.java @@ -87,8 +87,17 @@ private WindowOrientationListener(Context context, Handler handler, int rate) { mHandler = handler; mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE); mRate = rate; - mSensor = mSensorManager.getDefaultSensor(USE_GRAVITY_SENSOR - ? Sensor.TYPE_GRAVITY : Sensor.TYPE_ACCELEROMETER); + mSensor = null; + + if (context.getResources().getBoolean( + com.android.internal.R.bool.use_motion_accel) == true) { + mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_MOTION_ACCEL); + } + if (mSensor == null) { + mSensor = mSensorManager.getDefaultSensor(USE_GRAVITY_SENSOR + ? Sensor.TYPE_GRAVITY : Sensor.TYPE_ACCELEROMETER); + } + if (mSensor != null) { // Create listener only if sensors do exist mSensorEventListener = new SensorEventListenerImpl();