From a6b0305d097f7c334098754ef2c656a17439b2a7 Mon Sep 17 00:00:00 2001 From: Ido Ben-Hur Date: Mon, 19 Jun 2023 20:01:30 +0300 Subject: [PATCH] OpenDelta: Never crash on a/b perf mode set failure This can fail for all kinds of reasons, especially for kernel / device side failures or lack of support Let's not crash for it and let the user know via a toast --- res/values/strings.xml | 1 + src/eu/chainfire/opendelta/ABUpdate.java | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index c0958b2..3221e08 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -135,6 +135,7 @@ Disabled. AB performance mode Increase priority of the update process. Might influence normal usage when an update is in progress. + Error setting performance mode\nCheck the logs AB wake lock Keep the CPU awake when installing an update. Makes updating fast even if the screen is off Couldn\'t flash that file diff --git a/src/eu/chainfire/opendelta/ABUpdate.java b/src/eu/chainfire/opendelta/ABUpdate.java index 7361669..98c2212 100644 --- a/src/eu/chainfire/opendelta/ABUpdate.java +++ b/src/eu/chainfire/opendelta/ABUpdate.java @@ -15,10 +15,13 @@ */ package eu.chainfire.opendelta; +import android.content.Context; import android.os.PowerManager.WakeLock; +import android.os.ServiceSpecificException; import android.os.UpdateEngine; import android.os.UpdateEngineCallback; import android.util.Log; +import android.widget.Toast; import java.util.Enumeration; import java.util.zip.ZipEntry; @@ -242,7 +245,20 @@ class ABUpdate { return ERROR_CORRUPTED; } - mUpdateEngine.setPerformanceMode(mEnableABPerfMode); + try { + mUpdateEngine.setPerformanceMode(mEnableABPerfMode); + } catch (ServiceSpecificException e) { + Log.e(TAG, "Could not set performance mode, Earlier logs should point the reason. Trace:"); + e.printStackTrace(); + final Context context = mUpdateService.getApplicationContext(); + if (context != null) { + Toast.makeText( + context, + context.getString(R.string.ab_perf_mode_error), + Toast.LENGTH_LONG + ).show(); + } + } if (!bindCallbacks()) return ERROR_NOT_READY; String zipFileUri = "file://" + file.getAbsolutePath(); mUpdateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs);