Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/app/(app)/settings/critical.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const details: Record<Critical, string> = {
? '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.'
Expand All @@ -29,7 +29,7 @@ const details: Record<Critical, string> = {

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' },
]
: [
Expand Down Expand Up @@ -110,7 +110,7 @@ export default function CriticalSetup() {
<View style={styles.actions}>
{critical === 'available' && android && (
<Text style={[styles.hint, { color: palette.foreground.tertiary }]}>
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.
</Text>
)}
{critical === 'available' && (
Expand Down
4 changes: 2 additions & 2 deletions src/app/(app)/setup/critical.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<Critical | null>(null);
Expand Down Expand Up @@ -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={
Expand Down
10 changes: 7 additions & 3 deletions src/critical/permission.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -25,6 +26,9 @@ export async function getCritical(): Promise<Critical> {
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';
Expand All @@ -35,14 +39,14 @@ export async function getCritical(): Promise<Critical> {
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<Critical> {
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();
}

Expand Down