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
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
# Changelog

## Unreleased

- **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`).
- **An undone trial or a cut-off apply puts settings, live props and binds back too.** The
journal kept only files and the state, so a trial's `persist.*` prop (or one set by an apply
cut off after its settings) stayed set after "trial undone", the next apply took it for stock,
and `engine restore` left it set. `binds.txt` wasn't rolled back either. The journal now keeps
each one's value before, and `engine recover` writes them back.
- **Stock backups are checked before every use.** They're taken as the installer takes its
own: copied beside, checked against the stock md5, then renamed, so a cut-off copy never sits
under the backup's name. An app's odex backup has its md5 recorded now. A restore, uninstall or
rebuild never writes a backup that isn't the recorded md5 (a short odex under a stock apk with
no `classes.dex` crashed that app at every launch): a NEMESIS copy with that md5 stands in.
Without one, only that file waits: it's left as it is, and the apply, restore or uninstall
warns, naming the backup and the md5 it should have; the rest goes on. `engine status` shows
it as CHANGED, with why and what to do (copy the stock file there and apply, or open an
issue), until it's fixed. A damaged backup is never written back, and nothing overrides that. `engine restore` then ends with code 4, so
an uninstall stops before removing HMG-API and leaves that file's record and backups in place.
- **Room is checked before an apply** writes anything, on `/system` and `/data`. If `/system`
filled up anyway, `engine recover` removes the cut-off copy first and, when there's still no
room, the file before its saved copy goes back, instead of failing at every start.
- **A damaged journal, or a saved copy that's gone, no longer blocks everything.** `engine
recover` sets the journal aside (`state/journal.bad.json`) and says so; `engine status` and
`engine keep` say what's wrong instead of failing.
- **More is refused unless `hmgapi.json overrides.allow_critical` lists it** (with a warning):
`dalvik.*` and `persist.sys.dalvik.*` keys in `build.prop` and as live props
(`"prop:<key>"`, e.g. the runtime switch `persist.sys.dalvik.vm.lib`), `framework-res.apk`,
`libz`, `libcrypto`, `libssl`, the ICU libraries and data file, `libgui`, `libui`, `libEGL`,
`libGLESv2`, `libhardware`, `libsqlite`, `libexpat`, everything in `/system/lib/hw/` and
`/system/lib/egl/`, and `netd`, `mediaserver`, `logwrapper` and `e2fsck`.
- **HMG-API doesn't update itself while an apply is unfinished or a trial is in place**
(`engine update-hmgapi`, `--force` included): `engine keep` or `engine recover` first.
- **A rebuilt app's Dalvik cache entry is the only one touched.** The clean-up also deleted
other apps' entries whose names ended the same way, and the entry filled after a restore was
always named `system@app@`, wrong for an app in `/system/priv-app`. Tested off-car only.

## 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
577 changes: 507 additions & 70 deletions core/runtime/java/hmgapi/engine/Engine.java

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions core/runtime/java/hmgapi/engine/UsbUpdates.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,23 @@ static String installedVersion(Engine e) {
return Engine.HMGAPI_VERSION;
}

/**
* Why HMG-API can't update itself now, or null: never while an apply is unfinished or a
* trial is in place. The new installer would build on files and records that the next
* start rolls back (and its engine on a journal it may not read the same way). The
* catalogue's update asks this before it downloads.
*/
static String pendingWhy(Engine e) {
if (!e.journalFile.exists()) return null;
return "an earlier apply isn't finished or is a trial: run `engine keep` (trial) or `engine recover` first, then update HMG-API";
}

static int updateHmgApi(Engine e, String path, boolean force) throws Exception {
String pending = pendingWhy(e);
if (pending != null) { // --force is for an older release, not this
e.out.add("refused: " + pending);
return 1;
}
File zip = new File(path);
if (!zip.isFile()) {
e.out.add("no release at " + path);
Expand Down
290 changes: 290 additions & 0 deletions core/runtime/journal-test.sh

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions core/runtime/safety-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ printf '{"overrides": {"allow_critical": ["/system/build.prop:ro.build.version.r
mod a '{"type": "props", "path": "/system/build.prop", "set": {"ro.build.version.release": "4.4.4"}, "stock": "any"}'
eng plan; check "ro.* key allowed by override" 0 $rc
rm $R/data/hmgapi/settings/hmgapi.json
mod a '{"type": "props", "path": "/system/build.prop", "set": {"dalvik.vm.heapsize": "512m"}, "stock": "any"}'
eng plan; has "dalvik.* key refused" "dalvik.vm.heapsize; dalvik.* and persist.sys.dalvik.* properties set how Dalvik starts" "$out"; check "... refusal exit" 3 $rc
mod a '{"type": "props", "path": "/system/build.prop", "set": {"persist.sys.dalvik.vm.lib": "libart.so"}, "stock": "any"}'
eng plan; has "persist.sys.dalvik.* key in build.prop refused (the runtime switch)" "changes persist.sys.dalvik.vm.lib" "$out"
printf '{"overrides": {"allow_critical": ["/system/build.prop:dalvik.vm.heapsize"]}}\n' > $R/data/hmgapi/settings/hmgapi.json
mod a '{"type": "props", "path": "/system/build.prop", "set": {"dalvik.vm.heapsize": "512m"}, "stock": "any"}'
eng plan; check "dalvik.* key allowed by override" 0 $rc
has "... with a warning" "WARNING: /system/build.prop: dalvik.vm.heapsize can keep the unit from booting" "$out"
rm $R/data/hmgapi/settings/hmgapi.json
check "build.prop still untouched" "$STOCK_PROP" "$(md5 $R/system/build.prop)"

# ---- boot-critical and HMG-API's own files
mod a '{"type": "add", "path": "/system/lib/libc.so", "src": "a.xml", "stock": "any"}'
Expand All @@ -89,10 +99,29 @@ eng plan; has "HMG-API's own files refused even with overrides" "belongs to HMG-
rm $R/data/hmgapi/settings/hmgapi.json
mod a '{"type": "add", "path": "/system/framework/framework.jar", "src": "a.xml"}'
eng plan; has "boot class path jar refused" "framework.jar: the unit needs this file to boot" "$out"
for p in /system/framework/framework-res.apk /system/lib/libz.so /system/lib/libcrypto.so /system/lib/libicuuc.so \
/system/usr/icu/icudt51l.dat /system/lib/libgui.so /system/lib/libEGL.so /system/lib/hw/gralloc.tcc803x.so \
/system/lib/egl/libGLES_mali.so /system/bin/netd /system/bin/mediaserver; do
mod a '{"type": "add", "path": "'$p'", "src": "a.xml", "stock": "any"}'
eng plan; has "boot-critical: $p refused" "$p: the unit needs this file to boot" "$out"
done
printf '{"overrides": {"allow_critical": ["/system/lib/hw/gralloc.tcc803x.so"]}}\n' > $R/data/hmgapi/settings/hmgapi.json
mod a '{"type": "add", "path": "/system/lib/hw/gralloc.tcc803x.so", "src": "a.xml", "stock": "any"}'
eng plan; has "a hardware module allowed by override, with a warning" "WARNING: /system/lib/hw/gralloc.tcc803x.so is boot-critical" "$out"
rm $R/data/hmgapi/settings/hmgapi.json
mod a '{"type": "add", "path": "/system/lib/hwx/x.so", "src": "a.xml", "stock": "any"}'
eng plan; check "a folder that only starts like hw/ isn't critical" 0 $rc

# ---- live props
mod a '{"type": "prop", "key": "ro.secure", "value": "0"}'
eng plan; has "non-persist prop refused" "only persist.* properties can be set" "$out"
mod a '{"type": "prop", "key": "persist.sys.dalvik.vm.lib", "value": "libart.so"}'
eng plan; has "the runtime switch refused" "prop persist.sys.dalvik.vm.lib: dalvik.* and persist.sys.dalvik.* properties" "$out"
has "... naming the override" "overrides.allow_critical \"prop:persist.sys.dalvik.vm.lib\"" "$out"; check "... refusal exit" 3 $rc
printf '{"overrides": {"allow_critical": ["prop:persist.sys.dalvik.vm.lib"]}}\n' > $R/data/hmgapi/settings/hmgapi.json
eng plan; check "... allowed by override" 0 $rc
has "... with a warning" "WARNING: prop persist.sys.dalvik.vm.lib can keep the unit from booting" "$out"
rm $R/data/hmgapi/settings/hmgapi.json
printf 'prop/persist.sys.iap2.wifi=f\n' > $R/settings.txt
mod a '{"type": "prop", "key": "persist.sys.iap2.wifi", "value": "t"}, {"type": "prop", "key": "persist.iap2.iden.wireless", "value": "t"}'
eng apply; has "persist prop set live" "prop/persist.sys.iap2.wifi=t" "$(cat $R/settings.txt)"
Expand Down Expand Up @@ -123,6 +152,9 @@ has "hmgapid told to do it" "binds" "$(cat $R/actions.log 2>/dev/null)"
mod a '{"type": "bind", "src": "files/x", "target": "/system/bin/linker", "service": "x"}'
mkdir -p $R/data/hmgapi/mods/a/files; echo bin > $R/data/hmgapi/mods/a/files/x
eng plan; has "bind over a boot-critical binary refused" "the unit needs /system/bin/linker to boot" "$out"
mod a '{"type": "bind", "src": "files/x", "target": "/system/bin/netd", "service": "netd"}'
mkdir -p $R/data/hmgapi/mods/a/files; echo bin > $R/data/hmgapi/mods/a/files/x
eng plan; has "bind over a boot daemon refused" "the unit needs /system/bin/netd to boot" "$out"
mod a '{"type": "add", "path": "/system/etc/permissions/b.xml", "src": "a.xml"}'
eng apply; has "binds dropped with the mod: unbind planned" "binds" "$(cat $R/actions.log)"
check "binds.txt empty again" "" "$(cat $R/data/hmgapi/state/binds.txt)"
Expand Down
6 changes: 6 additions & 0 deletions core/runtime/usb-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ has "update in place" '"version": "2.0.0"' "$(cat $R/data/hmgapi/mods/beta/mod.j

eng update-hmgapi $U/HMGAPI/updates/hmgapi-fake.zip; check "fake release not run" 3 $rc
check "its installer didn't run" no "$([ -e $R/installed-9.9.9 ] && echo yes || echo no)"
echo '{"trial": true, "committed": true, "entries": [], "state": {}}' > $R/data/hmgapi/state/journal.json
eng update-hmgapi $U/HMGAPI/updates/hmgapi-9.9.9.zip; check "a trial in place: no self-update" 1 $rc
has "... saying what to do first" "refused: an earlier apply isn't finished or is a trial: run \`engine keep\` (trial) or \`engine recover\` first" "$out"
eng update-hmgapi $U/HMGAPI/updates/hmgapi-9.9.9.zip --force; check "... --force doesn't step around it" 1 $rc
check "... its installer didn't run" no "$([ -e $R/installed-9.9.9 ] && echo yes || echo no)"
rm $R/data/hmgapi/state/journal.json
eng update-hmgapi $U/HMGAPI/updates/hmgapi-9.9.9.zip; check "genuine release runs its installer" 0 $rc
has "installer output passed on" "fake installer ran" "$out"
check "installer ran" yes "$([ -e $R/installed-9.9.9 ] && echo yes)"
Expand Down
2 changes: 1 addition & 1 deletion install/common/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ elif [ -z "$ROOT" ] && [ -f "$D/state/files.json" ]; then
[ -f "$D/state/journal.json" ] && /system/bin/hmgapid engine recover
if ! r=$(/system/bin/hmgapid engine restore 2>&1); then
echo "$r"
fail "engine restore didn't finish, so HMG-API stays installed (mods' files must go back first). See the lines above."
fail "engine restore didn't put every file back to stock, so HMG-API stays installed (mods' files must go back first). See the lines above."
fi
log "mods' changes back to stock"
fi
Expand Down
4 changes: 2 additions & 2 deletions tools/test-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
# Each test: "ok" (its checks, and how many it skipped), "skip" (it skipped everything,
# and why) or "FAIL" (its failed checks).
cd "$(dirname "$0")/.."
ALL="core/hmgapid/test.sh core/client/test.sh core/zygote/test.sh tools/lpatch/test.sh core/runtime/engine-test.sh core/runtime/signing-test.sh core/runtime/system-test.sh core/runtime/safety-test.sh core/runtime/packages-test.sh core/runtime/map-test.sh core/runtime/local-map-test.sh core/runtime/usb-test.sh core/runtime/hooks-test.sh core/runtime/mod-dex-test.sh core/runtime/live-test.sh core/runtime/native-test.sh core/runtime/runtime-test.sh core/runtime/net-test.sh core/runtime/problem-test.sh core/runtime/homewifi-test.sh core/runtime/overlap-test.sh core/runtime/keys-test.sh core/runtime/commands-test.sh core/runtime/scriptcheck-test.sh core/hookpoints/test.sh core/app/qr-test.sh install/common/test.sh install/common/install-test.sh install/common/orders-test.sh install/usb/test.sh install/nemesis/mod-test.sh install/nemesis/sync-test.sh tools/mod-draft-test.sh tools/catalog-test.sh tools/car-triage-test.sh tools/version-test.sh tools/mkicon-test.sh tools/micom-decode-test.sh tools/cars-test.sh tools/sdk-test.sh tools/check-scripts.sh"
ALL="core/hmgapid/test.sh core/client/test.sh core/zygote/test.sh tools/lpatch/test.sh core/runtime/engine-test.sh core/runtime/signing-test.sh core/runtime/system-test.sh core/runtime/safety-test.sh core/runtime/journal-test.sh core/runtime/packages-test.sh core/runtime/map-test.sh core/runtime/local-map-test.sh core/runtime/usb-test.sh core/runtime/hooks-test.sh core/runtime/mod-dex-test.sh core/runtime/live-test.sh core/runtime/native-test.sh core/runtime/runtime-test.sh core/runtime/net-test.sh core/runtime/problem-test.sh core/runtime/homewifi-test.sh core/runtime/overlap-test.sh core/runtime/keys-test.sh core/runtime/commands-test.sh core/runtime/scriptcheck-test.sh core/hookpoints/test.sh core/app/qr-test.sh install/common/test.sh install/common/install-test.sh install/common/orders-test.sh install/usb/test.sh install/nemesis/mod-test.sh install/nemesis/sync-test.sh tools/mod-draft-test.sh tools/catalog-test.sh tools/car-triage-test.sh tools/version-test.sh tools/mkicon-test.sh tools/micom-decode-test.sh tools/cars-test.sh tools/sdk-test.sh tools/check-scripts.sh"
# no build, no ARM toolchain: all but hmgapid, the zygote wrapper, lpatch, the installers and the SDK
FAST="core/client/test.sh core/runtime/engine-test.sh core/runtime/signing-test.sh core/runtime/system-test.sh core/runtime/safety-test.sh core/runtime/packages-test.sh core/runtime/map-test.sh core/runtime/local-map-test.sh core/runtime/usb-test.sh core/runtime/hooks-test.sh core/runtime/mod-dex-test.sh core/runtime/live-test.sh core/runtime/native-test.sh core/runtime/runtime-test.sh core/runtime/net-test.sh core/runtime/problem-test.sh core/runtime/homewifi-test.sh core/runtime/overlap-test.sh core/runtime/keys-test.sh core/runtime/commands-test.sh core/runtime/scriptcheck-test.sh core/hookpoints/test.sh core/app/qr-test.sh install/common/test.sh install/nemesis/mod-test.sh install/nemesis/sync-test.sh tools/mod-draft-test.sh tools/catalog-test.sh tools/car-triage-test.sh tools/version-test.sh tools/mkicon-test.sh tools/micom-decode-test.sh tools/check-scripts.sh"
FAST="core/client/test.sh core/runtime/engine-test.sh core/runtime/signing-test.sh core/runtime/system-test.sh core/runtime/safety-test.sh core/runtime/journal-test.sh core/runtime/packages-test.sh core/runtime/map-test.sh core/runtime/local-map-test.sh core/runtime/usb-test.sh core/runtime/hooks-test.sh core/runtime/mod-dex-test.sh core/runtime/live-test.sh core/runtime/native-test.sh core/runtime/runtime-test.sh core/runtime/net-test.sh core/runtime/problem-test.sh core/runtime/homewifi-test.sh core/runtime/overlap-test.sh core/runtime/keys-test.sh core/runtime/commands-test.sh core/runtime/scriptcheck-test.sh core/hookpoints/test.sh core/app/qr-test.sh install/common/test.sh install/nemesis/mod-test.sh install/nemesis/sync-test.sh tools/mod-draft-test.sh tools/catalog-test.sh tools/car-triage-test.sh tools/version-test.sh tools/mkicon-test.sh tools/micom-decode-test.sh tools/check-scripts.sh"
# these write out/ (usb: out/payload and out/dist; sdk: out/mods, out/packages, out/dist) or read
# what another writes (install-test: out/payload), so they run one after another
SERIAL="install/common/install-test.sh install/usb/test.sh tools/sdk-test.sh"
Expand Down
4 changes: 2 additions & 2 deletions tools/test-select.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
RUNTIME = ['core/runtime/*-test.sh']
# the tests that compile hmgapi.engine (tools/engine-classes.sh): the rest of core/runtime's
# Java (hook, vehicle) is only compiled by the build and the SDK, and its own tests
ENGINE = ['core/runtime/engine-test.sh', 'core/runtime/signing-test.sh', 'core/runtime/system-test.sh', 'core/runtime/safety-test.sh',
ENGINE = ['core/runtime/engine-test.sh', 'core/runtime/signing-test.sh', 'core/runtime/system-test.sh', 'core/runtime/safety-test.sh', 'core/runtime/journal-test.sh',
'core/runtime/packages-test.sh', 'core/runtime/map-test.sh', 'core/runtime/local-map-test.sh', 'core/runtime/usb-test.sh', 'core/runtime/hooks-test.sh',
'core/runtime/live-test.sh', 'core/runtime/native-test.sh', 'core/runtime/runtime-test.sh', 'core/runtime/net-test.sh', 'core/runtime/homewifi-test.sh',
'core/runtime/overlap-test.sh', 'core/runtime/scriptcheck-test.sh', 'install/nemesis/mod-test.sh', 'install/nemesis/sync-test.sh',
Expand Down Expand Up @@ -54,7 +54,7 @@
(['install/*'], INSTALL + ['core/runtime/packages-test.sh']),
(['tools/zygote-orders.py'], ['install/common/orders-test.sh']),
(['install/nemesis/mod/*', 'install/nemesis/bin/open.sh'], SDK),
(['tools/mkdelta.py', 'tools/mkrecipe.py', 'tools/mkmemrecipe.py'], ['core/runtime/engine-test.sh', 'core/runtime/safety-test.sh', 'tools/lpatch/test.sh']),
(['tools/mkdelta.py', 'tools/mkrecipe.py', 'tools/mkmemrecipe.py'], ['core/runtime/engine-test.sh', 'core/runtime/safety-test.sh', 'core/runtime/journal-test.sh', 'tools/lpatch/test.sh']),
(['tools/mkinstallers.sh', 'tools/mkrelease.sh', 'tools/mkmodpkg.sh', 'tools/mknemesismod.sh', 'tools/nemesis-version.py', 'tools/nemesis-meta.py', 'tools/release-mods.txt'], INSTALL + ['core/runtime/signing-test.sh', 'core/runtime/usb-test.sh'] + SDK + MODS),
# the mod SDK and the reusable mod workflow
(['tools/build-mod.sh', 'tools/check-points.py', 'tools/sdk/*', 'tools/sdk-test.sh', 'tools/mkrecipe.py', 'tools/mkdelta.py', 'tools/mkmemrecipe.py', 'tools/mkicon.sh', 'tools/mod-draft.py', 'tools/check-scripts.sh', '.github/workflows/mod.yml'], SDK),
Expand Down
Loading