Skip to content

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

HomeKeyService: open Settings from the remote's Settings button

Nguyen Minh Tuanaefb8cc45f29
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
index 0c0626b7c..e00f10e6f 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
@@ -2,6 +2,7 @@ package com.gathin.tvhome;
import android.accessibilityservice.AccessibilityService;
import android.content.Intent;
+import android.provider.Settings;
import android.view.KeyEvent;
import android.view.accessibility.AccessibilityEvent;
@@ -16,8 +17,30 @@ import android.view.accessibility.AccessibilityEvent;
*/
public class HomeKeyService extends AccessibilityService {
+ /** Scancodes of remote buttons that should open Settings (config.xml, settings_key_scancodes). */
+ private int[] settingsScancodes = new int[0];
+
+ @Override
+ protected void onServiceConnected() {
+ super.onServiceConnected();
+ settingsScancodes = getResources().getIntArray(R.array.settings_key_scancodes);
+ }
+
+ private boolean isSettingsKey(KeyEvent event) {
+ if (event.getKeyCode() == KeyEvent.KEYCODE_SETTINGS) return true;
+ for (int code : settingsScancodes) if (event.getScanCode() == code) return true;
+ return false;
+ }
+
@Override
protected boolean onKeyEvent(KeyEvent event) {
+ // The stock launcher handled the remote's Settings button; with it disabled the button does nothing.
+ if (isSettingsKey(event)) {
+ if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) {
+ startActivity(new Intent(Settings.ACTION_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
+ }
+ return true;
+ }
if (event.getKeyCode() != KeyEvent.KEYCODE_ALL_APPS) return false;
if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) {
Intent home = new Intent(Intent.ACTION_MAIN)
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index d10ea0bd7..c0dc9181d 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -40,6 +40,13 @@
(XGIMI projectors: com.xgimi.action.hdmiPlayer). Leave empty to omit. -->
<string name="input_action" translatable="false"></string>
+ <!-- Remote buttons that open Settings, by Linux scancode (HOME_KEY_SERVICE=1 build-and-install.sh). Remotes
+ that send KEYCODE_SETTINGS need no entry. Some send a code Android does not map: the Xiaomi/Fengmi
+ projector remote's gear button is scancode 384 (KEY_TAPE). Find yours with
+ `tools/tv.py 'getevent -lt'` while pressing the button. Leave empty to omit. -->
+ <integer-array name="settings_key_scancodes">
+ </integer-array>
+
<!-- Show the Solar Hijri (Shamsi) date used in Iran and Afghanistan, e.g. "27 Mehr 1405", above the
Gregorian date. -->
<bool name="shamsi_date">false</bool>