Package-level declarations

Framing (app.tether.core.Record, app.tether.core.RecordReader), P-256 keys and the handshake, the AES-GCM record layer, the control message envelope and its type names (app.tether.core.T), body types (SMS, contacts, calls) and the audio frame.

Types

Link copied to clipboard
class AudioFrame(val codec: Int, val seq: Int, val payload: ByteArray)

Audio channel frame: codec ‖ seq ‖ payload.

Link copied to clipboard
object Bytes
Link copied to clipboard
data class CallEntry(val id: Long, val num: String, val name: String?, val date: Long, val dur: Int, val type: Int, val sub: Int?)
Link copied to clipboard
data class CallInfo(val cid: String, val num: String, val name: String?, val state: String, val dir: String, val sub: Int?, val since: Long?, val cause: String?, val hold: Boolean, val tone: String?)

A call as clients see it (protocol §5 Call). tone: "busy" | "congestion" | "ended", the tone Android's own phone app would play for how the call ended; sent only with state "ended".

Link copied to clipboard
class CentralHandshake(staticKey: KeyPair, peerStatic: ByteArray, token: ByteArray?, ephemeral: KeyPair = P256.generate(), nonce: ByteArray = ByteArray(16).also { SecureRandom().nextBytes(it) })

Central side; used by tests and the Mac-side tooling.

Link copied to clipboard
data class Contact(val id: Long, val name: String, val phones: List<Phone>, val emails: List<String>, val photo: String?, val starred: Boolean)
Link copied to clipboard
object Ext

Extension messages (protocol §7): the reserved namespace, the capability fields and the limits. Extension types are not core types, so they are never listed in T; the registry in app.tether.core.ext applies these rules.

Link copied to clipboard
Link copied to clipboard
object G711

G.711 µ-law, bit-exact with the iOS implementation.

Link copied to clipboard
class HandshakeException(msg: String, val reject: Int? = null) : Exception
Link copied to clipboard
class Hello(val mode: Int, val ephemeral: ByteArray, val nonce: ByteArray, val staticKey: ByteArray)
Link copied to clipboard
Link copied to clipboard
object Kind

Record kinds (protocol §2).

Link copied to clipboard
class Message(val t: String, val b: JSONObject = JSONObject(), val id: Int? = null, val re: Int? = null)

Control message envelope (protocol §5).

Link copied to clipboard
object P256

P-256 helpers: X9.63 uncompressed encoding, ECDH, HKDF.

Link copied to clipboard
data class PairingCode(val peripheralKey: ByteArray, val token: ByteArray, val deviceName: String)

Pairing code tether1:<S_P>.<token>.<name>; the QR code holds its link form tether://pair?c=<S_P>.<token>.<name> (since 1.2: the iPhone's Camera app offers to open it in the app). parse accepts both.

Link copied to clipboard
class PeripheralHandshake(staticKey: PrivateKey, ephemeral: KeyPair = P256.generate(), nonce: ByteArray = ByteArray(16).also { SecureRandom().nextBytes(it) })

Peripheral (Android) side of the handshake. staticKey may be an AndroidKeyStore key. staticPublic is its X9.63 encoding.

Link copied to clipboard
data class Phone(val n: String, val type: String, val label: String? = null)
Link copied to clipboard
class ProblemReport(app: String, created: String, scrubber: ReportScrubber = ReportScrubber(), maxBytes: Int = MAX_BYTES)

A plain-text problem report (the same format in the Android phone app, the Android client and the iPhone app):

Link copied to clipboard
object Proto
Link copied to clipboard
class Record(val kind: Int, val body: ByteArray)
Link copied to clipboard

Accumulates stream bytes and yields complete records.

Link copied to clipboard
object Reject
Link copied to clipboard
class ReportScrubber(names: Collection<String> = emptyList(), keep: Collection<String> = emptyList())

Removes what identifies a person from text that goes into a problem report (logs, system values): phone numbers, e-mail addresses, full Bluetooth / MAC addresses (only the last two bytes stay), IP addresses, IMEI- or serial-like digit runs, long keys and tokens, and any names given (Bluetooth device names, the client's name, SIM and carrier names). Timestamps, versions, build fingerprints, durations, counters and percentages stay as they are.

Link copied to clipboard
class SecureSession(sendKey: ByteArray, recvKey: ByteArray)

AES-256-GCM record layer with strict per-direction counters (protocol §4). Thread-safe.

Link copied to clipboard
Link copied to clipboard
class SessionKeys(val th: ByteArray, val c2p: ByteArray, val p2c: ByteArray)
Link copied to clipboard
data class Sms(val id: Long, val thread: Long, val addr: String, val body: String, val date: Long, val box: Int, val read: Boolean, val sub: Int?)
Link copied to clipboard
object T

Functions

Link copied to clipboard
fun idRanges(ids: List<Long>): JSONArray

Ids as inclusive ranges, [first,last,…], ascending: how "these rows still exist" is sent on sync so a client can drop what was deleted (SMS and call ids are mostly consecutive, so this stays small).

Link copied to clipboard

Same key as the iOS PhoneNumber.matchKey: the last 9 digits (Persian digits included), so "+98912…" = "0912…".

Link copied to clipboard
fun <T> paginate(items: List<T>, maxWeight: Int, weight: (T) -> Int): List<List<T>>

Splits items into pages whose summed weight stays under maxWeight.