App 2.19.1: Foreground apps diagnostic on the Logs tab

Read-only: recent foreground apps (usage events), open tasks,
policy_control and the status bar height, for finding the CarPlay
package before a full-screen experiment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-23 20:30:54 +02:00
co-authored by Claude Opus 5.5
parent 461f9d5578
commit 209a231511
9 changed files with 345 additions and 7 deletions
@@ -0,0 +1,69 @@
package com.evsuite.abrp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;
import org.junit.Test;
/** The Logs tab's foreground-app lines — pure JVM. */
public class ForegroundHistoryTest {
private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
private static ForegroundHistory.Event at(long seconds, String pkg, String cls) {
return new ForegroundHistory.Event(seconds * 1000, pkg, cls);
}
@Test
public void newestFirstWithTheActivityShortened() {
List<String> lines = ForegroundHistory.lines(Arrays.asList(
at(3600, "com.saic.launcher", "com.saic.launcher.Home"),
at(3700, "com.example.carplay", "com.example.carplay.ui.ProjectionActivity")),
10, UTC);
assertEquals(Arrays.asList(
"01:01:40 com.example.carplay .ui.ProjectionActivity",
"01:00:00 com.saic.launcher .Home"), lines);
}
@Test
public void repeatsOfTheSameScreenCollapse() {
List<String> lines = ForegroundHistory.lines(Arrays.asList(
at(1, "a.b", "a.b.Main"),
at(2, "a.b", "a.b.Main"),
at(3, "a.b", "a.b.Other"),
at(4, "c.d", null),
at(5, "c.d", null)), 10, UTC);
assertEquals(Arrays.asList(
"00:00:04 c.d",
"00:00:03 a.b .Other",
"00:00:01 a.b .Main"), lines);
}
@Test
public void limitKeepsTheNewest() {
List<String> lines = ForegroundHistory.lines(Arrays.asList(
at(1, "one", null), at(2, "two", null), at(3, "three", null)), 2, UTC);
assertEquals(Arrays.asList("00:00:03 three", "00:00:02 two"), lines);
}
@Test
public void emptyAndBlankEventsGiveNoLines() {
assertTrue(ForegroundHistory.lines(Collections.emptyList(), 10, UTC).isEmpty());
assertTrue(ForegroundHistory.lines(Arrays.asList(null, at(1, "", null), at(2, null, "x")), 10, UTC).isEmpty());
}
@Test
public void aClassOutsideItsPackageStaysWhole() {
assertEquals("com.other.Activity", ForegroundHistory.shortClass("a.b", "com.other.Activity"));
assertEquals(".Main", ForegroundHistory.shortClass("a.b", "a.b.Main"));
assertNull(ForegroundHistory.shortClass("a.b", null));
// "a.bc.Main" is not inside "a.b".
assertEquals("a.bc.Main", ForegroundHistory.shortClass("a.b", "a.bc.Main"));
}
}