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
fix: Home applies Launcher settings changes when they are left with the Home button
iytsc9c67d53aaa2
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.javaindex 70c48b0b5..20263e7dc 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java@@ -40,6 +40,16 @@ final class Config {static final String ROWS_BELOW_DOCK_KEY = "rows_below_dock";static final String WALLPAPER_CHOICE_KEY = "wallpaper_choice";static final String DOCK_OPACITY_KEY = "dock_opacity";+ /**+ * Counts the changes made in Launcher settings. Home remembers the count it was built with and rebuilds on+ * resume when it differs, however the settings were left (see MainActivity#onResume).+ */+ static final String SETTINGS_REVISION_KEY = "settings_revision";++ /** True when Launcher settings changed something since Home was built at revision {@code seen}. */+ static boolean settingsChanged(long seen, long current) {+ return seen != current;+ }private static final String THEME_REVISION_NAME = "theme_revision";private static final String THEME_SIGNATURE_KEY = "theme_signature";@@ -425,21 +435,13 @@ final class Config {// An on-TV wallpaper pick overrides the theme: a filename from the wallpapers/// collection, or "none". Unset means the theme decides (off by default).String wallpaperChoice = choices.getString(WALLPAPER_CHOICE_KEY, null);- if ("none".equals(wallpaperChoice)) {+ List<File> chosen = WallpaperRotation.chosen(dir == null ? Collections.emptyList()+ : WallpaperRotation.images(new File(dir, "wallpapers")), wallpaper, wallpaperChoice);+ if (chosen != null) {wallpapers.clear();- wallpaper = null;- wallpaperEnabled = false;- } else if (wallpaperChoice != null && dir != null) {- File picked = WallpaperRotation.find(- WallpaperRotation.images(new File(dir, "wallpapers")), wallpaperChoice);- if (picked == null && wallpaperChoice.equals(- wallpaper != null ? wallpaper.getName() : "")) picked = wallpaper;- if (picked != null) {- wallpapers.clear();- wallpapers.add(picked);- wallpaper = picked;- wallpaperEnabled = true;- }+ wallpapers.addAll(chosen);+ wallpaper = chosen.isEmpty() ? null : chosen.get(0);+ wallpaperEnabled = !chosen.isEmpty();}// A festive skin comes only from a theme; config.xml has no festival.Festival festival = json == null ? Festival.NONE : Festival.parse(string(json, "festival", ""),diff --git a/launcher/app/src/main/java/com/gathin/tvhome/LauncherSettingsActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/LauncherSettingsActivity.javaindex 956c08c93..95a59d421 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/LauncherSettingsActivity.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/LauncherSettingsActivity.java@@ -59,7 +59,7 @@ public final class LauncherSettingsActivity extends Activity {if (columns == value) return;columns = value;choices.edit().putInt("columns", value).apply();- setResult(RESULT_OK);+ changed();refresh();});}@@ -71,7 +71,7 @@ public final class LauncherSettingsActivity extends Activity {if (rowsBelowDock == value) return;rowsBelowDock = value;choices.edit().putInt(Config.ROWS_BELOW_DOCK_KEY, value).apply();- setResult(RESULT_OK);+ changed();refresh();});}@@ -83,7 +83,7 @@ public final class LauncherSettingsActivity extends Activity {if (dockOpacity == value) return;dockOpacity = value;choices.edit().putInt(Config.DOCK_OPACITY_KEY, value).apply();- setResult(RESULT_OK);+ changed();refresh();});}@@ -102,7 +102,7 @@ public final class LauncherSettingsActivity extends Activity {if (!animations) advancedEffects = false;choices.edit().putBoolean("animations", animations).putBoolean("advanced_effects", advancedEffects).apply();- setResult(RESULT_OK);+ changed();refresh();});advancedChoice = findViewById(R.id.advancedChoice);@@ -130,7 +130,7 @@ public final class LauncherSettingsActivity extends Activity {dockOpacity = current.dockOpacity;animations = current.animations;advancedEffects = current.animations && current.advancedEffects;- setResult(RESULT_OK);+ changed();refresh();});findViewById(R.id.defaultHomeChoice).setOnClickListener(v -> {@@ -173,13 +173,13 @@ public final class LauncherSettingsActivity extends Activity {choices.edit().putString(Config.WALLPAPER_CHOICE_KEY,images.get(which).getName()).apply();}- setResult(RESULT_OK);+ changed();Toast.makeText(this, R.string.wallpaper_applied, Toast.LENGTH_SHORT).show();refresh();}).setNeutralButton(R.string.wallpaper_theme_default, (dialog, which) -> {choices.edit().remove(Config.WALLPAPER_CHOICE_KEY).apply();- setResult(RESULT_OK);+ changed();refresh();}).setNegativeButton(android.R.string.cancel, null)@@ -194,10 +194,20 @@ public final class LauncherSettingsActivity extends Activity {return -1;}+ /**+ * A choice was saved. Home rebuilds when it next resumes because the change count moved, whether these+ * settings are left with Back or with the remote's Home button (which cancels the activity result).+ */+ private void changed() {+ setResult(RESULT_OK);+ choices.edit().putLong(Config.SETTINGS_REVISION_KEY,+ choices.getLong(Config.SETTINGS_REVISION_KEY, 0) + 1).apply();+ }+private void setAdvanced(boolean enabled) {advancedEffects = enabled;choices.edit().putBoolean("advanced_effects", enabled).apply();- setResult(RESULT_OK);+ changed();refresh();}diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.javaindex e6d030c6d..2e37711c0 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java@@ -111,6 +111,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {*/private static final long TIME_VALID_AFTER_MS = 1_735_689_600_000L;private String liveTvPkg;+ /** Launcher settings' change count this Home was built with (see onResume). */+ private long settingsRevision;/** Idle time on Home before ClockActivity; 0 is off (config.xml, home_idle_clock_minutes). */private long idleClockMs;private final Runnable showIdleClock = () -> startActivity(new Intent(this, ClockActivity.class));@@ -347,6 +349,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {// 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);+ settingsRevision = settingsRevision();applyViewInputsHandler(cfg.handleViewInputs);settingsKeycodes = cfg.settingsKeycodes;settingsKeyPanel = cfg.settingsKeyPanel;@@ -790,6 +793,13 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {recreate();return;}+ // Something changed in Launcher settings: rebuild with it, however the settings were left. Only Back+ // delivered their RESULT_OK; Home (the remote's button) clears them off this task and the result comes+ // back cancelled, so a new wallpaper or layout waited for the next process start.+ if (Config.settingsChanged(settingsRevision, settingsRevision())) {+ recreate();+ return;+ }restartIdleClock();promptsPaused = false;if (grid.getAdapter() == null) grid.setAdapter(adapter); // dropped by onTrimMemory@@ -834,16 +844,24 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {}}+ /** Launcher settings' change count (Config.SETTINGS_REVISION_KEY); onResume rebuilds Home when it moved. */+ private long settingsRevision() {+ return getSharedPreferences(Config.SETTINGS_NAME, MODE_PRIVATE).getLong(Config.SETTINGS_REVISION_KEY, 0);+ }++ /**+ * Only "Reorder tiles" in Launcher settings still answers with a result: Home rebuilds (the saved choices are+ * reloaded) and then enters reorder mode. Every other change is picked up in onResume through the change count.+ */@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);- if (requestCode == LAUNCHER_SETTINGS_REQUEST && resultCode == RESULT_OK) {- if (data != null && data.getBooleanExtra(LauncherSettingsActivity.EXTRA_REORDER, false)) {- getIntent().putExtra(LauncherSettingsActivity.EXTRA_REORDER, true);- }- // The old activity must not consume the pending action while recreation is queued.+ if (requestCode == LAUNCHER_SETTINGS_REQUEST && resultCode == RESULT_OK+ && data != null && data.getBooleanExtra(LauncherSettingsActivity.EXTRA_REORDER, false)) {+ getIntent().putExtra(LauncherSettingsActivity.EXTRA_REORDER, true);+ // The old activity must not consume the pending action, or rebuild a second time in onResume.settingsRecreationPending = true;- // Reload saved layout choices before entering the existing Home reorder mode.+ settingsRevision = settingsRevision();recreate();}}diff --git a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.java b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.javaindex 06b658fa1..3f8371f86 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.java@@ -3,6 +3,7 @@ package com.gathin.tvhome;import java.io.File;import java.util.ArrayList;import java.util.Arrays;+import java.util.Collections;import java.util.Comparator;import java.util.List;import java.util.Locale;@@ -39,6 +40,22 @@ final class WallpaperRotation {return null;}+ /** The on-TV choice (Launcher settings, Wallpaper) that turns the wallpaper off. */+ static final String CHOICE_NONE = "none";++ /**+ * What an on-TV wallpaper choice puts on Home in place of the theme's rotation: null when the theme decides+ * (no choice, or a picture that is no longer there), an empty list for {@link #CHOICE_NONE}, or the one picture+ * chosen from the theme's collection or its single {@code single} wallpaper.+ */+ static List<File> chosen(List<File> collection, File single, String choice) {+ if (choice == null) return null;+ if (CHOICE_NONE.equals(choice)) return Collections.emptyList();+ File picked = find(collection, choice);+ if (picked == null && single != null && choice.equals(single.getName())) picked = single;+ return picked == null ? null : Collections.singletonList(picked);+ }+static File pick(List<File> images, String previous, Random random) {List<File> candidates = new ArrayList<>(images);if (candidates.size() > 1) candidates.removeIf(image -> image.getName().equals(previous));diff --git a/launcher/app/src/test/java/com/gathin/tvhome/WallpaperRotationTest.java b/launcher/app/src/test/java/com/gathin/tvhome/WallpaperRotationTest.javaindex 3946ea357..b014c3d89 100644--- a/launcher/app/src/test/java/com/gathin/tvhome/WallpaperRotationTest.java+++ b/launcher/app/src/test/java/com/gathin/tvhome/WallpaperRotationTest.java@@ -93,6 +93,33 @@ public class WallpaperRotationTest {assertNull(WallpaperRotation.find(images, "c.jpg"));}+ @Test+ public void anOnTvPickReplacesTheRotation() {+ List<File> collection = Arrays.asList(new File("a.jpg"), new File("b.jpg"), new File("c.jpg"));+ File single = new File("wallpaper.jpg");+ // No choice, or a picture that has gone: the theme's rotation decides.+ assertNull(WallpaperRotation.chosen(collection, single, null));+ assertNull(WallpaperRotation.chosen(collection, single, "gone.jpg"));+ assertNull(WallpaperRotation.chosen(collection, null, "wallpaper.jpg"));+ // None: no wallpaper at all.+ assertTrue(WallpaperRotation.chosen(collection, single, WallpaperRotation.CHOICE_NONE).isEmpty());+ assertTrue(WallpaperRotation.chosen(Collections.emptyList(), null, WallpaperRotation.CHOICE_NONE).isEmpty());+ // A picked picture is the only one shown, so the rotation can't move past it.+ assertEquals(Collections.singletonList("b.jpg"), names(WallpaperRotation.chosen(collection, single, "b.jpg")));+ assertEquals(Collections.singletonList("wallpaper.jpg"),+ names(WallpaperRotation.chosen(collection, single, "wallpaper.jpg")));+ // Picking again simply replaces the earlier pick.+ assertEquals(Collections.singletonList("c.jpg"), names(WallpaperRotation.chosen(collection, single, "c.jpg")));+ }++ @Test+ public void homeRebuildsWhenTheSettingsRevisionMoved() {+ assertFalse(Config.settingsChanged(0, 0));+ assertFalse(Config.settingsChanged(3, 3));+ assertTrue(Config.settingsChanged(0, 1));+ assertTrue(Config.settingsChanged(4, 0)); // settings cleared+ }+@Testpublic void dueOnlyWithRotationOnAndTheIntervalPassed() {long minute = 60_000L;