Skip to content

Commit

Permalink
Sensor: Enable the motion accelerometer for screen orientation change
Browse files Browse the repository at this point in the history
The screen orientation can be detected by the motion accelerometer
instead of generic accelerometer to save power.

Change-Id: Iaeb3e5958d2ef7cc33080d7091ed8a5462695c67
  • Loading branch information
Oliver Wang authored and rmcc committed Nov 9, 2014
1 parent d9db6b5 commit e0c02b1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
14 changes: 14 additions & 0 deletions core/java/android/hardware/Sensor.java
Expand Up @@ -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.
* <p>
* 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.
*/
Expand Down
4 changes: 4 additions & 0 deletions core/res/res/values/config.xml
Expand Up @@ -1895,4 +1895,8 @@
<!-- Configuration to restart radio upon PDP_DEACTIVATE with
error cause as Regular deactivation(36). -->
<bool name="config_radio_reset_on_regular_deactivation">true</bool>

<!-- bool value to for enabling motion accelerometer -->
<bool name="use_motion_accel">false</bool>

</resources>
1 change: 1 addition & 0 deletions core/res/res/values/symbols.xml
Expand Up @@ -2101,6 +2101,7 @@
<java-symbol type="bool" name="config_sms_force_7bit_encoding" />
<java-symbol type="string" name="config_partial_segment_expire_age" />
<java-symbol type="bool" name="config_global_phone_enabled" />
<java-symbol type="bool" name="use_motion_accel" />

<!-- sim refresh for dual mode card -->
<java-symbol type="bool" name="config_sim_refresh_for_dual_mode_card" />
Expand Down
Expand Up @@ -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();
Expand Down

0 comments on commit e0c02b1

Please sign in to comment.