Skip to content

Restarts, applies and installs only start with the car in P - #433

Open
AwsomeFox wants to merge 6 commits into
release/2.0from
fix/restart-in-park
Open

AwsomeFox wants to merge 6 commits into
release/2.0from
fix/restart-in-park

Conversation

@AwsomeFox

@AwsomeFox AwsomeFox commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

A restart takes the reverse camera's picture away for about a minute (Android shows it on these units), and on 2026-11-27 a NEMESIS install (no HMG-API) cut off by a shift into reverse left a unit that didn't start. Every restart path, every change to /system and every install or update now reads gear.park first.

The rule

  • Not in P: refused before anything changes (exit 75), no override: restarts, applies, installs and updates. A car whose map reads P wrong gets its map fixed.
  • The way back to stock is never refused: uninstall.sh and engine restore warn out of P and go on. The USB uninstall then doesn't restart (a restart is still only in P) and its toast says to restart once in P. Listed as an exception in CLAUDE.md's Recommendations.
  • No gear reading: hmgapid reboot and the engine refuse (exit 76) unless given --gear-unknown-ok; the app passes it only after the owner taps "It's in P: go on". The USB, NEMESIS and adb routes have no one to ask: they warn to stay in P and go on.
  • In P: runs, and the owner is told to stay in P until it's done.
  • HMG-API's vehicle service now always runs (not only while a mod reads the car), so every car with a gear point in its map gives the reading.

Where

  • hmgapid reboot (C, op_reboot/gear_park): every restart.
  • Engine (Gear.java): apply/restore when files on /system change (so also before hold()), and update-hmgapi.
  • install.sh/uninstall.sh: lib.sh gear_gate, before anything changes (gear_gate ... warn for the uninstall). NEMESIS mod package scripts pass --gear-unknown-ok (same policy).
  • boot.sh: the restart after a rollback waits in the background (never holds the boot) for the parked state, or P with the car off (P for two minutes if power can't be read). No reading for 10 minutes: no restart, public/restart-needed for the app.
  • App (Park.java): Restart unit, Apply (when system files change), Install, Update HMG-API and both "Restart now" buttons.

Robustness to a cut-off install

What reverse does to a running install on a car is not checked yet (docs/car-test.md 10b lists what to look for). Hardened meanwhile:

  • install.sh, uninstall.sh and the USB troubleShooter ignore SIGPIPE/HUP/INT/TERM: a closed screen (Engineering Mode, NEMESIS Manager, adb) no longer kills them on their next output line.
  • Each file is synced before its rename, so a reset never leaves an empty app_process.
  • The USB installer's restart waits while the car isn't in P; its toasts say to stay in P.

Testing

Off-car only. tools/test-all.sh --fast: 31 ok, 1 skipped (no ImageMagick). New checks in engine-test.sh, install/common/test.sh (gear_gate, boot waits) and core/hmgapid/test.sh (reboot gate; its fake vehicle service answers gear.park from a file). The hmgapid, zygote, lpatch, install, usb and sdk tests couldn't run on the machine used (no qemu-arm/lld/payload build; the same 6 fail on untouched main there), so core/hmgapid/test.sh runs in CI first. hmgapid.c compiles for ARM with no warnings; the app compiles against android.jar. Not tested on a car.

Follow-ups

  • PR App: Get mods and Updates in the Mods tab #424 (catalog/app): once this is in main, put UpdatesTab's Update HMG-API (updateHmgApi) and its "Restart now", and CatalogFlow.run (the install from CatalogTab), through Park, have Catalog.run skip --gear-unknown-ok as an id (and check the gear before the download), and add a catalog-test.sh case for gear.park 0.
  • The gear reading on every car: straight from the car's system service when the map has none #489 (gear reading straight from the car's system service when the map has none): once it's in release/2.0, gear_gate uses lib.sh stock_gear_park when hmgapid's vehicle service doesn't answer yet (first install, early boot), so --gear-unknown-ok and "It's in P: go on" are only needed where the car's own service doesn't answer. hmgapid reboot and the engine's Gear get it through vehicle gear.park with no change here.
  • Apps left disabled by a cut-off apply (pm disable lasts across restarts): Engine: roll back a failed apply at once, journal held apps, keep file modes #434's held-apps journal, not this PR.
  • The wireless mod's NEMESIS scripts (apps_hold, Open-HMG/hmgapi-wireless-cp-aa) disable apps and swap /system files without a gear check.

