Skip to content

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

Launcher: keep the remote's Input button working without the stock launcher

Roca Changd2c5327862ff
diff --git a/README.md b/README.md
index 89c5b11cc..e56cfb778 100644
--- a/README.md
+++ b/README.md
@@ -81,6 +81,8 @@ A home screen that is yours again:
- **A greeting, a large thin clock and the date**, set in
[Outfit](https://fonts.google.com/specimen/Outfit).
- **A matching Clock screensaver**, optional, that drifts around the screen so nothing burns in.
+- **The remote's Input button keeps working.** On Google TV it was handled by the stock launcher;
+ a small accessibility service maps it (`KEYCODE_TV`) to the system input switcher, in any app.
And a TV that stops working against you: no sponsored rows, no "Discover" nags, no analytics
phoning home, no apps you never asked for.
diff --git a/launcher/app/src/main/AndroidManifest.xml b/launcher/app/src/main/AndroidManifest.xml
index 8cea721b9..b42ca7cff 100644
--- a/launcher/app/src/main/AndroidManifest.xml
+++ b/launcher/app/src/main/AndroidManifest.xml
@@ -44,5 +44,19 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
+
+ <!-- The remote's Input button (KEYCODE_TV) opens the input switcher; see InputKeyService. -->
+ <service
+ android:name=".InputKeyService"
+ android:exported="false"
+ android:label="@string/app_name"
+ android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
+ <intent-filter>
+ <action android:name="android.accessibilityservice.AccessibilityService" />
+ </intent-filter>
+ <meta-data
+ android:name="android.accessibilityservice"
+ android:resource="@xml/input_key_service" />
+ </service>
</application>
</manifest>
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java b/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java
new file mode 100644
index 000000000..0ebac190c
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java
@@ -0,0 +1,38 @@
+package com.gathin.tvhome;
+
+import android.accessibilityservice.AccessibilityService;
+import android.content.ActivityNotFoundException;
+import android.content.Intent;
+import android.view.KeyEvent;
+import android.view.accessibility.AccessibilityEvent;
+
+/**
+ * Maps the remote's Input button to the system input switcher, from any app. Remotes such as the Chromecast voice
+ * remote send KEYCODE_TV for it; on Google TV the stock launcher handles that key, so with the stock launcher
+ * disabled the button does nothing. Only KEYCODE_TV is consumed; every other key passes through untouched.
+ * build-and-install.sh enables it (settings secure enabled_accessibility_services).
+ */
+public class InputKeyService extends AccessibilityService {
+
+ private static final String ACTION_VIEW_INPUTS = "com.android.tv.action.VIEW_INPUTS";
+
+ @Override
+ protected boolean onKeyEvent(KeyEvent event) {
+ if (event.getKeyCode() != KeyEvent.KEYCODE_TV) return false;
+ if (event.getAction() == KeyEvent.ACTION_UP) {
+ try {
+ startActivity(new Intent(ACTION_VIEW_INPUTS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
+ } catch (ActivityNotFoundException ignored) {
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void onAccessibilityEvent(AccessibilityEvent event) {
+ }
+
+ @Override
+ public void onInterrupt() {
+ }
+}
diff --git a/launcher/app/src/main/res/values-de/strings.xml b/launcher/app/src/main/res/values-de/strings.xml
index c7331ed4d..34c94d6ed 100644
--- a/launcher/app/src/main/res/values-de/strings.xml
+++ b/launcher/app/src/main/res/values-de/strings.xml
@@ -19,4 +19,5 @@
<string name="not_available">Auf diesem TV nicht verfügbar</string>
<string name="cant_open">%1$s lässt sich nicht öffnen</string>
<string name="date_format">EEEE, d. MMMM</string>
+ <string name="input_key_service_description">Öffnet die Quellenauswahl, wenn die Input-Taste der Fernbedienung gedrückt wird.</string>
</resources>
diff --git a/launcher/app/src/main/res/values/strings.xml b/launcher/app/src/main/res/values/strings.xml
index 81b72f54a..e9c6268b4 100644
--- a/launcher/app/src/main/res/values/strings.xml
+++ b/launcher/app/src/main/res/values/strings.xml
@@ -20,4 +20,5 @@
<string name="cant_open">Can\'t open %1$s</string>
<string name="date_format">EEEE d MMMM</string>
<string name="dream_name">Clock</string>
+ <string name="input_key_service_description">Opens the input switcher when the remote\'s Input button is pressed.</string>
</resources>
diff --git a/launcher/app/src/main/res/xml/input_key_service.xml b/launcher/app/src/main/res/xml/input_key_service.xml
new file mode 100644
index 000000000..52eab154e
--- /dev/null
+++ b/launcher/app/src/main/res/xml/input_key_service.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
+ android:accessibilityEventTypes="typeWindowStateChanged"
+ android:accessibilityFeedbackType="feedbackGeneric"
+ android:accessibilityFlags="flagRequestFilterKeyEvents"
+ android:canRequestFilterKeyEvents="true"
+ android:description="@string/input_key_service_description" />
diff --git a/launcher/build-and-install.ps1 b/launcher/build-and-install.ps1
index eaab3dc74..d0e68aef1 100644
--- a/launcher/build-and-install.ps1
+++ b/launcher/build-and-install.ps1
@@ -41,6 +41,7 @@ if ("$out" -match 'Error') { throw 'could not set the new launcher as home; the
@(
'pm grant com.gathin.tvhome android.permission.ACCESS_FINE_LOCATION 2>/dev/null; echo location-granted',
'cmd package set-home-activity --user 0 com.gathin.tvhome',
- "pm disable-user --user 0 $StockLauncher"
+ "pm disable-user --user 0 $StockLauncher",
+ 's=$(settings get secure enabled_accessibility_services); case "$s" in *InputKeyService*) ;; null|"") settings put secure enabled_accessibility_services com.gathin.tvhome/.InputKeyService ;; *) settings put secure enabled_accessibility_services "$s:com.gathin.tvhome/.InputKeyService" ;; esac; settings put secure accessibility_enabled 1; echo input-button-enabled'
) | & $py -I ..\tools\tv.py --batch
Write-Host 'Installed. Press Home on the remote to see it.'
diff --git a/launcher/build-and-install.sh b/launcher/build-and-install.sh
index 9c9d2ed19..ffcb7553e 100755
--- a/launcher/build-and-install.sh
+++ b/launcher/build-and-install.sh
@@ -20,5 +20,6 @@ printf '%s\n' \
"pm grant com.gathin.tvhome android.permission.ACCESS_FINE_LOCATION 2>/dev/null; echo location-granted" \
"cmd package set-home-activity --user 0 com.gathin.tvhome/.MainActivity" \
"pm disable-user --user 0 $STOCK_LAUNCHER" \
+ 's=$(settings get secure enabled_accessibility_services); case "$s" in *InputKeyService*) ;; null|"") settings put secure enabled_accessibility_services com.gathin.tvhome/.InputKeyService ;; *) settings put secure enabled_accessibility_services "$s:com.gathin.tvhome/.InputKeyService" ;; esac; settings put secure accessibility_enabled 1; echo input-button-enabled' \
| "$PY" -I ../tools/tv.py --batch
echo "Installed. Press Home on the remote to see it."