Skip to content

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

launcher: arm standby exit when the opt-in arrives

VincentYe1230114c4d629b2
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/GuardKeep.java b/launcher/app/src/main/java/com/gathin/tvhome/GuardKeep.java
index cb3d8bf8c..96c873827 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/GuardKeep.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/GuardKeep.java
@@ -46,6 +46,9 @@ final class GuardKeep {
/** Puts HomeKeyService back on the enabled list when standby exit is opted in. Other services stay. */
static void ensureHomeKey(Context context) {
+ // The helper may already be bound. Arming only inside onServiceConnected misses an opt-in
+ // that arrives after that, so the first screen-off does nothing (Philips 65PUS8102).
+ HomeKeyService.applyStandbyOptIn();
if (!offInStandby(context)) return;
if (context.checkSelfPermission(Manifest.permission.WRITE_SECURE_SETTINGS)
!= PackageManager.PERMISSION_GRANTED) return;
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 af4229119..bf21d34a9 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
@@ -65,10 +65,13 @@ public class HomeKeyService extends AccessibilityService {
private BroadcastReceiver standbyExit;
/** disableSelf is how this service leaves for standby, not the user turning it off. */
private boolean steppingOut;
+ /** The bound helper, so the opt-in broadcast can arm it without waiting for a new connection. */
+ private static HomeKeyService running;
@Override
protected void onServiceConnected() {
super.onServiceConnected();
+ running = this;
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
@@ -99,8 +102,17 @@ public class HomeKeyService extends AccessibilityService {
unlockReceiver = null;
}
+ /** The opt-in broadcast: arm this binding now, or drop the receiver if the opt-in was turned off. */
+ static void applyStandbyOptIn() {
+ HomeKeyService service = running;
+ if (service == null) return;
+ if (GuardKeep.offInStandby(service)) service.armStandbyExit();
+ else service.disarmStandbyExit();
+ }
+
@Override
public void onDestroy() {
+ if (running == this) running = null;
stopWaitingForUnlock();
if (standbyExit != null) {
try {
@@ -129,6 +141,15 @@ public class HomeKeyService extends AccessibilityService {
if (power != null && !power.isInteractive()) leaveForStandby();
}
+ private void disarmStandbyExit() {
+ if (standbyExit == null) return;
+ try {
+ unregisterReceiver(standbyExit);
+ } catch (RuntimeException ignored) {
+ }
+ standbyExit = null;
+ }
+
private void leaveForStandby() {
steppingOut = true;
GuardKeep.stepOut(this);