Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

launcher: app_keys can switch to a TV input ("input:<id>")

Matheus Caldeiraa3b598e17628
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java b/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java
index 92cf977e8..e632d8f8b 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java
@@ -3,6 +3,7 @@ package com.gathin.tvhome;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
+import android.media.tv.TvContract;
import android.view.KeyEvent;
import java.util.Arrays;
@@ -14,7 +15,7 @@ import java.util.function.ToIntFunction;
* Remote buttons that only the stock launcher answered, for InputKeyService and HomeKeyService: app_keys
* (config.xml or a theme) maps a keycode to the app it opens, as "190:com.google.android.youtube.tv" or
* "KEYCODE_BUTTON_3:com.google.android.youtube.tv", or a scancode as "scan:490:com.wbd.hbomax". One map for both services; whichever filters the key first
- * consumes it.
+ * consumes it. A target of "input:<input id>" switches to that TV input (an HDMI port) instead of opening an app.
*/
final class RemoteKeys {
private RemoteKeys() { }
@@ -73,8 +74,29 @@ final class RemoteKeys {
return keys;
}
- /** Opens an app from a remote button: its TV entry if it has one, else its phone entry. */
+ /** The TV input id of an "input:<id>" target, e.g. "input:com.tcl.tvinput/.passthroughinput.TvPassThroughService/HW1413743104"; null for a package. */
+ static String inputId(String target) {
+ if (target == null || !target.startsWith("input:")) return null;
+ String id = target.substring("input:".length()).trim();
+ return id.isEmpty() ? null : id;
+ }
+
+ /** Opens an app from a remote button: its TV entry if it has one, else its phone entry. An "input:<id>" target
+ * switches to that TV input (an HDMI port) instead. */
static void launch(Context ctx, String pkg) {
+ String inputId = inputId(pkg);
+ if (inputId != null) {
+ // The same passthrough URI the Inputs menu opens, which the Live TV app handles.
+ Intent view = new Intent(Intent.ACTION_VIEW)
+ .setDataAndType(TvContract.buildChannelUriForPassthroughInput(inputId),
+ "vnd.android.cursor.item/channel")
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ ctx.startActivity(view);
+ } catch (ActivityNotFoundException ignored) {
+ }
+ return;
+ }
Intent open = ctx.getPackageManager().getLeanbackLaunchIntentForPackage(pkg);
if (open == null) open = ctx.getPackageManager().getLaunchIntentForPackage(pkg);
if (open == null) return;
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 4ca1b963c..bed9f9579 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -92,8 +92,10 @@
and TL;DR 200. Some remotes send several app buttons as one keycode and tell them apart only by scancode
(Sony BRAVIA: YouTube, Prime Video and Disney+ are all keycode 196, scancodes 485, 490 and 491); list those
as "scan:scancode:package", e.g. scan:490:com.wbd.hbomax, found with `tools/tv.py 'getevent -lt'` (the
- EV_KEY code, in hex). A scancode entry wins over a keycode. A listed app that is not installed leaves the
- button doing nothing. Leave empty to omit. -->
+ EV_KEY code, in hex). A scancode entry wins over a keycode. In place of a package, "input:<input id>"
+ switches to that TV input, e.g. scan:227:input:com.tcl.tvinput/.passthroughinput.TvPassThroughService/HW1413744640
+ for HDMI 3 on a TCL Smart TV Pro; the ids are in `tools/tv.py 'dumpsys tv_input'` (hdmi_port=N under
+ TvInputHardwareInfo). A listed app that is not installed leaves the button doing nothing. Leave empty to omit. -->
<string-array name="app_keys" translatable="false">
</string-array>
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java b/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java
index 1d637512b..db0fb5395 100644
--- a/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java
+++ b/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java
@@ -47,4 +47,13 @@ public class RemoteKeysTest {
// and the keycode parser leaves scancode entries alone
assertEquals(1, parse(entries.toArray(new String[0])).size());
}
+ @Test public void inputTargets() {
+ String hdmi = "com.tcl.tvinput/.passthroughinput.TvPassThroughService/HW1413743104";
+ Map<Integer, String> keys = parse("4062:input:" + hdmi);
+ assertEquals(hdmi, RemoteKeys.inputId(keys.get(4062)));
+ assertEquals(hdmi, RemoteKeys.inputId(RemoteKeys.parseAppScancodes(
+ java.util.Arrays.asList("scan:586:input:" + hdmi)).get(586)));
+ assertEquals(null, RemoteKeys.inputId("com.netflix.ninja"));
+ assertEquals(null, RemoteKeys.inputId("input: "));
+ }
}
diff --git a/themes/README.md b/themes/README.md
index e9ae32cfe..155988c2e 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -70,7 +70,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can
| `settings_key_keycodes` | list of keycodes | Remote buttons that open Settings, for `HomeKeyService` (TCL Google TV gear: `[83]`) |
| `settings_key_panel` | bool | Those buttons open a small quick settings panel (TV settings, Display, Network, Apps, Launcher settings) instead of the TV's Settings |
| `input_key_keycodes` | list of keycodes | More remote buttons that open the input switcher, for `InputKeyService` (`KEYCODE_TV` and `KEYCODE_TV_INPUT` always do) |
-| `app_keys` | list of strings | Remote buttons that open an app, as `"190:com.google.android.youtube.tv"` or `"KEYCODE_BUTTON_3:com.google.android.youtube.tv"`, or by scancode as `"scan:490:com.wbd.hbomax"` for remotes that share one keycode between app buttons (Sony BRAVIA), for `InputKeyService` or `HomeKeyService` |
+| `app_keys` | list of strings | Remote buttons that open an app, as `"190:com.google.android.youtube.tv"` or `"KEYCODE_BUTTON_3:com.google.android.youtube.tv"`, or by scancode as `"scan:490:com.wbd.hbomax"` for remotes that share one keycode between app buttons (Sony BRAVIA), for `InputKeyService` or `HomeKeyService`. `"input:<input id>"` in place of the package switches to a TV input instead, e.g. `"scan:227:input:com.tcl.tvinput/.passthroughinput.TvPassThroughService/HW1413744640"` for an HDMI port (ids from `dumpsys tv_input`) |
| `race_calendar` | list of races | F1 race-weekend mode: from 12 hours before a weekend's first session until 4 hours after the race starts, a panel under the clock shows the next session with a countdown (or the live one) and the weekend's session times in the TV's time zone. Write it with `tools/race_calendar.py <theme folder>`, which fetches the season from the free Jolpica API; the launcher itself never goes online |
| `home_idle_clock_minutes` | 0 to 1440 | Minutes Home may sit untouched before it shows the clock screensaver (a thin clock and date drifting over a slow glow, as the system "Clock" screensaver does). Any key returns to Home. It starts only from Home, never over Live TV or an app; 0 is off (default) |
| `cinematic_home` | bool | Cinematic top shelf: the focused dock app's artwork, softened, fills the top of the screen in its colour, with a larger name, "Last opened" (apps opened from Home), dock position dots, a focus glow in the app's colour and a translucent dock band; off by default |