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

Commit bf27786b authored by Kweku Adams's avatar Kweku Adams
Browse files

Enter quick doze with non-wakeup alarm.

If a user has an AlarmClock going off within the next hour, the device
won't go into deep Doze. When in Battery Saver, the system tries to
enter deep Doze faster, scheduling an alarm one minute after the screen
turns off to enter deep Doze. This conflict results in the system
scheduling a wakeup alarm every minute until the AlarmClock alarm.
Switching to a non-wakeup alarm prevents the system from waking up every
minute if the device is in Battery Saver mode and there's an AlarmClock
scheduled within the next hour.

Bug: 135975445
Test: atest com.android.server.DeviceIdleControllerTest
Change-Id: Ia60ec769979dc9a792dc73f2a6a646397af7adcb
Merged-In: I98bf4131b7b4a1006e37aa42bcbc7dda7e137d1d
parent 6540f108
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -2737,7 +2737,9 @@ public class DeviceIdleController extends SystemService
                resetIdleManagementLocked();
                // Wait a small amount of time in case something (eg: background service from
                // recently closed app) needs to finish running.
                scheduleAlarmLocked(mConstants.QUICK_DOZE_DELAY_TIMEOUT, false);
                // Use a non-wakeup alarm for going into quick doze in case an AlarmClock alarm
                // is scheduled soon. The non-wakeup alarm will be delayed by at most 2 minutes.
                scheduleAlarmLocked(mConstants.QUICK_DOZE_DELAY_TIMEOUT, false, false);
                EventLogTags.writeDeviceIdle(mState, "no activity");
            } else if (mState == STATE_ACTIVE) {
                mState = STATE_INACTIVE;
@@ -3362,6 +3364,10 @@ public class DeviceIdleController extends SystemService
    }

    void scheduleAlarmLocked(long delay, boolean idleUntil) {
        scheduleAlarmLocked(delay, idleUntil, true);
    }

    private void scheduleAlarmLocked(long delay, boolean idleUntil, boolean useWakeupAlarm) {
        if (DEBUG) Slog.d(TAG, "scheduleAlarmLocked(" + delay + ", " + idleUntil + ")");

        if (mUseMotionSensor && mMotionSensor == null
@@ -3377,12 +3383,14 @@ public class DeviceIdleController extends SystemService
            // can continue until the user interacts with the device.
            return;
        }
        final int alarmType = useWakeupAlarm
                ? AlarmManager.ELAPSED_REALTIME_WAKEUP : AlarmManager.ELAPSED_REALTIME;
        mNextAlarmTime = SystemClock.elapsedRealtime() + delay;
        if (idleUntil) {
            mAlarmManager.setIdleUntil(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            mAlarmManager.setIdleUntil(alarmType,
                    mNextAlarmTime, "DeviceIdleController.deep", mDeepAlarmListener, mHandler);
        } else {
            mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            mAlarmManager.set(alarmType,
                    mNextAlarmTime, "DeviceIdleController.deep", mDeepAlarmListener, mHandler);
        }
    }