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
feat(themes): rotate local wallpaper collections
Hari Haranb2a1208e18e3
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.javaindex 8a5547988..c36df63aa 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java@@ -74,8 +74,14 @@ final class Config {final int[] settingsKeycodes;/** The Settings button opens the quick settings panel instead of the TV's Settings (settings_key_panel). */final boolean settingsKeyPanel;+ /** Whether themes may show a wallpaper (config.json, wallpaper). */+ final boolean wallpaperEnabled;/** Full-screen picture behind the launcher, or null for the plain colour. */final File wallpaper;+ /** Rotating theme images, or the single wallpaper when no collection is configured. */+ final List<File> wallpapers;+ final int wallpaperRotationMinutes;+ final int wallpaperDim;/** Whether the overlay file was present and parsed. */final boolean overlayApplied;/** Festive skin from a theme (festival, festival_until, greeting, accent_color); {@link Festival#NONE} if none. */@@ -86,7 +92,8 @@ final class Config {int columns, int rowsBelowDock, boolean animations, boolean advancedEffects,boolean shamsiDate, String greetingName, boolean moduleCards, boolean reducedMotion, boolean dockTitle, boolean dockRow, boolean reorderButton, String vpnApp,boolean showHomeSettingsShortcut, boolean showStats, boolean appLibrary, int backgroundColor, int skyIntensity,- int[] settingsKeycodes, boolean settingsKeyPanel, File wallpaper, boolean overlayApplied,+ int[] settingsKeycodes, boolean settingsKeyPanel, boolean wallpaperEnabled, File wallpaper, List<File> wallpapers,+ int wallpaperRotationMinutes, int wallpaperDim, boolean overlayApplied,Festival festival) {this.dockApps = Collections.unmodifiableList(dockApps);this.fillDock = fillDock;@@ -115,7 +122,11 @@ final class Config {this.skyIntensity = skyIntensity;this.settingsKeycodes = settingsKeycodes;this.settingsKeyPanel = settingsKeyPanel;+ this.wallpaperEnabled = wallpaperEnabled;this.wallpaper = wallpaper;+ this.wallpapers = Collections.unmodifiableList(wallpapers);+ this.wallpaperRotationMinutes = wallpaperRotationMinutes;+ this.wallpaperDim = wallpaperDim;this.overlayApplied = overlayApplied;this.festival = festival;}@@ -200,7 +211,15 @@ final class Config {File wallpaper = dir != null ? new File(dir, WALLPAPER_NAME) : null;if (wallpaper != null && !(wallpaper.isFile() && wallpaper.length() > 0)) wallpaper = null;// A theme can also switch the wallpaper off while the file is still there.- if (json != null && json.has("wallpaper") && !bool(json, "wallpaper", true)) wallpaper = null;+ boolean wallpaperEnabled = json == null || bool(json, "wallpaper", true);+ if (!wallpaperEnabled) wallpaper = null;+ int rotationMinutes = json == null ? 0 : integer(json, "wallpaper_rotation_minutes", 0, 0, 1440);+ int wallpaperDim = json == null ? 0 : integer(json, "wallpaper_dim", 0, 0, 90);+ List<File> wallpapers = new ArrayList<>();+ if (rotationMinutes > 0 && dir != null && wallpaperEnabled) {+ wallpapers.addAll(WallpaperRotation.images(new File(dir, "wallpapers")));+ }+ if (wallpapers.isEmpty() && wallpaper != null) wallpapers.add(wallpaper);// A festive skin comes only from a theme; config.xml has no festival.Festival festival = json == null ? Festival.NONE : Festival.parse(string(json, "festival", ""),string(json, "festival_until", ""), string(json, "greeting", ""), string(json, "accent_color", ""));@@ -208,7 +227,8 @@ final class Config {return new Config(dock, fillDock, hidden, liveTv, liveTvAction, panelService, panelAction, inputAction,Math.max(1, columns), Math.max(0, rowsBelow), animations, advancedEffects,shamsi, greetingName, moduleCards, reducedMotion, dockTitle, dockRow, reorderButton, vpn, homeSettings, showStats, library, background,- Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, wallpaper, applied,+ Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, wallpaperEnabled, wallpaper,+ wallpapers, rotationMinutes, wallpaperDim, applied,festival);}diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.javaindex 1e5ef141b..7bf8b685e 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java@@ -99,6 +99,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {private AppAdapter adapter;private RecyclerView grid;private FrameLayout root;+ private WallpaperPlayer wallpaperPlayer;private GlassView glass;private View ambient;private TextView heroName;@@ -231,6 +232,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {updateGreeting();updateWifiLabel();sky.update();+ wallpaperPlayer.update();handler.postDelayed(this, MINUTE_MS);}};@@ -259,7 +261,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {root = findViewById(R.id.root);root.setBackgroundColor(cfg.backgroundColor);- if (cfg.wallpaper != null) showWallpaper(cfg.wallpaper);+ wallpaperPlayer = new WallpaperPlayer(this, root, cfg);sky = findViewById(R.id.sky);sky.setIntensity(cfg.skyIntensity);glass = findViewById(R.id.glass);@@ -501,42 +503,6 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {return true;}- /**- * A theme's full-screen picture behind everything. Decoded once at the size CENTER_CROP shows, so it- * costs a screen-sized bitmap (about 4 MB at 1080p), which is the price of a wallpaper on a 1 GB TV.- * A picture over 4K is refused rather than decoded (#166); the plain colour stays.- */- private void showWallpaper(File file) {- try {- android.util.DisplayMetrics dm = getResources().getDisplayMetrics();- android.graphics.BitmapFactory.Options opts = new android.graphics.BitmapFactory.Options();- opts.inJustDecodeBounds = true;- android.graphics.BitmapFactory.decodeFile(file.getPath(), opts);- int w = opts.outWidth, h = opts.outHeight;- if (w <= 0 || h <= 0) return;- int sample = WallpaperSize.sampleSize(w, h, dm.widthPixels, dm.heightPixels);- // The limit applies to what is decoded, so a 12 MP photo still works once it is sampled down.- if (!WallpaperSize.accepted(w / sample, h / sample)) return;- opts.inJustDecodeBounds = false;- opts.inSampleSize = sample;- int[] scale = WallpaperSize.coverScale(w / sample, h / sample, dm.widthPixels, dm.heightPixels);- if (scale != null) {- opts.inScaled = true;- opts.inDensity = scale[0];- opts.inTargetDensity = scale[1];- }- opts.inPreferredConfig = android.graphics.Bitmap.Config.RGB_565; // no alpha needed, half the memory- android.graphics.Bitmap bmp = android.graphics.BitmapFactory.decodeFile(file.getPath(), opts);- if (bmp == null) return;- android.widget.ImageView wall = new android.widget.ImageView(this);- wall.setScaleType(android.widget.ImageView.ScaleType.CENTER_CROP);- wall.setImageBitmap(bmp);- root.addView(wall, 0, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));- } catch (Exception | OutOfMemoryError e) {- // A bad or huge picture must never take the home screen down; the plain colour stays.- }- }-/*** Home pressed while Home is already in front: singleTask delivers it here, then onResume runs.* Back to the top with the first dock tile focused, like the stock launcher. Back from an app@@ -582,6 +548,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {updateInputsButton();if (showStats) startStats();sky.update();+ wallpaperPlayer.start();handler.postDelayed(minuteTick, MINUTE_MS);if (festive && diya != null) {diya.start();@@ -674,6 +641,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {protected void onPause() {super.onPause();endReorder(); // Home or another app while reordering keeps the order so far+ wallpaperPlayer.stop();stopAmbientAnimation();heroName.animate().cancel();ambient.animate().cancel();@@ -706,6 +674,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {@Overrideprotected void onDestroy() {super.onDestroy();+ wallpaperPlayer.close();ConnectivityManager cm = getSystemService(ConnectivityManager.class);TvInputManager tim = (TvInputManager) getSystemService(TV_INPUT_SERVICE);if (tim != null) tim.unregisterCallback(inputCallback);diff --git a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.javanew file mode 100644index 000000000..a00558902--- /dev/null+++ b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java@@ -0,0 +1,132 @@+package com.gathin.tvhome;++import android.content.Context;+import android.content.SharedPreferences;+import android.graphics.Bitmap;+import android.graphics.BitmapFactory;+import android.util.DisplayMetrics;+import android.util.Log;+import android.view.View;+import android.view.ViewGroup;+import android.widget.FrameLayout;+import android.widget.ImageView;++import java.io.File;+import java.util.ArrayList;+import java.util.List;+import java.util.Random;+import java.util.concurrent.ExecutorService;+import java.util.concurrent.Executors;++/** Displays and rotates a theme's local wallpaper images while Home is visible. */+final class WallpaperPlayer {+ private final FrameLayout root;+ private final ImageView image;+ private final List<File> files;+ private final long interval;+ private final SharedPreferences preferences;+ private final ExecutorService decoder = Executors.newSingleThreadExecutor();+ private final Random random = new Random();+ private final int width;+ private final int height;+ private boolean active;+ private boolean closed;+ private boolean loading;+ private String displayed = "";++ WallpaperPlayer(Context context, FrameLayout root, Config config) {+ this.root = root;+ files = new ArrayList<>(config.wallpapers);+ interval = config.wallpaperRotationMinutes * 60_000L;+ preferences = context.getSharedPreferences("wallpaper_rotation", Context.MODE_PRIVATE);+ DisplayMetrics metrics = context.getResources().getDisplayMetrics();+ width = metrics.widthPixels;+ height = metrics.heightPixels;+ image = new ImageView(context);+ image.setScaleType(ImageView.ScaleType.CENTER_CROP);+ image.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);+ if (config.wallpaperEnabled && !files.isEmpty()) {+ root.addView(image, 0, new FrameLayout.LayoutParams(+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));+ View shade = new View(context);+ shade.setBackgroundColor((config.wallpaperDim * 255 / 100) << 24);+ shade.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);+ root.addView(shade, 1, new FrameLayout.LayoutParams(+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));+ }+ }++ void start() {+ active = true;+ update();+ }++ void stop() {+ active = false;+ }++ void close() {+ active = false;+ closed = true;+ decoder.shutdownNow();+ }++ void update() {+ if (!active || closed || loading || files.isEmpty()) return;+ String previous = preferences.getString("image", "");+ File selected = WallpaperRotation.find(files, previous);+ long changed = preferences.getLong("changed", 0);+ if (selected == null || WallpaperRotation.due(changed, System.currentTimeMillis(), interval)) {+ selected = WallpaperRotation.pick(files, previous, random);+ }+ if (selected == null || selected.getName().equals(displayed)) return;+ File next = selected;+ loading = true;+ decoder.execute(() -> {+ Bitmap bitmap = decode(next);+ root.post(() -> {+ loading = false;+ if (closed || !active) {+ if (bitmap != null) bitmap.recycle();+ return;+ }+ if (bitmap == null) {+ files.remove(next);+ Log.w("TvHome.Wallpaper", "Skipping unreadable image: " + next.getName());+ update();+ return;+ }+ image.setImageBitmap(bitmap);+ displayed = next.getName();+ if (!displayed.equals(previous) || changed == 0) {+ preferences.edit().putString("image", displayed)+ .putLong("changed", System.currentTimeMillis()).apply();+ }+ });+ });+ }++ private Bitmap decode(File file) {+ try {+ BitmapFactory.Options options = new BitmapFactory.Options();+ options.inJustDecodeBounds = true;+ BitmapFactory.decodeFile(file.getPath(), options);+ int width = options.outWidth, height = options.outHeight;+ if (width <= 0 || height <= 0) return null;+ int sample = WallpaperSize.sampleSize(width, height, this.width, this.height);+ if (!WallpaperSize.accepted(width / sample, height / sample)) return null;+ options.inJustDecodeBounds = false;+ options.inSampleSize = sample;+ int[] scale = WallpaperSize.coverScale(width / sample, height / sample, this.width, this.height);+ if (scale != null) {+ options.inScaled = true;+ options.inDensity = scale[0];+ options.inTargetDensity = scale[1];+ }+ options.inPreferredConfig = Bitmap.Config.RGB_565;+ return BitmapFactory.decodeFile(file.getPath(), options);+ } catch (Exception | OutOfMemoryError failure) {+ return null;+ }+ }+}diff --git a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.java b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.javanew file mode 100644index 000000000..f1e7e553b--- /dev/null+++ b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.java@@ -0,0 +1,43 @@+package com.gathin.tvhome;++import java.io.File;+import java.util.ArrayList;+import java.util.Arrays;+import java.util.Comparator;+import java.util.List;+import java.util.Locale;+import java.util.Random;++final class WallpaperRotation {+ static List<File> images(File directory) {+ List<File> result = new ArrayList<>();+ File[] entries = directory == null ? null : directory.listFiles();+ if (entries == null) return result;+ Arrays.sort(entries, Comparator.comparing(File::getName));+ for (File entry : entries) {+ String name = entry.getName().toLowerCase(Locale.ROOT);+ if (entry.isFile() && entry.length() > 0 && entry.length() <= 10 * 1024 * 1024+ && (name.endsWith(".jpg") || name.endsWith(".jpeg")+ || name.endsWith(".png") || name.endsWith(".webp"))) {+ result.add(entry);+ if (result.size() == 100) break;+ }+ }+ return result;+ }++ static File find(List<File> images, String name) {+ for (File image : images) if (image.getName().equals(name)) return image;+ return null;+ }++ static File pick(List<File> images, String previous, Random random) {+ List<File> candidates = new ArrayList<>(images);+ if (candidates.size() > 1) candidates.removeIf(image -> image.getName().equals(previous));+ return candidates.isEmpty() ? null : candidates.get(random.nextInt(candidates.size()));+ }++ static boolean due(long previous, long now, long interval) {+ return interval > 0 && (previous == 0 || now < previous || now - previous >= interval);+ }+}diff --git a/themes/README.md b/themes/README.mdindex 82e4dd60e..5ca9593df 100644--- a/themes/README.md+++ b/themes/README.md@@ -50,6 +50,8 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can| `background_color` | `#RRGGBB` | Colour behind everything; black by default || `sky_intensity` | 0 to 100 | Time-of-day backdrop: a dark gradient that follows the clock, 0 hides it (default) || `wallpaper` | bool | Show `wallpaper.jpg` from the theme folder (`true`), or ignore it (`false`) |+| `wallpaper_rotation_minutes` | 0 to 1440 | Randomly rotate images in the theme's `wallpapers/` folder at this interval; 0 keeps the single-image behaviour |+| `wallpaper_dim` | 0 to 90 | Black overlay over wallpaper images, in percent; 0 by default || `festival` | string | Turns on a festive skin: the network pill becomes a diya whose flame follows the connection, Inputs a temple bell, Settings a marigold, and the first Home of the day gets a petal shower. `dussehra` and `diwali` have built-in greetings || `festival_until` | `YYYY-MM-DD` | Last day the festive skin shows; it switches itself off after that. A malformed date turns it off || `greeting` | string | Replaces the time-of-day greeting while the festive skin is on |@@ -64,6 +66,24 @@ under about 300 KB: the text, the hero name and the dock band are designed for bdecodes the picture into memory on every Home start. Pictures larger than the screen are scaled down toit; a picture that is still over 4K (about 8.4 million pixels) after it is sampled down to the screen is not shown at all, and the plain colour stays.+For an offline collection, put JPEG, PNG or WebP files in `wallpapers/` beside `config.json` and set:++```json+{ "wallpaper": true, "wallpaper_rotation_minutes": 30, "wallpaper_dim": 40 }+```++Both theme-push scripts copy that folder's images. Use filenames containing only letters, digits,+underscores, dots and hyphens. A new theme replaces the previous collection. The launcher considers+up to 100 nonempty images, at most 10 MB each, skips unreadable files and keeps the last good background.+An empty collection falls back to `wallpaper.jpg`, or the background colour if no image is available.+`"wallpaper": false` disables both single-image and collection backgrounds.++Selection is random without an immediate repeat when alternatives exist. The current image and its+change time survive app/process restarts. Rotation runs only while Home is visible; on return from+another app, an overdue background changes then. Images are decoded on a worker thread and bounded+to the screen size. There is no download service, Internet permission or computer-side scheduler.+The original system idle screensaver is left unchanged.+## Reduced motion`"reduced_motion": true` keeps the look but calms the movement: the highlight spring is stiff insteaddiff --git a/tools/theme.ps1 b/tools/theme.ps1index aef09ae05..b4ad1443a 100644--- a/tools/theme.ps1+++ b/tools/theme.ps1@@ -40,6 +40,14 @@ try { Get-Content $config -Raw | ConvertFrom-Json | Out-Null } catch { throw "$c& $py -I tv.py --push $config "$dir/config.json"$wall = Join-Path $Theme 'wallpaper.jpg'if (Test-Path $wall) { & $py -I b64push.py $wall "$dir/wallpaper.jpg" } else { & $py -I tv.py "rm -f $dir/wallpaper.jpg" | Out-Null }+& $py -I tv.py "mkdir -p $dir/wallpapers; rm -f $dir/wallpapers/*.jpg $dir/wallpapers/*.jpeg $dir/wallpapers/*.png $dir/wallpapers/*.webp $dir/wallpapers/*.JPG $dir/wallpapers/*.JPEG $dir/wallpapers/*.PNG $dir/wallpapers/*.WEBP" | Out-Null+$wallpapers = Join-Path $Theme 'wallpapers'+if (Test-Path $wallpapers -PathType Container) {+ Get-ChildItem $wallpapers -File | Where-Object { $_.Extension -match '^\.(jpg|jpeg|png|webp)$' } | ForEach-Object {+ if ($_.Name -notmatch '^[A-Za-z0-9_.-]+$') { throw "unsupported wallpaper filename: $($_.Name)" }+ & $py -I b64push.py $_.FullName "$dir/wallpapers/$($_.Name)"+ }+}& $py -I tv.py "printf '%s' '$revision' > $dir/theme_revision" | Out-Null& $py -I tv.py "$restart; echo applied"Write-Host "Theme $(Split-Path $Theme -Leaf) is on the TV. Undo with: tools\theme.ps1 -TvHost $TvHost -Reset"diff --git a/tools/theme.sh b/tools/theme.shindex 26f56fab9..e73f72156 100755--- a/tools/theme.sh+++ b/tools/theme.sh@@ -45,6 +45,18 @@ if [ -f "$THEME/wallpaper.jpg" ]; thenelsetv "rm -f $DIR/wallpaper.jpg" >/dev/nullfi+tv "mkdir -p $DIR/wallpapers; rm -f $DIR/wallpapers/*.jpg $DIR/wallpapers/*.jpeg $DIR/wallpapers/*.png $DIR/wallpapers/*.webp $DIR/wallpapers/*.JPG $DIR/wallpapers/*.JPEG $DIR/wallpapers/*.PNG $DIR/wallpapers/*.WEBP" >/dev/null+if [ -d "$THEME/wallpapers" ]; then+ for IMAGE in "$THEME"/wallpapers/*; do+ [ -f "$IMAGE" ] || continue+ case "$IMAGE" in+ *.jpg|*.jpeg|*.png|*.webp|*.JPG|*.JPEG|*.PNG|*.WEBP)+ NAME=$(basename "$IMAGE")+ [[ "$NAME" =~ ^[A-Za-z0-9_.-]+$ ]] || { echo "unsupported wallpaper filename: $NAME" >&2; exit 1; }+ "$PY" -I b64push.py "$IMAGE" "$DIR/wallpapers/$NAME" ;;+ esac+ done+fitv "printf '%s' '$REVISION' > $DIR/theme_revision" >/dev/nulltv "$RESTART; echo applied" | tail -n 1echo "Theme $(basename "$THEME") is on the TV. Undo with: tools/theme.sh --reset"