From 0c409e7a6a43fd5f7b4b4b9caaf64b3d9c7e94af Mon Sep 17 00:00:00 2001 From: Tom Brow Date: Mon, 16 Nov 2026 07:47:58 -0800 Subject: [PATCH] docs: design Android push notifications (#9555) Design docs for Android push notifications, matching what iOS has today: DM and mention notifications with real message text, grouped per conversation, and tapping one opens it. - **[ADR 0004](docs/adr/0004-push-gateway-hides-device-platform.md):** one push gateway per app distribution serves both platforms, and the relay can't tell an Android installation from an iOS one. - **[ADR 0005](docs/adr/0005-android-push-enrollment-attestation.md):** Android enrollment requires hardware Key Attestation on a locked bootloader, verified offline. Later installation calls are signed with the attested key. - **[ADR 0006](docs/adr/0006-android-notifications-run-app-dart-code.md):** Android builds notifications with the app's own Dart code in a background engine, instead of a native port of the iOS extension. - **[PLANS/ANDROID_PUSH.md](PLANS/ANDROID_PUSH.md):** the spec, plus the tickets it splits into. - **CONTEXT.md:** defines *wake signal* and *push gateway*. The privacy model stays the same: pushes carry a fixed wake signal and nothing about any event. ### Validation A throwaway [prototype](https://github.com/block/buzz/tree/prototype/android-push-headless-dart) checked ADR 0006 against FCM's ~10 s handler budget. It started a headless Dart engine from a killed app, signed in to a local relay and updated a placeholder notification with the real text. | Device | Wake to real text (median, 12 cold runs) | Memory (PSS) | |---|---|---| | Pixel 9a | 0.51 s (worst 0.54 s) | ~45 MB | | Emulator, CPU slowed ~8x | 0.80 s (worst 1.05 s) | ~57 MB | The relay ran on the same machine, so real network latency is still unmeasured. With an unresponsive relay, the placeholder notification stayed and the native watchdog ended the handler. This PR changes documentation only, so no app run applies. ### Regressions None. This PR adds documentation only and changes no behavior. The design keeps iOS push working through the rollout, and the relay learns no more about devices than it does today. --------- Signed-off-by: Tom Brow Co-authored-by: Tom Brow --- CONTEXT.md | 12 ++ PLANS/ANDROID_PUSH.md | 139 ++++++++++++++++++ ...0004-push-gateway-hides-device-platform.md | 16 ++ ...005-android-push-enrollment-attestation.md | 10 ++ ...android-notifications-run-app-dart-code.md | 13 ++ 5 files changed, 190 insertions(+) create mode 100644 PLANS/ANDROID_PUSH.md create mode 100644 docs/adr/0004-push-gateway-hides-device-platform.md create mode 100644 docs/adr/0005-android-push-enrollment-attestation.md create mode 100644 docs/adr/0006-android-notifications-run-app-dart-code.md diff --git a/CONTEXT.md b/CONTEXT.md index 193f06bef8..71d8132112 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -8,6 +8,18 @@ Shared terminology for Buzz product behavior. This glossary currently covers mob A notification directed to a user's mobile installation through the platform's push service. +### Wake signal + +The fixed push a [push gateway](#push-gateway) sends to an installation, telling it to fetch new events from its relays. It carries nothing about any event. + +_Avoid_: Silent push, content push + +### Push gateway + +The service that holds one mobile app's platform push credentials (an [internal build](#internal-build), the [public build](#public-build) or a fork's app) and sends [wake signals](#wake-signal) to that app's installations on every platform. See [ADR 0004](docs/adr/0004-push-gateway-hides-device-platform.md). + +_Avoid_: Push server, APNs gateway + ### Notification body The text a [mobile push notification](#mobile-push-notification) shows for a message: the message's text with its Markdown syntax removed, cut only where the platform would cut it. See [ADR 0002](docs/adr/0002-notification-message-text.md). diff --git a/PLANS/ANDROID_PUSH.md b/PLANS/ANDROID_PUSH.md new file mode 100644 index 0000000000..2afdf5210c --- /dev/null +++ b/PLANS/ANDROID_PUSH.md @@ -0,0 +1,139 @@ +--- +title: "Android push notifications" +tags: [mobile, android, push-notifications] +status: draft +created: 2026-11-15 +--- + +# Android push notifications + +## Problem Statement + +Buzz on iOS shows a mobile push notification when someone sends you a direct message or mentions you, even when the app isn't running. On Android, nothing arrives until you open the app, so Android users miss messages that iOS users see right away. + +## Solution + +Android installations get the same mobile push notifications as iOS: the same triggers, real message text, and tapping a notification opens the conversation. The design keeps today's privacy model. The push gateway sends a contentless wake signal, and the app fetches the message from its relay before showing it. The relay can't tell an Android installation from an iOS one. + +## User Stories + +1. As an Android user, I want a notification when someone sends me a direct message, so that I can reply without keeping the app open. +2. As an Android user, I want a notification when someone mentions me, so that I don't miss messages that need me. +3. As an Android user, I want the notification to show the sender and the message's own text, so that I can decide whether to open it. +4. As an Android user, I want notification text to follow the same notification body rules as iOS, so that code, links and line breaks read the same on both platforms. +5. As an Android user, I want tapping a notification to open that conversation, so that I can respond straight away. +6. As an Android user, I want notifications from one conversation grouped together, so that a busy DM doesn't flood my notification shade. +7. As an Android user, I want separate "Direct messages" and "Mentions" categories in system settings, so that I can silence one without the other. +8. As an Android user, I want Buzz to ask for notification permission at the same point the iOS app asks, so that the prompt arrives when its purpose is clear. +9. As an Android user who declined notification permission, I want the app to keep working normally, so that declining has no other cost. +10. As an Android user, I want a notification even when the app's fetch is slow or fails, so that a message is never silently missed. +11. As an Android user, I want the real notification to appear directly, with a generic one shown only when the fetch is slow and then replaced, so that one message never alerts twice. +12. As an Android user using the app, I want no system notification for a message while the app is open, so that the app doesn't notify me about what I'm looking at. +13. As an Android user whose phone was offline, I want a notification for each message I missed, grouped per conversation, so that coming back online doesn't hide all but the newest. +14. As an Android user, I want no notification for messages I sent myself from another device, so that my own activity doesn't buzz my phone. +15. As an Android user, I want muted channels to stay silent, so that muting means the same thing on every platform. +16. As an Android user, I want no notifications from hellthreads (messages tagging very many people), so that broadcast noise doesn't reach me, as on iOS. +17. As an Android user, I want a message I already saw in the app not to notify me again, so that notifications only show new things. +18. As an Android user signed into several communities, I want notifications from each of them, so that I don't need to switch communities to stay up to date. +19. As an Android user who signs out of a community, I want its notifications to stop, so that a signed-out account can't reach my phone. +20. As an Android user who reinstalls the app, I want notifications to resume after I sign in again, with no leftover state from the old install. +21. As an Android user whose push token rotates, I want notifications to keep arriving, so that token rotation is invisible to me. +22. As an Android user on a custom OS with Google Play services whose boot key the gateway operator has listed, such as GrapheneOS, I want push to work, so that a privacy-focused phone isn't excluded. +23. As an Android user whose phone can't provide hardware-backed attestation, or whose bootloader is unlocked, or that runs a custom OS whose boot key isn't listed, I want the app to work normally without push, and to see that push is unavailable, so that I understand why nothing arrives. +24. As a Buzz member, I want my relay unable to tell which platform each of my devices runs, so that platform details can't help correlate my identities. +25. As a Buzz member, I want push wakes to carry nothing about my messages, so that Google and Apple learn nothing beyond the fact that a wake happened. +26. As a relay operator, I want one push gateway per app distribution to serve both platforms, so that I configure push once per app. +27. As a push gateway operator, I want enrollment to require hardware attestation, so that scripted clients can't abuse the public enrollment endpoints. +28. As a push gateway operator, I want each installation's signed calls rate limited per attested key, and the enrollment challenge quota sized for both platforms, so that one installation can't flood the gateway and an Android launch can't starve iOS enrollment. +29. As a push gateway operator, I want the gateway to refresh Google's attestation revocation list itself, so that revoked keys stop enrolling without manual work. +30. As a distributor of a fork, I want to run my own gateway with my own Firebase project and Android signing key, so that my app's push is independent of anyone else's. +31. As a distributor, I want Firebase configuration supplied at build and deploy time, so that no distributor-specific values live in the open-source code. +32. As an iOS user, I want my notifications to keep working through the rollout, so that adding Android doesn't break iOS. +33. As a developer, I want Android notification building to reuse the app's Dart relay, sign-in and formatting code, so that there is one implementation to keep correct. + +## Implementation Decisions + +Decisions recorded as ADRs: [0004](../docs/adr/0004-push-gateway-hides-device-platform.md) (the push gateway hides each installation's platform from the relay), [0005](../docs/adr/0005-android-push-enrollment-attestation.md) (Android enrollment attestation) and [0006](../docs/adr/0006-android-notifications-run-app-dart-code.md) (notifications built by the app's Dart code). + +**Push gateway** + +- One gateway serves one app distribution on both platforms. Its configuration names the iOS app and APNs credentials as today, plus the Android package name, its accepted signing-certificate digests, and the Firebase project and service-account credentials for FCM HTTP v1. +- An installation records its platform and push endpoint. The platform lives only in gateway state reached through the sealed grant; nothing the relay sees reveals it. Existing installations are iOS. Android endpoints are FCM registration tokens, which are not hex, so endpoint validation and size limits become per platform. +- Enrollment takes a platform-specific attestation. iOS keeps App Attest. Android sends a Key Attestation certificate chain for a fresh key generated after the push token and gateway challenge are known. As App Attest's client data does on iOS, the attestation challenge binds the whole enrollment transcript: it is the SHA-256 of the transcript bytes, which contain the gateway challenge, so the push token, epoch and expiry are attested too, and the existing exact-replay recovery rule works unchanged. The gateway accepts the chain only when: + - it reaches a configured Google attestation root (Google publishes more than one; the list comes from Google's current documentation, and a root change is a reviewed configuration rollout, as for App Attest) and no certificate in it is revoked; + - the attestation challenge matches the transcript; + - the root of trust and key properties, read only from the hardware-enforced list (values in the software-enforced list are attacker-controlled), report a locked bootloader and either verified boot state Verified, or SelfSigned with a verified boot key equal to one of the gateway's configured boot-key digests (Unverified, Failed, and SelfSigned with any other key are rejected); + - both the attestation and KeyMint security levels are TrustedEnvironment or StrongBox, the key origin is generated, and the key is EC P-256 with a sign-only purpose; + - the attested application id names exactly one package, matching the configured package and a configured signing digest. This is the one value read from the software-enforced list, because the operating system, not the secure hardware, fills it in. It is trusted only because the boot state and boot key vouch for the operating system that wrote it. +- The boot-key list is one generic deployment setting, empty by default, so a default gateway accepts stock Android only. No operating system is named in code. An operator who wants GrapheneOS adds its published per-device verified boot key fingerprints, and updates the list when new phone models ship. +- The gateway fetches Google's revocation list periodically. A stale list fails closed only after a generous grace period. +- After enrollment, every installation call (delegate, revoke a delegation, rotate the endpoint, revoke the installation) is signed, as on iOS. iOS signs with an App Attest assertion. Android signs the same transcript bytes with the attested Keystore key, an ECDSA signature the gateway checks against the public key stored at enrollment. Keystore keys have no signature counter, so replay protection for Android rests on the single-use challenge already in each transcript. +- The enrollment request carries no platform field. It holds either an App Attest object or an Android attestation chain, and the gateway derives the platform from which one is present. +- Signed installation calls are rate limited per attested key. Attestation carries no stable device id and each enrollment makes a fresh key, so enrollment itself stays bounded by the deployment-wide challenge quota and by one installation per push token. That quota is sized for both platforms, and the Android client jitters its first enrollment so a release doesn't make every phone enroll at once. +- Delivery moves to one platform-neutral route. The existing APNs-named route stays as an alias until relays have moved over. The gateway maps the lease's priority class to each platform. +- For Android, the wake signal is a high-priority, data-only FCM message whose payload is fixed and compiled in, like today's APNs payload. It contains no relay-supplied bytes. +- Android wakes carry one constant collapse key and a time to live taken from the delivery's expiry. A collapse key only replaces a wake FCM is still holding for an unreachable phone, so an online phone still gets one wake per message, and a phone coming back online gets one wake instead of a burst (FCM keeps at most 100 uncollapsed messages per device and discards them all past that). The app treats FCM's deleted-messages callback as a wake. +- One delegation per installation and relay stays the rule for now (ADR 0004 keeps per-identity grants possible later). + +**Relay** + +- The lease keeps its `transport` member, and every platform sends the same fixed value that iOS sends today. It is a protocol constant, not device data, so it reveals nothing about the platform. Keeping it lets new clients, Android included, work with relays already deployed, and today's iOS clients work with new relays, so nothing has to roll out in a set order. +- The delivery URL setting points at the gateway's platform-neutral route. +- Classes stay the single default class. + +**Mobile, Android native** + +- A Firebase messaging service receives the wake. When the app is in the foreground (a native lifecycle check), it does nothing: the running app already shows new messages. Otherwise it starts a background Flutter engine running the wake-to-notification entrypoint and posts the result directly. The category is known only after the fetch, so no notification is posted before it. If nothing has been posted after about 2 s, it posts a generic "New activity" notification in a third "Other" category, which the real result replaces silently, and which is removed when the result is that there is nothing to show. A native watchdog finishes the work inside the platform's time limit even if Dart never answers. +- FCM token registration and rotation feed the same enrollment and endpoint-rotation flow iOS uses. +- The app generates an Android Keystore key with the gateway's challenge and sends its attestation chain at enrollment. +- Notification categories are "Direct messages", "Mentions" and "Other" (only the slow-fetch generic notification). Notifications use the platform's messaging style, grouped per conversation. A tap opens the conversation through the app's existing deep-link handling. +- The Android 13+ notification permission prompt appears at the same point iOS asks. +- Firebase configuration is a build-time setting supplied by each distributor, never committed. + +**Mobile, shared Dart** + +- One wake-to-notification function does what the iOS extension's resolver does. It reads the configured communities, signs in to each relay, fetches events with an overlap rather than strictly newer than the last one shown (a new message can carry an earlier `created_at` because of clock skew or delivery order, and the relay accepts timestamps up to 15 minutes off), deduplicates by event id against the shown record within that reorder window, as the iOS resolver does, applies the same eligibility rules (self-authored, muted, hellthread), and returns every eligible unshown message, bounded (newest 20 overall, with a per-conversation cap that fits the messaging style), each with title, body, conversation and navigation target. The Android handler posts or updates one notification per conversation, each alerting once. A wake therefore means "sync now", so a lost wake is recovered by the next one. iOS keeps one notification per push, because its extension can only rewrite the push it was handed. It runs headless, with no UI and no Riverpod app state, and uses short network timeouts of its own. +- The notification body formatter is ported to Dart and checked against the shared notification-body fixtures, as ADR 0002 requires of every platform. +- The background path records which messages it has shown, so the app and later wakes don't notify for them again. A process runs one background fetch at a time: a wake that arrives mid-run sets a rerun flag instead of starting a second engine. The shown record is updated in one atomic step together with the decision to post, in a store a headless isolate can read, since the foreground app writes the same record. +- Enrollment gains the Android attestation, and every later gateway call is signed with the attested key. The rest of the push layer (subscriptions, renewal, revocation outbox, setup recovery) is shared with iOS unchanged. + +Prototype evidence ([`prototype/android-push-headless-dart`](https://github.com/block/buzz/tree/prototype/android-push-headless-dart)): on an emulator, the real text was posted about 0.1 s after a cold wake, and about 0.8 s median (worst about 1 s) with the CPU slowed about 8x. Memory was about 57 MB PSS. A relay that accepts TCP and never answers held the handler until the watchdog fired. On a Pixel 9a over USB (median of 12 cold runs), the real text was posted 0.51 s after the wake (worst 0.54 s), about 45 MB PSS. Most of that time is native engine and Dart startup; the relay round trips over USB took about 0.16 s. The watchdog ended at 9.8 s on the phone, so the real one should fire at about 8 s. No run crossed a real network: the phone couldn't reach the test relay over Wi-Fi. + +## Testing Decisions + +Tests check behavior at two points, through public interfaces, with fakes only at external boundaries. + +- **Push gateway HTTP API.** Extend the existing HTTP delivery and attestation tests with a fake FCM sender and generated Key Attestation chains: enroll, delegate, deliver, rotate endpoint and revoke for an Android installation, and table rows for each rejected attestation (unlocked bootloader, Unverified or Failed boot state, SelfSigned with an unlisted key, SelfSigned with an empty list, a boot key supplied only in the software-enforced list, wrong package or signing digest, wrong challenge, revoked certificate, software-backed key), rows that accept Verified with any key and SelfSigned with a listed key, plus the per-key rate limit. Signed installation calls get matching rows: wrong key, altered transcript, reused challenge. Prior art: the gateway's HTTP delivery tests and App Attest assertion tests. +- **Dart wake-to-notification function.** Run it against a fake relay as a journey: DM and mention notify; self-authored, muted and hellthread messages don't; an already shown message doesn't notify again; a message that arrives after a newer one but carries an older timestamp still notifies; several messages across two conversations after one wake; a missed wake recovered by the next one; several communities; slow and unreachable relays return a fallback inside the time budget; two overlapping wakes, and the foreground app writing the shown record during a background run, never notify twice or lose a message. The ported body formatter runs the shared notification-body fixtures. Prior art: the iOS resolver tests in BuzzPushKit. +- **Relay.** The delivery URL setting accepts the platform-neutral route, in the existing relay configuration tests. +- **End to end.** Before readiness, exercise the real flow on a physical Android phone and an iOS device: enroll, receive a DM and a mention with the app killed, tap through, rotate the token, and sign out. + +## Out of Scope + +- Sender avatars in Android notifications. +- Push suppression based on desktop activity, which will be designed for all platforms together. +- Notifications for replies that don't mention you, or for general channel messages. New Android categories get added when those exist. +- UnifiedPush and phones without Google Play services (see ADR 0004 for why we're interested). +- Per-identity gateway grants. +- Event ids or encrypted content in the push. +- Moving the iOS notification extension onto the Dart code (see ADR 0006 for the memory condition). +- Phones without hardware-backed attestation, with an unlocked bootloader, or running a custom OS whose boot key isn't listed. + +## Further Notes + +- Real network latency over cellular is the main remaining performance risk; the prototype's relay ran on the same machine. +- Android deprioritizes apps whose high-priority pushes don't show a notification, which is why a slow fetch still ends in the generic notification. +- Each distributor sets up a Firebase project, registers its Android app, creates a service account for the gateway and records its signing certificate digests once. An agent can do most of this with the Firebase and Google Cloud CLIs, using a signed-in browser only for console-only steps. +- Known platform limits we don't control: after a user force-stops the app, FCM delivers nothing until the app is opened again, and some vendors' battery managers delay high-priority data messages. + +## Tickets + +Work blockers first. Each ticket is a vertical slice that can be verified on its own. + +1. **Platform-neutral delivery route.** The gateway accepts deliveries on a platform-neutral route, keeping the APNs route as an alias, and the relay's delivery URL setting accepts it. iOS keeps working. Blocked by: none. +2. **Gateway records installation platform and sends FCM wakes.** Adds the platform (derived from the attestation type) and per-platform endpoints, Keystore-signed installation calls, the FCM HTTP v1 sender (constant collapse key, time to live from the delivery expiry) and the Android configuration. Enrollment is tested end to end with a test-only attestation verifier, using a fake FCM sender. Blocked by: 1. +3. **Gateway verifies Android Key Attestation.** Adds Google roots, the revocation list refresh, the boot-state, boot-key list and app-identity checks, and the per-key rate limit. Tested with the table of rejected attestations. Blocked by: 2. +4. **Dart notification body formatter.** Ports the formatter to Dart, passing the shared notification-body fixtures. Blocked by: none. +5. **Dart wake-to-notification function.** Headless and journey-tested against a fake relay, returning every eligible unshown message, including the already-shown record, several messages after one wake, overlapping wakes and the fallback inside the time budget. Blocked by: 4. +6. **Android wake handling.** Firebase messaging service, the foreground check, background engine, the 2 s generic notification, deleted-messages handling, watchdog, categories, per-conversation grouping and tap-to-open, with wakes triggered locally, starting from the [prototype](https://github.com/block/buzz/tree/prototype/android-push-headless-dart). Verified on a physical phone. Blocked by: 5. +7. **Android enrollment and lease publication.** FCM token, Keystore attestation, enrollment, signed installation calls, token rotation, the permission prompt and sign-out revocation, wired into the shared push layer. End to end on a physical phone against a test gateway and relay. Blocked by: 3, 6. diff --git a/docs/adr/0004-push-gateway-hides-device-platform.md b/docs/adr/0004-push-gateway-hides-device-platform.md new file mode 100644 index 0000000000..659e37abd7 --- /dev/null +++ b/docs/adr/0004-push-gateway-hides-device-platform.md @@ -0,0 +1,16 @@ +# The push gateway hides each installation's platform from the relay + +A relay should learn as little as possible about the devices its members use, so that device details can't help correlate one person's identities. So a [push gateway](../../CONTEXT.md#push-gateway) serves one mobile app (an internal build, the public build or a fork's app) on every platform it ships on, rather than one gateway per platform. The installation's platform and push service live only inside the gateway-sealed grant, which the relay stores but can't read. The relay's push lease carries the same fixed `transport` value on every platform, uses one set of priority classes that the gateway maps to each platform, and follows the same renewal schedule on every platform. Every delivery request the relay sends goes to one platform-neutral gateway route and is the same whatever the device is. + +## Considered options + +- **One gateway per platform, with the relay choosing a gateway by platform.** It would keep the gateway's one-transport data model, but the relay would have to know each installation's platform. +- **Remove `transport` from the lease.** It would tidy the format, but released clients and relays require it, so removing it would need an ordered rollout across clients and relays. Since every platform sends the same constant, it tells the relay nothing, and the leftover value (which names APNs) is the accepted cost. + +## Consequences + +The relay still sees each installation's IP address and connection behavior, which correlate more strongly than platform does. This decision removes the one signal that the push protocol itself added. + +One installation still holds a single grant per relay, so two identities on one phone publish leases with the same opaque endpoint, and the relay can link them. Per-identity grants are out of scope for now, but we want to keep them possible. A fork can run its own gateway that issues them. Our gateway allows one delegation per installation and relay today, so offering them there later means relaxing that rule. + +Android installations use Firebase Cloud Messaging and require Google Play services. We are interested in also supporting UnifiedPush later, for Android phones without Google Play services (for example privacy-focused Android builds), which fits Buzz's privacy and self-sovereignty goals. That would mean the gateway posting wake signals to push servers its users choose, which brings its own security work. It becomes worth doing once Buzz ships outside Google Play. This ADR doesn't commit to it; it would be one more push service the gateway knows about, with no change on the relay. diff --git a/docs/adr/0005-android-push-enrollment-attestation.md b/docs/adr/0005-android-push-enrollment-attestation.md new file mode 100644 index 0000000000..b32f27b81e --- /dev/null +++ b/docs/adr/0005-android-push-enrollment-attestation.md @@ -0,0 +1,10 @@ +# Android push enrollment requires hardware key attestation of a trusted operating system + +The push gateway's enrollment endpoints are public and have no other authentication, so an installation proves it is the gateway's app on real hardware before it can enroll: App Attest on iOS, Android Key Attestation on Android. The gateway verifies Key Attestation offline, as it does App Attest, against Google's attestation roots and its published revocation list (the gateway's one periodic online fetch). The app identity in the attestation (package name and signing certificate) is filled in by the operating system, not the secure hardware, so it proves only as much as that operating system can be trusted. The gateway therefore accepts an attestation only when the hardware reports a locked bootloader and either a verified boot state of Verified (the phone maker's OS), or SelfSigned with a verified boot key on a list the operator configures. The list is empty by default, so a default gateway accepts stock Android only; an operator can add, for example, GrapheneOS's published per-device boot keys. Phones without hardware-backed attestation get no push; there is no software fallback. Every later installation call is signed with the attested key, as App Attest assertions are on iOS. Enrollment keeps its existing challenge quotas and adds a rate limit per attested key. + +## Considered options + +- **Play Integrity.** It would send Google a request for every enrollment, which works against Buzz's privacy goals, and it adds Google's server API and its quotas as a dependency. +- **Accept any locked SelfSigned phone.** Anyone can install a self-built OS with their own boot key and relock the bootloader, and that OS can claim to be our app. Attestation carries no stable device id and each enrollment makes a fresh key, so one such phone could script unlimited enrollments, bounded only by the deployment-wide challenge quota, whose exhaustion stops everyone else enrolling. +- **Stock Android only.** Simpler, with no list to maintain, but it excludes GrapheneOS, which Buzz's privacy goals make worth supporting. +- **Accept any boot state.** It would let more phones enroll, but a rooted phone could then claim to be any app, which leaves the endpoints open to the abuse attestation is meant to stop. diff --git a/docs/adr/0006-android-notifications-run-app-dart-code.md b/docs/adr/0006-android-notifications-run-app-dart-code.md new file mode 100644 index 0000000000..55126270c9 --- /dev/null +++ b/docs/adr/0006-android-notifications-run-app-dart-code.md @@ -0,0 +1,13 @@ +# Android notifications are built by the app's own Dart code + +On iOS, a native Swift notification service extension fetches and formats each notification. On Android, the push handler instead starts the app's Dart code in a background engine, without the UI, and that code fetches the message from the relay and builds the notification. This reuses the app's relay, sign-in and formatting code rather than porting the iOS extension to Kotlin. A prototype showed it fits Android's time limit for handling a push: on an emulator, the real text appeared about 0.1 s after a cold wake, and about 1 s with the CPU slowed 8x, against a budget of about 10 s. + +The handler posts the fetched notifications directly, because the category (and so the channel the user may have silenced) is known only after the fetch. If nothing is posted within about 2 s, it posts a generic notification in a separate "Other" category, which the real result replaces silently. A slow or failed fetch therefore still leaves a visible notification, and Android deprioritizes apps whose high-priority pushes show nothing. While the app is in the foreground the handler does nothing. Unlike the iOS extension, which can only rewrite the push it was handed, the handler posts every eligible unshown message it finds, grouped per conversation, so a wake means "sync now". The background path uses its own short network timeouts and a native watchdog, because the app's normal connect and sign-in timeouts are longer than the budget. + +## Considered options + +- **Port the iOS extension to Kotlin.** That means a second native copy of fetching, sign-in and formatting to keep in step with the app. + +## Consequences + +iOS could later share this Dart code too, but a notification service extension's memory limit (about 24 MB) is well below the background engine's footprint (about 57 MB in the prototype), so that needs its own measurement and work first.