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
This commit is contained in:
Ido Ben-Hur 2023-06-19 20:01:30 +03:00
parent 9f6e0b7df1
commit a6b0305d09
No known key found for this signature in database
GPG Key ID: 0B827201D8C20BFE
2 changed files with 18 additions and 1 deletions

View File

@ -135,6 +135,7 @@
<string name="progress_status_9">Disabled.</string>
<string name="ab_perf_mode_title">AB performance mode</string>
<string name="ab_perf_mode_summary_new">Increase priority of the update process. Might influence normal usage when an update is in progress.</string>
<string name="ab_perf_mode_error">Error setting performance mode\nCheck the logs</string>
<string name="ab_wake_lock_title">AB wake lock</string>
<string name="ab_wake_lock_summary">Keep the CPU awake when installing an update. Makes updating fast even if the screen is off</string>
<string name="state_error_flash_file_title">Couldn\'t flash that file</string>

View File

@ -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);