Skip to content

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

addons: add Open on wake, opens a chosen app when the screen turns on

Luiz Fernando9065bd91ef60
diff --git a/addons/README.md b/addons/README.md
index 58243b73c..f39fffd33 100644
--- a/addons/README.md
+++ b/addons/README.md
@@ -20,6 +20,7 @@ the core bigger or change how it behaves. You install an add-on only if you want
| [TV Hub](tv-hub/) | One live-TV guide for M3U/XMLTV playlists, Dispatcharr and HDHomeRun tuners, with a Media3 player and shortcuts to installed live-TV apps | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android TV 14) | `INTERNET` | <img src="tv-hub/screenshot.jpg" width="240" alt="TV Hub on a TV"> |
| [Headphones](headphones/) | Bluetooth headphones made easy: where the sound goes, paired pairs with battery, a pairing shortcut, and a quiet guard that pauses and mutes the speakers when headphones drop | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | Bluetooth (paired devices only) | <img src="headphones/screenshot.jpg" width="240" alt="Headphones on a TV"> |
| [TV Static](tv-static/) | An off-the-air moment each time the screen turns on: the picture opens from a bright line, snow and hiss, colour bars or an old "no signal" screen for 3 to 10 s, then fades into what was on screen; the card sets style, sound and length | [@luyzfernando08](https://github.com/luyzfernando08) | Xiaomi Mi Box S (Android TV 9), Philco by Skyworth (Android TV 14) | foreground service (screen-on watcher), start at boot, display over other apps | <img src="tv-static/screenshot.jpg" width="240" alt="TV Static on a TV"> |
+| [Open on wake](wake-app/) | Opens the app you choose each time the screen turns on, optionally at a link (a video, a channel); the card shows the app as a picture and sets the wait | [@luyzfernando08](https://github.com/luyzfernando08) | Xiaomi Mi Box S (Android TV 9) | foreground service (screen-on watcher), start at boot, display over other apps | <img src="wake-app/screenshot.jpg" width="240" alt="Open on wake on a TV"> |
| [Brightness](brightness/) | Dims the picture below the TV's own minimum over every app (and the picture settings on Realtek TVs), with a warm night mode on a schedule and a one-press normal screen | [@maxhayim](https://github.com/maxhayim) | MOKA R8G (Android 14) | overlay, foreground service, start at boot | <img src="brightness/screenshot.jpg" width="240" alt="Brightness on a TV"> |
| [Sleep Timer](sleep-timer/) | A sleep timer: 15 to 120 minutes, a one-minute countdown over what is playing with "15 more minutes", then standby; over HDMI-CEC the TV turns off with the box | [@luyzfernando08](https://github.com/luyzfernando08) | Xiaomi Mi Box S (Android TV 9) | accessibility (lock-screen action only), display over other apps, exact alarms | <img src="sleep-timer/screenshot.jpg" width="240" alt="Sleep Timer on a TV"> |
| [Scoreboard](scoreboard/) | Streaming app usage leaderboard tracking launches and watch time with D-pad click-to-launch | [@EricWoodford](https://github.com/EricWoodford) | TiVo Stream 4K (Android TV 12) | `PACKAGE_USAGE_STATS` (granted via ADB) | <img src="scoreboard/screenshot.jpg" width="240" alt="Scoreboard on a TV"> |
diff --git a/addons/wake-app/.gitignore b/addons/wake-app/.gitignore
new file mode 100644
index 000000000..b0bbcda92
--- /dev/null
+++ b/addons/wake-app/.gitignore
@@ -0,0 +1,4 @@
+app/build/
+.gradle/
+build/
+local.properties
diff --git a/addons/wake-app/README.md b/addons/wake-app/README.md
new file mode 100644
index 000000000..74571d27d
--- /dev/null
+++ b/addons/wake-app/README.md
@@ -0,0 +1,89 @@
+# Open on wake
+
+Opens the app you choose every time the screen turns on, so the TV wakes straight into YouTube, your live
+TV app or whatever you watch first, instead of the home screen. Separate from the launcher.
+
+Package `io.github.luyzfernando08.wakeapp`. You see it as **Open on wake** (Portuguese: **Abrir ao ligar**).
+On cleanyourtv's Home it is also a module card, **Open on wake**, which opens its settings.
+
+## Settings
+
+Open the card (or the app's own tile). OK on a row changes it:
+
+| Setting | Choices |
+|---|---|
+| Open on wake | on (default), off |
+| App | opens a grid of every app a launcher would show, except home screens; OK on one picks it. None is chosen at first, so nothing opens until you pick |
+| Link | shown only when one is set (see below); OK clears it |
+| Wait after waking | 0 s (default), 3 s, 5 s, 10 s, 15 s |
+| Try it now | opens the chosen app once |
+
+Choosing another app clears the link, since a link belongs to the app it was meant for.
+
+Home screens (any launcher, including cleanyourtv's) are left out of the list and never opened, even if one is set
+from the install script: waking into a launcher that opens the app that opens the launcher would loop.
+
+Nothing opens on a screen that turns on and off again inside the wait, and not twice within 5 seconds. After a
+reboot the app opens 8 seconds late, so the home screen is already up and does not cover it.
+
+A box behind HDMI is slower than a TV with Android built in: its screen turns on before the TV has switched
+itself on and over to that input, so a few seconds of wait lets the TV catch up before the app starts (on a
+Mi Box S the TV took about seven seconds). Used together with TV Static, set the wait to its length or a bit
+more, so the app opens after the effect.
+
+## Opening at a link (a channel, a video)
+
+Some apps take an address and open on it: the YouTube app a video or playlist, a live TV app a channel. Setting
+one is done from a computer, because a TV remote is a poor keyboard:
+
+```powershell
+addons\wake-app\build-and-install.ps1 -TvHost 192.168.1.50 -App com.google.android.youtube.tv -Link 'https://www.youtube.com/watch?v=VIDEO_ID'
+```
+
+```sh
+TV_HOST=192.168.1.50 addons/wake-app/build-and-install.sh --app <package> --link '<address>'
+```
+
+The app is sent a plain `VIEW` for that address and nothing else. If it does not take the address, the app opens
+normally. Which address each app understands is the app's own business and not checked here.
+
+## Install
+
+JDK 17 and Android SDK 34, as for the launcher, and the `tools/venv` from the main README. The `gradlew`
+scripts reuse the launcher's pinned Gradle wrapper with this folder as the project.
+
+```sh
+TV_HOST=192.168.1.50 addons/wake-app/build-and-install.sh
+TV_HOST=192.168.1.50 addons/wake-app/build-and-install.sh --uninstall
+```
+
+```powershell
+powershell -ExecutionPolicy Bypass -File addons\wake-app\build-and-install.ps1 -TvHost 192.168.1.50 [-App <package>] [-Link <address>] [-Uninstall]
+```
+
+Then press Home and answer **Show card** if you want the card; Keep hidden leaves an ordinary app tile.
+
+## Permissions
+
+- **Foreground service** (`FOREGROUND_SERVICE`, `FOREGROUND_SERVICE_SPECIAL_USE`): `WatchService` keeps one
+ receiver for `SCREEN_ON` and `SCREEN_OFF` registered, which Android delivers only to receivers registered at
+ run time, never from the manifest. It does nothing else: no polling, no wake lock. Its notification sits in a
+ minimum-importance channel.
+- **Start at boot** (`RECEIVE_BOOT_COMPLETED`): to start the watcher again after a reboot, and to open the app
+ once then. On TCL sets the install script also allows the `APP_AUTO_START` app-op.
+- **Display over other apps** (`SYSTEM_ALERT_WINDOW`), granted by the install script with `appops`: Android 10
+ and later only let an app start another app's screen from the background when it holds this. The app draws no
+ overlay window.
+- **App list**: a `<queries>` entry for launcher apps, so the picker can list them. No `QUERY_ALL_PACKAGES`.
+- No network, no storage permission, nothing collected. Settings stay in the app's private preferences.
+- **`WatchService`** is exported only to callers holding `WRITE_SECURE_SETTINGS`, which the adb shell has and
+ ordinary apps cannot get, so the install script can start it, and set the app and link, and nothing else can.
+- **`SettingsActivity`** (exported) is the app's tile and the module card.
+
+## Tested on
+
+- Xiaomi Mi Box S (MIBOX4, Android TV 9), with the reference launcher 3.1: the picker and the settings card
+ with the real remote; opening the chosen app by itself after the screen went off and on again (standby, woken
+ with the remote); a link: the YouTube app opened straight on a video screen, not on its home page. A launcher
+ chosen from the install script is refused. Not tried: a TCL set, a boot (the 8-second delay) or a link to
+ a live TV channel.
diff --git a/addons/wake-app/app/build.gradle b/addons/wake-app/app/build.gradle
new file mode 100644
index 000000000..a7698218d
--- /dev/null
+++ b/addons/wake-app/app/build.gradle
@@ -0,0 +1,30 @@
+plugins {
+ id 'com.android.application'
+}
+
+android {
+ namespace 'io.github.luyzfernando08.wakeapp'
+ compileSdk 34
+
+ defaultConfig {
+ applicationId 'io.github.luyzfernando08.wakeapp'
+ minSdk 26
+ targetSdk 34
+ versionCode 1
+ versionName '1.0'
+ }
+
+ buildTypes {
+ release {
+ minifyEnabled true
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
+ // Sideloaded over ADB, never published.
+ signingConfig signingConfigs.debug
+ }
+ }
+
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
+ }
+}
diff --git a/addons/wake-app/app/src/main/AndroidManifest.xml b/addons/wake-app/app/src/main/AndroidManifest.xml
new file mode 100644
index 000000000..06bec5bef
--- /dev/null
+++ b/addons/wake-app/app/src/main/AndroidManifest.xml
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
+ <!-- Android 10 and later only let an app open another app from the background when it may draw over other
+ apps. the install script grants it; on Android 9 it is not needed. -->
+ <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
+
+ <uses-feature android:name="android.software.leanback" android:required="false" />
+ <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
+
+ <!-- The picker lists the apps a launcher would show, minus the home screens. -->
+ <queries>
+ <intent>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.HOME" />
+ </intent>
+ <intent>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent>
+ <intent>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent>
+ </queries>
+
+ <application
+ android:allowBackup="false"
+ android:banner="@drawable/banner"
+ android:icon="@drawable/banner"
+ android:label="@string/app_name">
+
+ <!-- The settings screen: the app's own tile and, on the cleanyourtv launcher, its module card. -->
+ <activity
+ android:name=".SettingsActivity"
+ android:exported="true"
+ android:theme="@android:style/Theme.DeviceDefault.NoActionBar">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
+ </intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="com.gathin.tvhome.category.DOCK_CARD" />
+ </intent-filter>
+ <meta-data android:name="com.gathin.tvhome.card" android:resource="@xml/module_card" />
+ </activity>
+
+ <activity
+ android:name=".PickerActivity"
+ android:exported="false"
+ android:theme="@android:style/Theme.DeviceDefault.NoActionBar" />
+
+ <!-- Keeps the screen-on receiver registered: SCREEN_ON cannot be received from the manifest. Exported only
+ to callers holding WRITE_SECURE_SETTINGS (the adb shell), so the install script can start it. -->
+ <service
+ android:name=".WatchService"
+ android:exported="true"
+ android:permission="android.permission.WRITE_SECURE_SETTINGS"
+ android:foregroundServiceType="specialUse">
+ <property
+ android:name="android.app.PROPERTY_SPECIAL_USE_FGS_SUBTYPE"
+ android:value="Opens a chosen app when the screen turns on" />
+ </service>
+
+ <receiver
+ android:name=".BootReceiver"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.intent.action.BOOT_COMPLETED" />
+ <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
+ </intent-filter>
+ </receiver>
+ </application>
+</manifest>
diff --git a/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/BootReceiver.java b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/BootReceiver.java
new file mode 100644
index 000000000..b0e11ae71
--- /dev/null
+++ b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/BootReceiver.java
@@ -0,0 +1,15 @@
+package io.github.luyzfernando08.wakeapp;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+/** After a boot or an update: start watching the screen, and after a boot also open the app once. */
+public class BootReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Intent watch = new Intent(context, WatchService.class);
+ if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) watch.putExtra(WatchService.EXTRA_BOOT, true);
+ context.startForegroundService(watch);
+ }
+}
diff --git a/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/Launch.java b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/Launch.java
new file mode 100644
index 000000000..b0d94e4fc
--- /dev/null
+++ b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/Launch.java
@@ -0,0 +1,52 @@
+package io.github.luyzfernando08.wakeapp;
+
+import android.content.ActivityNotFoundException;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.net.Uri;
+
+/** Opens the chosen app, at its link when one is set. */
+final class Launch {
+ private Launch() { }
+
+ /**
+ * True for any app that is a home screen. Opening one on wake would put the TV back on the launcher it
+ * just woke into, and with a launcher that opens this app in turn, loop.
+ */
+ static boolean isHome(Context ctx, String pkg) {
+ Intent home = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME);
+ for (ResolveInfo info : ctx.getPackageManager().queryIntentActivities(home, 0)) {
+ if (info.activityInfo.packageName.equals(pkg)) return true;
+ }
+ return false;
+ }
+
+ /** Returns false when nothing was opened: no app chosen, a home screen, or it is no longer installed. */
+ static boolean open(Context ctx) {
+ String app = Prefs.app(ctx);
+ if (app.isEmpty() || isHome(ctx, app)) return false;
+ String link = Prefs.link(ctx);
+ if (!link.isEmpty()) {
+ Intent view = new Intent(Intent.ACTION_VIEW, Uri.parse(link)).setPackage(app)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ try {
+ ctx.startActivity(view);
+ return true;
+ } catch (ActivityNotFoundException e) {
+ // The app does not take that link: open the app itself instead.
+ }
+ }
+ PackageManager pm = ctx.getPackageManager();
+ Intent main = pm.getLeanbackLaunchIntentForPackage(app);
+ if (main == null) main = pm.getLaunchIntentForPackage(app);
+ if (main == null) return false;
+ try {
+ ctx.startActivity(main.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
+ return true;
+ } catch (ActivityNotFoundException e) {
+ return false;
+ }
+ }
+}
diff --git a/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/PickerActivity.java b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/PickerActivity.java
new file mode 100644
index 000000000..441250e79
--- /dev/null
+++ b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/PickerActivity.java
@@ -0,0 +1,113 @@
+package io.github.luyzfernando08.wakeapp;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.TypedValue;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.GridLayout;
+import android.widget.LinearLayout;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+/** Every app that can be opened from a launcher, as a grid of cards with its picture; OK chooses one. */
+public class PickerActivity extends Activity {
+ private static final int CELL_DP = 190, ART_W = 168, ART_H = 94;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ LinearLayout page = Ui.page(this);
+ Ui.heading(page, R.string.pick_title, R.string.pick_hint);
+
+ int widthDp = Math.round(getResources().getDisplayMetrics().widthPixels
+ / getResources().getDisplayMetrics().density);
+ int columns = Math.max(3, (widthDp - 96) / CELL_DP);
+ GridLayout grid = new GridLayout(this);
+ grid.setColumnCount(columns);
+
+ ScrollView scroll = new ScrollView(this);
+ scroll.setClipToPadding(false);
+ scroll.setPadding(0, Ui.dp(this, 6), 0, Ui.dp(this, 6));
+ scroll.addView(grid);
+ page.addView(scroll, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 0, 1f));
+
+ String current = Prefs.app(this);
+ View focus = null;
+ for (String[] entry : apps()) {
+ boolean chosen = entry[1].equals(current);
+ View cell = cell(entry[0], entry[1], chosen);
+ cell.setOnClickListener(v -> {
+ Prefs.setApp(this, entry[1]);
+ finish();
+ });
+ grid.addView(cell);
+ if (focus == null || chosen) focus = cell;
+ }
+ setContentView(page);
+ if (focus != null) focus.requestFocus();
+ }
+
+ private View cell(String label, String pkg, boolean chosen) {
+ LinearLayout cell = new LinearLayout(this);
+ cell.setOrientation(LinearLayout.VERTICAL);
+ cell.setGravity(Gravity.CENTER_HORIZONTAL);
+ int pad = Ui.dp(this, 10);
+ cell.setPadding(pad, pad, pad, pad);
+ cell.setFocusable(true);
+ cell.setClickable(true);
+ cell.setBackground(Ui.card(this, 16, chosen));
+ GridLayout.LayoutParams lp = new GridLayout.LayoutParams();
+ lp.width = Ui.dp(this, CELL_DP - 12);
+ lp.setMargins(Ui.dp(this, 6), Ui.dp(this, 6), Ui.dp(this, 6), Ui.dp(this, 6));
+ cell.setLayoutParams(lp);
+
+ cell.addView(Ui.art(this, pkg, ART_W, ART_H));
+ TextView name = new TextView(this);
+ name.setText(label);
+ name.setTextColor(chosen ? Ui.ACCENT : Color.WHITE);
+ name.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
+ name.setSingleLine(true);
+ name.setEllipsize(TextUtils.TruncateAt.END);
+ name.setGravity(Gravity.CENTER);
+ name.setPadding(0, Ui.dp(this, 8), 0, 0);
+ cell.addView(name, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
+
+ // A small lift on the focused card, so the choice reads from across the room.
+ cell.setOnFocusChangeListener((v, focused) ->
+ v.animate().scaleX(focused ? 1.06f : 1f).scaleY(focused ? 1.06f : 1f).setDuration(120).start());
+ return cell;
+ }
+
+ /** {label, package} for each launchable app except this one and the home screens, sorted by label. */
+ private List<String[]> apps() {
+ PackageManager pm = getPackageManager();
+ List<ResolveInfo> found = pm.queryIntentActivities(
+ new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LEANBACK_LAUNCHER), 0);
+ if (found.isEmpty()) {
+ found = pm.queryIntentActivities(new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER), 0);
+ }
+ List<String[]> apps = new ArrayList<>();
+ List<String> seen = new ArrayList<>();
+ for (ResolveInfo info : found) {
+ String pkg = info.activityInfo.packageName;
+ if (pkg.equals(getPackageName()) || seen.contains(pkg) || Launch.isHome(this, pkg)) continue;
+ seen.add(pkg);
+ apps.add(new String[]{info.loadLabel(pm).toString(), pkg});
+ }
+ Collections.sort(apps, (a, b) -> a[0].toLowerCase(Locale.ROOT).compareTo(b[0].toLowerCase(Locale.ROOT)));
+ return apps;
+ }
+}
diff --git a/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/Prefs.java b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/Prefs.java
new file mode 100644
index 000000000..a4e4d050e
--- /dev/null
+++ b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/Prefs.java
@@ -0,0 +1,51 @@
+package io.github.luyzfernando08.wakeapp;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+
+/** The choices made on the settings screen. */
+final class Prefs {
+ private Prefs() { }
+
+ /** How long to wait after the screen turns on. A box behind HDMI shows a picture several seconds later. */
+ static final int[] DELAYS = {0, 3, 5, 10, 15};
+
+ private static SharedPreferences prefs(Context ctx) {
+ return ctx.getSharedPreferences("settings", Context.MODE_PRIVATE);
+ }
+
+ static boolean enabled(Context ctx) {
+ return prefs(ctx).getBoolean("enabled", true);
+ }
+
+ static void setEnabled(Context ctx, boolean value) {
+ prefs(ctx).edit().putBoolean("enabled", value).apply();
+ }
+
+ /** The package to open, or "" when none has been chosen yet. */
+ static String app(Context ctx) {
+ return prefs(ctx).getString("app", "");
+ }
+
+ /** Changing the app drops the link: a link belongs to the app it was meant for. */
+ static void setApp(Context ctx, String value) {
+ prefs(ctx).edit().putString("app", value).putString("link", "").apply();
+ }
+
+ /** An optional address for the app to open (a video, a channel), or "" to open the app itself. */
+ static String link(Context ctx) {
+ return prefs(ctx).getString("link", "");
+ }
+
+ static void setLink(Context ctx, String value) {
+ prefs(ctx).edit().putString("link", value).apply();
+ }
+
+ static int delay(Context ctx) {
+ return prefs(ctx).getInt("delay", 0);
+ }
+
+ static void setDelay(Context ctx, int value) {
+ prefs(ctx).edit().putInt("delay", value).apply();
+ }
+}
diff --git a/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/SettingsActivity.java b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/SettingsActivity.java
new file mode 100644
index 000000000..5ffdbe60e
--- /dev/null
+++ b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/SettingsActivity.java
@@ -0,0 +1,115 @@
+package io.github.luyzfernando08.wakeapp;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.graphics.Color;
+import android.os.Bundle;
+import android.util.TypedValue;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+/**
+ * The module card on the launcher's Home (and the app's own tile): the chosen app as a large card (OK picks
+ * another), then switch the feature on or off, how long to wait after the screen turns on, and a button to try it
+ * now. Each row changes on OK.
+ */
+public class SettingsActivity extends Activity {
+ private LinearLayout hero;
+ private TextView enabled, link, delay;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ LinearLayout root = Ui.page(this);
+ Ui.heading(root, R.string.app_name, R.string.hint);
+
+ hero = new LinearLayout(this);
+ hero.setOrientation(LinearLayout.HORIZONTAL);
+ hero.setGravity(Gravity.CENTER_VERTICAL);
+ int pad = Ui.dp(this, 16);
+ hero.setPadding(pad, pad, pad, pad);
+ hero.setFocusable(true);
+ hero.setClickable(true);
+ hero.setBackground(Ui.card(this, 24, false));
+ hero.setOnClickListener(v -> startActivity(new Intent(this, PickerActivity.class)));
+ LinearLayout.LayoutParams heroLp = new LinearLayout.LayoutParams(Ui.dp(this, 560),
+ LinearLayout.LayoutParams.WRAP_CONTENT);
+ heroLp.bottomMargin = Ui.dp(this, 12);
+ root.addView(hero, heroLp);
+
+ enabled = Ui.row(root);
+ enabled.setOnClickListener(v -> {
+ Prefs.setEnabled(this, !Prefs.enabled(this));
+ refresh();
+ });
+ link = Ui.row(root);
+ link.setOnClickListener(v -> {
+ Prefs.setLink(this, "");
+ refresh();
+ });
+ delay = Ui.row(root);
+ delay.setOnClickListener(v -> {
+ int now = Prefs.delay(this), next = Prefs.DELAYS[0];
+ for (int i = 0; i < Prefs.DELAYS.length - 1; i++) {
+ if (Prefs.DELAYS[i] == now) next = Prefs.DELAYS[i + 1];
+ }
+ Prefs.setDelay(this, next);
+ refresh();
+ });
+ TextView test = Ui.row(root);
+ test.setText(R.string.test);
+ test.setOnClickListener(v -> {
+ if (!Launch.open(this)) hero.requestFocus();
+ });
+
+ setContentView(root);
+ hero.requestFocus();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ refresh();
+ }
+
+ private void refresh() {
+ String pkg = Prefs.app(this);
+ hero.removeAllViews();
+ hero.addView(Ui.art(this, pkg, 192, 108));
+ LinearLayout text = new LinearLayout(this);
+ text.setOrientation(LinearLayout.VERTICAL);
+ text.setPadding(Ui.dp(this, 20), 0, 0, 0);
+ TextView name = new TextView(this);
+ name.setText(appName(pkg));
+ name.setTextColor(Color.WHITE);
+ name.setTextSize(TypedValue.COMPLEX_UNIT_SP, 26);
+ name.setSingleLine(true);
+ text.addView(name);
+ TextView sub = new TextView(this);
+ sub.setText(pkg.isEmpty() ? R.string.choose : R.string.change);
+ sub.setTextColor(Ui.ACCENT);
+ sub.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
+ sub.setPadding(0, Ui.dp(this, 4), 0, 0);
+ text.addView(sub);
+ hero.addView(text, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
+
+ enabled.setText(getString(R.string.enabled_state,
+ getString(Prefs.enabled(this) ? R.string.on : R.string.off)));
+ String address = Prefs.link(this);
+ link.setVisibility(address.isEmpty() ? View.GONE : View.VISIBLE);
+ link.setText(getString(R.string.link_state, address));
+ delay.setText(getString(R.string.delay_state, Prefs.delay(this)));
+ }
+
+ private String appName(String pkg) {
+ if (pkg.isEmpty()) return getString(R.string.none);
+ try {
+ return getPackageManager().getApplicationLabel(getPackageManager().getApplicationInfo(pkg, 0)).toString();
+ } catch (PackageManager.NameNotFoundException e) {
+ return getString(R.string.missing, pkg);
+ }
+ }
+}
diff --git a/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/Ui.java b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/Ui.java
new file mode 100644
index 000000000..9e30aa02f
--- /dev/null
+++ b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/Ui.java
@@ -0,0 +1,128 @@
+package io.github.luyzfernando08.wakeapp;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.graphics.Color;
+import android.graphics.Outline;
+import android.graphics.drawable.Drawable;
+import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.StateListDrawable;
+import android.util.TypedValue;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewOutlineProvider;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+/** The two screens share one look: a dark page, soft rounded cards, a teal accent on what is chosen. */
+final class Ui {
+ private Ui() { }
+
+ static final int ACCENT = 0xFF4FB3A9;
+
+ static int dp(Context ctx, int v) {
+ return Math.round(v * ctx.getResources().getDisplayMetrics().density);
+ }
+
+ static LinearLayout page(Context ctx) {
+ LinearLayout root = new LinearLayout(ctx);
+ root.setOrientation(LinearLayout.VERTICAL);
+ root.setGravity(Gravity.CENTER_HORIZONTAL);
+ root.setBackgroundColor(0xFF0B0D12);
+ int pad = dp(ctx, 48);
+ root.setPadding(pad, pad, pad, pad);
+ return root;
+ }
+
+ static void heading(LinearLayout root, int title, int hint) {
+ Context ctx = root.getContext();
+ TextView t = new TextView(ctx);
+ t.setText(title);
+ t.setTextColor(Color.WHITE);
+ t.setTextSize(TypedValue.COMPLEX_UNIT_SP, 34);
+ root.addView(t);
+ TextView h = new TextView(ctx);
+ h.setText(hint);
+ h.setTextColor(0xB3FFFFFF);
+ h.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
+ h.setPadding(0, dp(ctx, 8), 0, dp(ctx, 24));
+ root.addView(h);
+ }
+
+ /** A focusable, rounded background: brighter when focused, with a teal outline when {@code chosen}. */
+ static Drawable card(Context ctx, int radiusDp, boolean chosen) {
+ StateListDrawable bg = new StateListDrawable();
+ bg.addState(new int[]{android.R.attr.state_focused}, shape(ctx, 0x40FFFFFF, radiusDp, chosen));
+ bg.addState(new int[]{}, shape(ctx, 0x14FFFFFF, radiusDp, chosen));
+ return bg;
+ }
+
+ private static GradientDrawable shape(Context ctx, int color, int radiusDp, boolean chosen) {
+ GradientDrawable d = new GradientDrawable();
+ d.setColor(color);
+ d.setCornerRadius(dp(ctx, radiusDp));
+ if (chosen) d.setStroke(dp(ctx, 3), ACCENT);
+ return d;
+ }
+
+ static TextView row(LinearLayout root) {
+ Context ctx = root.getContext();
+ TextView row = new TextView(ctx);
+ row.setTextColor(Color.WHITE);
+ row.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
+ row.setGravity(Gravity.CENTER_VERTICAL);
+ row.setSingleLine(true);
+ row.setPadding(dp(ctx, 24), dp(ctx, 14), dp(ctx, 24), dp(ctx, 14));
+ row.setFocusable(true);
+ row.setClickable(true);
+ row.setBackground(card(ctx, 28, false));
+ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(dp(ctx, 560),
+ LinearLayout.LayoutParams.WRAP_CONTENT);
+ lp.topMargin = dp(ctx, 10);
+ root.addView(row, lp);
+ return row;
+ }
+
+ /** The app's TV banner when it has one, else its icon on a dark tile; rounded either way. */
+ static ImageView art(Context ctx, String pkg, int widthDp, int heightDp) {
+ PackageManager pm = ctx.getPackageManager();
+ Drawable d = null;
+ boolean banner = false;
+ if (pkg != null && !pkg.isEmpty()) {
+ try {
+ Intent main = pm.getLeanbackLaunchIntentForPackage(pkg);
+ ResolveInfo info = main == null ? null : pm.resolveActivity(main, 0);
+ if (info != null) d = info.activityInfo.loadBanner(pm);
+ if (d == null) d = pm.getApplicationBanner(pkg);
+ banner = d != null;
+ if (d == null) d = pm.getApplicationIcon(pkg);
+ } catch (PackageManager.NameNotFoundException e) {
+ d = null;
+ }
+ }
+ ImageView view = new ImageView(ctx);
+ if (d == null) d = ctx.getDrawable(R.drawable.banner);
+ view.setImageDrawable(d);
+ view.setBackgroundColor(0xFF1B1F27);
+ if (banner || pkg == null || pkg.isEmpty()) {
+ view.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ } else {
+ view.setScaleType(ImageView.ScaleType.FIT_CENTER);
+ int pad = dp(ctx, heightDp / 5);
+ view.setPadding(pad, pad, pad, pad);
+ }
+ final float radius = dp(ctx, 12);
+ view.setOutlineProvider(new ViewOutlineProvider() {
+ @Override
+ public void getOutline(View v, Outline outline) {
+ outline.setRoundRect(0, 0, v.getWidth(), v.getHeight(), radius);
+ }
+ });
+ view.setClipToOutline(true);
+ view.setLayoutParams(new LinearLayout.LayoutParams(dp(ctx, widthDp), dp(ctx, heightDp)));
+ return view;
+ }
+}
diff --git a/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/WatchService.java b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/WatchService.java
new file mode 100644
index 000000000..359a648d9
--- /dev/null
+++ b/addons/wake-app/app/src/main/java/io/github/luyzfernando08/wakeapp/WatchService.java
@@ -0,0 +1,97 @@
+package io.github.luyzfernando08.wakeapp;
+
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.Looper;
+import android.os.SystemClock;
+
+/**
+ * Opens the chosen app whenever the screen turns on (the box waking from standby). SCREEN_ON is only delivered
+ * to a receiver registered at run time, so this foreground service keeps one registered; it does nothing else.
+ *
+ * The install script talks to it with extras, since a TV has no keyboard worth typing a link on:
+ * {@code --es app <package>}, {@code --es link <uri>} and {@code --ez test true}.
+ */
+public class WatchService extends Service {
+ static final String EXTRA_BOOT = "boot";
+ private static final String CHANNEL = "watch";
+ /** A screen that flickers on and off must not open the app twice. */
+ private static final long MIN_GAP_MS = 5000;
+ /** After a boot the home screen is still coming up; opening the app first would be covered by it. */
+ private static final long BOOT_EXTRA_MS = 8000;
+
+ private final Handler handler = new Handler(Looper.getMainLooper());
+ private long lastOpen;
+
+ private final Runnable open = new Runnable() {
+ @Override
+ public void run() {
+ long now = SystemClock.elapsedRealtime();
+ if (lastOpen != 0 && now - lastOpen < MIN_GAP_MS) return;
+ lastOpen = now;
+ Launch.open(WatchService.this);
+ }
+ };
+
+ private final BroadcastReceiver screen = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ // Screen off cancels a pending open: the TV was switched off again before the delay ran out.
+ if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) handler.removeCallbacks(open);
+ else schedule(0);
+ }
+ };
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ NotificationManager nm = getSystemService(NotificationManager.class);
+ nm.createNotificationChannel(new NotificationChannel(CHANNEL, getString(R.string.watching),
+ NotificationManager.IMPORTANCE_MIN));
+ Notification notification = new Notification.Builder(this, CHANNEL)
+ .setSmallIcon(android.R.drawable.ic_media_play)
+ .setContentTitle(getString(R.string.watching))
+ .build();
+ startForeground(1, notification);
+ IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
+ filter.addAction(Intent.ACTION_SCREEN_OFF);
+ registerReceiver(screen, filter);
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ if (intent != null) {
+ if (intent.hasExtra("app")) Prefs.setApp(this, intent.getStringExtra("app"));
+ if (intent.hasExtra("link")) Prefs.setLink(this, intent.getStringExtra("link"));
+ if (intent.getBooleanExtra("test", false)) Launch.open(this);
+ else if (intent.getBooleanExtra(EXTRA_BOOT, false)) schedule(BOOT_EXTRA_MS);
+ }
+ return START_STICKY;
+ }
+
+ private void schedule(long extraMs) {
+ if (!Prefs.enabled(this) || Prefs.app(this).isEmpty()) return;
+ handler.removeCallbacks(open);
+ handler.postDelayed(open, Prefs.delay(this) * 1000L + extraMs);
+ }
+
+ @Override
+ public void onDestroy() {
+ handler.removeCallbacks(open);
+ unregisterReceiver(screen);
+ super.onDestroy();
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return null;
+ }
+}
diff --git a/addons/wake-app/app/src/main/res/drawable/banner.xml b/addons/wake-app/app/src/main/res/drawable/banner.xml
new file mode 100644
index 000000000..020580b49
--- /dev/null
+++ b/addons/wake-app/app/src/main/res/drawable/banner.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- A screen with a play triangle and a power ring above it, on a dark tile. -->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="320dp"
+ android:height="180dp"
+ android:viewportWidth="320"
+ android:viewportHeight="180">
+ <path android:fillColor="#15181F" android:pathData="M0,0h320v180h-320z" />
+ <!-- screen -->
+ <path android:fillColor="#2A2F3A" android:pathData="M70,34h180a12,12 0,0 1,12 12v78a12,12 0,0 1,-12 12h-180a12,12 0,0 1,-12 -12v-78a12,12 0,0 1,12 -12z" />
+ <!-- stand -->
+ <path android:fillColor="#2A2F3A" android:pathData="M130,140h60v8h-60z" />
+ <!-- play triangle -->
+ <path android:fillColor="#4FB3A9" android:pathData="M142,64 L142,116 L186,90 Z" />
+ <!-- power ring -->
+ <path android:strokeColor="#4FB3A9" android:strokeWidth="5" android:strokeLineCap="round"
+ android:pathData="M226,60 L226,72 M214,64 A14,14 0,1 0 238,64" />
+</vector>
diff --git a/addons/wake-app/app/src/main/res/values-pt/strings.xml b/addons/wake-app/app/src/main/res/values-pt/strings.xml
new file mode 100644
index 000000000..0daee7918
--- /dev/null
+++ b/addons/wake-app/app/src/main/res/values-pt/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">Abrir ao ligar</string>
+ <string name="watching">Abrindo um app quando a TV liga</string>
+ <string name="hint">Abre o app que você escolher sempre que a tela acende.</string>
+ <string name="enabled_state">Abrir ao ligar: %1$s</string>
+ <string name="link_state">Link: %1$s (OK apaga)</string>
+ <string name="delay_state">Esperar após ligar: %1$d segundos</string>
+ <string name="test">Testar agora</string>
+ <string name="on">ligado</string>
+ <string name="off">desligado</string>
+ <string name="none">nenhum escolhido</string>
+ <string name="choose">OK para escolher um app</string>
+ <string name="change">OK para trocar o app</string>
+ <string name="missing">%1$s (não instalado)</string>
+ <string name="pick_title">Escolha o app</string>
+ <string name="pick_hint">OK escolhe o app. Voltar deixa como estava.</string>
+</resources>
diff --git a/addons/wake-app/app/src/main/res/values/strings.xml b/addons/wake-app/app/src/main/res/values/strings.xml
new file mode 100644
index 000000000..7c3799484
--- /dev/null
+++ b/addons/wake-app/app/src/main/res/values/strings.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+ <string name="app_name">Open on wake</string>
+ <string name="watching">Opening an app when the TV turns on</string>
+ <string name="hint">Opens the app you choose whenever the screen turns on.</string>
+ <string name="enabled_state">Open on wake: %1$s</string>
+ <string name="link_state">Link: %1$s (OK clears it)</string>
+ <string name="delay_state">Wait after waking: %1$d seconds</string>
+ <string name="test">Try it now</string>
+ <string name="on">on</string>
+ <string name="off">off</string>
+ <string name="none">none chosen</string>
+ <string name="choose">OK to choose an app</string>
+ <string name="change">OK to change the app</string>
+ <string name="missing">%1$s (not installed)</string>
+ <string name="pick_title">Choose the app</string>
+ <string name="pick_hint">OK picks the app. Back leaves it as it was.</string>
+</resources>
diff --git a/addons/wake-app/app/src/main/res/xml/module_card.xml b/addons/wake-app/app/src/main/res/xml/module_card.xml
new file mode 100644
index 000000000..0b47a0c01
--- /dev/null
+++ b/addons/wake-app/app/src/main/res/xml/module_card.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="utf-8"?>
+<card spec="1" label="Open on wake" accent="#4FB3A9" />
diff --git a/addons/wake-app/build-and-install.ps1 b/addons/wake-app/build-and-install.ps1
new file mode 100644
index 000000000..58f98f862
--- /dev/null
+++ b/addons/wake-app/build-and-install.ps1
@@ -0,0 +1,53 @@
+# Windows version of build-and-install.sh: build Open on wake, install it on the TV, let it open apps over
+# other apps and start the screen watcher.
+#
+# Usage: addons\wake-app\build-and-install.ps1 -TvHost 192.168.1.50
+# addons\wake-app\build-and-install.ps1 -TvHost 192.168.1.50 -App com.google.android.youtube.tv
+# addons\wake-app\build-and-install.ps1 -TvHost 192.168.1.50 -App com.google.android.youtube.tv -Link 'https://www.youtube.com/watch?v=...'
+# addons\wake-app\build-and-install.ps1 -TvHost 192.168.1.50 -Uninstall
+# -App and -Link set the choice from here; leave them out to pick the app on the TV (the Open on wake card).
+param(
+ [string]$TvHost = $env:TV_HOST,
+ [string]$App,
+ [string]$Link,
+ [switch]$Uninstall
+)
+$ErrorActionPreference = 'Stop'
+if (-not $TvHost) { throw 'pass -TvHost <tv ip> or set $env:TV_HOST' }
+$env:TV_HOST = $TvHost
+$here = $PSScriptRoot
+$tools = Join-Path (Split-Path (Split-Path $here -Parent) -Parent) 'tools'
+$py = Join-Path $tools 'venv\Scripts\python.exe'
+if (-not (Test-Path $py)) { throw 'run: python -m venv tools\venv; tools\venv\Scripts\python.exe -m pip install -r tools\requirements.txt' }
+$pkg = 'io.github.luyzfernando08.wakeapp'
+function Tv([string]$cmd) { & $py -I (Join-Path $tools 'tv.py') $cmd; if ($LASTEXITCODE) { throw "tv.py failed: $cmd" } }
+
+if ($Uninstall) {
+ Tv "pm uninstall $pkg"
+ exit 0
+}
+
+Push-Location $here
+# javac notes go to stderr, which Windows PowerShell 5.1 turns into errors under 'Stop'.
+$ErrorActionPreference = 'Continue'
+try {
+ & .\gradlew.bat assembleRelease -q
+} finally {
+ Pop-Location
+}
+if ($LASTEXITCODE) { throw 'build failed (JDK 17 and Android SDK 34 needed; see launcher\README)' }
+$ErrorActionPreference = 'Stop'
+& $py -I (Join-Path $tools 'b64push.py') (Join-Path $here 'app\build\outputs\apk\release\app-release.apk') /data/local/tmp/wakeapp.apk | Out-Null
+if ($LASTEXITCODE) { throw 'sending the APK failed; run this again' }
+Tv 'pm install -r /data/local/tmp/wakeapp.apk; rm -f /data/local/tmp/wakeapp.apk'
+# Android 10 and later let an app open another from the background only when it may draw over other apps.
+Tv "appops set $pkg SYSTEM_ALERT_WINDOW allow"
+# TCL's TclAppBoot keeps apps from starting at boot unless they may auto-start (AUTO_START on G08 builds,
+# APP_AUTO_START on G10); elsewhere the op doesn't exist. write-settings saves it before the next reboot.
+Tv "appops set $pkg AUTO_START allow 2>/dev/null; appops set $pkg APP_AUTO_START allow 2>/dev/null; appops write-settings 2>/dev/null; true" | Out-Null
+# Starting the watcher once takes the app out of the stopped state, without which Android withholds BOOT_COMPLETED.
+$extras = ''
+if ($App) { $extras += " --es app '$App'" }
+if ($Link) { $extras += " --es link '$Link'" }
+Tv "am start-foreground-service -n $pkg/.WatchService$extras"
+Write-Host 'Installed. Pick the app on the Open on wake card (or pass -App).'
diff --git a/addons/wake-app/build-and-install.sh b/addons/wake-app/build-and-install.sh
new file mode 100755
index 000000000..753dd7762
--- /dev/null
+++ b/addons/wake-app/build-and-install.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+# Build Open on wake, install it on the TV, let it open apps over other apps and start the screen watcher.
+#
+# Usage: TV_HOST=192.168.1.50 addons/wake-app/build-and-install.sh
+# TV_HOST=192.168.1.50 addons/wake-app/build-and-install.sh --app com.google.android.youtube.tv
+# TV_HOST=192.168.1.50 addons/wake-app/build-and-install.sh --app <package> --link '<address>'
+# TV_HOST=192.168.1.50 addons/wake-app/build-and-install.sh --uninstall
+# --app and --link set the choice from here; leave them out to pick the app on the TV (the Open on wake card).
+set -euo pipefail
+HERE="$(cd "$(dirname "$0")" && (pwd -W 2>/dev/null || pwd))"
+TOOLS="$HERE/../../tools"
+: "${TV_HOST:?set TV_HOST to the TV IP address, e.g. TV_HOST=192.168.1.50 $0}"
+PY="$TOOLS/venv/bin/python"
+[ -x "$PY" ] || PY="$TOOLS/venv/Scripts/python.exe"
+[ -x "$PY" ] || { echo "run: python3 -m venv tools/venv && tools/venv/bin/pip install -r tools/requirements.txt" >&2; exit 1; }
+export MSYS_NO_PATHCONV=1
+PKG=io.github.luyzfernando08.wakeapp
+tv() { "$PY" -I "$TOOLS/tv.py" "$@"; }
+
+APP=""
+LINK=""
+while [ $# -gt 0 ]; do
+ case "$1" in
+ --uninstall) tv "pm uninstall $PKG"; exit 0 ;;
+ --app) APP="${2:?--app needs a package name}"; shift 2 ;;
+ --link) LINK="${2:?--link needs an address}"; shift 2 ;;
+ *) echo "unknown option: $1" >&2; exit 1 ;;
+ esac
+done
+
+(cd "$HERE" && ./gradlew assembleRelease -q) || { echo "build failed (JDK 17 and Android SDK 34 needed; see launcher/README)" >&2; exit 1; }
+"$PY" -I "$TOOLS/b64push.py" "$HERE/app/build/outputs/apk/release/app-release.apk" /data/local/tmp/wakeapp.apk >/dev/null
+tv "pm install -r /data/local/tmp/wakeapp.apk; rm -f /data/local/tmp/wakeapp.apk"
+# Android 10 and later let an app open another from the background only when it may draw over other apps.
+tv "appops set $PKG SYSTEM_ALERT_WINDOW allow"
+# TCL's TclAppBoot keeps apps from starting at boot unless they may auto-start (AUTO_START on G08 builds,
+# APP_AUTO_START on G10); elsewhere the op doesn't exist. write-settings saves it before the next reboot.
+tv "appops set $PKG AUTO_START allow 2>/dev/null; appops set $PKG APP_AUTO_START allow 2>/dev/null; appops write-settings 2>/dev/null; true" >/dev/null
+# Starting the watcher once takes the app out of the stopped state, without which Android withholds BOOT_COMPLETED.
+EXTRAS=""
+[ -n "$APP" ] && EXTRAS="$EXTRAS --es app '$APP'"
+[ -n "$LINK" ] && EXTRAS="$EXTRAS --es link '$LINK'"
+tv "am start-foreground-service -n $PKG/.WatchService$EXTRAS"
+echo "Installed. Pick the app on the Open on wake card (or pass --app)."
diff --git a/addons/wake-app/build.gradle b/addons/wake-app/build.gradle
new file mode 100644
index 000000000..48978475f
--- /dev/null
+++ b/addons/wake-app/build.gradle
@@ -0,0 +1,3 @@
+plugins {
+ id 'com.android.application' version '8.5.2' apply false
+}
diff --git a/addons/wake-app/gradle.properties b/addons/wake-app/gradle.properties
new file mode 100644
index 000000000..18825f968
--- /dev/null
+++ b/addons/wake-app/gradle.properties
@@ -0,0 +1,3 @@
+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
+android.useAndroidX=true
+android.nonTransitiveRClass=true
diff --git a/addons/wake-app/gradlew b/addons/wake-app/gradlew
new file mode 100755
index 000000000..fbcfb4bcb
--- /dev/null
+++ b/addons/wake-app/gradlew
@@ -0,0 +1,4 @@
+#!/bin/sh
+# Reuse the repository's pinned Gradle distribution, but build this independent project.
+addon_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) || exit 1
+exec sh "$addon_dir/../../launcher/gradlew" -p "$addon_dir" "$@"
diff --git a/addons/wake-app/gradlew.bat b/addons/wake-app/gradlew.bat
new file mode 100644
index 000000000..42f222173
--- /dev/null
+++ b/addons/wake-app/gradlew.bat
@@ -0,0 +1,3 @@
+@echo off
+rem Reuse the repository wrapper; this add-on remains its own Gradle project.
+call "%~dp0..\..\launcher\gradlew.bat" -p "%~dp0." %*
diff --git a/addons/wake-app/screenshot.jpg b/addons/wake-app/screenshot.jpg
new file mode 100644
index 000000000..162a6b33b
Binary files /dev/null and b/addons/wake-app/screenshot.jpg differ
diff --git a/addons/wake-app/settings.gradle b/addons/wake-app/settings.gradle
new file mode 100644
index 000000000..aa95f434c
--- /dev/null
+++ b/addons/wake-app/settings.gradle
@@ -0,0 +1,16 @@
+pluginManagement {
+ repositories {
+ google()
+ mavenCentral()
+ gradlePluginPortal()
+ }
+}
+dependencyResolutionManagement {
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
+ repositories {
+ google()
+ mavenCentral()
+ }
+}
+rootProject.name = "wakeapp"
+include ':app'