Merge branch 'feat/16-upcoming-alarm-notification' into release/v1.0.0

# Conflicts:
#	app/src/main/java/de/jeanlucmakiola/clockula/ClockulaApp.kt
This commit is contained in:
makiolaj committed 2026-10-26 20:48:13 +01:00
commit 440d098c77
30 files changed
+1117 -49

No files matched your search

+75 -10
View File
@@ -112,7 +112,7 @@ kit module: the kit's roadmap keeps schedulers app-local.
| `data/di/` | `DataModule`, `DatabaseModule`, `RepositoryModule`, `TimeModule`, `RingtoneModule`, `ZoneModule` (M8; one `@Binds`, `ZoneNames → IcuZoneNames`), `BackupModule` (M10) |
| `data/backup/` | the backup's data-layer half (M10): `BackupDto`/`BackupCodec` (the pure JSON wire format, `ignoreUnknownKeys`, strict on known fields), `BackupDao` (one `@Transaction` replace-all over alarms/timers/world clocks; no schema or version change), `BackupRepository(+Impl)`, mapping through the existing `AlarmMapper`/`TimerMapper`/`WorldClockMapper`, never a second copy |
| `alarm/` | `AlarmEngine` and the four seams it talks to (`AlarmScheduler`, `AlarmCapabilities`, `RingCoordinator`, `AlarmNotifier`), plus `AlarmIntents` |
| `alarm/android/` | the seams' Android implementations: AlarmManager, the capability reads, the service handle, the snoozed notification |
| `alarm/android/` | the seams' Android implementations: AlarmManager, the capability reads, the service handle, the snoozed and upcoming notifications |
| `alarm/receiver/` | `AlarmFireReceiver`, `AlarmActionReceiver`, `SystemEventReceiver` |
| `alarm/ring/` | the alarm's ringing foreground service and its notifications. Its audio player and vibrator moved to `ring/` in M6, shared with the timer's ring |
| `alarm/di/` | `AlarmModule`: `@Binds` for the four seams |
@@ -253,9 +253,10 @@ so the skip eats a second alarm. With the watermark:
one after;
- watermark still in the future ⇒ fire the first candidate after it; write
nothing;
- watermark at or before now ⇒ consumed: clear the flag and the watermark, and
*still* return the first candidate after it, so the skipped occurrence cannot
ring on its way out through the grace window.
- watermark at or before now ⇒ consumed: clear the flag and the watermark,
record the skipped occurrence as the handled one, and *still* return the
first candidate after it, so the skipped occurrence cannot ring on its way
out through the grace window, on this pass or the next (#16).
Arming is deferred while a snooze is pending, and a **non-repeating** alarm with
the flag set is *disabled* rather than skipped: a one-shot has exactly one
@@ -734,7 +735,7 @@ and a TalkBack-shaped accessibility click completing the hold challenge.
throws, ring state for an alarm that is not there fails the foreign key, and
an explicit id moves the row-id allocator past it as SQLite's would.
- **Six fakes for the engine's seams.** `FakeAlarmScheduler` holds each of the
two AlarmManager slots as the value it currently holds, so a test asserts on
AlarmManager slots as the value it currently holds, so a test asserts on
what the system would be showing rather than on a call log;
`FakeRingCoordinator` records start/stop *in order*, because the order is the
take-over contract; `FakeAlarmNotifier`, `FakeAlarmCapabilities`,
@@ -969,7 +970,7 @@ declared because a specific path would otherwise fail, silently, at 07:00.
| `SCHEDULE_EXACT_ALARM` `android:maxSdkVersion="32"` | covers 31–32, where it is pre-granted. Bounded at 32 so it never overlaps the one above; that is the documented pattern and it keeps the store listing's story clean. Below 31 an exact alarm needs no permission at all |
| `RECEIVE_BOOT_COMPLETED` | AlarmManager keeps nothing across a reboot |
| `USE_FULL_SCREEN_INTENT` | the ring screen over the lock screen |
| `POST_NOTIFICATIONS` | the ring and snoozed notifications |
| `POST_NOTIFICATIONS` | the ring, snoozed and upcoming-alarm notifications |
| `FOREGROUND_SERVICE`, `FOREGROUND_SERVICE_SYSTEM_EXEMPTED` | the two ringing services: the alarm's, and (since M6) the timers' |
| `WAKE_LOCK` | keep the CPU up for the length of a ring |
| `VIBRATE` | an alarm and a timer both vibrate, and vibrate alone when no audio source opens |
@@ -1179,7 +1180,8 @@ user later makes repeating is safe by construction (§17).
The engine's verbs, for a reader looking for the one to call: `reschedule`,
`onFire`, `onAutoSilence`, `snooze(id, minutesOverride = null)`, `dismiss`,
`dismissUpcoming`, `onBootCompleted`, `resumeRingingIfAny`, `ringSession` and
`dismissUpcoming`, `dismissUpcomingOccurrence` (#16), `onUpcomingWindow`,
`onBootCompleted`, `resumeRingingIfAny`, `ringSession` and
the read-only `upcoming`. M9 added the last of the dismissals and the snooze's
parameter: `dismissUpcoming(id)` is the `AlarmClock` contract's dismissal *and*
the chooser dialog's, so the user's dismissal and an assistant's are the same
@@ -1207,17 +1209,18 @@ back the moment the slot is re-resolved.
unlimited, and "0 means infinite" is a trap. A refused snooze *dismisses*; it
never leaves the user with a ringing alarm they cannot silence.
### Two AlarmManager slots, deliberately separate
### Three AlarmManager slots, deliberately separate
| Slot | Registered with | Purpose |
|---|---|---|
| next alarm | `setAlarmClock(AlarmClockInfo(fireAt, showIntent), …)` | the user's next alarm. Doze-exempt, and the only variant that populates `getNextAlarmClock()` |
| auto-silence backstop | `setExactAndAllowWhileIdle` | stops a ring nobody dismissed |
| upcoming check (#16) | `setExactAndAllowWhileIdle`, else `setAndAllowWhileIdle` | wakes when the next upcoming-alarm window opens; see below |
They are separate because `getNextAlarmClock()` is what draws the status-bar icon
and the lockscreen line: a backstop sharing that slot would overwrite the user's
07:00 with an internal 07:10. Two `PendingIntent`s, two request codes, two
independent cancels. A test asserts no two request codes collide, because
07:00 with an internal 07:10. One `PendingIntent`, one request code and one
independent cancel per slot. A test asserts no two request codes collide, because
that collision is exactly how a backstop eats a user's alarm. A **snooze does**
go through the next-alarm slot: a snoozed alarm *is* the next alarm.
@@ -1225,6 +1228,68 @@ If exact alarms are unavailable the alarm is still registered, with
`setAndAllowWhileIdle`. There is no third branch: late is survivable, silent is
not.
### The upcoming-alarm notification (#16)
For someone already awake, an alarm about to ring can be dismissed without
opening the app: a silent "Upcoming alarm" notification with a **Dismiss**,
posted while the alarm is inside its window, and the same Dismiss as a chip on
the alarm's row for whoever opens the app instead.
- **The window** is `UpcomingNotices.LEAD` = **two hours** before a natural
occurrence, AOSP DeskClock's own lead for its upcoming notification and what
Google Clock is reported to use. The notice is silent and low-importance, so
being early costs nothing. It is a value, not a setting: the `alarm_upcoming`
channel is the off switch. Only `FireSource.OCCURRENCE` qualifies: a snoozed
alarm has its own notification with a Dismiss, and a ringing one belongs to
the ring screen.
- **Kept true in one place.** Every path that moves an alarm already ends in
`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) 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()`.
- **Dismiss is `dismissUpcoming`, pinned to one occurrence.**
`dismissUpcomingOccurrence(id, fireAt)` re-resolves under the lock and acts
only if the alarm's next fire is still that natural occurrence *and still in
the future*; otherwise it is `DismissOutcome.Stale` and dismisses nothing.
Without the pin a tap landing as the alarm starts would close the ring and get
round its challenge. When it matches, it takes `dismissUpcoming`'s own
branches: a repeating alarm skips that occurrence, a one-shot is switched off
(or deleted, if transient). A fire broadcast already in flight when a skip
was armed is `Ignored` by `onFire`, which checks the armed skip watermark
against the instant it carries. Only the skip: the handled-occurrence
watermark is left to the resolver, which deliberately re-arms a handled
occurrence that a clock moved backwards has put back in the future. A
repeating alarm's resolution is
persisted before the skip is armed, so an old skip that has gone by but was
never spent cannot absorb the new one. One window is left open on purpose: a Dismiss
whose handling straddles the occurrence by milliseconds, with another
reschedule spending the skip before the fire already in flight is handled,
can still let that fire ring. Closing it means keeping a skip tombstone apart
from the flag, and each attempt to do so opened a worse window elsewhere (a
skip switched off or re-armed inside the grace); a dismissed alarm ringing in
a millisecond race costs less than either.
- **No dismiss challenge before the ring**, as in Google Clock. The challenge
proves you are awake while an alarm sounds; before it, skipping is already one
unchallenged switch away in the editor. The notification's Dismiss does ask
for an **unlock** (`setAuthenticationRequired`), so a locked phone cannot be
talked out of its alarm by whoever picks it up. That flag needs Android 12;
below it the notice is `VISIBILITY_SECRET`, kept off the secure lock screen.
It is local-only, so it is never bridged to a watch, where the unlock would
not apply.
- **Denied notifications** cost the notice and nothing else; the row's chip
still works. A swipe is recorded as an `id@fireAt` key in a small
SharedPreferences file through the notification's delete intent, which fires
for the user's swipe and never for the app's own cancel, a reboot or a
blocked channel. So a reschedule, even in a new process, does not bring back
a notice the user got rid of, and one the system took away does come back.
**The `showIntent` was wrong until M9.** It is what the system opens when the
user taps the status-bar alarm icon or the lockscreen's next-alarm line, and it
pointed at the ring screen with `FLAG_ACTIVITY_CLEAR_TASK`, so tapping "my next