Optimize portable tile rendering and add optional memory saver

This commit is contained in:
Elijah Kuntz 2026-10-19 10:36:30 -07:00
parent 5bb15fa69e
commit 25ea43bea7
18 changed files with 918 additions and 63 deletions

25
AGENTS.md Normal file
View file

@ -0,0 +1,25 @@
# Repository guidance
Follow Android and Android TV best practices. Keep Luma portable across current and future devices, responsive on limited hardware, and economical with memory, GPU work, background CPU, and network use.
## Portability and configuration
- Do not select rendering paths or application behavior by device model, manufacturer, product name, serial number, IP address, or a list of known devices.
- Use documented platform APIs, API-level availability checks, measured capabilities, and resource limits when behavior needs to adapt. Provide a safe portable fallback. Make performance/quality tradeoffs explicit user settings when capability checks cannot reliably predict performance.
- Use the same defaults across devices unless a documented capability requires otherwise. Verify optimizations on both available test devices; record comparable workloads and distinguish measurements from assumptions. Never assume that an optimization on one GPU improves another.
- Keep deployment addresses, repository endpoints, and environment-specific values configurable or in deployment/test configuration. Do not embed a particular household's device addresses in production logic.
- Preserve existing launcher fallbacks, user preferences, and accessibility configuration during development and testing. Restore temporary test changes.
## Keys and security
- Never hardcode, commit, or log private keys, signing keystores, passwords, access tokens, or other secrets. Use ignored local configuration, environment variables, Android's secure storage, or a suitable secret manager.
- Preserve the existing local APK signing identity so installed devices can accept updates. Never generate a replacement key merely to work around a build or update failure.
- Keep TLS, SSH host identity checks, APK signature verification, and update integrity checks enabled. Resolve trust failures explicitly; do not bypass verification.
- Public verification material and intentional public defaults may be included when required by the design; document their purpose and keep them separate from secrets and device-specific behavior.
## Implementation and validation
- Prefer maintained platform APIs and small, understandable changes. Bound image dimensions, caches, queues, downloads, and worker concurrency; cancel obsolete work and release resources when Home is hidden.
- Preserve D-pad navigation, accessibility, focus visibility, smooth scrolling, and lifecycle recovery. Test meaningful failure and recovery cases for changes affecting rendering, persistence, updates, or background work.
- Do not ship a claimed performance improvement based only on an isolated microbenchmark. Compare normal and rapid navigation on both available devices and disclose material tradeoffs or untested cases.
- Review the final diff for hardcoded device assumptions and secrets before committing. Document relevant behavior, settings, and validation alongside the change.

View file

@ -40,7 +40,7 @@ To return to the previous routing, turn off Luma's Home override, then open Proj
**App labels** offers Always, Focused only (default), and Never. Accessibility app names remain available in all modes. Other settings include 5/6/7 columns, background dimming, automatic or fixed accent colors, reduced motion, clock visibility, and 90-second scene rotation. Alpine uses the bundled original wallpaper; Aurora and Midnight are inexpensive procedural gradients.
Focus uses a 6.5% scale increase, a 160 ms transition, and an app-colored cached soft shadow. Background crossfades last 280 ms. The launcher has no continuously rendered blur or background video. Optional screensaver video runs only while the screensaver is visible.
Focus uses a 6.5% scale increase, a 160 ms transition, and an app-colored cached soft shadow. Background crossfades last 280 ms. **Memory saver** in Appearance is off by default on every device. Enabling it reuses the background while app accent colors change, reducing image allocation and uploads; animation speed can vary with the graphics driver. It can be switched off at any time. The launcher has no continuously rendered blur or background video. Optional screensaver video runs only while the screensaver is visible.
The app grid uses one 260 ms scroll animation for remote focus movement. **App section text** can hide the heading, installed count, and customization hint; it is hidden by default without changing the original spacing.
@ -98,9 +98,10 @@ Android scheduling and installation behavior follow the [JobInfo API](https://de
- Platform Java/Android views and Canvas; no WebView, Compose runtime, playback engine, or third-party runtime dependencies.
- Single sampled RGB565 wallpaper (960 × 540 for the bundled 1920 × 1080 image). Cinematic gradients, dimming, and artwork are composed off the UI thread into an opaque texture capped at 960 × 540; navigation crossfades the finished textures instead of re-running several full-screen shaders every frame.
- App artwork is rasterized to 288 × 162. Icon cache is capped at 3 MiB; visible tiles also hold their displayed images.
- App artwork is rasterized to 288 × 162 over an opaque background. Rounded tiles use a cached bitmap shader instead of per-frame path clipping and redundant background blending. Icon cache is capped at 3 MiB; visible tiles also hold their displayed images.
- Plex image cache is capped at 3 MiB. Hero images are sampled to at most roughly 1280 × 720; rows and network response sizes are bounded.
- At most the current and previous composed backgrounds are displayed during a short crossfade. The compositor has one worker and one pending request; obsolete results are discarded. Its worker times out after two idle seconds. A focus debounce avoids loading Plex artwork for every passing selection. Only the focused tile draws an app-colored soft shadow. All tiles share a single 192 × 122 texture (about 92 KiB); no live elevation-shadow geometry is animated.
- At most the current and previous composed backgrounds are displayed during a short crossfade. The compositor has one worker and one pending request; obsolete results are discarded. Its worker times out after two idle seconds. A focus debounce avoids loading Plex artwork for every passing selection. Only the focused tile draws an app-colored soft shadow. All tiles share a single 192 × 122 alpha-only texture (about 23 KiB); no live elevation-shadow geometry is animated.
- The same rendering default applies to all devices, with no device-model, manufacturer, or IP-based renderer selection. Optional Memory saver adds a bounded alpha-only accent mask (at most 320 × 180), avoids composing a new full-color background for each accent change, and preserves artwork crossfades. It is an explicit user tradeoff, not an automatic hardware classification.
- No boot receiver, alarms, or PowerManager wake locks. Update checks use one brief JobScheduler job, normally daily. The optional Home override is an event-driven accessibility service in a separate process; turning it off removes that bound service. The optional DreamService runs only when Android explicitly binds it as a system screensaver.
- Clock updates once per minute; optional scene rotation runs only while Luma is visible.
- On pause, networking and scene animations are canceled. On stop, queued work, image references, and caches are cleared. Worker threads time out after ten idle seconds.
@ -152,6 +153,8 @@ bash scripts/build-wake-tests.sh
Successful output ends with `INSTRUMENTATION_CODE: -1` and PASS lines for all cases. The runner controls activity lifecycle callbacks and should be run with no other device tests in progress.
Android force-stops the target package during instrumentation and can mark its accessibility helper as stopped/crashed. After testing, check **Settings → Default launcher** and toggle **Luma Home button** off/on in Android Accessibility if needed, then reopen Luma. This is test-runner cleanup, not an action needed during normal TV wake.
Additional runners in the same test APK check real GPU pixels (`.TileRenderingInstrumentation`, `.RenderingInstrumentation`) and normal/rapid D-pad navigation without spawning an input process per key (`.NavigationInstrumentation`). Pass `-e memorySaver true` to the wake or navigation runner to exercise the optional mode; the runner restores its preference afterward.
The same test APK also includes `tv.luma.launcher.tests/.PerformanceInstrumentation` for the background/shadow A/B benchmark. It changes only runtime view state and writes a temporary `performance.txt` in Luma's external-files directory. Reopen Luma afterward and remove the diagnostic APK.
See [docs/ASSETS.md](docs/ASSETS.md) for the wallpaper generation prompt and asset provenance. Android TV intent handling follows [Android's TV app guidance](https://developer.android.com/training/tv/get-started/create); Plex integration follows the [official Plex Media Server API documentation](https://developer.plex.tv/pms/).

View file

@ -6,8 +6,8 @@ android {
applicationId 'tv.luma.launcher'
minSdk 26
targetSdk 34
versionCode 10
versionName '1.1.7'
versionCode 11
versionName '1.1.8'
}
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8; targetCompatibility JavaVersion.VERSION_1_8 }
}

