Skip to content

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

Add-on: Remote Access

מקס חיים1bcf92cb5a17
diff --git a/addons/README.md b/addons/README.md
index c3f00031d..7934fe782 100644
--- a/addons/README.md
+++ b/addons/README.md
@@ -20,6 +20,7 @@ the core bigger or change how it behaves. You install an add-on only if you want
| [TV Static](tv-static/) | An off-the-air moment each time the screen turns on: the picture opens from a bright line, snow and hiss, colour bars or an old "no signal" screen for 3 to 10 s, then fades into what was on screen; the card sets style, sound and length | [@luyzfernando08](https://github.com/luyzfernando08) | Xiaomi Mi Box S (Android TV 9), Philco by Skyworth (Android TV 14) | foreground service (screen-on watcher), start at boot, display over other apps | <img src="tv-static/screenshot.jpg" width="240" alt="TV Static on a TV"> |
| [Brightness](brightness/) | Dims the picture below the TV's own minimum over every app (and the picture settings on Realtek TVs), with a warm night mode on a schedule and a one-press normal screen | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | overlay, foreground service, start at boot | <img src="brightness/screenshot.jpg" width="240" alt="Brightness on a TV"> |
| [Sleep Timer](sleep-timer/) | A sleep timer: 15 to 120 minutes, a one-minute countdown over what is playing with "15 more minutes", then standby; over HDMI-CEC the TV turns off with the box | [@luyzfernando08](https://github.com/luyzfernando08) | Xiaomi Mi Box S (Android TV 9) | accessibility (lock-screen action only), display over other apps, exact alarms | <img src="sleep-timer/screenshot.jpg" width="240" alt="Sleep Timer on a TV"> |
+| [Remote Access](remote-access/) | Whether the TV is open to remote control: network debugging (ADB) and its port, the TV's address, Tailscale, and a button that switches network debugging off | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | network state; `WRITE_SECURE_SETTINGS` granted by ADB, only for the off button | <img src="remote-access/screenshot.jpg" width="240" alt="Remote Access on a TV"> |
A widget, an info tile, a storage or smart-home card: if it can live as its own small app, it can live
here. See the rules below.
diff --git a/addons/remote-access/.gitignore b/addons/remote-access/.gitignore
new file mode 100644
index 000000000..a7e04a21b
--- /dev/null
+++ b/addons/remote-access/.gitignore
@@ -0,0 +1,4 @@
+.gradle/
+build/
+app/build/
+local.properties
diff --git a/addons/remote-access/README.md b/addons/remote-access/README.md
new file mode 100644
index 000000000..e305b89e4
--- /dev/null
+++ b/addons/remote-access/README.md
@@ -0,0 +1,56 @@
+# Remote Access
+
+Is this TV open to remote control right now? One screen says whether network debugging (ADB) is on and on which
+port, the TV's address on your home network, and whether [Tailscale](https://tailscale.com) is installed and
+connected with its address. One button switches network debugging off: debugging switched on to set a TV up
+and then forgotten is the usual way a TV stays open. For the [Clean Your TV](../../README.md) launcher it declares
+a [module card](../../docs/modules.md): once you answer **Show card** its tile reads "Remote Access" with a red
+glow. On any other Android TV home it is an ordinary app.
+
+![Remote Access on a TV](screenshot.jpg)
+
+| Row | What it does |
+|---|---|
+| **Network debugging (ADB)** | Off, USB only, On (port 5555) or Wireless debugging. Focused first. OK twice within five seconds switches it off, which also ends any ADB session in progress. |
+| **This TV's address** | Its IPv4 address on the home network. |
+| **Tailscale** | Not installed, Installed and not connected, or Connected with its 100.x address. OK opens Tailscale. |
+| **Developer options** | Opens them, where debugging is switched on again. |
+
+It never switches debugging on: that stays in the TV's own Developer options.
+
+## Permissions
+
+| Permission | Why |
+|---|---|
+| `ACCESS_NETWORK_STATE` | The TV's addresses, and whether a VPN such as Tailscale is up. |
+| `WRITE_SECURE_SETTINGS` | Only to switch network debugging off. Android lets only ADB grant it; `install.sh` does. Without it the button opens Developer options instead. |
+
+It reads `adb_enabled`, `adb_wifi_enabled` and the `service.adb.tcp.port` property, the same values the TV's
+settings show. Package visibility is limited to `com.tailscale.ipn`. No internet permission: nothing leaves the
+TV. No background service, accounts, telemetry, ads or libraries.
+
+## Build and install
+
+JDK 17 and Android SDK platform 34 with build-tools 34.0.0, as for the launcher. From the repo root, with ADB on:
+
+```bash
+TV_HOST=<tv ip> addons/remote-access/install.sh
+```
+
+It builds the add-on, installs it, grants the permission for the off button, and opens it. Switching debugging
+off from the app ends the ADB connection the script used; that is the point. To build only:
+`cd addons/remote-access && ./gradlew assembleRelease`; the JVM tests run with `./gradlew testReleaseUnitTest`.
+
+## Limits
+
+- **The port** comes from a system property that is hidden from apps on some firmware; the row then says On
+ without a port.
+- **Other remote apps** (a vendor's phone app, Chromecast, AirPlay) are not ADB and are not covered.
+
+## Tested on
+
+MOKA R8G (Android 14), over ADB, on a home app that implements the module-card spec: the card prompt and the card, ADB shown as on at port 5555, the TV's address, Tailscale shown as not installed, and the permission for the off button granted by `install.sh`'s command. The off button itself was not pressed on the test TV, since it would end the ADB session the testing used. The JVM tests cover the states, the port property and the Tailscale address range.
+
+## Maintainer
+
+[@maxhayim](https://github.com/maxhayim)
diff --git a/addons/remote-access/app/build.gradle b/addons/remote-access/app/build.gradle
new file mode 100644
index 000000000..49d2d0ba2
--- /dev/null
+++ b/addons/remote-access/app/build.gradle
@@ -0,0 +1,36 @@
+plugins {
+ id 'com.android.application'
+}
+
+android {
+ namespace 'io.github.maxhayim.remoteaccess'
+ compileSdk 34
+
+ defaultConfig {
+ applicationId 'io.github.maxhayim.remoteaccess'
+ minSdk 26
+ targetSdk 34
+ versionCode 1
+ versionName '0.1'
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled true
+ shrinkResources true
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ // Sideloaded over ADB, never published: signed with the debug key, like the launcher.
+ signingConfig signingConfigs.debug
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
+ }
+}
+
+dependencies {
+ // No libraries in the APK. Test only: plain JVM tests in src/test.
+ testImplementation 'junit:junit:4.13.2'
+}
diff --git a/addons/remote-access/app/proguard-rules.pro b/addons/remote-access/app/proguard-rules.pro
new file mode 100644
index 000000000..a4435d69a
--- /dev/null
+++ b/addons/remote-access/app/proguard-rules.pro
@@ -0,0 +1,2 @@
+# Keep class and method names: readable stack traces matter more than the last few KB in a sideloaded app.
+-dontobfuscate
diff --git a/addons/remote-access/app/src/main/AndroidManifest.xml b/addons/remote-access/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..966a078c3
--- /dev/null
+++ b/addons/remote-access/app/src/main/AndroidManifest.xml
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools">
+
+ <uses-feature android:name="android.software.leanback" android:required="false" />
+ <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
+
+ <!-- The TV's addresses, and whether a VPN such as Tailscale is up. -->
+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
+ <!-- Switching network debugging off. Only ADB can grant it (install.sh does); without it the button explains. -->
+ <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"
+ tools:ignore="ProtectedPermissions" />
+
+ <!-- Whether the Tailscale app is installed. -->
+ <queries>
+ <package android:name="com.tailscale.ipn" />
+ </queries>
+
+ <application
+ android:allowBackup="false"
+ android:banner="@drawable/banner"
+ android:icon="@mipmap/ic_launcher"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.DeviceDefault.NoActionBar">
+
+ <activity
+ android:name=".MainActivity"
+ android:exported="true"
+ android:launchMode="singleTask">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.gathin.tvhome.category.DOCK_CARD" />
+ </intent-filter>
+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/module_card" />
+ </activity>
+ </application>
+</manifest>
diff --git a/addons/remote-access/app/src/main/java/io/github/maxhayim/remoteaccess/Access.java b/addons/remote-access/app/src/main/java/io/github/maxhayim/remoteaccess/Access.java
new file mode 100644
index 000000000..7584760cc
--- /dev/null
+++ b/addons/remote-access/app/src/main/java/io/github/maxhayim/remoteaccess/Access.java
@@ -0,0 +1,58 @@
+package io.github.maxhayim.remoteaccess;
+
+/** The wording and the address checks, with no Android types, so the JVM tests cover them. */
+final class Access {
+ enum Adb { OFF, USB_ONLY, NETWORK }
+
+ private Access() {
+ }
+
+ /**
+ * What ADB can be reached by. adb_enabled is the developer-options switch; a TCP port (adb tcpip) or wireless
+ * debugging makes it reachable over the network, which is what matters on a TV with no USB cable in.
+ */
+ static Adb adb(boolean enabled, boolean wireless, int tcpPort) {
+ if (!enabled) return Adb.OFF;
+ return wireless || tcpPort > 0 ? Adb.NETWORK : Adb.USB_ONLY;
+ }
+
+ static String adbValue(Adb a, boolean wireless, int tcpPort) {
+ switch (a) {
+ case NETWORK:
+ return tcpPort > 0 ? "On, port " + tcpPort : wireless ? "Wireless debugging" : "On";
+ case USB_ONLY:
+ return "USB only";
+ default:
+ return "Off";
+ }
+ }
+
+ /** -1 for an unset, empty or odd service.adb.tcp.port value. */
+ static int port(String prop) {
+ if (prop == null) return -1;
+ try {
+ int p = Integer.parseInt(prop.trim());
+ return p > 0 && p < 65536 ? p : -1;
+ } catch (NumberFormatException e) {
+ return -1;
+ }
+ }
+
+ /** Tailscale gives each device an address in 100.64.0.0/10 (the carrier-grade NAT range). */
+ static boolean tailscaleAddress(String ip) {
+ if (ip == null) return false;
+ String[] p = ip.split("\\.");
+ if (p.length != 4) return false;
+ try {
+ int a = Integer.parseInt(p[0]), b = Integer.parseInt(p[1]);
+ return a == 100 && b >= 64 && b <= 127;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ static String tailscale(boolean installed, String address) {
+ if (!installed) return "Not installed";
+ return address != null ? "Connected, " + address : "Installed, not connected";
+ }
+}
diff --git a/addons/remote-access/app/src/main/java/io/github/maxhayim/remoteaccess/MainActivity.java b/addons/remote-access/app/src/main/java/io/github/maxhayim/remoteaccess/MainActivity.java
new file mode 100644
index 000000000..b4956453a
--- /dev/null
+++ b/addons/remote-access/app/src/main/java/io/github/maxhayim/remoteaccess/MainActivity.java
@@ -0,0 +1,205 @@
+package io.github.maxhayim.remoteaccess;
+
+import android.Manifest;
+import android.app.Activity;
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.ConnectivityManager;
+import android.net.LinkAddress;
+import android.net.LinkProperties;
+import android.net.Network;
+import android.net.NetworkCapabilities;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import java.net.Inet4Address;
+
+/**
+ * The tile and module card open this: whether the TV can be controlled over the network, from where, and one
+ * press to close it. It reads what Android already shows in Settings and changes one setting, network
+ * debugging, and only to switch it off.
+ */
+public class MainActivity extends Activity {
+ private static final long CONFIRM_MS = 5000;
+ private static final String TAILSCALE = "com.tailscale.ipn";
+
+ private final Handler main = new Handler(Looper.getMainLooper());
+ private TextView status;
+ private Row adbRow, addressRow, tailscaleRow;
+ /** OK pressed once on the debugging row: a second press within CONFIRM_MS switches it off. */
+ private boolean armed;
+ private final Runnable disarm = () -> {
+ armed = false;
+ refresh();
+ };
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ LinearLayout page = new LinearLayout(this);
+ page.setOrientation(LinearLayout.VERTICAL);
+ page.setBackgroundColor(0xFF0D1117);
+ page.setPadding(px(48), px(32), px(48), px(24));
+ TextView title = new TextView(this);
+ title.setText(R.string.app_name);
+ title.setTextSize(28);
+ title.setTextColor(0xFFFFFFFF);
+ status = new TextView(this);
+ status.setTextSize(15);
+ status.setTextColor(0xFF8B949E);
+ status.setPadding(0, 0, 0, px(16));
+ page.addView(title);
+ page.addView(status);
+ ScrollView scroll = new ScrollView(this);
+ LinearLayout rows = new LinearLayout(this);
+ rows.setOrientation(LinearLayout.VERTICAL);
+ scroll.addView(rows);
+ page.addView(scroll, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f));
+ setContentView(page);
+
+ adbRow = add(rows, new Row(this, "Network debugging (ADB)", null, this::adbPressed));
+ addressRow = add(rows, new Row(this, "This TV's address", "On your home network.", null));
+ tailscaleRow = add(rows, new Row(this, "Tailscale", "Reach the TV from outside your home, privately.",
+ this::openTailscale));
+ add(rows, new Row(this, "Developer options", "Where network debugging is switched on again.",
+ () -> open(new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS))));
+ adbRow.requestFocus();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ refresh();
+ }
+
+ @Override
+ protected void onPause() {
+ main.removeCallbacks(disarm);
+ armed = false;
+ super.onPause();
+ }
+
+ private Row add(LinearLayout rows, Row r) {
+ rows.addView(r, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+ return r;
+ }
+
+ private void refresh() {
+ boolean enabled = global("adb_enabled") == 1;
+ boolean wireless = global("adb_wifi_enabled") == 1;
+ int port = Access.port(prop("service.adb.tcp.port"));
+ Access.Adb adb = Access.adb(enabled, wireless, port);
+ adbRow.setValue(armed ? "OK again: off" : Access.adbValue(adb, wireless, port));
+ if (adb == Access.Adb.OFF) {
+ adbRow.setDetail("Nobody can control this TV over the network.");
+ } else if (!canWrite()) {
+ adbRow.setDetail("Switch it off in Developer options (OK opens them). install.sh lets this button do it.");
+ } else {
+ adbRow.setDetail("Anyone allowed on your network can control this TV. OK twice switches it off.");
+ }
+
+ String[] found = addresses();
+ addressRow.setValue(found[0] != null ? found[0] : "No network");
+ boolean installed = installed(TAILSCALE);
+ tailscaleRow.setValue(Access.tailscale(installed, found[1]));
+
+ if (adb == Access.Adb.NETWORK) status.setText("Network debugging is on. Switch it off when you're done.");
+ else status.setText("Network debugging is off.");
+ }
+
+ private void adbPressed() {
+ boolean on = global("adb_enabled") == 1;
+ if (!on) return;
+ if (!canWrite()) {
+ open(new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
+ return;
+ }
+ if (!armed) {
+ armed = true;
+ main.postDelayed(disarm, CONFIRM_MS);
+ refresh();
+ return;
+ }
+ main.removeCallbacks(disarm);
+ armed = false;
+ try {
+ Settings.Global.putInt(getContentResolver(), "adb_wifi_enabled", 0);
+ Settings.Global.putInt(getContentResolver(), Settings.Global.ADB_ENABLED, 0);
+ } catch (SecurityException e) {
+ open(new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
+ }
+ refresh();
+ }
+
+ private boolean canWrite() {
+ return checkSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS) == PackageManager.PERMISSION_GRANTED;
+ }
+
+ private int global(String name) {
+ return Settings.Global.getInt(getContentResolver(), name, 0);
+ }
+
+ /** android.os.SystemProperties is hidden but readable; empty when this firmware refuses it. */
+ private static String prop(String name) {
+ try {
+ Object v = Class.forName("android.os.SystemProperties").getMethod("get", String.class).invoke(null, name);
+ return v == null ? "" : v.toString();
+ } catch (ReflectiveOperationException | RuntimeException e) {
+ return "";
+ }
+ }
+
+ /** [0] the home network's IPv4 address, [1] the Tailscale address; null where there is none. */
+ private String[] addresses() {
+ String[] out = new String[2];
+ ConnectivityManager cm = getSystemService(ConnectivityManager.class);
+ Network active = cm.getActiveNetwork();
+ for (Network n : cm.getAllNetworks()) {
+ NetworkCapabilities caps = cm.getNetworkCapabilities(n);
+ LinkProperties lp = cm.getLinkProperties(n);
+ if (caps == null || lp == null) continue;
+ boolean vpn = caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN);
+ for (LinkAddress la : lp.getLinkAddresses()) {
+ if (!(la.getAddress() instanceof Inet4Address)) continue;
+ String ip = la.getAddress().getHostAddress();
+ if (vpn && Access.tailscaleAddress(ip)) out[1] = ip;
+ else if (!vpn && (out[0] == null || n.equals(active))) out[0] = ip;
+ }
+ }
+ return out;
+ }
+
+ private boolean installed(String pkg) {
+ try {
+ getPackageManager().getPackageInfo(pkg, 0);
+ return true;
+ } catch (PackageManager.NameNotFoundException e) {
+ return false;
+ }
+ }
+
+ private void openTailscale() {
+ Intent i = getPackageManager().getLeanbackLaunchIntentForPackage(TAILSCALE);
+ if (i == null) i = getPackageManager().getLaunchIntentForPackage(TAILSCALE);
+ if (i != null) open(i);
+ }
+
+ private void open(Intent i) {
+ try {
+ startActivity(i);
+ } catch (ActivityNotFoundException | SecurityException ignored) {
+ // Some TVs have no screen for it.
+ }
+ }
+
+ private int px(int dp) {
+ return Math.round(dp * getResources().getDisplayMetrics().density);
+ }
+}
diff --git a/addons/remote-access/app/src/main/java/io/github/maxhayim/remoteaccess/Row.java b/addons/remote-access/app/src/main/java/io/github/maxhayim/remoteaccess/Row.java
new file mode 100644
index 000000000..c9a045f44
--- /dev/null
+++ b/addons/remote-access/app/src/main/java/io/github/maxhayim/remoteaccess/Row.java
@@ -0,0 +1,58 @@
+package io.github.maxhayim.remoteaccess;
+
+import android.content.Context;
+import android.view.Gravity;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+/**
+ * One settings row: a name with a line saying what it does on the left, its value on the right; OK runs it.
+ */
+final class Row extends LinearLayout {
+ private final TextView value;
+ private final TextView desc;
+
+ Row(Context context, String name, String description, Runnable onClick) {
+ super(context);
+ float dp = context.getResources().getDisplayMetrics().density;
+ setOrientation(HORIZONTAL);
+ setGravity(Gravity.CENTER_VERTICAL);
+ int ph = Math.round(16 * dp), pv = Math.round(10 * dp);
+ setPadding(ph, pv, ph, pv);
+ setBackgroundResource(R.drawable.row_background);
+ setFocusable(onClick != null);
+ setClickable(onClick != null);
+ if (onClick != null) setOnClickListener(v -> onClick.run());
+
+ LinearLayout text = new LinearLayout(context);
+ text.setOrientation(VERTICAL);
+ TextView label = new TextView(context);
+ label.setText(name);
+ label.setTextSize(17);
+ label.setTextColor(0xFFFFFFFF);
+ text.addView(label);
+ desc = new TextView(context);
+ desc.setTextSize(12);
+ desc.setTextColor(0xFF8B949E);
+ desc.setPadding(0, Math.round(2 * dp), Math.round(16 * dp), 0);
+ text.addView(desc);
+ setDetail(description);
+ addView(text, new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1f));
+
+ value = new TextView(context);
+ value.setTextSize(17);
+ value.setTextColor(0xFFC9D1D9);
+ value.setGravity(Gravity.END);
+ value.setMinWidth(Math.round(90 * dp));
+ addView(value, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+ }
+
+ void setDetail(String d) {
+ desc.setText(d == null ? "" : d);
+ desc.setVisibility(d == null || d.isEmpty() ? GONE : VISIBLE);
+ }
+
+ void setValue(String v) {
+ value.setText(v);
+ }
+}
diff --git a/addons/remote-access/app/src/main/res/drawable/banner.xml b/addons/remote-access/app/src/main/res/drawable/banner.xml
new file mode 100644
index 000000000..80ca4afee
--- /dev/null
+++ b/addons/remote-access/app/src/main/res/drawable/banner.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 16:9 banner: a screen with a terminal prompt and a padlock. Own art. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="320dp" android:height="180dp"
+ android:viewportWidth="320" android:viewportHeight="180">
+ <path android:fillColor="#101418" android:pathData="M0,0h320v180h-320z" />
+ <path android:fillColor="#1E2630" android:pathData="M24,24h272v132h-272z" />
+ <path android:strokeColor="#E5534B" android:strokeWidth="8" android:fillColor="#00000000" android:pathData="M70,70l26,20l-26,20" />
+ <path android:fillColor="#E5534B" android:pathData="M108,106h44v8h-44z" />
+ <path android:fillColor="#FFFFFF" android:pathData="M206,88h52v40h-52z" />
+ <path android:strokeColor="#FFFFFF" android:strokeWidth="6" android:fillColor="#00000000" android:pathData="M216,88v-10a16,16 0 0 1 32,0v10" />
+</vector>
diff --git a/addons/remote-access/app/src/main/res/drawable/ic_foreground.xml b/addons/remote-access/app/src/main/res/drawable/ic_foreground.xml
new file mode 100644
index 000000000..c9eca5ccb
--- /dev/null
+++ b/addons/remote-access/app/src/main/res/drawable/ic_foreground.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- A terminal prompt inside the adaptive icon's safe zone. Own art. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="108dp" android:height="108dp"
+ android:viewportWidth="108" android:viewportHeight="108">
+ <path android:strokeColor="#E5534B" android:strokeWidth="5" android:fillColor="#00000000" android:pathData="M38,44l12,10l-12,10" />
+ <path android:fillColor="#FFFFFF" android:pathData="M54,62h18v5h-18z" />
+</vector>
diff --git a/addons/remote-access/app/src/main/res/drawable/row_background.xml b/addons/remote-access/app/src/main/res/drawable/row_background.xml
new file mode 100644
index 000000000..03ccab9f5
--- /dev/null
+++ b/addons/remote-access/app/src/main/res/drawable/row_background.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- A settings row: transparent until focused, then a glass highlight like the launcher's. -->
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:state_focused="true">
+ <shape android:shape="rectangle">
+ <solid android:color="#33FFFFFF" />
+ <stroke android:width="1dp" android:color="#55FFFFFF" />
+ <corners android:radius="12dp" />
+ </shape>
+ </item>
+ <item>
+ <shape android:shape="rectangle">
+ <solid android:color="#00000000" />
+ <corners android:radius="12dp" />
+ </shape>
+ </item>
+</selector>
diff --git a/addons/remote-access/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/addons/remote-access/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
new file mode 100644
index 000000000..0a99b20b1
--- /dev/null
+++ b/addons/remote-access/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
+ <background android:drawable="@android:color/black" />
+ <foreground android:drawable="@drawable/ic_foreground" />
+</adaptive-icon>
diff --git a/addons/remote-access/app/src/main/res/values/strings.xml b/addons/remote-access/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..a9d957e1a
--- /dev/null
+++ b/addons/remote-access/app/src/main/res/values/strings.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">Remote Access</string>
+</resources>
diff --git a/addons/remote-access/app/src/main/res/xml/module_card.xml b/addons/remote-access/app/src/main/res/xml/module_card.xml
new file mode 100644
index 000000000..ee8efdae0
--- /dev/null
+++ b/addons/remote-access/app/src/main/res/xml/module_card.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<card spec="1" label="Remote Access" caption="ADB" accent="#E5534B" />
diff --git a/addons/remote-access/app/src/test/java/io/github/maxhayim/remoteaccess/AccessTest.java b/addons/remote-access/app/src/test/java/io/github/maxhayim/remoteaccess/AccessTest.java
new file mode 100644
index 000000000..f57237d57
--- /dev/null
+++ b/addons/remote-access/app/src/test/java/io/github/maxhayim/remoteaccess/AccessTest.java
@@ -0,0 +1,49 @@
+package io.github.maxhayim.remoteaccess;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class AccessTest {
+ @Test
+ public void adbStates() {
+ assertEquals(Access.Adb.OFF, Access.adb(false, true, 5555));
+ assertEquals(Access.Adb.USB_ONLY, Access.adb(true, false, -1));
+ assertEquals(Access.Adb.NETWORK, Access.adb(true, false, 5555));
+ assertEquals(Access.Adb.NETWORK, Access.adb(true, true, -1));
+ }
+
+ @Test
+ public void adbWording() {
+ assertEquals("On, port 5555", Access.adbValue(Access.Adb.NETWORK, false, 5555));
+ assertEquals("Wireless debugging", Access.adbValue(Access.Adb.NETWORK, true, -1));
+ assertEquals("Off", Access.adbValue(Access.Adb.OFF, false, -1));
+ }
+
+ @Test
+ public void ports() {
+ assertEquals(5555, Access.port("5555"));
+ assertEquals(-1, Access.port(""));
+ assertEquals(-1, Access.port("-1"));
+ assertEquals(-1, Access.port("70000"));
+ assertEquals(-1, Access.port(null));
+ }
+
+ @Test
+ public void tailscaleRange() {
+ assertTrue(Access.tailscaleAddress("100.64.0.1"));
+ assertTrue(Access.tailscaleAddress("100.101.102.103"));
+ assertFalse(Access.tailscaleAddress("100.128.0.1"));
+ assertFalse(Access.tailscaleAddress("10.0.0.37"));
+ assertFalse(Access.tailscaleAddress("fd7a::1"));
+ }
+
+ @Test
+ public void tailscaleWording() {
+ assertEquals("Not installed", Access.tailscale(false, null));
+ assertEquals("Installed, not connected", Access.tailscale(true, null));
+ assertEquals("Connected, 100.64.0.1", Access.tailscale(true, "100.64.0.1"));
+ }
+}
diff --git a/addons/remote-access/build.gradle b/addons/remote-access/build.gradle
new file mode 100644
index 000000000..48978475f
--- /dev/null
+++ b/addons/remote-access/build.gradle
@@ -0,0 +1,3 @@
+plugins {
+ id 'com.android.application' version '8.5.2' apply false
+}
diff --git a/addons/remote-access/gradle.properties b/addons/remote-access/gradle.properties
new file mode 100644
index 000000000..18825f968
--- /dev/null
+++ b/addons/remote-access/gradle.properties
@@ -0,0 +1,3 @@
+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
+android.useAndroidX=true
+android.nonTransitiveRClass=true
diff --git a/addons/remote-access/gradle/wrapper/gradle-wrapper.jar b/addons/remote-access/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 000000000..2c3521197
Binary files /dev/null and b/addons/remote-access/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/addons/remote-access/gradle/wrapper/gradle-wrapper.properties b/addons/remote-access/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 000000000..77f5d0ba6
--- /dev/null
+++ b/addons/remote-access/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,8 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
+distributionSha256Sum=d725d707bfabd4dfdc958c624003b3c80accc03f7037b5122c4b1d0ef15cecab
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/addons/remote-access/gradlew b/addons/remote-access/gradlew
new file mode 100755
index 000000000..f5feea6d6
--- /dev/null
+++ b/addons/remote-access/gradlew
@@ -0,0 +1,252 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
+' "$PWD" ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/addons/remote-access/gradlew.bat b/addons/remote-access/gradlew.bat
new file mode 100644
index 000000000..9d21a2183
--- /dev/null
+++ b/addons/remote-access/gradlew.bat
@@ -0,0 +1,94 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+@rem SPDX-License-Identifier: Apache-2.0
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo. 1>&2
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
+echo. 1>&2
+echo Please set the JAVA_HOME variable in your environment to match the 1>&2
+echo location of your Java installation. 1>&2
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/addons/remote-access/install.sh b/addons/remote-access/install.sh
new file mode 100755
index 000000000..988032b02
--- /dev/null
+++ b/addons/remote-access/install.sh
@@ -0,0 +1,27 @@
+#!/usr/bin/env bash
+# Build Remote Access, install it on the TV and let its button switch network debugging off.
+# TV_HOST=<tv ip> addons/remote-access/install.sh
+set -euo pipefail
+: "${TV_HOST:?set TV_HOST to the TV IP address}"
+cd "$(dirname "$0")"
+TOOLS="$(cd ../../tools && pwd)"
+PY=$TOOLS/venv/bin/python
+[ -x "$PY" ] || PY=$TOOLS/venv/Scripts/python.exe
+export MSYS_NO_PATHCONV=1
+PKG=io.github.maxhayim.remoteaccess
+# Script paths stay relative: with MSYS_NO_PATHCONV, Git Bash would hand Windows Python a /c/... path.
+tv() { "$PY" -I ../../tools/tv.py "$@"; }
+
+[ -f local.properties ] || { [ -n "${ANDROID_HOME:-}" ] && echo "sdk.dir=$ANDROID_HOME" > local.properties; } || true
+if [ -n "${JAVA_HOME:-}" ]; then export PATH="$JAVA_HOME/bin:$PATH"; fi
+./gradlew assembleRelease -q --console=plain
+
+"$PY" -I ../../tools/b64push.py app/build/outputs/apk/release/app-release.apk /data/local/tmp/remote-access.apk
+OUT=$(tv 'pm install -r /data/local/tmp/remote-access.apk; rm -f /data/local/tmp/remote-access.apk')
+echo "$OUT"
+case "$OUT" in *Success*) ;; *) echo "ERROR: pm install failed" >&2; exit 1 ;; esac
+
+# Only this lets the app switch network debugging off; it can read everything without it.
+tv "pm grant $PKG android.permission.WRITE_SECURE_SETTINGS; echo permission granted"
+tv "am start -n $PKG/.MainActivity >/dev/null; echo opened"
+echo "Installed. Remote Access is open on the TV; press Home and answer Show card for the card."
diff --git a/addons/remote-access/screenshot.jpg b/addons/remote-access/screenshot.jpg
new file mode 100644
index 000000000..d003dfdb2
Binary files /dev/null and b/addons/remote-access/screenshot.jpg differ
diff --git a/addons/remote-access/settings.gradle b/addons/remote-access/settings.gradle
new file mode 100644
index 000000000..2f1294305
--- /dev/null
+++ b/addons/remote-access/settings.gradle
@@ -0,0 +1,16 @@
+pluginManagement {
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+rootProject.name = "remote-access"
+include ':app'