Skip to content

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

Launcher: home_long_press_home, a held Home press opens Home too

Robert786beccf925d
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index 5501e41ef..3264d9dc6 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -312,6 +312,25 @@ Things that bit us or contributors, so they don't bite you. Commands use `tools/
and `query-activities` answer with the resolver table's winner, which is not necessarily the
activity that takes focus: `dumpsys activity activities | grep mFocusedApp` is the ground truth,
and it is what to check before saying the takeover worked.
+- **Home works when tapped but does nothing when pressed firmly**, after the stock launcher is
+ disabled, seen on a Philips 65OLED804/12 (TPM191E, Android TV 12, `STT2.230526.001`) with a slow
+ third-party remote whose presses last 430 to 550 ms. Android turns a Home press held past 400 ms
+ into its long-press action, and `dumpsys window policy` shows it is
+ `mLongPressOnHomeBehavior=LONG_PRESS_HOME_ALL_APPS`. `PhoneWindowManager.launchAllAppsAction` sends
+ `ACTION_ALL_APPS` to the system-image Home only (`MATCH_SYSTEM_ONLY`), which with the stock
+ launcher disabled is `com.android.tv.settings/.system.FallbackHome`, and nothing answers it there:
+ logcat shows `START u0 {act=android.intent.action.ALL_APPS pkg=com.android.tv.settings}` 400 ms
+ after each key down and the TV stays where it was. Before the debloat the stock launcher answered
+ with its app grid, so it looked like Home. An injected `input keyevent --longpress KEYCODE_HOME`
+ reproduces it and a plain `input keyevent KEYCODE_HOME` does not. `settings put secure
+ long_press_timeout 800` does not move the limit, not even after a reboot. `home_long_press_home`
+ in `config.xml` or a theme, with `HOME_KEY_SERVICE=1` at install, makes `HomeKeyService` take every
+ Home press and open Home on release. That needs the helper to filter keys, so it costs the held-key
+ repeat described under [the key-repeat section](#a-key-helper-is-bound-and-a-held-remote-button-stopped-repeating).
+ Confirmed on this set: with `HomeKeyService` bound, Volume Down held for 3 s gave one step in
+ `dumpsys audio`; unbound, a 1.07 s hold gave 14 repeats 50 ms apart. Single presses step once either
+ way, also through HDMI ARC to a home cinema system. Choose between a firm Home press and a held volume
+ ramp; this set cannot have both.
- **The TV drops off Wi-Fi for good the moment setupwraith is disabled**, seen on Google TV 14 (Sony
BRAVIA 9 II, Philips R8G, Skyworth SWTV-24NA-4K NF, Xiaomi TV Box S 3rd gen MiTV-AFMU0) and on a TCL
G07 on Google TV 11 (build AR17; on AR20 the network belonged to `android.uid.system`). A Wi-Fi
diff --git a/docs/switches.md b/docs/switches.md
index 44773bfef..f7a639f04 100644
--- a/docs/switches.md
+++ b/docs/switches.md
@@ -50,3 +50,4 @@ fits the rules; keys from before the rule sit on its wanted list until a screens
| `library_ok_opens` | <img src="switches/library_ok_opens.jpg" width="320" alt="library_ok_opens on a TV"> |
| `date_below_clock` | <img src="switches/date_below_clock.jpg" width="320" alt="date_below_clock on a TV"> |
| `power_on_home` | <img src="switches/power_on_home.jpg" width="320" alt="power_on_home on a TV"> |
+| `home_long_press_home` | <img src="switches/home_long_press_home.jpg" width="320" alt="home_long_press_home on a TV"> |
diff --git a/docs/switches/home_long_press_home.jpg b/docs/switches/home_long_press_home.jpg
new file mode 100644
index 000000000..5e25de29d
Binary files /dev/null and b/docs/switches/home_long_press_home.jpg differ
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
index be67171ae..bfe40f569 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
@@ -162,6 +162,8 @@ final class Config {
final String stockHomeRedirect;
/** A Live TV window the firmware opens by itself at power-on is sent back to Home (power_on_home). */
final boolean powerOnHome;
+ /** Every Home press opens this launcher, a held one too, instead of Android's long-press action (home_long_press_home). */
+ final boolean homeLongPressHome;
/** The Settings button opens the quick settings panel instead of the TV's Settings (settings_key_panel). */
final boolean settingsKeyPanel;
/** Home puts the remote's accessibility helpers back after a force stop (restore_key_services; ServiceRepair). */
@@ -260,7 +262,7 @@ final class Config {
List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, boolean ambientGlow, boolean appGlow, boolean fadeRows, int homeIdleClockMinutes,
boolean keyFilter, boolean dockGlass, String glowStyle, boolean wallpaperCaptions,
boolean handleViewInputs, boolean tileMenu, boolean dockEvenPadding, boolean dockBand, boolean cinematicDots, boolean cinematicWhiteFocus, boolean wifiStatusColor, int cinematicScrim, int cinematicArt,
- Map<String, Set<String>> wallpaperMoods, boolean gamepadPassthrough, boolean consumeVolumeKeys, boolean powerOnHome, boolean wifiStatusWarnings, List<String> topBarApps, boolean showGreeting, boolean headerWhite, boolean clockWallpaper, int clockWallpaperDim, boolean clockGlow, String glassStyle, boolean singleRow, boolean dockBandAll, boolean lunarDate, int lunarUtcOffset, boolean dateBelowClock) {
+ Map<String, Set<String>> wallpaperMoods, boolean gamepadPassthrough, boolean consumeVolumeKeys, boolean powerOnHome, boolean homeLongPressHome, boolean wifiStatusWarnings, List<String> topBarApps, boolean showGreeting, boolean headerWhite, boolean clockWallpaper, int clockWallpaperDim, boolean clockGlow, String glassStyle, boolean singleRow, boolean dockBandAll, boolean lunarDate, int lunarUtcOffset, boolean dateBelowClock) {
this.handleViewInputs = handleViewInputs;
this.tileMenu = tileMenu;
this.inputKeycodes = inputKeycodes;
@@ -350,6 +352,7 @@ final class Config {
this.gamepadPassthrough = gamepadPassthrough;
this.consumeVolumeKeys = consumeVolumeKeys;
this.powerOnHome = powerOnHome;
+ this.homeLongPressHome = homeLongPressHome;
this.wifiStatusWarnings = wifiStatusWarnings;
this.topBarApps = Collections.unmodifiableList(topBarApps);
this.showGreeting = showGreeting;
@@ -454,6 +457,7 @@ final class Config {
boolean gamepadPassthrough = res.getBoolean(R.bool.gamepad_passthrough);
boolean consumeVolumeKeys = res.getBoolean(R.bool.consume_volume_keys);
boolean powerOnHome = res.getBoolean(R.bool.power_on_home);
+ boolean homeLongPressHome = res.getBoolean(R.bool.home_long_press_home);
boolean dockGlass = res.getBoolean(R.bool.dock_glass);
boolean dockEvenPadding = res.getBoolean(R.bool.dock_even_padding);
boolean dockBand = res.getBoolean(R.bool.dock_band);
@@ -553,6 +557,7 @@ final class Config {
gamepadPassthrough = bool(json, "gamepad_passthrough", gamepadPassthrough);
consumeVolumeKeys = bool(json, "consume_volume_keys", consumeVolumeKeys);
powerOnHome = bool(json, "power_on_home", powerOnHome);
+ homeLongPressHome = bool(json, "home_long_press_home", homeLongPressHome);
dockGlass = bool(json, "dock_glass", dockGlass);
dockEvenPadding = bool(json, "dock_even_padding", dockEvenPadding);
dockBand = bool(json, "dock_band", dockBand);
@@ -633,7 +638,7 @@ final class Config {
json == null ? Collections.emptyList() : raceCalendar(json), cinematic, ambientGlow, appGlow, fadeRows,
Math.max(0, idleClockMinutes), keyFilter, dockGlass, glowStyle, wallpaperCaptions, handleViewInputs, tileMenu, dockEvenPadding,
dockBand, cinematicDots, cinematicWhiteFocus, wifiStatusColor, cinematicScrim, cinematicArt, wallpaperMoods, gamepadPassthrough,
- consumeVolumeKeys, powerOnHome, wifiStatusWarnings, topBarApps, showGreeting, headerWhite, clockWallpaper,
+ consumeVolumeKeys, powerOnHome, homeLongPressHome, wifiStatusWarnings, topBarApps, showGreeting, headerWhite, clockWallpaper,
Math.max(0, Math.min(90, clockWallpaperDim)), clockGlow, glassStyle, singleRow && dockRow, dockBandAll, lunar, lunarOffset,
dateBelowClock);
}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
index 016d41d45..f62abd46f 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
@@ -39,6 +39,9 @@ import java.util.Set;
* With power_on_home set, a Live TV window (live_tv_package) that the firmware opens by itself at power-on is sent
* back here too, until the first key press after boot or after the screen turns on (Changhong / Homwee boards).
*
+ * With home_long_press_home set, it takes every Home press, so one held past the long-press timeout opens this launcher
+ * instead of Android's ALL_APPS action, which nothing answers once the stock launcher is disabled (Philips TPM191E).
+ *
* Enable over adb:
* settings put secure enabled_accessibility_services com.gathin.tvhome/.HomeKeyService
* settings put secure accessibility_enabled 1
@@ -68,6 +71,8 @@ public class HomeKeyService extends AccessibilityService {
/** power_on_home: the Live TV package to send back to Home, empty when off; armed until this uptime or a key. */
private String powerOnLiveTv = "";
private long powerOnUntil;
+ /** home_long_press_home: this service takes every Home press, held ones included. */
+ private boolean homeLongPressHome;
/** power_on_home: re-arms after the screen turns on; null unless the key is on. */
private BroadcastReceiver screenOnReceiver;
/** Stops key filtering while a game controller is connected; null unless gamepad_passthrough and key_filter, or before the unlock. */
@@ -180,6 +185,7 @@ public class HomeKeyService extends AccessibilityService {
appKeys = RemoteKeys.parseAppKeys(config.appKeys);
appScancodes = RemoteKeys.parseAppScancodes(config.appKeys);
RemoteKeys.applyKeyFilter(this, config.keyFilter);
+ homeLongPressHome = config.homeLongPressHome;
stockHome.clear();
stockHomePackage = config.stockHomeRedirect;
if (!config.stockHomeRedirect.isEmpty()) {
@@ -251,6 +257,11 @@ public class HomeKeyService extends AccessibilityService {
}
if (RemoteKeys.handle(this, event, appKeys.get(event.getKeyCode()),
holdAppKeys.get(event.getKeyCode()))) return true;
+ // home_long_press_home: Android never sees the Home key, so a held press cannot turn into ALL_APPS.
+ if (homeLongPressHome && event.getKeyCode() == KeyEvent.KEYCODE_HOME) {
+ if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) openHome();
+ return true;
+ }
if (event.getKeyCode() == KeyEvent.KEYCODE_HOME && !stockHome.isEmpty()) {
redirectHomeKey(event);
return false;
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 580e748f8..3a670aff1 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -206,6 +206,15 @@
when that is on. A theme's config.json can set it too. Off by default. -->
<bool name="power_on_home">false</bool>
+ <!-- Every press of the remote's Home button opens this launcher, a held one too. Android turns a Home press held
+ past the long-press timeout (400 ms) into its long-press action; on Android TV that is ALL_APPS, sent to the
+ system-image launcher, and with the stock launcher disabled nothing answers it, so a firm press on a slow
+ remote does nothing (Philips TPM191E, Android 12). The long_press_timeout setting does not move that limit
+ there. HomeKeyService (HOME_KEY_SERVICE=1) then takes the Home key itself and opens Home on release. Needs
+ key_filter, so held keys such as Volume Up/Down stop repeating (confirmed on that Philips; single presses
+ still step). A theme's config.json can set it too. Off by default. -->
+ <bool name="home_long_press_home">false</bool>
+
<!-- Show the Solar Hijri (Shamsi) date used in Iran and Afghanistan, e.g. "27 Mehr 1405", above the
Gregorian date. -->
<bool name="shamsi_date">false</bool>
diff --git a/tests/test_home_long_press_home.py b/tests/test_home_long_press_home.py
new file mode 100644
index 000000000..24da1d367
--- /dev/null
+++ b/tests/test_home_long_press_home.py
@@ -0,0 +1,73 @@
+"""home_long_press_home: a held Home press must reach this launcher when the switch is on, and nothing else.
+
+On a Philips 65OLED804/12 (TPM191E, Android TV 12, STT2.230526.001) Android turns a Home press held past
+400 ms into ALL_APPS for the system-image Home, which is the settings app's FallbackHome once the stock
+launcher is disabled, so a firm press on a slow remote did nothing. With the switch on, HomeKeyService
+takes the Home key itself and opens Home on release.
+
+Each hop gets its own assertion, as in test_key_filter.py: config.xml defines it off, Config reads it from
+the resource and a theme, HomeKeyService checks it before the stock_home_redirect path (which lets a held
+press through on purpose), and the docs name it.
+
+Run from the repository root: python3 -m unittest discover -s tests -v
+"""
+from pathlib import Path
+import unittest
+
+
+ROOT = Path(__file__).resolve().parents[1]
+
+
+def read(relative):
+ """Text of a repo file, or empty if it does not exist yet (each test then fails with its own message)."""
+ path = ROOT / relative
+ return path.read_text(encoding="utf-8") if path.is_file() else ""
+
+
+CONFIG_XML = read("launcher/app/src/main/res/values/config.xml")
+CONFIG_JAVA = read("launcher/app/src/main/java/com/gathin/tvhome/Config.java")
+HOME_KEY = read("launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java")
+THEMES_README = read("themes/README.md")
+TROUBLE = read("docs/TROUBLESHOOTING.md")
+
+
+class TestHomeLongPressHomeWiring(unittest.TestCase):
+
+ def test_config_xml_defines_it_off(self):
+ self.assertIn('<bool name="home_long_press_home">false</bool>', CONFIG_XML,
+ "config.xml must define home_long_press_home, off, so no TV changes until it is set")
+
+ def test_config_reads_resource_and_theme_override(self):
+ self.assertIn('R.bool.home_long_press_home', CONFIG_JAVA)
+ self.assertIn('"home_long_press_home"', CONFIG_JAVA,
+ "a theme's config.json must be able to set home_long_press_home")
+ self.assertIn('this.homeLongPressHome = homeLongPressHome', CONFIG_JAVA)
+
+ def test_service_takes_home_before_the_stock_redirect(self):
+ takes = HOME_KEY.find('homeLongPressHome && event.getKeyCode() == KeyEvent.KEYCODE_HOME')
+ redirect = HOME_KEY.find('event.getKeyCode() == KeyEvent.KEYCODE_HOME && !stockHome.isEmpty()')
+ self.assertNotEqual(takes, -1, "HomeKeyService.onKeyEvent must check home_long_press_home")
+ self.assertNotEqual(redirect, -1, "the stock_home_redirect check moved; recheck the order here")
+ self.assertLess(takes, redirect,
+ "the switch must come first: redirectHomeKey passes a held press on to Android")
+ block = HOME_KEY[takes:redirect]
+ self.assertIn('return true', block, "the Home key must be consumed, or Android still sees the hold")
+ self.assertRegex(block, r'ACTION_UP\s*&&\s*!event\.isCanceled\(\)\)\s*openHome\(\)',
+ "Home must open on release, once per press")
+
+ def test_docs_name_it(self):
+ self.assertIn('`home_long_press_home`', THEMES_README, "themes/README.md Keys table needs a row")
+ self.assertIn('home_long_press_home', TROUBLE, "TROUBLESHOOTING.md should point the symptom at it")
+ self.assertIn('LONG_PRESS_HOME_ALL_APPS', TROUBLE)
+
+ def test_docs_state_the_volume_trade(self):
+ self.assertIn('cannot have both', TROUBLE,
+ "the entry must say a firm Home press and a held volume ramp exclude each other")
+ self.assertIn('Volume Up/Down stop repeating', THEMES_README,
+ "the Keys row must warn that held keys stop repeating")
+ self.assertIn('Volume Up/Down stop repeating', CONFIG_XML,
+ "the config.xml comment must warn that held keys stop repeating")
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/themes/README.md b/themes/README.md
index d080af63c..f85d45896 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -122,6 +122,7 @@ A new key needs one there in the same pull request.
| `consume_volume_keys` | bool | `true` makes the key helpers swallow Volume Up/Down and repeat a held one themselves (after 500 ms, every 60 ms). Use it on firmware that applies a volume key both before the helper and when the helper hands it back, so one tap moves two steps (TCL G03 / BeyondTV4, Android 11, #1100). Needs `key_filter` on. 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`) |
| `power_on_home` | bool | For firmware that opens the Live TV app (`live_tv_package`) by itself at every power-on (Changhong / Homwee): until the first key press after boot or screen-on, that Live TV window is sent back to Home (`HOME_KEY_SERVICE=1`). Ignored with `boot_to_live_tv`, or with Live TV as the Open on start app. Off by default |
+| `home_long_press_home` | bool | Every Home press opens Home, a held one too. Android turns a Home press held past 400 ms into ALL_APPS for the system-image launcher, which nothing answers once the stock launcher is disabled, so a firm press on a slow remote did nothing (Philips TPM191E, Android 12, where `long_press_timeout` does not move that limit). Needs `key_filter` (`HOME_KEY_SERVICE=1`), so held keys such as Volume Up/Down stop repeating, confirmed on that Philips; single presses still step. Off by default |
| `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) |
| `clock_wallpaper` | bool | The clock screensaver over Home's wallpaper instead of black with a coloured glow; the clock still moves every minute (`false` by default) |