Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# 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, 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`).

- **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 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`).

## 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
Expand Down
3 changes: 2 additions & 1 deletion core/app/java/hmgapi/app/SettingsTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
35 changes: 26 additions & 9 deletions core/runtime/java/hmgapi/engine/CarMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -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); 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
*
Expand Down Expand Up @@ -209,16 +209,20 @@ static CarMap finish(String root, CarMap m, File maps, Map<String, Object> 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)) && (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, 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;
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 ? "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";
Expand Down Expand Up @@ -340,6 +344,19 @@ static void drop(CarMap m, String app, String why) {
}
}

/** 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<String, Object> 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;
}
}

@SuppressWarnings("unchecked")
static boolean checkedHere(String root, CarMap m) {
try {
Expand Down
3 changes: 2 additions & 1 deletion core/runtime/java/hmgapi/engine/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 <zip|dir> | remove <id> | nemesis-sync | map | map-car [--local [--if-needed] | --write | --forget] | verify-map | report [--usb] | usb-scan | update-hmgapi <zip> | publish-state | apps");
out.add("usage: engine plan | apply [--trial] | keep | restore | status | recover | firmware-reset | install <zip|dir> | remove <id> | nemesis-sync | map | map-car [--local [--if-needed] | --write | --forget] | verify-map | install-check [--usb] | report [--usb] | usb-scan | update-hmgapi <zip> | publish-state | apps");
return 2;
}
Plan p = plan(restoreAll, force);
Expand Down
30 changes: 30 additions & 0 deletions core/runtime/java/hmgapi/engine/MapCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions core/runtime/local-map-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
47 changes: 40 additions & 7 deletions core/runtime/map-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,49 @@ 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: 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
# 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
25 changes: 25 additions & 0 deletions install/common/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,31 @@ if [ -x $ROOT/system/xbin/nemesis ]; then (sleep 120; $H engine nemesis-sync) </
# car (state/local-map.json): only when the map, the catalogue or the stock files changed since,
# so after an HMG-API install or update. Used from the next start. The owner's switch skips it.
if [ -d $D/maps ] && [ ! -f $D/settings/allow/no_local_points ]; then (sleep 90; $H engine map-car --local --if-needed) </dev/null >$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 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
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
[ $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
) </dev/null >$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
Expand Down
3 changes: 3 additions & 0 deletions install/common/install-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 14 additions & 0 deletions install/common/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -356,6 +358,18 @@ else
[ -n "$ROOT" ] || /system/bin/hmgapid sh "sh /data/hmgapi/app-pending.sh </dev/null >/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
Expand Down
Loading
Loading