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

## Unreleased

- **Restarts, applies and installs only start with the car in P.** 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.
`hmgapid reboot` (every restart: the app's buttons, the boot steps), `engine apply` when it
changes files on `/system` (and so may stop system apps for the swap), `engine update-hmgapi`,
and `install.sh` (every install route) read `gear.park` first. Not in P: refused (exit 75),
nothing changed, no override. The way back to stock is never refused: `uninstall.sh` and
`engine restore` warn and go on, so a car whose map reads P wrong can always uninstall; the
USB uninstall then doesn't restart, and says to restart once in P. No reading (the
car's map has no gear point, or the vehicle service isn't up yet): `hmgapid reboot` and the
engine refuse (exit 76) unless told `--gear-unknown-ok`, which the app passes once the owner
says the car is in P; the USB, NEMESIS and adb routes, with no one to ask, warn and go on. The
app tells the owner to stay in P until it's done, as does the USB installer's toast.
- **HMG-API's vehicle service always runs**, not only while a mod reads the car, so every car
with a gear point in its map gives the reading the checks above need.
- **The restart after a boot-time rollback waits for the car to be parked**, in the background
(the boot never waits): HMG-API's parked state, or in P with the car off (in P for two minutes
when the power status can't be read). Until then the app shows Restart needed; with no gear
reading for 10 minutes there's no restart, and the app's Restart asks the owner.
- **A cut-off install leaves less behind.** `install.sh`, `uninstall.sh` and the USB installer
ignore a closed output pipe and hang-ups (a screen that closed under them, an adb that
dropped), and sync each file before renaming it into place, so a reset right after never
leaves an empty `app_process`. The USB installer's restart waits while the car isn't in P.
Tested off-car only: what shifting into reverse does to a running install on a car is still
to be checked (`docs/car-test.md`).
- **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
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ HMG-API (1.1.0) is a mod manager for Hyundai/Kia/Genesis **Gen5W** head units (T

## Recommendations (warn, then follow the user)

Owners get to decide for their own units. Follow these by default. If the user asks to go against one, say the risk in a line or two, then do what they asked. HMG-API does the same for its users: a warning plus an override, never a silent block. For now one exception: an `app_process` not in `install/common/stock.txt` is refused with no owner-facing override (no stick file, no message names one); `HMGAPI_FORCE=1` over adb stays for maintainers.
Owners get to decide for their own units. Follow these by default. If the user asks to go against one, say the risk in a line or two, then do what they asked. HMG-API does the same for its users: a warning plus an override, never a silent block. For now two exceptions: an `app_process` not in `install/common/stock.txt` is refused with no owner-facing override (no stick file, no message names one); `HMGAPI_FORCE=1` over adb stays for maintainers. And a restart, an apply that changes `/system`, or an install or update while `gear.park` says the car isn't in P is refused (exit 75) with no override (no flag, no "the reading is wrong" button), saying to shift to P: 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 leaves the restart to the owner). With no gear reading it's the usual warning plus override (`--gear-unknown-ok`; the installers, with no one to ask, warn and go on). A restart takes the reverse camera's picture away for about a minute, and a shift into reverse can cut an install off (`hmgapi.engine.Gear`, `hmgapid reboot`, `lib.sh` `gear_gate`). New steps of that kind go through the same check.

- Only firmware from 2026 onward (`26xxxx`) is supported for now; maps target each car's newest for its region: US 260507 (some models are on 260903: `maps/hyundai/neev23/usa/260903`), Canada 260206. Each region has its own builds, so maps (`maps/<make>/<model>/<region>/<firmware>`, `car.json` `products`) and a mod's `"system"` match the full region, e.g. `CVEV.USA.`. Don't port pre-2026 firmware by default; ask the owner to update the head unit. With no map for the car, mods still install, points it can't find stay off, and a car missing from a mod's `"system"` is a warning with an override.
- Don't flash MICOM, the bootloader or modem firmware, or firmware meant for another car: these can brick the unit or the car beyond what a USB stick can fix.
Expand Down
67 changes: 36 additions & 31 deletions core/app/java/hmgapi/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void onClick(View v) {
Ui.button(actions, "Restart unit", new View.OnClickListener() {
@Override
public void onClick(View v) {
confirmRestart();
Park.confirmRestart(MainActivity.this);
}
});
top.addView(actions);
Expand Down Expand Up @@ -223,6 +223,8 @@ static long boot() {
}

boolean restartNeeded() {
// boot.sh rolled a cut-off apply back and waits for the car to be parked to restart, or left it to the owner
if (new java.io.File("/data/hmgapi/public/restart-needed").isFile()) return true;
return getSharedPreferences("hmgapi", MODE_PRIVATE).getLong("restart_boot", -1) == boot();
}

Expand Down Expand Up @@ -273,25 +275,38 @@ void done(Hmgapid.Result r, Exception e) {
: "Everything is applied.");
return;
}
new AlertDialog.Builder(MainActivity.this).setTitle("Apply these changes?").setMessage(shown)
final boolean files = filesChange(r.output);
new AlertDialog.Builder(MainActivity.this).setTitle("Apply these changes?")
.setMessage(files ? shown + "\n\nThis changes system files, so it only starts with the car in P. " + Park.STAY : shown)
.setNegativeButton("Cancel", null)
.setPositiveButton("Apply", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
apply();
if (!files) {
apply(false);
return;
}
Park.then(MainActivity.this, APPLYING, new Park.Go() {
@Override
public void go(boolean unknownOk) {
apply(unknownOk);
}
});
}
}).show();
}
}.start(this);
}

