diff --git a/app/src/main/java/de/jeanlucmakiola/clockula/domain/alarm/UpcomingNotices.kt b/app/src/main/java/de/jeanlucmakiola/clockula/domain/alarm/UpcomingNotices.kt index 1717b68..41d0ea0 100644 --- a/app/src/main/java/de/jeanlucmakiola/clockula/domain/alarm/UpcomingNotices.kt +++ b/app/src/main/java/de/jeanlucmakiola/clockula/domain/alarm/UpcomingNotices.kt @@ -51,13 +51,13 @@ object UpcomingNotices { * - a window opening, so its notice goes up; * - a noticed occurrence's fire grace running out, so a notice whose fire * came late (Doze, no exact alarms) does not outlive its alarm; - * - an armed skip's ([pendingSkips]) occurrence, so a skip dismissed in - * advance is spent on time and the list stops saying "skipping next" - * about an occurrence that has gone by. Nothing is registered to fire - * at a skipped occurrence, so there is no fire to race. + * - an armed skip's ([pendingSkips]) fire grace running out, so a skip + * dismissed in advance is spent on time and the list stops saying + * "skipping next" about an occurrence that has gone by. * - * The closing waits out the grace rather than land on the alarm's own - * instant, so it never races that alarm's fire. + * Both of the last two wait out the grace rather than land on the + * occurrence itself: a fire for it still in flight is refused as too late + * by then, so the check can never race it. */ fun plan( upcoming: List, @@ -74,8 +74,7 @@ object UpcomingNotices { .filter { it.source == FireSource.OCCURRENCE } .mapNotNull { entry -> entry.nextFire?.let { it - lead } } val closings = notices.map { it.fireAt + fireGrace } - val skipsSpent = pendingSkips - val nextCheckAt = (openings + closings + skipsSpent).filter { it > now }.minOrNull() + val nextCheckAt = (openings + closings + pendingSkips.map { it + fireGrace }).filter { it > now }.minOrNull() return UpcomingNoticePlan(notices, nextCheckAt) } } diff --git a/app/src/test/java/de/jeanlucmakiola/clockula/alarm/AlarmEngineUpcomingTest.kt b/app/src/test/java/de/jeanlucmakiola/clockula/alarm/AlarmEngineUpcomingTest.kt index 56de9e9..8027d9c 100644 --- a/app/src/test/java/de/jeanlucmakiola/clockula/alarm/AlarmEngineUpcomingTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/clockula/alarm/AlarmEngineUpcomingTest.kt @@ -71,9 +71,9 @@ class AlarmEngineUpcomingTest { assertThat(alarm.skipNextOccurrence).isTrue() assertThat(harness.scheduler.next?.fireAt).isEqualTo(sixThirtyTomorrow) assertThat(harness.notifier.upcoming).isEmpty() - // Back at the skipped occurrence, to spend the skip. - assertThat(harness.scheduler.upcomingCheck).isEqualTo(sixThirty) - harness.wallClock.instant = sixThirty + // Back once the skipped occurrence's grace is over, to spend the skip. + assertThat(harness.scheduler.upcomingCheck).isEqualTo(sixThirty + AlarmRing.FIRE_GRACE) + harness.wallClock.instant = sixThirty + AlarmRing.FIRE_GRACE harness.engine.onUpcomingWindow() assertThat(harness.alarms.find(1L)!!.skipNextOccurrence).isFalse() assertThat(harness.scheduler.next?.fireAt).isEqualTo(sixThirtyTomorrow) diff --git a/app/src/test/java/de/jeanlucmakiola/clockula/domain/alarm/UpcomingNoticesTest.kt b/app/src/test/java/de/jeanlucmakiola/clockula/domain/alarm/UpcomingNoticesTest.kt index 5bc3970..b7135d1 100644 --- a/app/src/test/java/de/jeanlucmakiola/clockula/domain/alarm/UpcomingNoticesTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/clockula/domain/alarm/UpcomingNoticesTest.kt @@ -103,7 +103,7 @@ class UpcomingNoticesTest { ) // So the skip is spent then, not at tomorrow's window. - assertThat(plan.nextCheckAt).isEqualTo(skipped) + assertThat(plan.nextCheckAt).isEqualTo(skipped + AlarmRing.FIRE_GRACE) } @Test diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 491b8c0..1c6340c 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -1239,11 +1239,11 @@ the alarm's row for whoever opens the app instead. `rescheduleLocked`, so that is where the notices are synced and the third slot is armed for the earliest window still to open, *after* the real registration. The check also wakes once a noticed occurrence's fire grace has - run out (so a notice cannot outlive a fire that came late; waiting out the - grace keeps it from racing that fire) and at an armed skip's occurrence (so a - skip dismissed in advance is spent on time, and the list stops saying - "skipping next" about an occurrence already gone; nothing is registered to - fire then, so there is nothing to race). The sync is wrapped so a notification failure costs nothing, + run out (so a notice cannot outlive a fire that came late) and once an armed + skip's has (so a skip dismissed in advance is spent on time, and the list + stops saying "skipping next" about an occurrence already gone). Both wait out + the grace rather than land on the occurrence itself: a fire for it still in + flight is refused as too late by then, so the check never races it. The sync is wrapped so a notification failure costs nothing, and on the fire path it is deferred until the ring has started, so its binder calls never stand between the fire and the sound. The check's receiver just calls `onUpcomingWindow()`, which is `reschedule()`.