Skip to content

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

Merge PR #1184: Launcher: action words as app_keys targets (mute, sleep, recents...)

Gathin231c6b396ce1b8
diff --cc launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java
index 0ef01dbc1,935aae4de..7396dba4f
--- a/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/RemoteKeys.java
@@@ -22,8 -25,8 +25,9 @@@ 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, and a target
- * of "inputs" opens the input switcher, for a remote whose source button sends a key Android does not map.
- * 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.
++ * A target of "input:<input id>" switches to that TV input (an HDMI port) instead of opening an app, a target
++ * of "inputs" opens the input switcher, for a remote whose source button sends a key Android does not map, and
++ * one of the action words (back, home, recents, mute, sleep, screensaver, settings, wifi) does that action.
*/
final class RemoteKeys {
@@@ -157,20 -157,77 +161,87 @@@
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;
+ if (INPUTS.equals(pkg)) {
+ // This launcher's own Inputs menu, as InputsRequestActivity opens it: addressed to Home directly, so a
+ // vendor input picker that also answers VIEW_INPUTS never turns it into a chooser.
+ try {
+ ctx.startActivity(new Intent(ctx, MainActivity.class).setAction(MainActivity.ACTION_VIEW_INPUTS)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
+ } catch (ActivityNotFoundException ignored) {
+ }
+ return;
+ }
String inputId = inputId(pkg);
if (inputId != null) {
// The same passthrough URI the Inputs menu opens, which the Live TV app handles.
diff --cc launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java
index 66b5bebba,dbf857564..3682e40ef
--- a/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java
+++ b/launcher/app/src/test/java/com/gathin/tvhome/RemoteKeysTest.java
@@@ -94,9 -96,27 +96,33 @@@ public class RemoteKeysTest
assertNull(RemoteKeys.target(null, "hold.app", 0));
}
+ @Test public void inputsTargetKeptForAScancode() {
+ Map<Integer, String> scans = RemoteKeys.parseAppScancodes(Arrays.asList("scan:365:inputs"));
+ assertEquals(RemoteKeys.INPUTS, scans.get(365));
+ assertNull(RemoteKeys.inputId(RemoteKeys.INPUTS));
+ }
++
+ @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 --cc themes/README.md
index 8802013ea,055a1ba25..92d6358da
--- a/themes/README.md
+++ b/themes/README.md
@@@ -104,7 -100,7 +104,7 @@@ A new key needs one there in the same p
| `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`). `"inputs"` in place of the package opens the Inputs menu, for a remote whose source button sends a key Android does not map, e.g. `"scan:365:inputs"` (TCL 65C745). 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 |
++| `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`). `"inputs"` in place of the package opens the Inputs menu, for a remote whose source button sends a key Android does not map, e.g. `"scan:365:inputs"` (TCL 65C745). 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`) |