Skip to content

Latest commit

 

History

History
636 lines (506 loc) · 83.4 KB

TV.md

File metadata and controls

636 lines (506 loc) · 83.4 KB

The TV

The tablet talks to the household's Android TV box (a Xiaomi TV Box, "MiTV-AFKR0", Android 11) over two links on the home network, and, for volume and mute, to the Samsung TV the box is plugged into (a Q60AA 85", QE85Q60AAUXXN, Tizen 2021), which passes its sound to a soundbar on ARC. None of these links uses the internet; only What to watch (below) looks titles up online, on Watchmode, with the household's own key, and still sends the TV nothing but an app link.

Remote protocol (always) Debugging link ("What's playing", optional) Samsung TV ("TV sound", optional)
Code androidtv/ (AndroidTvRemote), app/.../drivers/TvController.kt, TvLocator.kt and Mdns.kt (finding the box) androidtv/.../playback/ (TvShell, MediaSessions, PlaybackLink) samsungtv/ (SamsungTvRemote, RenderingControl, SamsungSound), app/.../drivers/SamsungSoundController.kt
Protocol Android TV Remote v2, TLS, port 6466, paired with the code the TV shows Classic ADB over TCP, port 5555, an RSA key the TV allows once, through dadb 2.0.0 Samsung's remote WebSocket, TLS, port 8002, a token the TV hands out once Allow is chosen; UPnP RenderingControl, plain HTTP, port 9197, no pairing
Knows power, the app in front, the box's own volume and mute whether the app plays, is paused, stopped or loading; the position; sometimes the title the TV's volume (0..100) and mute, if they follow its keys (below)
Does every key, app launch, the box's volume, text, power nothing: one read-only command (below) volume up, volume down, mute; an exact volume over UPnP
Can't know whether anything is playing anything the app does not put in its media session what the soundbar does, if UPnP reports the TV's own speaker

Control goes over the remote protocol, except volume and mute, which go to the Samsung while it is paired and answering. The debugging link exists only because the remote protocol never reports playback. Where each part is checked on the tablet, and what was found, is at the end: On-device test and Results for this TV.

Finding the box

The app knows the box by who it is, not by where it was. Two things identify it: its mDNS service instance name, and the certificate its pairing accepted. The name is announced as _androidtvremote2._tcp, "Xiaomi TV Box" here, and kept at pairing as tvServiceName. The saved address (tvHost) is only a hint: the place to connect first.

The code is in three parts. TvLocator makes the decisions; it has no Android code and is tested on the JVM. AndroidMdns wraps NsdManager. TvController connects the two.

Why. On 30 November 2026 the box came back from a long sleep with a new DHCP lease (.55 → .58). The app kept the old address and said "The TV isn't reachable." The old rediscovery waited 30 s after the connection dropped, doubling up to 10 minutes. That wait also started again at every CONNECTING ↔ DISCONNECTED flip of the reconnect loop, which tries at least every 30 s. So the lookup never ran, not even in the 100 s after a restart of the app on the tablet. Nothing was logged either.

What runs. All of this runs only while a TV is paired and the app runs. Setup's list of boxes uses the same browse while it is open.

When What Cost
Always, while paired (TvLocator.watch) A browse for _androidtvremote2._tcp. When the paired box announces another address, that address is checked and followed right away, from the announcement itself. The browse starts over when the tablet's network comes back. Next to nothing (below)
The session drops, or the app starts (keepLooking) A look at once. Then one every 45 s while the box is away, on a fixed period from the first look; the reconnect loop's flips do not reset it. Also a look at once when the network comes back (NetworkWatch.back). A 3 s look: a fresh browse plus a resolve of the saved name, under a Wi-Fi multicast lock for those 3 s
A command while not connected (beforeSend): a key, an app link from What to watch, search, volume A look, and side by side an attempt at the saved address. The attempt uses AndroidTvRemote.retryNow, which skips the reconnect loop's wait of up to 30 s. The command goes ahead as soon as either one connects. At most one look (3 s), or one connection attempt (5 s) if that is longer
The box at the saved address refuses this tablet One look: another box may have taken the address One look

