Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
addons: TV Static, an off-the-air moment each time the screen turns on
Luiz Fernandocfdd0f7f7990
diff --git a/addons/README.md b/addons/README.mdindex 7136a318a..002553a11 100644--- a/addons/README.md+++ b/addons/README.md@@ -15,6 +15,7 @@ the core bigger or change how it behaves. You install an add-on only if you want| [Photo Prints](photo-prints/) | Your own photos as a screensaver: dated prints dealt in on a time-of-day sky, and a card that starts the slideshow | [@shivamsingh262](https://github.com/shivamsingh262) | Sony BRAVIA KD-65X82L (Google TV 12) | None || [Photo screensaver](photo-screensaver/) | Your own pictures and MP4 clips as the TV's screensaver and as a card, slowly zooming and crossfading (20 s each by default); optional time, photo dates, prints on a sky and weather | [JorickGU](https://github.com/JorickGU) | TCL 43P69K (Google TV 12) | `INTERNET` and coarse location, only with the weather option on || [Prayer Times](prayer-times/) | Today's prayer times for one city from Aladhan (no key), the next prayer with a countdown, Gregorian and Hijri dates | [@majnioui](https://github.com/majnioui) | Xiaomi TV (MiTV-MOOR2), Google TV 11 | `INTERNET` |+| [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 for 3 to 10 s, then fades into what was on screen; the card sets 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 |A widget, an info tile, a storage or smart-home card: if it can live as its own small app, it can livehere. See the rules below.diff --git a/addons/tv-static/.gitignore b/addons/tv-static/.gitignorenew file mode 100644index 000000000..875cd7fd6--- /dev/null+++ b/addons/tv-static/.gitignore@@ -0,0 +1,3 @@+app/build/+.gradle/+build/diff --git a/addons/tv-static/README.md b/addons/tv-static/README.mdnew file mode 100644index 000000000..549262688--- /dev/null+++ b/addons/tv-static/README.md@@ -0,0 +1,74 @@+# TV Static++An old set coming on, every time the screen turns on: the picture opens out of a bright line like a picture+tube warming up, then snow and hiss as if the set were off the air, and after a few seconds it fades into+whatever was on screen. Any key ends it at once and is not passed on. Separate from the launcher.++Package `io.github.luyzfernando08.tvstatic`. You see it as **TV Static** (Portuguese: **Chiado**). On+cleanyourtv's Home it is also a module card, **TV Static**, which opens its settings.++## Settings++Open the card (or the app's own tile). OK on a row changes it:++| Setting | Choices |+|---|---|+| Effect on wake | on (default), off |+| Sound | on (default), muted |+| Length | 3 s (default), 5 s, 10 s |+| Try it now | plays it once |++A TV with Android built in shows a picture as soon as it wakes, and 3 seconds is plenty. A box behind HDMI is+different: its screen turns on before the TV has switched itself on and over to that input. On a Mi Box S+the TV only showed a picture about seven seconds after the box woke, so there 10 seconds is the setting that+shows a few seconds of snow.++Nothing plays when the screen turns *off*: by the time an app hears of it the screen is already dark, and+the power key goes to the system first.++## 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/tv-static/build-and-install.sh # plays it once when done+TV_HOST=192.168.1.50 addons/tv-static/build-and-install.sh --no-play # someone is watching+TV_HOST=192.168.1.50 addons/tv-static/build-and-install.sh --uninstall+```++```powershell+powershell -ExecutionPolicy Bypass -File addons\tv-static\build-and-install.ps1 -TvHost 192.168.1.50 [-NoPlay] [-Uninstall]+```++Then press Home and answer **Show card** if you want the card; Keep hidden leaves an ordinary app tile.++## Memory++The snow is a 240x135 bitmap refilled each frame and stretched over the screen without smoothing, so the+dots stay hard blocks. The hiss is generated white noise in one static `AudioTrack` buffer (about 130 KB at+10 seconds). The watcher service, which stays up, used about 8 MB on a Mi Box S.++## Permissions++- **Foreground service** (`FOREGROUND_SERVICE`, `FOREGROUND_SERVICE_SPECIAL_USE`): `WatchService` keeps one+ receiver for `SCREEN_ON` registered, which Android delivers only to receivers registered at run time, never+ from the manifest. It does nothing else: no polling, no timer, 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 play the+ effect 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 open a screen from the background when it holds this. The app draws no overlay+ window; it only opens its own full-screen activity.+- 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 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 2.6: the effect with sound on waking+ from standby with the real remote (at 10 seconds, see above), the card prompt and the card, the settings+ screen and Try it now.+- Philco Smart TV by Skyworth (sunnyvale, MediaTek, Android TV 14): the effect on waking from standby with the+ real remote, which needs the display-over-other-apps grant.diff --git a/addons/tv-static/app/build.gradle b/addons/tv-static/app/build.gradlenew file mode 100644index 000000000..bf60b9aa6--- /dev/null+++ b/addons/tv-static/app/build.gradle@@ -0,0 +1,30 @@+plugins {+ id 'com.android.application'+}++android {+ namespace 'io.github.luyzfernando08.tvstatic'+ compileSdk 34++ defaultConfig {+ applicationId 'io.github.luyzfernando08.tvstatic'+ 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/tv-static/app/src/main/AndroidManifest.xml b/addons/tv-static/app/src/main/AndroidManifest.xmlnew file mode 100644index 000000000..98cf9da99--- /dev/null+++ b/addons/tv-static/app/src/main/AndroidManifest.xml@@ -0,0 +1,67 @@+<?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 a screen 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" />++ <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>++ <!-- The "off the air" screen: translucent, so the picture underneath shows through as it fades out. -->+ <activity+ android:name=".StaticActivity"+ android:exported="false"+ android:excludeFromRecents="true"+ android:launchMode="singleInstance"+ android:noHistory="true"+ android:screenOrientation="landscape"+ android:theme="@style/Static" />++ <!-- 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="Plays a short static effect 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/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/BootReceiver.java b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/BootReceiver.javanew file mode 100644index 000000000..2525e41bf--- /dev/null+++ b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/BootReceiver.java@@ -0,0 +1,15 @@+package io.github.luyzfernando08.tvstatic;++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 play the effect 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_PLAY, true);+ context.startForegroundService(watch);+ }+}diff --git a/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/Prefs.java b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/Prefs.javanew file mode 100644index 000000000..a8c9b8610--- /dev/null+++ b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/Prefs.java@@ -0,0 +1,40 @@+package io.github.luyzfernando08.tvstatic;++import android.content.Context;+import android.content.SharedPreferences;++/** The choices made on the settings screen. */+final class Prefs {+ private Prefs() { }++ /** A box behind HDMI can take several seconds to show a picture after waking; 10 s covers that. */+ static final int[] SECONDS = {3, 5, 10};++ 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 boolean sound(Context ctx) {+ return prefs(ctx).getBoolean("sound", true);+ }++ static int seconds(Context ctx) {+ return prefs(ctx).getInt("seconds", 3);+ }++ static void setEnabled(Context ctx, boolean value) {+ prefs(ctx).edit().putBoolean("enabled", value).apply();+ }++ static void setSound(Context ctx, boolean value) {+ prefs(ctx).edit().putBoolean("sound", value).apply();+ }++ static void setSeconds(Context ctx, int value) {+ prefs(ctx).edit().putInt("seconds", value).apply();+ }+}diff --git a/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/SettingsActivity.java b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/SettingsActivity.javanew file mode 100644index 000000000..5cb353d74--- /dev/null+++ b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/SettingsActivity.java@@ -0,0 +1,107 @@+package io.github.luyzfernando08.tvstatic;++import android.app.Activity;+import android.content.Intent;+import android.graphics.Color;+import android.graphics.drawable.GradientDrawable;+import android.graphics.drawable.StateListDrawable;+import android.os.Bundle;+import android.util.TypedValue;+import android.view.Gravity;+import android.widget.LinearLayout;+import android.widget.TextView;++/**+ * The module card on the launcher's Home (and the app's own tile): switch the effect on or off, with or+ * without sound, how long it runs, and a button to try it now. Each row changes its value on OK.+ */+public class SettingsActivity extends Activity {+ private TextView enabled, sound, seconds;++ @Override+ protected void onCreate(Bundle savedInstanceState) {+ super.onCreate(savedInstanceState);+ LinearLayout root = new LinearLayout(this);+ root.setOrientation(LinearLayout.VERTICAL);+ root.setGravity(Gravity.CENTER_HORIZONTAL);+ root.setBackgroundColor(0xFF0B0D12);+ int pad = dp(48);+ root.setPadding(pad, pad, pad, pad);++ TextView title = new TextView(this);+ title.setText(R.string.app_name);+ title.setTextColor(Color.WHITE);+ title.setTextSize(TypedValue.COMPLEX_UNIT_SP, 34);+ root.addView(title);+ TextView hint = new TextView(this);+ hint.setText(R.string.hint);+ hint.setTextColor(0xB3FFFFFF);+ hint.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);+ hint.setPadding(0, dp(8), 0, dp(28));+ root.addView(hint);++ enabled = row(root);+ enabled.setOnClickListener(v -> {+ Prefs.setEnabled(this, !Prefs.enabled(this));+ refresh();+ });+ sound = row(root);+ sound.setOnClickListener(v -> {+ Prefs.setSound(this, !Prefs.sound(this));+ refresh();+ });+ seconds = row(root);+ seconds.setOnClickListener(v -> {+ int now = Prefs.seconds(this), next = Prefs.SECONDS[0];+ for (int i = 0; i < Prefs.SECONDS.length - 1; i++) {+ if (Prefs.SECONDS[i] == now) next = Prefs.SECONDS[i + 1];+ }+ Prefs.setSeconds(this, next);+ refresh();+ });+ TextView test = row(root);+ test.setText(R.string.test);+ test.setOnClickListener(v -> startActivity(new Intent(this, StaticActivity.class)));++ setContentView(root);+ refresh();+ enabled.requestFocus();+ }++ private void refresh() {+ enabled.setText(getString(R.string.enabled_state,+ getString(Prefs.enabled(this) ? R.string.on : R.string.off)));+ sound.setText(getString(R.string.sound_state,+ getString(Prefs.sound(this) ? R.string.with_sound : R.string.without_sound)));+ seconds.setText(getString(R.string.seconds_state, Prefs.seconds(this)));+ }++ private TextView row(LinearLayout root) {+ TextView row = new TextView(this);+ row.setTextColor(Color.WHITE);+ row.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);+ row.setGravity(Gravity.CENTER_VERTICAL);+ row.setPadding(dp(24), dp(14), dp(24), dp(14));+ row.setFocusable(true);+ row.setClickable(true);+ StateListDrawable bg = new StateListDrawable();+ bg.addState(new int[]{android.R.attr.state_focused}, pill(0x40FFFFFF));+ bg.addState(new int[]{}, pill(0x14FFFFFF));+ row.setBackground(bg);+ LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(dp(560), LinearLayout.LayoutParams.WRAP_CONTENT);+ lp.topMargin = dp(10);+ root.addView(row, lp);+ return row;+ }++ private GradientDrawable pill(int color) {+ GradientDrawable d = new GradientDrawable();+ d.setColor(color);+ d.setCornerRadius(dp(28));+ return d;+ }++ private int dp(int v) {+ return Math.round(v * getResources().getDisplayMetrics().density);+ }+}diff --git a/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/StaticActivity.java b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/StaticActivity.javanew file mode 100644index 000000000..aebb32d9c--- /dev/null+++ b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/StaticActivity.java@@ -0,0 +1,89 @@+package io.github.luyzfernando08.tvstatic;++import android.app.Activity;+import android.media.AudioAttributes;+import android.media.AudioFormat;+import android.media.AudioTrack;+import android.os.Bundle;+import android.view.KeyEvent;+import android.view.View;++/** "Off the air": the tube opens, snow and hiss for a moment, then the picture underneath fades in. */+public class StaticActivity extends Activity {+ private static final int RATE = 22050;+ private AudioTrack hiss;++ @Override+ protected void onCreate(Bundle savedInstanceState) {+ super.onCreate(savedInstanceState);+ StaticView view = new StaticView(this, Prefs.seconds(this), this::finish);+ view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION+ | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);+ setContentView(view);+ hiss = Prefs.sound(this) ? makeHiss(view.snowMs) : null;+ if (hiss != null) view.postDelayed(() -> {+ if (hiss != null) hiss.play();+ }, StaticView.OPEN_MS);+ }++ /** White noise for the snow's length, shaped so it starts and dies away with the picture. */+ private static AudioTrack makeHiss(int snowMs) {+ int samples = RATE * (snowMs + StaticView.FADE_MS) / 1000;+ short[] pcm = new short[samples];+ int fadeIn = RATE / 20, fadeOut = RATE * StaticView.FADE_MS / 1000;+ long seed = System.nanoTime() | 1;+ for (int i = 0; i < samples; i++) {+ seed ^= seed << 13;+ seed ^= seed >>> 7;+ seed ^= seed << 17;+ float gain = 0.3f;+ if (i < fadeIn) gain *= i / (float) fadeIn;+ if (i > samples - fadeOut) gain *= (samples - i) / (float) fadeOut;+ pcm[i] = (short) ((int) seed * gain / 65536f);+ }+ try {+ AudioTrack track = new AudioTrack.Builder()+ .setAudioAttributes(new AudioAttributes.Builder()+ .setUsage(AudioAttributes.USAGE_MEDIA)+ .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build())+ .setAudioFormat(new AudioFormat.Builder().setSampleRate(RATE)+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)+ .setChannelMask(AudioFormat.CHANNEL_OUT_MONO).build())+ .setTransferMode(AudioTrack.MODE_STATIC)+ .setBufferSizeInBytes(samples * 2)+ .build();+ track.write(pcm, 0, samples);+ return track;+ } catch (RuntimeException e) {+ return null; // no sound is fine; the picture still plays+ }+ }++ /** Any key ends it at once, and is not passed on. */+ @Override+ public boolean onKeyDown(int keyCode, KeyEvent event) {+ finish();+ return true;+ }++ @Override+ public void finish() {+ super.finish();+ overridePendingTransition(0, 0);+ }++ @Override+ protected void onPause() {+ super.onPause();+ if (!isFinishing()) finish();+ }++ @Override+ protected void onDestroy() {+ if (hiss != null) {+ hiss.release();+ hiss = null;+ }+ super.onDestroy();+ }+}diff --git a/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/StaticView.java b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/StaticView.javanew file mode 100644index 000000000..fa4411ae8--- /dev/null+++ b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/StaticView.java@@ -0,0 +1,94 @@+package io.github.luyzfernando08.tvstatic;++import android.content.Context;+import android.graphics.Bitmap;+import android.graphics.Canvas;+import android.graphics.Color;+import android.graphics.Paint;+import android.graphics.Rect;+import android.os.SystemClock;+import android.view.View;++/**+ * Snow drawn into a small bitmap and stretched over the screen without smoothing, so each dot stays a hard+ * block like an analogue set's. Timeline: the tube opens from a bright line, snow with a slow rolling band,+ * then the snow fades and the window, translucent, shows what is underneath.+ */+class StaticView extends View {+ static final int OPEN_MS = 300;+ static final int FADE_MS = 500;+ private static final int W = 240, H = 135;++ /** Snow time: the chosen length less the opening and the fade. */+ final int snowMs;+ private final Runnable done;+ private final Bitmap snow = Bitmap.createBitmap(W, H, Bitmap.Config.ARGB_8888);+ private final int[] pixels = new int[W * H];+ private final Paint paint = new Paint();+ private final Paint fill = new Paint();+ private final Rect dst = new Rect();+ private long start;+ private long seed = System.nanoTime() | 1;+ private boolean finished;++ StaticView(Context context, int seconds, Runnable done) {+ super(context);+ snowMs = Math.max(500, seconds * 1000 - OPEN_MS - FADE_MS);+ this.done = done;+ paint.setFilterBitmap(false);+ }++ private int next() {+ seed ^= seed << 13;+ seed ^= seed >>> 7;+ seed ^= seed << 17;+ return (int) seed;+ }++ private void fillSnow(long t) {+ // A darker band rolls slowly down the picture, as when the vertical hold drifts.+ int band = (int) ((t / 6) % (H + 30)) - 30;+ for (int y = 0; y < H; y++) {+ boolean inBand = y >= band && y < band + 18;+ int row = y * W;+ for (int x = 0; x < W; x++) {+ int v = next() & 0xFF;+ if (inBand) v = v * 3 / 5;+ pixels[row + x] = 0xFF000000 | v << 16 | v << 8 | v;+ }+ }+ snow.setPixels(pixels, 0, W, 0, 0, W, H);+ }++ @Override+ protected void onDraw(Canvas canvas) {+ if (start == 0) start = SystemClock.uptimeMillis();+ long t = SystemClock.uptimeMillis() - start;+ int w = getWidth(), h = getHeight();+ if (t >= OPEN_MS + snowMs + FADE_MS) {+ if (!finished) {+ finished = true;+ done.run();+ }+ return;+ }+ fillSnow(t);+ if (t < OPEN_MS) {+ // The tube opens: black, a bright line across the middle that grows into the picture.+ canvas.drawColor(Color.BLACK);+ float k = t / (float) OPEN_MS;+ int half = Math.max(2, (int) (h / 2f * k * k));+ dst.set(0, h / 2 - half, w, h / 2 + half);+ canvas.drawBitmap(snow, null, dst, paint);+ fill.setColor(Color.argb((int) (220 * (1 - k)), 255, 255, 255));+ canvas.drawRect(dst, fill);+ } else {+ int alpha = 255;+ if (t > OPEN_MS + snowMs) alpha = (int) (255 * (1 - (t - OPEN_MS - snowMs) / (float) FADE_MS));+ paint.setAlpha(alpha);+ dst.set(0, 0, w, h);+ canvas.drawBitmap(snow, null, dst, paint);+ }+ postInvalidateOnAnimation();+ }+}diff --git a/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/WatchService.java b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/WatchService.javanew file mode 100644index 000000000..c7de0b9d8--- /dev/null+++ b/addons/tv-static/app/src/main/java/io/github/luyzfernando08/tvstatic/WatchService.java@@ -0,0 +1,71 @@+package io.github.luyzfernando08.tvstatic;++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.IBinder;+import android.os.SystemClock;++/**+ * Plays the static 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.+ */+public class WatchService extends Service {+ static final String EXTRA_PLAY = "play";+ private static final String CHANNEL = "watch";+ /** A screen that flickers on and off must not replay the effect over itself. */+ private static final long MIN_GAP_MS = 5000;++ private long lastPlay;++ private final BroadcastReceiver screenOn = new BroadcastReceiver() {+ @Override+ public void onReceive(Context context, Intent intent) {+ play();+ }+ };++ @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);+ registerReceiver(screenOn, new IntentFilter(Intent.ACTION_SCREEN_ON));+ }++ @Override+ public int onStartCommand(Intent intent, int flags, int startId) {+ if (intent != null && intent.getBooleanExtra(EXTRA_PLAY, false)) play();+ return START_STICKY;+ }++ private void play() {+ if (!Prefs.enabled(this)) return;+ long now = SystemClock.elapsedRealtime();+ if (lastPlay != 0 && now - lastPlay < MIN_GAP_MS) return;+ lastPlay = now;+ startActivity(new Intent(this, StaticActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));+ }++ @Override+ public void onDestroy() {+ unregisterReceiver(screenOn);+ super.onDestroy();+ }++ @Override+ public IBinder onBind(Intent intent) {+ return null;+ }+}diff --git a/addons/tv-static/app/src/main/res/drawable/banner.xml b/addons/tv-static/app/src/main/res/drawable/banner.xmlnew file mode 100644index 000000000..2026443d3--- /dev/null+++ b/addons/tv-static/app/src/main/res/drawable/banner.xml@@ -0,0 +1,26 @@+<?xml version="1.0" encoding="utf-8"?>+<!-- An old set showing snow: grey bars of different shades inside a rounded screen, 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" />+ <!-- antennas -->+ <path android:strokeColor="#9AA4B2" android:strokeWidth="4" android:strokeLineCap="round"+ android:pathData="M160,38 L130,12 M160,38 L190,12" />+ <!-- cabinet -->+ <path android:fillColor="#2A2F3A" android:pathData="M88,38h144a14,14 0,0 1,14 14v96a14,14 0,0 1,-14 14h-144a14,14 0,0 1,-14 -14v-96a14,14 0,0 1,14 -14z" />+ <!-- screen with snow bars -->+ <path android:fillColor="#5D6470" android:pathData="M96,50h110v12h-110z" />+ <path android:fillColor="#C9CED6" android:pathData="M96,62h110v10h-110z" />+ <path android:fillColor="#7C8390" android:pathData="M96,72h110v14h-110z" />+ <path android:fillColor="#E8EBEF" android:pathData="M96,86h110v8h-110z" />+ <path android:fillColor="#3E434D" android:pathData="M96,94h110v12h-110z" />+ <path android:fillColor="#A9AFB9" android:pathData="M96,106h110v12h-110z" />+ <path android:fillColor="#6B717D" android:pathData="M96,118h110v14h-110z" />+ <path android:fillColor="#D7DBE1" android:pathData="M96,132h110v18h-110z" />+ <!-- knobs -->+ <path android:fillColor="#9AA4B2" android:pathData="M226,70m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0" />+ <path android:fillColor="#9AA4B2" android:pathData="M226,100m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0" />+</vector>diff --git a/addons/tv-static/app/src/main/res/values-pt/strings.xml b/addons/tv-static/app/src/main/res/values-pt/strings.xmlnew file mode 100644index 000000000..97fc339ae--- /dev/null+++ b/addons/tv-static/app/src/main/res/values-pt/strings.xml@@ -0,0 +1,14 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <string name="app_name">Chiado</string>+ <string name="watching">Chiado ao ligar a TV</string>+ <string name="hint">TV fora do ar sempre que a tela acende. Qualquer tecla corta o efeito.</string>+ <string name="enabled_state">Efeito ao ligar: %1$s</string>+ <string name="sound_state">Som: %1$s</string>+ <string name="seconds_state">Duração: %1$d segundos</string>+ <string name="test">Testar agora</string>+ <string name="on">ligado</string>+ <string name="off">desligado</string>+ <string name="with_sound">com som</string>+ <string name="without_sound">sem som</string>+</resources>diff --git a/addons/tv-static/app/src/main/res/values/values.xml b/addons/tv-static/app/src/main/res/values/values.xmlnew file mode 100644index 000000000..434c4ee72--- /dev/null+++ b/addons/tv-static/app/src/main/res/values/values.xml@@ -0,0 +1,22 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <string name="app_name">TV Static</string>+ <string name="watching">Static when the TV turns on</string>+ <string name="hint">An off-the-air screen whenever the screen turns on. Any key ends it.</string>+ <string name="enabled_state">Effect on wake: %1$s</string>+ <string name="sound_state">Sound: %1$s</string>+ <string name="seconds_state">Length: %1$d seconds</string>+ <string name="test">Try it now</string>+ <string name="on">on</string>+ <string name="off">off</string>+ <string name="with_sound">on</string>+ <string name="without_sound">muted</string>++ <style name="Static" parent="android:Theme.DeviceDefault.NoActionBar.Fullscreen">+ <item name="android:windowIsTranslucent">true</item>+ <item name="android:windowBackground">@android:color/transparent</item>+ <item name="android:windowAnimationStyle">@null</item>+ <item name="android:windowNoTitle">true</item>+ <item name="android:backgroundDimEnabled">false</item>+ </style>+</resources>diff --git a/addons/tv-static/app/src/main/res/xml/module_card.xml b/addons/tv-static/app/src/main/res/xml/module_card.xmlnew file mode 100644index 000000000..96366e58d--- /dev/null+++ b/addons/tv-static/app/src/main/res/xml/module_card.xml@@ -0,0 +1,2 @@+<?xml version="1.0" encoding="utf-8"?>+<card spec="1" label="TV Static" accent="#9AA4B2" />diff --git a/addons/tv-static/build-and-install.ps1 b/addons/tv-static/build-and-install.ps1new file mode 100644index 000000000..29bbd9c48--- /dev/null+++ b/addons/tv-static/build-and-install.ps1@@ -0,0 +1,46 @@+# Windows version of build-and-install.sh: build TV Static, install it on the TV, let it open over other apps+# and start the screen watcher, which plays the effect once so you can see it.+#+# Usage: addons\tv-static\build-and-install.ps1 -TvHost 192.168.1.50+# addons\tv-static\build-and-install.ps1 -TvHost 192.168.1.50 -NoPlay # install without playing it now+# addons\tv-static\build-and-install.ps1 -TvHost 192.168.1.50 -Uninstall+param(+ [string]$TvHost = $env:TV_HOST,+ [switch]$NoPlay,+ [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.tvstatic'+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/tvstatic.apk | Out-Null+if ($LASTEXITCODE) { throw 'sending the APK failed; run this again' }+Tv 'pm install -r /data/local/tmp/tvstatic.apk; rm -f /data/local/tmp/tvstatic.apk'+# Android 10 and later let an app open a screen 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; elsewhere the op doesn't exist.+Tv "appops set $pkg APP_AUTO_START allow 2>/dev/null; true" | Out-Null+# Starting the watcher once takes the app out of the stopped state, without which Android withholds BOOT_COMPLETED.+Tv "am start-foreground-service -n $pkg/.WatchService --ez play $(if ($NoPlay) { 'false' } else { 'true' })"+Write-Host 'Installed. The static plays whenever the screen turns on; its settings are on the TV Static card.'diff --git a/addons/tv-static/build-and-install.sh b/addons/tv-static/build-and-install.shnew file mode 100755index 000000000..e690496cb--- /dev/null+++ b/addons/tv-static/build-and-install.sh@@ -0,0 +1,35 @@+#!/usr/bin/env bash+# Build TV Static, install it on the TV, let it open over other apps and start the screen watcher, which plays+# the effect once so you can see it.+#+# Usage: TV_HOST=192.168.1.50 addons/tv-static/build-and-install.sh+# TV_HOST=192.168.1.50 addons/tv-static/build-and-install.sh --no-play # install without playing it now+# TV_HOST=192.168.1.50 addons/tv-static/build-and-install.sh --uninstall+set -euo pipefail+HERE="$(cd "$(dirname "$0")" && 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.tvstatic+tv() { "$PY" -I "$TOOLS/tv.py" "$@"; }++if [ "${1:-}" = --uninstall ]; then+ tv "pm uninstall $PKG"+ exit 0+fi+PLAY=true+[ "${1:-}" = --no-play ] && PLAY=false++(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/tvstatic.apk >/dev/null+tv "pm install -r /data/local/tmp/tvstatic.apk; rm -f /data/local/tmp/tvstatic.apk"+# Android 10 and later let an app open a screen 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; elsewhere the op doesn't exist.+tv "appops set $PKG APP_AUTO_START allow 2>/dev/null; true" >/dev/null+# Starting the watcher once takes the app out of the stopped state, without which Android withholds BOOT_COMPLETED.+tv "am start-foreground-service -n $PKG/.WatchService --ez play $PLAY"+echo "Installed. The static plays whenever the screen turns on; its settings are on the TV Static card."diff --git a/addons/tv-static/build.gradle b/addons/tv-static/build.gradlenew file mode 100644index 000000000..48978475f--- /dev/null+++ b/addons/tv-static/build.gradle@@ -0,0 +1,3 @@+plugins {+ id 'com.android.application' version '8.5.2' apply false+}diff --git a/addons/tv-static/gradle.properties b/addons/tv-static/gradle.propertiesnew file mode 100644index 000000000..18825f968--- /dev/null+++ b/addons/tv-static/gradle.properties@@ -0,0 +1,3 @@+org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8+android.useAndroidX=true+android.nonTransitiveRClass=truediff --git a/addons/tv-static/gradlew b/addons/tv-static/gradlewnew file mode 100755index 000000000..fbcfb4bcb--- /dev/null+++ b/addons/tv-static/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/tv-static/gradlew.bat b/addons/tv-static/gradlew.batnew file mode 100644index 000000000..42f222173--- /dev/null+++ b/addons/tv-static/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/tv-static/settings.gradle b/addons/tv-static/settings.gradlenew file mode 100644index 000000000..8d42f2b25--- /dev/null+++ b/addons/tv-static/settings.gradle@@ -0,0 +1,16 @@+pluginManagement {+ repositories {+ google()+ mavenCentral()+ gradlePluginPortal()+ }+}+dependencyResolutionManagement {+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)+ repositories {+ google()+ mavenCentral()+ }+}+rootProject.name = "tvstatic"+include ':app'