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

About discovery and connectivity

The phone and the desktop have to find each other, stay connected for hours while the phone sleeps in a pocket, and find each other again whenever an address changes. This page explains how they do it, why the local network comes first, and why the phone app asks for the permissions and exemptions it asks for.

Finding each other

No single discovery method works on every home or office network, so Tetheron uses two at once.

The first is mDNS, the mechanism printers and media players use. Both devices announce a service named _tether._tcp. Routers mostly let mDNS through, and ordinary tools such as avahi-browse can see it, which helps when diagnosing a problem. The Debian and Ubuntu family already runs avahi-daemon on the mDNS port and a second responder would conflict with it, so the daemon publishes and browses through Avahi, which makes avahi-daemon a required package. The phone uses Android’s own service discovery. mDNS fails more often than it should: many access points drop or throttle multicast traffic to save power, guest networks and “AP isolation” block it, and Android’s implementation is unreliable on some manufacturers’ Wi-Fi drivers.

The second is a small UDP broadcast packet, the beacon, sent every five seconds. Broadcast gets through on some networks that mangle multicast. The beacon uses port 7360, the same number as the TCP port, so the firewall needs one entry for both. The desktop sends beacons whenever the daemon runs. The phone sends them only while the app is on screen, or for a minute after the screen turns on, because Android drops broadcast and multicast packets while the screen is off unless an app holds a multicast lock, and holding that lock costs battery. So the desktop advertises all the time and the phone usually finds the desktop.

ADR-0004 lists the other options that were considered, among them Bluetooth advertising and a rendezvous server.

Neither mechanism is trusted. An announcement is a hint to try dialling an address. Who is there is decided by the key in the TLS handshake; see About the security model. Both mechanisms tell everyone on the local network a device’s name and id. You can switch discovery off on the desktop, and paired devices still reconnect through the addresses they remember.

Neither mechanism crosses from one subnet to another, and some networks block both. For those cases you can enter the other device’s address by hand. A manual address is stored and dialled on every reconnect attempt, next to the discovered ones. Connect across networks has the steps. The pairing QR code also carries the desktop’s current addresses, so a phone that scans it can connect and pair where discovery is blocked.

Staying connected

Both devices listen on TCP port 7360 and either may dial. The phone may be unreachable for incoming connections while it dozes, and the desktop may be asleep when the phone comes home, so whichever device wakes up first restores the link. A design in which only the desktop listens was rejected for that reason. When both dial at the same moment, both sides apply the same fixed rule to pick the connection to keep.

Each side keeps a list of addresses for each paired device: discovered ones, manual ones and the last one that worked. When the connection drops, it dials them again, waiting one second at first and doubling up to a minute between attempts.

The connection itself shows whether it is alive. An idle connection carries a ping every 15 seconds, and a side that hears nothing for 45 seconds drops the connection and reconnects.

Why the local network comes first

Two devices behind different routers cannot find each other without a meeting point, and some pairs cannot connect directly at all and need a relay. A meeting point or a relay is a server. Someone has to run it, keep it up and deal with abuse, and a server that is on by default is a privacy decision made for you. ADR-0010 therefore sets this order:

  1. The local network first. Every feature works with no hosted service, and the features that need low latency (mirroring, calls, clipboard) work best there.
  2. A VPN or mesh network through a manual address. If you already run Tailscale, ZeroTier or WireGuard, your devices share a virtual network. Enter the phone’s or desktop’s address on that network and Tetheron works across the internet today. This is a supported configuration, and it stays optional.
  3. A relay, which is planned. You would be able to host it yourself. Devices would prove their identity to it with their keys and meet by the id of their paired peer. The relay would pass the encrypted bytes along without being able to read them, and would see only which ids talk, when and how much. A hosted default may be offered, but it stays off until you opt in.

The code already treats a connection as an opaque stream of bytes and does not assume the peer is on the local subnet, so the relay can be added without changing any feature or message.

Waking the phone through Google’s push service is ruled out for good. It would require Google Play Services and a Google cloud project.

Disconnecting on purpose

Both apps have a Disconnect button. In the first release it closed the connection, and the other side, seeing what looked like a network failure, reconnected within a second.

The app now sends a Disconnect message before closing. Both sides then hold: they stop dialling each other until you press Connect on either device. The pairing is untouched.

The hold is kept in memory only, so restarting the daemon or the phone’s service clears it. It stops outgoing dials and still accepts incoming ones: if one side has forgotten the hold because it restarted, its next dial is accepted and the hold ends on the other side too. A daemon or app that shuts down also announces it, with the reason “shutdown”. The peer does not hold in that case and resumes as soon as discovery sees the device again.

Two other designs were considered. “Pause sync” would keep the connection open and stop the features, but the phone would still show “connected” and every feature would need a paused state. Treating a disconnect as a temporary unpair would destroy the pairing for a passing wish. ADR-0012 records the choice.

How Android shapes the phone side

Android works hard to stop apps from running in the background, and a connection that must deliver a notification within a second is what it tries to prevent. Most of what the phone app asks for during set-up exists to keep that one connection alive. Grant Android permissions walks through the set-up, and ADR-0005 records the design.

The foreground service and its notification

The connection lives in a foreground service. Android requires such a service to declare a type and to show a notification for as long as it runs. Tetheron uses the type connectedDevice, which exists for apps that maintain a connection to an external device. The general-purpose type for syncing data is limited to six hours a day on Android 15, which rules it out.

That is why the app shows a permanent notification. It is silent and has the lowest importance. You can hide its channel in Android’s settings, and Android then shows its own generic notice.

The service restarts after a reboot and after an app update, and it redials when the network changes.

Battery optimisation

When the phone is idle, Android’s Doze mode suspends network access for most apps, apart from occasional maintenance windows. An app that is exempt from battery optimisation keeps its network access, so the app asks for the exemption. Without it, a notification can take minutes to arrive while the screen is off, and the link is restored when you turn the screen on. The app shows a warning while the exemption is missing.

The app does not hold the phone awake. It takes a wake lock only for the duration of a file transfer. A permanent wake lock was rejected because of the battery drain.

Notification access and restricted settings

Reading notifications needs notification access, which you grant in Android’s settings. For an app that was not installed from an app store, Android 13 and later may disable that switch until you choose Allow restricted settings in the app’s info page. The app detects the situation and shows the steps.

The companion device registration

Android lets an app register another device as its companion. A registered app is treated more gently in the background, and on Android 15 and later it is allowed to see notifications that contain one-time codes, which Android otherwise redacts for notification listeners it does not trust.

The app offers this registration during set-up where the phone allows it. On recent Android builds, a Samsung phone with Android 16 among them, the permission for the kind of registration that Tetheron needs is reserved for apps that the manufacturer preinstalls. There the step is skipped with an explanation, and the foreground service and the battery exemption keep the connection alive without it. On those builds, notifications with one-time codes reach the desktop only after the “sensitive notifications” grant, which is part of the enhanced tier.

Manufacturer app killers

Some manufacturers add their own limits on top of Android’s. Samsung puts apps to sleep after days without use unless they are listed under Never sleeping apps. Xiaomi needs Autostart to be allowed. No programming interface switches these, so the app can only guide you to the setting, and it does so only on phones from those manufacturers.

What was rejected

Scheduled background jobs run at most every 15 minutes and cannot hold a connection. Google’s push service needs a cloud service, which Tetheron does not have. Using an accessibility service to stay alive would be an abuse of an interface made for assistive tools.

The cost of the chosen design is a long set-up: a notification permission, notification access with the restricted-settings detour, the battery exemption and, on some phones, a manufacturer setting.