Writing a replacement phone (dialer) app for Android
androidtelecomdialerincallservicecall-screeningrolemanagernotificationscompose
Any Android app can become the system phone app by holding the dialer role. Telecom then binds the app's InCallService for every call, hands it the call-screening hook and the shared block list, and routes tel: and Call-button intents to it. Justin's Phone app (io.jhampton.phone, Kotlin + Compose, no server, shipped 2026-10-15) is built this way. This article collects how the pieces fit and what could and could not be tested.
Becoming the default dialer
- Request
RoleManager.ROLE_DIALERwithcreateRequestRoleIntent. To qualify, the manifest needs activities handlingACTION_DIALboth with no data and withtel:, plusCALL_BUTTONandVIEWfor calls. - The
InCallServicedeclaresandroid.telecom.IN_CALL_SERVICE_UI = true. Leaving outIN_CALL_SERVICE_RINGINGmeans Telecom keeps playing the ringtone and vibration, so the app never has to manage ringing (or get it wrong). - No database of its own is needed: contacts, the call log, the block list and SMS all come from the system providers.
Incoming calls and notifications
- Show a CallStyle notification with a full-screen intent pointing at the in-call activity (
showWhenLocked+turnScreenOn). Unlocked phones get a heads-up card; locked phones get the full ring screen. - On Android 14+, sideloaded apps may not hold the full-screen-intent permission by default. Check
NotificationManager.canUseFullScreenIntent()and send the user to the setting from a setup card. - Answer must be an activity PendingIntent, not a broadcast: a broadcast receiver cannot start an activity (notification trampolines are blocked), and answering needs the call screen. Decline, Hang up, Mute and Speaker can be broadcasts.
- The ongoing-call notification is a plain notification, not CallStyle: CallStyle requires either a foreground service or a full-screen intent. See Android notifications and PendingIntent pitfalls.
- Dual SIM: when a call enters
STATE_SELECT_PHONE_ACCOUNT, the in-call UI must show an account picker and callphoneAccountSelected, or the outgoing call just hangs. - Decline with a text:
call.reject(true, message)makes Telecom send it through the default SMS app's respond-via-message service. Nothing to implement in the dialer beyond the menu.
Call screening
A CallScreeningService declared by the dialer role holder (guarded by BIND_SCREENING_SERVICE) is bound automatically, sees each incoming call first and must answer within 5 seconds, so do its lookups on a worker thread.
- Define "known" generously: in contacts, or dialed by the user in the last 30 days.
- Spam = the user reported the number, or the network's STIR/SHAKEN verification status is FAILED. Offer Warn / Silence / Block, defaulting to Warn.
- Neighbor spoofing (same area code and exchange as the user's own number) is only ever a suspect label, never an action: real neighbors share it too.
- Unknown callers: Ring / Silence / Send to voicemail. Rejecting uses setDisallowCall(true) + setRejectCall(true); the call still lands in the call log (type 6, "blocked").
- The block list is BlockedNumberContract, shared by the default dialer and the default SMS app (and usable only by them). The Message app and Phone therefore share one list without any code between them.
- Keep reported numbers on the phone, keyed by a normalized form (last 10 digits for North American numbers); match SMS threads to callers on the last 7 digits, then a stricter comparison.
Showing the caller's last text
Reading the newest SMS in either direction for the caller's number (needs READ_SMS, behind a setting) and showing it on the ring screen is cheap and useful: it answers "why are they calling" before picking up.
Testing on the emulator
Works: heads-up and locked full-screen ringing, answer, hold/resume, a second outgoing call, swap, merge into a conference with per-participant end/private, call log and missed-call badge, decline with text, screening rules (unknown caller sent to voicemail while a contact rang). Place inbound calls from the emulator console (adb emu gsm call <number>).
Not testable there: call waiting (the emulator modem drops a second incoming call during an active one), Bluetooth audio routing, the proximity sensor, the dual-SIM picker, STIR/SHAKEN labels, and the Android 14+ full-screen-intent permission for a sideloaded APK. After testing, give the dialer role back to the stock app.
Gotchas
- A long number wrapped under the keypad. A formatted number ("+1 405-773-0110") was wider than its row at 34 sp on a real phone;
maxLines = 1does not stop ComposeTextfrom wrapping when soft wrap is on, so the second line drew under the keys. Fix: no soft wrap, step the font size down to a floor until it fits, then drop leading digits behind an ellipsis (the end of a number is what the user is typing; this Compose version had no start ellipsis). Reproduced by giving the emulator the phone's real size and density (wm size,wm density). - A setup card above the keypad made the column overflow and squashed the call button, the last child measured. Put fixed-size controls first in measurement order or make the card scroll.
- Visual voicemail is carrier dependent and call recording is mostly blocked on modern Android; neither is a weekend feature.
See also
- Message, Justin's Android SMS app (architecture and decisions)
- Unknown-sender quarantine and OTP exemptions for SMS
- Android notifications and PendingIntent pitfalls
- Driving the Android emulator headlessly for QA
- In-app updates for sideloaded Android apps