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: restore_key_services, off by default, gates the repair after a force stop
Cristian Rojasb7940a3c752c
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.mdindex 3352ef113..2fba97eea 100644--- a/docs/TROUBLESHOOTING.md+++ b/docs/TROUBLESHOOTING.md@@ -295,9 +295,9 @@ tools/tv.py 'dumpsys accessibility'| Input button | `com.gathin.tvhome/.InputKeyService` | `KEYCODE_TV`, `KEYCODE_TV_INPUT`, plus the keycodes in `input_key_keycodes` and `app_keys` (`config.xml` or a theme) |A force stop of the launcher (Settings > Apps, a cleaner app, `am force-stop`) takes both helpers off-that list. When the installer enabled a helper it also granted `WRITE_SECURE_SETTINGS`, and Home puts-the helpers that were running back on the list the next time it starts; a helper turned off in-Settings stays off.+that list. With `restore_key_services` on (`config.xml` or a theme) and `WRITE_SECURE_SETTINGS` granted+(`RESTORE_KEY_SERVICES=1` at install, `-RestoreKeyServices` on Windows), Home puts the helpers that were+running back on the list the next time it starts; a helper turned off in Settings stays off.- **Enabled** means the component is in that user's colon-separated list (the class may be written infull, `com.gathin.tvhome/com.gathin.tvhome.HomeKeyService`). Match the whole component.diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.javaindex b55b5a100..615caafaf 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java@@ -103,6 +103,8 @@ final class Config {final List<String> appKeys;/** 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). */+ final boolean restoreKeyServices;/** Whether themes may show a wallpaper (config.json, wallpaper). */final boolean wallpaperEnabled;/** Full-screen picture behind the launcher, or null for the plain colour. */@@ -135,7 +137,7 @@ final class Config {int columns, int rowsBelowDock, boolean animations, boolean advancedEffects,boolean shamsiDate, String greetingName, boolean moduleCards, boolean reducedMotion, boolean dockTitle, boolean dockRow, boolean reorderButton, boolean showNetworkPill, boolean iconOnlyButtons, boolean libraryButton, int wifiLabelWidth, boolean alwaysShowNames, boolean wallpaperTrueColor, String vpnApp,boolean showHomeSettingsShortcut, boolean showStats, boolean appLibrary, int backgroundColor, int skyIntensity,- int[] settingsKeycodes, boolean settingsKeyPanel, boolean wallpaperEnabled, File wallpaper, List<File> wallpapers,+ int[] settingsKeycodes, boolean settingsKeyPanel, boolean restoreKeyServices, boolean wallpaperEnabled, File wallpaper, List<File> wallpapers,int wallpaperRotationMinutes, int wallpaperDim, String wallpaperOrder, boolean overlayApplied,Festival festival, int[] inputKeycodes, List<String> appKeys,List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, boolean ambientGlow, int homeIdleClockMinutes) {@@ -177,6 +179,7 @@ final class Config {this.skyIntensity = skyIntensity;this.settingsKeycodes = settingsKeycodes;this.settingsKeyPanel = settingsKeyPanel;+ this.restoreKeyServices = restoreKeyServices;this.wallpaperEnabled = wallpaperEnabled;this.wallpaper = wallpaper;this.wallpapers = Collections.unmodifiableList(wallpapers);@@ -234,6 +237,7 @@ final class Config {int skyIntensity = res.getInteger(R.integer.sky_intensity);int[] settingsKeycodes = res.getIntArray(R.array.settings_key_keycodes);boolean settingsKeyPanel = res.getBoolean(R.bool.settings_key_panel);+ boolean restoreKeyServices = res.getBoolean(R.bool.restore_key_services);int[] inputKeycodes = res.getIntArray(R.array.input_key_keycodes);List<String> appKeys = new ArrayList<>(Arrays.asList(res.getStringArray(R.array.app_keys)));boolean cinematic = res.getBoolean(R.bool.cinematic_home);@@ -283,6 +287,7 @@ final class Config {skyIntensity = integer(json, "sky_intensity", skyIntensity, 0, 100);settingsKeycodes = intArray(json, "settings_key_keycodes", settingsKeycodes);settingsKeyPanel = bool(json, "settings_key_panel", settingsKeyPanel);+ restoreKeyServices = bool(json, "restore_key_services", restoreKeyServices);inputKeycodes = intArray(json, "input_key_keycodes", inputKeycodes);appKeys = stringList(json, "app_keys", appKeys);cinematic = bool(json, "cinematic_home", cinematic);@@ -344,7 +349,7 @@ final class Config {panelAction, inputAction,Math.max(1, columns), Math.max(0, rowsBelow), animations, advancedEffects,shamsi, greetingName, moduleCards, reducedMotion, dockTitle, dockRow, reorderButton, showNetworkPill, iconOnlyButtons, libraryButton, wifiLabelWidth, alwaysShowNames, wallpaperTrueColor, vpn, homeSettings, showStats, library, background,- Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, wallpaperEnabled, wallpaper,+ Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, restoreKeyServices, wallpaperEnabled, wallpaper,wallpapers, rotationMinutes, wallpaperDim, wallpaperOrder, applied,festival, inputKeycodes, appKeys, json == null ? Collections.emptyList() : raceCalendar(json), cinematic, ambientGlow,Math.max(0, idleClockMinutes));diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.javaindex e1ddd2e9e..c7b57642f 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java@@ -305,8 +305,9 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {density = getResources().getDisplayMetrics().density;// config.xml, overlaid by config.json from a pushed theme (see Config and tools/theme.sh).Config cfg = Config.load(this);- // After a force stop, put back the remote's accessibility helpers that Android took off the list.- ServiceRepair.restore(this);+ // restore_key_services: after a force stop, put back the remote's accessibility helpers that Android took+ // off the list (needs WRITE_SECURE_SETTINGS, granted by build-and-install with RESTORE_KEY_SERVICES=1).+ if (cfg.restoreKeyServices) ServiceRepair.restore(this);settingsKeycodes = cfg.settingsKeycodes;settingsKeyPanel = cfg.settingsKeyPanel;COLUMNS = cfg.columns;diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xmlindex 4ca1b963c..236166653 100644--- a/launcher/app/src/main/res/values/config.xml+++ b/launcher/app/src/main/res/values/config.xml@@ -77,6 +77,12 @@Both keys can also be set from a theme's config.json ("settings_key_keycodes": [83]). --><bool name="settings_key_panel">false</bool>+ <!-- A force stop of the launcher (Settings, a cleaner app, am force-stop) takes HomeKeyService and InputKeyService+ off the enabled list. true: Home puts the helpers that were running back when it starts; one turned off in+ Settings stays off. Needs WRITE_SECURE_SETTINGS, which build-and-install grants with RESTORE_KEY_SERVICES=1+ (-RestoreKeyServices on Windows). Can also be set with "restore_key_services": true in a theme's config.json. -->+ <bool name="restore_key_services">false</bool>+<!-- More remote buttons that open the input switcher, by Android keycode (INPUT_KEY_SERVICE=1build-and-install.sh; KEYCODE_TV always does). For buttons only a disabled app answered: the XiaomiMiTV-AXFR2 remote's PatchWall button is 192 (KEYCODE_BUTTON_5). `dumpsys window policy` lists whichdiff --git a/launcher/build-and-install.ps1 b/launcher/build-and-install.ps1index 08ae3019e..a55d748f1 100644--- a/launcher/build-and-install.ps1+++ b/launcher/build-and-install.ps1@@ -7,11 +7,13 @@# [-InputKeyService] remote's Input button opens the input switcher (Google TV), plus config.xml# input_key_keycodes and app_keys; re-pass on every install# [-HomeKeyService] remotes whose Home button sends KEYCODE_ALL_APPS (Xiaomi sticks)+# [-RestoreKeyServices] grants WRITE_SECURE_SETTINGS for restore_key_services (helpers back after a force stop)param([string]$TvHost = $env:TV_HOST,[string]$StockLauncher = '',[switch]$InputKeyService,- [switch]$HomeKeyService+ [switch]$HomeKeyService,+ [switch]$RestoreKeyServices)$ErrorActionPreference = 'Stop'# Pipe plain UTF-8 to native commands; the default here prepends a BOM that corrupts the first command.@@ -95,9 +97,12 @@ function Enable-Service([string]$Name) {$svc = "com.gathin.tvhome/.$Name"# Through stdin: Windows PowerShell 5.1 drops the inner double quotes from a native argument, and the# TV's shell then fails with "no closing quote" while the service stays off.- ('s=$(settings get secure enabled_accessibility_services); case "$s" in *' + $Name + '*) ;; null|"") settings put secure enabled_accessibility_services ' + $svc + ' ;; *) settings put secure enabled_accessibility_services "$s:' + $svc + '" ;; esac; settings put secure accessibility_enabled 1; pm grant com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS 2>/dev/null; echo ' + $Name + ' enabled') |+ ('s=$(settings get secure enabled_accessibility_services); case "$s" in *' + $Name + '*) ;; null|"") settings put secure enabled_accessibility_services ' + $svc + ' ;; *) settings put secure enabled_accessibility_services "$s:' + $svc + '" ;; esac; settings put secure accessibility_enabled 1; echo ' + $Name + ' enabled') |& $py -I ..\tools\tv.py --batch}if ($InputKeyService) { Enable-Service 'InputKeyService' }if ($HomeKeyService) { Enable-Service 'HomeKeyService' }+if ($RestoreKeyServices) {+ 'pm grant com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS && echo restore-granted' | & $py -I ..\tools\tv.py --batch+}Write-Host 'Installed. Press Home on the remote to see it.'diff --git a/launcher/build-and-install.sh b/launcher/build-and-install.shindex e5e6f3844..7f4e5a309 100755--- a/launcher/build-and-install.sh+++ b/launcher/build-and-install.sh@@ -185,10 +185,15 @@ esac# It also handles input_key_keycodes and app_keys (config.xml or a theme; a YouTube button)# HOME_KEY_SERVICE=1 remotes whose Home button sends KEYCODE_ALL_APPS instead of HOME, e.g. Xiaomi# sticks: the key is routed to the launcher (HomeKeyService)+# RESTORE_KEY_SERVICES=1 grants WRITE_SECURE_SETTINGS, so that with restore_key_services (config.xml or a+# theme) Home puts these helpers back after a force stop of the launcherenable_service() { # appends to enabled_accessibility_services without dropping other servicessvc=com.gathin.tvhome/.$1- "$PY" -I ../tools/tv.py "s=\$(settings get secure enabled_accessibility_services); case \"\$s\" in *$1*) ;; null|'') settings put secure enabled_accessibility_services $svc ;; *) settings put secure enabled_accessibility_services \"\$s:$svc\" ;; esac; settings put secure accessibility_enabled 1; pm grant com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS 2>/dev/null; echo $1 enabled"+ "$PY" -I ../tools/tv.py "s=\$(settings get secure enabled_accessibility_services); case \"\$s\" in *$1*) ;; null|'') settings put secure enabled_accessibility_services $svc ;; *) settings put secure enabled_accessibility_services \"\$s:$svc\" ;; esac; settings put secure accessibility_enabled 1; echo $1 enabled"}if [ "${INPUT_KEY_SERVICE:-0}" = 1 ]; then enable_service InputKeyService; fiif [ "${HOME_KEY_SERVICE:-0}" = 1 ]; then enable_service HomeKeyService; fi+if [ "${RESTORE_KEY_SERVICES:-0}" = 1 ]; then+ "$PY" -I ../tools/tv.py "pm grant com.gathin.tvhome android.permission.WRITE_SECURE_SETTINGS && echo restore-granted"+fiecho "Installed. Press Home on the remote to see it."diff --git a/themes/README.md b/themes/README.mdindex e9ae32cfe..06e243217 100644--- a/themes/README.md+++ b/themes/README.md@@ -69,6 +69,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can| `accent_color` | `#RRGGBB` | Colour of the focus glow while the festive skin is on; diya gold if not set || `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 |+| `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` || `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 |