diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f898a92..b7376e8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## Unreleased + +- **The gear reading works on every car, map or not.** HMG-API read "in P" through the hook + map, so a car with no map had no gear reading. The reading now falls back to the car's own + system service (`com.hkmc.micom.system`, `getGearPStatus`, transaction 36: the same in every + stock build checked), which needs no map, hook or patched file. The vehicle service uses it + (`hmgapid vehicle gear.park`), and `lib.sh`'s `stock_gear_park` gives it to the installer and + boot scripts even when the vehicle service isn't running. + ## 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 diff --git a/core/runtime/java/hmgapi/vehicle/Hub.java b/core/runtime/java/hmgapi/vehicle/Hub.java index f5ae9378..402b8aea 100644 --- a/core/runtime/java/hmgapi/vehicle/Hub.java +++ b/core/runtime/java/hmgapi/vehicle/Hub.java @@ -3,6 +3,7 @@ import android.net.LocalServerSocket; import android.net.LocalSocket; import android.os.IBinder; +import android.os.Parcel; import hmgapi.engine.CarMap; import hmgapi.engine.SystemCheck; @@ -213,7 +214,8 @@ static void eventsTick() { services.remove("framework.car_services.power"); } try { - g = num(call(system(), "framework.system_service.gear_p_status")) == 1 ? 1 : 0; + g = gearP(); + if (g < 0) g = -1; } catch (Throwable t) { g = -1; } @@ -449,8 +451,11 @@ static synchronized String value(String name) { } static String read(String name) throws Exception { + if ("gear.park".equals(name)) { // on every car: no map needed (gearP) + int g = gearP(); + return g < 0 ? null : bool(g == 1); + } if (!Points.ready()) return null; - if ("gear.park".equals(name)) return bool(num(call(system(), "framework.system_service.gear_p_status")) == 1); if ("power".equals(name)) { if (!Points.has("framework.power_service.power_status")) return null; return Parking.powerName(num(call(power(), "framework.power_service.power_status"))); @@ -544,6 +549,48 @@ static String hevRaw(String flag) throws Exception { return v < 0 ? null : String.valueOf(v); } + /** + * The gear: 1 in P, 0 not, -1 no reading. Through the map's point when the map has it, else + * straight from the stock service, which needs no map, hook or patched file: + * com.hkmc.micom.system (com.hkmc.Service.SYSTEM_SERVICE), ISystemService.getGearPStatus, + * transaction 36 (0x24) and the same in every stock framework checked (21 builds, 260206 to + * 260903, Kia and Hyundai, US, CA, KOR); its implementation returns a field, with no permission + * check. lib.sh stock_gear_park reads the same for the installer and boot scripts. + */ + static int gearP() { + try { + if (Points.ready() && Points.has("framework.system_service.gear_p_status")) { + int g = num(call(system(), "framework.system_service.gear_p_status")); + if (g >= 0) return g == 1 ? 1 : 0; + } + } catch (Throwable t) { + // the stock service below + } + return stockGearP(); + } + + static final String SYSTEM_SERVICE = "com.hkmc.micom.system", SYSTEM_IFACE = "com.hkmc.micom.ISystemService"; + static final int GEAR_P_STATUS = 36; // TRANSACTION_getGearPStatus + + static int stockGearP() { + Parcel data = null, reply = null; + try { + IBinder b = (IBinder) Class.forName("android.os.ServiceManager").getMethod("getService", String.class).invoke(null, SYSTEM_SERVICE); + if (b == null) return -1; + data = Parcel.obtain(); + reply = Parcel.obtain(); + data.writeInterfaceToken(SYSTEM_IFACE); + if (!b.transact(GEAR_P_STATUS, data, reply, 0)) return -1; + reply.readException(); + return reply.readInt() == 1 ? 1 : 0; + } catch (Throwable t) { + return -1; + } finally { + if (data != null) data.recycle(); + if (reply != null) reply.recycle(); + } + } + static Object system() throws Exception { return service("framework.car_services.system", "framework.system_service_stub.as_interface", null); } @@ -646,11 +693,7 @@ static Object get(String what) { } public boolean park() { - try { - return num(call(system(), "framework.system_service.gear_p_status")) == 1; - } catch (Exception e) { - return false; - } + return gearP() == 1; } public void chargeDoor(boolean close) { run(get("bcm"), "framework.bcm_service.charge_door", close); } diff --git a/install/common/lib.sh b/install/common/lib.sh index 295394e6..39464536 100644 --- a/install/common/lib.sh +++ b/install/common/lib.sh @@ -9,6 +9,20 @@ HOOK_END="# HMGAPI_HOOK end" log() { echo "$1"; echo "$1" >> "$LOG" 2>/dev/null; } sum() { set -- $(md5 "$1" 2>/dev/null); echo "$1"; } +# The gear from the car's own system service, with no map, hook or patched file (and no +# HMG-API vehicle service): com.hkmc.micom.system's getGearPStatus, transaction 36, the same +# in every stock framework checked (hmgapi.vehicle.Hub.gearP reads the same). Prints 1 in P, +# 0 not in P, nothing when there's no reading (Android not up, the service not answering). +# Toolbox's `service`; the reply is `Result: Parcel(00000000 00000001 '........')`. +stock_gear_park() { + local r + r=$(service call com.hkmc.micom.system 36 2>/dev/null) || return 0 + case "$r" in + *"Parcel(00000000 00000001"*) echo 1 ;; + *"Parcel(00000000 00000000"*) echo 0 ;; + esac +} + # NEMESIS 1.17's LivePatch puts its own shell script at /system/bin/app_process (its watchdog # writes it again on every boot, LivePatch package or not) and runs app_process.real, which # holds whatever binary it found there first: stock, or HMG-API's wrapper. Under that script diff --git a/install/common/test.sh b/install/common/test.sh index 21bc1355..ea0a19e3 100644 --- a/install/common/test.sh +++ b/install/common/test.sh @@ -108,6 +108,16 @@ echo 999999 > "$D/state/hook-check.pid" HC > /dev/null check "hook-check: a stale lock (after a restart) doesn't stop it" "1" "$(grep -c 'HMGAPI_HOOK begin' "$T/system/etc/install-recovery.sh")" +# stock_gear_park (lib.sh): the gear from the car's system service, no map needed +mkdir -p "$T/gb" +GP() { printf '#!/bin/sh\necho "$*" > %s/gb/args\n%s\n' "$T" "$1" > "$T/gb/service"; chmod +x "$T/gb/service"; env PATH="$T/gb:$PATH" $SH -c ". $PWD/lib.sh; stock_gear_park"; } +check "stock_gear_park: in P" "1" "$(GP "echo \"Result: Parcel(00000000 00000001 '........')\"")" +check "... asks com.hkmc.micom.system for transaction 36" "call com.hkmc.micom.system 36" "$(cat "$T/gb/args")" +check "stock_gear_park: not in P" "0" "$(GP "echo \"Result: Parcel(00000000 00000000 '........')\"")" +check "stock_gear_park: the service not there: no reading" "" "$(GP "echo \"Result: Parcel(fffffffe ffffffb6 '........')\"")" +check "stock_gear_park: service fails: no reading" "" "$(GP "exit 1")" +rm -rf "$T/gb" + # boot.sh: an apply that was cut off (or a trial) is rolled back, then one restart. A # recover that fails part-way keeps its journal, so restarting on it would loop. mkdir -p "$T/system/bin"