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
This commit is contained in:
LuK1337
2024-05-14 19:40:37 +02:00
committed by althafvly
parent 2430816688
commit 91c94df741

View File

@@ -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 @@ package org.lineageos.updater.controller;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.ServiceSpecificException;
import android.os.UpdateEngine;
import android.os.UpdateEngineCallback;
import android.text.TextUtils;
@@ -208,7 +209,17 @@ class ABUpdateInstaller {
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);
@@ -242,7 +253,7 @@ class ABUpdateInstaller {
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)