Files
mg4/app/src/main/java/com/evsuite/abrp/BootReceiver.java
T
TCFDONMEZandClaude 2fd7b2dde1 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>
2026-09-22 10:45:00 +03:00

70 lines
3.1 KiB
Java

package com.evsuite.abrp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.util.Log;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* Restarts uploading when the head unit powers up.
*
* BOOT_COMPLETED alone was not enough. An MG4's head unit rarely cold-boots: switching the
* car on usually resumes it, and the resume is announced with QUICKBOOT_POWERON instead.
* Users reported uploading never starting with the car, and this is why — the app was
* waiting for a broadcast their car does not always send. The other EVSuite apps already
* listen to the whole family; this one now does too.
*
* MY_PACKAGE_REPLACED is in the list for a different reason: an update stops the service,
* and nothing else would bring it back until the next power cycle.
*/
public class BootReceiver extends BroadcastReceiver {
private static final String TAG = "EVABRP.Boot";
private static final Set<String> START_ACTIONS = new HashSet<>(Arrays.asList(
Intent.ACTION_BOOT_COMPLETED,
Intent.ACTION_MY_PACKAGE_REPLACED,
"android.intent.action.LOCKED_BOOT_COMPLETED",
"android.intent.action.QUICKBOOT_POWERON",
"com.htc.intent.action.QUICKBOOT_POWERON"
));
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action == null || !START_ACTIONS.contains(action)) return;
SharedPreferences prefs = context.getSharedPreferences("abrp_prefs", Context.MODE_PRIVATE);
boolean enabled = prefs.getBoolean("service_enabled", false);
boolean autostart = prefs.getBoolean(UploadSettings.KEY_AUTOSTART, UploadSettings.DEFAULT_AUTOSTART);
// Credentials come from SecurePrefs, not from the plaintext file. This receiver used
// to read "token" out of abrp_prefs — where it has not lived since the credentials
// were encrypted, because the migration deletes the plaintext copy. The check
// therefore always failed, and uploading never started by itself on any car.
SharedPreferences secure = SecurePrefs.get(context);
boolean haveCreds = !secure.getString(SecurePrefs.KEY_TOKEN, "").trim().isEmpty()
&& !secure.getString(SecurePrefs.KEY_API_KEY, "").trim().isEmpty();
if (!enabled || !autostart || !haveCreds) {
Log.i(TAG, action + " ignored (enabled=" + enabled
+ " autostart=" + autostart + " credentials=" + haveCreds + ")");
return;
}
Log.i(TAG, action + " — starting upload service");
try {
context.startForegroundService(new Intent(context, AbrpUploadService.class));
} catch (Exception e) {
// A start refused this early is not worth crashing the boot broadcast over: the
// next power cycle, or opening the app, starts it just the same.
Log.w(TAG, "startForegroundService failed: " + e.getMessage());
}
}
}