Skip to content

Snooze glucose alerts from anywhere: over other apps, on the lock screen, and with volume buttons - #4623

Draft
petervanrijt wants to merge 18 commits into
NightscoutFoundation:masterfrom
petervanrijt:alarm-snooze-v2
Draft

Snooze glucose alerts from anywhere: over other apps, on the lock screen, and with volume buttons#4623
petervanrijt wants to merge 18 commits into
NightscoutFoundation:masterfrom
petervanrijt:alarm-snooze-v2

Conversation

@petervanrijt

@petervanrijt petervanrijt commented Jul 12, 2026

Copy link
Copy Markdown

What this PR does

What this PR does

Snoozing a glucose alert no longer requires opening xDrip first:

  • Snooze screen over the app in use — when an alert fires while you are using another app, the snooze screen floats on top of it; after snoozing you are returned to that app automatically. Opt-in via Settings → Alarms and Alerts → Glucose alerts settings, requires the Android permission Display over other apps (xDrip asks for it at startup).
  • Snooze screen on the lock screen — with Override silent mode (per alert) or Wake Screen enabled, an alert wakes the display and shows the snooze screen above the lock screen, without unlocking. Closing it returns to the lock screen.
  • Volume-button snooze, also from the lock screen — press the same volume button twice within 1.5 seconds to snooze. While an alert is sounding, the volume buttons no longer change the phone volume. A held button does not count as a double press.
  • Snoozed-alert status — the ongoing notification (and optionally the Extra Status Line) shows "Alert <name> snoozed until HH:mm" while an alert is snoozed, and hides it when glucose recovers.
  • Test alert with a 5-second delay — time to switch apps or turn the screen off, so the new screens can be tested from Edit Alert → Test alert.
  • Robustness fixes — crash when disabling alerts while the alert type is missing; REMOVE ALERT leaving an orphaned active alert (and its sound) behind; test alerts not being snoozable; full-screen intents silently ignored due to notification channel importance (fixed with a migration that only runs for users who need it).

The alert sound itself is never reduced or suppressed by any of this: every failure direction is "more conspicuous" or "convenience unavailable", never "quieter or missed".

What existing users need to change

After updating, xDrip asks once per start to grant Display over other apps; without it everything keeps working except the pop-up over other apps. Note two behaviour changes: snoozing with a volume button now takes a double press (was a single press), and alerts with Override silent mode now wake up into the snooze screen instead of the main screen. Users of xDrip notification channels who use Wake Screen or override-silent alerts get a fresh high-importance alert channel; re-apply any custom channel settings there if desired.

Documentation (included in this PR)

Design, decisions, safety review and per-change test plans:

Notes for reviewers

  • Supersedes draft Snooze glucose alerts with volume buttons, also from lock screen #4510: scope cleaned up per the feedback there (no extra wake switch — the existing Wake Screen setting is reused; single shared key handler; documented test plans per change).
  • The robustness fixes (CHG7/A1) are preconditions for the new snooze paths (consistent ActiveBgAlert state, snoozable test alerts), not standalone refactoring.
  • No new string resources: per review feedback the new user-facing texts are plain English literals for now; a dedicated follow-up PR will move them into translatable resources once the wording is agreed. Existing translated strings are untouched.
  • Phone app only; the Wear module is untouched.

Full disclosure

This pull request is accelerated using Claude Code (model Opus 5 with effort setting on high or maximum).

@Navid200

Copy link
Copy Markdown
Collaborator

Thanks

It will take a while to make the strings perfect. I suggest removing all the strings from this PR.

New floating snooze screen shown when a glucose alert fires while another app is in the foreground; after snoozing, the previous app is restored automatically.
New full-screen snooze screen that turns the display on and appears above the lock screen (without unlocking) when a glucose alert fires; closing it returns to the lock screen.
Volume buttons snooze an active alert with a double press of the same button within 1.5 seconds and no longer change the phone volume during an alarm. Pop-up snooze screens close automatically when the alert is snoozed elsewhere or ends, their navigation menu is disabled, and orphaned alert leftovers are cleaned up.
When a glucose alert fires, the snooze screen is brought up over the app in use or - with Wake Screen or override-silent - above the lock screen. The ongoing notification refreshes immediately after snoozing, and the event log explains when a snooze screen cannot be shown.
An active alert whose alert type is missing (such as a test alert) is no longer deleted during lookups, so it can still be snoozed; adds a helper to read the snoozed state.
While a glucose alert is snoozed, the ongoing notification shows 'Alert <name> snoozed until HH:mm'; the line disappears when glucose recovers or the snooze ends.
The test alert now fires after five seconds, so the lock-screen and over-other-apps behaviour can be tested; removing an alert also stops and clears its active alarm.
For users of the wake-screen or override-silent features, the glucose alert notification channel is recreated with high importance, which Android requires for full-screen alerts; all other users keep their existing channel and its settings.
The home screen uses the shared double-press volume snooze and, when the snooze-over-other-apps option is enabled without the required Android permission, asks at startup to grant it.
Enabling 'Snooze screen over other apps' without the system permission opens the Android settings screen where it can be granted.
With the new option enabled, the extra status line shows 'Alert <name> snoozed until HH:mm' while an alert is snoozed, identical to the notification text.
The floating theme keeps the app behind the snooze screen visible and running, so it is restored unchanged after snoozing.
…larms

