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
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
package com.evsuite.abrp;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/** The floating button's position and tap rules — pure JVM. */
|
||||
public class FloatingButtonGeometryTest {
|
||||
|
||||
@Test
|
||||
public void startsAtTheRightEdgeAboutFortyPercentDown() {
|
||||
// The MG4 head unit is 1920 x 720; 64 px button, 16 px margin.
|
||||
assertArrayEquals(new int[]{1840, 288}, FloatingButtonGeometry.defaultPosition(1920, 720, 64, 16));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staysFullyOnScreen() {
|
||||
assertEquals(0, FloatingButtonGeometry.clamp(-50, 64, 1920));
|
||||
assertEquals(1856, FloatingButtonGeometry.clamp(5000, 64, 1920));
|
||||
assertEquals(700, FloatingButtonGeometry.clamp(700, 64, 1920));
|
||||
// A saved position from a larger screen still lands inside a smaller one.
|
||||
assertEquals(720 - 64, FloatingButtonGeometry.clamp(1000, 64, 720));
|
||||
// A screen smaller than the button pins it to the corner instead of going negative.
|
||||
assertEquals(0, FloatingButtonGeometry.clamp(10, 64, 40));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void aTouchWithinTheSlopIsATapAnythingFurtherADrag() {
|
||||
assertTrue(FloatingButtonGeometry.isTap(0, 0, 8));
|
||||
assertTrue(FloatingButtonGeometry.isTap(5, -6, 8)); // 7.8 px
|
||||
assertFalse(FloatingButtonGeometry.isTap(6, 6, 8)); // 8.5 px
|
||||
assertFalse(FloatingButtonGeometry.isTap(0, 40, 8));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user