private void apply() {
static final String APPLYING = "Applying changes to system files";

private void apply(final boolean unknownOk) {
final AlertDialog wait = new AlertDialog.Builder(this)
.setMessage("Applying… (rebuilding apps can take a few minutes; leave the head unit on)").setCancelable(false).show();
new Ui.Job<Hmgapid.Result>() {
@Override
Hmgapid.Result work() throws Exception {
return Hmgapid.call(900000, "engine", "apply");
return Hmgapid.call(900000, Park.with(unknownOk, "engine", "apply"));
}

@Override
Expand All @@ -301,6 +316,13 @@ void done(Hmgapid.Result r, Exception e) {
message("Lost contact while applying", e.getMessage() + ". The apply finishes on its own; open HMG-API again to check.");
return;
}
// the car left P since the check (or gives no reading): nothing was changed
if (Park.refused(MainActivity.this, r, APPLYING, new Park.Go() {
@Override
public void go(boolean ok) {
apply(ok);
}
})) return;
boolean restart = restartNeeded() || r.output.contains("restart the head unit");
if (r.output.contains("restart the head unit")) needRestart();
AlertDialog.Builder d = new AlertDialog.Builder(MainActivity.this)
Expand All @@ -327,6 +349,14 @@ void message(String title, String text) {
new AlertDialog.Builder(this).setTitle(title).setMessage(text).setPositiveButton("OK", null).show();
}

/** Does an engine plan change files on /system (only in P: hmgapi.engine.Gear)? */
static boolean filesChange(String out) {
for (String l : out.split("\n")) {
if (l.startsWith("change ") || l.startsWith("update ") || l.startsWith("restore ")) return true;
}
return false;
}

/** Does an engine plan change anything? */
static boolean changes(String out) {
for (String l : out.split("\n")) {
Expand All @@ -347,32 +377,7 @@ static String readable(String out) {
return b.toString().trim();
}

private void confirmRestart() {
new AlertDialog.Builder(this)
.setTitle("Restart the head unit?")
.setMessage("The screen goes dark for about a minute. Don't use this while driving with navigation or a call active.")
.setNegativeButton("Cancel", null)
.setPositiveButton("Restart", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
restart();
}
})
.show();
}

void restart() {
new Ui.Job<Hmgapid.Result>() {
@Override
Hmgapid.Result work() throws Exception {
return Hmgapid.call("reboot");
}

@Override
void done(Hmgapid.Result r, Exception e) {
if (e == null && r.code == 0) return;
message("Couldn't restart", e != null ? "hmgapid isn't running (" + e.getMessage() + ")" : r.output.trim());
}
}.start(this);
Park.restart(this);
}
}
157 changes: 157 additions & 0 deletions core/app/java/hmgapi/app/Park.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package hmgapi.app;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;

/**
* Steps that only start with the car in P: a restart (it takes the reverse camera's picture
* away for about a minute), and anything that changes /system or stops system apps for a
* while (an apply, an install, an HMG-API update), which a shift into reverse can cut off half
* done. The gear comes from HMG-API's vehicle reading (hmgapid `vehicle gear.park`). Not in P:
* the owner is told to shift to P, and nothing starts. No reading on this car: the warning
* plus override (the owner says the car is in P, and the step runs with --gear-unknown-ok).
* hmgapid's reboot and the engine check again (hmgapi.engine.Gear: exit codes 75 and 76), so
* a shift between the check here and the step still stops it.
*/
final class Park {
private Park() {}

static final int NOT_PARKED = 75;
static final int UNKNOWN = 76;
static final String OVERRIDE = "--gear-unknown-ok";
static final String STAY = "Keep the car in P until it's done.";

interface Go {
/** the step itself; unknownOk: add OVERRIDE (no gear reading, the owner said go on) */
void go(boolean unknownOk);
}

/** what: the step, for the messages ("Restarting the head unit") */
static void then(final Activity a, final String what, final Go go) {
new Ui.Job<Integer>() {
@Override
Integer work() throws Exception {
Hmgapid.Result r = Hmgapid.call("vehicle", "gear.park");
return r.code == 0 ? parse(r.output) : -1;
}

@Override
void done(Integer g, Exception e) {
int v = e != null || g == null ? -1 : g;
if (v == 1) go.go(false);
else if (v == 0) notParked(a, what);
else unknown(a, what, go);
}
}.start(a);
}

/** hmgapid's answer, "gear.park 1" ("-" when the car didn't answer): 1, 0, or -1 */
static int parse(String out) {
for (String l : out.split("\n")) {
l = l.trim();
if (l.equals("gear.park 1")) return 1;
if (l.equals("gear.park 0")) return 0;
}
return -1;
}

static void notParked(Activity a, String what) {
new AlertDialog.Builder(a).setTitle("Shift to P first")
.setMessage(what + " only starts with the car in P: shifting into reverse while it runs can cut it off "
+ "half done, and a restart takes the reverse camera's picture away for about a minute. Nothing was changed.")
.setPositiveButton("OK", null).show();
}

static void unknown(Activity a, final String what, final Go go) {
new AlertDialog.Builder(a).setTitle("Is the car in P?")
.setMessage("HMG-API can't read the gear on this car, so it can't check that it's in P. " + what
+ " should only run in P: shifting into reverse while it runs can cut it off half done, and a "
+ "restart takes the reverse camera's picture away for about a minute.\n\nPut the car in P. " + STAY)
.setNegativeButton("Cancel", null)
.setPositiveButton("It's in P: go on", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
go.go(true);
}
}).show();
}

/**
* An op the engine or hmgapid refused for the gear (75, 76): said here, true. For 76 the
* owner may go on: retry runs the step again with OVERRIDE.
*/
static boolean refused(Activity a, Hmgapid.Result r, String what, Go retry) {
if (r == null) return false;
if (r.code == NOT_PARKED) {
notParked(a, what);
return true;
}
if (r.code == UNKNOWN) {
unknown(a, what, retry);
return true;
}
return false;
}

/** a command with OVERRIDE added when asked */
static String[] with(boolean unknownOk, String... cmd) {
if (!unknownOk) return cmd;
String[] c = new String[cmd.length + 1];
System.arraycopy(cmd, 0, c, 0, cmd.length);
c[cmd.length] = OVERRIDE;
return c;
}

/** Restart the head unit: asked first, then only in P (every restart button: Main, Updates) */
static void confirmRestart(final Activity a) {
new AlertDialog.Builder(a)
.setTitle("Restart the head unit?")
.setMessage("The screen goes dark for about a minute, and the reverse camera's picture with it, so this "
+ "only runs with the car in P. Don't use it with navigation or a call active.")
.setNegativeButton("Cancel", null)
.setPositiveButton("Restart", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface d, int which) {
restart(a);
}
})
.show();
}

/** the restart itself, after the owner's yes: the gear, then hmgapid reboot */
static void restart(final Activity a) {
then(a, RESTART, new Go() {
@Override
public void go(boolean unknownOk) {
restartNow(a, unknownOk);
}
});
}

static final String RESTART = "Restarting the head unit";

/** hmgapid reboot, which checks the gear again (a shift since the check here: said, nothing done) */
static void restartNow(final Activity a, final boolean unknownOk) {
new Ui.Job<Hmgapid.Result>() {
@Override
Hmgapid.Result work() throws Exception {
return Hmgapid.call(with(unknownOk, "reboot"));
}

@Override
void done(Hmgapid.Result r, Exception e) {
if (e == null && r.code == 0) return;
if (e == null && refused(a, r, RESTART, new Go() {
@Override
public void go(boolean ok) {
restartNow(a, ok);
}
})) return;
new AlertDialog.Builder(a).setTitle("Couldn't restart")
.setMessage(e != null ? "hmgapid isn't running (" + e.getMessage() + ")" : r.output.trim())
.setPositiveButton("OK", null).show();
}
}.start(a);
}
}
Loading
Loading