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
Merge remote-tracking branch 'origin/main' into fix/input-key-service-after-force-stop
Cristian Rojas91fc3573bfd3
diff --cc launcher/app/src/main/AndroidManifest.xmlindex 48c919343,04ad18af3..4cee7a6b2--- a/launcher/app/src/main/AndroidManifest.xml+++ b/launcher/app/src/main/AndroidManifest.xml@@@ -14,10 -14,9 +14,13 @@@FINE" rule does not apply here. --><uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"tools:ignore="CoarseFineLocation" />+ <!-- Puts the remote's accessibility helpers back after a force stop of this app took them off the enabled+ list (ServiceRepair). Granted with pm grant by build-and-install when a helper is enabled. -->+ <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"+ tools:ignore="ProtectedPermissions" />+ <!-- YaOS (Yandex TV OS): HDMI, AV and the tuner all play in com.yandex.tv.live, whose activities require+ this permission (protection level normal, so it is granted at install). Ignored on other TVs. -->+ <uses-permission android:name="yandex.tv.permission.ACCESS_TV_SOURCE" /><!-- Android 11+ package visibility: lets the launcher list the TV apps it shows as tiles, and theapps that declare a module card (docs/specs/card.md). -->diff --cc launcher/app/src/main/java/com/gathin/tvhome/Config.javaindex 615caafaf,9fa072656..d742a3fc8--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java@@@ -101,10 -114,13 +114,15 @@@ final class Configfinal int[] inputKeycodes;/** Remote buttons that open an app, "keycode:package" or "KEYCODE_NAME:package" (config.xml app_keys). */final List<String> appKeys;+ /** Whether the key services request key filtering (config.xml or theme key_filter); false keeps key+ * auto-repeat working on firmware whose AccessibilityInputFilter drops repeats (TCL Android 12). */+ final boolean keyFilter;+ /** Stock launcher whose home screen is sent back here if the firmware revives it (config.xml stock_home_redirect). */+ final String stockHomeRedirect;/** 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. */@@@ -128,21 -146,39 +148,39 @@@final boolean cinematicHome;/** The glow in the focused app's colour behind the dock (config.xml, ambient_glow); false keeps the background plain. */final boolean ambientGlow;+ /** The focus highlight in the focused app's colour on every tile (config.xml, app_glow), as cinematic_home does for the dock. */+ final boolean appGlow;/** Minutes Home may sit untouched before the clock screensaver (config.xml, home_idle_clock_minutes); 0 is off. */final int homeIdleClockMinutes;+ /** The dock band as light frosted glass like the pills (config.xml, dock_glass); false keeps the solid band. */+ final boolean dockGlass;+ /** Shape of the glow behind the focused app (config.xml, glow_style): {@link #GLOW_RADIAL} or {@link #GLOW_HORIZON}. */+ final String glowStyle;++ static final String GLOW_RADIAL = "radial", GLOW_HORIZON = "horizon";+ /** Show each rotating wallpaper's name from wallpapers/captions.txt (config.xml / theme wallpaper_captions). */+ final boolean wallpaperCaptions;+ /** Answer VIEW_INPUTS with the Inputs menu (handle_view_inputs); see InputsRequestActivity. */+ final boolean handleViewInputs;private Config(List<String> dockApps, boolean fillDock, List<String> hiddenApps, String liveTvPackage,- String liveTvAction, Map<String, String> launchActions, Map<String, String> appLabels,- Map<String, String> appBanners, String sourcePanelService, String sourcePanelAction, String inputAction,- 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,+ String liveTvAction, String liveTvInputId, Map<String, String> launchActions, Map<String, String> appLabels,+ Map<String, String> appBanners, String sourcePanelService, String sourcePanelAction,+ String sourcePanelExtra, boolean coocaaSources, String inputAction,+ String inputUriScheme, int columns, int rowsBelowDock, boolean animations, boolean advancedEffects,+ boolean shamsiDate, String greetingName, boolean moduleCards, boolean reducedMotion, boolean bootToLiveTv, boolean dockTitle, boolean dockRow, boolean reorderButton, boolean showNetworkPill, boolean showInputsPill, boolean iconOnlyButtons, boolean libraryButton, int wifiLabelWidth, boolean alwaysShowNames, boolean wallpaperTrueColor, boolean focusOvershoot, 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) {+ int wallpaperRotationMinutes, int wallpaperDim, int dockOpacity, String wallpaperOrder, boolean overlayApplied,+ Festival festival, int[] inputKeycodes, List<String> appKeys, String stockHomeRedirect,+ List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, boolean ambientGlow, boolean appGlow, int homeIdleClockMinutes,+ boolean keyFilter, boolean dockGlass, String glowStyle, boolean wallpaperCaptions,+ boolean handleViewInputs) {+ this.handleViewInputs = handleViewInputs;this.inputKeycodes = inputKeycodes;this.appKeys = Collections.unmodifiableList(appKeys);+ this.keyFilter = keyFilter;+ this.stockHomeRedirect = stockHomeRedirect;this.dockApps = Collections.unmodifiableList(dockApps);this.fillDock = fillDock;this.hiddenApps = Collections.unmodifiableList(hiddenApps);@@@ -237,12 -297,17 +300,18 @@@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);+ boolean handleViewInputs = res.getBoolean(R.bool.handle_view_inputs);List<String> appKeys = new ArrayList<>(Arrays.asList(res.getStringArray(R.array.app_keys)));+ String stockHomeRedirect = res.getString(R.string.stock_home_redirect).trim();boolean cinematic = res.getBoolean(R.bool.cinematic_home);boolean ambientGlow = res.getBoolean(R.bool.ambient_glow);+ boolean appGlow = res.getBoolean(R.bool.app_glow);int idleClockMinutes = res.getInteger(R.integer.home_idle_clock_minutes);+ boolean keyFilter = res.getBoolean(R.bool.key_filter);+ boolean dockGlass = res.getBoolean(R.bool.dock_glass);+ String glowStyle = res.getString(R.string.glow_style);boolean applied = false;File dir = dir(ctx);@@@ -287,12 -360,17 +364,18 @@@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);+ handleViewInputs = bool(json, "handle_view_inputs", handleViewInputs);appKeys = stringList(json, "app_keys", appKeys);+ stockHomeRedirect = string(json, "stock_home_redirect", stockHomeRedirect);cinematic = bool(json, "cinematic_home", cinematic);ambientGlow = bool(json, "ambient_glow", ambientGlow);+ appGlow = bool(json, "app_glow", appGlow);idleClockMinutes = integer(json, "home_idle_clock_minutes", idleClockMinutes, 0, 1440);+ keyFilter = bool(json, "key_filter", keyFilter);+ dockGlass = bool(json, "dock_glass", dockGlass);+ glowStyle = string(json, "glow_style", glowStyle);}// A theme push or reset invalidates choices made on the TV. On first use, remember the// current theme without clearing choices from an older launcher version.@@@ -344,15 -423,15 +428,15 @@@Festival festival = json == null ? Festival.NONE : Festival.parse(string(json, "festival", ""),string(json, "festival_until", ""), string(json, "greeting", ""), string(json, "accent_color", ""));- return new Config(dock, fillDock, hidden, liveTv, liveTvAction, packageMap(launchActions), packageMap(appLabels),+ return new Config(dock, fillDock, hidden, liveTv, liveTvAction, liveTvInputId, packageMap(launchActions), packageMap(appLabels),packageMap(appBanners), panelService,- panelAction, inputAction,+ panelAction, panelExtra, coocaaSources, inputAction, inputUriScheme,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,+ shamsi, greetingName, moduleCards, reducedMotion, bootToLiveTv, dockTitle, dockRow, reorderButton, showNetworkPill, showInputsPill, iconOnlyButtons, libraryButton, wifiLabelWidth, alwaysShowNames, wallpaperTrueColor, focusOvershoot, 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));+ wallpapers, rotationMinutes, wallpaperDim, dockOpacity, wallpaperOrder, applied,+ festival, inputKeycodes, appKeys, stockHomeRedirect, json == null ? Collections.emptyList() : raceCalendar(json), cinematic, ambientGlow, appGlow,+ Math.max(0, idleClockMinutes), keyFilter, dockGlass, glowStyle, wallpaperCaptions, handleViewInputs);}/**diff --cc launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.javaindex bba78012d,80baab2a5..634dec909--- a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java@@@ -31,8 -51,43 +51,44 @@@ public class HomeKeyService extends Acc@Overrideprotected void onServiceConnected() {super.onServiceConnected();+ ServiceRepair.connected(this, getClass());settingsScancodes = getResources().getIntArray(R.array.settings_key_scancodes);+ // The service is directBootAware: Android 11 skips a service that is not while the user is still+ // locked at boot, writes accessibility_enabled=0 and, on TCL G03 firmware, never binds it after the+ // unlock. Config.load reads credential-protected storage, so wait for the unlock before reading it.+ UserManager users = getSystemService(UserManager.class);+ if (users.isUserUnlocked()) {+ loadConfig();+ return;+ }+ unlockReceiver = new BroadcastReceiver() {+ @Override+ public void onReceive(Context context, Intent intent) {+ stopWaitingForUnlock();+ loadConfig();+ }+ };+ registerReceiver(unlockReceiver, new IntentFilter(Intent.ACTION_USER_UNLOCKED));+ // The unlock may have happened between the check and the registration.+ if (users.isUserUnlocked()) {+ stopWaitingForUnlock();+ loadConfig();+ }+ }++ private void stopWaitingForUnlock() {+ if (unlockReceiver == null) return;+ unregisterReceiver(unlockReceiver);+ unlockReceiver = null;+ }++ @Override+ public void onDestroy() {+ stopWaitingForUnlock();+ super.onDestroy();+ }++ private void loadConfig() {// Keycodes and the panel choice can also come from a theme; theme.sh restarts this service.Config config = Config.load(this);settingsKeycodes = config.settingsKeycodes;@@@ -81,15 -144,15 +145,22 @@@return true;}+ /** Unbound by Android: the user turned the helper off, so Home doesn't put it back (ServiceRepair). */+ @Override+ public boolean onUnbind(Intent intent) {+ ServiceRepair.disconnected(this, getClass());+ return super.onUnbind(intent);+ }+@Overridepublic void onAccessibilityEvent(AccessibilityEvent event) {+ // stock_home_redirect: the firmware turned the stock launcher back on and its home screen came up.+ if (stockHome.isEmpty() || event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) return;+ CharSequence cls = event.getClassName();+ if (cls != null && stockHome.contains(cls.toString())) {+ startActivity(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME).setPackage(getPackageName())+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED));+ }}@Overridediff --cc launcher/app/src/main/java/com/gathin/tvhome/MainActivity.javaindex c7b57642f,d5a729c21..e8218ba59--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java@@@ -305,9 -338,7 +338,10 @@@ public class MainActivity extends Activdensity = getResources().getDisplayMetrics().density;// config.xml, overlaid by config.json from a pushed theme (see Config and tools/theme.sh).Config cfg = Config.load(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);+ applyViewInputsHandler(cfg.handleViewInputs);settingsKeycodes = cfg.settingsKeycodes;settingsKeyPanel = cfg.settingsKeyPanel;COLUMNS = cfg.columns;diff --cc launcher/build-and-install.shindex 7f4e5a309,0ceb1ac75..5b4e12de4--- a/launcher/build-and-install.sh+++ b/launcher/build-and-install.sh@@@ -185,11 -185,13 +185,15 @@@ esa# 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 launcher+ # TCL firmware (TclAppBoot) refuses to bind an app's accessibility service while the app is not running unless it+ # holds the AUTO_START app-op, so grant it first; other TVs do not know the op and ignore it. A service that is+ # already listed was refused while the APK was replaced, and binds again only once the list changes, so clear it,+ # switch accessibility off and write it back (as tools/theme.sh does).enable_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; echo $1 enabled"+ "$PY" -I ../tools/tv.py "cmd appops set com.gathin.tvhome AUTO_START allow 2>/dev/null; s=\$(settings get secure enabled_accessibility_services); case \"\$s\" in *$1*) settings put secure enabled_accessibility_services ''; settings put secure accessibility_enabled 0; sleep 1; settings put secure enabled_accessibility_services \"\$s\" ;; 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; fidiff --cc themes/README.mdindex 06e243217,9c1c549bf..020671b30--- a/themes/README.md+++ b/themes/README.md@@@ -69,13 -84,20 +84,21 @@@ is ignored, and a file that doesn't par| `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` |+ | `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 |+ | `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`) |+ | `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` |+ | `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`) |+ | `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`. Prefix an entry with `hold:` to open a second app on a long press, e.g. `"hold:190:com.netflix.ninja"` || `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) |+ | `glow_style` | string | Shape of the glow behind the focused app, in its colour: `radial` (default) or `horizon`, the colour washing down from the top edge to black; the cinematic shelf keeps its own || `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 |+ | `dock_glass` | bool | The dock band as light frosted glass like the top bar's pills (`false` by default); suits `sky_intensity` or a wallpaper, where the solid band reads as a dark slab || `ambient_glow` | bool | The glow behind the dock in the focused app's colour (`true` by default); `false` keeps only `background_color` or the wallpaper, e.g. for a calm photo background |+ | `app_glow` | bool | The focus highlight glows in the focused app's colour on every tile, as `cinematic_home` does for the dock (`false` by default) |## Wallpapers