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
Launcher: action words as app_keys targets (mute, sleep, recents...)
ScaryFr9221de338a169a
diff --git a/README.md b/README.mdindex e84c36dbc..618b7f382 100644--- a/README.md+++ b/README.md@@ -597,6 +597,8 @@ tools/tv.py 'settings put secure screensaver_components com.gathin.tvhome/.Clock(`app_keys` and `input_key_keycodes`, in config.xml or a theme; `HOME_KEY_SERVICE=1` reads `app_keys` too).- A `hold:` prefix on an `app_keys` entry gives that button a second app: a normal press opens theunprefixed app, holding for half a second opens the hold one (by keycode or `hold:scan:...`).+- In place of an app, an `app_keys` entry can name an action: `back`, `home`, `recents`, `mute`, `sleep`,+ `screensaver`, `settings` or `wifi`, so a spare colour button can mute the TV or, held, put it in standby.- `HOME_KEY_SERVICE=1` also fixes sticks whose Home key sends ALL_APPS, and opens Settings from the remote's**gear** button, even one Android does not map (scancodes or keycodes in config.xml).- With `settings_key_panel` the gear opens a [small quick settings panel](docs/quick-settings-panel.jpg)diff --git a/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java b/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.javaindex dd1a8a146..935aae4de 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java@@ -5,7 +5,10 @@ import android.accessibilityservice.AccessibilityServiceInfo;import android.content.ActivityNotFoundException;import android.content.Context;import android.content.Intent;+import android.media.AudioManager;import android.media.tv.TvContract;+import android.os.Build;+import android.provider.Settings;import android.view.KeyEvent;import java.util.ArrayList;@@ -22,7 +25,8 @@ import java.util.function.ToIntFunction;* prefix makes an entry the long-press action instead: "hold:KEYCODE_BUTTON_8:org.xbmc.kodi" opens Kodi when* that button is held for HOLD_MS, while the unprefixed entry still opens on a tap; "hold:scan:490:..." does* the same for a scancode. One set of maps for both services; whichever filters the key first consumes it.- * A target of "input:<input id>" switches to that TV input (an HDMI port) instead of opening an app.+ * A target of "input:<input id>" switches to that TV input (an HDMI port) instead of opening an app, and one+ * of the action words (back, home, recents, mute, sleep, screensaver, settings, wifi) does that instead.*/final class RemoteKeys {@@ -153,10 +157,77 @@ final class RemoteKeys {return id.isEmpty() ? null : id;}+ /**+ * The accessibility global action for an action word, or 0 when the target is something else. "sleep" is+ * GLOBAL_ACTION_LOCK_SCREEN, which puts a TV in standby (as the Sleep Timer add-on does); Android has it from 28.+ */+ static int globalAction(String target, int sdk) {+ switch (target) {+ case "back": return AccessibilityService.GLOBAL_ACTION_BACK;+ case "home": return AccessibilityService.GLOBAL_ACTION_HOME;+ case "recents": return AccessibilityService.GLOBAL_ACTION_RECENTS;+ case "sleep": return sdk >= 28 ? AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN : 0;+ default: return 0;+ }+ }++ /** Whether a target is an action word rather than an app or an input. A package name always has a dot. */+ static boolean isAction(String target) {+ switch (target) {+ case "back": case "home": case "recents": case "mute": case "sleep":+ case "screensaver": case "settings": case "wifi":+ return true;+ default:+ return false;+ }+ }++ /** Runs an action word; false for an app or an input. Needs no permission the launcher does not already have. */+ private static boolean runAction(Context ctx, String target) {+ if (!isAction(target)) return false;+ int global = globalAction(target, Build.VERSION.SDK_INT);+ if (global != 0) {+ if (ctx instanceof AccessibilityService) ((AccessibilityService) ctx).performGlobalAction(global);+ return true;+ }+ switch (target) {+ case "mute":+ // The media stream a TV plays everything on, with its own volume bar, as a remote's mute button would.+ AudioManager audio = ctx.getSystemService(AudioManager.class);+ if (audio != null) audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,+ AudioManager.ADJUST_TOGGLE_MUTE, AudioManager.FLAG_SHOW_UI);+ break;+ case "screensaver":+ // The screensaver chosen in the TV's settings, through the system's "start now" shortcut; the+ // launcher's own clock where the firmware has no such shortcut.+ Intent dream = new Intent(Intent.ACTION_MAIN)+ .setClassName("com.android.systemui", "com.android.systemui.Somnambulator");+ if (ctx.getPackageManager().resolveActivity(dream, 0) == null) dream = new Intent(ctx, ClockActivity.class);+ start(ctx, dream);+ break;+ case "settings":+ start(ctx, SystemSettings.intent(ctx, Settings.ACTION_SETTINGS));+ break;+ case "wifi":+ start(ctx, SystemSettings.intent(ctx, Settings.ACTION_WIFI_SETTINGS));+ break;+ default:+ break; // "sleep" below Android 9: consumed, nothing to do+ }+ return true;+ }++ private static void start(Context ctx, Intent intent) {+ try {+ ctx.startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));+ } catch (ActivityNotFoundException | SecurityException ignored) {+ }+ }+/** 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. */+ * switches to that TV input (an HDMI port) instead, and an action word runs that action. */static void launch(Context ctx, String pkg) {- if (pkg == null) return;+ if (pkg == null || runAction(ctx, pkg)) return;String inputId = inputId(pkg);if (inputId != null) {// The same passthrough URI the Inputs menu opens, which the Live TV app handles.diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xmlindex f600b7d60..e2c47e8c5 100644--- a/launcher/app/src/main/res/values/config.xml+++ b/launcher/app/src/main/res/values/config.xml@@ -169,7 +169,10 @@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/HW1413744640for HDMI 3 on a TCL Smart TV Pro; the ids are in `tools/tv.py 'dumpsys tv_input'` (hdmi_port=N under- TvInputHardwareInfo). Prefix an entry with "hold:" for the same button's long press:+ TvInputHardwareInfo). An action word in place of a package runs that action instead: back, home, recents,+ mute (toggles the sound, with the TV's volume bar), sleep (standby, Android 9 and later), screensaver (the+ one chosen in the TV's settings, or the launcher's clock), settings or wifi; e.g. KEYCODE_PROG_YELLOW:mute+ and hold:KEYCODE_PROG_YELLOW:sleep. Prefix an entry with "hold:" for the same button's long press:"hold:KEYCODE_BUTTON_8:org.xbmc.kodi" opens Kodi when held for half a second, while the unprefixed entrystill opens on a tap; "hold:scan:490:..." works for scancodes. A key with only a hold entry does nothingon a tap. A listed app that is not installed leaves the button doing nothing. Leave empty to omit. -->diff --git a/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java b/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.javaindex 2186a2903..dbf857564 100644--- a/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java+++ b/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java@@ -1,9 +1,11 @@package com.gathin.tvhome;+import android.accessibilityservice.AccessibilityService;import java.util.Arrays;import java.util.Map;import org.junit.Test;import static org.junit.Assert.assertEquals;+import static org.junit.Assert.assertFalse;import static org.junit.Assert.assertNull;import static org.junit.Assert.assertTrue;@@ -93,4 +95,28 @@ public class RemoteKeysTest {assertEquals("app", RemoteKeys.target("app", null, 5000));assertNull(RemoteKeys.target(null, "hold.app", 0));}++ @Test public void actionWordsAreTargets() {+ Map<Integer, String> keys = parse("190:mute", "KEYCODE_BUTTON_8:screensaver");+ assertEquals("mute", keys.get(190));+ assertEquals("screensaver", keys.get(195));+ assertEquals("sleep", parseHold("hold:190:sleep").get(190));+ for (String word : new String[] {"back", "home", "recents", "mute", "sleep", "screensaver", "settings", "wifi"}) {+ assertTrue(word, RemoteKeys.isAction(word));+ }+ assertFalse(RemoteKeys.isAction("com.netflix.ninja"));+ assertFalse(RemoteKeys.isAction("input:com.tcl.tvinput/.passthroughinput.TvPassThroughService/HW1"));+ assertFalse(RemoteKeys.isAction("Mute"));+ }++ @Test public void globalActions() {+ assertEquals(AccessibilityService.GLOBAL_ACTION_BACK, RemoteKeys.globalAction("back", 26));+ assertEquals(AccessibilityService.GLOBAL_ACTION_HOME, RemoteKeys.globalAction("home", 26));+ assertEquals(AccessibilityService.GLOBAL_ACTION_RECENTS, RemoteKeys.globalAction("recents", 26));+ assertEquals(AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN, RemoteKeys.globalAction("sleep", 28));+ // No lock-screen action before Android 9: the key is consumed and nothing happens.+ assertEquals(0, RemoteKeys.globalAction("sleep", 27));+ assertEquals(0, RemoteKeys.globalAction("mute", 34));+ assertEquals(0, RemoteKeys.globalAction("com.netflix.ninja", 34));+ }}diff --git a/themes/README.md b/themes/README.mdindex fd66ad533..055a1ba25 100644--- a/themes/README.md+++ b/themes/README.md@@ -100,7 +100,7 @@ A new key needs one there in the same pull request.| `settings_fallback_components` | list, `config.xml` only | Vendor screens tried in order when nothing usable answers the standard Settings action (Xiaomi China, TCL/FFALCON, and Fire OS, where the real menu lives in its launcher), each as `package/activity`; the first one whose package is installed wins, and when none is, the standard intent is sent anyway and may open nothing. Fire OS answers that intent with a `CTSDummy` stub, which counts as missing so the fallback runs. A package named here also has to be listed in the launcher's `<queries>` (Android 11 package visibility), so a set whose settings app is neither of these needs a build, not a theme push. Not read from a theme || `restore_key_services` | bool | After a force stop of the launcher, Home puts the remote's accessibility helpers (`HomeKeyService`, `InputKeyService`) back on the enabled list; needs `RESTORE_KEY_SERVICES=1` at install. Off by default || `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`. `"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`). Prefix an entry with `hold:` to make it the long-press action, e.g. `"hold:190:com.netflix.ninja"`, while the unprefixed entry still opens on a tap |+| `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`). An action word in place of the package runs that action: `back`, `home`, `recents`, `mute`, `sleep` (standby, Android 9 and later), `screensaver`, `settings` or `wifi`, e.g. `"KEYCODE_PROG_YELLOW:mute"`. Prefix an entry with `hold:` to make it the long-press action, e.g. `"hold:190:com.netflix.ninja"`, while the unprefixed entry still opens on a tap || `key_filter` | bool | `false` makes the key helpers stop filtering keys while staying enabled. Use it on firmware where any key-filtering accessibility service breaks long-press repeat (TCL Google TV on Android 12): the remote buttons above stop working, and volume repeat comes back || `gamepad_passthrough` | bool | `true` makes the key helpers stop filtering keys while a game controller is connected, so games see its buttons (Steam Link with an Xbox controller); the remote buttons above do nothing until it disconnects. Needs `key_filter` on. A voice remote that reports a joystick does not count. Off by default || `stock_home_redirect` | string | Stock launcher package; if the firmware turns it back on (XGIMI), its home screen is sent straight back here (`HOME_KEY_SERVICE=1`) |