Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
Remote keys: map app buttons by scancode
Wouter Dammandc358576a3f9
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.javaindex 2cc4aa27d..538ae432a 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java@@ -26,6 +26,7 @@ public class HomeKeyService extends AccessibilityService {private boolean settingsPanel;/** app_keys, the same map InputKeyService reads, for setups that run only this service. */private Map<Integer, String> appKeys = Collections.emptyMap();+ private Map<Integer, String> appScancodes = Collections.emptyMap();@Overrideprotected void onServiceConnected() {@@ -36,6 +37,7 @@ public class HomeKeyService extends AccessibilityService {settingsKeycodes = config.settingsKeycodes;settingsPanel = config.settingsKeyPanel;appKeys = RemoteKeys.parseAppKeys(config.appKeys);+ appScancodes = RemoteKeys.parseAppScancodes(config.appKeys);}private boolean isSettingsKey(KeyEvent event) {@@ -47,6 +49,12 @@ public class HomeKeyService extends AccessibilityService {@Overrideprotected boolean onKeyEvent(KeyEvent event) {+ // A scancode entry is more specific than any keycode, so it goes first.+ String scanApp = appScancodes.get(event.getScanCode());+ if (scanApp != null) {+ if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) RemoteKeys.launch(this, scanApp);+ return true;+ }// The stock launcher handled the remote's Settings button; with it disabled the button does nothing.if (isSettingsKey(event)) {if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) {diff --git a/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java b/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.javaindex 26e2d0cbc..cdfc24d01 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java@@ -22,6 +22,7 @@ public class InputKeyService extends AccessibilityService {private int[] inputKeycodes = new int[0];private Map<Integer, String> appKeys = Collections.emptyMap();+ private Map<Integer, String> appScancodes = Collections.emptyMap();@Overrideprotected void onServiceConnected() {@@ -30,6 +31,7 @@ public class InputKeyService extends AccessibilityService {Config config = Config.load(this);inputKeycodes = config.inputKeycodes;appKeys = RemoteKeys.parseAppKeys(config.appKeys);+ appScancodes = RemoteKeys.parseAppScancodes(config.appKeys);}private boolean isInputKey(int keyCode) {@@ -40,6 +42,12 @@ public class InputKeyService extends AccessibilityService {@Overrideprotected boolean onKeyEvent(KeyEvent event) {+ // A scancode entry is more specific than any keycode, so it goes first.+ String scanApp = appScancodes.get(event.getScanCode());+ if (scanApp != null) {+ if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) RemoteKeys.launch(this, scanApp);+ return true;+ }String app = appKeys.get(event.getKeyCode());if (app == null && !isInputKey(event.getKeyCode())) return false;if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) {diff --git a/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java b/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.javaindex 21e4345fa..92cf977e8 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java@@ -13,7 +13,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". One map for both services; whichever filters the key first+ * "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.*/final class RemoteKeys {@@ -53,6 +53,26 @@ final class RemoteKeys {return keys;}+ /**+ * scancode -> package, from the "scan:490:com.wbd.hbomax" entries of the same list. For remotes that send+ * several app buttons as one keycode and tell them apart by scancode (Sony BRAVIA: YouTube, Prime Video and+ * Disney+ are all keycode 196, scancodes 485, 490 and 491). Find it with `getevent -lt` while pressing the+ * button: the EV_KEY code, in hex. Other entries are skipped; for a scancode listed twice the last entry wins.+ */+ static Map<Integer, String> parseAppScancodes(Iterable<String> entries) {+ Map<Integer, String> keys = new HashMap<>();+ for (String entry : entries) {+ if (entry == null) continue;+ String[] parts = entry.split(":", 3);+ if (parts.length != 3 || !parts[0].trim().equals("scan") || parts[2].trim().isEmpty()) continue;+ String code = parts[1].trim();+ if (!code.matches("[0-9]{1,6}")) continue;+ int scan = Integer.parseInt(code);+ if (scan > 0) keys.put(scan, parts[2].trim());+ }+ return keys;+ }+/** Opens an app from a remote button: its TV entry if it has one, else its phone entry. */static void launch(Context ctx, String pkg) {Intent open = ctx.getPackageManager().getLeanbackLaunchIntentForPackage(pkg);diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xmlindex 3deebbea4..8162e632f 100644--- a/launcher/app/src/main/res/values/config.xml+++ b/launcher/app/src/main/res/values/config.xml@@ -89,7 +89,11 @@YouTube button sends 190 (KEYCODE_BUTTON_3) to the stock launcher, so it does nothing once launcherxis disabled (Chromecast with Google TV, Xiaomi MiTV-AXFR2): 190:com.google.android.youtube.tv bringsit back. The KTC LUMIO VISION remote (Realtek Google TV) sends Netflix 191, YouTube 190, Prime Video 195- and TL;DR 200. A listed app that is not installed leaves the button doing nothing. Leave empty to omit. -->+ 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. --><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.javaindex 80908ea2a..1d637512b 100644--- a/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java+++ b/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java@@ -36,4 +36,15 @@ public class RemoteKeysTest {Map<Integer, String> keys = parse("190:a.b", "190:c.d");assertEquals("c.d", keys.get(190));}++ @Test public void scancodeEntries() {+ java.util.List<String> entries = java.util.Arrays.asList(+ "scan:490:com.wbd.hbomax", " scan : 491 : a.b ", "scan:x:a.b", "scan:12:", "190:c.d", "scan:491:e.f");+ Map<Integer, String> scans = RemoteKeys.parseAppScancodes(entries);+ assertEquals(2, scans.size());+ assertEquals("com.wbd.hbomax", scans.get(490));+ assertEquals("e.f", scans.get(491));+ // and the keycode parser leaves scancode entries alone+ assertEquals(1, parse(entries.toArray(new String[0])).size());+ }}diff --git a/themes/README.md b/themes/README.mdindex d08c19670..a031ee267 100644--- a/themes/README.md+++ b/themes/README.md@@ -62,7 +62,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"`, 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` || `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 || `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 |