From 91c94df741040e34d7877a426824a8b7f1b188e9 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Tue, 14 May 2024 19:40:37 +0200 Subject: [PATCH] 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 --- .../updater/controller/ABUpdateInstaller.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/org/lineageos/updater/controller/ABUpdateInstaller.java b/src/org/lineageos/updater/controller/ABUpdateInstaller.java index 9fdc75e0..465dcdf1 100644 --- a/src/org/lineageos/updater/controller/ABUpdateInstaller.java +++ b/src/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 @@ 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)