Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
addons: Bluetooth Connect, connect or disconnect a paired speaker from a Home card (Philips UHD Android TV, Android 14)
Shwan Ciyako1ba1c4a04b88
diff --git a/addons/README.md b/addons/README.mdindex 2da690c29..18ffea426 100644--- a/addons/README.md+++ b/addons/README.md@@ -22,6 +22,7 @@ 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"> |diff --git a/addons/bluetooth-connect/.gitignore b/addons/bluetooth-connect/.gitignorenew file mode 100644index 000000000..a7e04a21b--- /dev/null+++ b/addons/bluetooth-connect/.gitignore@@ -0,0 +1,4 @@+.gradle/+build/+app/build/+local.propertiesdiff --git a/addons/bluetooth-connect/README.md b/addons/bluetooth-connect/README.mdnew file mode 100644index 000000000..e626bf09f--- /dev/null+++ b/addons/bluetooth-connect/README.md@@ -0,0 +1,33 @@+# Bluetooth Connect++The TV's Bluetooth settings offer Connect and Unpair for a speaker, but no Disconnect. This add-on lists the paired+speakers and headphones, each with its state, and OK on one connects it or, when it is connected, disconnects it.+Nothing is unpaired. For the [Clean Your TV](../../README.md) launcher it declares a+[module card](../../docs/modules.md): once you answer **Show card** its tile reads "Bluetooth" with a teal glow. On+any other Android TV home it is an ordinary app.++++| Row | What it does |+|---|---|+| **Each paired speaker or headphones** | Shows Connected or Not connected. OK connects or disconnects it; the row says Working... until Android reports the change. A speaker that is switched off stays Not connected. |++Android's public API has neither call, so the add-on uses the audio profile's own connect and disconnect, which a+normal app may call with the Nearby devices permission. It acts on classic Bluetooth audio (A2DP) only. On the+Philips it was made on, the speaker stayed disconnected until connected again; a speaker may reconnect by itself+when it is switched on, as it does without this app. [Headphones](../headphones/) lists the same devices with+battery and a quiet guard but cannot connect or disconnect them.++## Install++`TV_HOST=<tv ip> addons/bluetooth-connect/install.sh` builds it, installs it and grants the permission.++## Permissions++| Permission | Why |+|---|---|+| Nearby devices (`BLUETOOTH_CONNECT`, Android 12+) | To list paired devices and connect or disconnect them. Granted by `install.sh`; otherwise the app asks once. |+| Bluetooth (`BLUETOOTH`, Android 11 and older) | The same on older versions, granted at install. |++No scanning, no location, no internet permission: nothing leaves the TV. No background service, telemetry, ads,+accounts or libraries.diff --git a/addons/bluetooth-connect/app/build.gradle b/addons/bluetooth-connect/app/build.gradlenew file mode 100644index 000000000..19dd305d1--- /dev/null+++ b/addons/bluetooth-connect/app/build.gradle@@ -0,0 +1,36 @@+plugins {+ id 'com.android.application'+}++android {+ namespace 'com.gathin.btconnect'+ compileSdk 34++ defaultConfig {+ applicationId 'com.gathin.btconnect'+ 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/bluetooth-connect/app/proguard-rules.pro b/addons/bluetooth-connect/app/proguard-rules.pronew file mode 100644index 000000000..a4435d69a--- /dev/null+++ b/addons/bluetooth-connect/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.+-dontobfuscatediff --git a/addons/bluetooth-connect/app/src/main/AndroidManifest.xml b/addons/bluetooth-connect/app/src/main/AndroidManifest.xmlnew file mode 100644index 000000000..bb52faaf8--- /dev/null+++ b/addons/bluetooth-connect/app/src/main/AndroidManifest.xml@@ -0,0 +1,33 @@+<?xml version="1.0" encoding="utf-8"?>+<manifest xmlns:android="http://schemas.android.com/apk/res/android">++ <uses-feature android:name="android.software.leanback" android:required="false" />+ <uses-feature android:name="android.hardware.touchscreen" android:required="false" />++ <!-- Listing paired speakers and connecting or disconnecting them. install.sh grants it; otherwise the app asks once. -->+ <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />+ <uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />++ <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/bluetooth-connect/app/src/main/java/com/gathin/btconnect/Link.java b/addons/bluetooth-connect/app/src/main/java/com/gathin/btconnect/Link.javanew file mode 100644index 000000000..22fe8cde3--- /dev/null+++ b/addons/bluetooth-connect/app/src/main/java/com/gathin/btconnect/Link.java@@ -0,0 +1,30 @@+package com.gathin.btconnect;++import android.bluetooth.BluetoothA2dp;+import android.bluetooth.BluetoothClass;+import android.bluetooth.BluetoothDevice;++/**+ * Connecting and disconnecting a paired speaker. Android's public API has neither, so this calls the audio+ * profile's own connect and disconnect, which a plain app may use with the Nearby devices permission.+ */+final class Link {+ private Link() { }++ /** A speaker or headphones: anything the TV can send sound to. */+ static boolean isAudio(BluetoothClass c) {+ if (c == null) return true; // unknown class: show it rather than hide a speaker+ return c.getMajorDeviceClass() == BluetoothClass.Device.Major.AUDIO_VIDEO+ || c.hasService(BluetoothClass.Service.AUDIO);+ }++ /** True when Android accepted the request; the connection itself changes a moment later. */+ static boolean set(BluetoothA2dp a2dp, BluetoothDevice device, boolean connect) {+ try {+ return (Boolean) BluetoothA2dp.class.getMethod(connect ? "connect" : "disconnect", BluetoothDevice.class)+ .invoke(a2dp, device);+ } catch (ReflectiveOperationException | SecurityException refused) {+ return false;+ }+ }+}diff --git a/addons/bluetooth-connect/app/src/main/java/com/gathin/btconnect/MainActivity.java b/addons/bluetooth-connect/app/src/main/java/com/gathin/btconnect/MainActivity.javanew file mode 100644index 000000000..a0f899bb8--- /dev/null+++ b/addons/bluetooth-connect/app/src/main/java/com/gathin/btconnect/MainActivity.java@@ -0,0 +1,169 @@+package com.gathin.btconnect;++import android.Manifest;+import android.annotation.SuppressLint;+import android.app.Activity;+import android.bluetooth.BluetoothA2dp;+import android.bluetooth.BluetoothAdapter;+import android.bluetooth.BluetoothDevice;+import android.bluetooth.BluetoothManager;+import android.bluetooth.BluetoothProfile;+import android.content.BroadcastReceiver;+import android.content.Context;+import android.content.Intent;+import android.content.IntentFilter;+import android.content.pm.PackageManager;+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.util.HashSet;+import java.util.Set;++/**+ * The tile and module card open this: the paired speakers and headphones, each with its state, and OK on one+ * connects it or, when it is connected, disconnects it. The TV's own Bluetooth settings only offer Connect and Unpair.+ */+public class MainActivity extends Activity {+ private final Handler main = new Handler(Looper.getMainLooper());+ private LinearLayout list;+ private TextView status;+ private BluetoothAdapter adapter;+ private BluetoothA2dp a2dp;+ /** Addresses asked to change a moment ago, shown as "Working…" until the state change arrives. */+ private final Set<String> pending = new HashSet<>();+ private final BroadcastReceiver changed = new BroadcastReceiver() {+ @Override public void onReceive(Context context, Intent intent) {+ BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);+ if (device != null) pending.remove(device.getAddress());+ refresh();+ }+ };++ @Override+ protected void onCreate(Bundle savedInstanceState) {+ super.onCreate(savedInstanceState);+ float dp = getResources().getDisplayMetrics().density;+ LinearLayout page = new LinearLayout(this);+ page.setOrientation(LinearLayout.VERTICAL);+ page.setBackgroundColor(0xFF0D1117);+ page.setPadding(Math.round(48 * dp), Math.round(32 * dp), Math.round(48 * dp), Math.round(24 * dp));+ 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, Math.round(16 * dp));+ page.addView(title);+ page.addView(status);+ ScrollView scroll = new ScrollView(this);+ list = new LinearLayout(this);+ list.setOrientation(LinearLayout.VERTICAL);+ scroll.addView(list);+ page.addView(scroll, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f));+ setContentView(page);+ adapter = getSystemService(BluetoothManager.class).getAdapter();+ }++ @Override+ protected void onResume() {+ super.onResume();+ if (checkSelfPermission(Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {+ requestPermissions(new String[]{Manifest.permission.BLUETOOTH_CONNECT}, 1);+ return;+ }+ start();+ }++ @Override+ public void onRequestPermissionsResult(int code, String[] permissions, int[] results) {+ if (results.length > 0 && results[0] == PackageManager.PERMISSION_GRANTED) start();+ else status.setText("Needs the Nearby devices permission: run install.sh once, or allow it in the app's settings.");+ }++ private void start() {+ if (adapter == null || !adapter.isEnabled()) {+ status.setText("Bluetooth is off. Turn it on in the TV's settings.");+ return;+ }+ registerReceiver(changed, new IntentFilter(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED));+ if (a2dp != null) {+ refresh();+ return;+ }+ adapter.getProfileProxy(this, new BluetoothProfile.ServiceListener() {+ @Override public void onServiceConnected(int profile, BluetoothProfile proxy) {+ a2dp = (BluetoothA2dp) proxy;+ refresh();+ }+ @Override public void onServiceDisconnected(int profile) {+ a2dp = null;+ }+ }, BluetoothProfile.A2DP);+ }++ @Override+ protected void onPause() {+ try {+ unregisterReceiver(changed);+ } catch (IllegalArgumentException notRegistered) {+ }+ main.removeCallbacksAndMessages(null);+ super.onPause();+ }++ @Override+ protected void onDestroy() {+ if (a2dp != null) adapter.closeProfileProxy(BluetoothProfile.A2DP, a2dp);+ super.onDestroy();+ }++ /** Only runs after onResume has checked the Nearby devices permission. */+ @SuppressLint("MissingPermission")+ private void refresh() {+ if (a2dp == null) return;+ int focus = 0;+ for (int i = 0; i < list.getChildCount(); i++) if (list.getChildAt(i).isFocused()) focus = i;+ list.removeAllViews();+ Set<String> on = new HashSet<>();+ for (BluetoothDevice d : a2dp.getConnectedDevices()) on.add(d.getAddress());+ for (BluetoothDevice device : adapter.getBondedDevices()) {+ if (!Link.isAudio(device.getBluetoothClass())) continue;+ String address = device.getAddress();+ boolean connected = on.contains(address);+ Row row = new Row(this, device.getName() == null ? address : device.getName(),+ pending.contains(address) ? "Working…" : connected ? "Connected" : "Not connected",+ () -> toggle(device, connected));+ row.setValue(connected ? "Disconnect" : "Connect");+ list.addView(row, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,+ ViewGroup.LayoutParams.WRAP_CONTENT));+ }+ status.setText(list.getChildCount() == 0+ ? "No paired speakers. Pair one in the TV's Bluetooth settings first."+ : "OK connects or disconnects a speaker.");+ if (list.getChildCount() > 0) list.getChildAt(Math.min(focus, list.getChildCount() - 1)).requestFocus();+ }++ private void toggle(BluetoothDevice device, boolean connected) {+ if (a2dp == null || pending.contains(device.getAddress())) return;+ if (!Link.set(a2dp, device, !connected)) {+ status.setText("Android refused. Use the TV's Bluetooth settings: "+ + Settings.ACTION_BLUETOOTH_SETTINGS.substring(Settings.ACTION_BLUETOOTH_SETTINGS.lastIndexOf('.') + 1));+ return;+ }+ pending.add(device.getAddress());+ refresh();+ // A state change normally clears it; if none arrives (a speaker that is off), stop saying Working.+ main.postDelayed(() -> {+ pending.remove(device.getAddress());+ refresh();+ }, 12000);+ }+}diff --git a/addons/bluetooth-connect/app/src/main/java/com/gathin/btconnect/Row.java b/addons/bluetooth-connect/app/src/main/java/com/gathin/btconnect/Row.javanew file mode 100644index 000000000..eb6d46bc7--- /dev/null+++ b/addons/bluetooth-connect/app/src/main/java/com/gathin/btconnect/Row.java@@ -0,0 +1,58 @@+package com.gathin.btconnect;++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/bluetooth-connect/app/src/main/res/drawable/banner.xml b/addons/bluetooth-connect/app/src/main/res/drawable/banner.xmlnew file mode 100644index 000000000..db4cf37dd--- /dev/null+++ b/addons/bluetooth-connect/app/src/main/res/drawable/banner.xml@@ -0,0 +1,13 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- 16:9 banner: a speaker with a link that is cut. 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="#39C5CF" android:pathData="M200,50h60v80h-60z" />+ <path android:fillColor="#101418" android:pathData="M230,72m-10,0a10,10 0 1 1 20,0a10,10 0 1 1 -20,0" />+ <path android:fillColor="#101418" android:pathData="M230,106m-16,0a16,16 0 1 1 32,0a16,16 0 1 1 -32,0" />+ <path android:fillColor="#FFFFFF" android:pathData="M60,60h60v14h-60z" />+ <path android:fillColor="#FFFFFF" android:pathData="M60,106h24v14h-24z" />+ <path android:fillColor="#FFFFFF" android:pathData="M96,106h24v14h-24z" />+</vector>diff --git a/addons/bluetooth-connect/app/src/main/res/drawable/ic_foreground.xml b/addons/bluetooth-connect/app/src/main/res/drawable/ic_foreground.xmlnew file mode 100644index 000000000..d39b4d5c8--- /dev/null+++ b/addons/bluetooth-connect/app/src/main/res/drawable/ic_foreground.xml@@ -0,0 +1,9 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- A speaker 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:fillColor="#39C5CF" android:pathData="M40,30h28v48h-28z" />+ <path android:fillColor="#000000" android:pathData="M54,42m-5,0a5,5 0 1 1 10,0a5,5 0 1 1 -10,0" />+ <path android:fillColor="#000000" android:pathData="M54,62m-9,0a9,9 0 1 1 18,0a9,9 0 1 1 -18,0" />+</vector>diff --git a/addons/bluetooth-connect/app/src/main/res/drawable/row_background.xml b/addons/bluetooth-connect/app/src/main/res/drawable/row_background.xmlnew file mode 100644index 000000000..03ccab9f5--- /dev/null+++ b/addons/bluetooth-connect/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/bluetooth-connect/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/addons/bluetooth-connect/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xmlnew file mode 100644index 000000000..0a99b20b1--- /dev/null+++ b/addons/bluetooth-connect/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/bluetooth-connect/app/src/main/res/values/strings.xml b/addons/bluetooth-connect/app/src/main/res/values/strings.xmlnew file mode 100644index 000000000..df1e9fd58--- /dev/null+++ b/addons/bluetooth-connect/app/src/main/res/values/strings.xml@@ -0,0 +1,4 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <string name="app_name">Bluetooth Connect</string>+</resources>diff --git a/addons/bluetooth-connect/app/src/main/res/xml/module_card.xml b/addons/bluetooth-connect/app/src/main/res/xml/module_card.xmlnew file mode 100644index 000000000..642e8bb2a--- /dev/null+++ b/addons/bluetooth-connect/app/src/main/res/xml/module_card.xml@@ -0,0 +1,2 @@+<?xml version="1.0" encoding="utf-8"?>+<card spec="1" label="Bluetooth" caption="Connect / disconnect" accent="#39C5CF" />diff --git a/addons/bluetooth-connect/app/src/test/java/com/gathin/btconnect/LinkTest.java b/addons/bluetooth-connect/app/src/test/java/com/gathin/btconnect/LinkTest.javanew file mode 100644index 000000000..d54175a6f--- /dev/null+++ b/addons/bluetooth-connect/app/src/test/java/com/gathin/btconnect/LinkTest.java@@ -0,0 +1,11 @@+package com.gathin.btconnect;++import static org.junit.Assert.assertTrue;++import org.junit.Test;++public class LinkTest {+ @Test public void unknownClassIsShown() {+ assertTrue(Link.isAudio(null));+ }+}diff --git a/addons/bluetooth-connect/build.gradle b/addons/bluetooth-connect/build.gradlenew file mode 100644index 000000000..48978475f--- /dev/null+++ b/addons/bluetooth-connect/build.gradle@@ -0,0 +1,3 @@+plugins {+ id 'com.android.application' version '8.5.2' apply false+}diff --git a/addons/bluetooth-connect/gradle.properties b/addons/bluetooth-connect/gradle.propertiesnew file mode 100644index 000000000..18825f968--- /dev/null+++ b/addons/bluetooth-connect/gradle.properties@@ -0,0 +1,3 @@+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8+android.useAndroidX=true+android.nonTransitiveRClass=truediff --git a/addons/bluetooth-connect/gradle/wrapper/gradle-wrapper.jar b/addons/bluetooth-connect/gradle/wrapper/gradle-wrapper.jarnew file mode 100644index 000000000..2c3521197Binary files /dev/null and b/addons/bluetooth-connect/gradle/wrapper/gradle-wrapper.jar differdiff --git a/addons/bluetooth-connect/gradle/wrapper/gradle-wrapper.properties b/addons/bluetooth-connect/gradle/wrapper/gradle-wrapper.propertiesnew file mode 100644index 000000000..77f5d0ba6--- /dev/null+++ b/addons/bluetooth-connect/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/distsdiff --git a/addons/bluetooth-connect/gradlew b/addons/bluetooth-connect/gradlewnew file mode 100755index 000000000..f5feea6d6--- /dev/null+++ b/addons/bluetooth-connect/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/bluetooth-connect/gradlew.bat b/addons/bluetooth-connect/gradlew.batnew file mode 100644index 000000000..9d21a2183--- /dev/null+++ b/addons/bluetooth-connect/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++:omegadiff --git a/addons/bluetooth-connect/install.sh b/addons/bluetooth-connect/install.shnew file mode 100755index 000000000..5f9dc7b04--- /dev/null+++ b/addons/bluetooth-connect/install.sh@@ -0,0 +1,27 @@+#!/usr/bin/env bash+# Build Bluetooth Connect, install it on the TV and let it switch its own key service on.+# TV_HOST=<tv ip> addons/bluetooth-connect/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=com.gathin.btconnect+# 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/bluetooth-connect.apk+OUT=$(tv 'pm install -r /data/local/tmp/bluetooth-connect.apk; rm -f /data/local/tmp/bluetooth-connect.apk')+echo "$OUT"+case "$OUT" in *Success*) ;; *) echo "ERROR: pm install failed" >&2; exit 1 ;; esac++# Nearby devices, so the app lists and switches paired speakers without asking on the TV.+tv "pm grant $PKG android.permission.BLUETOOTH_CONNECT; echo permission granted"+tv "am start -n $PKG/.MainActivity >/dev/null; echo opened"+echo "Installed. Bluetooth Connect is open on the TV; press Home and answer Show card for the card."diff --git a/addons/bluetooth-connect/screenshot.jpg b/addons/bluetooth-connect/screenshot.jpgnew file mode 100644index 000000000..80cd69d96Binary files /dev/null and b/addons/bluetooth-connect/screenshot.jpg differdiff --git a/addons/bluetooth-connect/settings.gradle b/addons/bluetooth-connect/settings.gradlenew file mode 100644index 000000000..30b19ec0f--- /dev/null+++ b/addons/bluetooth-connect/settings.gradle@@ -0,0 +1,16 @@+pluginManagement {+ repositories {+ google()+ mavenCentral()+ gradlePluginPortal()+ }+}+dependencyResolutionManagement {+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)+ repositories {+ google()+ mavenCentral()+ }+}+rootProject.name = "bluetooth-connect"+include ':app'