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: ClockRefresh listens for the display itself and owns its TextClock walk
Axel Rosado6101b95bdc8e
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ClockFormat.java b/launcher/app/src/main/java/com/gathin/tvhome/ClockFormat.javaindex a8693b65e..a26954dd3 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/ClockFormat.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockFormat.java@@ -24,21 +24,6 @@ final class ClockFormat {}}- /**- * Redraws every TextClock under root with the current time. setFormat12Hour chooses the format again and- * calls the clock's onTimeChanged (checked in AOSP 8, 9 and 11), so setting the pattern it already has- * changes nothing but the text. For ClockRefresh, on Android before 12 where ACTION_TIME_TICK may stop.- */- static void refresh(View root) {- if (root instanceof TextClock) {- TextClock c = (TextClock) root;- c.setFormat12Hour(c.getFormat12Hour());- } else if (root instanceof ViewGroup) {- ViewGroup g = (ViewGroup) root;- for (int i = 0; i < g.getChildCount(); i++) refresh(g.getChildAt(i));- }- }-static boolean is24(Context ctx, String mode) {return "24".equals(mode) || !"12".equals(mode) && DateFormat.is24HourFormat(ctx);}diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ClockRefresh.java b/launcher/app/src/main/java/com/gathin/tvhome/ClockRefresh.javaindex d3fbd79b9..dc8cc53f6 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/ClockRefresh.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockRefresh.java@@ -5,48 +5,26 @@ import android.hardware.display.DisplayManager;import android.os.Build;import android.view.Display;import android.view.View;+import android.view.ViewGroup;+import android.widget.TextClock;/*** Keeps the TextClocks under a view ticking on their own. Before Android 12 a TextClock without seconds only* advances on ACTION_TIME_TICK; some firmware stops sending it for good after a sleep (a TCL Android 9 TV, once* the power button has been used), which freezes every clock until a reboot. From Android 12 a TextClock times* itself, so there this does nothing. Otherwise it redraws them at each minute change of the wall clock, and as- * soon as the display comes back on.+ * soon as the display comes back on: the wait to the next minute runs on uptime, which stands still while the set+ * sleeps. A display listener rather than ACTION_SCREEN_ON, as that same TCL firmware leaves the app that was on+ * screen out of that broadcast.*/-final class ClockRefresh implements Runnable {- static final boolean NEEDED = Build.VERSION.SDK_INT < Build.VERSION_CODES.S;+final class ClockRefresh implements Runnable, DisplayManager.DisplayListener {/** Past the minute change, so the redraw cannot land just before it and repaint the old minute. */private static final long MARGIN_MS = 250L;private final View root;private final DisplayManager displays;- /**- * The wait to the next minute runs on uptime, which stands still while the set sleeps, so after the power- * button the clock would show the time it went to sleep at for up to a minute. The display turning back on- * redraws it at once. A display listener rather than ACTION_SCREEN_ON: that same TCL firmware leaves the- * app that was on screen out of that broadcast.- */- private final DisplayManager.DisplayListener displayListener = new DisplayManager.DisplayListener() {- private boolean on = true;-- @Override- public void onDisplayChanged(int displayId) {- Display d = root.getDisplay();- if (d == null || d.getDisplayId() != displayId) return;- boolean nowOn = d.getState() == Display.STATE_ON;- if (nowOn && !on) run();- on = nowOn;- }-- @Override- public void onDisplayAdded(int displayId) {- }-- @Override- public void onDisplayRemoved(int displayId) {- }- };- private boolean listening;+ /** The display's last state seen by onDisplayChanged; it is on when start() runs. */+ private boolean on = true;/** root holds the TextClocks. */ClockRefresh(View root) {@@ -54,32 +32,62 @@ final class ClockRefresh implements Runnable {displays = (DisplayManager) root.getContext().getSystemService(Context.DISPLAY_SERVICE);}- /** Redraw at the next minute change, then every minute and when the display comes on; also re-aligns after the wall clock was set. */+ /**+ * Redraw at the next minute change, then every minute and when the display comes on; calling it again+ * re-aligns after the wall clock was set (registering the same listener twice is a no-op).+ */void start() {- if (!NEEDED) return;- if (!listening) {- displays.registerDisplayListener(displayListener, null);- listening = true;- }+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) return;+ displays.registerDisplayListener(this, null);schedule();}+ /** Safe to call when never started. */void stop() {root.removeCallbacks(this);- if (listening) {- displays.unregisterDisplayListener(displayListener);- listening = false;- }+ displays.unregisterDisplayListener(this);}@Overridepublic void run() {- ClockFormat.refresh(root);+ redraw(root);schedule();}+ /** Redraws when our display goes from off to on, not on its other changes. */+ @Override+ public void onDisplayChanged(int displayId) {+ Display d = root.getDisplay();+ if (d == null || d.getDisplayId() != displayId) return;+ boolean nowOn = d.getState() == Display.STATE_ON;+ if (nowOn && !on) run();+ on = nowOn;+ }++ @Override+ public void onDisplayAdded(int displayId) {+ }++ @Override+ public void onDisplayRemoved(int displayId) {+ }+private void schedule() {root.removeCallbacks(this);root.postDelayed(this, 60_000L - System.currentTimeMillis() % 60_000L + MARGIN_MS);}++ /**+ * setFormat12Hour chooses the format again and calls the clock's onTimeChanged (checked in AOSP 8, 9 and 11),+ * so setting the pattern it already has changes nothing but the text.+ */+ private static void redraw(View v) {+ if (v instanceof TextClock) {+ TextClock c = (TextClock) v;+ c.setFormat12Hour(c.getFormat12Hour());+ } else if (v instanceof ViewGroup) {+ ViewGroup g = (ViewGroup) v;+ for (int i = 0; i < g.getChildCount(); i++) redraw(g.getChildAt(i));+ }+ }}