diff --git a/AGENTS.md b/AGENTS.md index a645f1e..b5e4b92 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -8,7 +8,7 @@ Follow Android and Android TV best practices. Keep Luma portable across current - 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. +- Preserve installed launchers unless the user explicitly authorizes their removal. Preserve user preferences and accessibility configuration during development and testing. Restore temporary test changes. ## Keys and security diff --git a/README.md b/README.md index 2e86bf8..17af55d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Luma for Android TV -A native, remote-first Android TV launcher designed for limited-memory streamers and integrated TVs. It is installed alongside Projectivy as `tv.luma.launcher`; Projectivy remains available as a fallback. +A native, remote-first Android TV launcher designed for limited-memory streamers and integrated TVs. Its package name is `tv.luma.launcher`. -Version **1.1.11** reuses unchanged app tiles when returning Home and avoids reloading already displayed Plex artwork. Every resume restores missing images, including when Android briefly pauses the launcher without stopping it. Leaving the launcher releases image memory. Updates can be installed directly from the TV; physical-input controls appear on compatible TVs. +Version **1.1.12** removes obsolete alternate-launcher integration, avoids redundant screen-on window updates during navigation, and waits for focus to settle before transitioning app background colors. Every resume restores missing images, including when Android briefly pauses the launcher without stopping it. Leaving the launcher releases image memory. Updates can be installed directly from the TV; physical-input controls appear on compatible TVs. ## Use it -Press **Home**, or open **Luma** from Projectivy's app list. Set `LUMA_ADB_DEVICE` to your connected ADB device address to open it from a computer: +Press **Home** after configuring Home routing, or open **Luma** from Android's app list. Set `LUMA_ADB_DEVICE` to your connected ADB device address to open it from a computer: ```sh .tools/platform-tools/adb -s "$LUMA_ADB_DEVICE" shell am start -n tv.luma.launcher/.MainActivity @@ -20,13 +20,11 @@ Press **Home**, or open **Luma** from Projectivy's app list. Set `LUMA_ADB_DEVIC ## Default launcher and Home routing -**Settings → Default launcher** provides Android's Home app chooser, a Home button override toggle, and a direct Projectivy fallback. Enabling the override opens Android Accessibility settings; enable **Luma Home button** there. Turning it off in Luma disables only Luma's accessibility service. +**Settings → Default launcher** provides Android's Home app chooser and a Home button override toggle. Use the native chooser where supported. On devices that keep routing Home to Google TV, enable **Luma Home button** in Android Accessibility settings. Turning the override off in Luma disables only Luma's own service. -On this onn. device, Android records Luma as the Home role holder but still resolves Home to Google's launcher. Luma's accessibility workaround redirects that stock Home window and handles Home key events where Android delivers them. It runs in a separate small `:home` process so the launcher UI and its artwork can still be reclaimed while another app runs. It requests window-state events only from Google Home and Projectivy, without permission to retrieve window content. It has no polling loop or network work. +The event-driven helper handles Home keys where Android delivers them and redirects Google's stock Home window. It runs in a separate small `:home` process so artwork memory can be reclaimed when another app opens. It cannot retrieve window content and has no polling loop or network work. Android's stock launcher remains installed. -Projectivy's **Settings → General → Override current launcher** is switched off to avoid competing Home handlers. Projectivy's application and accessibility service, and Button Mapper's accessibility service, remain enabled. The Projectivy app tile and **Open Projectivy** deliberately allow the fallback to remain open until the next Home press. Back stays on Luma. - -To return to the previous routing, turn off Luma's Home override, then open Projectivy and re-enable **Override current launcher**. No launcher needs to be disabled or uninstalled. The native chooser uses Android's [Home role API](https://developer.android.com/reference/android/app/role/RoleManager); the workaround uses the documented [AccessibilityService callbacks](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService). +The native chooser uses Android's [Home role API](https://developer.android.com/reference/android/app/role/RoleManager); the override uses documented [AccessibilityService callbacks](https://developer.android.com/reference/android/accessibilityservice/AccessibilityService). ## TV inputs @@ -46,7 +44,7 @@ Luma opens an available standard TV channel viewer, with Android's native `TvVie **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. App accent changes wait for a 160 ms pause in color selection, coalescing passing selections during rapid navigation while tile focus feedback stays immediate. Reduced motion applies colors immediately. **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. +Focus uses a 6.5% scale increase, a 160 ms transition, and an app-colored cached soft shadow. Background crossfades last 280 ms. App accent changes wait for a 250 ms pause in color selection, coalescing passing selections during rapid navigation while tile focus feedback stays immediate. Reduced motion applies colors immediately. **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. @@ -130,7 +128,7 @@ For a fresh macOS checkout, run `scripts/bootstrap.sh`, review/accept the SDK li The local build creates and reuses `.tools/luma-development.keystore`. Preserve that file to install future updates over the existing APK. It is ignored by source control. This is a development signing identity for your sideloaded build; configure your own signing identity before distributing it. -To remove only Luma, run `adb uninstall tv.luma.launcher`; Projectivy remains installed. No command in the build/install scripts disables another launcher or changes the default Home app. +To remove Luma, run `adb uninstall tv.luma.launcher`. No command in the build/install scripts disables another launcher or changes the default Home app. ## Device checks diff --git a/app/build.gradle b/app/build.gradle index d03f1ba..182f8bd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId 'tv.luma.launcher' minSdk 26 targetSdk 34 - versionCode 14 - versionName '1.1.11' + versionCode 15 + versionName '1.1.12' } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8; targetCompatibility JavaVersion.VERSION_1_8 } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index dd99523..35c9049 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,4 +1,4 @@ - + diff --git a/app/src/main/java/tv/luma/launcher/HomeControlReceiver.java b/app/src/main/java/tv/luma/launcher/HomeControlReceiver.java index 07ffd7c..289cfca 100644 --- a/app/src/main/java/tv/luma/launcher/HomeControlReceiver.java +++ b/app/src/main/java/tv/luma/launcher/HomeControlReceiver.java @@ -6,28 +6,11 @@ import android.content.Intent; /** Private, explicit cross-process controls; only Luma's own UID can call this receiver. */ public final class HomeControlReceiver extends BroadcastReceiver { - static final String FALLBACK = "tv.luma.launcher.ALLOW_PROJECTIVY"; static final String DISABLE = "tv.luma.launcher.DISABLE_HOME_OVERRIDE"; - static void setFallback(Context context, boolean allow) { - if (isFallback(context) == allow) return; - context - .getSharedPreferences("home-routing", Context.MODE_PRIVATE) - .edit() - .putBoolean("fallback", allow) - .apply(); - } - - static boolean isFallback(Context context) { - return context - .getSharedPreferences("home-routing", Context.MODE_PRIVATE) - .getBoolean("fallback", false); - } - @Override public void onReceive(Context context, Intent intent) { - if (FALLBACK.equals(intent.getAction())) setFallback(context, true); - else if (DISABLE.equals(intent.getAction()) && LumaHomeService.active != null) { + if (DISABLE.equals(intent.getAction()) && LumaHomeService.active != null) { LumaHomeService.active.disableSelf(); } } diff --git a/app/src/main/java/tv/luma/launcher/LumaHomeService.java b/app/src/main/java/tv/luma/launcher/LumaHomeService.java index 5fb5876..d354954 100644 --- a/app/src/main/java/tv/luma/launcher/LumaHomeService.java +++ b/app/src/main/java/tv/luma/launcher/LumaHomeService.java @@ -18,7 +18,6 @@ public final class LumaHomeService extends AccessibilityService { public boolean onKeyEvent(KeyEvent event) { if (event.getKeyCode() != KeyEvent.KEYCODE_HOME) return false; if (event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() == 0) { - HomeControlReceiver.setFallback(this, false); openLuma(); } return true; @@ -32,11 +31,6 @@ public final class LumaHomeService extends AccessibilityService { // Class names only: no view hierarchy, text, screenshots, or content inspection. if (pkg.equals("com.google.android.apps.tv.launcherx") && cls.equals("com.google.android.apps.tv.launcherx.home.HomeActivity")) { - HomeControlReceiver.setFallback(this, false); - openLuma(); - } else if (pkg.equals("com.spocky.projengmenu") - && cls.equals("com.spocky.projengmenu.ui.home.MainActivity") - && !HomeControlReceiver.isFallback(this)) { openLuma(); } } diff --git a/app/src/main/java/tv/luma/launcher/MainActivity.java b/app/src/main/java/tv/luma/launcher/MainActivity.java index f864080..fbbce89 100644 --- a/app/src/main/java/tv/luma/launcher/MainActivity.java +++ b/app/src/main/java/tv/luma/launcher/MainActivity.java @@ -389,7 +389,7 @@ public final class MainActivity extends Activity { currentDialog = null; saverDownloading = false; } - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setKeepScreenOn(false); handler.removeCallbacks(idleSaver); stopSaver(false); scene.pause(); @@ -690,10 +690,6 @@ public final class MainActivity extends Activity { } private void launch(AppRepository.App a) { - if (a.component.getPackageName().equals("com.spocky.projengmenu")) { - fallback(); - return; - } try { Intent i = new Intent(Intent.ACTION_MAIN) @@ -706,34 +702,6 @@ public final class MainActivity extends Activity { } } - private void fallback() { - // Wait for the private router process to allow this explicit fallback launch. - sendOrderedBroadcast( - new Intent(this, HomeControlReceiver.class).setAction(HomeControlReceiver.FALLBACK), - null, - new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - openProjectivy(); - } - }, - handler, - Activity.RESULT_OK, - null, - null); - } - - private void openProjectivy() { - try { - Intent i = getPackageManager().getLeanbackLaunchIntentForPackage("com.spocky.projengmenu"); - if (i == null) i = getPackageManager().getLaunchIntentForPackage("com.spocky.projengmenu"); - if (i != null) startActivity(i); - else toast("Projectivy is not available"); - } catch (Exception e) { - toast("Unable to open Projectivy"); - } - } - @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); @@ -861,7 +829,10 @@ public final class MainActivity extends Activity { : "A new Luma version is available", this::updatesSettings); action( - p, "Default launcher", "Home button routing and fallback", this::defaultLauncherSettings); + p, + "Default launcher", + "Home button routing and system defaults", + this::defaultLauncherSettings); action( p, "Plex media rows", @@ -881,14 +852,6 @@ public final class MainActivity extends Activity { toast("Settings unavailable"); } }); - action( - p, - "Open Projectivy", - "Your existing launcher is always available", - () -> { - dismiss(); - fallback(); - }); action( p, "About Luma", @@ -1199,8 +1162,7 @@ public final class MainActivity extends Activity { "System Home: " + (nativeHome ? "Luma" : "Managed by this TV") + "\nHome button override: " - + (enabled ? "On" : "Off") - + "\nProjectivy stays installed and available as your fallback."); + + (enabled ? "On" : "Off")); action( p, "Choose default Home app", @@ -1253,8 +1215,7 @@ public final class MainActivity extends Activity { panel( "Enable Home routing", "In Android Accessibility, enable Luma Home button.\n\n" - + "In Projectivy settings → General, turn off Override current launcher to" - + " avoid competing Home handlers. Projectivy itself stays available."); + + "This routes the Home button to Luma."); action( help, "Open Accessibility settings", @@ -1273,14 +1234,6 @@ public final class MainActivity extends Activity { action(help, "Back", null, this::defaultLauncherSettings); } }); - action( - p, - "Open Projectivy", - "Use your fallback without turning Luma off", - () -> { - dismiss(); - fallback(); - }); action(p, "Back", null, this::showSettings); } @@ -1492,7 +1445,7 @@ public final class MainActivity extends Activity { "No ads or analytics. Wallpaper, app artwork, and Plex requests stop when another app" + " opens. Image caches are bounded and cleared when Luma leaves the screen.\n\n" + "Menu opens settings. Hold OK on an app to customize it. Back stays on Luma. Open" - + " Projectivy from Settings or its app tile.\n\n" + + " Android settings from Luma settings.\n\n" + "Manage Home routing and scheduled update checks in Settings.", 13, Ui.MUTED); @@ -1995,12 +1948,19 @@ public final class MainActivity extends Activity { return super.dispatchTouchEvent(event); } + private void setKeepScreenOn(boolean enabled) { + int flag = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; + boolean current = (getWindow().getAttributes().flags & flag) != 0; + if (current == enabled) return; + if (enabled) getWindow().addFlags(flag); + else getWindow().clearFlags(flag); + } + private void resetSaverTimer() { handler.removeCallbacks(idleSaver); int minutes = prefs.getInt("saverTimeout", 10); - if (foreground && (minutes > 0 || saver != null)) - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); - else getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + if (foreground && (minutes > 0 || saver != null)) setKeepScreenOn(true); + else setKeepScreenOn(false); if (foreground && saver == null && currentDialog == null && minutes > 0) handler.postDelayed(idleSaver, minutes * 60000L); } @@ -2013,7 +1973,7 @@ public final class MainActivity extends Activity { scene.pause(); scroll.stopAnimation(); saver = new SaverView(this); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setKeepScreenOn(true); root.addView(saver, new FrameLayout.LayoutParams(-1, -1)); saver.requestFocus(); } @@ -2023,7 +1983,7 @@ public final class MainActivity extends Activity { saver.stop(); root.removeView(saver); saver = null; - getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); + setKeepScreenOn(false); if (resume && foreground) { scene.resume(); AppTile tile = tiles.get(selected); diff --git a/app/src/main/java/tv/luma/launcher/SceneView.java b/app/src/main/java/tv/luma/launcher/SceneView.java index fb4048c..a715283 100644 --- a/app/src/main/java/tv/luma/launcher/SceneView.java +++ b/app/src/main/java/tv/luma/launcher/SceneView.java @@ -32,7 +32,7 @@ final class SceneView extends View { private ValueAnimator animator, colorAnimator; private boolean useTintMask; private boolean accentPending; - // Let the 160 ms focus lift finish; passing selections need no full-screen transition. + // Keep full-screen color work out of continuous D-pad navigation; tile focus stays immediate. private final Runnable accentUpdate = () -> { accentPending = false; @@ -120,7 +120,7 @@ final class SceneView extends View { targetAccent = color; removeCallbacks(accentUpdate); accentPending = animate && motion && active && frame != null; - if (accentPending) postDelayed(accentUpdate, 160); + if (accentPending) postDelayed(accentUpdate, 250); else applyAccent(color, animate); } @@ -132,6 +132,8 @@ final class SceneView extends View { return; } if (colorAnimator != null) colorAnimator.cancel(); + // Coalesced navigation may return to the color that is already displayed. + if (accent == color) return; if (!animate || !motion || frame == null) { accent = color; invalidate(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6ee8671..a4b0248 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,4 @@ Luma Home button - Opens Luma when you press Home or the stock launcher appears. Does not read screen content. Projectivy remains available from Luma settings. Turn off other launcher Home overrides to avoid conflicts. + Opens Luma when you press Home or the stock launcher appears. Does not read screen content. Turn off other launcher Home overrides to avoid conflicts. diff --git a/app/src/main/res/xml/home_accessibility.xml b/app/src/main/res/xml/home_accessibility.xml index 2da87d4..fa626f5 100644 --- a/app/src/main/res/xml/home_accessibility.xml +++ b/app/src/main/res/xml/home_accessibility.xml @@ -1,6 +1,6 @@ [] {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"); diff --git a/tests/device/AndroidManifest.xml b/tests/device/AndroidManifest.xml index 2fe1032..acffcda 100644 --- a/tests/device/AndroidManifest.xml +++ b/tests/device/AndroidManifest.xml @@ -11,4 +11,6 @@ + + diff --git a/tests/device/JankInstrumentation.java b/tests/device/JankInstrumentation.java new file mode 100644 index 0000000..ee47a05 --- /dev/null +++ b/tests/device/JankInstrumentation.java @@ -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 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); + } +} diff --git a/tests/device/WindowFlagsInstrumentation.java b/tests/device/WindowFlagsInstrumentation.java new file mode 100644 index 0000000..2fded96 --- /dev/null +++ b/tests/device/WindowFlagsInstrumentation.java @@ -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); + } +} diff --git a/tests/device/jank-trace.pbtxt b/tests/device/jank-trace.pbtxt new file mode 100644 index 0000000..6c5e101 --- /dev/null +++ b/tests/device/jank-trace.pbtxt @@ -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" } }