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

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) {