Optimize portable tile rendering and add optional memory saver
This commit is contained in:
parent
5bb15fa69e
commit
25ea43bea7
18 changed files with 918 additions and 63 deletions
|
|
@ -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>
|
||||
|
|
|
|||
124
tests/device/NavigationInstrumentation.java
Normal file
124
tests/device/NavigationInstrumentation.java
Normal 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);
|
||||
}
|
||||
}
|
||||
270
tests/device/RenderingInstrumentation.java
Normal file
270
tests/device/RenderingInstrumentation.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
230
tests/device/TileRenderingInstrumentation.java
Normal file
230
tests/device/TileRenderingInstrumentation.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue