Skip to content

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

Launcher: keep the clocks moving where the firmware stops ACTION_TIME_TICK (TCL Android 9)

Axel Rosadoe9990b856f2d
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index e843cc078..c3b5bc3ea 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -1356,6 +1356,22 @@ Fix: `inputs_cec_state_only` true in `config.xml` and rebuild, or `"inputs_cec_s
Connected). The trade: a device without CEC, such as a laptop, shows no state either. The switch and its
screenshot: [docs/switches.md](switches.md).
+## Every clock stops after the power button, until a reboot (TCL UnionTV)
+
+**Seen on:** a TCL UnionTV (`ro.product.model` UnionTV, Android 9, `PPR2.180905.006.A1`).
+
+The clocks freeze at the minute the TV was last put to sleep with the power button, while the system time stays
+right. TCL's AlarmManager skips new alarms while `sys.tcl.powerstatus` reads `suspend` (logcat: `sys.tcl.powerstatus
+is suspend, skip setImplLocked`), and on waking it drops the one that sends `ACTION_TIME_TICK`:
+`dumpsys alarm | grep mLastTick` shows the last tick at the minute of the power press. Before Android 12 a
+`TextClock` only moves on that tick.
+
+The launcher redraws its own clocks every minute, and when the display comes back on, on Android 11 and older, so
+Home and the Clock screensaver keep time. Clocks in other apps stay frozen. Unplugging the TV, or setting the time
+once, arms the tick again until the next power press:
+`tools/tv.py "cmd alarm set-time $(( $(date +%s) * 1000 ))"` (the sum is done on the computer: the TV's shell
+overflows it).
+
## A key helper is bound and a held remote button stopped repeating
Hold volume up or down and the volume moves one step per press instead of ramping. The remote may be
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ClockFormat.java b/launcher/app/src/main/java/com/gathin/tvhome/ClockFormat.java
index a26954dd3..a8693b65e 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/ClockFormat.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockFormat.java
@@ -24,6 +24,21 @@ 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.java
new file mode 100644
index 000000000..d3fbd79b9
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockRefresh.java
@@ -0,0 +1,85 @@
+package com.gathin.tvhome;
+
+import android.content.Context;
+import android.hardware.display.DisplayManager;
+import android.os.Build;
+import android.view.Display;
+import android.view.View;
+
+/**
+ * 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.
+ */
+final class ClockRefresh implements Runnable {
+ static final boolean NEEDED = Build.VERSION.SDK_INT < Build.VERSION_CODES.S;
+ /** 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;
+
+ /** root holds the TextClocks. */
+ ClockRefresh(View root) {
+ this.root = root;
+ 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. */
+ void start() {
+ if (!NEEDED) return;
+ if (!listening) {
+ displays.registerDisplayListener(displayListener, null);
+ listening = true;
+ }
+ schedule();
+ }
+
+ void stop() {
+ root.removeCallbacks(this);
+ if (listening) {
+ displays.unregisterDisplayListener(displayListener);
+ listening = false;
+ }
+ }
+
+ @Override
+ public void run() {
+ ClockFormat.refresh(root);
+ schedule();
+ }
+
+ private void schedule() {
+ root.removeCallbacks(this);
+ root.postDelayed(this, 60_000L - System.currentTimeMillis() % 60_000L + MARGIN_MS);
+ }
+}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ClockScene.java b/launcher/app/src/main/java/com/gathin/tvhome/ClockScene.java
index dcae93ad7..d56e19f83 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/ClockScene.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ClockScene.java
@@ -27,7 +27,8 @@ import java.util.Set;
/**
* The clock screensaver's scene (layout dream_clock): the thin clock and date on black over a slow ambient
- * glow. Every minute the clock drifts to a new spot and the glow shifts colour, so nothing burns in.
+ * glow. Every minute the clock drifts to a new spot and the glow shifts colour, so nothing burns in; a
+ * ClockRefresh keeps its TextClocks current where Android would not.
* Shared by ClockDream (the system screensaver) and ClockActivity (Home left idle).
*/
final class ClockScene {
@@ -42,6 +43,7 @@ final class ClockScene {
private final Handler handler = new Handler(Looper.getMainLooper());
private final Random random = new Random();
private final View content;
+ private final ClockRefresh clockRefresh;
private final ImageView ambient;
private final GradientDrawable glow;
private int colorIndex;
@@ -75,6 +77,7 @@ final class ClockScene {
/** root is the inflated dream_clock layout. */
ClockScene(View root) {
content = root.findViewById(R.id.dreamContent);
+ clockRefresh = new ClockRefresh(content);
ambient = root.findViewById(R.id.dreamAmbient);
glow = new GradientDrawable();
glow.setGradientType(GradientDrawable.RADIAL_GRADIENT);
@@ -93,11 +96,13 @@ final class ClockScene {
});
handler.removeCallbacks(tick);
handler.postDelayed(tick, MOVE_MS);
+ clockRefresh.start();
if (wallpaperFile != null && !wallpaperShown) loadWallpaper();
}
void stop() {
handler.removeCallbacksAndMessages(null); // the tick and any glow steps still queued
+ clockRefresh.stop();
content.animate().cancel();
wallpaperGeneration++; // a decode still running must not attach its picture to a stopped scene
}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
index 12fc3090a..4e3b8bd06 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -427,8 +427,11 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
@Override
public void onReceive(Context context, Intent intent) {
updateClockVisibility();
+ clockRefresh.start(); // the wall clock was set: line the redraw up with the new minute
}
};
+ /** Keeps the Home clocks moving on Android before 12 when the firmware stops ACTION_TIME_TICK (see ClockRefresh). */
+ private ClockRefresh clockRefresh;
private final Runnable minuteTick = new Runnable() {
@Override
public void run() {
@@ -535,6 +538,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
if (!cfg.dockTitle) hero.setVisibility(View.GONE);
greeting = findViewById(R.id.greeting);
clockBlock = findViewById(R.id.leftBlock);
+ clockRefresh = new ClockRefresh(clockBlock);
greetingColor = greeting.getCurrentTextColor();
if (!cfg.showGreeting) greeting.setVisibility(View.GONE);
// Keep the other header layouts as designed: their extra lines change the block's centre.
@@ -1071,6 +1075,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
registerReceiver(timeReceiver, timeFilter);
}
updateClockVisibility();
+ clockRefresh.start(); // with timeReceiver: while Home is visible, paused or not
tileRefresh.onStart();
}
@@ -1324,6 +1329,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
super.onStop();
started = false;
unregisterReceiver(timeReceiver);
+ clockRefresh.stop();
handler.removeCallbacks(clockCheck);
stopped = true;
tileRefresh.onStop();