Add or change a protocol feature
This page takes a feature from a .proto message to a button in the desktop
app. It follows one small feature that already exists: Ring phone
(capability ring, message RingPhone). Open the files named in each step
and copy the pattern.
A protocol change touches proto/, the Rust side and the Kotlin side in the
same pull request, together with the reference pages that describe it.
Before you begin
- Build both sides: see Set up a development environment and Build, run and install from source.
- Keep the wire protocol reference and the D-Bus API reference open next to the code.
- Decide whether the change needs an architecture decision record (see When you need an ADR). If it does, write the record first.
The steps cover frames on the control connection between the phone app and
the daemon. Messages between the daemon and the shell helper of the enhanced
tier live in proto/tether/v1/shell.proto. They are outside Envelope and
are negotiated through the abilities in ShellHello. The compatibility rules
below apply to them as well.
Overview of the path
proto/tether/v1/misc.proto message RingPhone
proto/tether/v1/envelope.proto Envelope.msg, field 102
|
+-- desktop/crates/tether-proto Rust types (prost, at build time)
| tether-core capability, gating, Core::ring_phone
| tetherd Features::ring_phone, D-Bus RingPhone
| tether-cli tether-cli ring <id>
| tether-gtk Backend::ring_phone, Overview row
|
+-- android/app Kotlin types (Wire, at build time)
transport/Protocol.kt capability "ring"
features/misc/RingController.kt handler
Write the contract
-
Define the message in the
.protofile of its feature area.RingPhoneis inproto/tether/v1/misc.proto:// Desktop -> phone. start = true plays the alarm ringtone at full volume with // vibration and shows a full-screen stop activity; start = false stops it. message RingPhone { bool start = 1; }State the direction and the semantics in the comment. If you create a new
.protofile, give it the same header as the others (package tether.v1,java_package = "org.tether.proto.v1",java_multiple_files = true), import it inenvelope.protoand add it to the file list indesktop/crates/tether-proto/build.rs. Wire on the Android side picks up every file underproto/by itself. -
Add the message to the
oneof msgofEnvelopeinproto/tether/v1/envelope.proto. Field numbers are grouped in blocks of ten per feature area:Numbers Area 10–13 session ( Hello,Ping,Pong,Disconnect)20–24 pairing 30–31 device information and battery 40–43 notifications 50–51 blobs 60 StreamOpen70–77 messages 80–82 contacts 90–93 media sessions and volume 100–105 Do Not Disturb, ring, connectivity, clipboard, share 110–113 files 120–127 photos 130–137 calls, call log, Bluetooth identity 140–145 enhanced tier, app side A message that belongs to an existing area takes the next free number in that block (
RingPhone ring_phone = 102;). A new area starts the next free block. -
Choose the capability. A feature is active only when both sides list its capability in
Hello.capabilities. Reuse the capability of the area when the new frame cannot be used without the existing ones. Add a new string when a peer could support one without the other (ringis separate fromdnd). Sub-features use a dotted name:messages.mms,calls.dial. -
Describe the contract in
docs/reference/protocol.md: a row in the “Capabilities” table and the behaviour in the section of the feature area (forring: “DND, ring, connectivity”). Include limits, timeouts and what the receiver does when it cannot comply.
Implement the desktop side
Rust types are generated at build time by
desktop/crates/tether-proto/build.rs with protox and prost-build. You
do not need protoc. After cargo build the message is
tether_proto::v1::RingPhone and the oneof case is
tether_proto::v1::envelope::Msg::RingPhone.
-
In
desktop/crates/tether-core/:File What to add src/lib.rsthe capability string in CAPABILITIES, which must matchProtocol.kton Androidsrc/session.rsan arm in required_capability(Msg::RingPhone(_) => "ring") and the frame’s name for the log inmsg_namesrc/device.rsfor a frame the peer sends to ask for something, a PeerRequestvariant (PeerRequest::Ring). For state the peer reports, anEventvariantsrc/core/mod.rsan arm in the dispatch matchthat turns the frame into the request or eventsrc/core/feature_flow.rsa typed send helper on Core(Core::ring_phone), which callsCore::sendtests/messages_contacts.rsa round trip between two in-process cores Core::sendrefuses a frame whose capability the peer did not announce (Error::Unsupported). Capabilities added in Milestone 3 and 4 are also checked on receipt (M3_CAPABILITIES,M4_CAPABILITIESinlib.rs, helpers insrc/core/call_flow.rsandsrc/core/enhance_flow.rs). Do the same for a new capability.To try the feature without a phone, teach
examples/fake_phone.rsto answer or print the frame. -
In
desktop/crates/tetherd/, add the feature logic to the module of the feature area undersrc/features/. Each module is animpl Featuresblock:src/features/misc.rshasFeatures::ring_phone, which sends the frame through the core, keeps theringingflag inMiscStateand announces the property change.- Events that arrive from the phone are routed to the feature in
Features::handleinsrc/features/mod.rs. - Data that must survive a restart goes into the per-device cache in
src/db.rs.
-
Expose it on D-Bus in
desktop/crates/tetherd/src/dbus/device.rs(theorg.tether.Device1interface) ordbus/daemon.rs(org.tether.Daemon1). Forringthis is the methodring_phone(RingPhone(b start)on the bus) and the propertyringing(Ringing). Signals are emitted from the feature code with thedevice_signal!macro, property changes withdevice_props_changed!(both insrc/features/mod.rs). -
Document every new method, property and signal in
docs/reference/dbus-api.md, in the section of the capability. In the pull request, state who can call a new method and what it can do (see the hardening checklist). -
Add the command to
tether-cliindesktop/crates/tether-cli/:src/proxies.rs: the method on theorg.tether.Device1proxy trait (fn ring_phone(&self, start: bool) -> zbus::Result<()>;).src/main.rs: a variant of theCmdenum (Cmd::Ring) and its arm in the commandmatch.
Describe the command in the command-line reference.
-
Add it to the desktop app in
desktop/crates/tether-gtk/. The user interface talks to aBackendtrait, which has a D-Bus implementation and an in-process fake:File What to add src/backend/mod.rsthe method on the Backendtrait (async fn ring_phone(&self, device_id: &str, start: bool) -> Result<()>;) and any new field of the device snapshot (ringing)src/backend/dbus.rsthe method on the zbus proxy trait and the Backendimplementation that calls itsrc/backend/mock.rsthe same method on the fake daemon, with plausible behaviour, and the capability in its capability list src/widgets/…the widget. ringis a row on the Overview page,src/widgets/overview_page.rsShow the control only while the device is connected and has the capability (
d.connected && d.has_capability("ring")).A method that is missing in the fake daemon breaks the
mockbuild, which screenshots and user interface work depend on. CI does not build that feature, so check it yourself:cd desktop cargo clippy --workspace --all-targets --features tether-gtk/mock -- -D warnings cargo run -p tether-gtk --features mock -- --mock
Implement the Android side
Kotlin types are generated at build time by the Wire Gradle plugin from the
same proto/ tree (wire { … } in android/app/build.gradle.kts). The
classes are in the package org.tether.proto.v1. An Envelope has one
nullable property per oneof case (envelope.ring_phone). All paths below
are under android/app/src/main/java/org/tether/android/.
-
Announce the capability in
transport/Protocol.kt, functioncapabilities(). Add it unconditionally if the feature needs no permission (add("ring")), otherwise only while the permission is held and the user has the feature switched on:if (settings?.syncContacts != false && Permissions.contacts(context)) add("contacts")Permission checks live in
core/Permissions.kt. -
Write the handler as a class that implements
Feature(transport/Feature.kt).features/misc/RingController.ktis the model:override suspend fun onMessage(session: Session, envelope: Envelope): Boolean { val req = envelope.ring_phone ?: return false if (session.peer?.has("ring") != true) return true if (req.start) start() else stop() return true }Return
falsefor frames that are not yours andtrueonce the frame is consumed. Ignore the frame when the peer did not announce the capability. UseonPairedto push initial state after a connection is established (features/misc/DndFeature.ktdoes this forDndState). -
Register the feature in
AppGraph.kt: aby lazyproperty and an entry in thefeatures = listOf(…)argument ofTetherEngine. -
Declare what the feature needs in
android/app/src/main/AndroidManifest.xml.ringaddedVIBRATE,USE_FULL_SCREEN_INTENTand the activityRingActivity(android:exported="false"). Every new permission gets a comment in the manifest that says why it is there. If the user sees a prompt or has to change a setting, describe it in Grant Android permissions and list the permission in Android permissions and grants. -
Add unit tests under
android/app/src/test/java/for logic that does not need a device (parsing, paging, diffing, encoding).
Keep the shared test vectors green
The protocol reference contains byte-exact test vectors that both
implementations check: the short authentication string (SAS, the six-digit
pairing code), the QR proof and a framed StreamOpen.
| Vector | Rust test | Kotlin test |
|---|---|---|
| SAS and QR proof (“Pairing”, “Test vectors”) | desktop/crates/tether-core/src/pairing.rs | android/app/src/test/java/org/tether/android/pairing/SasTest.kt, QrPairingUriTest.kt |
StreamOpen frame (“Test vectors (M2)”) | desktop/crates/tether-core/src/streams.rs | android/app/src/test/java/org/tether/android/transport/StreamManagerTest.kt |
-
If you change pairing, framing or a message that has a vector, the vectors must still pass on both sides. If you add something whose bytes both sides must agree on (a derivation, a hash, a frame layout), add a vector to
docs/reference/protocol.mdand a test for it in both languages. -
Run the checks of both sides as described in Test your changes.
Update the project records
-
Update, in the same pull request:
- Feature table: add or flip the row of the feature (tier, milestone, status).
- Roadmap: the status paragraph of the milestone, with what was and was not verified on a real phone.
CHANGELOG.md: a line under “Unreleased”, and whether the protocol change is additive.- The user guide, if a user can see the feature: the matching page under
docs/how-to/.
Compatibility rules
- Never renumber or reuse a field number, in
Envelopeor in any message. - When you remove a field, reserve its number (
reserved 4;) so that it cannot be reused by accident. - Add fields and messages. Do not change existing ones. A new optional field or a new message with a capability is compatible. Changing the type or meaning of an existing field is incompatible.
- Negotiate with capabilities. A peer that lacks a capability must never
receive the frames it enables, and must behave as before. The sender
checks the peer’s
Hello.capabilities. The receiver ignores frames for capabilities that were not announced. - The phone announces a capability only while it holds the permission behind
it. The list is fixed for the duration of a connection. The desktop treats
Hello.capabilitiesas the truth for that session and hides controls for missing capabilities. - An incompatible change needs an architecture decision record and a bump of
the protocol version:
PROTOCOL_VERSIONindesktop/crates/tether-proto/src/lib.rsandProtocol.VERSIONintransport/Protocol.kt. Its commit carries!and aBREAKING CHANGE:footer (see Submit a pull request). - Validate every length and index that comes off the wire. Frames are capped at 4 MiB and inline blobs at 256 KiB.
- Protocol constants (ports, timeouts, limits) are defined once per side and
match
docs/reference/protocol.md:desktop/crates/tether-proto/src/lib.rsand the modules oftether-corein Rust,transport/Protocol.ktin Kotlin.
When you need an ADR
Write an architecture decision record before the code when the change is expensive to reverse:
- the shape of the protocol: transport, framing, a new kind of connection, the pairing or trust model, an incompatible change,
- cryptography,
- a platform mechanism (a new Android service type, a hidden API, a kernel module, a new way to reach the phone),
- a dependency on a system service on either side,
- packaging or licence.
A message that is added to an existing feature area and follows a decision that is already recorded does not need a new record. Link the existing one in the pull request.