Remove obsolete launcher integration and reduce navigation jank
This commit is contained in:
parent
ac0a892c5f
commit
2739b278cd
21 changed files with 394 additions and 129 deletions
|
|
@ -90,7 +90,7 @@ public final class AccentSchedulingInstrumentation extends Instrumentation {
|
|||
call("setMotion", new Class<?>[] {boolean.class}, true);
|
||||
for (int color : new int[] {Color.RED, Color.CYAN, Color.GREEN}) {
|
||||
color(color, true);
|
||||
Thread.sleep(60);
|
||||
Thread.sleep(200);
|
||||
if (get("frame") != frame || (int) get("generation") != generation)
|
||||
throw new AssertionError("passing selection composed a background");
|
||||
}
|
||||
|
|
@ -105,6 +105,24 @@ public final class AccentSchedulingInstrumentation extends Instrumentation {
|
|||
.append("PASS: coalesced passing colors, retained final color; memorySaver=")
|
||||
.append(memory)
|
||||
.append('\n');
|
||||
color(Color.WHITE, false);
|
||||
settled();
|
||||
Object settledFrame = get("frame"), settledAnimator = get("colorAnimator");
|
||||
int settledGeneration = (int) get("generation");
|
||||
color(Color.RED, true);
|
||||
Thread.sleep(200);
|
||||
color(Color.WHITE, true);
|
||||
settled();
|
||||
if (get("frame") != settledFrame
|
||||
|| (int) get("generation") != settledGeneration
|
||||
|| get("colorAnimator") != settledAnimator)
|
||||
throw new AssertionError("returning to the displayed color started redundant work");
|
||||
report
|
||||
.append(
|
||||
"PASS: returning to displayed color needs no composition or color animation;"
|
||||
+ " memorySaver=")
|
||||
.append(memory)
|
||||
.append('\n');
|
||||
color(Color.MAGENTA, true);
|
||||
call("pause", new Class<?>[0]);
|
||||
generation = (int) get("generation");
|
||||
|
|
|
|||
|
|
@ -11,4 +11,6 @@
|
|||
<instrumentation android:name=".WarmReturnInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
|
||||
<instrumentation android:name="tv.luma.launcher.PlexArtworkInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
|
||||
<instrumentation android:name=".GridReuseInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
|
||||
<instrumentation android:name=".JankInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
|
||||
<instrumentation android:name=".WindowFlagsInstrumentation" android:targetPackage="tv.luma.launcher" android:functionalTest="true" />
|
||||
</manifest>
|
||||
|
|
|
|||
155
tests/device/JankInstrumentation.java
Normal file
155
tests/device/JankInstrumentation.java
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
package tv.luma.launcher.tests;
|
||||
|
||||
import android.app.*;
|
||||
import android.content.*;
|
||||
import android.graphics.*;
|
||||
import android.os.*;
|
||||
import android.view.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Current gfxinfo jank with original or matched app pairs; runtime isolations never change
|
||||
* defaults.
|
||||
*/
|
||||
public final class JankInstrumentation extends Instrumentation {
|
||||
private String mode = "matched", memory = "keep";
|
||||
|
||||
private Object get(Object o, String n) throws Exception {
|
||||
Field f = o.getClass().getDeclaredField(n);
|
||||
f.setAccessible(true);
|
||||
return f.get(o);
|
||||
}
|
||||
|
||||
private void call(Object o, String n, Class<?>[] types, Object... args) throws Exception {
|
||||
Method m = o.getClass().getDeclaredMethod(n, types);
|
||||
m.setAccessible(true);
|
||||
runOnMainSync(
|
||||
() -> {
|
||||
try {
|
||||
m.invoke(o, args);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String shell(String cmd) throws Exception {
|
||||
try (ParcelFileDescriptor fd = getUiAutomation().executeShellCommand(cmd);
|
||||
InputStream in = new ParcelFileDescriptor.AutoCloseInputStream(fd);
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
|
||||
byte[] b = new byte[8192];
|
||||
int n;
|
||||
while ((n = in.read(b)) != -1) out.write(b, 0, n);
|
||||
return out.toString("UTF-8");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle b) {
|
||||
super.onCreate(b);
|
||||
if (b != null) {
|
||||
mode = b.getString("mode", "matched");
|
||||
memory = b.getString("memory", "keep");
|
||||
}
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
Bundle result = new Bundle();
|
||||
StringBuilder report = new StringBuilder();
|
||||
int status = Activity.RESULT_OK;
|
||||
SharedPreferences p = getTargetContext().getSharedPreferences("luma", 0);
|
||||
Map<String, ?> old = new HashMap<>(p.getAll());
|
||||
try {
|
||||
SharedPreferences.Editor edit = p.edit().putBoolean("media", false);
|
||||
if (!mode.equals("original"))
|
||||
edit.putString(
|
||||
"order", "com.plexapp.android,com.spotify.tv.android," + p.getString("order", ""));
|
||||
if (mode.equals("fixed")) edit.putInt("accent", 0xff5b4125);
|
||||
else edit.putInt("accent", 0);
|
||||
if (!edit.commit()) throw new AssertionError("test preferences");
|
||||
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);
|
||||
Object scene = get(a, "scene");
|
||||
if (!memory.equals("keep"))
|
||||
call(scene, "setMemorySaver", new Class<?>[] {boolean.class}, memory.equals("on"));
|
||||
call(scene, "configure", new Class<?>[] {String.class, float.class}, "alpine", .2f);
|
||||
call(scene, "setMotion", new Class<?>[] {boolean.class}, true);
|
||||
Map<?, ?> tiles = (Map<?, ?>) get(a, "tiles");
|
||||
View[] items = tiles.values().toArray(new View[0]);
|
||||
if (items.length < 2) throw new AssertionError("insufficient app tiles");
|
||||
if (!mode.equals("original")
|
||||
&& (!items[0].getTag().equals("com.plexapp.android")
|
||||
|| !items[1].getTag().equals("com.spotify.tv.android")))
|
||||
throw new AssertionError("matched pair unavailable");
|
||||
if (mode.equals("hidden")) runOnMainSync(() -> ((View) scene).setVisibility(View.INVISIBLE));
|
||||
if (mode.equals("noshadow"))
|
||||
runOnMainSync(
|
||||
() -> {
|
||||
for (View tile : items)
|
||||
try {
|
||||
((Paint) get(tile, "shadowPaint"))
|
||||
.setColorFilter(
|
||||
new PorterDuffColorFilter(Color.TRANSPARENT, PorterDuff.Mode.SRC_IN));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
runOnMainSync(items[0]::requestFocus);
|
||||
Thread.sleep(900);
|
||||
report
|
||||
.append("mode=")
|
||||
.append(mode)
|
||||
.append(" memorySaver=")
|
||||
.append(get(scene, "useTintMask"))
|
||||
.append(" pair=")
|
||||
.append(items[0].getTag())
|
||||
.append(',')
|
||||
.append(items[1].getTag())
|
||||
.append('\n');
|
||||
shell("dumpsys gfxinfo tv.luma.launcher reset");
|
||||
Trace.beginSection("LumaJankWorkload");
|
||||
long start = SystemClock.uptimeMillis();
|
||||
for (int i = 0; i < 60; i++) {
|
||||
long due = start + i * 200L;
|
||||
long wait = due - SystemClock.uptimeMillis();
|
||||
if (wait > 0) Thread.sleep(wait);
|
||||
sendKeyDownUpSync(i % 2 == 0 ? KeyEvent.KEYCODE_DPAD_RIGHT : KeyEvent.KEYCODE_DPAD_LEFT);
|
||||
}
|
||||
Thread.sleep(500);
|
||||
Trace.endSection();
|
||||
report
|
||||
.append("injected=60 elapsedMs=")
|
||||
.append(SystemClock.uptimeMillis() - start)
|
||||
.append('\n');
|
||||
report.append(shell("dumpsys gfxinfo tv.luma.launcher framestats"));
|
||||
report.append("\nPASS: current jank capture completed\n");
|
||||
} catch (Throwable t) {
|
||||
report.append("FAIL: ").append(t).append('\n');
|
||||
status = Activity.RESULT_CANCELED;
|
||||
} finally {
|
||||
SharedPreferences.Editor edit = p.edit();
|
||||
for (String k : new String[] {"order", "media", "accent"}) {
|
||||
Object v = old.get(k);
|
||||
if (!old.containsKey(k)) edit.remove(k);
|
||||
else if (v instanceof Boolean) edit.putBoolean(k, (Boolean) v);
|
||||
else if (v instanceof Integer) edit.putInt(k, (Integer) v);
|
||||
else edit.putString(k, (String) v);
|
||||
}
|
||||
if (!edit.commit()) {
|
||||
report.append("FAIL: preferences not restored\n");
|
||||
status = Activity.RESULT_CANCELED;
|
||||
}
|
||||
}
|
||||
result.putString("stream", report.toString());
|
||||
finish(status, result);
|
||||
}
|
||||
}
|
||||
102
tests/device/WindowFlagsInstrumentation.java
Normal file
102
tests/device/WindowFlagsInstrumentation.java
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
package tv.luma.launcher.tests;
|
||||
|
||||
import android.app.*;
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.view.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/** Repeated interaction must not dispatch identical window attributes and request relayout. */
|
||||
public final class WindowFlagsInstrumentation extends Instrumentation {
|
||||
@Override
|
||||
public void onCreate(Bundle b) {
|
||||
super.onCreate(b);
|
||||
start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
Bundle result = new Bundle();
|
||||
StringBuilder report = new StringBuilder();
|
||||
int status = Activity.RESULT_OK;
|
||||
SharedPreferences prefs = getTargetContext().getSharedPreferences("luma", 0);
|
||||
boolean existed = prefs.contains("saverTimeout");
|
||||
int original = prefs.getInt("saverTimeout", 10);
|
||||
Activity activity = null;
|
||||
Window.Callback callback = null;
|
||||
try {
|
||||
prefs.edit().putInt("saverTimeout", 10).commit();
|
||||
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(1800);
|
||||
final Activity a = activity;
|
||||
callback = a.getWindow().getCallback();
|
||||
final Window.Callback delegate = callback;
|
||||
AtomicInteger changes = new AtomicInteger();
|
||||
Window.Callback observer =
|
||||
(Window.Callback)
|
||||
Proxy.newProxyInstance(
|
||||
Window.Callback.class.getClassLoader(),
|
||||
new Class<?>[] {Window.Callback.class},
|
||||
(proxy, method, args) -> {
|
||||
if (method.getName().equals("onWindowAttributesChanged"))
|
||||
changes.incrementAndGet();
|
||||
try {
|
||||
return method.invoke(delegate, args);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw e.getCause();
|
||||
}
|
||||
});
|
||||
runOnMainSync(() -> a.getWindow().setCallback(observer));
|
||||
for (int i = 0; i < 20; i++) runOnMainSync(a::onUserInteraction);
|
||||
if (changes.get() != 0)
|
||||
throw new AssertionError(
|
||||
"repeated interaction dispatched " + changes.get() + " redundant window updates");
|
||||
report.append("PASS: twenty interactions caused zero redundant window-attribute updates\n");
|
||||
prefs.edit().putInt("saverTimeout", 0).commit();
|
||||
runOnMainSync(a::onUserInteraction);
|
||||
if (changes.get() != 1
|
||||
|| (a.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
!= 0) throw new AssertionError("screensaver Off did not release keep-screen-on once");
|
||||
runOnMainSync(a::onUserInteraction);
|
||||
if (changes.get() != 1)
|
||||
throw new AssertionError("repeated Off interaction updated the window");
|
||||
prefs.edit().putInt("saverTimeout", 10).commit();
|
||||
runOnMainSync(a::onUserInteraction);
|
||||
if (changes.get() != 2
|
||||
|| (a.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
== 0)
|
||||
throw new AssertionError("screensaver timer did not reacquire keep-screen-on once");
|
||||
runOnMainSync(() -> callActivityOnPause(a));
|
||||
if ((a.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
!= 0) throw new AssertionError("pause retained screen-on flag");
|
||||
runOnMainSync(() -> callActivityOnResume(a));
|
||||
if ((a.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
== 0) throw new AssertionError("resume did not restore timer screen-on flag");
|
||||
report.append("PASS: timeout changes and pause/resume update keep-screen-on correctly\n");
|
||||
} catch (Throwable error) {
|
||||
report.append("FAIL: ").append(error).append('\n');
|
||||
status = Activity.RESULT_CANCELED;
|
||||
} finally {
|
||||
if (activity != null && callback != null) {
|
||||
final Activity a = activity;
|
||||
final Window.Callback c = callback;
|
||||
runOnMainSync(() -> a.getWindow().setCallback(c));
|
||||
}
|
||||
SharedPreferences.Editor edit = prefs.edit();
|
||||
if (existed) edit.putInt("saverTimeout", original);
|
||||
else edit.remove("saverTimeout");
|
||||
if (!edit.commit()) {
|
||||
report.append("FAIL: timeout not restored\n");
|
||||
status = Activity.RESULT_CANCELED;
|
||||
}
|
||||
}
|
||||
result.putString("stream", report.toString());
|
||||
finish(status, result);
|
||||
}
|
||||
}
|
||||
17
tests/device/jank-trace.pbtxt
Normal file
17
tests/device/jank-trace.pbtxt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
buffers { size_kb: 65536 fill_policy: RING_BUFFER }
|
||||
duration_ms: 22000
|
||||
data_sources { config { name: "linux.ftrace" ftrace_config {
|
||||
ftrace_events: "sched/sched_switch"
|
||||
ftrace_events: "sched/sched_waking"
|
||||
ftrace_events: "power/cpu_frequency"
|
||||
ftrace_events: "power/cpu_idle"
|
||||
atrace_categories: "gfx"
|
||||
atrace_categories: "view"
|
||||
atrace_categories: "wm"
|
||||
atrace_categories: "dalvik"
|
||||
atrace_apps: "tv.luma.launcher"
|
||||
} } }
|
||||
data_sources { config { name: "linux.process_stats" process_stats_config { scan_all_processes_on_start: true proc_stats_poll_ms: 1000 } } }
|
||||
data_sources { config { name: "android.surfaceflinger.frametimeline" } }
|
||||
data_sources { config { name: "gpu.renderstages" } }
|
||||
data_sources { config { name: "android.gpu.memory" } }
|
||||
Loading…
Add table
Add a link
Reference in a new issue