Repository navigation
Conversation
…e modes A failed apply (rename, dexopt, remount, copy, settings, state write) now puts every file and setting back in the same run, last changed first, deletes its temp files and starts the apps it stopped. Only a power cut, a killed engine or a failed rollback leaves the journal for recover. Apps stopped (pm disable) while their files change are written to the journal and state/held.txt before they're stopped. recover starts them again, and boot.sh runs engine release-held once Android is up (not while an unfinished apply is waiting). Android itself, persistent apps, OTAClient and apps already off are never stopped. Each file's mode, owner and SELinux label are read before HMG-API first writes it (FileMeta, files.json stockMeta, journal entries) and put back on apply, rollback and restore. A change under /system/bin or /system/xbin must give a "mode". Tests: engine, safety, overlap and boot.sh, with a fake pm and failure injection (HMGAPI_TEST_FAIL, off the unit only). Tested off-car only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
stagedIn puts them in mods/ right before an apply plans, and they went back only when the plan was refused. An apply that fails part-way (an exception, the files rolled back or left for recover) left them in mods/, where their code loads at the next boot, on /system files built for the versions before them. Found combining the open PRs: with #433's gear check and #434's in-run rollback there are more such paths; whichever lands after this puts them back there too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CHANGELOG: keep main's root-service settings entry and this branch's three engine entries under Unreleased. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VysseCodes
left a comment
There was a problem hiding this comment.
Looks good. This PR keeps the held-apps journal (state/held.txt); I've asked #433 to drop its version.
On the new rule refusing /system/bin/xbin changes with no "mode": I checked the mod repos. hmgapi-adb only sets props, hmgapi-adbd binds /sbin/adbd, and hmgapi-nemesis-shortcut has no patches.json, so none is affected.
#434 writes down the apps an apply stops before pm disable and turns them on again at recover, more fully than this PR did. Take state/held.txt out of the engine, boot.sh, the tests, the changelog and the car test, so this PR stays about the gear check. The rest of the cut-off-install hardening (ignoring a closed pipe, syncing before each rename) stays. Tested off-car: tools/test-all.sh --fast, 32 ok, 1 skipped (no ImageMagick). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Engine.recover: #434's version (startHeld, rollback) with the staged ids taken from the journal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CHANGELOG: release/2.0 turned the old Unreleased heading into 1.1.0, which is rc.10's code. This branch's three engine entries and the root-service settings entry came after it, so they go under a new Unreleased heading above 1.1.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VysseCodes
left a comment
There was a problem hiding this comment.
The normal apply path looks good, and it works on a car. These are all in the failure paths:
- The new
/system/bin//system/xbinmode rule is too broad (Engine.java~1284). It refuses any change there with no"mode", including alinesoraddedit to an existing file, whose stock mode (755 root:shell) this PR already keeps (targetMeta). The refusal has no override.safety-test.sh(~101) asserts it fornetd, which already exists, anddocs/mod-reference.mdsays both "keeps the mode, owner and SELinux label" and "must give a mode". Suggest: require a mode only for a new file in those folders. hold()can leave apps stopped (~1917).held = hold(changed, j)is only assigned whenhold()returns. Ifpmfails on the second app, the first stays disabled: the rollback succeeds, thefinallysees an emptyheldand releases nothing, and the app stays off until the next boot. That breaks the changelog's "always come back". Suggest filling the caller's set as each app is disabled (or releasing fromheld.txtin thefinally).hold()ignorespm disable's exit code (~2288). The old code held only apps whose disable worked. Now an app that never stopped keeps running on half-changed files, is reported as "stopped" and written toheld.txt. If its laterpm enablereply lacks "new state", it stays inheld.txt, andboot.shwarns about it every boot.release()can throw from thefinally(~2037). Ifpmcan't start, the caller gets a bare IOException instead of "apply failed: …" and its lines, and the remaining held apps are skipped until the next boot. Suggest catching per app insiderelease()and leaving the rest inheld.txt.- Minor: the
own()helper (mode +meta.txt) is copied intoengine-test.sh,overlap-test.shandsafety-test.sh. One shared copy would keep them from drifting.
From the review of this change: - A file in /system/bin or /system/xbin that has a stock copy keeps that copy's mode, owner and label, so a change to it no longer needs a "mode". Only a new file there does (it would get 644 and not run). The check moved from guard() to build(), where the stock is known. - hold() fills the caller's held set as it goes, each app before its pm disable, so if pm throws at the second app the first is still started again by apply's finally. - hold() checks pm disable's exit code and reply. An app pm won't stop keeps running as before, with a warning; it's dropped from the held set, the journal and held.txt. - release() never throws: a pm that fails for one app leaves that app in held.txt and goes on with the rest, so apply's own failure is what gets reported. The held apps are released even if remount ro throws. - The tests share one own() helper (core/runtime/test-meta.sh). engine-test.sh adds a second app and covers pm failing mid-hold, pm refusing to stop an app, and pm failing at release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VysseCodes
left a comment
There was a problem hiding this comment.
Every point from the review is fixed: the mode rule only for new files in /system/bin and /system/xbin (moved to build(), where the stock is known), hold() filling the held set before each pm disable and dropping apps pm won't stop, release() never throwing, and one shared own() helper. engine-test (224) and safety-test (56) pass here. Thanks.
Fixes the three problems from the 2026-11-26 review of
Engine.java.Held apps
hold()stops (pm disable) are written to the journal andstate/held.txtbefore any is stopped.engine recoverstarts them again. At boot,boot.shwaits forsys.boot_completedand runs the newengine release-held, which refuses while an unfinished apply's journal is there (apps never run on half-changed files).uninstall.shruns recover whenheld.txtis there too.android/ anything in/system/framework, persistent apps (flagsin/data/system/packages.xml), OTAClient, and apps that were off already (before,release()turned those on).File modes
FileMeta: real mode, uid, gid and SELinux label (libcorestatandandroid.os.SELinuxon the unit, toolbox as fallback). Recorded before HMG-API's first write (files.jsonstockMeta, each journal entry) and put back on apply, rollback and restore./system/binor/system/xbinwith no"mode"is refused.Failed apply
binds.txt;*.hmgapi-newandstage/are deleted; held apps are started after the rollback.recoversays "rolled back" only when a file changed, soboot.shdoesn't restart the unit for nothing.Tests
engine-test.sh: failures at swap, dexopt, copy, remount; a simulated power cut, then recover (Android not up) and release-held; a rollback that fails, finished by recover; modes, owners and labels through apply/restore; an old record restored with the defaults. Fakepm; owners/labels off the unit in$R/meta.txt; failure injection withHMGAPI_TEST_FAIL(off the unit only).safety-test.sh: the bin/xbin"mode"rule, stock mode/owner/label back after restore.overlap-test.sh: mode/owner/label kept over a NEMESIS package, after its uninstall (rebase), and on restore.install/common/test.sh: boot.sh runsengine release-heldwhenheld.txtis left.tools/test-all.sh --fast: 31 ok, 1 skipped (no ImageMagick), 0 failed. Full run on macOS: the 6 tests that need qemu-arm, mksh or./build.sh(hmgapid, zygote, lpatch, install-test, usb, sdk) fail the same way on untouched main; CI should run them.Tested off-car only, on no car. Worth checking on a car:
statandandroid.os.SELinuxwork from the engine'sapp_process(ifstatfails, the apply stops before anything changes).🤖 Generated with Claude Code