View file

@ -1,4 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="tv.luma.launcher" android:versionCode="10" android:versionName="1.1.7">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="tv.luma.launcher" android:versionCode="11" android:versionName="1.1.8">
<uses-sdk android:minSdkVersion="26" android:targetSdkVersion="34" />
<uses-feature android:name="android.software.leanback" android:required="true" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />

View file

@ -68,6 +68,8 @@ final class AppRepository {
d.setBounds(97, 34, 191, 128);
}
d.draw(c);
// The app image was painted over an opaque color; let HWUI skip alpha blending.
b.setHasAlpha(false);
icons.put(app.pkg, b);
return b;
} catch (Exception e) {

View file

@ -34,7 +34,7 @@ final class AppTile extends LinearLayout {
setClipToPadding(false);
setWillNotDraw(false);
if (shadowMask == null) {
shadowMask = Bitmap.createBitmap(192, 122, Bitmap.Config.ARGB_8888);
shadowMask = Bitmap.createBitmap(192, 122, Bitmap.Config.ALPHA_8);
Canvas canvas = new Canvas(shadowMask);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(Color.WHITE);
@ -106,7 +106,7 @@ final class AppTile extends LinearLayout {
}
void setAccent(int color) {
shadowPaint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
shadowPaint.setColor(color);
invalidate();
}
@ -131,8 +131,7 @@ final class AppTile extends LinearLayout {
}
void bitmap(Bitmap b) {
art.bitmap = b;
art.invalidate();
art.image(b);
}
boolean hasImage() {
@ -147,6 +146,9 @@ final class AppTile extends LinearLayout {
private static final class ArtView extends View {
final Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
final RectF rect = new RectF();
final Paint imagePaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
final Matrix imageMatrix = new Matrix();
BitmapShader imageShader;
final Path clip = new Path();
Bitmap bitmap;
boolean focus;
@ -157,19 +159,6 @@ final class AppTile extends LinearLayout {
super(c);
fallback = s;
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
setElevation(0);
setOutlineProvider(
new ViewOutlineProvider() {
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(
2,
2,
Math.max(3, view.getWidth() - 2),
Math.max(3, view.getHeight() - 2),
Ui.dp(c, 12));
}
});
}
protected void onSizeChanged(int w, int h, int ow, int oh) {
@ -180,27 +169,38 @@ final class AppTile extends LinearLayout {
h - Ui.dp(getContext(), 2));
clip.reset();
clip.addRoundRect(rect, Ui.dp(getContext(), 12), Ui.dp(getContext(), 12), Path.Direction.CW);
positionImage();
}
void image(Bitmap b) {
bitmap = b;
imageShader =
b == null ? null : new BitmapShader(b, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
imagePaint.setShader(imageShader);
positionImage();
invalidate();
}
private void positionImage() {
if (bitmap == null || imageShader == null || rect.width() <= 0) return;
float scale = Math.max(rect.width() / bitmap.getWidth(), rect.height() / bitmap.getHeight());
imageMatrix.setScale(scale, scale);
imageMatrix.postTranslate(
rect.centerX() - bitmap.getWidth() * scale / 2,
rect.centerY() - bitmap.getHeight() * scale / 2);
imageShader.setLocalMatrix(imageMatrix);
}
protected void onDraw(Canvas c) {
c.save();
c.clipPath(clip);
p.setColor(0xFF1B263B);
c.drawRect(rect, p);
if (bitmap == null || bitmap.hasAlpha()) {
p.setColor(0xFF1B263B);
c.drawRoundRect(rect, Ui.dp(getContext(), 12), Ui.dp(getContext(), 12), p);
}
if (bitmap != null) {
float scale =
Math.max(rect.width() / bitmap.getWidth(), rect.height() / bitmap.getHeight());
float w = bitmap.getWidth() * scale, h = bitmap.getHeight() * scale;
c.drawBitmap(
bitmap,
null,
new RectF(
rect.centerX() - w / 2,
rect.centerY() - h / 2,
rect.centerX() + w / 2,
rect.centerY() + h / 2),
p);
c.drawRoundRect(rect, Ui.dp(getContext(), 12), Ui.dp(getContext(), 12), imagePaint);
} else {
c.save();
c.clipPath(clip);
p.setColor(Ui.WHITE);
p.setTextSize(Ui.dp(getContext(), 17));
p.setTypeface(Typeface.create("sans-serif-medium", 0));
@ -210,8 +210,11 @@ final class AppTile extends LinearLayout {
rect.centerX(),
rect.centerY() + Ui.dp(getContext(), 5),
p);
c.restore();
}
if (progress > 0) {
c.save();
c.clipPath(clip);
p.setColor(0xA0080D18);
c.drawRect(rect.left, rect.bottom - Ui.dp(getContext(), 4), rect.right, rect.bottom, p);
p.setColor(Ui.GOLD);
@ -221,8 +224,8 @@ final class AppTile extends LinearLayout {
rect.left + rect.width() * progress,
rect.bottom,
p);
c.restore();
}
c.restore();
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(Ui.dp(getContext(), focus ? 1.5f : 1));
p.setColor(focus ? 0xDBF4E8D8 : 0x26FFFFFF);

View file

@ -1277,6 +1277,16 @@ public final class MainActivity extends Activity {
});
}
});
action(
p,
"Memory saver · " + on(prefs.getBoolean("memorySaver", false)),
"Uses less memory for background colors; animation speed varies by device",
() -> {
boolean enabled = !prefs.getBoolean("memorySaver", false);
prefs.edit().putBoolean("memorySaver", enabled).apply();
scene.setMemorySaver(enabled);
appearance();
});
action(
p,
"Focus animations · " + on(motion()),

View file

@ -21,19 +21,24 @@ final class SceneView extends View {
TimeUnit.SECONDS,
new ArrayBlockingQueue<>(1),
new ThreadPoolExecutor.DiscardOldestPolicy());
private Bitmap wallpaper, mediaArt, frame, previousFrame;
private Bitmap wallpaper, mediaArt, frame, previousFrame, mask, previousMask;
private final Paint tintPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
private float mix = 1;
private boolean motion = true, active = true, dirty = true;
private volatile int generation;
private int accent = 0xFF5B4125;
private int accent = 0xFF5B4125, targetAccent = accent;
private String scene = "alpine";
private float dim = .24f;
private ValueAnimator animator;
private ValueAnimator animator, colorAnimator;
private boolean useTintMask;
SceneView(Context c) {
super(c);
setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
renderer.allowCoreThreadTimeOut(true);
useTintMask =
c.getSharedPreferences("luma", Context.MODE_PRIVATE).getBoolean("memorySaver", false);
tintPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD));
}
static Bitmap decodeWallpaper(Context c) {
@ -74,6 +79,20 @@ final class SceneView extends View {
requestRender();
}
void setMemorySaver(boolean enabled) {
if (useTintMask == enabled) return;
stopAnimations();
useTintMask = enabled;
// Full-color and mask bases encode different pixel values; retain source artwork for
// rebuilding.
generation++;
renderer.getQueue().clear();
frame = previousFrame = mask = previousMask = null;
dirty = true;
requestRender();
invalidate();
}
void setMotion(boolean enabled) {
motion = enabled;
if (!enabled) stopAnimations();
@ -87,9 +106,34 @@ final class SceneView extends View {
}
void accent(int color, boolean animate) {
if (accent == color) return;
accent = color;
requestRender();
if (!useTintMask) {
if (accent == color) return;
accent = targetAccent = color;
requestRender();
return;
}
if (targetAccent == color) return;
targetAccent = color;
if (colorAnimator != null) colorAnimator.cancel();
if (!animate || !motion || frame == null) {
accent = color;
invalidate();
return;
}
final int from = accent;
colorAnimator = ValueAnimator.ofFloat(0, 1);
colorAnimator.setDuration(280);
colorAnimator.addUpdateListener(
a -> {
float f = (float) a.getAnimatedValue();
accent =
Color.rgb(
Math.round(Color.red(from) * (1 - f) + Color.red(color) * f),
Math.round(Color.green(from) * (1 - f) + Color.green(color) * f),
Math.round(Color.blue(from) * (1 - f) + Color.blue(color) * f));
invalidate();
});
colorAnimator.start();
}
@Override
@ -107,14 +151,16 @@ final class SceneView extends View {
final int h = Math.max(1, Math.round(getHeight() * scale));
final Bitmap art = mediaArt != null ? mediaArt : scene.equals("alpine") ? wallpaper : null;
final String theme = scene;
final int color = accent;
final int color = useTintMask ? Color.BLACK : accent;
final boolean masked = useTintMask;
final float darkness = dim;
renderer.execute(
() -> {
if (ticket != generation) return;
Bitmap composed;
Bitmap composed, tint;
try {
composed = compose(w, h, art, theme, darkness, color);
tint = masked ? makeMask(w, h, art != null && !art.isRecycled()) : null;
} catch (OutOfMemoryError e) {
return;
}
@ -123,11 +169,14 @@ final class SceneView extends View {
() -> {
if (ticket != generation || !active) return;
dirty = false;
stopAnimations();
stopImageAnimation();
previousFrame = frame;
previousMask = mask;
frame = composed;
mask = tint;
if (!motion || previousFrame == null) {
previousFrame = null;
previousMask = null;
mix = 1;
invalidate();
return;
@ -145,6 +194,7 @@ final class SceneView extends View {
@Override
public void onAnimationEnd(Animator animation) {
previousFrame = null;
previousMask = null;
mix = 1;
invalidate();
}
@ -211,17 +261,70 @@ final class SceneView extends View {
return result;
}
/** The protected accent contribution is independent of the wallpaper RGB. */
private static Bitmap makeMask(int width, int height, boolean artwork) {
float scale = Math.min(1f, Math.min(320f / width, 180f / height));
int w = Math.max(1, Math.round(width * scale)), h = Math.max(1, Math.round(height * scale));
Bitmap result = Bitmap.createBitmap(w, h, Bitmap.Config.ALPHA_8);
Canvas c = new Canvas(result);
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setShader(
new RadialGradient(
w * .76f,
h * .25f,
w * .8f,
new int[] {0xA0FFFFFF, 0x00FFFFFF},
null,
Shader.TileMode.CLAMP));
p.setAlpha(artwork ? 65 : 150);
c.drawRect(0, 0, w, h, p);
p.setAlpha(255);
p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
p.setShader(
new LinearGradient(
0,
0,
w * .88f,
0,
new int[] {0xE0FFFFFF, 0x9CFFFFFF, 0x00FFFFFF},
new float[] {0, .48f, 1},
Shader.TileMode.CLAMP));
c.drawRect(0, 0, w, h, p);
p.setShader(
new LinearGradient(
0,
h * .24f,
0,
h,
new int[] {0x00FFFFFF, 0xA8FFFFFF, 0xFCFFFFFF, 0xFFFFFFFF},
new float[] {0, .47f, .82f, 1},
Shader.TileMode.CLAMP));
c.drawRect(0, 0, w, h, p);
return result;
}
@Override
protected void onDraw(Canvas c) {
destination.set(0, 0, getWidth(), getHeight());
if (previousFrame != null) c.drawBitmap(previousFrame, null, destination, paint);
if (frame == null) {
c.drawColor(Ui.BG);
return;
}
paint.setAlpha(previousFrame == null ? 255 : (int) (mix * 255));
if (previousFrame != null) c.drawBitmap(previousFrame, null, destination, paint);
paint.setAlpha(previousFrame == null ? 255 : (int) (255 * mix));
c.drawBitmap(frame, null, destination, paint);
paint.setAlpha(255);
if (useTintMask) {
if (previousFrame != null) drawMask(c, previousMask, 1 - mix);
drawMask(c, mask, previousFrame == null ? 1 : mix);
}
}
private void drawMask(Canvas c, Bitmap image, float opacity) {
if (image == null || opacity <= 0) return;
tintPaint.setColor(accent);
tintPaint.setAlpha(Math.round(255 * opacity));
c.drawBitmap(image, null, destination, tintPaint);
}
@Override
@ -229,12 +332,20 @@ final class SceneView extends View {
return true;
}
void stopAnimations() {
private void stopImageAnimation() {
if (animator != null) animator.cancel();
previousFrame = null;
previousMask = null;
mix = 1;
}
void stopAnimations() {
stopImageAnimation();
if (colorAnimator != null) colorAnimator.cancel();
accent = targetAccent;
invalidate();
}
void pause() {
active = false;
generation++;
@ -252,6 +363,7 @@ final class SceneView extends View {
wallpaper = null;
mediaArt = null;
frame = null;
mask = null;
dirty = true;
invalidate();
}

View file

@ -1 +1 @@
Further improves focus animation performance with a small shared soft-shadow texture. Keeps the cinematic background, app-colored glow, focus enlargement, and smooth scrolling. Includes the integrated-TV background rendering optimization.
Improves app-tile rendering and reduces the shared focus-shadow texture to one quarter of its previous size. Adds an optional Memory saver setting for background colors. All devices use the same rendering default, with no model-specific pathways. Keeps cinematic artwork, focus effects, and smooth scrolling. Tested on the onn box and integrated TV.

View file

@ -48,7 +48,7 @@ No launcher application was disabled or uninstalled. Screensaver selection at th
Build validation uses aapt2, javac, D8, zipalign, and apksigner signature verification. There are no third-party runtime libraries.
Final APK (1.1.7): 2,753,622 bytes. SHA-256: `b15cd4abad3cb55eab29916fdd61b4702e665d163d3225779b04b7dee302ee23`.
Final APK (1.1.8): 2,753,622 bytes. SHA-256: `9f4fecf5162c897e9614b9fe4b3af37989bd10d3959d9278f1314e4e0630b80b`.
## Updater regression — October 18, 2026
@ -108,3 +108,32 @@ The same TV-local focus benchmark with the new shadow enabled produced **640 fra
The enhanced wake regression passed with the cached-shadow build, including checking that its animation stops on leaving Home, nonblank bounded backgrounds, interrupted-load recovery, screensaver dismissal, and five stop/start cycles. An initial attempt began while the TV was asleep; later ADB disconnects interrupted streamed test reports. Running the diagnostic locally with saved output while the TV was awake completed successfully. The temporary diagnostic APK is removed after verification.
The broader 42-key D-pad sequence on 1.1.7 recorded 861 frames, 16 missed deadlines (1.86%), median 14 ms, 90th percentile 25 ms, and 95th percentile 25 ms. This is roughly level with the 1.1.6 sample (1.41%, 13/24/26 ms); the cached shadow's isolated-focus consistency gain did not produce a measurable improvement to the whole navigation workload in these samples. It is not presented as a new overall performance leap. Screenshots confirm the soft app-colored shadow, scale/outline, wallpaper, and spacing remain visible. The remaining navigation time is primarily GPU/compositing work; main-thread draw/traversal was already sub-millisecond in the sampled 1.1.6 trace. The onn comparison remains 1.1.5, rather than claiming a same-version hardware comparison.
## Portable tile optimization — October 19, 2026
Version 1.1.8 uses the same default rendering path and settings on every device. No model, manufacturer, product, IP address, or device-name selection is used. App banners are marked opaque after composition over an opaque background. Rounded app artwork uses a cached bitmap shader and matrix, avoiding repeated path clipping and redundant background draws. Transparent artwork retains its underfill and media progress bars retain their rounded clipping. The shared focus shadow is now ALPHA_8: 23,424 bytes instead of 93,696 bytes. Focus enlargement, color glow, 160 ms focus transitions, background transitions, and smooth scrolling remain enabled.
The onn and integrated TV were first brought to the same released 1.1.7 baseline. The following comparisons use a same-signature diagnostic with real D-pad key injection, Android FrameMetrics, and identical 42-key sequences across the app rows. Normal navigation waits 350 ms between keys; rapid navigation waits 80 ms. This avoids the extra process/VM startup caused by invoking Android's shell `input` command for every key. Metrics were collected locally on each device, rather than timing the ADB connection.
| Device / pace | 1.1.7 median / p90 | 1.1.8 median / p90 | Missed deadlines, baseline → optimized |
| --- | ---: | ---: | ---: |
| onn, normal | 12.09 / 15.08 ms | 10.49 / 13.30 ms | 8/798 → 7/801 |
| onn, rapid | 11.60 / 14.89 ms | 10.76 / 13.63 ms | 3/254 → 1/255 |
| TV, normal | 25.03 / 26.75 ms | 13.28 / 24.24 ms | 32/828 → 17/864 |
| TV, rapid | 25.36 / 26.91 ms | 24.39 / 25.17 ms | 28/212 → 25/210 |
The TV improves substantially in normal-navigation median duration, but its rapid-navigation GPU cost remains greater than the onn's. These are short samples of each device's existing app grid, not proof of identical hardware performance or perfect 60 fps. FrameMetrics total duration and deadlines are reported directly; they should not be mixed with earlier gfxinfo histogram values or an isolated first-six-tile benchmark. All samples above had zero dropped FrameMetrics callbacks. Raw reports are saved locally under `output/performance/round2/` and are ignored by Git.
**Settings → Appearance → Memory saver** is available on every device and is **off by default**. It separates accent tint into a bounded alpha mask, retaining the same composed background when only the selected app's color changes. This reduces repeated full-image allocation/uploads, with a different GPU tradeoff. Earlier shell-workload onn PSS samples were 132,417 KiB for 1.1.7, 109,413 KiB for optimized tiles with the default background, and 67,578 KiB with Memory saver and optimized tiles. PSS is variable, includes framework/graphics overhead, and is not a guaranteed reduction on every device.
With Memory saver enabled, the same native-input test measured normal/rapid p90 durations of 13.03/14.88 ms on the onn and 24.44/24.81 ms on the TV. Missed-deadline counts were 12/681 and 1/259 on the onn, and 20/732 and 27/208 on the TV. It is not consistently faster than the default, so it is an explicit preference rather than an automatic device classification. Both modes work on both devices. GPU-specific single-pass shader experiments were discarded after they regressed performance.
GPU PixelCopy checks passed on both devices for wide opaque banners, portrait center cropping, transparent artwork, media progress bars, and rounded corners. Sampled tile interior differences against the previous drawing implementation were at most 1/255 per color channel. Clearing a tile image also clears its cached shader reference. Memory-saver backgrounds matched the original composited colors within 2/255, and artwork crossfades at 25%, 50%, and 75% matched within 3/255. Accent changes reused the existing background and mask.
Wake regression passed on both devices in both rendering modes: cold launch, interrupted loading/pause/resume, memory trim, existing-tile reuse, partial-grid recovery, bounded nonblank backgrounds, texture/queue release on stop, screensaver dismissal, and five stop/start cycles. Memory-saver checks also verified loading the saved preference and switching back and forth at runtime. Temporary preference changes were restored by the test runners. The first tile-comparison test had an uninitialized reference bitmap in the diagnostic overlay; fixing that test setup allowed the comparisons to pass without changing production rendering.
The final signed 1.1.8 APK was installed on both devices and retains the previous certificate. Final screenshots show the original five-column spacious layout, mountain background, rounded banners, and app-colored focused shadow. Temporary diagnostic packages were uninstalled. The onn Home helper was re-bound after instrumentation using its original enabled-service list, retaining Button Mapper; Home from Android settings and repeated Back returned/stayed in Luma. The TV's Home override remains off with its original empty service list. Projectivy remains installed and enabled.
With Android settings foreground, the onn UI and Home helper each consumed zero CPU ticks over five seconds. The TV initially consumed five CPU ticks over five seconds after installation; a later five-second sample after settling consumed zero. These short samples show idle behavior after pending work completes, rather than establishing overnight endurance. Both devices were returned to Luma after verification.

Binary file not shown.

Binary file not shown.

View file

@ -1,11 +1,11 @@
{
"schema": 1,
"packageName": "tv.luma.launcher",
"versionCode": 10,
"versionName": "1.1.7",
"versionCode": 11,
"versionName": "1.1.8",
"minSdk": 26,
"apk": "Luma.apk",
"size": 2753622,
"sha256": "b15cd4abad3cb55eab29916fdd61b4702e665d163d3225779b04b7dee302ee23",
"notes": "Further improves focus animation performance with a small shared soft-shadow texture. Keeps the cinematic background, app-colored glow, focus enlargement, and smooth scrolling. Includes the integrated-TV background rendering optimization."
"sha256": "9f4fecf5162c897e9614b9fe4b3af37989bd10d3959d9278f1314e4e0630b80b",
"notes": "Improves app-tile rendering and reduces the shared focus-shadow texture to one quarter of its previous size. Adds an optional Memory saver setting for background colors. All devices use the same rendering default, with no model-specific pathways. Keeps cinematic artwork, focus effects, and smooth scrolling. Tested on the onn box and integrated TV."
}

View file

@ -4,4 +4,7 @@
<instrumentation android:name=".WakeRegressionInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
<instrumentation android:name="tv.luma.launcher.UpdaterInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
<instrumentation android:name=".PerformanceInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
<instrumentation android:name=".RenderingInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
<instrumentation android:name=".NavigationInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
<instrumentation android:name=".TileRenderingInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
</manifest>

View file

@ -0,0 +1,124 @@
package tv.luma.launcher.tests;
import android.app.*;
import android.content.*;
import android.os.*;
import android.view.*;
import java.lang.reflect.*;
import java.util.*;
/** Real D-pad injection without spawning the Android input command/VM for every key. */
public final class NavigationInstrumentation extends Instrumentation {
private boolean testMemorySaver;
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
testMemorySaver = b != null && "true".equals(b.getString("memorySaver"));
start();
}
@Override
public void onStart() {
Bundle result = new Bundle();
StringBuilder report = new StringBuilder();
SharedPreferences prefs = getTargetContext().getSharedPreferences("luma", 0);
boolean hadSetting = prefs.contains("memorySaver"),
original = prefs.getBoolean("memorySaver", false);
int status = Activity.RESULT_OK;
HandlerThread listener = new HandlerThread("navigation-metrics");
listener.start();
try {
if (testMemorySaver && !prefs.edit().putBoolean("memorySaver", true).commit())
throw new AssertionError("could not save memory preference");
Activity a =
startActivitySync(
new Intent(Intent.ACTION_MAIN)
.setComponent(
new ComponentName("tv.luma.launcher", "tv.luma.launcher.MainActivity"))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
Thread.sleep(3000);
if (!((PowerManager) a.getSystemService(Context.POWER_SERVICE)).isInteractive())
throw new AssertionError("screen asleep");
for (int i = 0; i < 3; i++) sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
Thread.sleep(500);
List<long[]> frames = Collections.synchronizedList(new ArrayList<>());
a.getWindow()
.addOnFrameMetricsAvailableListener(
(w, f, d) ->
frames.add(
new long[] {
f.getMetric(FrameMetrics.TOTAL_DURATION),
f.getMetric(FrameMetrics.DEADLINE),
f.getMetric(FrameMetrics.GPU_DURATION),
d
}),
new Handler(listener.getLooper()));
int[] keys = {22, 22, 22, 22, 22, 21, 21, 21, 21, 21, 20, 20, 19, 19};
for (int delay : new int[] {350, 80}) {
frames.clear();
long start = SystemClock.uptimeMillis();
for (int round = 0; round < 3; round++)
for (int key : keys) {
sendKeyDownUpSync(key);
Thread.sleep(delay);
}
Thread.sleep(450);
List<long[]> sample;
synchronized (frames) {
sample = new ArrayList<>(frames);
}
List<Long> total = new ArrayList<>(), gpu = new ArrayList<>();
int missed = 0, dropped = 0;
for (long[] f : sample) {
total.add(f[0]);
gpu.add(f[2]);
if (f[1] > 0 && f[0] > f[1]) missed++;
dropped += f[3];
}
Collections.sort(total);
Collections.sort(gpu);
if (total.size() < 40)
throw new AssertionError("insufficient rendered frames " + total.size());
report
.append("delayMs=")
.append(delay)
.append(" frames=")
.append(total.size())
.append(" medianMs=")
.append(total.get(total.size() / 2) / 1e6)
.append(" p90Ms=")
.append(total.get((int) (total.size() * .9)) / 1e6)
.append(" p95Ms=")
.append(total.get((int) (total.size() * .95)) / 1e6)
.append(" deadlineMissed=")
.append(missed)
.append(" droppedCallbacks=")
.append(dropped)
.append(" gpuP90Ms=")
.append(gpu.get((int) (gpu.size() * .9)) / 1e6)
.append(" elapsedMs=")
.append(SystemClock.uptimeMillis() - start)
.append('\n');
Thread.sleep(600);
}
report.append("PASS: normal and rapid real D-pad navigation\n");
} catch (Throwable t) {
report.append("FAIL: ").append(t).append('\n');
status = Activity.RESULT_CANCELED;
} finally {
listener.quitSafely();
if (testMemorySaver) {
SharedPreferences.Editor edit = prefs.edit();
if (hadSetting) edit.putBoolean("memorySaver", original);
else edit.remove("memorySaver");
if (!edit.commit()) {
report.append("FAIL: could not restore memory preference\n");
status = Activity.RESULT_CANCELED;
}
}
}
result.putString("stream", report.toString());
finish(status, result);
}
}

View file

@ -0,0 +1,270 @@
package tv.luma.launcher.tests;
import android.app.Activity;
import android.app.Instrumentation;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.*;
import android.os.*;
import android.view.*;
import java.lang.reflect.*;
import java.util.concurrent.*;
/**
* Compare real GPU crossfade pixels with the compatible renderer, including differently sized
* inputs.
*/
public final class RenderingInstrumentation extends Instrumentation {
private Field member(Object o, String name) throws Exception {
Field f = o.getClass().getDeclaredField(name);
f.setAccessible(true);
return f;
}
private Object get(Object o, String name) throws Exception {
return member(o, name).get(o);
}
private void set(Object o, String name, Object value) throws Exception {
member(o, name).set(o, value);
}
private void invoke(Object o, String name) throws Exception {
Method m = o.getClass().getDeclaredMethod(name);
m.setAccessible(true);
m.invoke(o);
}
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
start();
}
private Bitmap capture(Activity activity) throws Exception {
Bitmap[] copy = new Bitmap[1];
CountDownLatch done = new CountDownLatch(1);
int[] code = {-1};
runOnMainSync(
() -> {
View v = activity.getWindow().getDecorView();
copy[0] = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
PixelCopy.request(
activity.getWindow(),
copy[0],
r -> {
code[0] = r;
done.countDown();
},
new Handler(Looper.getMainLooper()));
});
if (!done.await(4, TimeUnit.SECONDS) || code[0] != PixelCopy.SUCCESS)
throw new AssertionError("PixelCopy failed: " + code[0]);
return copy[0];
}
private Bitmap pattern(int w, int h, int a, int b) {
Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
bitmap.setHasAlpha(false);
Paint paint = new Paint();
paint.setShader(new LinearGradient(0, 0, w, h, a, b, Shader.TileMode.CLAMP));
new Canvas(bitmap).drawRect(0, 0, w, h, paint);
return bitmap;
}
private Object call(Object object, String name, Class<?>[] types, Object... args)
throws Exception {
Method method = object.getClass().getDeclaredMethod(name, types);
method.setAccessible(true);
return method.invoke(object, args);
}
private Bitmap compose(Object scene, Bitmap image, String theme, int color) throws Exception {
return (Bitmap)
call(
scene,
"compose",
new Class<?>[] {
int.class, int.class, Bitmap.class, String.class, float.class, int.class
},
960,
540,
image,
theme,
.20f,
color);
}
private Bitmap mask(Object scene, boolean image) throws Exception {
return (Bitmap)
call(
scene,
"makeMask",
new Class<?>[] {int.class, int.class, boolean.class},
960,
540,
image);
}
private void show(
View scene,
Bitmap frame,
Bitmap mask,
Bitmap previous,
Bitmap previousMask,
int color,
float mix) {
runOnMainSync(
() -> {
try {
set(scene, "frame", frame);
set(scene, "mask", mask);
set(scene, "previousFrame", previous);
set(scene, "previousMask", previousMask);
set(scene, "accent", color);
set(scene, "targetAccent", color);
set(scene, "mix", mix);
scene.invalidate();
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
private int compare(Bitmap expected, Bitmap actual) {
int worst = 0;
// Avoid the ticking clock and app rows; compare the cinematic area through the real window.
for (int y = 150; y < actual.getHeight() * .6; y += 13)
for (int x = 20; x < actual.getWidth() - 20; x += 13) {
int a = expected.getPixel(x, y), b = actual.getPixel(x, y);
for (int shift : new int[] {0, 8, 16})
worst = Math.max(worst, Math.abs(((a >> shift) & 255) - ((b >> shift) & 255)));
}
return worst;
}
@Override
public void onStart() {
Bundle result = new Bundle();
StringBuilder report = new StringBuilder();
try {
Activity activity =
startActivitySync(
new Intent(Intent.ACTION_MAIN)
.setComponent(
new ComponentName("tv.luma.launcher", "tv.luma.launcher.MainActivity"))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
Thread.sleep(3000);
View scene = (View) get(activity, "scene");
runOnMainSync(
() -> {
try {
set(scene, "useTintMask", true);
invoke(scene, "requestRender");
} catch (Exception e) {
throw new RuntimeException(e);
}
});
Thread.sleep(700);
Object base = get(scene, "frame"), tint = get(scene, "mask");
if (base == null || tint == null) throw new AssertionError("initial image not loaded");
runOnMainSync(
() -> {
try {
call(scene, "accent", new Class<?>[] {int.class, boolean.class}, Color.CYAN, false);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
if (get(scene, "frame") != base || get(scene, "mask") != tint)
throw new AssertionError("accent changed cached wallpaper/mask");
report.append("PASS: changing accent reuses the same wallpaper and mask\n");
runOnMainSync(
() -> {
try {
invoke(scene, "pause");
} catch (Exception e) {
throw new RuntimeException(e);
}
});
Bitmap artwork = pattern(320, 180, Color.RED, Color.CYAN);
Bitmap darkArtwork = compose(scene, artwork, "alpine", Color.BLACK),
artMask = mask(scene, true);
Bitmap darkGradient = compose(scene, null, "aurora", Color.BLACK),
gradientMask = mask(scene, false);
for (boolean hasArt : new boolean[] {true, false})
for (int color : new int[] {0xFF5B4125, 0xFF193C6A, Color.WHITE}) {
Bitmap referenceImage =
compose(scene, hasArt ? artwork : null, hasArt ? "alpine" : "aurora", color);
show(scene, referenceImage, null, null, null, color, 1);
Thread.sleep(120);
Bitmap reference = capture(activity);
show(
scene,
hasArt ? darkArtwork : darkGradient,
hasArt ? artMask : gradientMask,
null,
null,
color,
1);
Thread.sleep(120);
Bitmap actual = capture(activity);
int worst = compare(reference, actual);
if (worst > 5)
throw new AssertionError(
"mask/reference pixels differ by " + worst + " artwork=" + hasArt);
report
.append("PASS: mask matches original background; artwork=")
.append(hasArt)
.append(" max difference ")
.append(worst)
.append('\n');
reference.recycle();
actual.recycle();
}
int color = 0xFF193C6A;
Bitmap before = compose(scene, artwork, "alpine", color),
after = compose(scene, null, "aurora", color);
for (float mix : new float[] {.25f, .5f, .75f}) {
Bitmap expected = Bitmap.createBitmap(960, 540, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(expected);
Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
canvas.drawBitmap(before, 0, 0, paint);
paint.setAlpha((int) (255 * mix));
canvas.drawBitmap(after, 0, 0, paint);
show(scene, expected, null, null, null, color, 1);
Thread.sleep(120);
Bitmap reference = capture(activity);
show(scene, darkGradient, gradientMask, darkArtwork, artMask, color, mix);
Thread.sleep(120);
Bitmap actual = capture(activity);
int worst = compare(reference, actual);
if (worst > 5) throw new AssertionError("art crossfade differs by " + worst + " at " + mix);
report
.append("PASS: artwork crossfade ")
.append(mix)
.append(" matches original; max difference ")
.append(worst)
.append('\n');
reference.recycle();
actual.recycle();
}
runOnMainSync(
() -> {
try {
invoke(scene, "release");
} catch (Exception e) {
throw new RuntimeException(e);
}
});
for (String name : new String[] {"frame", "previousFrame", "mask", "previousMask"})
if (get(scene, name) != null) throw new AssertionError("retained background " + name);
report.append("PASS: source images and tint masks released on stop\n");
result.putString("stream", report.toString());
finish(Activity.RESULT_OK, result);
} catch (Throwable t) {
result.putString("stream", report + "FAIL: " + t + "\n");
finish(Activity.RESULT_CANCELED, result);
}
}
}

View file

@ -0,0 +1,230 @@
package tv.luma.launcher.tests;
import android.app.*;
import android.content.*;
import android.graphics.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import java.lang.reflect.*;
import java.util.concurrent.*;
/** Compare actual GPU app-tile interiors with the previous clip-and-bitmap implementation. */
public final class TileRenderingInstrumentation extends Instrumentation {
private Object get(Object o, String name) throws Exception {
Field f = o.getClass().getDeclaredField(name);
f.setAccessible(true);
return f.get(o);
}
private void set(Object o, String name, Object v) throws Exception {
Field f = o.getClass().getDeclaredField(name);
f.setAccessible(true);
f.set(o, v);
}
private int dp(Context c, float n) {
return Math.round(n * c.getResources().getDisplayMetrics().density);
}
private Bitmap capture(Activity a) throws Exception {
CountDownLatch done = new CountDownLatch(1);
Bitmap[] image = {null};
int[] code = {-1};
runOnMainSync(
() -> {
View v = a.getWindow().getDecorView();
image[0] = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
PixelCopy.request(
a.getWindow(),
image[0],
r -> {
code[0] = r;
done.countDown();
},
new Handler(Looper.getMainLooper()));
});
if (!done.await(4, TimeUnit.SECONDS) || code[0] != 0)
throw new AssertionError("PixelCopy " + code[0]);
return image[0];
}
private final class Reference extends View {
final Paint p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
final RectF r = new RectF();
final Path clip = new Path();
Bitmap bitmap;
float progress;
Reference(Context c) {
super(c);
}
protected void onSizeChanged(int w, int h, int x, int y) {
r.set(
dp(getContext(), 2),
dp(getContext(), 2),
w - dp(getContext(), 2),
h - dp(getContext(), 2));
clip.addRoundRect(r, dp(getContext(), 12), dp(getContext(), 12), Path.Direction.CW);
}
protected void onDraw(Canvas c) {
if (bitmap == null) return;
c.save();
c.clipPath(clip);
p.setColor(0xFF1B263B);
c.drawRect(r, p);
float s = Math.max(r.width() / bitmap.getWidth(), r.height() / bitmap.getHeight());
float w = bitmap.getWidth() * s, h = bitmap.getHeight() * s;
c.drawBitmap(
bitmap,
null,
new RectF(
r.centerX() - w / 2, r.centerY() - h / 2, r.centerX() + w / 2, r.centerY() + h / 2),
p);
if (progress > 0) {
p.setColor(0xA0080D18);
c.drawRect(r.left, r.bottom - dp(getContext(), 4), r.right, r.bottom, p);
p.setColor(0xFFE8CBA6);
c.drawRect(
r.left, r.bottom - dp(getContext(), 4), r.left + r.width() * progress, r.bottom, p);
}
c.restore();
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(dp(getContext(), 1.5f));
p.setColor(0xDBF4E8D8);
c.drawRoundRect(r, dp(getContext(), 12), dp(getContext(), 12), p);
p.setStyle(Paint.Style.FILL);
}
}
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
start();
}
@Override
public void onStart() {
Bundle result = new Bundle();
StringBuilder report = new StringBuilder();
try {
Activity a =
startActivitySync(
new Intent(Intent.ACTION_MAIN)
.setComponent(
new ComponentName("tv.luma.launcher", "tv.luma.launcher.MainActivity"))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
Thread.sleep(2500);
Class<?> type = Class.forName("tv.luma.launcher.AppTile");
Constructor<?> constructor =
type.getDeclaredConstructor(Context.class, String.class, int.class, boolean.class);
constructor.setAccessible(true);
Object[] tile = {null};
View[] art = {null};
Reference[] reference = {null};
FrameLayout[] overlay = {null};
runOnMainSync(
() -> {
try {
tile[0] = constructor.newInstance(a, "Sample", 150, false);
art[0] = (View) get(tile[0], "art");
((LinearLayout) tile[0]).removeView(art[0]);
set(art[0], "focus", true);
overlay[0] = new FrameLayout(a);
overlay[0].setBackgroundColor(0xFF080D18);
reference[0] = new Reference(a);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(512, 288);
lp.leftMargin = 200;
lp.topMargin = 200;
overlay[0].addView(reference[0], lp);
overlay[0].addView(art[0], new FrameLayout.LayoutParams(lp));
((FrameLayout) get(a, "root"))
.addView(overlay[0], new FrameLayout.LayoutParams(-1, -1));
} catch (Exception e) {
throw new RuntimeException(e);
}
});
Method image = type.getDeclaredMethod("bitmap", Bitmap.class);
image.setAccessible(true);
for (int mode = 0; mode < 3; mode++) {
int w = mode == 1 ? 100 : 360, h = mode == 1 ? 300 : 160;
Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Paint p = new Paint();
p.setShader(
new LinearGradient(
0, 0, w, h, mode == 2 ? 0x00000000 : Color.RED, Color.CYAN, Shader.TileMode.CLAMP));
new Canvas(b).drawRect(0, 0, w, h, p);
if (mode != 2) b.setHasAlpha(false);
final float progress = mode == 2 ? .65f : 0;
runOnMainSync(
() -> {
try {
image.invoke(tile[0], b);
set(art[0], "progress", progress);
reference[0].bitmap = b;
reference[0].progress = progress;
reference[0].setVisibility(View.VISIBLE);
reference[0].invalidate();
art[0].setVisibility(View.INVISIBLE);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
Thread.sleep(150);
Bitmap before = capture(a);
runOnMainSync(
() -> {
reference[0].setVisibility(View.INVISIBLE);
art[0].setVisibility(View.VISIBLE);
art[0].invalidate();
});
Thread.sleep(150);
Bitmap after = capture(a);
int worst = 0;
for (int y = 206; y < 483; y += 3)
for (int x = 230; x < 682; x += 3) {
int aa = before.getPixel(x, y), bb = after.getPixel(x, y);
for (int shift : new int[] {0, 8, 16})
worst = Math.max(worst, Math.abs(((aa >> shift) & 255) - ((bb >> shift) & 255)));
}
if (worst > 3)
throw new AssertionError("tile crop/pixels changed by " + worst + " mode=" + mode);
if (after.getPixel(202, 202) != 0xFF080D18)
throw new AssertionError("bitmap leaks outside rounded corner");
report
.append("PASS: tile crop/opacity/progress mode ")
.append(mode)
.append("; max pixel difference ")
.append(worst)
.append('\n');
before.recycle();
after.recycle();
}
runOnMainSync(
() -> {
try {
image.invoke(tile[0], new Object[] {null});
} catch (Exception e) {
throw new RuntimeException(e);
}
});
if (get(art[0], "imageShader") != null
|| ((Paint) get(art[0], "imagePaint")).getShader() != null)
throw new AssertionError("tile shader retains released image");
Bitmap shadow = (Bitmap) get(tile[0], "shadowMask");
if (shadow.getConfig() != Bitmap.Config.ALPHA_8 || shadow.getAllocationByteCount() > 24576)
throw new AssertionError("shadow exceeds small alpha texture budget");
report
.append("PASS: shader releases images; shared shadow uses ")
.append(shadow.getAllocationByteCount())
.append(" bytes\n");
result.putString("stream", report.toString());
finish(Activity.RESULT_OK, result);
} catch (Throwable t) {
result.putString("stream", report + "FAIL: " + t + "\n");
finish(Activity.RESULT_CANCELED, result);
}
}
}

View file

@ -5,6 +5,7 @@ import android.app.Instrumentation;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import java.lang.reflect.Field;
@ -17,10 +18,12 @@ import java.util.concurrent.TimeUnit;
public final class WakeRegressionInstrumentation extends Instrumentation {
private Activity activity;
private final StringBuilder results = new StringBuilder();
private boolean testMemorySaver;
@Override
public void onCreate(Bundle arguments) {
super.onCreate(arguments);
testMemorySaver = arguments != null && "true".equals(arguments.getString("memorySaver"));
start();
}
@ -40,6 +43,9 @@ public final class WakeRegressionInstrumentation extends Instrumentation {
Object scene = field(activity, "scene");
Bitmap wallpaper = (Bitmap) field(scene, "wallpaper");
Bitmap frame = (Bitmap) field(scene, "frame");
Bitmap mask = (Bitmap) field(scene, "mask");
if ((boolean) field(scene, "useTintMask")
&& (mask == null || mask.getWidth() > 320 || mask.getHeight() > 180)) return false;
if (frame == null || frame.isRecycled() || frame.getWidth() > 960 || frame.getHeight() > 540)
return false;
// A decoded source alone must not conceal a missing or blank composed background.
@ -72,7 +78,13 @@ public final class WakeRegressionInstrumentation extends Instrumentation {
@Override
public void onStart() {
Bundle result = new Bundle();
SharedPreferences prefs = getTargetContext().getSharedPreferences("luma", 0);
boolean hadSetting = prefs.contains("memorySaver"),
original = prefs.getBoolean("memorySaver", false);
int status = Activity.RESULT_OK;
try {
if (testMemorySaver && !prefs.edit().putBoolean("memorySaver", true).commit())
throw new AssertionError("could not save memory preference");
activity =
startActivitySync(
new Intent(Intent.ACTION_MAIN)
@ -81,6 +93,8 @@ public final class WakeRegressionInstrumentation extends Instrumentation {
new ComponentName("tv.luma.launcher", "tv.luma.launcher.MainActivity"))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
awaitImages("cold launch loads all app icons and wallpaper");
if (testMemorySaver && !(boolean) field(field(activity, "scene"), "useTintMask"))
throw new AssertionError("saved memory preference was not loaded");
ThreadPoolExecutor worker = (ThreadPoolExecutor) field(activity, "work");
CountDownLatch blocked = new CountDownLatch(1), release = new CountDownLatch(1);
worker.execute(
@ -196,7 +210,10 @@ public final class WakeRegressionInstrumentation extends Instrumentation {
throw new AssertionError("focus shadow still animating after stop");
}
Object scene = field(activity, "scene");
for (String name : new String[] {"wallpaper", "mediaArt", "frame", "previousFrame"})
for (String name :
new String[] {
"wallpaper", "mediaArt", "frame", "previousFrame", "mask", "previousMask"
})
if (field(scene, name) != null)
throw new AssertionError("background retained " + name);
if (!((ThreadPoolExecutor) field(scene, "renderer")).getQueue().isEmpty())
@ -240,12 +257,39 @@ public final class WakeRegressionInstrumentation extends Instrumentation {
});
awaitImages("stop/start recovery cycle " + (i + 1));
}
result.putString("stream", results.toString());
finish(Activity.RESULT_OK, result);
if (testMemorySaver) {
for (boolean enabled : new boolean[] {false, true}) {
runOnMainSync(
() -> {
try {
Object scene = field(activity, "scene");
java.lang.reflect.Method method =
scene.getClass().getDeclaredMethod("setMemorySaver", boolean.class);
method.setAccessible(true);
method.invoke(scene, enabled);
} catch (Exception e) {
throw new RuntimeException(e);
}
});
awaitImages("runtime memory saver switch " + enabled + " restores background");
}
}
} catch (Throwable error) {
result.putString("stream", results + "FAIL: " + error + "\n");
finish(Activity.RESULT_CANCELED, result);
results.append("FAIL: ").append(error).append('\n');
status = Activity.RESULT_CANCELED;
} finally {
if (testMemorySaver) {
SharedPreferences.Editor edit = prefs.edit();
if (hadSetting) edit.putBoolean("memorySaver", original);
else edit.remove("memorySaver");
if (!edit.commit()) {
results.append("FAIL: could not restore memory preference\n");
status = Activity.RESULT_CANCELED;
}
}
}
result.putString("stream", results.toString());
finish(status, result);
}
private void block(CountDownLatch entered, CountDownLatch release) {