From 8edca930e65d7a0670ed4ef49effe6d245e55c19 Mon Sep 17 00:00:00 2001 From: VysseCodes <205995085+VysseCodes@users.noreply.github.com> Date: Mon, 30 Nov 2026 18:58:39 -0600 Subject: [PATCH 1/5] Hooks on with an unverified map; the installer checks it and leaves a Car Report Owners without NEMESIS or adb couldn't turn HMG-API on: an unverified (mapped or probed) map ran only after engine verify-map passed on the car, and only the HMG-API app ran it, whose tile needs the hooks. NEMESIS owners got in through NEMESIS Manager's Launch. Seen on a 2024 Ioniq 5 (US 260903) installed from a USB stick. A map whose stock files match the car now runs unchecked; only a failed verify-map on that car turns it off ("Try unchecked maps" overrides). The installer runs engine install-check before the restart: checks the map and, when it isn't verified or there's none, writes a Car Report (also to the stick for a stick install). Tested off-car only (test-all.sh --fast, map, local-map, install, usb tests). --- CHANGELOG.md | 15 ++++++ core/runtime/java/hmgapi/engine/CarMap.java | 34 ++++++++++---- core/runtime/java/hmgapi/engine/Engine.java | 3 +- core/runtime/java/hmgapi/engine/MapCheck.java | 30 ++++++++++++ core/runtime/local-map-test.sh | 4 +- core/runtime/map-test.sh | 46 ++++++++++++++++--- install/common/install-test.sh | 3 ++ install/common/install.sh | 12 +++++ install/usb/troubleShooter | 2 +- 9 files changed, 130 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f898a92..3719f4ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,20 @@ # Changelog +## Unreleased + +- **HMG-API turns on without NEMESIS or adb on cars whose map isn't verified yet** (a 2024 + Ioniq 5, US 260903, installed from a USB stick: no tile after restarts). Hooks ran with an + unverified (`mapped` or `probed`) map only after `engine verify-map` passed on the car, and + only the HMG-API app could run it, whose tile needs the hooks; NEMESIS owners got in through + NEMESIS Manager's Launch. Now a map whose stock files match the car runs unchecked, and only a + failed `verify-map` on that car turns it off ("Try unchecked maps" runs it even then). The + installer checks the map itself before the restart (`engine install-check`), and when the map + isn't verified or there's none it leaves a Car Report, on the USB stick too for a stick + install (`HMG-API reports`). + +- **A root service can read its own settings** (`HmgApi.settings()`, `saveSettings()`): the + daemon sees such a service as root, so the client names its mod (`HMGAPI_MOD`). + ## 1.1.0 (2026-11-28) 1.1.0-rc.10's code: only the version, this heading and the release notes changed. It is the diff --git a/core/runtime/java/hmgapi/engine/CarMap.java b/core/runtime/java/hmgapi/engine/CarMap.java index 14ad9514..3ae85b3f 100644 --- a/core/runtime/java/hmgapi/engine/CarMap.java +++ b/core/runtime/java/hmgapi/engine/CarMap.java @@ -17,9 +17,9 @@ * * none no map for this car (make/model/region/firmware): hooks off * mismatch a map, but the car's framework isn't the one it was made from: hooks off - * mapped points found from the car's stock files, not checked on a car yet: - * runs if hmgapi.json "testing_maps" is true, or after this car passed - * `engine verify-map` (state/map-check.json) + * mapped points found from the car's stock files, not checked on a car yet: runs + * (its stock files match, or it would be mismatch), unless this car failed + * `engine verify-map` on it (state/map-check.json); "testing_maps" runs it even then * probed made on the car itself (engine map-car --write, from its own files): as mapped * verified checked on a real car: runs * @@ -212,13 +212,18 @@ static CarMap finish(String root, CarMap m, File maps, Map local boolean testing = m.testing; if ("verified".equals(m.status)) { m.runnable = true; - } else if (("mapped".equals(m.status) || "probed".equals(m.status)) && (m.checkedHere || testing)) { - m.runnable = true; + } else if ("mapped".equals(m.status) || "probed".equals(m.status)) { + // the owner's call (2026-11-30): a map whose stock files match runs without a + // check; only a failed check here stops it. The boot risk is app_process, which + // the installer's stock gate covers, and the zygote's boot guard catches a crash loop. + boolean failed = !m.checkedHere && checkFailedHere(root, m); + m.runnable = !failed || testing; m.reason = m.checkedHere ? "map checked on this car (not yet marked verified)" - : "map not checked on a car yet; running because hmgapi.json testing_maps is on"; + : failed ? (testing ? "the map failed `hmgapid engine verify-map` on this car; running because hmgapi.json testing_maps is on" + : "the map for " + m.car + " failed `hmgapid engine verify-map` on this car (state/map-check.json)") + : "map not checked on a car yet (its stock files match this car)"; } else { - m.reason = "the map for " + m.car + " isn't checked on a car yet: run `hmgapid engine verify-map`" - + " (or set hmgapi.json testing_maps to try it)"; + m.reason = "the map for " + m.car + " has status " + m.status + ": hooks off"; } } catch (Exception e) { m.status = "none"; @@ -341,6 +346,19 @@ static void drop(CarMap m, String app, String why) { } @SuppressWarnings("unchecked") + /** this map, as it is now, failed `engine verify-map` on this unit */ + static boolean checkFailedHere(String root, CarMap m) { + try { + File f = new File(root + "/data/hmgapi/state/map-check.json"); + if (!f.isFile()) return false; + Map c = Json.object(Engine.read(f)); + return Boolean.FALSE.equals(c.get("ok")) && m.folder.equals(c.get("folder")) + && String.valueOf(m.carJson.get("files")).equals(String.valueOf(c.get("files"))); + } catch (Exception e) { + return false; + } + } + static boolean checkedHere(String root, CarMap m) { try { File f = new File(root + "/data/hmgapi/state/map-check.json"); diff --git a/core/runtime/java/hmgapi/engine/Engine.java b/core/runtime/java/hmgapi/engine/Engine.java index 9557ac56..f16d9102 100644 --- a/core/runtime/java/hmgapi/engine/Engine.java +++ b/core/runtime/java/hmgapi/engine/Engine.java @@ -371,6 +371,7 @@ int run(String[] args) throws Exception { if ("status".equals(cmd)) return status(); if ("verify-map".equals(cmd)) return MapCheck.run(this); + if ("install-check".equals(cmd)) return MapCheck.afterInstall(this, args.length > 1 && "--usb".equals(args[1])); if ("map-car".equals(cmd)) return MapProbe.run(this, args); if ("report".equals(cmd)) return Report.run(this, args.length > 1 && "--usb".equals(args[1])); if ("problem".equals(cmd)) return ProblemLog.run(this, args); @@ -437,7 +438,7 @@ int run(String[] args) throws Exception { if (!map.runnable) out.add("hooks are off on this car (" + map.reason + "): mods apply without their hooks"); } if (!restoreAll && !"plan".equals(cmd) && !"apply".equals(cmd)) { - out.add("usage: engine plan | apply [--trial] | keep | restore | status | recover | firmware-reset | install | remove | nemesis-sync | map | map-car [--local [--if-needed] | --write | --forget] | verify-map | report [--usb] | usb-scan | update-hmgapi | publish-state | apps"); + out.add("usage: engine plan | apply [--trial] | keep | restore | status | recover | firmware-reset | install | remove | nemesis-sync | map | map-car [--local [--if-needed] | --write | --forget] | verify-map | install-check [--usb] | report [--usb] | usb-scan | update-hmgapi | publish-state | apps"); return 2; } Plan p = plan(restoreAll, force); diff --git a/core/runtime/java/hmgapi/engine/MapCheck.java b/core/runtime/java/hmgapi/engine/MapCheck.java index 578a7426..7b5e4351 100644 --- a/core/runtime/java/hmgapi/engine/MapCheck.java +++ b/core/runtime/java/hmgapi/engine/MapCheck.java @@ -21,6 +21,36 @@ final class MapCheck { private MapCheck() {} + /** + * engine install-check [--usb]: the installer's last step (install.sh), so an owner + * with no adb and no NEMESIS never needs the HMG-API app (whose tile needs the hooks). + * An unchecked map whose stock files match runs anyway (CarMap); it's checked now + * (read-only, as run), before the restart that starts the zygote, so one that doesn't + * resolve here is off from that start instead of hooking the wrong code. When the map + * isn't "verified", the Car Report too (--usb: also to the stick), what a maintainer + * needs to verify the map or make one. Never fails the install: always 0. + */ + static int afterInstall(Engine e, boolean usb) { + try { + CarMap m = CarMap.load(e.root, e.facts, e.hmgapi); + if (!m.checkedHere && m.folder != null && !m.points.isEmpty() + && ("mapped".equals(m.status) || "probed".equals(m.status))) { + e.out.add("this car's hook map isn't checked on it yet: checking it now"); + run(e); + m = CarMap.load(e.root, e.facts, e.hmgapi); + } + e.out.add(m.describe()); + if (!"verified".equals(m.status)) { + e.out.add(m.runnable ? "Car Report, so this car's map can be marked verified:" + : "HMG-API's hooks stay off on this car for now. Car Report, for the maintainers:"); + Report.run(e, usb); + } + } catch (Throwable t) { + e.out.add("install-check: " + t); + } + return 0; + } + @SuppressWarnings("unchecked") static int run(Engine e) throws Exception { CarMap m = CarMap.load(e.root, e.facts, e.hmgapi); diff --git a/core/runtime/local-map-test.sh b/core/runtime/local-map-test.sh index f88f1812..bb8866fc 100644 --- a/core/runtime/local-map-test.sh +++ b/core/runtime/local-map-test.sh @@ -80,7 +80,7 @@ F2=$(md5of $R/system/framework/framework.odex) rm $L eng map; has "another framework build: HMG-API's map doesn't fit" "hook map: mismatch" "$out" whole TEST.USA. "$F2" -eng map; has "... the whole map made on this car stands in, probed, until checked" "hook map: probed for Test (usa 260507, mapped on this car), hooks off" "$out" +eng map; has "... the whole map made on this car stands in, probed: on unchecked (its stock files match)" "hook map: probed for Test (usa 260507, mapped on this car), hooks on" "$out" printf '{"folder": "local", "files": {"/system/app/Test.odex": "%s", "/system/framework/framework.odex": "%s"}, "ok": true}\n' "$S" "$F2" > $D/state/map-check.json eng map; has "... checked on this car (verify-map): hooks on" "hook map: probed for Test (usa 260507, mapped on this car), hooks on" "$out" rm -r $D/maps/kia @@ -143,7 +143,7 @@ public class X { eng map-car --write; has "--write with HMG-API's map fitting: says --local instead" "map-car --local\` adds the points it lacks" "$out" cp $T/fw2/dex/classes.dex $R/system/framework/framework.odex eng map-car --write; has "--write on a map that doesn't fit (mismatch): written, outside maps/" "written: /data/hmgapi/state/local-map.json (this car's own map, status probed, instead of kia/test/usa/260507" "$out" - eng map; has "... and used as this car's map" "(usa 260507, mapped on this car), hooks off" "$out" + eng map; has "... and used as this car's map" "(usa 260507, mapped on this car), hooks on" "$out" check "... maps/ untouched" "car.json framework.json test.json" "$(ls $M | tr '\n' ' ' | sed 's/ $//')" fi diff --git a/core/runtime/map-test.sh b/core/runtime/map-test.sh index fd828be0..e01573de 100755 --- a/core/runtime/map-test.sh +++ b/core/runtime/map-test.sh @@ -62,16 +62,48 @@ eng map; has "different framework build: hooks off" "hook map: mismatch" "$out" echo stock-fw > $R/system/framework/framework.odex car mapped -eng map; has "mapped, not checked: off" "isn't checked on a car yet" "$out" -eng plan; check "mods still apply then" 0 $rc -has "without their hooks, and says why" "hooks are off on this car (the map for Test (usa 260507) isn't checked" "$out" +eng map; has "mapped, not checked, stock files match: on (the owner's call, 2026-11-30)" "hooks on (map not checked on a car yet (its stock files match this car))" "$out" +eng plan; check "mods apply then" 0 $rc eng restore; check "restore still works" 0 $rc -printf '{"testing_maps": true}\n' > $R/data/hmgapi/settings/hmgapi.json -eng map; has "mapped + testing mode: on" "running because hmgapi.json testing_maps is on" "$out" -rm $R/data/hmgapi/settings/hmgapi.json printf '{"folder": "kia/test/usa/260507", "files": {"/system/app/Test.odex": "%s", "/system/framework/framework.odex": "%s"}, "ok": true}\n' "$S" "$F" > $R/data/hmgapi/state/map-check.json eng map; has "mapped + checked on this car: on" "map checked on this car" "$out" eng plan; check "engine applies mods then" 0 $rc printf '{"folder": "kia/test/usa/260507", "files": {"/system/app/Test.odex": "%s", "/system/framework/framework.odex": "%s"}, "ok": false}\n' "$S" "$F" > $R/data/hmgapi/state/map-check.json -eng map; has "a failed check doesn't count" "hooks off" "$out" +eng map; has "a failed check here: off, says why" "failed \`hmgapid engine verify-map\` on this car" "$out" +has "... hooks off" "hooks off" "$out" +eng plan; check "mods still apply then" 0 $rc +has "without their hooks" "hooks are off on this car" "$out" +eng restore +printf '{"testing_maps": true}\n' > $R/data/hmgapi/settings/hmgapi.json +eng map; has "failed check + testing mode: on" "running because hmgapi.json testing_maps is on" "$out" +rm $R/data/hmgapi/settings/hmgapi.json + +# install-check, the installer's last step: an owner with no adb and no NEMESIS can't open the +# app (its tile needs the hooks), so the install checks the map itself and leaves a Car Report +rm -f $R/data/hmgapi/state/map-check.json; rm -rf $R/data/hmgapi/public/reports +ieng() { set +e; out=$(HMGAPI_TEST_MAPCHECK=$1 HMGAPI_ROOT=$R HMGAPI_HOST=1 java -cp "$CP" hmgapi.engine.Engine install-check 2>&1); rc=$?; set -e; } +ieng pass +check "install-check: never fails the install" 0 $rc +has "... a mapped map not checked here: checked now" "checking it now" "$out" +has "... passes: hooks on from the next start" "map checked on this car" "$out" +check "... the check is kept" yes "$(grep -q '"ok": true' $R/data/hmgapi/state/map-check.json && echo yes)" +has "... and a Car Report, so the map can be marked verified" "so this car's map can be marked verified" "$out" +check "... saved" yes "$(ls $R/data/hmgapi/public/reports/*.json >/dev/null 2>&1 && echo yes)" +rm -rf $R/data/hmgapi/public/reports +ieng pass +check "... run again: not checked twice" "" "$(echo "$out" | grep 'checking it now' || true)" +rm -f $R/data/hmgapi/state/map-check.json +ieng fail:test.a.go +check "... a check that fails: still 0" 0 $rc +has "... hooks stay off, says so" "HMG-API's hooks stay off on this car for now" "$out" +rm -f $R/data/hmgapi/state/map-check.json; rm -rf $R/data/hmgapi/public/reports +car verified +ieng pass +check "... a verified map: no check" "" "$(echo "$out" | grep 'checking it now' || true)" +check "... and no report" no "$(ls $R/data/hmgapi/public/reports/*.json >/dev/null 2>&1 && echo yes || echo no)" +printf 'ro.build.product=OTHER.USA.0000.V015.012.260507\nro.board.platform=tcc803x\n' > $R/props.txt +ieng pass +has "... no map for this car: says so" "no hook map for this car" "$out" +has "... and leaves a Car Report" "HMG-API's hooks stay off on this car for now" "$out" +check "... saved" yes "$(ls $R/data/hmgapi/public/reports/*.json >/dev/null 2>&1 && echo yes)" exit $fail diff --git a/install/common/install-test.sh b/install/common/install-test.sh index dd8aa7da..96142253 100644 --- a/install/common/install-test.sh +++ b/install/common/install-test.sh @@ -212,6 +212,9 @@ echo "$(md5sum < $T/newfw | cut -c1-32) test new firmware" >> $P/stock.txt (cd $P && md5sum hmgapid lpatch app_process libhmgapi_hook.so hmgapi-hook.jar HmgApi.apk install.sh uninstall.sh lib.sh stock.txt app-pending.sh app-open.sh hook-check.sh boot.sh MAPS.md5 > MANIFEST) export HMGAPI_TEST_ENGINE=$T/bin/engine run $P/install.sh $P +check "install: checks the hook map itself (no app, adb or NEMESIS needed to turn the hooks on)" "engine install-check" "$(calls | grep '^engine install-check' || true)" +export HMGAPI_FROM_USB=1; run $P/install.sh $P; unset HMGAPI_FROM_USB +check "... from the USB stick: the Car Report goes on the stick too" "engine install-check --usb" "$(calls | grep '^engine install-check' || true)" mkdir -p $R/data/hmgapi/state; echo '{"files": {}, "settings": {}}' > $R/data/hmgapi/state/files.json firmware_update; NEWFW=$(tree); calls >/dev/null diff --git a/install/common/install.sh b/install/common/install.sh index bc889914..920e98c7 100644 --- a/install/common/install.sh +++ b/install/common/install.sh @@ -356,6 +356,18 @@ else [ -n "$ROOT" ] || /system/bin/hmgapid sh "sh /data/hmgapi/app-pending.sh /dev/null 2>&1 &" >/dev/null 2>&1 log "Android isn't up: the HMG-API app installs by itself once it is" fi +# the hook map, checked on this car now if it isn't yet (hooks run only with a checked map, and +# the zygote decides at the next start), and the Car Report when the map isn't verified: no app +# needed (its tile needs the hooks), no adb, no NEMESIS. HMGAPI_FROM_USB: the report goes on the stick too. +ICUSB=; [ "$HMGAPI_FROM_USB" = 1 ] && ICUSB=--usb +if [ -z "$ROOT" ]; then + log "checking this car's hook map (this can take a minute)" + r=$(CLASSPATH=/system/framework/hmgapi-hook.jar ANDROID_ROOT=/system ANDROID_DATA=/data /system/bin/app_process /system/bin hmgapi.engine.Engine install-check $ICUSB 2>&1) + log "$r" +elif [ -n "$HMGAPI_TEST_ENGINE" ]; then + r=$($HMGAPI_TEST_ENGINE install-check $ICUSB 2>&1) + log "$r" +fi # NEMESIS's package list: HMG-API and its mods listed there too (not when NEMESIS runs this: it's listing it already) if [ "$HMGAPI_FROM_NEMESIS" != 1 ] && [ -x "$ROOT/system/xbin/nemesis" ]; then if [ -z "$ROOT" ]; then diff --git a/install/usb/troubleShooter b/install/usb/troubleShooter index a65670ed..7943fb24 100755 --- a/install/usb/troubleShooter +++ b/install/usb/troubleShooter @@ -81,7 +81,7 @@ toast "HMG-API $(cat "$P/VERSION" 2>/dev/null): installing..." # from /data: the stick may be pulled, and it may not allow running files rm -r "$STAGE" 2>/dev/null mkdir -p "${STAGE%/*}" && cp -r "$P" "$STAGE" || { toast "HMG-API: can't copy from the USB stick. Nothing was changed."; finish 1; } -sh "$STAGE/install.sh" "$STAGE" > "$STAGE.log" 2>&1 +HMGAPI_FROM_USB=1 sh "$STAGE/install.sh" "$STAGE" > "$STAGE.log" 2>&1 # FROM_USB: the Car Report goes on the stick too rc=$? cp "$STAGE.log" "$U/HMGAPI/install.log" 2>/dev/null rm -r "$STAGE" "$STAGE.log" 2>/dev/null From 68e07c56dfc4e7544994d1fc3f8f542612ddf30e Mon Sep 17 00:00:00 2001 From: VysseCodes <205995085+VysseCodes@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:14:02 -0600 Subject: [PATCH 2/5] A map that failed its check on this car stays off: Try unchecked maps no longer overrides that A failed verify-map on the car is evidence the map is wrong there, and a wrong hook in system_server crash-loops Android until the boot guard turns hooks off. Maps nobody has checked still run when their stock files match. The app's description of the switch now says what it still does: every hook may use the points mapped on this car. Tested off-car only (map-test.sh, local-map-test.sh). --- CHANGELOG.md | 2 +- core/app/java/hmgapi/app/SettingsTab.java | 3 ++- core/runtime/java/hmgapi/engine/CarMap.java | 13 ++++++------- core/runtime/map-test.sh | 3 ++- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3719f4ba..865356ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ unverified (`mapped` or `probed`) map only after `engine verify-map` passed on the car, and only the HMG-API app could run it, whose tile needs the hooks; NEMESIS owners got in through NEMESIS Manager's Launch. Now a map whose stock files match the car runs unchecked, and only a - failed `verify-map` on that car turns it off ("Try unchecked maps" runs it even then). The + failed `verify-map` on that car turns it off, with no override. The installer checks the map itself before the restart (`engine install-check`), and when the map isn't verified or there's none it leaves a Car Report, on the USB stick too for a stick install (`HMG-API reports`). diff --git a/core/app/java/hmgapi/app/SettingsTab.java b/core/app/java/hmgapi/app/SettingsTab.java index 773fff2a..09a794a5 100644 --- a/core/app/java/hmgapi/app/SettingsTab.java +++ b/core/app/java/hmgapi/app/SettingsTab.java @@ -308,7 +308,8 @@ public void run() { a.needRestart(); } }); - owner("Maps not checked on a car yet", "For a car HMG-API is new on: hooks run with a map nobody has checked on this car. " + owner("Maps not checked on a car yet", "For a car HMG-API is new on: every hook may use the points HMG-API found on this " + + "car itself, not only readings and mods that watch. A map that failed its check on this car stays off either way. " + "If Android fails to start three times during one boot with its hooks, or the head unit restarts six times in a row " + "within two minutes of starting, HMG-API's boot guard turns its hooks off. Takes effect at the next restart.", "Try unchecked maps", "testing_maps", false, new Runnable() { diff --git a/core/runtime/java/hmgapi/engine/CarMap.java b/core/runtime/java/hmgapi/engine/CarMap.java index 3ae85b3f..2ca3da80 100644 --- a/core/runtime/java/hmgapi/engine/CarMap.java +++ b/core/runtime/java/hmgapi/engine/CarMap.java @@ -19,7 +19,7 @@ * mismatch a map, but the car's framework isn't the one it was made from: hooks off * mapped points found from the car's stock files, not checked on a car yet: runs * (its stock files match, or it would be mismatch), unless this car failed - * `engine verify-map` on it (state/map-check.json); "testing_maps" runs it even then + * `engine verify-map` on it (state/map-check.json); nothing overrides that * probed made on the car itself (engine map-car --write, from its own files): as mapped * verified checked on a real car: runs * @@ -209,18 +209,17 @@ static CarMap finish(String root, CarMap m, File maps, Map local m.local.clear(); } } - boolean testing = m.testing; if ("verified".equals(m.status)) { m.runnable = true; } else if ("mapped".equals(m.status) || "probed".equals(m.status)) { // the owner's call (2026-11-30): a map whose stock files match runs without a - // check; only a failed check here stops it. The boot risk is app_process, which - // the installer's stock gate covers, and the zygote's boot guard catches a crash loop. + // check; only a failed check here stops it, and nothing overrides that (2026-12-01): + // a failed check is evidence the map is wrong for this car, and a wrong hook in + // system_server crash-loops Android until the boot guard turns hooks off. boolean failed = !m.checkedHere && checkFailedHere(root, m); - m.runnable = !failed || testing; + m.runnable = !failed; m.reason = m.checkedHere ? "map checked on this car (not yet marked verified)" - : failed ? (testing ? "the map failed `hmgapid engine verify-map` on this car; running because hmgapi.json testing_maps is on" - : "the map for " + m.car + " failed `hmgapid engine verify-map` on this car (state/map-check.json)") + : failed ? "the map for " + m.car + " failed `hmgapid engine verify-map` on this car (state/map-check.json)" : "map not checked on a car yet (its stock files match this car)"; } else { m.reason = "the map for " + m.car + " has status " + m.status + ": hooks off"; diff --git a/core/runtime/map-test.sh b/core/runtime/map-test.sh index e01573de..4aff296f 100755 --- a/core/runtime/map-test.sh +++ b/core/runtime/map-test.sh @@ -75,7 +75,8 @@ eng plan; check "mods still apply then" 0 $rc has "without their hooks" "hooks are off on this car" "$out" eng restore printf '{"testing_maps": true}\n' > $R/data/hmgapi/settings/hmgapi.json -eng map; has "failed check + testing mode: on" "running because hmgapi.json testing_maps is on" "$out" +eng map; has "failed check + testing mode: still off" "failed \`hmgapid engine verify-map\` on this car" "$out" +has "... hooks off" "hooks off" "$out" rm $R/data/hmgapi/settings/hmgapi.json # install-check, the installer's last step: an owner with no adb and no NEMESIS can't open the From ae4d35b801edcf54f5ddc992d5bdb2c30986ddde Mon Sep 17 00:00:00 2001 From: VysseCodes <205995085+VysseCodes@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:28:47 -0600 Subject: [PATCH 3/5] Open the HMG-API app once after an install or update, so owners see its status Owners without NEMESIS or adb had no way into the app on a car whose hooks are off (its tile needs the hooks). install.sh leaves state/open-once; boot.sh runs open.sh once Android is up, the app's own install is done and, when the car gives a gear reading, it's in P, then 20 s for the launcher and projection apps. Given up after an hour, tried again at the next start. Tested off-car only (install/common/test.sh). --- CHANGELOG.md | 5 +++++ install/common/boot.sh | 19 ++++++++++++++++++ install/common/install.sh | 2 ++ install/common/test.sh | 41 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 865356ef..e2294655 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ isn't verified or there's none it leaves a Car Report, on the USB stick too for a stick install (`HMG-API reports`). +- **The HMG-API app opens by itself once after an install or update**, so owners see its + status (hooks on or off and why, the map, the Car Report) without the tile, NEMESIS or adb. + It waits for Android, for the app's own install and, on a car that gives a gear reading, + for P; given up after an hour and tried again at the next start. + - **A root service can read its own settings** (`HmgApi.settings()`, `saveSettings()`): the daemon sees such a service as root, so the client names its mod (`HMGAPI_MOD`). diff --git a/install/common/boot.sh b/install/common/boot.sh index 6128e957..d32da0c6 100644 --- a/install/common/boot.sh +++ b/install/common/boot.sh @@ -32,6 +32,25 @@ if [ -x $ROOT/system/xbin/nemesis ]; then (sleep 120; $H engine nemesis-sync) $D/map-local.log 2>&1 & fi +# Once after an install or update (install.sh leaves state/open-once): open the HMG-API app +# so the owner sees its status (hooks on or off and why, the map, the Car Report) with no +# tile, NEMESIS or adb, since the tile needs the hooks. Waits for Android, for the app's own +# install (app-pending.sh) and, when the car gives a reading, for P; then the launcher and +# projection apps get 20 s first. Given up after an hour: tried again at the next start. +if [ -f $D/state/open-once ]; then ( + step=${HMGAPI_TEST_STEP:-10}; tries=${HMGAPI_TEST_TRIES:-360}; n=0 + while [ $n -lt $tries ]; do + if [ "$(getprop sys.boot_completed)" = 1 ] && [ ! -f $D/public/HmgApi.apk ]; then + case "$($H vehicle gear.park 2>/dev/null)" in "gear.park 0") ;; *) break ;; esac # no reading: open + fi + sleep $step; n=$((n + 1)) + done + [ $n -lt $tries ] || { echo "$(date) open-once: Android, the app or P not there within the hour: next start"; exit 0; } + sleep ${HMGAPI_TEST_SETTLE:-20} + rm -f $D/state/open-once + echo "$(date) open-once: opening the app" + sh $D/open.sh +) $D/open-once.log 2>&1 & fi if [ -f $D/state/journal.json ]; then # Restart only after a recover that finished (it takes the journal away). One that # failed part-way has "rolled back" in its log too and keeps the journal: restarting diff --git a/install/common/install.sh b/install/common/install.sh index 920e98c7..d9cd4267 100644 --- a/install/common/install.sh +++ b/install/common/install.sh @@ -303,6 +303,8 @@ rm -f "$D/hook/boot" "$D/hook/disable" cp "$P/uninstall.sh" "$P/lib.sh" "$P/stock.txt" "$P/app-pending.sh" "$P/hook-check.sh" "$P/boot.sh" "$D/" && chmod 700 "$D/uninstall.sh" "$D/app-pending.sh" "$D/hook-check.sh" "$D/boot.sh" # open.sh (NEMESIS Manager's Launch, adb) installs the app from this copy if it's missing, then opens it cp "$P/app-open.sh" "$D/open.sh" && chmod 700 "$D/open.sh" || fail "keep open.sh" +# boot.sh opens the app once after the restart, so the owner sees HMG-API's status without the tile +mkdir -p "$D/state" && : > "$D/state/open-once" || log "note: the app won't open by itself after the restart (open it from its tile)" cp "$P/HmgApi.apk" "$D/HmgApi.apk" && chmod 644 "$D/HmgApi.apk" || fail "keep a copy of the app" # HMG-API's NEMESIS scripts and incompatible packages: engine nemesis-sync lists HMG-API and its mods in NEMESIS with them if [ -d "$P/nemesis" ]; then diff --git a/install/common/test.sh b/install/common/test.sh index 21bc1355..42960b32 100644 --- a/install/common/test.sh +++ b/install/common/test.sh @@ -135,4 +135,45 @@ check "... and boot.log says so" "1" "$(grep -c "recover didn't finish" "$T/boot rm -f "$D/state/journal.json"; rm -f "$T/hmgapid.calls" env ROOT="$T" $SH "$PWD/boot.sh" > /dev/null 2>&1; wait check "boot: no journal: recover isn't run" "" "$(calls)" + +# boot.sh, once after an install: opens the app (open.sh) when Android is up, the app is +# installed and, with a gear reading, the car is in P. Then never again. +mkdir -p "$T/bin" +cat > "$T/bin/getprop" </dev/null +EOF +chmod +x "$T/bin/getprop" +cat > "$T/system/bin/hmgapid" <> "$T/hmgapid.calls" +[ "\$1 \$2" = "vehicle gear.park" ] && cat "$T/gear" 2>/dev/null +exit 0 +EOF +echo 'echo opened >> "$ROOT/opened"' > "$D/open.sh" +# boot.sh leaves the job running: wait for its last line (opened, or given up), or 30 s with no flag +OB() { + rm -f "$T/opened" "$D/open-once.log" + env PATH="$T/bin:$PATH" ROOT="$T" HMGAPI_TEST_STEP=0.1 HMGAPI_TEST_TRIES=${1:-20} HMGAPI_TEST_SETTLE=0 $SH "$PWD/boot.sh" > /dev/null 2>&1; wait + [ -f "$D/state/open-once" ] || return 0 + i=0; while [ $i -lt 300 ] && ! grep -q -e "opening the app" -e "next start" "$D/open-once.log" 2>/dev/null; do sleep 0.1; i=$((i + 1)); done + sleep 0.3 +} +opened() { [ -f "$T/opened" ] && wc -l < "$T/opened" | tr -d ' ' || echo 0; } +echo 1 > "$T/boot_completed"; rm -f "$T/gear" +: > "$D/state/open-once"; OB +check "open-once: Android up, no gear reading: the app opens" "1" "$(opened)" +check "... once: the flag is gone" "no" "$([ -f "$D/state/open-once" ] && echo yes || echo no)" +OB +check "... and not at the next start" "0" "$(opened)" +: > "$D/state/open-once"; echo "gear.park 0" > "$T/gear"; OB 10 +check "open-once: not in P: not opened" "0" "$(opened)" +check "... the flag kept for the next start" "yes" "$([ -f "$D/state/open-once" ] && echo yes || echo no)" +echo "gear.park 1" > "$T/gear"; OB +check "open-once: in P: opened" "1" "$(opened)" +: > "$D/state/open-once"; rm -f "$T/gear"; echo 0 > "$T/boot_completed"; OB 10 +check "open-once: Android not up: not opened, kept" "0 yes" "$(opened) $([ -f "$D/state/open-once" ] && echo yes || echo no)" +echo 1 > "$T/boot_completed"; mkdir -p "$D/public"; : > "$D/public/HmgApi.apk"; OB 10 +check "open-once: the app's own install still waiting: not opened" "0" "$(opened)" +rm -f "$D/public/HmgApi.apk" "$D/state/open-once" exit $fail From 08e8e723dcd8338849c4861dca8e20b670b6d76c Mon Sep 17 00:00:00 2001 From: VysseCodes <205995085+VysseCodes@users.noreply.github.com> Date: Wed, 2 Dec 2026 11:20:23 -0600 Subject: [PATCH 4/5] Review: @SuppressWarnings back on checkedHere; the changelog says unchecked maps now run (35 of 38) --- CHANGELOG.md | 4 +++- core/runtime/java/hmgapi/engine/CarMap.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2294655..eebf3990 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ unverified (`mapped` or `probed`) map only after `engine verify-map` passed on the car, and only the HMG-API app could run it, whose tile needs the hooks; NEMESIS owners got in through NEMESIS Manager's Launch. Now a map whose stock files match the car runs unchecked, and only a - failed `verify-map` on that car turns it off, with no override. The + failed `verify-map` on that car turns it off, with no override. **That means hooks now run on cars whose map nobody has + checked on a car (35 of the 38 maps today)**; the boot guard turns them off if Android stops + starting. The installer checks the map itself before the restart (`engine install-check`), and when the map isn't verified or there's none it leaves a Car Report, on the USB stick too for a stick install (`HMG-API reports`). diff --git a/core/runtime/java/hmgapi/engine/CarMap.java b/core/runtime/java/hmgapi/engine/CarMap.java index 2ca3da80..91392667 100644 --- a/core/runtime/java/hmgapi/engine/CarMap.java +++ b/core/runtime/java/hmgapi/engine/CarMap.java @@ -344,7 +344,6 @@ static void drop(CarMap m, String app, String why) { } } - @SuppressWarnings("unchecked") /** this map, as it is now, failed `engine verify-map` on this unit */ static boolean checkFailedHere(String root, CarMap m) { try { @@ -358,6 +357,7 @@ static boolean checkFailedHere(String root, CarMap m) { } } + @SuppressWarnings("unchecked") static boolean checkedHere(String root, CarMap m) { try { File f = new File(root + "/data/hmgapi/state/map-check.json"); From 3e8b93f4e8fb96136cda9deda467935a3fa45a82 Mon Sep 17 00:00:00 2001 From: VysseCodes <205995085+VysseCodes@users.noreply.github.com> Date: Wed, 2 Dec 2026 12:14:55 -0600 Subject: [PATCH 5/5] The app opens once only on an explicit "in P" (review) With no gear reading, an error or hmgapid not answering, the app could open mid-drive. It now opens only on gear.park 1 from HMG-API's vehicle service or, when that gives no reading, a 1 from the car's own system service (lib.sh stock_gear_park, #489: no map needed, so cars without a map get it too, used once the installed lib.sh has it). "Not in P" from the vehicle service wins over the other. Otherwise it waits, and tries again at the next start. Tested off-car: install/common/test.sh in sh and bash (no reading at all: not opened; the car's service P / not P; the vehicle service's "not in P" wins). --- CHANGELOG.md | 5 +++-- install/common/boot.sh | 12 +++++++++--- install/common/test.sh | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eebf3990..1509efc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,9 @@ - **The HMG-API app opens by itself once after an install or update**, so owners see its status (hooks on or off and why, the map, the Car Report) without the tile, NEMESIS or adb. - It waits for Android, for the app's own install and, on a car that gives a gear reading, - for P; given up after an hour and tried again at the next start. + It waits for Android, for the app's own install and for an explicit "in P" (HMG-API's vehicle + service, else the car's own system service, so cars with no map too); no reading is never + taken for P. Given up after an hour and tried again at the next start. - **A root service can read its own settings** (`HmgApi.settings()`, `saveSettings()`): the daemon sees such a service as root, so the client names its mod (`HMGAPI_MOD`). diff --git a/install/common/boot.sh b/install/common/boot.sh index d32da0c6..bdb92fd9 100644 --- a/install/common/boot.sh +++ b/install/common/boot.sh @@ -35,13 +35,19 @@ if [ -d $D/maps ] && [ ! -f $D/settings/allow/no_local_points ]; then (sleep 90; # Once after an install or update (install.sh leaves state/open-once): open the HMG-API app # so the owner sees its status (hooks on or off and why, the map, the Car Report) with no # tile, NEMESIS or adb, since the tile needs the hooks. Waits for Android, for the app's own -# install (app-pending.sh) and, when the car gives a reading, for P; then the launcher and -# projection apps get 20 s first. Given up after an hour: tried again at the next start. +# install (app-pending.sh) and for an explicit "in P": HMG-API's vehicle service, else the car's +# own system service (lib.sh stock_gear_park, no map needed). No reading is never taken for P. +# Then the launcher and projection apps get 20 s first. Given up after an hour: tried again at +# the next start. if [ -f $D/state/open-once ]; then ( step=${HMGAPI_TEST_STEP:-10}; tries=${HMGAPI_TEST_TRIES:-360}; n=0 while [ $n -lt $tries ]; do if [ "$(getprop sys.boot_completed)" = 1 ] && [ ! -f $D/public/HmgApi.apk ]; then - case "$($H vehicle gear.park 2>/dev/null)" in "gear.park 0") ;; *) break ;; esac # no reading: open + g=$($H vehicle gear.park 2>/dev/null) + [ "$g" = "gear.park 1" ] && break + if [ "$g" != "gear.park 0" ] && [ "$(. $D/lib.sh 2>/dev/null; command -v stock_gear_park >/dev/null 2>&1 && stock_gear_park)" = 1 ]; then + break # no reading from the vehicle service; the car's own service says P + fi fi sleep $step; n=$((n + 1)) done diff --git a/install/common/test.sh b/install/common/test.sh index 42960b32..84e91f78 100644 --- a/install/common/test.sh +++ b/install/common/test.sh @@ -161,11 +161,21 @@ OB() { } opened() { [ -f "$T/opened" ] && wc -l < "$T/opened" | tr -d ' ' || echo 0; } echo 1 > "$T/boot_completed"; rm -f "$T/gear" -: > "$D/state/open-once"; OB -check "open-once: Android up, no gear reading: the app opens" "1" "$(opened)" +: > "$D/state/open-once"; OB 10 +check "open-once: Android up, no gear reading at all: not opened (never taken for P)" "0 yes" "$(opened) $([ -f "$D/state/open-once" ] && echo yes || echo no)" +# the car's own system service (lib.sh stock_gear_park, #489) when the vehicle service gives nothing +cp "$D/lib.sh" "$T/lib.keep" 2>/dev/null || true +printf 'stock_gear_park() { cat %s/stockgear 2>/dev/null; }\n' "$T" > "$D/lib.sh" +echo 0 > "$T/stockgear"; OB 10 +check "open-once: no vehicle reading, the car's service says not in P: not opened" "0" "$(opened)" +echo 1 > "$T/stockgear"; OB +check "open-once: no vehicle reading, the car's service says P: opened" "1" "$(opened)" check "... once: the flag is gone" "no" "$([ -f "$D/state/open-once" ] && echo yes || echo no)" OB check "... and not at the next start" "0" "$(opened)" +: > "$D/state/open-once"; echo "gear.park 0" > "$T/gear"; echo 1 > "$T/stockgear"; OB 10 +check "open-once: the vehicle service says not in P: not opened, whatever the other says" "0" "$(opened)" +rm -f "$T/stockgear" "$D/lib.sh" "$D/state/open-once"; [ -f "$T/lib.keep" ] && mv "$T/lib.keep" "$D/lib.sh"; rm -f "$T/gear" : > "$D/state/open-once"; echo "gear.park 0" > "$T/gear"; OB 10 check "open-once: not in P: not opened" "0" "$(opened)" check "... the flag kept for the next start" "yes" "$([ -f "$D/state/open-once" ] && echo yes || echo no)"