Skip to content

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

Launcher: open_on_start_network_wait, so the boot's app waits for the network (#2033)

Hernán Zini117046a05660
diff --git a/docs/switches.md b/docs/switches.md
index 28650c749..0987134af 100644
--- a/docs/switches.md
+++ b/docs/switches.md
@@ -41,6 +41,7 @@ fits the rules; keys from before the rule sit on its wanted list until a screens
| `clock_wallpaper_dim` | <img src="switches/clock_wallpaper.jpg" width="320" alt="clock_wallpaper_dim on a TV"> |
| `clock_glow` | <img src="switches/clock_glow.jpg" width="320" alt="clock_glow on a TV"> |
| `open_on_start_choice` | <img src="switches/open_on_start_choice.jpg" width="320" alt="open_on_start_choice on a TV"> |
+| `open_on_start_network_wait` | <img src="switches/open_on_start_network_wait.jpg" width="320" alt="open_on_start_network_wait on a TV"> |
| `single_row` | <img src="switches/single_row.jpg" width="320" alt="single_row on a TV"> |
| `dock_band_all` | <img src="switches/single_row.jpg" width="320" alt="dock_band_all on a TV"> |
| `uniform_tiles` | <img src="switches/uniform_tiles.jpg" width="320" alt="uniform_tiles on a TV"> |
diff --git a/docs/switches/open_on_start_network_wait.jpg b/docs/switches/open_on_start_network_wait.jpg
new file mode 100644
index 000000000..01a22e271
Binary files /dev/null and b/docs/switches/open_on_start_network_wait.jpg differ
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
index 5d4b78fbd..5990a04d8 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
@@ -105,6 +105,8 @@ final class Config {
final boolean bootToLiveTv;
/** Show the Open on start row in Launcher settings (config.xml, open_on_start_choice). */
final boolean openOnStartChoice;
+ /** Seconds the boot's app waits for a validated network; 0 opens it at once (open_on_start_network_wait). */
+ final int openOnStartNetworkWait;
/** The focused dock app's name in large type above the dock (config.xml, dock_title). */
final boolean dockTitle;
/** The dock as its own row: band, no names, parked low (config.xml dock_row). false: one plain grid. */
@@ -272,7 +274,8 @@ final class Config {
List<RaceWeekend.Race> raceCalendar, boolean cinematicHome, boolean ambientGlow, boolean appGlow, boolean fadeRows, int homeIdleClockMinutes,
boolean keyFilter, boolean dockGlass, String glowStyle, boolean wallpaperCaptions,
boolean handleViewInputs, boolean tileMenu, boolean dockEvenPadding, boolean dockBand, boolean cinematicDots, boolean cinematicWhiteFocus, boolean wifiStatusColor, int cinematicScrim, int cinematicArt,
- Map<String, Set<String>> wallpaperMoods, boolean gamepadPassthrough, boolean consumeVolumeKeys, boolean powerOnHome, boolean homeLongPressHome, boolean wifiStatusWarnings, List<String> topBarApps, boolean showGreeting, boolean headerWhite, boolean clockWallpaper, int clockWallpaperDim, boolean clockGlow, String glassStyle, boolean singleRow, boolean dockBandAll, boolean lunarDate, int lunarUtcOffset, boolean dateBelowClock, boolean vpnPill, String locale, boolean powerOnHomeAlways, boolean inputsConnectedOnly) {
+ Map<String, Set<String>> wallpaperMoods, boolean gamepadPassthrough, boolean consumeVolumeKeys, boolean powerOnHome, boolean homeLongPressHome, boolean wifiStatusWarnings, List<String> topBarApps, boolean showGreeting, boolean headerWhite, boolean clockWallpaper, int clockWallpaperDim, boolean clockGlow, String glassStyle, boolean singleRow, boolean dockBandAll, boolean lunarDate, int lunarUtcOffset, boolean dateBelowClock, boolean vpnPill, String locale, boolean powerOnHomeAlways, boolean inputsConnectedOnly,
+ int openOnStartNetworkWait) {
this.handleViewInputs = handleViewInputs;
this.tileMenu = tileMenu;
this.inputKeycodes = inputKeycodes;
@@ -368,6 +371,7 @@ final class Config {
this.homeLongPressHome = homeLongPressHome;
this.powerOnHomeAlways = powerOnHomeAlways;
this.inputsConnectedOnly = inputsConnectedOnly;
+ this.openOnStartNetworkWait = openOnStartNetworkWait;
this.wifiStatusWarnings = wifiStatusWarnings;
this.topBarApps = Collections.unmodifiableList(topBarApps);
this.showGreeting = showGreeting;
@@ -431,6 +435,7 @@ final class Config {
boolean reducedMotion = res.getBoolean(R.bool.reduced_motion);
boolean bootToLiveTv = res.getBoolean(R.bool.boot_to_live_tv);
boolean openOnStartChoice = res.getBoolean(R.bool.open_on_start_choice);
+ int openOnStartNetworkWait = res.getInteger(R.integer.open_on_start_network_wait);
boolean dockTitle = res.getBoolean(R.bool.dock_title);
boolean dockRow = res.getBoolean(R.bool.dock_row);
boolean topMenu = res.getBoolean(R.bool.top_menu);
@@ -536,6 +541,7 @@ final class Config {
reducedMotion = bool(json, "reduced_motion", reducedMotion);
bootToLiveTv = bool(json, "boot_to_live_tv", bootToLiveTv);
openOnStartChoice = bool(json, "open_on_start_choice", openOnStartChoice);
+ openOnStartNetworkWait = integer(json, "open_on_start_network_wait", openOnStartNetworkWait, 0, 600);
dockTitle = bool(json, "dock_title", dockTitle);
dockRow = bool(json, "dock_row", dockRow);
topMenu = bool(json, "top_menu", topMenu);
@@ -665,7 +671,8 @@ final class Config {
dockBand, cinematicDots, cinematicWhiteFocus, wifiStatusColor, cinematicScrim, cinematicArt, wallpaperMoods, gamepadPassthrough,
consumeVolumeKeys, powerOnHome, homeLongPressHome, wifiStatusWarnings, topBarApps, showGreeting, headerWhite, clockWallpaper,
Math.max(0, Math.min(90, clockWallpaperDim)), clockGlow, glassStyle, singleRow && dockRow, dockBandAll, lunar, lunarOffset,
- dateBelowClock, vpnPill, locale, powerOnHomeAlways, inputsConnectedOnly);
+ dateBelowClock, vpnPill, locale, powerOnHomeAlways, inputsConnectedOnly,
+ Math.max(0, Math.min(600, openOnStartNetworkWait)));
}
/**
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 179614434..545826236 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -251,6 +251,24 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
private boolean bootToLiveTv;
/** open_on_start_choice: the app picked in Launcher settings may open on the first Home of each boot. */
private boolean openOnStartChoice;
+ /** open_on_start_network_wait, in ms; the boot's app while it waits for the network, and until when. */
+ private long openOnStartWaitMs;
+ private Intent startPending;
+ private long startDeadline;
+ private final Runnable openWhenOnline = new Runnable() {
+ @Override
+ public void run() {
+ if (startPending == null) return;
+ if (!OpenOnStart.opensNow(OpenOnStart.online(MainActivity.this), SystemClock.elapsedRealtime(),
+ startDeadline)) {
+ handler.postDelayed(this, 500);
+ return;
+ }
+ Intent i = startPending;
+ startPending = null;
+ open(i);
+ }
+ };
/** hidden_apps as the adapter sees them (config.xml or a theme's config.json): a hidden app gets no card either. */
private Set<String> hiddenApps = Collections.emptySet();
private List<Cards.Card> cards = Collections.emptyList();
@@ -415,6 +433,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
idleClockMs = cfg.homeIdleClockMinutes * MINUTE_MS;
bootToLiveTv = cfg.bootToLiveTv;
openOnStartChoice = cfg.openOnStartChoice;
+ openOnStartWaitMs = cfg.openOnStartNetworkWait * 1000L;
liveTvAction = cfg.liveTvAction;
liveTvInputId = cfg.liveTvInputId;
appLibraryEnabled = cfg.appLibrary;
@@ -1162,6 +1181,8 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
ambient.animate().cancel();
heroArt.animate().cancel();
handler.removeCallbacks(minuteTick);
+ handler.removeCallbacks(openWhenOnline);
+ startPending = null; // leaving Home before the network came back: the boot's app stays closed
stopStats();
if (diya != null) diya.stop();
cancelPendingFocusScroll();
@@ -2883,6 +2904,13 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
if (!prefs.edit().putInt(OpenOnStart.BOOT_KEY, boot).commit()) return false;
Intent i = bootToLiveTv ? liveTvIntent() : OpenOnStart.intent(getPackageManager(), app);
if (i == null) return false;
+ // open_on_start_network_wait: Home stays on screen until the network is back or the wait is over.
+ if (openOnStartWaitMs > 0 && !OpenOnStart.online(this)) {
+ startPending = i;
+ startDeadline = SystemClock.elapsedRealtime() + openOnStartWaitMs;
+ handler.postDelayed(openWhenOnline, 500);
+ return false;
+ }
open(i);
return true;
}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/OpenOnStart.java b/launcher/app/src/main/java/com/gathin/tvhome/OpenOnStart.java
index c80fdb9f6..23cd992da 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/OpenOnStart.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/OpenOnStart.java
@@ -3,6 +3,9 @@ package com.gathin.tvhome;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
+import android.net.ConnectivityManager;
+import android.net.Network;
+import android.net.NetworkCapabilities;
import android.provider.Settings;
/** open_on_start_choice: the app Home opens once after each boot, picked in Launcher settings. */
@@ -31,6 +34,19 @@ final class OpenOnStart {
ctx.getSharedPreferences(BOOT_PREFS, Context.MODE_PRIVATE).edit().putInt(BOOT_KEY, boot(ctx)).commit();
}
+ /** open_on_start_network_wait: the app opens once the network is validated, or when the wait is over. */
+ static boolean opensNow(boolean online, long now, long deadline) {
+ return online || now >= deadline;
+ }
+
+ /** Android has reached the internet through the active network (ACCESS_NETWORK_STATE). */
+ static boolean online(Context ctx) {
+ ConnectivityManager cm = ctx.getSystemService(ConnectivityManager.class);
+ Network n = cm != null ? cm.getActiveNetwork() : null;
+ NetworkCapabilities caps = n != null ? cm.getNetworkCapabilities(n) : null;
+ return caps != null && caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
+ }
+
/** The app's TV entry point, or its phone one; null when it is uninstalled or disabled, so Home stays. */
static Intent intent(PackageManager pm, String pkg) {
Intent i = pm.getLeanbackLaunchIntentForPackage(pkg);
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index c963338f1..9a5695e83 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -47,6 +47,13 @@
Off by default; a theme can set "open_on_start_choice": true. -->
<bool name="open_on_start_choice">false</bool>
+ <!-- Seconds the first Home after the TV starts waits for a working internet connection before it opens the
+ boot_to_live_tv or Open on start app. A streaming app opened before the network is back shows an error,
+ and after a power cut Wi-Fi can take minutes, as the router starts again too. Home stays on screen
+ meanwhile, and leaving Home cancels the opening. 0, the default: open at once. Up to 600; a theme can
+ set "open_on_start_network_wait": 180. -->
+ <integer name="open_on_start_network_wait">0</integer>
+
<!-- Some TVs give their Live TV app no leanback entry point at all, so `live_tv_package` above
resolves to nothing (TCL Android TV 9 on China-market sets is one). This action is then sent
to that package instead, and the app starts normally. Leave empty to omit. -->
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/OpenOnStartTest.java b/launcher/app/src/test/java/com/gathin/tvhome/OpenOnStartTest.java
index c230c55f8..9fdb8e965 100644
--- a/launcher/app/src/test/java/com/gathin/tvhome/OpenOnStartTest.java
+++ b/launcher/app/src/test/java/com/gathin/tvhome/OpenOnStartTest.java
@@ -29,4 +29,13 @@ public class OpenOnStartTest {
@Test public void theLauncherItselfIsNeverOpened() {
assertFalse(OpenOnStart.due(12, 11, SELF, SELF));
}
+
+ @Test public void onlineTheAppOpensAtOnce() {
+ assertTrue(OpenOnStart.opensNow(true, 1_000, 60_000));
+ }
+
+ @Test public void offlineTheAppWaitsUntilTheEndOfTheWait() {
+ assertFalse(OpenOnStart.opensNow(false, 59_999, 60_000));
+ assertTrue(OpenOnStart.opensNow(false, 60_000, 60_000));
+ }
}
diff --git a/themes/README.md b/themes/README.md
index 9fe471a6e..a2e2f685b 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -94,6 +94,7 @@ A new key needs one there in the same pull request.
| `reduced_motion` | bool | Calmer motion for weak GPUs: the highlight slides without bouncing and settles within 5 frames, every animation lasts 90 ms or less, names, the top shelf, the glow and the highlight appear instead of fading, and there is no tile entrance (`false` by default) |
| `boot_to_live_tv` | bool | Open the Live TV app (`live_tv_package`) on the first Home after the TV starts, once per boot |
| `open_on_start_choice` | bool | `true` adds an **Open on start** row to Launcher settings: pick an app on the TV, and the first Home after each boot opens it instead (once per boot; `boot_to_live_tv` wins when both are set; an app that is gone or disabled leaves Home on screen). Off by default |
+| `open_on_start_network_wait` | 0 to 600 | Seconds the first Home after the TV starts waits for a working internet connection before it opens the `boot_to_live_tv` or Open on start app. A streaming app opened before the network is back shows an error, and after a power cut Wi-Fi can take minutes, as the router starts again too. Home stays on screen meanwhile, and leaving Home cancels the opening. `0`, the default, opens the app at once |
| `focus_overshoot` | bool | The highlight and the focused tile swing past their target before settling (`true` by default); `false` glides straight there with smooth scrolling |
| `vpn_app` | string | App the network pill opens when a VPN is configured; also shows a red "VPN off" badge while no VPN is up |
| `vpn_pill` | bool | The VPN as its own pill after the network pill instead of a badge inside it: solid green while a VPN is up, solid red "VPN off" while none is and `vpn_app` is installed, hidden otherwise. Pressing it opens `vpn_app` (without it, the App library, or VPN settings with `app_library` off); it keeps its label with `icon_only_buttons`; the network pill then opens Wi-Fi settings. Ignored with `top_menu`. A VPN app's kill switch holds a VPN up while the app says disconnected, so the pill stays green then (`false` by default) |