Android versions.

  • Android 14 and later (API 34+; the tablet runs Android 16). discoverServices runs the browse. Each service found is followed with registerServiceInfoCallback, which reports the address again whenever it changes, until the service is lost. A look also resolves the saved name directly with the same callback, without a browse.
  • Android 13 (API 33, the app's minimum). resolveService, once for each service found. Resolves run one at a time across the app, because it fails with FAILURE_ALREADY_ACTIVE while another is running. The 45 s looks cover address changes.
  • IPv4 only. Only IPv4 addresses are used. On Android 14+ getHost() can return an IPv6 link-local address; the old code could have saved one as the TV's address.

Cost. The browse is Android's own mDNS stack. It sends queries with a growing gap and listens to the network's announcements, and the app's code runs only when a box is found, moves or is lost. No multicast lock is held for the browse, so with the screen off the Wi-Fi chip may filter announcements; the looks, which hold the lock for their 3 s, cover that. While the box is away, a look is a few packets every 45 s: about 640 looks of 3 s in 8 hours with the box unplugged. While connected there are no looks at all. Android allows an app only a few NsdManager requests at once (FAILURE_MAX_LIMIT), and each service followed is one. So once a TV is paired and its service name is known, a browse resolves only the services under its names; other boxes are seen, but not resolved. Before pairing, Setup's list resolves them all. The Samsung's mDNS search (below) uses the same AndroidMdns, so the app has one NsdManager user.

Matching (TvRules.pairedCandidates, TvLocator.decide):

  1. Names, best first. The saved service name. Then the TV's name, from its certificate. Then either of them as mDNS renames a second box that announced a name already taken, for example "Xiaomi TV Box (2)".
  2. Still at the saved address. If the saved address is announced under one of those names, and the box there does not refuse this tablet, the box is there and nothing is checked.
  3. Somewhere else. Each other address under those names is checked, best name first. A check is one remote connection with this tablet's certificate, closed again with nothing sent (TvController.accepts). The first box that accepts it is followed: tvHost and tvServiceName are updated and the session moves there. A box that refuses the certificate is another box; it is logged and left alone.
  4. Two boxes that both accept this tablet (both paired with it): the better name wins.
  5. Other boxes. A box under another name is never contacted. A box under one of these names but unrelated is asked once, at most, whether it knows this tablet; it refuses, and the pairing certificate means it could never be controlled anyway.

Learning the name. A pairing made by typing the address has no service name. The TV's name comes from its certificate, and that is not the mDNS name. While connected, the service announced at the connected address is the paired box, so its name is kept. The same rule picks up a box that was renamed since.

What the household sees.

  • A command while the box is away.
    • "I can't find the TV on the network. Is it on?" when nothing announced it during the 3 s look and nothing answered at the saved address. The message comes after about 3 s, or at most one connection attempt (5 s).
    • "The TV isn't reachable." when the box is announced but its remote service does not answer.
    • "The TV no longer accepts this tablet. Pair it again in Settings." when the box refuses the certificate and the paired box is nowhere else.
  • Settings → TV. "On the network at …. Found by its name, so a new address needs nothing from you." This is information only; there is nothing to type. When the TV is away the line reads "Last seen at …". After a look that found nothing, the status reads "Can't find the TV on the network. Is it on? Still looking."

Logs. These are under the tag TvController, one line per event. Addresses show only their last part ("…58"). Examples:

  • Watch: browsing _androidtvremote2._tcp
  • Watch: 'Xiaomi TV Box' at …58 (the paired box's name)
  • Watch: 'Xiaomi TV Box' at …58 accepts this tablet: followed there from …55
  • The TV moved to a new address (…55 → …58); kept
  • Look (send): 2 service(s) seen ('Xiaomi TV Box', 'Bedroom TV'); the paired box is not announced (saved …55)
  • Watch: browse failed (code 0)

In the failure codes, 0–6 are NsdManager's FAILURE_* values. The app adds three of its own: -1, no NsdManager; -2, Android refused the call; -3, an Android 13 resolve gave no answer in 10 s.

Possible causes of the 30 November failure that were checked. None of these can be tested from the Mac; the logs above now show each case.

  • The flip-restarted wait (above). This was the cause: it alone is enough for the lookup never to run.
  • Android 16's local network protection. On Android 16 it is opt-in, and this app targets SDK 36. Once the address was right the remote connection worked, and the protection gates mDNS and sockets alike. A later target SDK will need ACCESS_LOCAL_NETWORK.
  • NsdManager in a secondary user (user 10). DNS-SD needs no permission. If the browse fails, the log now says browse failed.
  • A resolve that never answered. This can happen with concurrent resolveService calls on Android 13, as the old code made them; resolves now run one at a time. Android 14+ resolves through the callback.
  • No saved service name, or an IPv6 address. Both are possible with the old code. The name is now learnt while connected, and only IPv4 addresses are used.

The Samsung follows its TV by id (below, "Following the paired TV"). It is now also looked for at once in three cases: when the box answers again (the TV wakes with it over HDMI-CEC), when the box moves (a new lease for the TV too, perhaps), and when the network comes back. This is SamsungSoundController.lookAgain, using Rediscovery.HINT, and it applies only while the Samsung is not answering where it was. So after a night off it is found within seconds of the box waking, not at the next retry, which can be up to 30 minutes away. A volume request while the Samsung is away still goes to the box and starts a search; the next request goes to the Samsung.

Tests.

  • TvLocatorTest, against a fake network, fake boxes and a fake session, in virtual time. Documentation addresses (192.0.2.x) only, and nothing opens a socket. It covers:
    • an address change while connected, followed from the announcement itself;
    • a command while disconnected: looked up, followed, then sent;
    • a TV that is off, reported as not found after the 3 s look;
    • a TV that is announced but not answering;
    • two boxes with similar names, where the paired one is picked by its certificate;
    • another box at the saved address;
    • looks every 45 s without drift while the reconnect loop flips, and at once when the network comes back;
    • a name learnt while connected;
    • the browse starting over.
  • DriverRulesTest: candidates, renamed names, short addresses, and how the session's states map to the finder's.
  • AndroidTvRemoteEndToEndTest.retryNowEndsTheReconnectWaitAtOnce.
  • DiscoveryTest.aHintThatTheTvMayBeBackLooksAtOnceNotAtTheNextRetry.

On-device test: finding the box

With the box on and paired. A laptop with adb logcat -s TvController helps.

  1. Open the app. Within a few seconds the log shows Watch: browsing … and Watch: 'Xiaomi TV Box' at …NN (the paired box's name). Settings → TV shows the address under "Connected".
  2. Give the box another address in the router: change its DHCP reservation, or remove its lease and restart the box. As soon as it announces itself, the log shows … accepts this tablet: followed there from … and the TV is Connected again. Settings → TV shows the new address.
  3. Do step 2 again with the app closed, then open it. It is Connected within a few seconds of starting, because a look runs at once.
  4. Unplug the box, then say "pause the TV". After about 3–5 s the answer is "I can't find the TV on the network. Is it on?", and the log shows Look (send): … the paired box is not announced. Settings → TV says "Can't find the TV on the network. Is it on? Still looking."
  5. Plug the box back in. It is Connected within 45 s, or at once when a command is sent.
  6. Write down what happened, with the date, in "Results for this TV".

Switching the TV off with the box (HDMI-CEC)

"Turn off the TV" sends the box's power key over the remote protocol, so only the box sleeps unless the box is set to switch the TV off with it. On the household's Xiaomi box (Android 11) that setting was off (hdmi_control_auto_device_off_enabled=0): the physical remote switches the Samsung off (by IR) and the TV then puts the box to sleep over CEC, which is why the remote turned both off and the app only the box. Turning on works without it: the box wakes the TV with <Text View On> (one-touch play is on).

The box ignores KEYCODE_TV_POWER (tried 27 November: no CEC message, box stayed awake), so the fix is the box's own setting, turned on 27 November from the laptop:

adb -s <box>:5555 shell settings put global hdmi_control_auto_device_off_enabled 1

(or on the box: Settings → Device preferences → Inputs → HDMI-CEC → "Device auto power off", wording varies). After it, "turn off the TV" from the tablet sent the box to sleep and the box sent <Standby> to the TV: both went off. Side effect: whenever the box sleeps on its own (its idle timer), the TV goes off too. Set it back to 0 to undo. A reset box needs this again; the app cannot set it (its link to the box is read-only, dumpsys media_session only).

The debugging link ("What's playing")

The command allowlist

The debugging link has shell rights on the TV, so what it may run is fixed in code: TvReadCommand in androidtv/.../playback/TvShell.kt has one entry, and DadbTvShell checks the text again before it goes out.

Command Why
dumpsys media_session Lists each media session: its app, active, PlaybackState {state=…, position=…, updated=…} and metadata

Nothing else is ever sent: no key events, installs, file copies, settings or other shells. Tests pin this (TvShellTest): the allowlist is exactly that line, the real dadb client opens nothing but shell,v2,raw:dumpsys media_session against a fake adbd, and only TvShell.kt imports dadb and calls nothing on it but shell(). dadb is an implementation dependency of androidtv, so the app module cannot reach it at all. Mute is not read here: the remote protocol's mute flag matches the TV's own (dumpsys audio, checked on the box).

What the app does with it

  • Home (every layout's TV card, Clock first's TV line, the remote panel): playing or loading shows Pause and sends the PAUSE key; paused, stopped or nothing playing shows Play and sends PLAY. Only when the state is not known (the link is off or not set up) is it the combined Play/pause sending the toggle. After a tap the button shows the expected state at once; the next reading confirms it, and if the TV never follows the key the real state is back after 4 s. The line reads "TV · Netflix · paused", "· playing" or "· loading", and "· muted" when the TV is muted; Mute becomes Unmute while muted.
  • Assistant (control_tv in core/.../HomeTools.kt): with the state known, "pause" on a paused TV answers "It's already paused." without sending anything ("It's already playing.", "Nothing is playing on the TV." likewise); otherwise the discrete key is sent and the reply waits up to 3 s for the TV to report the change: "Paused." only if it did, else "I pressed pause, but the TV is still playing." The toggle becomes the key that is needed. With the state unknown, keys and replies are as before. home_status says "Netflix is paused on the TV.", "The TV is playing The Crown on Netflix.", "… Nothing is playing.", "It's muted." Which tool to call stays with the models; only the tool's execution uses the state.
  • Stop on apps that can't stop: each session advertises its actions (actions= in the dump, PlaybackState.ACTION_*). YouTube (382) and Netflix (1049468) don't offer stop and ignore the key; Prime Video does. When the app in front offers no stop, "stop the TV" pauses it instead: "Paused. YouTube can only pause, not stop." This is read from the TV, not a list of apps. Fixtures: androidtv/src/test/resources/media_session/android11-{netflix,youtube}-{playing,paused}.txt (27 November, the household's box; YouTube's title replaced).
  • The session that matters (MediaSessions.nowPlaying): the TV's current app's session (an active one with a state first); else the most recently updated playing one (music behind the home screen). State 0 on the app in front reads as stopped: after Stop, Prime Video stays in front with state 0 (seen on the box). Titles that only name the app ("PrimeVideo") are dropped.

Polling

Only while the remote protocol is connected and says the TV is on; stopped as soon as it is off. Every 2.5 s while the app is in front or the assistant is listening, every 15 s otherwise, every 0.5 s for 4 s after a play, pause, stop, next or previous key. One connection is kept open between reads.

Setup (Settings → TV → What's playing)

Off until set up. The steps, as the app shows them:

  1. On the TV, open Settings → Device Preferences → About, and press Build 7 times until it says you are a developer.
  2. Go back to Device Preferences → Developer options. Turn on USB debugging, and Network debugging (it may be called ADB debugging).
  3. Press Connect here. On the TV, tick "Always allow from this computer" and choose Allow.

The tablet's key is generated once and kept in the app's private storage (files/drivers/tv-link/adbkey). "Disconnect and forget the key" turns the link off and deletes it; Developer options → "Revoke USB debugging authorizations" removes it from the TV too.

Android 11's pairing-code Wireless debugging (TLS, _adb-tls-pairing._tcp) is not supported: dadb has no TLS transport. The household's box offers classic network debugging on port 5555, which is what this uses. A TLS transport would be another TvShell.

Failure modes

All quiet: playback goes back to "not known" (the plain Play/pause button and today's replies), and Settings says why.

Settings says When What the link does
Waiting for the TV to be on TV off or the remote not connected nothing
Not connected yet: follow the steps, then press Connect switched on, never allowed nothing: it never opens a connection with an unknown key by itself, so the TV never asks by surprise
Waiting for you to allow it on the TV Connect pressed, the TV is asking waits up to 2 minutes
Connected — reading what's playing reading polls as above
Not available: turn on network debugging on the TV nothing answers on port 5555 tries again every minute (after Connect, waits for the next Connect)
Not allowed on the TV. Press Connect and choose Allow denied, not answered in time, or the TV no longer allows the key waits for Connect
Lost the connection. Trying again… a working connection stopped answering (a hung read is cut after 8 s) reconnects after 2 s, doubling to a minute

The dump is a debugging format, not an API; the parser (MediaSessions) reads the lines every version prints (ownerPid=, package=, active=, state=, metadata:), with fixtures from the household's box (Prime Video idle, playing, paused) and from AOSP's format for Android 9 (metadata: without a space) and 14 (state=PAUSED(2), a session id in the header).

Search on the TV, and what's on it

Direct TV search is YouTube only (when What to watch is off; when What to watch is on, non-YouTube voice searches look up titles on Watchmode instead). "Search the TV for The Bear", "search YouTube for cat videos" and the remote panel's Search YouTube field open YouTube on the TV on its results for the words; the results and choices are on the TV's screen. With What to watch off, "Search Netflix for The Bear" (or any other app) sends nothing and says how to ask instead. The tablet looks nothing up on the internet and uses no catalogue or other service; the words go to the box in YouTube's link, which the box's YouTube app opens as it would a link from a phone. Only the remote protocol's app-link launch is used. No developer tool on the TV is used for this; the read-only "What's playing" link above is only read by "what's on the TV". Why the other ways were dropped is below, in "What was tried on the box".

The tools (core/.../HomeTools.kt; their sentences are tv_search.* in replies.properties):

  • search_tv(query, app?): "Search on the TV for a film, series, person or topic, in one TV app or across the whole TV." The description and parameters are what FunctionGemma v7 was trained on and stay byte for byte as they are (TvSearchTest.theSchemasAreAsDesigned, PromptsGoldenTest); only what the tool does changed. query is the user's words (one line, at most 100 characters).
  • tv_status(): "Say what the TV is doing: whether it is on, which app is showing and what is playing." Off, not reachable, on and the app in front (the remote protocol's current app), and with the "What's playing" link set up and reading a session, the title and playing, paused or loading, and muted. The sentences are home_status's ("The TV is playing The Crown on Netflix."). It never sends a key. A title is whatever an app put in its media session, so the answer is spoken and never handed back to the language model (untrustedOutput).

How a search goes (SearchTvTool, TvSearch):

  • No app, the TV itself, or YouTube (app left out; a TV phrase such as "the TV"; or a name that open_tv_app resolves to com.google.android.youtube.tv, from the household's names or the catalog's): https://www.youtube.com/results?search_query=<words> goes to the box once as an app link (Command.LaunchApp; the words URL-encoded as a form value, spaces as +, & as %26, é as %C3%A9). The launch is trusted: nothing waits for the TV to report YouTube in front, no key is pressed and nothing is typed, so the answer is at once: "Searching YouTube for the bear." The same with YouTube already in front, when the box sends no new "app in front" report.
  • Any other app, or one nobody knows (Netflix, Prime Video, Disney+, HBO Max, YouTube Kids, "Zattoo"): nothing is sent. "I can only search YouTube on the TV. Say "search YouTube for the bear"." (not done, ok = false).
  • No words: "What should I search for on the TV?" The TV off: "The TV is off. Turn it on, then ask again." (as before; open_tv_app does not turn the TV on either). A TV that cannot open links (no APP_LAUNCH): "The TV can't do that." The box not answering: the driver's own sentence ("The TV isn't reachable.").

Until 29 November 2026 a search pressed SEARCH and typed the words through the remote protocol's text input, and for YouTube sent the link and waited up to 8 s for the box to report YouTube in front, searching the whole TV when it did not. With YouTube already in front no report came, so the wait ran out and SEARCH opened the Google Assistant on top of the results. The typing path (typeIntoSearch, Command.SearchTv, the per-app table tv/search.json and its probe states) is gone; AndroidTvRemote.sendText and textFieldsFocused stay for Command.TypeText and the search probe.

Who calls them. The remote panel's Search YouTube field (label "Search YouTube", button "Search", read by TalkBack as "Search YouTube on the TV") calls search_tv with no app through the tool registry, as the assistant does, and shows its sentence under the field (read out by TalkBack); it is there for a TV that opens app links (Capability.APP_LAUNCH). By voice, which tool and which words are FunctionGemma's choice, never a word list. Both tools are first taught in data v7 (ToolSpec.firstCommandData = 7); the app gives the command tier only ToolRegistry.specsFor(ModelSpec.commandData), and the shipped FunctionGemma v7 (commandData = 7 in ModelCatalog.COMMAND_TIER) is given both. An older file is not, its answers are parsed against its own list only (so search_tv … from v6 would be "not understood"), and the short prompt names no tools, so it is byte for byte the same either way (PromptsGoldenTest, CommandTierToolsTest, TvSearchCommandTierTest).

The command model today (the shipped nlu/assets/nlu/en, 29 November 2026; TvSearchCommandTierTest). Most search and "what's playing" requests are other and reach FunctionGemma ("search the tv for the bear", "search netflix for the bear", "find the bear on netflix", "what's playing on the tv", "what is the tv showing", "what's on netflix"). Three it grabs, left for its next training round rather than patched with words:

  • "search for the bear on the tv" → tv_open_app (0.94, app "bear"): "I don't see bear on the TV…";
  • "search on the tv" → tv_on (0.90);
  • "what's on the tv", "what's on tv" → list_show (0.96, 0.91): it reads the shopping list.

Iteration 14 (29 November 2026) tried to teach these with training data and was not shipped: its one variant that kept every test set's total also stopped asking which lamp for "dim the lamp" (NLU.md, iteration 14). "Search disney plus for frozen" opens Disney+ without searching, the same kind of grab (EvalTest.KNOWN_GAPS).

FunctionGemma v7 was trained when other apps were searched too, and its data's earlier-turn replies are the old sentences ("Searching the TV for …", "Opening Netflix and searching for …"); a later round should be taught the YouTube-only replies.

What was tried on the box

The test box: a Xiaomi Google TV box, Android 11, with Projectivy as its home screen, and Google TV Home and the Google Assistant disabled. Tried on 29 November 2026 with the search probe below and the app:

What Result
YouTube's results link, https://www.youtube.com/results?search_query=<words>, as an app link Works: YouTube opens on the results; the box reports YouTube in front about 0.4 s later. With YouTube already in front, no new "app in front" report arrives.
The SEARCH key Opens the Google Assistant only (nothing, now that the Assistant is disabled).
The Assistant's typed search Cannot search what to watch: that needs Google TV Home, which is disabled.
Netflix's search, https://www.netflix.com/search?q=<words> No search link: the https /search address is not in the Netflix app's intent filters, so it is not routed to the app.
Netflix's nflx://…/search Netflix exits, or ignores it.
A Netflix title link with ?source=30 Works (opens the title page). Not used by search.
Prime Video, Disney+, HBO Max No search link known; not searched.

Still to try: "what's on the TV" with the "What's playing" link on and off.

Search probe

app/src/androidTest/.../TvSearchProbe.kt found the results above, and stays for the next question. It runs while someone watches the TV, in the app's process, and uses the app's own paired session (TvController; it never pairs, and fails with a message if the app has no paired TV) and only the remote protocol: keys, remote_ime_batch_edit and app-link launches. No adb to the box; no POWER, no volume key; it ends on HOME. It reconnects once so the handshake (remote_configure features, IME bit included, remote_set_active, remote_start, volume) is logged, then logs every message the box sends with its time (AndroidTvRemote.inboundListener, debug only, null in the app; pings only counted) and every message sent. Steps: 2 SEARCH from home; 3 type probe, ENTER, DPAD_CENTER; 4 BACK, BACK, HOME; 5 long SEARCH, KEYCODE_ASSIST, KEYCODE_VOICE_ASSIST; 6 YouTube's results link, Netflix's search and title links, the app's own "open Netflix"/"open YouTube" (catalog link, then market://launch after 5 s) and both market://launch links, each timed until the box reports an app in front (only remote_ime_key_inject names it); 7 SEARCH, text and ENTER inside YouTube; 8 a table of step → messages → current app. Each step prints STEP n: <what to look at>.

./gradlew :app:assembleDebug :app:assembleDebugAndroidTest
adb install -r -d --user 10 app/build/outputs/apk/debug/app-debug.apk
adb install -r -d --user 10 app/build/outputs/apk/androidTest/debug/app-debug-androidTest.apk
adb shell am instrument -w --user 10 -e class dev.privateassistant.app.TvSearchProbe -e pause 6000 \
  dev.privateassistant.app.test/androidx.test.runner.AndroidJUnitRunner

-e pause (ms between steps, default 6000), -e capture (ms listened to after each key, 6000), -e poll (ms waited for the app in front after a launch, 12000); -e script "KEY;wait:1500;text:probe;link:https://…;app:Netflix;long:SEARCH" runs only those steps, in order, for a short probe. The lines print as they come, are logged under TvProbe (adb logcat -s TvProbe) and are kept in the app's files/probe/tv-search.txt. About four minutes with the defaults.

What the remote protocol can and cannot do

From the research behind these tools (29 November 2026). [D] marks what a vendor documents, [C] what a forum or GitHub project reports; anything else is unconfirmed and must be tried on the TV first.

  • App links. remote_app_link_launch_request looks like a plain ACTION_VIEW on the URI, resolved by the app that claims it [C]. That is why market://launch stopped working: the Play Store resolves it, and the change was on Google's side (androidtvremote2 #46) [C]. intent: URIs are not accepted ("You can only send URLs", #17) [C], so there is no known way to send ACTION_SEARCH with a query, or START_PLAYBACK.
  • Playback. An app starts playing only when told android.intent.extra.START_PLAYBACK=true (Android blog, 2017) [D], which a URL cannot carry. Over this protocol "play" means: open the title page, wait for the app to be in front, press DPAD_CENTER. YouTube watch?v= links play [D]; a Netflix title page needs ?source=30 [D]; Prime Video, Disney+ and HBO Max title links are unreliable [C]; a "Who's watching?" profile screen can stop any of them.
  • Typing. remote_ime_batch_edit types into whichever field has focus [D], with the IME and field counters taken from remote_ime_key_inject and remote_ime_show_request, as androidtvremote2 does since its fix for #51 [C]. The global search box appends text while some apps replace it (#32) [C]; Netflix's search may have no IME field at all. Search no longer types (above).
  • The SEARCH key opens search or the Assistant on Android 11 Google TV; newer Google TV builds open a voice-only Gemini panel (universal-remote-card 4.12.3) [C]. On the household's box it opens only the Assistant, which cannot search what to watch without Google TV Home (29 November 2026, above).
  • The box's own global search has no known URL form; android.search.action.GLOBAL_SEARCH with a query is an ADB command [D], and the tablet runs nothing on the box.

Considered and not built (decided 29 November 2026):

  • A catalogue of what to watch (cards on the tablet, "play it"). The TV's own search and apps are the source of truth instead. Of the sources compared, TMDB's terms forbid use "in connection with … a machine learning (ML) or artificial intelligence (AI) based Application"; JustWatch sells its API to businesses only and forbids scraping; Trakt's availability data is limited; the Streaming Availability API (a free key per household) was the candidate. Reversed on 30 November 2026: built as What to watch, with Watchmode and the household's own key. TMDB and JustWatch stay unused.
  • The TV's own voice search fed with audio (remote_voice_*, implemented in androidtvremote2 0.3.0): it would send the household's voice to Google through the TV, and gives the tablet no result.
  • Launching the Samsung TV's own apps: it switches the TV away from the box's input. samsungtv/ stays volume and mute only.
  • Developer tools on the box for new features. Only keys, text input and app links; the read-only "What's playing" link is the one exception, and "what's on the TV" may read it.

The household's TV apps

The remote protocol cannot list the apps installed on the box: it reports only the package of the app in front. So the household's TV apps (Settings → Your home → TV apps, HomeConfig.tvApps) are learned: every app the box reports in front is added (TvController → TvRules.learnCurrentApp → TvApps.learn), named from the catalog (TvAppCatalog) or, for an app it does not know, from its package. An app installed but not opened since the tablet was paired is therefore missing until it is opened once (on 30 November 2026 that was Disney+ on the household's box).

  • Launchers are not apps. Home screens are entries of the catalog flagged launcher (Google TV Home, Android TV Home, Leanback, Projectivy com.spocky.projengmenu, FLauncher, Fire TV Home, AOSP's): they are never learned, never added by hand, never offered on the remote, by voice or to the models. Settings, the screensaver, the assistant and makers' system apps stay a short prefix list (TvApps.isSystem).
  • Tidied at start (TvApps.tidy, in AppGraph's start): a list kept by an older version loses any launcher or system package, and a name that was only made from the package becomes the catalog's (ch.rsi.player was "Player"; it is "RSI Play"). A name the household chose stays.
  • Add an app the TV has (Settings → TV apps): every app in the catalog that is not on the list (by any of its packages, or another build of one), as one-tap choices, narrowed by typing; or a name or package typed in. Added by hand, an app is one of the TV apps at once (What to watch offers Play on TV for it).
  • Try on TV (What to watch, below) adds the app when the box shows it after the link.
  • Catalog apps added on 30 November 2026: Play Suisse (ch.srgssr.playsuisse, not seen on a TV yet) and RSI Play (ch.rsi.player, seen on the household's box).

Tests: TvAppsTest (launchers never learned or added, the tidy, catalog names, the choices), DriverRulesTest (Projectivy in front is not learned), TvAppsScreenshotTest (61-settings-tv-apps-add-from-catalog.png).

What to watch (Watchmode)

Films and series are looked up on the tablet with Watchmode using each household's own free API key, stored encrypted on the tablet; the country is configurable (Switzerland by default, plus Spain); tapping a result or selecting it by voice opens that title on the TV box by app link. JustWatch (no public API) and TMDB (terms prohibit AI apps) are not used. The TV is still sent only app links over the remote protocol: no adb, no intent extras.

Code: core/.../watch/ (WatchmodeClient, WatchLinks, WatchChoices with WatchPicks, WatchOnTv), core/src/main/resources/tv/watch-links.json, app/.../watch/WhatToWatch.kt, app/.../data/ApiKeyVault.kt, app/.../ui/WhatToWatchPanel.kt, app/.../ui/WatchSettings.kt, app/.../voice/Dictation.kt (the search field's microphone), the TV strip on Home (TvStrip in app/.../ui/HomeScreen.kt).

Watchmode's API, as checked on 30 November 2026

From the OpenAPI description (version 1.11.0, openapi.json, which the docs page renders), llms.txt, llms-full.txt (every service with its id and countries), pricing, the terms (updated 24 October 2026), app deep links and the key sign-up page. Nothing was called with a key: the app's tests use answers written from the documented examples (core/src/test/resources/watchmode/).

What Watchmode documents What the app does
Base and key https://api.watchmode.com/v1. The key in the X-API-Key header ("recommended"), or Authorization: Bearer; the ?apiKey= query parameter is "legacy … prefer X-API-Key" X-API-Key, so the key is in no URL
Title search /v1/autocomplete-search/?search_value=…&search_type=2 (titles only): name, relevance, type, id, year, result_type, imdb_id, tmdb_id, tmdb_type, image_url. /v1/search/?search_field=name&search_value=… gives title_results (id, name, type, year, IMDb and TMDB ids) without images. 1 credit each Autocomplete, on Find only (never per keystroke): ranked by relevance and forgiving of a partial name. At most 12 titles; people left out
Types movie, tv_series, tv_miniseries, tv_special, tv_movie, short_film Film (movie, TV movie, short), Series (series, miniseries), TV special
Where it streams /v1/title/{id}/sources/?regions=CH: one row per service and country: source_id, name, type (sub, rent, buy, free, tve), region, web_url, ios_url, android_url, tvos_url, android_tv_url, roku_url, format, price, seasons, episodes. 1 credit with a Watchmode id. "Requested regions must be enabled for your plan" Asked for the chosen country only
Links on the free plan web_url is a link. ios_url and android_url are the sentence "Deeplinks available for paid plans only."; tvos_url, android_tv_url, roku_url "TV links available for paid plans only." Only web_url is read; the TV link is made from it (below)
Top picks: /v1/list-titles/ Filters by types, regions, source_types, source_ids, genres, dates, ratings, people; sort_by popularity_desc among others ("Watchmode's normalized popularity percentile"); limit 1–250; answer titles (id, title, year, imdb_id, tmdb_id, tmdb_type, type, popularity_percentile), page, total_results, total_pages. "1 per requested region per page; 1 when regions are omitted" regions=<country>&types=movie,tv_series,tv_miniseries&sort_by=popularity_desc&limit=12: 1 credit. No source_ids or source_types: they would tell Watchmode which services the household has
Top picks: /v1/releases/ "Recently released or upcoming releases on major streaming services … Primarily US release dates, though most major services release globally on the same day." start_date, end_date (default yesterday to 30 days ahead), limit 1–250; answer releases (id, title, type, season_number, source_release_date, source_id, source_name, is_original, poster_url, IMDb and TMDB ids). "1 credit per page". No country The last 14 days, limit=100: 1 credit. Kept on the tablet: only releases on a service in watch-links.json (US-only services such as Hulu are left out), one card per title, the household's TV apps first
/v1/sources/, /v1/regions/ Services: id, name, type (sub, purchase, free, tve), regions, logo_100px, android_scheme, host_source. Regions: country, name, flag, data_tier, plan_enabled. 1 credit each Not called: the ids are in tv/watch-links.json
Countries 436 services in 54 countries, Switzerland and Spain among them. The free plan has "streaming sources in up to 3 countries", chosen at sign-up Switzerland and Spain; more are a line in the data file
Services in CH and ES (llms-full.txt) Netflix 203 (all 54), Prime Video 26, Amazon (rent and buy) 24, Disney+ 372, HBO Max 387, AppleTV+ 371, AppleTV (rent and buy) 349, Paramount Plus 444 (CH), Play Suisse 616 (CH), Movistar+ 456, RTVE Play 653, Atres Player 546, SkyShowtime 464, Filmin 457 (all ES), among others Mapped in the data file
Free plan 2,500 credits a month; "120 requests/minute on the free plan"; headers X-RateLimit-Limit, X-RateLimit-Remaining, X-Account-Quota, X-Account-Quota-Used Searches kept 10 minutes in memory, sources 24 hours on disk
Errors 401 bad key; 429 "account quota, concurrency or request rate limit exceeded" (with Retry-After when supplied); 404 title not found; JSON with statusCode/statusMessage or errorMessage. No 402 is documented Fixed sentences; after a 429 (or a 402) nothing is sent for a minute; 404 is "nowhere to watch it". The server's own text is never shown
Terms Free plan: "Non-commercial use, with attribution": "Free use must credit and link to Watchmode.com wherever its data is displayed." Use in "a software application that you own"; no reselling or sharing the data with third parties; free-plan data cached at most 30 days; all data deleted when the account is cancelled "Data from Watchmode", a link to watchmode.com, on the panel and its Settings page, and in the licences. Each household uses its own key in its own app. The cache is deleted with the key or the switch
Images Poster and image_url fields "may point to a third-party host. Watchmode does not grant any license to the underlying image"; "Direct linking (hotlinking) to images hosted on Watchmode's CDN … is prohibited." The examples use a placeholder host; cdn.watchmode.com serves logos and flags No posters: text cards (name, year, film or series). No image host is on the allowlist

Note on regional accounts: what a sources request returns for a country not enabled on the user's Watchmode plan (an error vs an empty list) and the exact web_url shape for services outside Netflix, Prime Video, and Disney+ are handled conservatively: recognised shapes build a direct title link, while unknown shapes fall back to opening the app.

On the tablet

  • Where: the What to watch button on Home's TV strip (for a paired TV that opens app links, while the strip is shown; it opens the panel straight away, whatever state What to watch is in), and the TV remote's own button, which opens it in place of the remote. Settings → Your home → TV → What to watch holds its settings.
  • Off, no key, or a key that cannot be read: the panel explains itself and offers Set up in Settings; nothing is sent.
  • Top picks, before any search: "Popular in Switzerland" (9 cards) and "New on streaming" (6 cards, "Series · Season 2 · Netflix", "On your TV" in words for the household's apps, which come first), then "Updated 09:14". The lists are kept on disk and fetched again only when older than 12 hours, so opening the panel normally costs nothing and they cost at most 4 credits a day. Offline or over quota, the last lists are shown with their time (kept at most 7 days); after a failed attempt nothing is asked for 30 minutes. A card opens the title as a search result does; Back returns to the picks.
  • Search: type a film or series and press Find (or the keyboard's search key), or say it: the microphone in the field. Results are cards: the name, then "Series · 2022". "Looking…" on the button while it waits; "Nothing found for “…”."; the tablet offline, the key refused, too many requests or Watchmode not answering: one fixed sentence each (watch.* in replies.properties).
  • Saying the title (Dictation, the field's microphone; hidden with Voice off): a tap listens for one phrase, a second tap ("Stop listening") ends it; the field says "Listening… say the title" with the voice level under it, then "Getting the words…". What was said fills the field and is looked up at once, as Find would: the household asked to search by voice, and a misheard word is corrected by typing and Find (a search costs 1 credit; the same words again cost nothing for 10 minutes). Nothing heard: "I didn't catch a title. …". It is the app's own voice loop, as for a request: one take recorded as "Teach it your voice" records them (VoiceController.beginDictation, recordTake), with the wake phrase not listened for meanwhile and a request under way cancelled, recognised on the microphone thread by the same recognisers (Android's on-device one or Moonshine; VoiceController.recognise), so the audio stays on the tablet. The words are only typed into the field: never handed to the assistant, not shown in its bar, not kept in the heard list or the log. The TV is turned down while it listens, as for a request. Android's RecognizerIntent dialog is not used: on some tablets it sends the voice to Google.
  • A title: "On your TV in Switzerland": the services whose app is in the household's TV apps (Settings → TV apps; a hidden app counts, it is still on the box), subscription and free first, then with a TV login, rent, buy; the formats and seasons beside each. Each has Play on TV, or Open when no link could be made from the address. Whether a service's link was opened on the household's box (verified) is kept as data only: the button and the reply are the same. Apps the TV hasn't shown yet lists the services whose app is in the TV app catalog but not among the TV apps (installed and not opened since pairing, or not installed: the tablet cannot tell), each with Try on TV. Not on your TV lists services with no known TV app in the secondary colour, without a button: it answers "where is it?" and sends nothing. Search YouTube for this sends YouTube's results link for the title, as the remote's search does. Back (or "‹ Results", "‹ Top picks") returns without a new request.
  • Play on TV (WatchOnTv): the link once, as an app link, trusted like YouTube's search link; the reply is at once ("Opening The Bear on Netflix on the TV."). With Press OK on the profile screen on (off by default), the OK key follows PROFILE_OK_DELAY_MILLIS (4 s) later for a "Who's watching?" screen. The TV off, unable to open links or not answering: the usual sentences; nothing more is sent.
  • Try on TV: the link (or the catalog's package) once, the same way, never followed by OK; "Sent The Bear to Disney+ on the TV. Checking that Disney+ opens…". Then the package the box reports in front is watched, read only, for 10 s (WatchOnTv.arrival, TvController.currentPackage): when it is the app (or another build of it), the app is added to the TV apps (TvApps.learn, as the TV driver does for every app in front) and the panel says "Disney+ opened on the TV, so it's one of your TV apps now."; otherwise "Disney+ didn't open on the TV. The app may not be installed there." Nothing more is sent either way.
  • Settings → Your home → TV → What to watch: Find what to watch online (off by default); Your Watchmode key: a masked field (paste or type; never kept in the screen's saved state) and Save key, then only "•••• " and its last four characters with Replace and Remove (asks first); Country: Switzerland, Spain (from the data file, named in the tablet's language); On the TV: Press OK on the profile screen.
  • By voice (WatchVoice, WatchVoiceChoice): when Find what to watch online is on, non-YouTube search_tv requests (no app, "the TV", Netflix, Disney+, …) search Watchmode on the tablet instead of sending YouTube's link (saying "search YouTube for …" and the remote panel's Search YouTube button still open YouTube directly).
    • A single exact title match fetches its streaming options at once, opens the numbered What to watch panel on the tablet (WatchVoicePanel, leaving the AssistantBar visible underneath) and asks e.g. "The Bear is on Disney+. Open it on the TV?" (or lists the TV's apps when several have it). Multiple title matches show up to six numbered cards (1–6) and read the first three aloud.
    • While the results are on screen (up to 90 s, or until dismissed), spoken or typed choices — a number or ordinal ("1", "the second one"), a service name ("Netflix", "Disney plus"), a title name, confirmation ("yes", "play it"), or cancellation ("no", "never mind") — are resolved by app code (WatchVoice.tryHandle, using pack words from values.json's watch table) before the command model or FunctionGemma runs. Picking a title from a numbered list by voice opens it straight on the TV when a single household TV app (or the app asked for) has it — no second "Open it on the TV?" confirmation — and asks which app only when several apps carry it or the app has not been tried yet. Saying "play it" on an options card opens the suggested title instead of pressing OK, speaking "Opening The Bear on Disney+ on the TV." Any unrelated command ("turn off the kitchen") dismisses the choices and passes straight to the assistant. Every card and Play on TV button stays touchable too.

The key

  • Sealed: AES-256-GCM with a key generated in the Android Keystore (AndroidKeystoreCipher, alias privateassistant.watchmode, no user authentication, a fresh IV from the Keystore for every write), in no_backup/watchmode/key (a version byte, the IV, the ciphertext). Never in settings.json, a backup (the app backs up nothing, and the no-backup folder never), a diagnostics report, a log or a screenshot. It is opened for each request and not kept in memory; Settings keeps only its last four characters.
  • A damaged file, a restored one or a reset Keystore: the key reads as missing, and the panel and Settings say "The saved Watchmode key can't be read on this tablet any more. Enter it again …"; nothing is sent.
  • Removing it deletes the file and every answer kept from Watchmode. Switching the feature off deletes the answers too.
  • Tests: ApiKeyVaultTest (with a fake cipher, as Robolectric has no Keystore: nothing of the key in the file, a fresh IV per write, remove deletes the file, a damaged or foreign file reads as no key, nothing stored that is not a key), WhatToWatchScreenshotTest (the key never on screen, in settings.json or in a log line).

Putting the key on the tablet

  1. Get a key: sign up at api.watchmode.com/requestApiKey (free, no card). When it asks for countries, choose Switzerland and Spain (the free plan allows three).

  2. Type or paste it in Settings → Your home → TV → What to watch → Your Watchmode key → Save key, then switch Find what to watch online on.

  3. Or import it without typing (test code only, in the androidTest APK: ImportWatchmodeKey). Put the key alone in a file on the laptop, then:

    adb push watchmode.key /data/local/tmp/watchmode.key
    adb shell am instrument -w --user 10 -e class dev.privateassistant.app.ImportWatchmodeKey \
      -e file /data/local/tmp/watchmode.key -e country CH -e enable true \
      dev.privateassistant.app.test/androidx.test.runner.AndroidJUnitRunner
    rm watchmode.key

    It stores the key through the app's own ApiKeyVault, deletes /data/local/tmp/watchmode.key (through the instrumentation's shell, also when something fails) and reports only "stored, ends in ••••XXXX" and whether the file is gone; if it says it could not delete it, run adb shell rm /data/local/tmp/watchmode.key. -e country (CH or ES) and -e enable true are optional.

The key never goes into git, a log, a diagnostics report or a chat; tests use a made-up one.

Network and caches

  • Its own door to the internet: an AllowlistHttp open to api.watchmode.com alone, and only while the switch is on (the app's other doors never allow it). https only, no redirects, 8 s timeouts, a User-Agent naming the app and its version. Only when the switch is on, a readable key is stored and the network is validated.
  • Sent: the words of a search, a title's id with the country, and the key in its header; for the top picks, the country, the types, two dates and the sizes. Not sent: the household's apps or services (no source_ids), names, or anything else.
  • Kept: searches 10 minutes in memory (the same words again send nothing); a title's sources for a country 24 hours in no_backup/watchmode/sources; the top picks in no_backup/watchmode/top, fresh for 12 hours and kept at most 7 days. Both are purged whenever touched and at start, so nothing comes near the free plan's 30 days.
  • Credits: each search and each title opened (once a day) 1; the top picks at most 4 a day. A household that opens the panel daily and looks at a few titles stays well under the free plan's 2,500 a month.
  • Logged (tag WhatToWatch): api.watchmode.com: HTTP 200, … HTTP 429, … failed (SocketTimeoutException). Never the key, a URL, the words or a title.

TV links per service (tv/watch-links.json)

A service is "on your TV" when one of its packages is in the household's TV apps, and "to try" when its first package is an app in TvAppCatalog (every service in the file is; WatchLinksTest checks it). The link is made from Watchmode's web_url only when its host is one of the service's own, and is always https; anything else gets no link, and the button opens the app instead. verified records which links were seen to open the title on the household's box; the screen does not show it.

Service (Watchmode ids) App on the box web_url → link sent to the box Opened on the box
Netflix (203) com.netflix.ninja netflix.com/[cc/]title/<id> or /watch/<id> → https://www.netflix.com/title/<id>?source=30 Yes (29 November 2026, the title page)
Prime Video (26), Amazon rent and buy (24) com.amazon.amazonvideo.livingroom the amzn1.dv.gti.<uuid> in a primevideo.com or watch.amazon.*/amazon.* address → https://app.primevideo.com/detail?gti=<gti>; an address with only an ASIN gets no link Yes (30 November 2026, Play on TV)
Disney+ (372) com.disney.disneyplus passed through (https://www.disneyplus.com/browse/entity-<uuid>) Yes (30 November 2026, Play on TV), although the box's app had been seen to list only / and /f/open-in-app
HBO Max (387) com.wbd.stream (com.hbo.hbonow) passed through (play.hbomax.com/movie/<uuid>; play.max.com before 2025) No
Apple TV (371 Apple TV+, 349 rent and buy) com.apple.atve.androidtv.appletv passed through (tv.apple.com/<cc>/movie/<slug>/umc.cmc.<id>) No
SkyShowtime (464) com.skyshowtime.skyshowtime.google passed through (www.skyshowtime.com/<cc>/stream/…) No. The box's app was seen to list only /deeplink
Movistar Plus+ (456) es.plus.yomvi passed through (ver.movistarplus.es, www.movistarplus.es) No
RTVE Play (653) com.rtve.androidtv passed through (www.rtve.es) No
ATRESplayer (546) com.a3.sgt passed through (www.atresplayer.com) No
Play Suisse (616) ch.srgssr.playsuisse (package not checked; in TvAppCatalog since 30 November 2026) passed through (www.playsuisse.ch) No
YouTube (369) com.google.android.youtube.tv watch?v=<id> or youtu.be/<id> → https://www.youtube.com/watch?v=<id> No (its results link is)
Filmin (457), MUBI (181), Paramount+ (444), Pluto TV (391), Rakuten TV (417), Crunchyroll (80) as in TvAppCatalog passed through on their own hosts No

Tests: WatchLinksTest (each rule from sample addresses, foreign hosts, credentials, ports, placeholders, intent: and other schemes refused, every service's app in TvAppCatalog, the verified three), WatchChoicesTest (country, one row per service and offer, on the TV, to try and elsewhere, sub and free before rent and buy, other builds and hidden apps, the app recognised when the box reports it, the top picks kept on the tablet), WatchmodeClientTest (what is sent, the caches, every failure, the log; the top picks by country and dates only, kept 12 hours, the last ones kept while they cannot be fetched, deleted with the key), WatchOnTvTest (the link once, OK only when asked and after the delay, no "untested" wording, Try on TV and the 10 s watch), DictationTest (one take, its text tidied, nothing else, Voice off), WhatToWatchScreenshotTest (the screens, 61-watch-set-up.png to 69-watch-mic-results.png in app/build/screenshots/: top picks, Try on TV adding Disney+, the microphone filling the field without the assistant), WatchFromHomeTest (the strip's button in every layout, upright and at font sizes 1.3 and 2.0, 71-home-strip-watch-*.png). Watchmode's answers are written from its documented examples (core/src/test/resources/watchmode/); no test calls the real API.

Still to do on the box

Open one title per service by its link with the search probe (-e script "link:<the link the panel sends>;wait:6000", while someone watches the TV), for the household's services not tried yet: HBO Max, Apple TV, SkyShowtime, Movistar Plus+, RTVE Play, ATRESplayer, Play Suisse. For each, write here whether it opened the title, the app's home, or nothing, and whether a profile screen came first; set "verified": true in tv/watch-links.json for those that open the title (data only), and change the rule for those that need another form. Measure how long Netflix's profile screen takes after a cold start, to check the 4 s of Press OK on the profile screen. Check that Play Suisse's package on the box is ch.srgssr.playsuisse (Try on TV adds whatever the box reports). Still to verify in live use: what /v1/list-titles/ with regions returns on the free plan (the docs say nothing against it), and how many of /v1/releases/' US-dated titles are also in Switzerland and Spain.

Ducking: the box's own volume while listening

While the assistant listens, the box's own music volume (STREAM_MUSIC, 0..15) is lowered and then put back. The box's volume is what the room hears through the TV and the soundbar: on 26 November 2026, with Netflix playing, 15 → 9 for 3 s was clearly quieter in room testing. The box reports its level, maximum and mute over the remote protocol (remote_set_volume_level, AndroidTvRemote.volumeInfo, which matched dumpsys audio on the box), and its volume keys change STREAM_MUSIC (adjustSuggestedStreamVolume in its dumpsys audio). So this needs nothing from the Samsung and is exact.

  • How far: to 60 % of the level (TvRules.DUCK_FRACTION), and at least 2 steps down (DUCK_MIN_STEPS): 15 → 9, 10 → 6, 5 → 3, 3 → 1. A share rather than a fixed number of steps keeps a quiet TV from going silent and a loud one from staying loud. 15 → 9 is the step tested on the living-room TV.
  • How: volume keys, one at a time, each waiting for the box to report the new level (AndroidTvRemote.setVolume). Lowering from 15 takes about six key presses; the box shows its volume bar meanwhile.
  • Restore: to exactly the level from before, but only if the level is still where ducking left it (or where a volume command below left it). The box's volume is read before restoring, and compared with the level ducking reached, as the box reported it after the last key; so the duck itself never reads as someone else's change. If the level moved for another reason (the TV's own remote), theirs stands.
  • Volume commands while it is lowered (TvDuck.command; the assistant's "volume up", "set the volume to …", "mute", and the remote panel's volume and mute keys, whenever they go to the box): they count from the level from before, so the restore does not undo them. With "Listen for a follow-up" on, listening (and so the duck) lasts through the answer, which is when this matters; without it the restore starts as soon as the request is heard, and the command waits for it and applies from the household's level.
    • Up or down moves the box from where ducking left it at once (heard, and the box shows its bar), and the restore goes to the level from before plus the same steps, within 0..15: from 12, lowered to 7, "volume up" (3 steps) is 10 while listening and 15 afterwards; the panel's key one step at a time the same way. Before 29 November 2026 this ended at 10, below where it started: the restore saw a level it had not left and stood aside.
    • An exact level ("set the TV volume to 33") is set at once and ends the duck: nothing is restored afterwards.
    • Mute stays muted after listening: the restore's volume keys would unmute the box, so the level from before is kept, and put back when it is unmuted, by "unmute the TV", the panel, or the TV's own remote (the box reports it, TvDuck.resume). Mute and unmute within one turn: the level from before comes back as usual.
    • What is kept (TvDuckStore) changes with the command, before the first key and again once the box reports where it got to, so a crash after "volume up" puts back the new level, and after an exact level nothing.
    • The Samsung is never ducked: when it is the route, its volume and mute commands go to it, the box's duck and restore go on unchanged, and nothing undoes the Samsung's change. A requested step counts on the box's 15-step scale, so on the Samsung each one is 3 key presses (TvRules.SAMSUNG_PRESSES_PER_REQUESTED_STEP): a default "volume up" (3 steps) is 9 of its 100, where it was 3 of 100 and could not be heard against the box coming back up by 6 of 15. A remote-panel tap stays one press, like the TV's own remote.
  • Limits. A change on the TV's own remote while lowered cannot be told from one that is: the remote protocol reports the new level, not who pressed. So it stands as it is (lowered + their steps), not counted from the level from before. While the box is ducked with the mute key (the fallback below), "mute the TV" answers "already muted" (the box reports itself muted) and listening's end unmutes it. Home's volume shows the lowered level while listening.
  • Kept across a crash: the level from before is written to the drivers' store (files/drivers/tv-duck, TvDuckStore) before the first key, not to the settings, so ducking does not rewrite them. A duck an older version kept in settings (AppSettings.tvDuck) is moved there once. After a crash or restart mid-duck, the next time the box is connected, on and reports its volume, the level is put back (TvDuck.resume). A crash part-way down restores from anywhere on the way down.
  • Mute as the fallback: only when the box reports mute but no usable level, or when its keys do not move the level (a fixed-volume output). As before, it then mutes only a box that is on and not muted, and unmutes only if it is still muted.
  • Left alone: a box that is off, not reported, muted by someone, or at level 0.
  • Only the latest call counts: listening stopping half-way through the lowering stops it there and restores from there; listening starting again half-way through a restore stays where it got to. Listening again while still lowered (a follow-up) does not lower it again. Everything runs under one lock (TvDuck), and the box's own volume commands wait for it, so "volume up" said right after listening applies after the restore, from the household's level. One restore per turn: once it is done nothing is kept, and the next turn lowers from the new level.

Unit tests: TvSoundTest (app; ducking against a fake box), DriverRulesTest (the rules), AndroidTvRemoteEndToEndTest.setVolumeStopsWhenToldTo.

The Samsung: volume and mute

Why. "Turn the TV volume up", "mute the TV" should change what the room hears. Volume keys sent to the box change only the box's own volume (adjustSuggestedStreamVolume in its dumpsys audio), and nothing goes out over HDMI-CEC: the box's CEC history showed no <User Control Pressed> (tested 26 November 2026). So the box cannot reach the soundbar. The Samsung can: its remote's volume keys go to the soundbar over ARC.

Routing (TvSoundRouter, TvRules.soundOp). The TV's commands that are volume or mute (AdjustVolume, SetVolume, the VOLUME_UP, VOLUME_DOWN and MUTE keys from Home and the remote panel) go to the Samsung while it is paired, answering and still allows the tablet. Otherwise, or if it stops answering before anything was sent, they go to the box as before. Routing is by command, never by words: which tool and arguments stays with the models. Ducking stays on the box (above).

Pairing (Settings → TV → TV sound). Opening the section searches the network once (below, "Finding the Samsung") and lists the Samsung TVs that answered, by name and model ("Samsung Q60AA 85 · QE85Q60AAUXXN"). Choose one, or, if none is listed, type its address under Enter its address (the TV shows it in Settings → General → Network → Network Status → IP Settings) and press Connect the Samsung TV; Look again searches again. A typed address must be on the home network (10.x, 172.16–31.x, 192.168.x or 169.254.x); anything else is refused before anything is sent. Then choose Allow on the TV with its remote. The app first reads http://<tv>:8001/api/v2/ to check that a Samsung answers there (its name, model, id and TokenAuthSupport), then opens wss://<tv>:8002/api/v2/channels/samsung.remote.control?name=<base64 "Home tablet">. The TV shows its prompt; Allow answers ms.channel.connect with a token, Deny answers ms.channel.unauthorized. The token is kept the way the box's pairing is: a file in the app's private storage (files/drivers/samsung/token, beside files/drivers/tv/), written to the disk and then renamed over the old one. The address, the TV's name, model and id, and "paired" are in settings. Forget the Samsung TV deletes the token; the TV's own list of devices (Settings → General → External Device Manager → Device Connection Manager → Device List) removes it there too. A token belongs to one TV: connecting to another TV deletes it first; connecting to the same TV (same id) at another address keeps it.

Finding the Samsung

The search (SamsungTvFinder, UdpSsdp, AndroidSamsungNetwork). The box is found by mDNS (Finding the box). Samsung TVs answer SSDP, so the app sends one M-SEARCH (239.255.255.250:1900, MX 3) for each of urn:samsung.com:device:RemoteControlReceiver:1, urn:dial-multiscreen-org:service:dial:1 and urn:schemas-upnp-org:device:MediaRenderer:1, twice in case UDP loses one, and listens for 3 s. At the same time it browses mDNS for _samsungmsf._tcp (Samsung's multiscreen service, through the box's own AndroidMdns). Each address that answered is asked /api/v2/ (1.5 s timeout); only what answers as a Samsung TV is listed, once per TV id. The box answers DIAL too, and is dropped there.

Network rules.

  • A WifiManager.MulticastLock is held for the 3 s of a search only, and released in a finally.
  • The search goes out from the tablet's Wi-Fi (or Ethernet) IPv4 address, on that interface, with a multicast TTL of 2. Without a home-network address on Wi-Fi or Ethernet, nothing is sent at all.
  • Only answers from home-network addresses are contacted, and only by their source address: the LOCATION URLs in answers are never fetched. Nothing goes off the local network.
  • No addresses are written in the code; the household's TV is only ever an address from a search, the settings, or what the user typed.

Its id. /api/v2/ gives the TV's uuid as device.duid, device.id and the top-level id (on this TV the same value), and the UPnP device.udn. The first of them (duid) is kept at pairing as samsungId, and a device is the paired TV if any of its uuids matches (case and the uuid: prefix ignored). The SSDP USN uuids are not relied on: the media renderer's can differ from the TV's id.

Following the paired TV (SamsungTvFollower). Keys go to the Samsung only while the device at the saved address is confirmed to be the paired TV, besides being paired, answering and allowing the tablet (TvRules.samsungIsTheRoute). A check first asks the saved address /api/v2/ (one HTTP request):

  • The same id there: nothing else is done.
  • Nothing, or another device there (another id, or not a Samsung): no keys go there, and the network is searched. The TV with the same id, found at another address, becomes the address, kept in settings without asking (the log says "The Samsung TV moved to a new address; kept"). Volume goes to the box until then.
  • The token at the new address. Samsung tokens belong to the client (the name "Home tablet" and its token), not to the address, so the token is kept. It is checked once there by opening the remote channel with it and closing it (SamsungTvRemote.check, nothing sent). If the TV refuses it, or starts asking on screen, Settings says "The TV no longer allows this tablet. Press Connect the Samsung TV and choose Allow." and volume goes to the box.
  • A pairing from before ids were kept takes the id of the Samsung of that name at its saved address, at the first check after the update. If that address does not answer, it takes the one TV of that name (and model, if known) found; two of them, and neither is taken.

When it checks. On start (and after pairing); when a reading or a key fails at the address (UPnP stops answering); when UPnP answers again after a failure (to confirm it is still the TV); when a volume request comes while the TV is away; when Settings → TV opens; and, while it is not answering, when the box answers again, when the box moves, or when the network comes back (Rediscovery.HINT, Finding the box). A check searches only if the saved address did not confirm the TV. Searches are short (3 s) and rare: at most one a minute (Settings: one per 10 s), and while the TV is not found, again after 2, 4, 8 and 16 minutes, then every 30 minutes. A TV off for the night means about 20 searches of 3 s in 8 hours, and none once it answers again. There is no other polling for discovery; the UPnP reading (every 2.5 s or 30 s) is what notices a failure.

Tests: SsdpTest (the M-SEARCH, answers in the shape Samsung TVs give them in samsungtv/src/test/resources/samsung/ssdp-*.txt with fake uuids, home-network addresses, and one search over UDP against a responder on localhost), DiscoveryTest (a fake network: the list by name and model, an IP change, another device on the old IP, a token rejected at the new address, a TV off for the night, pairings without an id, the schedule), SamsungTvRemoteTest.checkingTheTokenOpensAndClosesWithoutSendingAKey, and DriverRulesTest (the route, the status, keeping the token, typed addresses). The SSDP answers are written in the documented shape, not recorded from this TV; the log line Search: n SSDP answer(s) (…) on the tablet shows what it really answers.

Keys. One connection per burst: connect with the token, wait for ms.channel.connect, send {"method":"ms.remote.control","params":{"Cmd":"Click","DataOfCmd":"KEY_VOLUP","Option":"false","TypeOfRemote":"SendRemoteKey"}} per key 250 ms apart, close. With a token the TV knows, it answers at once; silence for 4 s means it is asking on screen again, and the key is not sent (Settings says to connect again). KEY_POWER is not used: power stays with the box, whose HDMI-CEC already switches the TV.

State. UPnP RenderingControl at http://<tv>:9197/upnp/control/RenderingControl1, GetVolume and GetMute (InstanceID 0, Channel Master), read every 2.5 s while the app is in front or the assistant listens (at once when listening starts), every 30 s otherwise, and again after each key. Home and the assistant use this mute state, so "mute" on a muted TV answers "The TV is already muted." and mute and unmute are not blind toggles.

Which level UPnP reports. On 26 November 2026 GetVolume returned 32 and GetMute 0. On this TV (Q60AA, with the soundbar on ARC) it is the TV's own speaker's level, not the soundbar's: see "Results for this TV" below. The app works either way. After each burst of keys it reads UPnP again: if the reading moved with the keys, it follows them (SoundTracking, kept in settings as samsungVolumeFollowsKeys and samsungMuteFollowsKeys). If it did not move (read twice, 0.7 s apart), the reading is the TV's unused speaker. Then Home and the assistant show the volume and mute as unknown rather than wrong: "mute" sends the key and says "I've pressed mute on the TV." The keys still work, because they go where the TV's remote sends them.

"Set the TV volume to 20" (set_volume, percent) becomes UPnP SetVolume with the same number, since the TV's scale is 0..100. It is used unless UPnP was seen not to follow the keys. Then it answers "The TV can only turn the sound up or down, not to a number." On this TV UPnP does not follow the keys, so it is refused, as designed (results below).

Steps. "Turn it up" is 3 key presses (the tool's default), as on the box. On the TV's 0..100 scale that is a smaller change than 3 of the box's 15 steps. If it is too small in the room, change the default in the tool rather than add rules.

No libraries. The WebSocket (RFC 6455) and HTTP are small and spoken over plain sockets. The TV's certificate is self-signed and accepted as the box's is (the household's LAN; what goes over it is a token and volume keys). Android's cleartext-HTTP policy covers its HTTP clients, not sockets. Tests run against a fake TV (FakeSamsungTv), over plain sockets and TLS with a self-signed certificate, with SOAP answers in the TV's format (samsungtv/src/test/resources/samsung/).

Failure modes

Settings says When What volume does
Not connected: volume changes the box's own volume never paired goes to the box
Looking for the TV… Connect the Samsung TV pressed, the app just started, or a search for the paired TV is under way goes to the box until the TV is confirmed and read
On the TV, choose Allow with its remote the prompt is on the TV goes to the box; waits 45 s for Allow
Connected — volume and mute go to the TV paired, confirmed by its id, and UPnP answers goes to the Samsung
The TV isn't answering. Volume goes to the box until it does. the TV is off or in standby and not found elsewhere, or another device has its address goes to the box; read again every 2.5 s or 30 s, searched for as above
The TV no longer allows this tablet. Press Connect the Samsung TV and choose Allow. the TV forgot the token (silence or ms.channel.unauthorized on connect), or refused it at a new address goes to the box
Not allowed on the TV / Nobody answered on the TV Deny chosen, or no answer to the prompt goes to the box
No Samsung TV answered at that address nothing, or not a Samsung, at the address goes to the box
No Samsung TV found on the network. the search found none (TV off, another Wi-Fi, multicast blocked by the router) enter its address instead

A key burst that breaks after the first key has gone out is not repeated on the box: the reply says "The TV didn't respond."

Privacy

The link stays on the home network and reads only playback state; what it reads stays on the tablet. The Privacy page says so. Search on the TV puts the words in YouTube's link to the box, which its YouTube app opens as it would a link from a phone; the tablet sends them nowhere else. What to watch, while switched on with a key, sends the words searched for, a title id and the country (for its top picks, the country and dates; never the household's services), with the household's key in a header, to api.watchmode.com only; the TV gets only the title's app link. A title said into its microphone is recognised on the tablet, as a request is. The key is sealed by the Android Keystore in the no-backup folder (What to watch). The Samsung link stays on the home network too: it sends volume and mute keys and reads the volume, and the token stays in the app's private storage. Finding it is an SSDP search on the Wi-Fi (TTL 2) and /api/v2/ at home-network addresses that answered, nothing else. The diagnostics report leaves out the TV's name, address and id.

On-device test: ducking and TV sound

Run with the Android TV box, Samsung TV, and soundbar on, and a video playing (e.g. Netflix). A laptop with adb logcat -s TvController SamsungSound helps but is not needed.

  1. Ducking. Note the box's volume (its volume bar; adb shell dumpsys audio | grep -A3 "STREAM_MUSIC" on the box should say 15). Say the wake phrase and a request. While the assistant listens the sound drops audibly and the box's bar goes down to 9, not to mute. When the answer is spoken it is back at 15 exactly. Repeat with the box at 10 (expect 6 while listening).
  2. Someone changes it while ducked. Say the wake phrase, and while it listens press volume up twice on the box's remote (9 → 11). After the answer, the volume stays at 11, not 15. 2b. Volume commands while ducked (box route: forget the Samsung, or with it unplugged; "Listen for a follow-up" on). Box at 12. Wake phrase, "turn the TV volume up": the bar goes 7 → 10 while it answers, and to 15 when it stops listening, and stays. Again from 12 with "turn the TV volume down": 4, then 9. "Set the TV volume to 33": 5, and still 5 afterwards. "Mute the TV": stays muted after listening; "unmute the TV" (or the remote's mute key) brings back 12, not 7. The remote panel's volume up, tapped twice while it listens: 12 → 14 afterwards.
  3. Crash mid-duck. Say the wake phrase, and while it listens run adb shell am force-stop --user 10 dev.privateassistant.app. The box stays at 9. Open the app again: once the TV shows Connected, the box goes back to 15 by itself.
  4. Pair the Samsung. Settings → TV → TV sound: within about 3 s it lists "Samsung Q60AA 85 · QE85Q60AAUXXN". Choose it, and choose Allow on the TV. Settings shows "Samsung Q60AA 85" and "Connected — volume and mute go to the TV". (If nothing is listed: Enter its address, type the address the TV shows, press Connect the Samsung TV.)
  5. Volume. Say "turn the TV volume up". The soundbar's level goes up (the TV shows the soundbar's volume), and the box's own bar does not move. Then "turn the TV volume down". Note how big 3 steps feels (the default amount).
  6. Which level UPnP reports. After step 5, adb shell run-as dev.privateassistant.app --user 10 cat files/settings.json | grep samsung shows "samsungVolumeFollowsKeys": true or false (the log says Learnt: UPnP volume follows the keys=… under the tag SamsungSound; Settings → Tablet & privacy → Share diagnostics has it too, on the "tv sound (samsung)" line). Write down which, and whether Home's TV volume follows the soundbar. With false, Home shows no volume level; that is expected.
  7. Mute. Say "mute the TV": the soundbar goes quiet. Say "mute the TV" again: "The TV is already muted." if mute follows the keys (mute=true), else "I've pressed mute on the TV." and it unmutes (record which). "Unmute the TV" brings the sound back. Tap Mute on Home's TV card: same.
  8. An exact level. Say "set the TV volume to 20". On this TV (volume=false, results below) the reply is "The TV can only turn the sound up or down, not to a number." and nothing changes.
  9. Fallback. Switch the Samsung off at the wall, or unplug its network, and wait 30 s. Settings says "The TV isn't answering…". "Turn the TV volume up" then moves the box's own bar. Back on, it goes to the Samsung again within 30 s (2.5 s with the app in front).
  10. Ducking with the Samsung paired. Repeat step 1: ducking still moves the box's bar, not the soundbar's level. Then wake phrase, "turn the TV volume up": the soundbar goes up 3 and stays up, and the box's bar goes back to its level from before. If 3 is too little to hear, note it (the tool's default amount).
  11. Forget. Settings → TV → TV sound → Forget the Samsung TV: volume goes to the box again.

On-device test: finding the Samsung

With the TV on, and adb logcat -s SamsungSound if a laptop is at hand. The router's DHCP client list (or the TV's Network Status) shows the TV's address; the steps never need it typed.

  1. An update keeps the pairing. Install over a build that was paired before ids were kept (before 27 November 2026) and open the app. Within a few seconds "Connected — volume and mute go to the TV" as before, with no search (the log has no Search: line), and adb shell run-as dev.privateassistant.app --user 10 cat files/settings.json | grep samsung now has "samsungId": "uuid:…" and "samsungModel": "QE85Q60AAUXXN".
  2. The list. Forget the Samsung TV, then leave Settings → TV and open it again. "Samsung Q60AA 85 · QE85Q60AAUXXN" is listed within about 3 s (log: Search: n SSDP answer(s) (urn:…); write down which targets it answered and whether mDNS found it). Choose it, Allow on the TV: Connected. "Look again" searches again; "Enter its address" shows the address field.
  3. A new address. In the router, give the TV another address (change its DHCP reservation, or remove it and restart the TV so it takes a new lease). The next reading at the old address fails, which starts a search (log: The TV moved to a new address (FAILURE); the token works and The Samsung TV moved to a new address; kept); a volume request meanwhile goes to the box. Within a minute (30 s readings with the app in the background), "Connected" again without asking, samsungHost in settings is the new address, and "turn the TV volume up" moves the soundbar. Opening Settings → TV also finds it at once.
  4. The token there. If, after step 3, Settings says "The TV no longer allows this tablet…", the TV did not take the token at the new address: write that down here (it would mean this TV ties tokens to the address after all). Connect the Samsung TV, Allow, and it works again.
  5. Another device at the old address. If something else can be given the TV's old address (a laptop or phone with a fixed address), do so after step 3 with the TV off at the wall, then restart the app. Settings says "The TV isn't answering…" and volume goes to the box: no keys go to the other device (adb logcat shows another device has its address). Switch the TV on: it is found at its address again.
  6. Off for the night. Switch the TV off with its remote and leave it for 10 minutes: the log shows one search when it stops answering, then one about 2 minutes later and one about 4 minutes after that (the gaps double, up to 30 minutes), not more. Switch it on: Connected within 30 s (2.5 s with the app in front), with no search.

Write the answers to 2, 3 and 4 in "Results for this TV", with the date.

Results for this TV

Samsung Q60AA 85" (QE85Q60AAUXXN, Tizen 2021), soundbar on ARC.

  • 26 November 2026: paired over wss://…:8002 with TokenAuthSupport; volume and mute keys work. GetVolume 32, GetMute 0.
  • 27 November 2026: the app learnt SamsungSound: Learnt: UPnP volume follows the keys=false, mute=null. The TV's UPnP volume is the TV speakers', not the soundbar's: the keys change the soundbar and UPnP's reading stays where it was. So Home and the assistant show the Samsung's volume as unknown, and "set the TV volume to 20" is refused ("The TV can only turn the sound up or down, not to a number."), as designed. Whether mute follows its key is not known yet (mute=null: learnt only from a mute key press with a reading before and after; on-device test step 7). Previously the TV's address had to be typed by hand even though DHCP can reassign it; finding it by SSDP and following it by id (above) solves that.