Skip to content

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

launcher: with restore_key_services off the helpers record nothing

Cristian Rojas191448f2471e
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 634dec909..68bef961e 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
@@ -33,6 +33,8 @@ import java.util.Set;
*/
public class HomeKeyService extends AccessibilityService {
+ /** restore_key_services was on when the config was read: this helper is noted for ServiceRepair. */
+ private boolean repairRecord;
/** Remote buttons that should open Settings (config.xml, settings_key_scancodes and settings_key_keycodes). */
private int[] settingsScancodes = new int[0];
private int[] settingsKeycodes = new int[0];
@@ -51,7 +53,6 @@ public class HomeKeyService extends AccessibilityService {
@Override
protected void onServiceConnected() {
super.onServiceConnected();
- ServiceRepair.connected(this, getClass());
settingsScancodes = getResources().getIntArray(R.array.settings_key_scancodes);
// The service is directBootAware: Android 11 skips a service that is not while the user is still
// locked at boot, writes accessibility_enabled=0 and, on TCL G03 firmware, never binds it after the
@@ -91,6 +92,10 @@ public class HomeKeyService extends AccessibilityService {
private void loadConfig() {
// Keycodes and the panel choice can also come from a theme; theme.sh restarts this service.
Config config = Config.load(this);
+ // restore_key_services: note that this helper runs, so Home can put it back after a force stop. Here, not
+ // in onServiceConnected: the note is in credential-protected storage too, readable only after the unlock.
+ repairRecord = config.restoreKeyServices;
+ if (repairRecord) ServiceRepair.connected(this, getClass());
settingsKeycodes = config.settingsKeycodes;
settingsPanel = config.settingsKeyPanel;
appKeys = RemoteKeys.parseAppKeys(config.appKeys);
@@ -148,7 +153,7 @@ public class HomeKeyService extends AccessibilityService {
/** Unbound by Android: the user turned the helper off, so Home doesn't put it back (ServiceRepair). */
@Override
public boolean onUnbind(Intent intent) {
- ServiceRepair.disconnected(this, getClass());
+ if (repairRecord) ServiceRepair.disconnected(this, getClass());
return super.onUnbind(intent);
}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java b/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java
index b69c7f834..45e54135c 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/InputKeyService.java
@@ -25,13 +25,17 @@ public class InputKeyService extends AccessibilityService {
private Map<Integer, String> appScancodes = Collections.emptyMap();
private Map<Integer, String> holdAppKeys = Collections.emptyMap();
private Map<Integer, String> holdAppScancodes = Collections.emptyMap();
+ /** restore_key_services was on when the config was read: this helper is noted for ServiceRepair. */
+ private boolean repairRecord;
@Override
protected void onServiceConnected() {
super.onServiceConnected();
- ServiceRepair.connected(this, getClass());
// From config.xml or a theme's config.json; theme.sh rebinds this service after a push.
Config config = Config.load(this);
+ // restore_key_services: note that this helper runs, so Home can put it back after a force stop.
+ repairRecord = config.restoreKeyServices;
+ if (repairRecord) ServiceRepair.connected(this, getClass());
inputKeycodes = config.inputKeycodes;
appKeys = RemoteKeys.parseAppKeys(config.appKeys);
appScancodes = RemoteKeys.parseAppScancodes(config.appKeys);
@@ -66,7 +70,7 @@ public class InputKeyService extends AccessibilityService {
/** Unbound by Android: the user turned the helper off, so Home doesn't put it back (ServiceRepair). */
@Override
public boolean onUnbind(Intent intent) {
- ServiceRepair.disconnected(this, getClass());
+ if (repairRecord) ServiceRepair.disconnected(this, getClass());
return super.onUnbind(intent);
}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/ServiceRepair.java b/launcher/app/src/main/java/com/gathin/tvhome/ServiceRepair.java
index c04f6123d..8465d0696 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/ServiceRepair.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ServiceRepair.java
@@ -14,9 +14,10 @@ import java.util.List;
/**
* Android takes an app's accessibility services off the enabled list when the app is force-stopped (Settings, a
* cleaner app, or am force-stop), and the remote's Home, Input and app buttons then stop working until the helper
- * is turned on again over ADB. A running helper records itself here and drops the record when Android unbinds it
- * (the user turned it off); a force stop kills the process before that, so the record stays. Home starting again
- * puts recorded helpers back on the list, when the installer granted WRITE_SECURE_SETTINGS.
+ * is turned on again over ADB. With restore_key_services on, a running helper records itself here and drops the
+ * record when Android unbinds it (the user turned it off); a force stop kills the process before that, so the
+ * record stays. Home starting again puts recorded helpers back on the list, when the installer granted
+ * WRITE_SECURE_SETTINGS. With the flag off nothing is recorded and nothing is restored.
*/
final class ServiceRepair {
private static final String PREFS = "accessibility_helpers";