Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Connection protocol

A connection carries bundles and read-only requests between the CLI and the app over USB: through the USB accessory, or through adb. It adds convenience, not trust: the app treats everything it receives as untrusted input and runs Acceptance on every bundle. Both transports carry the same frames; only how a connection starts differs. Why it works this way is in Connecting.

The app serves a connection only while the phone is unlocked. While it is locked it answers with a BYE whose reason is locked, in place of the hello or of the next answer (Ending).

Transport

USB accessory (Android Open Accessory)

  • The CLI looks for a phone by its USB interfaces: MTP (ff/ff/00 named MTP), PTP (06/01/01) or adb (ff/42/01). It never sends the requests below to any other device. With --transport auto it does this only when no phone is reachable over adb.
  • It switches the phone into accessory mode with AOA requests 51 (get protocol, at least 1), 52 (strings) and 53 (start). The strings are manufacturer QuitLock, model QuitLock CLI, description QuitLock command-line tool, version 1, and an empty URI and serial. The phone comes back as 18d1:2d00, or 18d1:2d01 with adb.
  • Android starts the app’s AccessoryActivity for that accessory (res/xml/accessory_filter.xml), which has no screen; it opens the accessory and finishes. The app keeps it open, reading on one thread, until the cable goes: a closed accessory cannot be opened again while a read on it is still blocked.
  • Sync. Each connection starts with a sync record from the CLI: 16 bytes 00 'QuitLock-sync' 00 01, then a 16-byte random nonce. The app sends the same 32 bytes back and then the hello. The app discards everything before the record; the CLI discards everything before the answer (at most 4 MiB). A record that reached the phone while the app was not listening gets no answer; the CLI sends it again after 1.5 seconds without one. A different record arriving during a connection means a new computer took the cable: the app ends the old connection and answers the next copy.
  • Packets. Every write on either side ends in a short USB packet: a write whose length is a multiple of 64 is sent as two, the last byte apart. No side sends a zero-length packet. The app reads 16384 bytes at a time.
  • A connection ends with a BYE, a protocol error, or the cable going. After one ends the app listens for the next sync.

adb

  • The CLI first wakes the app: adb shell am broadcast --include-stopped-packages -a dev.t342.quitlock.LISTEN -p <application id>. The receiver requires android.permission.DUMP, which the shell has and no app can get.
  • The app then listens on a Unix socket in the abstract namespace named <application id>.session (so dev.t342.quitlock.session, or dev.t342.quitlock.dev.session for a dev build), until 30 seconds pass with no connection open. The CLI sends the broadcast again if it needs to.
  • The CLI reaches it with adb forward tcp:<port> localabstract:<name> and removes the forward when done.
  • The app checks the peer credentials of each connection and closes any whose UID is not the adb shell user (2000), without a hello. A dev build also accepts UID 0, because adbd runs as root on some emulator images.
  • Up to three connections at a time; a fourth gets a BYE with reason busy.
  • On an armed phone in a release build adb is on only during a debugging window (Connecting).

Frames

Each frame is a 1-byte type, a 4-byte length, then that many bytes of body. The length is at most 1 MiB. JSON bodies are canonical JSON.

TypeNameDirectionBody
0x01HELLOapp → CLIJSON, see 8.3. Sent once, first.
0x02REQUESTCLI → appJSON {"op":"status"}, {"op":"config"}, {"op":"waiting"} (Waiting change) or {"op":"log","from":<n>} (the event log). Read-only; no signature.
0x03RESPONSEapp → CLIJSON answer to a REQUEST.
0x04BUNDLECLI → appOne envelope, with nothing after it.
0x05APK_DATACLI → appA chunk of the APK for the preceding update bundle. At most 64 KiB per frame.
0x06APK_ENDCLI → appEmpty. All APK bytes have been sent.
0x07RESULTapp → CLIJSON, see 8.4. One per BUNDLE; for an update, sent after APK_END.
0x08BYEeitherFrom the CLI: empty, the connection is done. From the app: JSON {"reason":...}, see Ending.

An unknown frame type, an oversized frame or a frame out of order ends the connection.

Ending

The CLI ends a connection with an empty BYE, which the app does not answer. The app ends one itself with a BYE carrying a reason, sent in place of the hello or of the next RESPONSE or RESULT:

ReasonMeaning
lockedThe phone is locked. The CLI asks the user to unlock it and tries again for up to a minute.
busyToo many connections are open.
errorThe app failed while answering.

A reader treats any other reason as a plain end of the connection.

Hello

{"app_version":"0.1.0","build":"release","device_id":"514c…0d","last_seq":1799913600000,"mode":"solo","pairing":false,"protocol":2,"state":"armed"}
KeyValues
protocolConnection protocol version. 2 since 2026-12-01, when the phone began sending BYE with a reason and serving without a tap; the CLI refuses any other.
app_versionThe app’s version name.
buildrelease or dev.
device_id32 hex characters, or the empty string before enrolment.
statenot_owner (installed, not yet device owner), unarmed or armed.
modenone (no keys), solo or partner.
last_seqLast accepted sequence number; 0 if none.
pairingtrue while the phone waits for a re-pair enrolment. Added 2026-11-15; a CLI treats a missing key as false.
partner_readytrue while the phone is ready for a partner key (Who may do what). Added 2026-11-15, milestone 9; missing means false.

A phone that reports pairing accepts one enrolment, which must carry the device ID the phone already has. While armed, its config must be the one in force or tighter, so the CLI sends the config it reads with {"op":"config"}.

The hello is not signed and proves nothing. The CLI uses it for display and to pick the device ID for new bundles.

Status response

The answer to {"op":"status"}:

KeyMeaning
state, modeAs in the hello.
owner_keysThe enrolled owner public keys, 64 hex characters each; empty before enrolment. Added 2026-11-15.
partner_keyThe enrolled partner public key; present only in partner mode. Added 2026-11-15.
dns_host, delay_tierFrom the enrolled config. Absent until a config has been enrolled; never defaults.
self_checkA list of strings, one per problem the last self-check found while armed; empty if every policy was in place. Reading status runs no check.
pendingPresent only while an action is counting down: kind (config, key_add, key_remove, partner_remove, exit, key_replacement or update), remaining_ms, and deadline (Unix milliseconds, an estimate).
phone_secretsowner and partner, each present only when set: pin, password or (owner only) screen_lock. Added 2026-11-15, milestone 9.
waitingPresent only while a change waits (Waiting changes): type, approved and needs (lists of roles), expires (Unix milliseconds). Added 2026-11-15, milestone 9.

Waiting change

The answer to {"op":"waiting"} is {} when nothing waits, otherwise {"bundle":"<hex>","approved":[...],"needs":[...]}: the stored envelope (payload and its signatures, without any APK), and the roles. The CLI shows it with the same summary as inspect; a partner who approves adds their signature and sends the envelope back as a BUNDLE, which completes it (Waiting changes). The hex proves nothing by itself: the partner’s CLI checks the signatures it can and the phone checks them all again.

Result

{"code":"ok","effect":"delayed","deadline":1800086400000}

code is ok or a failure code from Acceptance. On ok, effect is immediate, delayed or waiting (Waiting changes; needs then lists the roles still to approve), and deadline (Unix milliseconds, an estimate for display) is present when delayed.