Files
mg4/app/src/test/java/com/evsuite/abrp/SteeringKeyReportTest.java
T
nilsandClaude Opus 5.5 55710fb722 App 2.7.1: voice-key double press works; floating button removed
The car's key report, from the on-screen key log in 2.7.0:
android.intent.extra.hardkey.keycode = 287 (Integer),
android.intent.extra.hardkey.down (Boolean; one report on press, one on
release) and android.intent.extra.hardkey.longpress (Boolean). 2.7.0
only looked for short names like "keyCode", so it never found the code.
SteeringKeyReport now matches extras by the last part of their name,
case-insensitively, and is Android-free; its tests include the exact
double press logged on the car (releases 279 ms apart). Replayed in the
car's format on the emulator: double press opens the app, single and
long presses do not.

The floating button is removed (class, geometry and test, the overlay
permission, setting, switch and strings): it did not show over the MG4
launcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QLJfZQZeAKAwSqViTmLzki
2026-10-17 23:38:36 +02:00

67 lines
2.3 KiB
Java

package com.evsuite.abrp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
/** Reading the head unit's key reports, as seen on the MG4 — pure JVM. */
public class SteeringKeyReportTest {
private static Map<String, Object> car(int code, boolean down, boolean longPress) {
Map<String, Object> m = new HashMap<>();
m.put("android.intent.extra.hardkey.keycode", code);
m.put("android.intent.extra.hardkey.down", down);
m.put("android.intent.extra.hardkey.longpress", longPress);
return m;
}
@Test
public void readsTheMg4Format() {
SteeringKeyReport r = SteeringKeyReport.parse(car(287, true, false));
assertEquals(Integer.valueOf(287), r.code);
assertEquals(Boolean.TRUE, r.down);
assertFalse(r.longPress);
assertEquals(Boolean.FALSE, SteeringKeyReport.parse(car(287, false, false)).down);
assertTrue(SteeringKeyReport.parse(car(287, true, true)).longPress);
}
@Test
public void theDoublePressFromTheCarOpensTheApp() {
// The sequence logged on the MG4 at 23:31:02: down .300, up .442, down .545, up .721.
DoublePressDetector d = new DoublePressDetector(SteeringKeyListener.VOICE_KEY);
long[] at = {300, 442, 545, 721};
boolean[] down = {true, false, true, false};
boolean opened = false;
for (int i = 0; i < at.length; i++) {
SteeringKeyReport r = SteeringKeyReport.parse(car(287, down[i], false));
opened |= d.accept(r.code, r.down, r.longPress, at[i]);
}
assertTrue(opened);
}
@Test
public void simpleNamesStillWork() {
Map<String, Object> m = new HashMap<>();
m.put("keyCode", 17);
m.put("action", 1);
SteeringKeyReport r = SteeringKeyReport.parse(m);
assertEquals(Integer.valueOf(17), r.code);
assertEquals(Boolean.FALSE, r.down);
}
@Test
public void nothingUsableStaysUnknown() {
SteeringKeyReport r = SteeringKeyReport.parse(new HashMap<>());
assertNull(r.code);
assertNull(r.down);
assertFalse(r.longPress);
assertNull(SteeringKeyReport.parse(null).code);
}
}