Skip to content

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

Merge PR #1387: launcher: drop HomeKeyService while the screen is off

Gathin23860142f51285
diff --cc launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
index 3dcd4eb02,bf21d34a9..016d41d45
--- a/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/HomeKeyService.java
@@@ -8,9 -8,9 +8,10 @@@ import android.content.Context
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.os.Build;
import android.os.Handler;
import android.os.Looper;
+ import android.os.PowerManager;
import android.os.SystemClock;
import android.os.UserManager;
import android.content.pm.PackageManager;
@@@ -62,15 -59,14 +63,21 @@@ public class HomeKeyService extends Acc
private BroadcastReceiver unlockReceiver;
/** The stock launcher's HOME activities (stock_home_redirect), disabled ones included. */
private final Set<String> stockHome = new HashSet<>();
+ /** stock_home_redirect, the stock launcher's package. */
+ private String stockHomePackage = "";
+ /** power_on_home: the Live TV package to send back to Home, empty when off; armed until this uptime or a key. */
+ private String powerOnLiveTv = "";
+ private long powerOnUntil;
+ /** power_on_home: re-arms after the screen turns on; null unless the key is on. */
+ private BroadcastReceiver screenOnReceiver;
/** Stops key filtering while a game controller is connected; null unless gamepad_passthrough and key_filter, or before the unlock. */
private GamepadPassthrough gamepads;
+ /** Screen-off receiver while guard_off_in_standby is set; null otherwise. */
+ 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() {
@@@ -105,10 -102,25 +113,26 @@@
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 (screenOnReceiver != null) unregisterReceiver(screenOnReceiver);
+ if (standbyExit != null) {
+ try {
+ unregisterReceiver(standbyExit);
+ } catch (RuntimeException ignored) {
+ }
+ standbyExit = null;
+ }
if (gamepads != null) gamepads.stop();
if (consumeVolumeKeys) VolumeKeys.stop();
super.onDestroy();
@@@ -154,7 -181,8 +207,8 @@@
info.eventTypes |= AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED;
setServiceInfo(info);
}
- if (!stockHome.isEmpty()) probeAtBoot();
+ if (!stockHome.isEmpty() || !powerOnLiveTv.isEmpty()) probeAtBoot();
+ armStandbyExit();
holdAppKeys = RemoteKeys.parseHoldAppKeys(config.appKeys);
holdAppScancodes = RemoteKeys.parseHoldAppScancodes(config.appKeys);
// gamepad_passthrough, off by default. Only with key_filter on: off, the service never filters keys.