🤖 Generated with Claude Code

A restart takes the reverse camera's picture away for about a minute, and on
2026-11-27 a NEMESIS install (no HMG-API) cut off by a shift into reverse left
a unit that didn't start. So every restart path, every change to /system and
every install or update now reads gear.park first.

- hmgapid reboot: refused out of P (75); with no gear reading refused (76)
  unless --gear-unknown-ok.
- Engine: apply and restore that change files (and so may hold system apps),
  and update-hmgapi, check the gear (Gear): not in P 75, no reading 76 unless
  --gear-unknown-ok. The apps hold() stops are written down first
  (state/held.txt) and turned on again by the next start's recover, since
  pm disable lasts across restarts.
- install.sh and uninstall.sh (every route): gear_gate in lib.sh, not in P
  stops with nothing changed, no reading warns and goes on. They and the USB
  installer ignore a closed pipe and hang-ups, and each file is synced before
  its rename. The USB installer's toasts say to stay in P, and its restart
  waits while the car isn't in P.
- boot.sh: the restart after a rollback waits in the background until the car
  is parked (parked state, or P with the car off); no reading for 10 minutes:
  no restart, and a notice for the app.
- The vehicle service always runs, so every car with a gear point gives the
  reading.
- App: Restart, Apply (when files change), Install and Update HMG-API check
  the gear first (Park), say to stay in P, and ask the owner when the car
  gives no reading.

Tested off-car only (tools/test-all.sh --fast all pass; the ARM tests could
not run on this machine). What shifting into reverse does to a running install
on a car is still to check: docs/car-test.md 10b.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AwsomeFox
AwsomeFox requested review from a team and VysseCodes as code owners November 27, 2026 14:34
…t allowed (13)

An op the app's uid may not use answers 13 before the root-only check that
answers 2, as for every other op.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwsomeFox added a commit that referenced this pull request Nov 28, 2026
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>
…estart-in-park

# Conflicts:
#	CHANGELOG.md

@VysseCodes VysseCodes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • state/held.txt: #434 adds a fuller version of the held-apps journal (written before pm disable, released on recover). Please drop that part from this PR and keep it about the gear check.
  • Description: it names CatalogActivity/ModUpdatesActivity; the code has CatalogTab/UpdatesTab.
  • Merge order: #434 → #430 → #433, so this one rebases last.

More review on the "not in P" case to follow.

@VysseCodes

Copy link
Copy Markdown
Collaborator

@Open-HMG/maintainers, input wanted on one design question before this goes in.

When the gear reads "not in P", should the owner be able to override?

As written, "not in P" has no override (only "no reading" has --gear-unknown-ok), and uninstall.sh and install.sh exit 75 on it. If a map's gear.park point is wrong and reads 0 while parked, the owner can't uninstall, install, apply or restart. The project's usual rule is a warning plus an override, not a silent block.

