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>
71 lines
2.8 KiB
Java
71 lines
2.8 KiB
Java
package com.evsuite.abrp;
|
|
|
|
import android.content.Context;
|
|
import android.content.SharedPreferences;
|
|
import android.util.Log;
|
|
|
|
import androidx.security.crypto.EncryptedSharedPreferences;
|
|
import androidx.security.crypto.MasterKey;
|
|
|
|
/**
|
|
* Storage for the ABRP credentials (api_key, token).
|
|
*
|
|
* They used to sit in plaintext in the regular SharedPreferences file, which
|
|
* `adb backup` hands out. They now live in an AndroidKeyStore-backed encrypted
|
|
* file, and the plaintext copy is wiped on first access.
|
|
*/
|
|
final class SecurePrefs {
|
|
|
|
private static final String TAG = "SecurePrefs";
|
|
private static final String FILE_NAME = "abrp_secure_prefs";
|
|
private static final String PLAIN_NAME = "abrp_prefs";
|
|
|
|
static final String KEY_API_KEY = "api_key";
|
|
static final String KEY_TOKEN = "token";
|
|
|
|
private static SharedPreferences instance;
|
|
|
|
private SecurePrefs() { }
|
|
|
|
/**
|
|
* Encrypted preferences, or the plaintext file if the crypto stack is
|
|
* unavailable. Falling back keeps the app usable on a device with a broken
|
|
* keystore instead of crashing it in a vehicle.
|
|
*/
|
|
static synchronized SharedPreferences get(Context context) {
|
|
if (instance != null) return instance;
|
|
Context app = context.getApplicationContext();
|
|
try {
|
|
MasterKey masterKey = new MasterKey.Builder(app)
|
|
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
|
|
.build();
|
|
instance = EncryptedSharedPreferences.create(
|
|
app,
|
|
FILE_NAME,
|
|
masterKey,
|
|
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
|
|
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM);
|
|
migratePlaintext(app, instance);
|
|
} catch (Exception e) {
|
|
Log.e(TAG, "Encrypted preferences unavailable, falling back to plaintext", e);
|
|
instance = app.getSharedPreferences(PLAIN_NAME, Context.MODE_PRIVATE);
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
/** Moves credentials written by an older version, then deletes the plaintext copy. */
|
|
private static void migratePlaintext(Context context, SharedPreferences secure) {
|
|
SharedPreferences plain = context.getSharedPreferences(PLAIN_NAME, Context.MODE_PRIVATE);
|
|
String apiKey = plain.getString(KEY_API_KEY, null);
|
|
String token = plain.getString(KEY_TOKEN, null);
|
|
if (apiKey == null && token == null) return;
|
|
|
|
SharedPreferences.Editor secureEdit = secure.edit();
|
|
if (apiKey != null) secureEdit.putString(KEY_API_KEY, apiKey);
|
|
if (token != null) secureEdit.putString(KEY_TOKEN, token);
|
|
secureEdit.commit();
|
|
|
|
plain.edit().remove(KEY_API_KEY).remove(KEY_TOKEN).commit();
|
|
}
|
|
}
|