📚 Encyclopedia

Android · updated 2026-10-13

Syncing an SMS app with the Android telephony provider

androidsmsmmssynccontent-providerperformance

A third-party SMS app usually keeps its own database (Room in the Message app) and mirrors the system providers content://sms and content://mms. The provider is the source of truth for messages; the app database adds local-only state (blocked, pinned, starred, quarantined, private, drafts). Most bugs live at the seam between the two.

Incremental sync

Never blind-upsert rows that carry local state

Room's @Upsert replaces every column, including ones with defaults. Blocked conversations reappeared after every sync because SMS sync upserted a fresh entity with isBlocked=false. Use a targeted updateSyncFields() UPDATE for existing rows and a full insert only for new ones. Same rule for group membership: heal recipient lists grow-only, because the provider's canonical-address tables can transiently return fewer rows.

Read state

markRead that only zeroed the denormalized counter was undone by the next recount. Mark the message rows read and recount in one transaction, and mirror read=1 to the system provider.

Status transitions

Use MAX(status, :new) in the UPDATE so a late sync cannot move SENT back to PENDING; claim scheduled work with an atomic UPDATE ... WHERE status = 0 rather than check-then-act.

Imports bypass receive-time rules

Anything decided only in the receive path (spam quarantine, kid-mode blocking) is skipped by a provider import. A fresh install imported every existing thread as trusted. Apply the same gate to threads new to the app database during sync. See Unknown-sender quarantine and OTP exemptions for SMS.

Phone number normalization

Normalize only things that look like phone numbers (normalizeSafe). Email gateways and alphanumeric sender IDs must be kept as typed. Navigating to a thread id computed from the raw address while the send wrote under the normalized one created empty duplicate conversations.

Gotchas

See also

Linked from

Sources: message memory (project_bugs_fixed, quarantine_2026_09, project_sms_app), Message app v2.9.2 to v2.32.2