Skip to content

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

launcher: red "VPN off" badge on the network pill when vpn_app is set and no VPN is up

Florian Zaruba0c5ddcedb8c0
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 448e52157..fbbde735b 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -526,10 +526,10 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
/** Shows the Wi-Fi network name on the button when we can read it, otherwise the connection type. */
private void updateWifiLabel() {
String text = getString(R.string.wifi);
- boolean vpn = false;
+ boolean vpn = false, online = false;
try {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
- boolean online = false, wifi = false, ethernet = false;
+ boolean wifi = false, ethernet = false;
// All networks, not just the active one: with a VPN up the active network is the VPN itself.
for (Network net : cm != null ? cm.getAllNetworks() : new Network[0]) {
NetworkCapabilities caps = cm.getNetworkCapabilities(net);
@@ -559,10 +559,12 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
}
} catch (Exception ignored) {
}
- if (vpn) {
- // Network name, then a green lock-and-VPN capsule drawn in place of the word "VPN".
- String badge = getString(R.string.vpn);
- VpnBadge span = new VpnBadge(getDrawable(R.drawable.ic_lock), density);
+ // With a VPN app configured, a VPN that is down matters too: show a red "VPN off" capsule then.
+ boolean vpnDown = !vpn && online && !vpnApp.isEmpty();
+ if (vpn || vpnDown) {
+ // Network name, then the green lock-and-VPN (or red "VPN off") capsule drawn in place of the word.
+ String badge = getString(vpn ? R.string.vpn : R.string.vpn_off);
+ VpnBadge span = new VpnBadge(vpn ? getDrawable(R.drawable.ic_lock) : null, density);
// The pill has a maximum width and ellipsizes at the end, which would cut the badge off after
// a long network name, so shorten the name to whatever room the badge leaves. The total paddings
// include the Wi-Fi icon.
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java b/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java
index a585d9243..229e869f8 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/VpnBadge.java
@@ -10,20 +10,27 @@ import androidx.annotation.NonNull;
/**
* The green "VPN" capsule drawn inside the network pill while a VPN is up: a lock and the word VPN, dark on
- * green, so it reads on both the frosted and the focused (white) pill.
+ * green, so it reads on both the frosted and the focused (white) pill. With a VPN app configured and no VPN
+ * up, the same capsule turns red, without the lock, so a dropped VPN is noticed.
*/
final class VpnBadge extends ReplacementSpan {
private static final int GREEN = 0xFF30D158;
private static final int INK = 0xFF06290F;
+ private static final int RED = 0xFFFF453A;
+ private static final int INK_OFF = 0xFFFFFFFF;
private final Drawable lock;
private final float density;
+ private final int fill, ink;
private final RectF rect = new RectF();
+ /** @param lock the lock icon for the "up" badge, or null for the red "off" badge */
VpnBadge(Drawable lock, float density) {
- this.lock = lock.mutate();
- this.lock.setTint(INK);
+ this.fill = lock != null ? GREEN : RED;
+ this.ink = lock != null ? INK : INK_OFF;
+ this.lock = lock != null ? lock.mutate() : null;
+ if (this.lock != null) this.lock.setTint(ink);
this.density = density;
}
@@ -32,7 +39,11 @@ final class VpnBadge extends ReplacementSpan {
}
private float lockSize(Paint p) {
- return p.getTextSize() * 0.8f;
+ return lock != null ? p.getTextSize() * 0.8f : 0;
+ }
+
+ private float lockGap() {
+ return lock != null ? 4 * density : 2 * density;
}
@Override
@@ -42,7 +53,7 @@ final class VpnBadge extends ReplacementSpan {
float w = paint.measureText(text, start, end);
paint.setTextSize(old);
// margin + left pad + lock + gap + text + right pad
- return (int) (8 * density + 7 * density + lockSize(paint) + 4 * density + w + 9 * density);
+ return (int) (8 * density + 7 * density + lockSize(paint) + lockGap() + w + 9 * density);
}
@Override
@@ -57,18 +68,20 @@ final class VpnBadge extends ReplacementSpan {
rect.set(left, cy - h / 2f, right, cy + h / 2f);
int oldColor = paint.getColor();
- paint.setColor(GREEN);
+ paint.setColor(fill);
c.drawRoundRect(rect, h / 2f, h / 2f, paint);
int lx = (int) (left + 7 * density);
- lock.setBounds(lx, (int) (cy - lockPx / 2f), (int) (lx + lockPx), (int) (cy + lockPx / 2f));
- lock.draw(c);
+ if (lock != null) {
+ lock.setBounds(lx, (int) (cy - lockPx / 2f), (int) (lx + lockPx), (int) (cy + lockPx / 2f));
+ lock.draw(c);
+ }
- paint.setColor(INK);
+ paint.setColor(ink);
paint.setTextSize(textSize(paint));
Paint.FontMetrics fm = paint.getFontMetrics();
float ty = cy - (fm.ascent + fm.descent) / 2f;
- c.drawText(text, start, end, lx + lockPx + 4 * density, ty, paint);
+ c.drawText(text, start, end, lx + lockPx + lockGap(), ty, paint);
paint.setTextSize(base);
paint.setColor(oldColor);
}
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 32937b8b5..6628ad522 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -44,7 +44,8 @@
Gregorian date. -->
<bool name="shamsi_date">false</bool>
<!-- Optional VPN app the network pill opens (hold the pill for Wi-Fi settings), e.g. the package of the
- VPN you use. Empty: the pill opens Wi-Fi settings. The VPN badge shows for any VPN either way. -->
+ VPN you use. Empty: the pill opens Wi-Fi settings. The green VPN badge shows for any VPN either way;
+ with an app set here, a red "VPN off" badge also shows while no VPN is up. -->
<string name="vpn_app" translatable="false"></string>
<!-- Grid rows left visible under the dock on the home screen. 0 = dock sits at the very bottom. -->
<integer name="rows_below_dock">0</integer>
diff --git a/launcher/app/src/main/res/values/strings.xml b/launcher/app/src/main/res/values/strings.xml
index c2a91674a..f08bb1f53 100644
--- a/launcher/app/src/main/res/values/strings.xml
+++ b/launcher/app/src/main/res/values/strings.xml
@@ -21,6 +21,7 @@
<string name="date_format">EEEE d MMMM</string>
<string name="dream_name">Clock</string>
<string name="vpn">VPN</string>
+ <string name="vpn_off">VPN off</string>
<string name="home_settings">Default home</string>
<string name="home_settings_help">Choose a home screen in system settings, then press Home.</string>
<string name="input_key_service_description">Opens the input switcher when the remote\'s Input button is pressed.</string>
diff --git a/themes/README.md b/themes/README.md
index ecc77a771..19f25365a 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -31,7 +31,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can
| `columns` | 1 to 8 | Tiles per row; tiles shrink to fit from 5 up |
| `rows_below_dock` | 0 to 3 | Grid rows left visible under the dock |
| `shamsi_date` | bool | Show the Solar Hijri date above the Gregorian one |
-| `vpn_app` | string | App the network pill opens when a VPN is configured |
+| `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 |
| `show_home_settings_shortcut` | bool | The "Default home" tile, where the TV has a home picker |
| `background_color` | `#RRGGBB` | Colour behind everything; black by default |
| `wallpaper` | bool | Show `wallpaper.jpg` from the theme folder (`true`), or ignore it (`false`) |