Skip to content

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

addons: TV Inspector, remote key tester and TV capabilities

Shahrukh Shikalgar88c166f261b1
diff --git a/addons/README.md b/addons/README.md
index 0c29866d3..cb52dc7a7 100644
--- a/addons/README.md
+++ b/addons/README.md
@@ -9,7 +9,6 @@ the core bigger or change how it behaves. You install an add-on only if you want
| Add-on | What it does | Author | Tested on | Permissions | Screenshot |
|---|---|---|---|---|---|
-| [Jewish Calendar](jewish-calendar/) | Offline Hebrew and Gregorian dates, holiday/Shabbat greetings, and an optional clock screensaver | [lionlev21](https://github.com/lionlev21) | Android TV 12 (model private) | None | <img src="jewish-calendar/screenshot.jpg" width="240" alt="Jewish Calendar on a TV"> |
| [Frigate Glance](frigate-glance/) | Frigate camera pop-ups over whatever is playing | [NickLD](https://github.com/NickLD) | TCL 65Q650G | overlay, accessibility (card keys), network, foreground service | <img src="frigate-glance/screenshot.jpg" width="240" alt="Frigate Glance on a TV"> |
| [Capacity Stats](capacity-stats/) | Available/total and used/total RAM; available/total storage | [lionlev21](https://github.com/lionlev21) | Android TV 12 (model private) | None | <img src="capacity-stats/screenshot.jpg" width="240" alt="Capacity Stats on a TV"> |
| [Weather](weather/) | The weather for one city: now, US air quality and the next three days, from Open-Meteo (no key) | [@Sumyabazar1](https://github.com/Sumyabazar1) | Hisense SmartTV 4K FFM (lushan), Google TV 12 | `INTERNET` | <img src="weather/screenshot.jpg" width="240" alt="Weather on a TV"> |
@@ -23,17 +22,14 @@ the core bigger or change how it behaves. You install an add-on only if you want
| [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"> |
| [Quiet Hours](quiet-hours/) | A volume cap for the night (or all day): the volume is brought back down to the cap whenever it goes above, a muted TV is left alone, headphones can stay uncapped | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | foreground service, start at boot | <img src="quiet-hours/screenshot.jpg" width="240" alt="Quiet Hours 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"> |
-| [Bluetooth Connect](bluetooth-connect/) | Paired Bluetooth speakers and headphones with a Connect / Disconnect button, which the TV's own settings lack | [@thenewnano](https://github.com/thenewnano) | Philips UHD Android TV (Android 14) | Nearby devices (`BLUETOOTH_CONNECT`), granted by ADB | <img src="bluetooth-connect/screenshot.jpg" width="240" alt="Bluetooth Connect on a TV"> |
| [AirPlay Status](airplay-status/) | How iPhones and Macs see this TV: its AirPlay name, screen mirroring offered or audio only (and why), and the other AirPlay receivers on the network | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | network (mDNS listening only), network state | <img src="airplay-status/screenshot.jpg" width="240" alt="AirPlay Status on a TV"> |
| [Sources](sources/) | The TV's sources by the names devices give themselves over HDMI-CEC ("PlayStation 5", not "HDMI 2"), with their state, and Live TV; OK switches | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | None | <img src="sources/screenshot.jpg" width="240" alt="Sources on a TV"> |
| [Smart Home](smart-home/) | Home Assistant on the TV: scenes, lights and switches (OK toggles, left and right dim), climate, temperature and humidity, doors and windows, and locks shown but never opened | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | `INTERNET` (your Home Assistant only) | <img src="smart-home/screenshot.jpg" width="240" alt="Smart Home on a TV"> |
| [Ad Blocking](ad-blocking/) | Your Pi-hole (6 or 5) or AdGuard Home on the TV: today's queries and blocked share, and one OK to pause blocking for five minutes | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | `INTERNET` (your blocker only) | <img src="ad-blocking/screenshot.jpg" width="240" alt="Ad Blocking on a TV"> |
| [Startup & Branding](startup-branding/) | A welcome screen of your own: your picture, a background colour and a line of text, full screen for a few seconds or until Back or OK, with a live preview, Fit/Fill/Stretch/Original scaling and a compatibility check of what the TV allows without root | [@maxhayim](https://github.com/maxhayim) | MOKA M1G (Android TV 11) | None | <img src="startup-branding/screenshot.jpg" width="240" alt="Startup & Branding on a TV"> |
| [World Clock](world-clock/) | One to six offline clocks with dates, UTC offsets and day differences; city search and D-pad controls | [@SaviorOneZero](https://github.com/SaviorOneZero) | Samsung C71KW-200 / AT&T Osprey (Android TV 11) | None | <img src="world-clock/screenshot.jpg" width="240" alt="World Clock on a TV"> |
+| [TV Inspector](tv-inspector/) | What the remote sends (key name, key code, scan code, device) and what the TV can play: display modes, HDR, video decoders, audio outputs and formats, input devices; every line also in logcat for a `tv.json` or a bug report | [@shaharukhs](https://github.com/shaharukhs) | Sansui TV (Skyworth eleonas, MediaTek MT9676), Android TV 14 | None | <img src="tv-inspector/screenshot.jpg" width="240" alt="TV Inspector on a TV"> |
| [Flock](flock/) | An interactive flocking simulation using separation, alignment and cohesion, controlled with the TV remote | CleanYourTV contributors | TCL 32S5K (Android TV 14) | None | <img src="flock/screenshot.jpg" width="240" alt="Flock on TCL Android TV"> |
-| [News screensaver](news-screensaver/) | Headlines from your own RSS and Atom feeds as the TV's screensaver and as a card, one at a time with source, age, a QR code to the article and Left/Right paging; feeds (with names), seconds per headline and idle time are set with `setup.sh` or on the TV | [@modist](https://github.com/modist) | Philips 2021/22 UHD Android TV (Android 11) | `INTERNET` | <img src="news-screensaver/screenshot.jpg" width="240" alt="News screensaver on a TV"> |
-| [Digital Rain](digital-rain/) | A Matrix-style screensaver: mirrored katakana and digits falling in green trails with bright heads, drawn on the TV with no network; the card starts it at once | [@dennis-oleary](https://github.com/dennis-oleary) | NVIDIA SHIELD Android TV Pro 2019 (Android TV 11) | None | <img src="digital-rain/screenshot.jpg" width="240" alt="Digital Rain on a TV"> |
-| [Bluetooth Toggle](bluetooth-toggle/) | For Android 12 and older (13 and newer do not let apps switch Bluetooth). A one-press Bluetooth switch: the tile turns Bluetooth off or on, a small panel says which, and Pair accessory is one press away | [@justin-newman](https://github.com/justin-newman) | Hisense 75U75N (hengshan), Google TV 12 | Bluetooth (`BLUETOOTH_CONNECT`) | <img src="bluetooth-toggle/screenshot.jpg" width="240" alt="Bluetooth Toggle 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/tv-inspector/README.md b/addons/tv-inspector/README.md
new file mode 100644
index 000000000..ff6dcec95
--- /dev/null
+++ b/addons/tv-inspector/README.md
@@ -0,0 +1,53 @@
+# TV Inspector
+
+Optional standalone Android TV module card, maintained by [@shaharukhs](https://github.com/shaharukhs).
+It answers the two questions a TV list or a bug report keeps asking: what does this remote actually send,
+and what can this TV play?
+
+- **Remote keys.** Press any button and see its key name, key code, scan code and the input device it came
+ from, with the last eight keys listed. The D-pad is reported instead of moving the focus. Press Back twice
+ to leave; volume keys still change the volume. A key injected with `input keyevent` shows as a virtual
+ device, so an injected key can't be mistaken for the real remote. Home and Power never reach apps, and a
+ button that an accessibility helper (such as the launcher's own) takes first shows nothing here: that is
+ itself the answer.
+- **TV info.** Manufacturer and model, device, board and SoC, Android version, firmware build, security
+ patch and RAM; the current display mode, every supported resolution with its refresh rates, and the HDR
+ formats the screen reports; hardware or software decoders for AV1, VP9, HEVC, H.264, Dolby Vision and
+ MPEG-2 with the largest size each takes; the audio outputs (speakers, HDMI ARC/eARC, optical, Bluetooth)
+ with the formats they accept, and the Dolby and DTS decoders present; and the remotes and other input
+ devices connected. Move through the sections with the D-pad.
+
+Every line is also written to logcat under the tag `TvInspector`, so you can copy it to a `tv.json`, a
+`docs/devices/` note or an issue without typing it off the screen:
+
+```bash
+TV_HOST=<tv ip> tools/venv/bin/python -I tools/tv.py 'logcat -d -s TvInspector'
+```
+
+## Build and install
+
+JDK 17 and Android SDK 34, from this folder: `./gradlew testReleaseUnitTest lintRelease assembleRelease`.
+The small gradlew scripts reuse the repository's pinned Gradle wrapper with this folder as the project, so
+keep the folder inside the repository when building. Install it as `addons/README.md` describes, or with
+`tools/manage.py install tv-inspector`. No binaries or prebuilt APKs are committed.
+
+The launcher discovers the static module card and asks once whether to show it. Module spec 1 has static
+captions, so the card always reads "Remote keys and TV info"; OK opens the app.
+
+## Permissions
+
+None. No network, no telemetry, no ads, no background service and nothing runs after you leave the screen.
+It only reads what Android gives any app: `Build` fields, the display modes, `MediaCodecList`, the audio
+output devices and the input device list. It does not read the serial number, Android ID, MAC address,
+Wi-Fi or accounts. Audio outputs are listed by type, not by name, because a Bluetooth speaker's name is
+whatever its owner called it. Input device names are shown as the device reports them: blur one before
+posting a screenshot if it carries a person's name.
+
+## Validation
+
+Tested on a **Sansui TV (Skyworth eleonas, MediaTek MT9676) running Android TV 14**, firmware
+UKN5.251016.083: the key tester with the real BLE remote (D-pad and OK reported with their scan codes and
+device), the TV info screen (4K at 60 Hz, Dolby Vision, HDR10 and HLG, hardware AV1, Dolby Atmos over the
+speakers) and the logcat lines.
+
+7 JVM tests, lintRelease (0 errors) and the release build pass. The release APK is about 18 KB.
diff --git a/addons/tv-inspector/app/build.gradle b/addons/tv-inspector/app/build.gradle
new file mode 100644
index 000000000..999fdbf7b
--- /dev/null
+++ b/addons/tv-inspector/app/build.gradle
@@ -0,0 +1,18 @@
+plugins { id 'com.android.application' }
+android {
+ namespace 'io.github.shaharukhs.tvinspector'
+ compileSdk 34
+ buildFeatures { aidl false }
+ defaultConfig { applicationId 'io.github.shaharukhs.tvinspector'; minSdk 26; targetSdk 34; versionCode 1; versionName '1.0' }
+ buildTypes { release {
+ minifyEnabled true
+ shrinkResources true
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
+ signingConfig signingConfigs.debug
+ } }
+ compileOptions { sourceCompatibility JavaVersion.VERSION_17; targetCompatibility JavaVersion.VERSION_17 }
+}
+dependencies {
+
+ testImplementation 'junit:junit:4.13.2'
+}
diff --git a/addons/tv-inspector/app/proguard-rules.pro b/addons/tv-inspector/app/proguard-rules.pro
new file mode 100644
index 000000000..4cd4de6dc
--- /dev/null
+++ b/addons/tv-inspector/app/proguard-rules.pro
@@ -0,0 +1 @@
+# No rules needed: the app uses only the Android framework.
diff --git a/addons/tv-inspector/app/src/main/AndroidManifest.xml b/addons/tv-inspector/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..ed673d0a9
--- /dev/null
+++ b/addons/tv-inspector/app/src/main/AndroidManifest.xml
@@ -0,0 +1,16 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <uses-feature android:name="android.software.leanback" android:required="true" />
+ <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
+ <application android:allowBackup="false" android:supportsRtl="true" android:theme="@android:style/Theme.Material.NoActionBar.Fullscreen"
+ android:label="@string/app_name" android:icon="@drawable/icon" android:banner="@drawable/icon">
+ <activity android:name=".InspectorActivity" android:exported="true">
+ <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>
+ <activity android:name=".KeysActivity" android:exported="false" />
+ <activity android:name=".InfoActivity" android:exported="false" />
+
+ </application>
+</manifest>
diff --git a/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/InfoActivity.java b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/InfoActivity.java
new file mode 100644
index 000000000..20cd5f30f
--- /dev/null
+++ b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/InfoActivity.java
@@ -0,0 +1,164 @@
+package io.github.shaharukhs.tvinspector;
+
+import android.app.ActivityManager;
+import android.hardware.display.DisplayManager;
+import android.media.AudioDeviceInfo;
+import android.media.AudioManager;
+import android.media.MediaCodecInfo;
+import android.media.MediaCodecList;
+import android.os.Build;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.Display;
+import android.view.InputDevice;
+import android.widget.TextView;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+/** What the TV reports about itself, its screen, its decoders, its audio outputs and its input devices. */
+public final class InfoActivity extends Screen {
+ private static final String[][] VIDEO = {
+ {"video/av01", "AV1"}, {"video/x-vnd.on2.vp9", "VP9"}, {"video/hevc", "HEVC (H.265)"},
+ {"video/avc", "H.264"}, {"video/dolby-vision", "Dolby Vision"}, {"video/mpeg2", "MPEG-2"}};
+ private static final String[][] AUDIO = {
+ {"audio/ac3", "Dolby Digital"}, {"audio/eac3", "Dolby Digital Plus"}, {"audio/eac3-joc", "Dolby Atmos (DD+ JOC)"},
+ {"audio/ac4", "Dolby AC-4"}, {"audio/true-hd", "Dolby TrueHD"}, {"audio/vnd.dts", "DTS"},
+ {"audio/vnd.dts.hd", "DTS-HD"}};
+ private TextView loading;
+
+ @Override public void onCreate(Bundle state) {
+ super.onCreate(state);
+ layout();
+ text(getString(R.string.info), 30);
+ loading = text(getString(R.string.loading), 20);
+ // The codec list can take a second on a slow TV, so it is read off the main thread, once.
+ new Thread(() -> {
+ String[][] sections = {
+ {getString(R.string.section_tv), device()},
+ {getString(R.string.section_screen), screen()},
+ {getString(R.string.section_video), String.join("\n", decoders())},
+ {getString(R.string.section_audio), audio()},
+ {getString(R.string.section_inputs), inputs()}};
+ for (String[] s : sections) for (String line : s[1].split("\n")) Log.i("TvInspector", s[0] + ": " + line);
+ runOnUiThread(() -> {
+ if (isDestroyed()) return;
+ column.removeView(loading);
+ TextView first = null;
+ for (String[] s : sections) {
+ TextView view = section(s[0], s[1]);
+ if (first == null) first = view;
+ }
+ text(getString(R.string.logcat), 16);
+ button(getString(R.string.back), this::finish);
+ first.requestFocus();
+ });
+ }, "tv-inspector").start();
+ }
+
+ private String device() {
+ StringBuilder b = new StringBuilder();
+ b.append(Build.MANUFACTURER).append(' ').append(Build.MODEL)
+ .append("\nDevice ").append(Build.DEVICE).append(", board ").append(Build.BOARD)
+ .append(", hardware ").append(Build.HARDWARE);
+ if (Build.VERSION.SDK_INT >= 31) b.append("\nSoC ").append(Build.SOC_MANUFACTURER).append(' ').append(Build.SOC_MODEL);
+ b.append("\nAndroid ").append(Build.VERSION.RELEASE).append(" (API ").append(Build.VERSION.SDK_INT).append(')')
+ .append("\nFirmware ").append(Build.DISPLAY)
+ .append("\nSecurity patch ").append(Build.VERSION.SECURITY_PATCH);
+ ActivityManager am = getSystemService(ActivityManager.class);
+ ActivityManager.MemoryInfo memory = new ActivityManager.MemoryInfo();
+ am.getMemoryInfo(memory);
+ b.append("\nRAM ").append(memory.totalMem / (1024 * 1024)).append(" MB");
+ if (am.isLowRamDevice()) b.append(", low-RAM device");
+ return b.toString();
+ }
+
+ @SuppressWarnings("deprecation")
+ private String screen() {
+ Display display = getSystemService(DisplayManager.class).getDisplay(Display.DEFAULT_DISPLAY);
+ Display.Mode now = display.getMode();
+ StringBuilder b = new StringBuilder("Now ").append(now.getPhysicalWidth()).append(" × ").append(now.getPhysicalHeight())
+ .append(" at ").append(Labels.refresh(now.getRefreshRate())).append(" Hz");
+ Display.Mode[] modes = display.getSupportedModes();
+ int[] widths = new int[modes.length], heights = new int[modes.length];
+ float[] rates = new float[modes.length];
+ for (int i = 0; i < modes.length; i++) {
+ widths[i] = modes[i].getPhysicalWidth(); heights[i] = modes[i].getPhysicalHeight(); rates[i] = modes[i].getRefreshRate();
+ }
+ for (String line : Labels.modes(widths, heights, rates)) b.append('\n').append(line);
+ Display.HdrCapabilities hdr = display.getHdrCapabilities();
+ List<String> types = new ArrayList<>();
+ if (hdr != null) for (int type : hdr.getSupportedHdrTypes()) types.add(Labels.hdr(type));
+ b.append("\nHDR: ").append(types.isEmpty() ? "none reported" : String.join(", ", types));
+ return b.toString();
+ }
+
+ private List<String> decoders() {
+ Map<String, int[]> best = new LinkedHashMap<>(); // mime -> {hardware rank, software rank}
+ for (String[] v : VIDEO) best.put(v[0], new int[]{Labels.MISSING, Labels.MISSING});
+ for (MediaCodecInfo info : new MediaCodecList(MediaCodecList.REGULAR_CODECS).getCodecInfos()) {
+ if (info.isEncoder()) continue;
+ boolean hardware = Build.VERSION.SDK_INT >= 29 ? info.isHardwareAccelerated() : !Labels.softwareCodec(info.getName());
+ for (String type : info.getSupportedTypes()) {
+ int[] ranks = best.get(type.toLowerCase(Locale.ROOT));
+ if (ranks == null) continue;
+ int rank = Labels.SIZES.length;
+ try {
+ MediaCodecInfo.VideoCapabilities caps = info.getCapabilitiesForType(type).getVideoCapabilities();
+ for (int i = 0; i < Labels.SIZES.length && caps != null; i++) {
+ if (caps.isSizeSupported(Labels.SIZES[i][0], Labels.SIZES[i][1])) { rank = i; break; }
+ }
+ } catch (IllegalArgumentException ignored) { }
+ int slot = hardware ? 0 : 1;
+ ranks[slot] = Labels.better(ranks[slot], rank);
+ }
+ }
+ List<String> lines = new ArrayList<>();
+ for (String[] v : VIDEO) { int[] r = best.get(v[0]); lines.add(Labels.decoder(v[1], r[0], r[1])); }
+ return lines;
+ }
+
+ private String audio() {
+ StringBuilder b = new StringBuilder();
+ for (AudioDeviceInfo out : getSystemService(AudioManager.class).getDevices(AudioManager.GET_DEVICES_OUTPUTS)) {
+ Set<String> formats = new LinkedHashSet<>();
+ for (int encoding : out.getEncodings()) formats.add(Labels.encoding(encoding));
+ // Product names are left out: a Bluetooth output carries whatever its owner named it.
+ if (b.length() > 0) b.append('\n');
+ b.append(Labels.output(out.getType())).append(": ")
+ .append(formats.isEmpty() ? "formats not reported" : String.join(", ", formats));
+ }
+ Set<String> found = new LinkedHashSet<>();
+ Set<String> wanted = new LinkedHashSet<>();
+ for (String[] a : AUDIO) wanted.add(a[0]);
+ for (MediaCodecInfo info : new MediaCodecList(MediaCodecList.REGULAR_CODECS).getCodecInfos()) {
+ if (info.isEncoder()) continue;
+ for (String type : info.getSupportedTypes()) if (wanted.contains(type.toLowerCase(Locale.ROOT))) found.add(type.toLowerCase(Locale.ROOT));
+ }
+ List<String> names = new ArrayList<>();
+ for (String[] a : AUDIO) if (found.contains(a[0])) names.add(a[1]);
+ if (b.length() > 0) b.append('\n');
+ b.append("Decoders on the TV: ").append(names.isEmpty() ? "no Dolby or DTS decoder" : String.join(", ", names));
+ return b.toString();
+ }
+
+ private String inputs() {
+ List<String> lines = new ArrayList<>();
+ for (int id : InputDevice.getDeviceIds()) {
+ InputDevice d = InputDevice.getDevice(id);
+ if (d == null || d.isVirtual()) continue;
+ List<String> kinds = new ArrayList<>();
+ if (d.supportsSource(InputDevice.SOURCE_DPAD)) kinds.add("D-pad");
+ if (d.supportsSource(InputDevice.SOURCE_TOUCHSCREEN)) kinds.add("touch");
+ else if (d.supportsSource(InputDevice.SOURCE_KEYBOARD)) kinds.add("keys");
+ if (d.supportsSource(InputDevice.SOURCE_MOUSE)) kinds.add("pointer");
+ if (d.supportsSource(InputDevice.SOURCE_JOYSTICK)) kinds.add("gamepad");
+ lines.add(d.getName() + (kinds.isEmpty() ? "" : " (" + String.join(", ", kinds) + ")"));
+ }
+ return lines.isEmpty() ? "none" : String.join("\n", lines);
+ }
+}
diff --git a/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/InspectorActivity.java b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/InspectorActivity.java
new file mode 100644
index 000000000..936141347
--- /dev/null
+++ b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/InspectorActivity.java
@@ -0,0 +1,19 @@
+package io.github.shaharukhs.tvinspector;
+
+import android.content.Intent;
+import android.os.Bundle;
+import android.widget.Button;
+
+/** The card's screen: a choice between the key tester and the TV info sheet. */
+public final class InspectorActivity extends Screen {
+ @Override public void onCreate(Bundle state) {
+ super.onCreate(state);
+ layout();
+ text(getString(R.string.app_name), 30);
+ text(getString(R.string.intro), 20);
+ Button keys = button(getString(R.string.keys), () -> startActivity(new Intent(this, KeysActivity.class)));
+ button(getString(R.string.info), () -> startActivity(new Intent(this, InfoActivity.class)));
+ button(getString(R.string.back), this::finish);
+ keys.requestFocus();
+ }
+}
diff --git a/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/KeysActivity.java b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/KeysActivity.java
new file mode 100644
index 000000000..730f3b613
--- /dev/null
+++ b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/KeysActivity.java
@@ -0,0 +1,64 @@
+package io.github.shaharukhs.tvinspector;
+
+import android.os.Bundle;
+import android.os.SystemClock;
+import android.util.Log;
+import android.view.InputDevice;
+import android.view.KeyEvent;
+import android.widget.TextView;
+import java.util.ArrayDeque;
+import java.util.Deque;
+
+/** Shows every key the remote delivers to apps: its name, key code, scan code and the device it came from. */
+public final class KeysActivity extends Screen {
+ private static final int RECENT = 8;
+ private final Deque<String> recent = new ArrayDeque<>();
+ private TextView name, detail, hint, history;
+ private long lastBack;
+
+ @Override public void onCreate(Bundle state) {
+ super.onCreate(state);
+ layout();
+ hint = text(getString(R.string.keys_hint), 20);
+ name = text(getString(R.string.keys_waiting), 34);
+ detail = text("", 20);
+ text(getString(R.string.keys_recent), 22);
+ history = text("", 18);
+ text(getString(R.string.keys_missing), 16);
+ }
+
+ /** Takes every key before focus handling, so the D-pad is reported instead of moving anything. */
+ @Override public boolean dispatchKeyEvent(KeyEvent event) {
+ int code = event.getKeyCode();
+ if (code == KeyEvent.KEYCODE_BACK) {
+ if (event.getAction() != KeyEvent.ACTION_UP) return true;
+ long now = SystemClock.uptimeMillis();
+ if (now - lastBack < 2000) { finish(); return true; }
+ lastBack = now;
+ show(event);
+ hint.setText(getString(R.string.keys_back_again));
+ return true;
+ }
+ if (event.getAction() == KeyEvent.ACTION_DOWN) show(event);
+ boolean volume = code == KeyEvent.KEYCODE_VOLUME_UP || code == KeyEvent.KEYCODE_VOLUME_DOWN
+ || code == KeyEvent.KEYCODE_VOLUME_MUTE;
+ return volume ? super.dispatchKeyEvent(event) : true;
+ }
+
+ private void show(KeyEvent event) {
+ String key = KeyEvent.keyCodeToString(event.getKeyCode());
+ if (event.getRepeatCount() > 0) {
+ name.setText(key + ", " + getString(R.string.keys_held, event.getRepeatCount()));
+ return;
+ }
+ InputDevice device = event.getDevice();
+ String line = Labels.key(key, event.getKeyCode(), event.getScanCode(),
+ device == null || device.isVirtual() ? null : device.getName());
+ name.setText(key);
+ detail.setText(line);
+ recent.addFirst(line);
+ while (recent.size() > RECENT) recent.removeLast();
+ history.setText(String.join("\n", recent));
+ Log.i("TvInspector", "key " + line);
+ }
+}
diff --git a/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/Labels.java b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/Labels.java
new file mode 100644
index 000000000..2954cc1ea
--- /dev/null
+++ b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/Labels.java
@@ -0,0 +1,127 @@
+package io.github.shaharukhs.tvinspector;
+
+import android.media.AudioDeviceInfo;
+import android.media.AudioFormat;
+import android.view.Display;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+/** Names for the numbers Android hands back. Only constants, no Android calls, so the JVM tests can run it. */
+final class Labels {
+ private Labels() { }
+
+ /** Standard picture sizes, largest first; a decoder's rank is the index of the largest one it accepts. */
+ static final int[][] SIZES = {{7680, 4320}, {3840, 2160}, {1920, 1080}, {1280, 720}};
+ private static final String[] SIZE_NAMES = {"8K", "4K", "1080p", "720p"};
+ /** No decoder of that kind; any rank 0..SIZES.length is a decoder (SIZES.length: below 720p). */
+ static final int MISSING = -1;
+
+ static int better(int a, int b) { return a < 0 ? b : b < 0 ? a : Math.min(a, b); }
+
+ static String decoder(String label, int hardware, int software) {
+ if (hardware >= 0) return label + ": hardware, " + size(hardware);
+ if (software >= 0) return label + ": software only, " + size(software);
+ return label + ": no decoder";
+ }
+
+ private static String size(int rank) { return rank < SIZE_NAMES.length ? "up to " + SIZE_NAMES[rank] : "below 720p"; }
+
+ /** Codec names Android ships as software decoders, for TVs older than API 29's isHardwareAccelerated. */
+ static boolean softwareCodec(String name) {
+ String lower = name.toLowerCase(Locale.ROOT);
+ return lower.startsWith("omx.google.") || lower.startsWith("c2.android.");
+ }
+
+ static String refresh(float hz) {
+ String text = String.format(Locale.US, "%.2f", hz).replaceAll("0+$", "");
+ return text.endsWith(".") ? text.substring(0, text.length() - 1) : text;
+ }
+
+ /** One line per resolution, largest first, with its refresh rates fastest first: "3840 × 2160: 60, 50 Hz". */
+ static List<String> modes(int[] widths, int[] heights, float[] rates) {
+ Integer[] order = new Integer[widths.length];
+ for (int i = 0; i < order.length; i++) order[i] = i;
+ Arrays.sort(order, (a, b) -> {
+ long area = (long) widths[b] * heights[b] - (long) widths[a] * heights[a];
+ if (area != 0) return area > 0 ? 1 : -1;
+ if (widths[a] != widths[b]) return widths[b] - widths[a];
+ return Float.compare(rates[b], rates[a]);
+ });
+ Map<String, Set<String>> lines = new LinkedHashMap<>();
+ for (int i : order) {
+ lines.computeIfAbsent(widths[i] + " × " + heights[i], k -> new LinkedHashSet<>()).add(refresh(rates[i]));
+ }
+ List<String> result = new ArrayList<>();
+ for (Map.Entry<String, Set<String>> line : lines.entrySet()) {
+ result.add(line.getKey() + ": " + String.join(", ", line.getValue()) + " Hz");
+ }
+ return result;
+ }
+
+ static String hdr(int type) {
+ switch (type) {
+ case Display.HdrCapabilities.HDR_TYPE_DOLBY_VISION: return "Dolby Vision";
+ case Display.HdrCapabilities.HDR_TYPE_HDR10: return "HDR10";
+ case Display.HdrCapabilities.HDR_TYPE_HLG: return "HLG";
+ case Display.HdrCapabilities.HDR_TYPE_HDR10_PLUS: return "HDR10+";
+ default: return "HDR type " + type;
+ }
+ }
+
+ static String encoding(int encoding) {
+ switch (encoding) {
+ case AudioFormat.ENCODING_PCM_8BIT: return "PCM 8-bit";
+ case AudioFormat.ENCODING_PCM_16BIT: return "PCM 16-bit";
+ case AudioFormat.ENCODING_PCM_24BIT_PACKED: return "PCM 24-bit";
+ case AudioFormat.ENCODING_PCM_32BIT: return "PCM 32-bit";
+ case AudioFormat.ENCODING_PCM_FLOAT: return "PCM float";
+ case AudioFormat.ENCODING_AC3: return "Dolby Digital";
+ case AudioFormat.ENCODING_E_AC3: return "Dolby Digital Plus";
+ case AudioFormat.ENCODING_E_AC3_JOC: return "Dolby Atmos (DD+ JOC)";
+ case AudioFormat.ENCODING_DOLBY_TRUEHD: return "Dolby TrueHD";
+ case AudioFormat.ENCODING_DOLBY_MAT: return "Dolby MAT";
+ case AudioFormat.ENCODING_AC4: return "Dolby AC-4";
+ case AudioFormat.ENCODING_DTS: return "DTS";
+ case AudioFormat.ENCODING_DTS_HD: return "DTS-HD";
+ case AudioFormat.ENCODING_DTS_HD_MA: return "DTS-HD MA";
+ case AudioFormat.ENCODING_DTS_UHD_P1: return "DTS:X";
+ case AudioFormat.ENCODING_IEC61937: return "IEC 61937 passthrough";
+ case AudioFormat.ENCODING_MP3: return "MP3";
+ case AudioFormat.ENCODING_AAC_LC: return "AAC";
+ case AudioFormat.ENCODING_OPUS: return "Opus";
+ default: return "encoding " + encoding;
+ }
+ }
+
+ static String output(int type) {
+ switch (type) {
+ case AudioDeviceInfo.TYPE_BUILTIN_SPEAKER: return "TV speakers";
+ case AudioDeviceInfo.TYPE_HDMI: return "HDMI";
+ case AudioDeviceInfo.TYPE_HDMI_ARC: return "HDMI ARC";
+ case AudioDeviceInfo.TYPE_HDMI_EARC: return "HDMI eARC";
+ case AudioDeviceInfo.TYPE_LINE_DIGITAL: return "Optical (S/PDIF)";
+ case AudioDeviceInfo.TYPE_LINE_ANALOG: return "Analogue line out";
+ case AudioDeviceInfo.TYPE_AUX_LINE: return "Aux line out";
+ case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
+ case AudioDeviceInfo.TYPE_WIRED_HEADSET: return "Headphone jack";
+ case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP: return "Bluetooth";
+ case AudioDeviceInfo.TYPE_BLE_HEADSET:
+ case AudioDeviceInfo.TYPE_BLE_SPEAKER: return "Bluetooth LE";
+ case AudioDeviceInfo.TYPE_USB_DEVICE:
+ case AudioDeviceInfo.TYPE_USB_HEADSET: return "USB audio";
+ default: return "output type " + type;
+ }
+ }
+
+ /** "KEYCODE_G (35), scan code 34, from Remote": a null device is one the event names no real hardware for. */
+ static String key(String name, int code, int scan, String device) {
+ return name + " (" + code + "), scan code " + scan + ", "
+ + (device == null ? "virtual device: injected or sent by the system" : "from " + device);
+ }
+}
diff --git a/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/Screen.java b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/Screen.java
new file mode 100644
index 000000000..0a0ae19c3
--- /dev/null
+++ b/addons/tv-inspector/app/src/main/java/io/github/shaharukhs/tvinspector/Screen.java
@@ -0,0 +1,59 @@
+package io.github.shaharukhs.tvinspector;
+
+import android.app.Activity;
+import android.graphics.Color;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.StateListDrawable;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.Button;
+import android.widget.LinearLayout;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+/** The plain dark column every screen of the add-on is built from. */
+abstract class Screen extends Activity {
+ static final int BACKGROUND = Color.rgb(21, 32, 43);
+ LinearLayout column;
+
+ void layout() {
+ ScrollView scroll = new ScrollView(this);
+ column = new LinearLayout(this);
+ column.setOrientation(LinearLayout.VERTICAL);
+ column.setPadding(48, 32, 48, 32);
+ column.setLayoutDirection(View.LAYOUT_DIRECTION_LOCALE);
+ scroll.setBackgroundColor(BACKGROUND);
+ scroll.addView(column);
+ setContentView(scroll);
+ }
+
+ TextView text(String value, int size) {
+ TextView view = new TextView(this);
+ view.setText(value); view.setTextSize(size); view.setTextColor(Color.WHITE);
+ view.setGravity(Gravity.START); view.setTextDirection(View.TEXT_DIRECTION_LOCALE);
+ view.setPadding(12, 14, 12, 14);
+ column.addView(view, new LinearLayout.LayoutParams(-1, -2));
+ return view;
+ }
+
+ /** A focusable block, so the D-pad walks the page and the scroll view follows the focus. */
+ TextView section(String title, String body) {
+ TextView view = text(title + "\n" + body, 18);
+ view.setFocusable(true);
+ StateListDrawable background = new StateListDrawable();
+ GradientDrawable focused = new GradientDrawable();
+ focused.setColor(Color.rgb(44, 62, 80)); focused.setCornerRadius(12);
+ background.addState(new int[]{android.R.attr.state_focused}, focused);
+ background.addState(new int[]{}, new ColorDrawable(Color.TRANSPARENT));
+ view.setBackground(background);
+ return view;
+ }
+
+ Button button(String value, Runnable action) {
+ Button view = new Button(this); view.setText(value);
+ view.setOnClickListener(v -> action.run());
+ column.addView(view, new LinearLayout.LayoutParams(-1, -2));
+ return view;
+ }
+}
diff --git a/addons/tv-inspector/app/src/main/res/drawable/icon.xml b/addons/tv-inspector/app/src/main/res/drawable/icon.xml
new file mode 100644
index 000000000..9ef8dcbcf
--- /dev/null
+++ b/addons/tv-inspector/app/src/main/res/drawable/icon.xml
@@ -0,0 +1,7 @@
+<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="#15202B" android:pathData="M0,0h320v180h-320z" />
+<path android:fillColor="#5FA8D3" android:pathData="M138,30h44a10,10 0 0,1 10,10v100a10,10 0 0,1 -10,10h-44a10,10 0 0,1 -10,-10v-100a10,10 0 0,1 10,-10z" />
+<path android:fillColor="#15202B" android:pathData="M142,68a18,18 0 1,0 36,0a18,18 0 1,0 -36,0z M146,108h10v10h-10z M164,108h10v10h-10z M146,126h10v10h-10z M164,126h10v10h-10z" />
+<path android:fillColor="#5FA8D3" android:pathData="M152,68a8,8 0 1,0 16,0a8,8 0 1,0 -16,0z" />
+<path android:fillColor="#F2C14E" android:pathData="M155,38h10v10h-10z" />
+</vector>
diff --git a/addons/tv-inspector/app/src/main/res/values/strings.xml b/addons/tv-inspector/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..223db5032
--- /dev/null
+++ b/addons/tv-inspector/app/src/main/res/values/strings.xml
@@ -0,0 +1,20 @@
+<resources>
+ <string name="app_name">TV Inspector</string>
+ <string name="intro">What this TV\'s remote sends, and what the TV can play. Handy when you write a tv.json, map a button or file a bug.</string>
+ <string name="keys">Remote keys</string>
+ <string name="info">TV info</string>
+ <string name="back">Back</string>
+ <string name="keys_hint">Press any button on the remote. Press Back twice to leave.</string>
+ <string name="keys_waiting">Waiting for a key…</string>
+ <string name="keys_held">held, repeat %1$d</string>
+ <string name="keys_back_again">Press Back again to leave.</string>
+ <string name="keys_missing">Home and Power never reach apps. A button that shows nothing here is taken by the system or by an accessibility helper first. Volume keys still change the volume.</string>
+ <string name="keys_recent">Recent keys</string>
+ <string name="loading">Reading the TV…</string>
+ <string name="section_tv">This TV</string>
+ <string name="section_screen">Screen</string>
+ <string name="section_video">Video decoders</string>
+ <string name="section_audio">Audio</string>
+ <string name="section_inputs">Remotes and input devices</string>
+ <string name="logcat">The same lines are in logcat: tools/tv.py \'logcat -d -s TvInspector\'</string>
+</resources>
diff --git a/addons/tv-inspector/app/src/main/res/xml/module_card.xml b/addons/tv-inspector/app/src/main/res/xml/module_card.xml
new file mode 100644
index 000000000..b20d4d21e
--- /dev/null
+++ b/addons/tv-inspector/app/src/main/res/xml/module_card.xml
@@ -0,0 +1 @@
+<card spec="1" label="TV Inspector" caption="Remote keys and TV info" accent="#5FA8D3" />
diff --git a/addons/tv-inspector/app/src/test/java/io/github/shaharukhs/tvinspector/LabelsTest.java b/addons/tv-inspector/app/src/test/java/io/github/shaharukhs/tvinspector/LabelsTest.java
new file mode 100644
index 000000000..83d680a51
--- /dev/null
+++ b/addons/tv-inspector/app/src/test/java/io/github/shaharukhs/tvinspector/LabelsTest.java
@@ -0,0 +1,54 @@
+package io.github.shaharukhs.tvinspector;
+
+import android.media.AudioDeviceInfo;
+import android.media.AudioFormat;
+import android.view.Display;
+import java.util.Arrays;
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class LabelsTest {
+ @Test public void refreshRatesDropTrailingZeros() {
+ assertEquals("60", Labels.refresh(60f));
+ assertEquals("59.94", Labels.refresh(59.94f));
+ assertEquals("23.98", Labels.refresh(23.976f));
+ assertEquals("100", Labels.refresh(100f));
+ }
+ @Test public void modesGroupByResolutionLargestAndFastestFirst() {
+ int[] w = {1920, 3840, 3840, 1920, 3840};
+ int[] h = {1080, 2160, 2160, 1080, 2160};
+ float[] hz = {60f, 24f, 60f, 50f, 60.0001f};
+ assertEquals(Arrays.asList("3840 × 2160: 60, 24 Hz", "1920 × 1080: 60, 50 Hz"), Labels.modes(w, h, hz));
+ assertTrue(Labels.modes(new int[0], new int[0], new float[0]).isEmpty());
+ }
+ @Test public void decoderLinesPreferHardware() {
+ assertEquals("HEVC: hardware, up to 4K", Labels.decoder("HEVC", 1, 0));
+ assertEquals("AV1: software only, up to 1080p", Labels.decoder("AV1", Labels.MISSING, 2));
+ assertEquals("VP9: hardware, below 720p", Labels.decoder("VP9", Labels.SIZES.length, Labels.MISSING));
+ assertEquals("MPEG-2: no decoder", Labels.decoder("MPEG-2", Labels.MISSING, Labels.MISSING));
+ }
+ @Test public void betterKeepsTheLargestSizeAndIgnoresMissing() {
+ assertEquals(1, Labels.better(Labels.MISSING, 1));
+ assertEquals(1, Labels.better(1, Labels.MISSING));
+ assertEquals(0, Labels.better(2, 0));
+ assertEquals(Labels.MISSING, Labels.better(Labels.MISSING, Labels.MISSING));
+ }
+ @Test public void androidSoftwareDecodersAreRecognised() {
+ assertTrue(Labels.softwareCodec("c2.android.hevc.decoder"));
+ assertTrue(Labels.softwareCodec("OMX.google.vp9.decoder"));
+ assertFalse(Labels.softwareCodec("OMX.amlogic.hevc.decoder.awesome2"));
+ }
+ @Test public void constantsGetNames() {
+ assertEquals("HDR10+", Labels.hdr(Display.HdrCapabilities.HDR_TYPE_HDR10_PLUS));
+ assertEquals("HDR type 99", Labels.hdr(99));
+ assertEquals("Dolby Atmos (DD+ JOC)", Labels.encoding(AudioFormat.ENCODING_E_AC3_JOC));
+ assertEquals("encoding 999", Labels.encoding(999));
+ assertEquals("HDMI ARC", Labels.output(AudioDeviceInfo.TYPE_HDMI_ARC));
+ assertEquals("Headphone jack", Labels.output(AudioDeviceInfo.TYPE_WIRED_HEADSET));
+ }
+ @Test public void keyLinesNameTheDeviceOrSayItIsVirtual() {
+ assertEquals("KEYCODE_G (35), scan code 34, from Realtek Remote", Labels.key("KEYCODE_G", 35, 34, "Realtek Remote"));
+ assertEquals("KEYCODE_DPAD_UP (19), scan code 0, virtual device: injected or sent by the system",
+ Labels.key("KEYCODE_DPAD_UP", 19, 0, null));
+ }
+}
diff --git a/addons/tv-inspector/build.gradle b/addons/tv-inspector/build.gradle
new file mode 100644
index 000000000..48978475f
--- /dev/null
+++ b/addons/tv-inspector/build.gradle
@@ -0,0 +1,3 @@
+plugins {
+ id 'com.android.application' version '8.5.2' apply false
+}
diff --git a/addons/tv-inspector/gradle.properties b/addons/tv-inspector/gradle.properties
new file mode 100644
index 000000000..18825f968
--- /dev/null
+++ b/addons/tv-inspector/gradle.properties
@@ -0,0 +1,3 @@
+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
+android.useAndroidX=true
+android.nonTransitiveRClass=true
diff --git a/addons/tv-inspector/gradlew b/addons/tv-inspector/gradlew
new file mode 100644
index 000000000..fbcfb4bcb
--- /dev/null
+++ b/addons/tv-inspector/gradlew
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Reuse the repository's pinned Gradle distribution, but build this independent project.
+addon_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) || exit 1
+exec sh "$addon_dir/../../launcher/gradlew" -p "$addon_dir" "$@"
diff --git a/addons/tv-inspector/gradlew.bat b/addons/tv-inspector/gradlew.bat
new file mode 100644
index 000000000..b003250db
--- /dev/null
+++ b/addons/tv-inspector/gradlew.bat
@@ -0,0 +1,3 @@
+@echo off
+rem Reuse the repository wrapper; this add-on remains its own Gradle project.
+call "%~dp0..\..\launcher\gradlew.bat" -p "%~dp0." %*
diff --git a/addons/tv-inspector/screenshot.jpg b/addons/tv-inspector/screenshot.jpg
new file mode 100644
index 000000000..2f66268b8
Binary files /dev/null and b/addons/tv-inspector/screenshot.jpg differ
diff --git a/addons/tv-inspector/settings.gradle b/addons/tv-inspector/settings.gradle
new file mode 100644
index 000000000..7e9e82dec
--- /dev/null
+++ b/addons/tv-inspector/settings.gradle
@@ -0,0 +1,16 @@
+pluginManagement {
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+rootProject.name = "tv-inspector"
+include ':app'