Skip to content

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

Bring a killed key helper back: add, remove, add

Nathanb79c0ffc596b
diff --git a/docs/TROUBLESHOOTING.md b/docs/TROUBLESHOOTING.md
index f5929eb23..6e292e77b 100644
--- a/docs/TROUBLESHOOTING.md
+++ b/docs/TROUBLESHOOTING.md
@@ -521,6 +521,20 @@ that list. With `restore_key_services` on (`config.xml` or a theme) and `WRITE_S
(`RESTORE_KEY_SERVICES=1` at install, `-RestoreKeyServices` on Windows), Home puts the helpers that were
running back on the list the next time it starts; a helper turned off in Settings stays off.
+- **Home puts the helper back on the list after a force stop, and it still is not bound.** `dumpsys
+ accessibility` then shows `Bound services:{}`, `accessibility_enabled` falls back to `0`, and the helper
+ sits under `Crashed services`: a killed helper is marked crashed, and Android never binds a crashed
+ service again, whatever the list says. It drops the mark only when it sees the helper leave the list,
+ and after a force stop the list is already empty, so a plain removal changes nothing. `ServiceRepair`
+ therefore adds the helpers, removes them and adds them again, a second apart. Seen on a Hisense SmartTV
+ 4K FFM (`songshan`, Android 11, `RTT2.220118.001`), whose standby (`com.hisense.STR_SUSPEND`) kills every
+ third-party app except the one on screen (`PowerVtImp: kill 3rd app`): the remote's app buttons stopped
+ after the first standby with another app open. By hand, the same three writes:
+
+ ```sh
+ tools/tv.py "settings put secure enabled_accessibility_services com.gathin.tvhome/.InputKeyService; sleep 1; settings put secure enabled_accessibility_services ''; sleep 1; settings put secure enabled_accessibility_services com.gathin.tvhome/.InputKeyService"
+ ```
+
- **Enabled** means the component is in that user's colon-separated list (the class may be written in
full, `com.gathin.tvhome/com.gathin.tvhome.HomeKeyService`). Match the whole component.
- **Bound** means it appears under that user's `Bound services` section of the dump (`services` on older
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 8465d0696..3fb726946 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/ServiceRepair.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/ServiceRepair.java
@@ -46,18 +46,46 @@ final class ServiceRepair {
if (name != null) enabled.add(name);
}
}
- StringBuilder updated = new StringBuilder(list == null || list.equals("null") ? "" : list);
- boolean missing = false;
+ List<ComponentName> recorded = new ArrayList<>();
for (String service : prefs(context).getAll().keySet()) {
- ComponentName name = new ComponentName(context.getPackageName(), service);
- if (enabled.contains(name)) continue;
+ recorded.add(new ComponentName(context.getPackageName(), service));
+ }
+ if (recorded.isEmpty()) return;
+ // The list without our recorded helpers, then with all of them.
+ StringBuilder others = new StringBuilder();
+ for (ComponentName name : enabled) {
+ if (recorded.contains(name)) continue;
+ if (others.length() > 0) others.append(':');
+ others.append(name.flattenToShortString());
+ }
+ StringBuilder updated = new StringBuilder(others);
+ boolean missing = false;
+ for (ComponentName name : recorded) {
+ if (!enabled.contains(name)) missing = true;
if (updated.length() > 0) updated.append(':');
updated.append(name.flattenToShortString());
- missing = true;
}
if (!missing) return;
- Settings.Secure.putString(cr, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, updated.toString());
- Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_ENABLED, 1);
+ // A killed helper also lands on Android's "Crashed services" list (dumpsys accessibility), and a
+ // crashed service is never bound again, so putting it back on the list alone binds nothing and the
+ // switch falls back to 0 (Hisense songshan, Android 11, whose standby kills third-party apps). Android
+ // drops the crashed mark when it sees the helper leave the enabled list, so add, remove, add: after a
+ // force stop the list is already empty, and a removal that changes nothing is not seen. Off the main
+ // thread, so Home does not wait for the pauses.
+ final String without = others.toString();
+ final String with = updated.toString();
+ new Thread(() -> {
+ try {
+ Settings.Secure.putString(cr, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, with);
+ Thread.sleep(1000);
+ Settings.Secure.putString(cr, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, without);
+ Thread.sleep(1000);
+ Settings.Secure.putString(cr, Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, with);
+ Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_ENABLED, 1);
+ } catch (RuntimeException | InterruptedException ignored) {
+ // The setting is the system's; a refusal leaves the helper off, as before.
+ }
+ }, "ServiceRepair").start();
} catch (RuntimeException ignored) {
// The setting is the system's; a refusal leaves the helper off, as before.
}