DEV Community

Cover image for How Inbo organizes SMS without a backend
Harish Kotra (he/him)
Harish Kotra (he/him)

Posted on AI-assisted

How Inbo organizes SMS without a backend

A useful SMS app has two jobs. It has to handle the basics every day, from receiving a long SMS to sending a reply on the right SIM. It also has to make an inbox full of receipts, verification codes, and delivery updates easy to navigate. Inbo puts both jobs in one native Android app. It handles SMS through Android’s telephony APIs and indexes, classifies, and searches messages on the device.

Inbo started as a fork of Clear SMS. I kept its telephony infrastructure, rule engine, sender directory, and parsers, then built Inbo’s inbox categories, OTP expiry, saved messages, Daily briefing, and bulk inbox controls on top. Pip, the mascot, appears at selected moments such as onboarding and empty states. The architecture is driven by a practical constraint. Android owns shared SMS history, while Inbo needs a separate place for everything it learns about that history. Inbo source · Clear SMS upstream

One shared history, one app-local projection

One shared history, one app-local projection

The system provider lets another default SMS app see the same raw history. Inbo's Room database holds a local copy for browsing and search, plus Inbo-specific information such as the category, extracted transaction amount, saved-message status, and reminders. Android provider identifiers tie the copies together. The database uses separate unique indices for SMS and MMS provider IDs, because the two providers can issue the same numeric ID for different messages.

The default role is an Android-managed grant. On Android 10 and later, Inbo asks the system to present the SMS role prompt. On earlier releases, the helper uses the telephony change-default intent. The onboarding flow and the Default SMS app row in Settings both use this helper.

fun createRequestIntent(context: Context): Intent {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        val roleManager = requireNotNull(context.getSystemService(RoleManager::class.java))
        return roleManager.createRequestRoleIntent(RoleManager.ROLE_SMS)
    }
    return Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT)
        .putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME, context.packageName)
}
Enter fullscreen mode Exit fullscreen mode

Settings checks the real role again after the prompt closes and when the app resumes. That matters when someone switches to another messaging app through Android settings. Android RoleManager

Delivery and import can happen at the same time

When Android delivers an SMS, Inbo decodes the PDUs, combines multipart messages, records receive time and available network send time, and tries to write the SMS provider row. If the provider write fails, a Room-only row keeps the message visible. The repository then checks blocking rules, classifies the text, and commits the message and any derived financial or reminder rows in one Room transaction. An exception during a derived write can roll back that unit of work.

The initial import and catch-up use WorkManager. The importer commits pages and resumes from a checkpoint. It may race a live broadcast for the same provider row. A unique provider ID and an insert that ignores conflicts let the repository reuse the row that committed first. It compares message identity before treating the conflict as a duplicate, since Android may reuse an ID after its row is removed. The same routing path handles recent caught-up messages and live arrivals. Historical SMS imported during onboarding stay quiet.

Outgoing SMS goes through Android’s SmsManager for the selected subscription, where available. For multipart messages, sent and delivery callbacks are tracked per part. A failure in one part fails the send, and Inbo reports delivery only after every part reports it. Picture MMS uses a separate carrier path. Its behavior depends on the network and Android configuration.

Classification needs explicit rules and useful fallbacks

A sender ID alone tells you who sent a message. The body tells you whether it’s a verification request, a bill coming due, or a completed debit. Inbo first evaluates user rules, then the bundled rules, sender directory, content signals, and contacts. Messages without a sufficient signal land in Unknown. Final checks protect recognizable OTPs and completed transactions from broad promotional rules while preserving explicit scam flags.

The evaluator works on a bounded prefix of the body. The original text stays available in the conversation. Rule loading rejects risky patterns such as nested unbounded quantifiers. Typed extraction lets a rule declare an amount or due_date and leave locale-sensitive parsing to Kotlin.

OTP expiry is a separate question from OTP detection. Inbo displays a deadline only when it finds one supported relative duration. A message that explicitly says “valid for 5 minutes” gives enough information. The parser uses network send time when available and plausible, falling back to device receipt time.

val receivedAt = 1_700_000_000_000L
val sentAt = receivedAt - 30_000L
val expiresAt = OtpValidity.expiresAt(
    body = "Your verification code is 482731. It is valid for 5 minutes.",
    receivedAt = receivedAt,
    sentAt = sentAt,
)
// expiresAt == sentAt + 300_000L
Enter fullscreen mode Exit fullscreen mode

Even where expiry is unknown, the original OTP can still be copied. The clipboard helper flags the clip as sensitive on supported Android versions. OTP expiry parser · OTP clipboard helper

Search the index, then page the results

Typing each new character should not require scanning every message body. Room maintains an external-content FTS4 table backed by the message table. Search uses prefix matching against indexed sender and body tokens and returns paged results. The UI gates very short input. The query builder treats punctuation as a separator and appends the prefix marker itself.

@Fts4(contentEntity = MessageEntity::class)
@Entity(tableName = "messages_fts")
data class MessageFtsEntity(
    val sender: String,
    val body: String,
)
Enter fullscreen mode Exit fullscreen mode

For example, SearchQueryFormat.toFtsMatch("parcel ZX81") produces parcel* ZX81*. Both prefixes must match. Searching for an arbitrary substring in the middle of a token has different semantics and is outside this FTS query. That trade-off keeps search-as-you-type useful without scanning the inbox on each keystroke. FTS entity · Query builder

Settings affect behavior as well as presentation

Preferences DataStore holds the choices users see in Compose. The router reads those choices before posting ordinary message, OTP, and train SMS alerts. Android’s notification channels still determine device presentation. Reminder alarms use AlarmManager and check the reminder setting before posting. Train alerts come from received SMS, with no network train-status service.

Periodic cleanup uses WorkManager and starts with every policy set to Never. While Inbo holds the SMS role, it applies independent age cutoffs for OTPs, promotions, and blocked messages. The repository selects eligible rows and deletes them in one local transaction. Saved messages are excluded in that query, so saving a message before cleanup selects it protects it from that operation. The existing deletion path handles the linked provider rows, attachments, and affected notifications.

What to test in a fork

An emulator seeded with synthetic SMS makes it easy to check parsing, filters, and notification routing. A phone with an active SIM is still the place to validate provider behavior, multipart delivery receipts, dual SIM selection, and carrier MMS. For a rule change, test a matching sample and a near-miss, such as a debit confirmation next to an OTP authorizing a debit. Run the checks used by Android CI.

python3 scripts/audit_rule_coverage.py scripts/demo/messages.jsonl
./gradlew ktlintCheck lintDebug testDebugUnitTest
Enter fullscreen mode Exit fullscreen mode

Good follow-up projects include search facets, optional saved-message labels, and more regional sender rules. Each can build on the existing local data paths. The repository keeps the original Clear SMS license and notices, with the exact upstream version and contribution steps in the README.

Code & more: https://www.dailybuild.xyz/project/325-inbo

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The bounded-prefix classification rule is the decision I would steal — parsing only a prefix and keeping the original text available is exactly the kind of restraint that keeps a local classifier honest. Same for refusing to show an OTP deadline when expiry is unknown instead of guessing one.

The part I would want to hear more about is the failure mode: what happens when one sender ID serves two categories, say a bank that sends both OTPs and marketing from the same sender? Does the rule evaluator fall back to body keywords, or does the sender directory win?

And on the search side — prefix matching on both tokens is fast, but how do you handle someone searching for a partial tracking number in the middle of a token?