Options:

  1. Override for everything: refused by default, but a separate flag (e.g. --not-parked-ok, or the app's "I'm in P, the reading is wrong") goes ahead with a warning.
  2. Override for uninstall only: install, apply and restart stay blocked; uninstall.sh warns and goes on, so the owner can always get back to stock.
  3. Keep as is: no override; accept the lockout risk from a wrong map reading.

Which do you prefer, and why?

#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>
@AwsomeFox

Copy link
Copy Markdown
Contributor Author

My vote: 2, plus an explicit override for the rest.

  • Uninstall can always get back to stock: on "not in P" it warns and goes on. A wrong gear.park point must never lock an owner out of stock.
  • Install, apply and restart stay refused by default, but take an explicit override (--not-parked-ok, and in the app an "I'm in P, the reading is wrong" confirm), with a warning.

A wrong map reading then costs one extra tap instead of a lockout, and nothing restarts the head unit while driving unless the owner says they're parked. I won't implement it until the maintainers agree.

AwsomeFox added a commit that referenced this pull request Nov 30, 2026
Kept #434's held-apps journal where #433 dropped its own version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DY-Jeong added a commit to DY-Jeong/HMG-API that referenced this pull request Dec 1, 2026
…tart with the car in P

From AwsomeFox/fix/restart-in-park (Open-HMG#433).

# Conflicts:
#	CLAUDE.md
#	core/hmgapid/hmgapid.c
#	core/runtime/java/hmgapi/engine/Engine.java
#	core/runtime/java/hmgapi/engine/ModRuntime.java
DY-Jeong added a commit to DY-Jeong/HMG-API that referenced this pull request Dec 1, 2026
…gear check reads through it)

Taken from upstream's integration branch (Open-HMG#440, 6264f2d): Open-HMG#433 runs the vehicle
service always, so live-test and safe-test expect it.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AwsomeFox
AwsomeFox changed the base branch from main to release/2.0 December 1, 2026 16:39
…o fix/restart-in-park

# Conflicts:
#	CHANGELOG.md
@VysseCodes

Copy link
Copy Markdown
Collaborator

Decision: option 2.

  • Uninstall: when the gear reads "not in P", it warns and goes on, so a wrong gear.park reading can never lock an owner out of stock.
  • Install, apply and restart: refused when the gear reads "not in P", with no override. "No reading" keeps --gear-unknown-ok as it is now.

I know the vote was 2 plus an override for the rest. I'd rather not have a "not parked" override at all: if a car's map reads P wrong, the fix is the map, and uninstall is always there in the meantime.

Since this is a block with no override, please add it to the exceptions in CLAUDE.md's Recommendations section in this PR. Merge order is unchanged: #434 → #430 → #433.

The review's decision (option 2): a car whose gear.park reads 0 while
parked must never be kept from stock. uninstall.sh (gear_gate ... warn)
and engine restore, its first half, now warn out of P and go on.
Restarts, applies, installs and updates are still refused out of P with
no override; a map that reads P wrong is fixed in the map.

The USB uninstall reads the gear before it runs (the uninstall takes
hmgapid away). Out of P it uninstalls, doesn't restart, and its toast
says to restart once in P.

CLAUDE.md's Recommendations now list this as an exception: no override
for "not in P", and the way back to stock never refused.

Tested off-car: engine-test, install/common/test.sh, the NEMESIS mod
and sync tests and check-scripts pass. install/usb/test.sh (its new
uninstall-out-of-P case) needs the ARM payload build, so CI runs it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sirishant added a commit to sirishant/HMG-API that referenced this pull request Dec 2, 2026
HMG-API 2.0 refuses installs, updates and restarts unless hmgapid's gear.park reads 1
(Open-HMG#433, no override), and there is no reading from this car yet. The
logger now asks for it every 5 s in the background, like the ignition, and notes it
under the HMG-API tag at each log's start and whenever it changes: 1, 0, "-" (the car
didn't answer), no answer or no reading. gear.park is declared in mod.json; a test
checks every reading the script asks for is declared.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VysseCodes

Copy link
Copy Markdown
Collaborator

For the "no gear reading" case: #489 gives a reading on cars without a hook map. The gear point is a stock Binder service (com.hkmc.micom.system, ISystemService.getGearPStatus, transaction 36 in all 21 stock builds we have, no permission check), so it's read directly when the map has no point:

  • hmgapid vehicle gear.park answers on every car (Hub.gearP), so hmgapid reboot and the engine's Gear check get it once the vehicle service runs (this PR makes it always run).
  • lib.sh stock_gear_park (prints 1, 0 or nothing) for gear_gate in install.sh/uninstall.sh and boot.sh, before the vehicle service is up.

With both, --gear-unknown-ok and the "It's in P: go on" tap should only be needed where the car's own service doesn't answer. Worth using in gear_gate once #489 merges (or I can add it in a follow-up).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants