Architecture
NightJar ships as one APK with two parts. The module runs inside Android’s phone service, com.android.phone.
The app runs as dev.nightjar and holds the history, the detectors, the notifications and your settings.
Runtime parts
Section titled “Runtime parts”| Part | Process | Work |
|---|---|---|
| Module | com.android.phone |
Records each message, identifies its type, applies the rules, holds or blocks |
| App | dev.nightjar |
Stores and explains events, runs detectors, sends notifications, manages rules and settings |
The app compiles your rules into a snapshot and sends it to the module. The module checks each message against the snapshot and sends what it sees back to the app as events. Events travel over a content provider. Rules, settings and commands travel over a binder. IPC describes both channels.
Vector or LSPosed loads the module through dev.nightjar.app.xposed.XposedEntry, which assets/xposed_init lists.
The module uses the legacy Xposed API 82, which both frameworks support.
Message path
Section titled “Message path”- The modem passes the PDU to the phone service, and the radio layer acknowledges it to the network. NightJar doesn’t change the acknowledgement, so the sender sees a blocked message as delivered.
- A capture hook, for example on
newSmsor the IMS listener, records the raw PDU. - NightJar’s head filter runs first in the
InboundSmsHandlerfilter chain. It identifies the type and checks the rules snapshot, which returns Allow, Notify, Hold or Block. WAP pushes, SIM data downloads, cell broadcasts and voicemail indicators have their own enforcement points. See Rule engine. - For Hold and Block, the head filter ends the message with
dropFilteredSms. The PDU travels to the app with the event, and for Hold the app keeps it so you can release the message later. - For Allow and Notify, Android continues as usual. Meaning hooks record which filter or app received the message.
- Each hook puts its observation into a lock-free queue of 4,096 entries. A worker thread joins the observations
of one message into a single event. The
NightjarIpcthread sends the events to the app in batches of up to 50. - The app stores the event, gives it a severity, runs the detectors and sends a notification if your settings ask for one.
Startup and connection
Section titled “Startup and connection”The module’s session moves through four states: LOADED, HOOKING, then RUNNING or UNSUPPORTED.
- Vector or LSPosed calls
XposedEntrywhencom.android.phonestarts. - The module installs its hooks on the main thread of the phone service. If the capture hooks fail, the module
removes all its hooks and the session is
UNSUPPORTED. - On its worker thread, the module wires the services that need the phone service’s context. It loads its stored copy of the last rules snapshot, settings and Blocking switch, so it can hold and block before the app connects.
- The
NightjarIpcthread sends ahelloto the app. The reply carries the rules snapshot, the settings and the Blocking switch. On a fresh boot thehelloarrives before the first unlock, when the app can’t read your rules. The module then keeps the stored copy. After you unlock, the app sends the current rules and settings. - The module then sends events, counters, hook health and log lines, one call at a time in that order of priority.
If the app isn’t running, refuses the call or was force-stopped, the module keeps recording. Events wait in a buffer of 1,000 events or 4 MB, and the module retries after 1 second, then backs off up to 60 seconds. When the buffer is full, the oldest event is dropped and the drop is reported with the next batch. After a reconnect, the module resends unacknowledged events in their original order.
The module stores the last rules snapshot, settings and Blocking switch in device-protected storage each time the app sends them, and loads them at startup. Blocking works after a reboot before the first unlock, and stays off if you turned it off. If a stored file is missing or can’t be read, the module uses the default for it: no rules, which allows each message, and blocking on.
Held messages and release
Section titled “Held messages and release”The app stores the PDUs of a held message. When you tap Release, the app sends the PDUs to the module with the
RELEASE command, up to 32 parts. The module registers a token for each part and then injects the parts in order,
so the released message arrives complete and isn’t classed as injected or held again. If a part fails, the module
stops and returns the error. The message stays on hold and the app shows the error.
The module refuses to release types that can’t be held, such as SIM updates and cell broadcasts, even if a rules file or the app asks for it.
Data in the app
Section titled “Data in the app”- The main database uses Room with SQLCipher. The key is 32 random bytes in app-private storage with mode 0600, so a root backup of the app restores a database that still opens.
- Before the first unlock, the main database isn’t available. The provider writes incoming events to a staging database in device-protected storage, capped at 500 events. The staging database keeps raw event JSON and no decoded text. After you unlock, the app moves the staged events into the main database.
- Schema changes use migrations. The app never deletes the database to upgrade it.
Fail open
Section titled “Fail open”If the module fails, Android handles the message as if NightJar weren’t installed.
- A catch-all wraps each hook callback. If NightJar’s code throws, the original Android method runs.
- Hooks don’t do I/O, binder calls, lock waits or file logging on the main looper or the radio HAL threads.
- Without a valid rules snapshot, the module allows each message.
- The head filter reports a message as filtered only after
dropFilteredSmshas run. - The module doesn’t change the network acknowledgement.
- When the event queue is full, the module drops new observations and counts them. Hook threads don’t wait. The Protection status screen shows the count.
Trust boundaries
Section titled “Trust boundaries”NightJar doesn’t trust the mobile network, other apps on the phone, or copies of the app’s data.
| Boundary | Control |
|---|---|
| Mobile network to module | The parser (pduparse) never throws, and a catch-all wraps each hook. |
| Other apps to module | The control binder accepts calls only from the app’s UID. |
| Other apps to app | The IPC provider accepts calls only from UID 1001, the phone process. |
| App with the same package name | The module checks the app’s signing certificate and sends no message content until it matches. |
| Copies of the database file | SQLCipher encrypts the database, and cloud backup is off. The key is in app-private storage, so a copy of the whole app data, for example a root backup, includes the key. |
| App to internet | The app has no internet permission. A build check fails if a change adds it. |
To report a security issue, see the security policy.
Gradle modules
Section titled “Gradle modules”| Module | Contents |
|---|---|
app |
The companion app (Kotlin, Jetpack Compose, Hilt, Room with SQLCipher) and the Xposed entry point |
payload |
Code that runs in the phone service: hooks, capture, firewall, IPC and the event store. No Android app dependencies. |
contract |
Wire names, IPC keys, message types (ClassId) and subtypes shared by the payload and the app |
rules |
The rules model, rule engine, presets and enforcement matrix |
pduparse |
A pure-Java parser for PDU, UDH, WSP, WBXML and OTA data that never throws |
decoder |
PDU and cell broadcast decoders in Kotlin, built on pduparse |
xposed-stubs, hiddenapi-stubs |
Compile-only API stubs |
buildSrc |
Gradle tasks for the quality checks |
The build compiles the payload to a separate dex, and a quality check inspects that dex.
Read next
Section titled “Read next”- Hooks: where the module attaches, and what happens when a hook is missing.
- Rule engine: how a message gets its action, and the safety limits.
- IPC: the channels between the module and the app.