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

Commit 03237fc7 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Exempting time-tick from device-idle

The device screen may be on and the clock may be visible while the
device is in idle mode. We should allow time_tick to flow normally in
such cases.

Test: Manual inspection of flags from the output of
adb shell dumpsys alarm
should show flag value of 0x9 for the alarm TIME_TICK
when time_tick_allowed_while_idle is true, and 0x1 when
time_tick_allowed_while_idle is false.

Bug: 163270237
Change-Id: I4ca345f5cb14c317462d9a5b0ec9bac9f9f69b41
parent 7d79aae5
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -417,6 +417,9 @@ public class AlarmManagerService extends SystemService {
        @VisibleForTesting
        static final String KEY_LAZY_BATCHING = "lazy_batching";

        private static final String KEY_TIME_TICK_ALLOWED_WHILE_IDLE =
                "time_tick_allowed_while_idle";

        private static final long DEFAULT_MIN_FUTURITY = 5 * 1000;
        private static final long DEFAULT_MIN_INTERVAL = 60 * 1000;
        private static final long DEFAULT_MAX_INTERVAL = 365 * DateUtils.DAY_IN_MILLIS;
@@ -440,6 +443,7 @@ public class AlarmManagerService extends SystemService {
        private static final long DEFAULT_APP_STANDBY_RESTRICTED_WINDOW = MILLIS_IN_DAY;

        private static final boolean DEFAULT_LAZY_BATCHING = true;
        private static final boolean DEFAULT_TIME_TICK_ALLOWED_WHILE_IDLE = true;

        // Minimum futurity of a new alarm
        public long MIN_FUTURITY = DEFAULT_MIN_FUTURITY;
@@ -470,6 +474,7 @@ public class AlarmManagerService extends SystemService {
        public long APP_STANDBY_RESTRICTED_WINDOW = DEFAULT_APP_STANDBY_RESTRICTED_WINDOW;

        public boolean LAZY_BATCHING = DEFAULT_LAZY_BATCHING;
        public boolean TIME_TICK_ALLOWED_WHILE_IDLE = DEFAULT_TIME_TICK_ALLOWED_WHILE_IDLE;

        private long mLastAllowWhileIdleWhitelistDuration = -1;

@@ -557,6 +562,11 @@ public class AlarmManagerService extends SystemService {
                                migrateAlarmsToNewStoreLocked();
                            }
                            break;
                        case KEY_TIME_TICK_ALLOWED_WHILE_IDLE:
                            TIME_TICK_ALLOWED_WHILE_IDLE = properties.getBoolean(
                                    KEY_TIME_TICK_ALLOWED_WHILE_IDLE,
                                    DEFAULT_TIME_TICK_ALLOWED_WHILE_IDLE);
                            break;
                        default:
                            if (name.startsWith(KEY_PREFIX_STANDBY_QUOTA) && !standbyQuotaUpdated) {
                                // The quotas need to be updated in order, so we can't just rely
@@ -690,6 +700,9 @@ public class AlarmManagerService extends SystemService {
            pw.print(KEY_LAZY_BATCHING, LAZY_BATCHING);
            pw.println();

            pw.print(KEY_TIME_TICK_ALLOWED_WHILE_IDLE, TIME_TICK_ALLOWED_WHILE_IDLE);
            pw.println();

            pw.decreaseIndent();
        }

@@ -3756,9 +3769,14 @@ public class AlarmManagerService extends SystemService {
            final long tickEventDelay = nextTime - currentTime;

            final WorkSource workSource = null; // Let system take blame for time tick events.

            int flags = AlarmManager.FLAG_STANDALONE;
            flags |= mConstants.TIME_TICK_ALLOWED_WHILE_IDLE ? FLAG_ALLOW_WHILE_IDLE_UNRESTRICTED
                    : 0;

            setImpl(ELAPSED_REALTIME, mInjector.getElapsedRealtime() + tickEventDelay, 0,
                    0, null, mTimeTickTrigger, TIME_TICK_TAG, AlarmManager.FLAG_STANDALONE,
                    workSource, null, Process.myUid(), "android");
                    0, null, mTimeTickTrigger, TIME_TICK_TAG, flags, workSource, null,
                    Process.myUid(), "android");

            // Finally, remember when we set the tick alarm
            synchronized (mLock) {