App 2.19.3: update log on the Logs tab

Every update and install step, with the platform's own result, kept
across the restart an install causes, so a failed install on the car
can be read off the screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LhzAVaUyqcw5PkGjz4mWW6
This commit is contained in:
2026-10-23 21:15:44 +02:00
co-authored by Claude Opus 5.5
parent 50217aef74
commit 51beea5ed8
11 changed files with 147 additions and 7 deletions
@@ -29,6 +29,8 @@ public final class OtaInstallResultReceiver extends BroadcastReceiver {
int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, PackageInstaller.STATUS_FAILURE);
String message = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE);
Log.i(TAG, "OTA install result: status=" + status + " msg=" + message);
UpdateLog.record(context, "Install result: status " + status
+ (message != null ? ", " + message : ""));
switch (status) {
case PackageInstaller.STATUS_PENDING_USER_ACTION:
@@ -468,11 +468,14 @@ final class OtaUpdater {
return InstallResult.SESSION_STARTED;
} catch (Throwable t) {
Log.w(TAG, "OTA session install failed; trying system install UI", t);
UpdateLog.record(context, "Installer session failed: " + t);
try {
launchInstallerActivity(context, apk);
UpdateLog.record(context, "Opened the system installer instead");
return InstallResult.INSTALL_UI_STARTED;
} catch (Throwable fallback) {
Log.w(TAG, "OTA install UI failed", fallback);
UpdateLog.record(context, "System installer failed too: " + fallback);
return InstallResult.SESSION_FAILED;
}
}
@@ -490,6 +493,8 @@ final class OtaUpdater {
.getPackageArchiveInfo(apk.getAbsolutePath(), 0);
if (info == null || info.packageName == null) {
Log.w(TAG, "OTA archive cannot be parsed by the package manager");
UpdateLog.record(context, "Package manager cannot parse " + apk.getName()
+ " (" + apk.length() + " bytes)");
return false;
}
if (!context.getPackageName().equals(info.packageName)) {
@@ -533,6 +538,8 @@ final class OtaUpdater {
// confirm, EXTRA_INTENT. An immutable PendingIntent would arrive empty.
PendingIntent pending = PendingIntent.getBroadcast(context, sessionId, callback,
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE);
// Written before commit: a successful install replaces this process at once.
UpdateLog.record(context, "Handed " + apk.length() + " bytes to the installer");
session.commit(pending.getIntentSender());
committed = true;
Log.i(TAG, "OTA session " + sessionId + " committed (" + apk.length() + " bytes)");
@@ -83,10 +83,12 @@ final class UpdateHook {
message = runCheck(app, listener, main);
} catch (Throwable t) {
Log.w(TAG, "Update check threw", t);
message = "Update check failed";
// The class only: a network error's text can carry the server's address.
message = "Update check failed (" + t.getClass().getSimpleName() + ")";
} finally {
checking.set(false);
}
UpdateLog.record(app, "Check: " + message);
if (listener != null) {
final String result = message;
main.post(() -> listener.onResult(result));
@@ -112,10 +114,11 @@ final class UpdateHook {
message = runUsbInstall(app);
} catch (Throwable t) {
Log.w(TAG, "USB install threw", t);
message = "Installing from USB failed";
message = "Installing from USB failed: " + t;
} finally {
checking.set(false);
}
UpdateLog.record(app, "USB: " + message);
if (listener != null) {
final String result = message;
main.post(() -> listener.onResult(result));
@@ -141,6 +144,7 @@ final class UpdateHook {
if (best == null) {
return "No newer NilsMG4-unstable-<version>.apk on a USB stick (installed: " + current + ")";
}
UpdateLog.record(app, "USB: found " + best + " (" + best.length() + " bytes)");
File sidecar = new File(best.getPath() + ".sha256");
String expected = sidecar.isFile() && sidecar.length() < 16 * 1024
? OtaUpdater.parseExpectedSha256(new String(java.nio.file.Files.readAllBytes(sidecar.toPath()),
@@ -156,6 +160,7 @@ final class UpdateHook {
StringBuilder hex = new StringBuilder();
for (byte b : digest.digest()) hex.append(String.format(java.util.Locale.US, "%02x", b));
if (!hex.toString().equalsIgnoreCase(expected)) return "Not installed: " + best.getName() + " does not match its SHA-256";
UpdateLog.record(app, "USB: SHA-256 matches");
String version = OtaUpdater.versionFromAssetName(best.getName());
switch (OtaUpdater.install(app, best)) {
case SESSION_STARTED: