Updater: Handle ErrorCode::kUpdateAlreadyInstalled more gracefully
If applyPayload() fails with kUpdateAlreadyInstalled, mark update as
already installed. While this is not ideal since this might not be the
update we actually installed, it's still better than outright dying.
Test: install update, unset needs_reboot_id, kill updater, install
update again.
Change-Id: Iac264896cffd1db522d81fc2050eb71d62ca91bf
diff --git a/app/src/main/java/org/lineageos/updater/controller/ABUpdateInstaller.java b/app/src/main/java/org/lineageos/updater/controller/ABUpdateInstaller.java
index a7ad9fa..535f984 100644
--- a/app/src/main/java/org/lineageos/updater/controller/ABUpdateInstaller.java
+++ b/app/src/main/java/org/lineageos/updater/controller/ABUpdateInstaller.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017-2022 The LineageOS Project
+ * Copyright (C) 2017-2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
import android.content.Context;
import android.content.SharedPreferences;
+import android.os.ServiceSpecificException;
import android.os.UpdateEngine;
import android.os.UpdateEngineCallback;
import android.text.TextUtils;
@@ -212,7 +213,17 @@
mUpdateEngine.setPerformanceMode(enableABPerfMode);
String zipFileUri = "file://" + file.getAbsolutePath();
- mUpdateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs);
+ try {
+ mUpdateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs);
+ } catch (ServiceSpecificException e) {
+ if (e.errorCode == 66 /* kUpdateAlreadyInstalled */) {
+ installationDone(true);
+ mUpdaterController.getActualUpdate(mDownloadId).setStatus(UpdateStatus.INSTALLED);
+ mUpdaterController.notifyUpdateChange(mDownloadId);
+ return;
+ }
+ throw e;
+ }
mUpdaterController.getActualUpdate(mDownloadId).setStatus(UpdateStatus.INSTALLING);
mUpdaterController.notifyUpdateChange(mDownloadId);
@@ -246,7 +257,7 @@
private void installationDone(boolean needsReboot) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
- String id = needsReboot ? prefs.getString(PREF_INSTALLING_AB_ID, null) : null;
+ String id = needsReboot ? mDownloadId : null;
PreferenceManager.getDefaultSharedPreferences(mContext).edit()
.putString(Constants.PREF_NEEDS_REBOOT_ID, id)
.remove(PREF_INSTALLING_AB_ID)