Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4d424c2 authored by Robin Lee's avatar Robin Lee
Browse files

Make DeviceIdle motion sensing flaggable-off

We will still go through the same routine as before, and in particular
a misconfigured phone without any motion sensors will still fail to
progress into full doze state.

With config_autoPowerModeUseMotionSensor overriden to false, this is not
true any more and we make STATE_SENSING a no-op that moves straight into
STATE_LOCATING as if we immediately got a "no motion" callback.

Bug: 110756616
Test: atest com.android.server.DeviceIdleControllerTest
Test: atest BatterySaverPolicyTest
Change-Id: I00d778c44257b3e3682494c0d3b10f4c3d68c382
parent af7deaba
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -222,6 +222,11 @@
         so that applications can still use their own mechanisms. -->
         so that applications can still use their own mechanisms. -->
    <bool name="config_enableAutoPowerModes">false</bool>
    <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.
    <!-- The threshold angle for any motion detection in auto-power save modes.
         In hundreths of a degree. -->
         In hundreths of a degree. -->
    <integer name="config_autoPowerModeThresholdAngle">200</integer>
    <integer name="config_autoPowerModeThresholdAngle">200</integer>
+1 −0
Original line number Original line Diff line number Diff line
@@ -265,6 +265,7 @@
  <java-symbol type="integer" name="config_autoPowerModeAnyMotionSensor" />
  <java-symbol type="integer" name="config_autoPowerModeAnyMotionSensor" />
  <java-symbol type="bool" name="config_autoPowerModePreferWristTilt" />
  <java-symbol type="bool" name="config_autoPowerModePreferWristTilt" />
  <java-symbol type="bool" name="config_autoPowerModePrefetchLocation" />
  <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_emergency_call_while_sim_locked" />
  <java-symbol type="bool" name="config_enable_puk_unlock_screen" />
  <java-symbol type="bool" name="config_enable_puk_unlock_screen" />
  <java-symbol type="bool" name="config_disableLockscreenByDefault" />
  <java-symbol type="bool" name="config_disableLockscreenByDefault" />
+7 −2
Original line number Original line Diff line number Diff line
@@ -26,8 +26,6 @@ import android.os.PowerManager;
import android.os.SystemClock;
import android.os.SystemClock;
import android.util.Slog;
import android.util.Slog;


import java.lang.Float;

/**
/**
 * Determines if the device has been set upon a stationary object.
 * Determines if the device has been set upon a stationary object.
 */
 */
@@ -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.
     * Acquire accel data until we determine AnyMotion status.
     */
     */
+47 −23
Original line number Original line Diff line number Diff line
@@ -272,6 +272,7 @@ public class DeviceIdleController extends SystemService
    private PowerManager mPowerManager;
    private PowerManager mPowerManager;
    private INetworkPolicyManager mNetworkPolicyManager;
    private INetworkPolicyManager mNetworkPolicyManager;
    private SensorManager mSensorManager;
    private SensorManager mSensorManager;
    private final boolean mUseMotionSensor;
    private Sensor mMotionSensor;
    private Sensor mMotionSensor;
    private LocationRequest mLocationRequest;
    private LocationRequest mLocationRequest;
    private Intent mIdleIntent;
    private Intent mIdleIntent;
