From 84ab2f7641a0dda42464b805c5a11c9b8dde4d01 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 3 Dec 2026 17:16:02 +0000 Subject: [PATCH] fix(critical): ask for Do Not Disturb access so Android phones without the channel switch can ring in DND Samsung's One UI leaves the per-channel "Override Do Not Disturb" switch out of the channel's settings page, so critical setup sent people to a page with nothing to turn on and looped back to the same button. With Do Not Disturb access, Android honours the channel's bypassDnd when the app creates it, and still keeps a switch the person changed themselves. --- README.md | 2 +- app.json | 1 + src/app/(app)/settings/critical.tsx | 6 +++--- src/app/(app)/setup/critical.tsx | 4 ++-- src/critical/permission.android.ts | 10 +++++++--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6975d63..7a943e2 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ flowchart LR **iOS**: `plugins/critical-alerts.js` adds the critical alerts entitlement, which Apple grants per app. Until it's granted, the plugin stays disabled in `app.json` and critical pushes arrive as normal ones. Once granted, enable it on the App ID, set `enabled: true` and regenerate the profile with `eas credentials`. -**Android**: pushes name a channel. `alerts` is high importance with the default sound; `critical` is max importance on the alarm stream. Ringing in Do Not Disturb needs the channel's **Override Do Not Disturb** switch, which the app links to. +**Android**: pushes name a channel. `alerts` is high importance with the default sound; `critical` is max importance on the alarm stream. Ringing in Do Not Disturb needs the channel's **Override Do Not Disturb** switch. Some phones, such as Samsung's, leave it out of the channel's page, so the app asks for Do Not Disturb access (`ACCESS_NOTIFICATION_POLICY`) instead, which lets it set the switch when it creates its channels. ## Tests diff --git a/app.json b/app.json index fba3a27..da306ed 100644 --- a/app.json +++ b/app.json @@ -136,6 +136,7 @@ }, "android": { "package": "io.appwrite.beep", + "permissions": ["android.permission.ACCESS_NOTIFICATION_POLICY"], "blockedPermissions": [ "android.permission.FOREGROUND_SERVICE", "android.permission.FOREGROUND_SERVICE_REMOTE_MESSAGING", diff --git a/src/app/(app)/settings/critical.tsx b/src/app/(app)/settings/critical.tsx index 3117dca..51c513b 100644 --- a/src/app/(app)/settings/critical.tsx +++ b/src/app/(app)/settings/critical.tsx @@ -18,7 +18,7 @@ const details: Record = { ? 'Critical monitors ring this phone like an alarm, on silent and in Do Not Disturb.' : `Critical monitors ring this ${deviceName} on silent, in Do Not Disturb and in Sleep.`, available: android - ? 'Critical monitors ring on silent once Beep can send notifications. Turn on “Override Do Not Disturb” for the Critical alerts channel so they ring in Do Not Disturb too.' + ? 'Critical monitors ring on silent once Beep can send notifications. Allow Do Not Disturb access for Beep so they ring in Do Not Disturb too.' : `${systemName} asks once. Allow critical alerts so critical monitors can ring through silent mode and Focus.`, off: android ? 'Notifications or the Critical alerts channel are off for Beep. Turn them on in Android Settings.' @@ -29,7 +29,7 @@ const details: Record = { const steps = android ? [ - { title: '2. Let them override Do Not Disturb', subtitle: 'Android asks you to switch it on for the channel' }, + { title: '2. Let them override Do Not Disturb', subtitle: 'Allow Do Not Disturb access for Beep' }, { title: '3. Set the volume', subtitle: 'They ring at your alarm volume' }, ] : [ @@ -110,7 +110,7 @@ export default function CriticalSetup() { {critical === 'available' && android && ( - Android opens the channel’s settings. Scroll down to “Override Do Not Disturb” and switch it on. + Android opens Do Not Disturb access. Find Beep in the list and switch it on. )} {critical === 'available' && ( diff --git a/src/app/(app)/setup/critical.tsx b/src/app/(app)/setup/critical.tsx index 0f56158..47bc4bd 100644 --- a/src/app/(app)/setup/critical.tsx +++ b/src/app/(app)/setup/critical.tsx @@ -12,7 +12,7 @@ const android = Platform.OS === 'android'; /** * Critical alerts, a separate ask once notifications are allowed. iOS asks in its own sheet; Android opens the - * critical channel's settings for its "Override Do Not Disturb" switch, and carries on once it's on. + * Do Not Disturb access list for Beep's switch, and carries on once the critical channel overrides Do Not Disturb. */ export default function SetupCritical() { const [critical, setCritical] = useState(null); @@ -53,7 +53,7 @@ export default function SetupCritical() { title="Ring for what matters" body={ android - ? 'Monitors your team sets to Critical ring on silent, at alarm volume, once Beep can send notifications. Turn on “Override Do Not Disturb” for the Critical alerts channel so they ring in Do Not Disturb too.' + ? 'Monitors your team sets to Critical ring on silent, at alarm volume, once Beep can send notifications. Allow Do Not Disturb access for Beep so they ring in Do Not Disturb too.' : `Monitors your team sets to Critical can ring this ${deviceName} on silent, in Do Not Disturb and in Sleep. Everything else stays a normal notification. ${systemName} asks once.` } actions={ diff --git a/src/critical/permission.android.ts b/src/critical/permission.android.ts index da165a0..b35b075 100644 --- a/src/critical/permission.android.ts +++ b/src/critical/permission.android.ts @@ -8,7 +8,8 @@ import { channels, createChannels } from '@/push/channels'; /** * Android. Critical pushes arrive on the `critical` channel, which rings on the alarm stream, so it * plays with the ringer on silent. Breaking through Do Not Disturb takes the channel's "Override Do Not - * Disturb" switch, which only the person can turn on: + * Disturb" switch. Some phones, such as Samsung's, leave that switch out of the channel's page, so the app asks for + * Do Not Disturb access instead: with it, Android lets the app set the switch when it creates its channels. * - `allowed`: the channel is on and overrides Do Not Disturb. * - `available`: the channel is on but doesn't override Do Not Disturb yet, or notifications haven't been asked for. * - `off`: the person refused notifications, or turned them or the channel off. @@ -25,6 +26,9 @@ export async function getCritical(): Promise { if (status !== 'granted') { return status === 'denied' && !canAskAgain ? 'off' : 'available'; } + // Sets the override once the person grants Do Not Disturb access; Android ignores it without that access, and + // keeps the person's choice once they've changed the switch themselves. + await createChannels(); const channel = await Notifications.getNotificationChannelAsync(channels.critical); if (channel === null) { return 'available'; @@ -35,14 +39,14 @@ export async function getCritical(): Promise { return channel.bypassDnd ? 'allowed' : 'available'; } -/** Asks for notifications if needed, then opens the critical channel's settings for the override switch. */ +/** Asks for notifications if needed, then opens Android's Do Not Disturb access list for Beep's switch. */ export async function requestCritical(): Promise { await createChannels(); const { status } = await Notifications.requestPermissionsAsync(); if (status !== 'granted') { return 'off'; } - await openSettings(); + await Linking.sendIntent('android.settings.NOTIFICATION_POLICY_ACCESS_SETTINGS'); return getCritical(); }