Fatih'sMG4 — ABRP telemetry for an MG4 EH32 on SWI69

A fork of malys/EVABRPUploader (itself a fork of Leon Kernan's ABRP_Uploader)
carrying the changes that make it work on this car. History starts here: the
tree is what matters, and the upstream projects are where the earlier work
belongs.

EVHardware is vendored rather than tracked as a submodule, so one clone
builds.

Telemetry. SOC, battery power and range read as unavailable on SWI69 because
the vendor fallbacks were gated to SWI68 alone, while the property ids they
use are the ones this car publishes — the gates now admit SWI69. Tyre
pressure, the odometer and charge status come from the vendor block too,
since the generic properties for all three are declared here and never
publish. Tyre pressure is confirmed on the vehicle; the other two are not
yet.

Vehicle page. Every signal the car answers, in a table. One that it does not
publish shows a dash: an unimplemented VHAL property returns zero, and
"0 °C" would read as a measurement.

Wi-Fi page. Joins a network the unit already has saved, so a phone hotspot
does not need a trip into Settings on every drive. Tried on the upload tick
and from a button, skipped while already associated. This leans on the unit
being API 28 and the build being platform-signed — getConfiguredNetworks and
enableNetwork are closed to ordinary apps from API 29 — and fails quietly
where that does not hold.

The OTA updater points at this repository. An APK from upstream is signed
with a different key, which Android will not install over a platform-signed
build.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
TCFDONMEZ
2026-09-22 10:45:00 +03:00
co-authored by Claude
commit 2fd7b2dde1
245 changed files with 35594 additions and 0 deletions
@@ -0,0 +1,123 @@
package com.evsuite.abrp;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
/**
* ABRP telemetry endpoint.
*
* Credentials go in the POST body, never in the query string: a URL travels
* through proxies, CDN access logs and crash reports, a body does not.
*/
final class AbrpApi {
/** No query string: credentials travel in the body, so the URL is a constant. */
static final String API_URL = "https://api.iternio.com/1/tlm/send";
/**
* Read-only endpoint used to validate credentials. The connection test must never
* touch /tlm/send: posting a placeholder sample tells ABRP the car really is in that
* state and corrupts the user's live route plan.
*/
static final String VERIFY_URL = "https://api.iternio.com/1/tlm/get_next_charge";
private static final int TIMEOUT_MS = 8_000;
private AbrpApi() { }
/** HTTP status plus response body. */
static final class Response {
final int code;
final String body;
Response(int code, String body) {
this.code = code;
this.body = body;
}
}
/**
* Validates credentials without writing anything. Read-only by construction: it is a
* GET against {@link #VERIFY_URL}, so no telemetry is recorded whatever the outcome.
*
* Tension with T-912 (no credential in a URL): this endpoint only accepts the token as
* a query parameter. The api_key is moved to the Authorization header, which is the
* part we can keep out of access logs; the token cannot be, short of dropping the
* read-only check and going back to writing fake telemetry. Sending one token in one
* URL when the user presses Test beats corrupting their route plan on every press.
*/
static Response verifyCredentials(String apiKey, String token) throws IOException {
HttpURLConnection conn = null;
try {
String url = VERIFY_URL
+ "?token=" + URLEncoder.encode(token, StandardCharsets.UTF_8.name());
conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Authorization", "APIKEY " + apiKey);
conn.setConnectTimeout(TIMEOUT_MS);
conn.setReadTimeout(TIMEOUT_MS);
int code = conn.getResponseCode();
return new Response(code, readBody(conn, code));
} finally {
if (conn != null) conn.disconnect();
}
}
/** Posts one telemetry sample. Throws on network failure. */
static Response send(String apiKey, String token, String tlmJson) throws IOException {
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) new URL(API_URL).openConnection();
conn.setRequestMethod("POST");
conn.setConnectTimeout(TIMEOUT_MS);
conn.setReadTimeout(TIMEOUT_MS);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
byte[] payload = formBody(apiKey, token, tlmJson).getBytes(StandardCharsets.UTF_8);
conn.setFixedLengthStreamingMode(payload.length);
try (OutputStream out = conn.getOutputStream()) {
out.write(payload);
}
int code = conn.getResponseCode();
return new Response(code, readBody(conn, code));
} finally {
if (conn != null) conn.disconnect();
}
}
/** Form-encoded request body carrying the credentials and the telemetry sample. */
static String formBody(String apiKey, String token, String tlmJson) throws IOException {
return "api_key=" + URLEncoder.encode(apiKey, StandardCharsets.UTF_8.name())
+ "&token=" + URLEncoder.encode(token, StandardCharsets.UTF_8.name())
+ "&tlm=" + URLEncoder.encode(tlmJson, StandardCharsets.UTF_8.name());
}
private static String readBody(HttpURLConnection conn, int code) {
// getErrorStream() returns null on some non-200 responses; passing null to
// InputStreamReader throws. Checked rather than left to the catch-all below.
java.io.InputStream stream;
try {
stream = code == 200 ? conn.getInputStream() : conn.getErrorStream();
} catch (Exception e) {
return "";
}
if (stream == null) return "";
try (BufferedReader br = new BufferedReader(
new InputStreamReader(stream, StandardCharsets.UTF_8))) {
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) sb.append(line);
return sb.toString();
} catch (Exception e) {
return "";
}
}
}