@@ -1629,6 +1630,9 @@ public class DeviceIdleController extends SystemService
        mHandler = mInjector.getHandler(this);
        mHandler = mInjector.getHandler(this);
        mAppStateTracker = mInjector.getAppStateTracker(context, FgThread.get().getLooper());
        mAppStateTracker = mInjector.getAppStateTracker(context, FgThread.get().getLooper());
        LocalServices.addService(AppStateTracker.class, mAppStateTracker);
        LocalServices.addService(AppStateTracker.class, mAppStateTracker);

        mUseMotionSensor = context.getResources().getBoolean(
                com.android.internal.R.bool.config_autoPowerModeUseMotionSensor);
    }
    }


    public DeviceIdleController(Context context) {
    public DeviceIdleController(Context context) {
@@ -1729,6 +1733,8 @@ public class DeviceIdleController extends SystemService
                        ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
                        ServiceManager.getService(Context.NETWORK_POLICY_SERVICE));
                mNetworkPolicyManagerInternal = getLocalService(NetworkPolicyManagerInternal.class);
                mNetworkPolicyManagerInternal = getLocalService(NetworkPolicyManagerInternal.class);
                mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);
                mSensorManager = (SensorManager) getContext().getSystemService(Context.SENSOR_SERVICE);

                if (mUseMotionSensor) {
                    int sigMotionSensorId = getContext().getResources().getInteger(
                    int sigMotionSensorId = getContext().getResources().getInteger(
                            com.android.internal.R.integer.config_autoPowerModeAnyMotionSensor);
                            com.android.internal.R.integer.config_autoPowerModeAnyMotionSensor);
                    if (sigMotionSensorId > 0) {
                    if (sigMotionSensorId > 0) {
@@ -1744,6 +1750,7 @@ public class DeviceIdleController extends SystemService
                        mMotionSensor = mSensorManager.getDefaultSensor(
                        mMotionSensor = mSensorManager.getDefaultSensor(
                                Sensor.TYPE_SIGNIFICANT_MOTION, true);
                                Sensor.TYPE_SIGNIFICANT_MOTION, true);
                    }
                    }
                }


                if (getContext().getResources().getBoolean(
                if (getContext().getResources().getBoolean(
                        com.android.internal.R.bool.config_autoPowerModePrefetchLocation)) {
                        com.android.internal.R.bool.config_autoPowerModePrefetchLocation)) {
@@ -2588,14 +2595,21 @@ public class DeviceIdleController extends SystemService
                mState = STATE_SENSING;
                mState = STATE_SENSING;
                if (DEBUG) Slog.d(TAG, "Moved from STATE_IDLE_PENDING to STATE_SENSING.");
                if (DEBUG) Slog.d(TAG, "Moved from STATE_IDLE_PENDING to STATE_SENSING.");
                EventLogTags.writeDeviceIdle(mState, reason);
                EventLogTags.writeDeviceIdle(mState, reason);
                scheduleSensingTimeoutAlarmLocked(mConstants.SENSING_TIMEOUT);
                cancelLocatingLocked();
                cancelLocatingLocked();
                mNotMoving = false;
                mLocated = false;
                mLocated = false;
                mLastGenericLocation = null;
                mLastGenericLocation = null;
                mLastGpsLocation = 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();
                    mAnyMotionDetector.checkForAnyMotion();
                    break;
                    break;
                }

                mNotMoving = true;
                // Otherwise, fall through and check this off the list of requirements.
            case STATE_SENSING:
            case STATE_SENSING:
                cancelSensingTimeoutAlarmLocked();
                cancelSensingTimeoutAlarmLocked();
                mState = STATE_LOCATING;
                mState = STATE_LOCATING;
@@ -2893,9 +2907,12 @@ public class DeviceIdleController extends SystemService


    void scheduleAlarmLocked(long delay, boolean idleUntil) {
    void scheduleAlarmLocked(long delay, boolean idleUntil) {
        if (DEBUG) Slog.d(TAG, "scheduleAlarmLocked(" + delay + ", " + 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 (mUseMotionSensor && mMotionSensor == null
            // If there is no motion sensor on this device, then we won't schedule
                && 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
            // 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
            // turns off normal execution of device idling, although it is still possible to
            // manually poke it by pretending like the alarm is going off.
            // manually poke it by pretending like the alarm is going off.
@@ -3765,13 +3782,20 @@ public class DeviceIdleController extends SystemService
            pw.print("  mLightEnabled="); pw.print(mLightEnabled);
            pw.print("  mLightEnabled="); pw.print(mLightEnabled);
            pw.print("  mDeepEnabled="); pw.println(mDeepEnabled);
            pw.print("  mDeepEnabled="); pw.println(mDeepEnabled);
            pw.print("  mForceIdle="); pw.println(mForceIdle);
            pw.print("  mForceIdle="); pw.println(mForceIdle);
            pw.print("  mUseMotionSensor="); pw.print(mUseMotionSensor);
            if (mUseMotionSensor) {
                pw.print(" mMotionSensor="); pw.println(mMotionSensor);
                pw.print(" mMotionSensor="); pw.println(mMotionSensor);
            } else {
                pw.println();
            }
            pw.print("  mScreenOn="); pw.println(mScreenOn);
            pw.print("  mScreenOn="); pw.println(mScreenOn);
            pw.print("  mScreenLocked="); pw.println(mScreenLocked);
            pw.print("  mScreenLocked="); pw.println(mScreenLocked);
            pw.print("  mNetworkConnected="); pw.println(mNetworkConnected);
            pw.print("  mNetworkConnected="); pw.println(mNetworkConnected);
            pw.print("  mCharging="); pw.println(mCharging);
            pw.print("  mCharging="); pw.println(mCharging);
            pw.print("  mMotionActive="); pw.println(mMotionListener.active);
            pw.print("  mMotionActive="); pw.println(mMotionListener.active);
            if (mUseMotionSensor) {
                pw.print("  mNotMoving="); pw.println(mNotMoving);
                pw.print("  mNotMoving="); pw.println(mNotMoving);
            }
            pw.print("  mLocating="); pw.print(mLocating); pw.print(" mHasGps=");
            pw.print("  mLocating="); pw.print(mLocating); pw.print(" mHasGps=");
                    pw.print(mHasGps); pw.print(" mHasNetwork=");
                    pw.print(mHasGps); pw.print(" mHasNetwork=");
                    pw.print(mHasNetworkLocation); pw.print(" mLocated="); pw.println(mLocated);
                    pw.print(mHasNetworkLocation); pw.print(" mLocated="); pw.println(mLocated);