Loading core/res/res/values/config.xml +5 −0 Original line number Diff line number Diff line Loading @@ -222,6 +222,11 @@ so that applications can still use their own mechanisms. --> <bool name="config_enableAutoPowerModes">false</bool> <!-- Whether (if true) this is a kind of device that can be moved around (eg. phone/laptop), or (if false) something for which movement is either not measurable or should not count toward power states (eg. tv/soundbar). --> <bool name="config_autoPowerModeUseMotionSensor">true</bool> <!-- The threshold angle for any motion detection in auto-power save modes. In hundreths of a degree. --> <integer name="config_autoPowerModeThresholdAngle">200</integer> Loading core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -265,6 +265,7 @@ <java-symbol type="integer" name="config_autoPowerModeAnyMotionSensor" /> <java-symbol type="bool" name="config_autoPowerModePreferWristTilt" /> <java-symbol type="bool" name="config_autoPowerModePrefetchLocation" /> <java-symbol type="bool" name="config_autoPowerModeUseMotionSensor" /> <java-symbol type="bool" name="config_enable_emergency_call_while_sim_locked" /> <java-symbol type="bool" name="config_enable_puk_unlock_screen" /> <java-symbol type="bool" name="config_disableLockscreenByDefault" /> Loading services/core/java/com/android/server/AnyMotionDetector.java +7 −2 Original line number Diff line number Diff line Loading @@ -26,8 +26,6 @@ import android.os.PowerManager; import android.os.SystemClock; import android.util.Slog; import java.lang.Float; /** * Determines if the device has been set upon a stationary object. */ Loading Loading @@ -140,6 +138,13 @@ public class AnyMotionDetector { } } /** * If we do not have an accelerometer, we are not going to collect much data. */ public boolean hasSensor() { return mAccelSensor != null; } /* * Acquire accel data until we determine AnyMotion status. */ Loading services/core/java/com/android/server/DeviceIdleController.java +47 −23 Original line number Diff line number Diff line Loading @@ -272,6 +272,7 @@ public class DeviceIdleController extends SystemService private PowerManager mPowerManager; private INetworkPolicyManager mNetworkPolicyManager; private SensorManager mSensorManager; private final boolean mUseMotionSensor; private Sensor mMotionSensor; private LocationRequest mLocationRequest; private Intent mIdleIntent; Loading Loading @@ -1629,6 +1630,9 @@ public class DeviceIdleController extends SystemService mHandler = mInjector.getHandler(this); mAppStateTracker = mInjector.getAppStateTracker(context, FgThread.get().getLooper()); LocalServices.addService(AppStateTracker.class, mAppStateTracker); mUseMotionSensor = context.getResources().getBoolean( com.android.internal.R.bool.config_autoPowerModeUseMotionSensor); } public DeviceIdleController(Context context) { Loading Loading @@ -1729,6 +1733,8 @@ public class DeviceIdleController extends SystemService ServiceManager.getService(Context.NETWORK_POLICY_SERVICE)); mNetworkPolicyManagerInternal = getLocalService(NetworkPolicyManagerInternal.class); mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE); if (mUseMotionSensor) { int sigMotionSensorId = getContext().getResources().getInteger( com.android.internal.R.integer.config_autoPowerModeAnyMotionSensor); if (sigMotionSensorId > 0) { Loading @@ -1744,6 +1750,7 @@ public class DeviceIdleController extends SystemService mMotionSensor = mSensorManager.getDefaultSensor( Sensor.TYPE_SIGNIFICANT_MOTION, true); } } if (getContext().getResources().getBoolean( com.android.internal.R.bool.config_autoPowerModePrefetchLocation)) { Loading Loading @@ -2588,14 +2595,21 @@ public class DeviceIdleController extends SystemService mState = STATE_SENSING; if (DEBUG) Slog.d(TAG, "Moved from STATE_IDLE_PENDING to STATE_SENSING."); EventLogTags.writeDeviceIdle(mState, reason); scheduleSensingTimeoutAlarmLocked(mConstants.SENSING_TIMEOUT); cancelLocatingLocked(); mNotMoving = false; mLocated = false; mLastGenericLocation = null; mLastGpsLocation = null; // If we have an accelerometer, wait to find out whether we are moving. if (mUseMotionSensor && mAnyMotionDetector.hasSensor()) { scheduleSensingTimeoutAlarmLocked(mConstants.SENSING_TIMEOUT); mNotMoving = false; mAnyMotionDetector.checkForAnyMotion(); break; } mNotMoving = true; // Otherwise, fall through and check this off the list of requirements. case STATE_SENSING: cancelSensingTimeoutAlarmLocked(); mState = STATE_LOCATING; Loading Loading @@ -2893,9 +2907,12 @@ public class DeviceIdleController extends SystemService void scheduleAlarmLocked(long delay, boolean idleUntil) { if (DEBUG) Slog.d(TAG, "scheduleAlarmLocked(" + delay + ", " + idleUntil + ")"); if (mMotionSensor == null && !(mState == STATE_QUICK_DOZE_DELAY || mState == STATE_IDLE || mState == STATE_IDLE_MAINTENANCE)) { // If there is no motion sensor on this device, then we won't schedule if (mUseMotionSensor && mMotionSensor == null && mState != STATE_QUICK_DOZE_DELAY && mState != STATE_IDLE && mState != STATE_IDLE_MAINTENANCE) { // If there is no motion sensor on this device, but we need one, then we won't schedule // alarms, because we can't determine if the device is not moving. This effectively // turns off normal execution of device idling, although it is still possible to // manually poke it by pretending like the alarm is going off. Loading Loading @@ -3765,13 +3782,20 @@ public class DeviceIdleController extends SystemService pw.print(" mLightEnabled="); pw.print(mLightEnabled); pw.print(" mDeepEnabled="); pw.println(mDeepEnabled); pw.print(" mForceIdle="); pw.println(mForceIdle); pw.print(" mUseMotionSensor="); pw.print(mUseMotionSensor); if (mUseMotionSensor) { pw.print(" mMotionSensor="); pw.println(mMotionSensor); } else { pw.println(); } pw.print(" mScreenOn="); pw.println(mScreenOn); pw.print(" mScreenLocked="); pw.println(mScreenLocked); pw.print(" mNetworkConnected="); pw.println(mNetworkConnected); pw.print(" mCharging="); pw.println(mCharging); pw.print(" mMotionActive="); pw.println(mMotionListener.active); if (mUseMotionSensor) { pw.print(" mNotMoving="); pw.println(mNotMoving); } pw.print(" mLocating="); pw.print(mLocating); pw.print(" mHasGps="); pw.print(mHasGps); pw.print(" mHasNetwork="); pw.print(mHasNetworkLocation); pw.print(" mLocated="); pw.println(mLocated); Loading Loading
core/res/res/values/config.xml +5 −0 Original line number Diff line number Diff line Loading @@ -222,6 +222,11 @@ so that applications can still use their own mechanisms. --> <bool name="config_enableAutoPowerModes">false</bool> <!-- Whether (if true) this is a kind of device that can be moved around (eg. phone/laptop), or (if false) something for which movement is either not measurable or should not count toward power states (eg. tv/soundbar). --> <bool name="config_autoPowerModeUseMotionSensor">true</bool> <!-- The threshold angle for any motion detection in auto-power save modes. In hundreths of a degree. --> <integer name="config_autoPowerModeThresholdAngle">200</integer> Loading
core/res/res/values/symbols.xml +1 −0 Original line number Diff line number Diff line Loading @@ -265,6 +265,7 @@ <java-symbol type="integer" name="config_autoPowerModeAnyMotionSensor" /> <java-symbol type="bool" name="config_autoPowerModePreferWristTilt" /> <java-symbol type="bool" name="config_autoPowerModePrefetchLocation" /> <java-symbol type="bool" name="config_autoPowerModeUseMotionSensor" /> <java-symbol type="bool" name="config_enable_emergency_call_while_sim_locked" /> <java-symbol type="bool" name="config_enable_puk_unlock_screen" /> <java-symbol type="bool" name="config_disableLockscreenByDefault" /> Loading
services/core/java/com/android/server/AnyMotionDetector.java +7 −2 Original line number Diff line number Diff line Loading @@ -26,8 +26,6 @@ import android.os.PowerManager; import android.os.SystemClock; import android.util.Slog; import java.lang.Float; /** * Determines if the device has been set upon a stationary object. */ Loading Loading @@ -140,6 +138,13 @@ public class AnyMotionDetector { } } /** * If we do not have an accelerometer, we are not going to collect much data. */ public boolean hasSensor() { return mAccelSensor != null; } /* * Acquire accel data until we determine AnyMotion status. */ Loading
services/core/java/com/android/server/DeviceIdleController.java +47 −23 Original line number Diff line number Diff line Loading @@ -272,6 +272,7 @@ public class DeviceIdleController extends SystemService private PowerManager mPowerManager; private INetworkPolicyManager mNetworkPolicyManager; private SensorManager mSensorManager; private final boolean mUseMotionSensor; private Sensor mMotionSensor; private LocationRequest mLocationRequest; private Intent mIdleIntent; Loading Loading @@ -1629,6 +1630,9 @@ public class DeviceIdleController extends SystemService mHandler = mInjector.getHandler(this); mAppStateTracker = mInjector.getAppStateTracker(context, FgThread.get().getLooper()); LocalServices.addService(AppStateTracker.class, mAppStateTracker); mUseMotionSensor = context.getResources().getBoolean( com.android.internal.R.bool.config_autoPowerModeUseMotionSensor); } public DeviceIdleController(Context context) { Loading Loading @@ -1729,6 +1733,8 @@ public class DeviceIdleController extends SystemService ServiceManager.getService(Context.NETWORK_POLICY_SERVICE)); mNetworkPolicyManagerInternal = getLocalService(NetworkPolicyManagerInternal.class); mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE); if (mUseMotionSensor) { int sigMotionSensorId = getContext().getResources().getInteger( com.android.internal.R.integer.config_autoPowerModeAnyMotionSensor); if (sigMotionSensorId > 0) { Loading @@ -1744,6 +1750,7 @@ public class DeviceIdleController extends SystemService mMotionSensor = mSensorManager.getDefaultSensor( Sensor.TYPE_SIGNIFICANT_MOTION, true); } } if (getContext().getResources().getBoolean( com.android.internal.R.bool.config_autoPowerModePrefetchLocation)) { Loading Loading @@ -2588,14 +2595,21 @@ public class DeviceIdleController extends SystemService mState = STATE_SENSING; if (DEBUG) Slog.d(TAG, "Moved from STATE_IDLE_PENDING to STATE_SENSING."); EventLogTags.writeDeviceIdle(mState, reason); scheduleSensingTimeoutAlarmLocked(mConstants.SENSING_TIMEOUT); cancelLocatingLocked(); mNotMoving = false; mLocated = false; mLastGenericLocation = null; mLastGpsLocation = null; // If we have an accelerometer, wait to find out whether we are moving. if (mUseMotionSensor && mAnyMotionDetector.hasSensor()) { scheduleSensingTimeoutAlarmLocked(mConstants.SENSING_TIMEOUT); mNotMoving = false; mAnyMotionDetector.checkForAnyMotion(); break; } mNotMoving = true; // Otherwise, fall through and check this off the list of requirements. case STATE_SENSING: cancelSensingTimeoutAlarmLocked(); mState = STATE_LOCATING; Loading Loading @@ -2893,9 +2907,12 @@ public class DeviceIdleController extends SystemService void scheduleAlarmLocked(long delay, boolean idleUntil) { if (DEBUG) Slog.d(TAG, "scheduleAlarmLocked(" + delay + ", " + idleUntil + ")"); if (mMotionSensor == null && !(mState == STATE_QUICK_DOZE_DELAY || mState == STATE_IDLE || mState == STATE_IDLE_MAINTENANCE)) { // If there is no motion sensor on this device, then we won't schedule if (mUseMotionSensor && mMotionSensor == null && mState != STATE_QUICK_DOZE_DELAY && mState != STATE_IDLE && mState != STATE_IDLE_MAINTENANCE) { // If there is no motion sensor on this device, but we need one, then we won't schedule // alarms, because we can't determine if the device is not moving. This effectively // turns off normal execution of device idling, although it is still possible to // manually poke it by pretending like the alarm is going off. Loading Loading @@ -3765,13 +3782,20 @@ public class DeviceIdleController extends SystemService pw.print(" mLightEnabled="); pw.print(mLightEnabled); pw.print(" mDeepEnabled="); pw.println(mDeepEnabled); pw.print(" mForceIdle="); pw.println(mForceIdle); pw.print(" mUseMotionSensor="); pw.print(mUseMotionSensor); if (mUseMotionSensor) { pw.print(" mMotionSensor="); pw.println(mMotionSensor); } else { pw.println(); } pw.print(" mScreenOn="); pw.println(mScreenOn); pw.print(" mScreenLocked="); pw.println(mScreenLocked); pw.print(" mNetworkConnected="); pw.println(mNetworkConnected); pw.print(" mCharging="); pw.println(mCharging); pw.print(" mMotionActive="); pw.println(mMotionListener.active); if (mUseMotionSensor) { pw.print(" mNotMoving="); pw.println(mNotMoving); } pw.print(" mLocating="); pw.print(mLocating); pw.print(" mHasGps="); pw.print(mHasGps); pw.print(" mHasNetwork="); pw.print(mHasNetworkLocation); pw.print(" mLocated="); pw.println(mLocated); Loading