New switch for the snooze screen over other apps (default on), placed directly above 'Buttons silence alarms', which can only be enabled together with it.
New option that shows the snoozed-alert status in the extra status line.
New user-facing texts for the snooze screens, the volume-button snooze, the snoozed-alert status and the permission prompts.
Design decisions, safety review and per-change test plans for the snooze changes (CHG1-CHG14), linked from the pull request description.
@petervanrijt

petervanrijt commented Jul 14, 2026 via email

Copy link
Copy Markdown
Author

@Navid200

Copy link
Copy Markdown
Collaborator

If you prefer to keep the strings, we can work on them. It is just that it will only delay the PR in going through.
The reason I suggest keeping them as text in English is that then they will not be show stoppers as long as they get the point across.
We will then be able to open another PR later and spend as much time on it to agree on the strings without delaying the functionality. That's the only reason I have suggested that. I will work with you to get this done any way you prefer.
My suggestion is to expedite this PR by making it contain as little as possible that requires a review. Strings are very critical and can take a long time to review and come to agreement on.

@jamorham

Copy link
Copy Markdown
Collaborator

I don't really like the look of what looks like changes to the alerting logic. To snooze an alert you should just be able to call AlertPlayer.getPlayer().OpportunisticSnooze(); which is what is done for incoming alert snoozing from other sources. As far as I know this function works very well and doesn't need any changes to the alert code.

From what I understand this PR should be UI changes only to support the lock screen snoozing.

@Navid200

Navid200 commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

I would like us to work on this and make it do what it needs without doing anything else.
Your original PR changed 9 files. This one changes 31.
We should be able to accomplish our common intent with a simpler PR.

I could be wrong about all your intentions. My hope is for the user to be able to snooze an alert without having to look at the screen.

The existing mechanism in xDrip requires xDrip to be in foreground. This is why the existing mechanism is not adequate. I always think of someone who gets an alert in an inconvenient situation for example while driving. The intent is to be able to silence the alert without having to take your eyes off the road.

I understood from your original PR that you had found a way to force Android to bring up an xDrip page on screen when you pressed the volume button. Now that xDrip is in foreground, pressing the button a second time should snooze it because we already have the mechanism.
Am I misunderstanding your intent or your findings?
If not, we should be able to accomplish this still with changing only 9 or even less files.

I am more than happy to work on this to assist you if you are OK with that.

@jamorham

Copy link
Copy Markdown
Collaborator

The documentation looks like it probably should be attached to the PR rather than added to the source tree as it seems to relate to the changes only.

Per review feedback: all new string resources are removed and strings.xml is back to master, so existing translations are untouched. The new user-facing texts remain as plain English literals; a follow-up PR will move them into translatable resources. Also updates the change documentation.
The design, review and test documents (CHG1-CHG15) are attached to the pull request conversation instead, so the diff contains application changes only.
@petervanrijt

Copy link
Copy Markdown
Author

Thank you!

Processed

  • ✅ merged NightscoutFoundation:master into alarm-snooze-v2 — local merge 13 July 2026 13:44, pushed 14 July 2026.
  • ✅ Comment 4961115319 @Navid200: "It will take a while to make the strings perfect. I suggest removing all the strings from this PR."
  • ✅ Comment 5014902562 @jamorham: "The documentation looks like it probably should be attached to the PR rather than added to the source tree as it seems to relate to the changes only."

Help

In response of comment 5008280148 @Navid200: Ofcourse your help is more than welcome, please do. With a (third) newborn my time is somewhat limited 😅.

To answer the other questions

Snoozing itself uses the existing path: the snooze screen and the volume keys both end up in AlertPlayer.Snooze() — the same call OpportunisticSnooze() wraps. I deliberately didn't call OpportunisticSnooze() itself, because its internal 3-second rate limit would swallow the second press of the double-press confirmation, and it shows its own toast.

Why UI alone doesn't get there: volume keys need a foreground activity to receive key events, and the lock-screen UI needs the notification's full-screen intent — which Android silently drops on upgraded installs whose alert channel importance is below HIGH. That is the only reason for the small channel migration; it enables the screen, nothing else. A MediaSession-based approach could intercept volume keys without any UI, but it competes with other media apps for the keys and behaviour varies per OEM — for a glucose alarm I preferred the predictable failure mode (if no screen shows, the alarm simply keeps sounding).

Beyond the UI there are, deliberately, a few small non-UI changes:

  1. After a snooze from any source (snooze screen, notification, watch, broadcast), the pop-up snooze screens close and the ongoing notification refreshes right away — small hooks in Snooze()/stopAlert(). Reason: a snooze screen must never stay up, and the notification must never show a sounding alert, for an alert that has already been handled elsewhere; the UI has to reflect the true alert state at all times.
  2. GuessDefaultSnoozeTime() falls back to the per-type default when an alert has no snooze time set. Reason: the volume-key and lock-screen paths snooze without showing a picker, so the default they apply must always be a sane value.
  3. The orphaned-alert fixes — ActiveBgAlert.alertTypegetOnly() no longer deletes the active alert record as a side effect when the alert type is missing, and REMOVE ALERT now clears its active alert. Reason: the double-press path relies on ActiveBgAlert.getOnly() returning consistent state; without these fixes a double press can show success while the alert state is inconsistent — apparent success without effect, the worst failure mode for a glucose alarm — and test alerts, exactly how users will try the new snooze paths, cannot be snoozed at all.

Over the coming week I'll retest everything against the documentation. If all tests pass, I'll mark this PR as Ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants