OpenDelta: Describe non update engine errors as well

And improve some code / logic
This commit is contained in:
Ido Ben-Hur 2023-02-23 02:26:13 +02:00
parent 04ba2a76c8
commit 0daa4ad9ef
No known key found for this signature in database
GPG Key ID: 0B827201D8C20BFE
3 changed files with 43 additions and 40 deletions

View File

@ -162,6 +162,11 @@
<!-- Above string is WRONG. Keeping for historical reasons. This error cannot be reached unless we call applyPayload with SWITCH_SLOT_ON_REBOOT=0 -->
<string name="error_ab_60">Not enough free space</string>
<string name="error_ab_61">Device corruption\nA clean install through recovery is advised</string>
<!-- non UpdateEngine errors -->
<string name="error_ab_99">Update file not found\nPress check / select it again</string>
<string name="error_ab_98">Update engine isn\'t ready\nReboot and try again</string>
<string name="error_ab_97">Update file corrupted\nDownload the file again</string>
<string name="error_ab_96">Not an AB update file\nDownload the file again</string>
<string name="long_press_info_toast">Long press to hide</string>
<string name="hide_info_toast">Info hidden. Undo in settings</string>
</resources>

View File

@ -42,6 +42,12 @@ class ABUpdate {
private static final String PREFS_IS_INSTALLING_UPDATE = "prefs_is_installing_update";
private static final long WAKELOCK_TIMEOUT = 60 * 60 * 1000; /* 1 hour */
// non UpdateEngine errors
public static final int ERROR_NOT_FOUND = 99;
private static final int ERROR_NOT_READY = 98;
private static final int ERROR_CORRUPTED = 97;
private static final int ERROR_INVALID = 96;
private static ABUpdate mInstance;
private final UpdateService mUpdateService;
@ -103,21 +109,27 @@ class ABUpdate {
}
};
public boolean start(String zipPath, ProgressListener listener) {
public int start(String zipPath, ProgressListener listener) {
try (ZipFile zipFile = new ZipFile(zipPath)) {
if (!isABUpdate(zipFile)) return ERROR_INVALID;
} catch (Exception ex) {
Logger.ex(ex);
return ERROR_INVALID;
}
mZipPath = zipPath;
mProgressListener = listener;
if (isInstallingUpdate(mUpdateService)) {
return true;
return -1;
}
final boolean installing = startUpdate();
setInstallingUpdate(installing, mUpdateService);
final int installing = startUpdate();
setInstallingUpdate(installing < 0, mUpdateService);
return installing;
}
public boolean resume() {
public int resume() {
final boolean installing = bindCallbacks();
setInstallingUpdate(installing, mUpdateService);
return installing;
return installing ? -1 : ERROR_NOT_READY;
}
public void pokeStatus() {
@ -165,17 +177,16 @@ class ABUpdate {
return true;
}
private boolean startUpdate() {
private int startUpdate() {
File file = new File(mZipPath);
if (!file.exists()) {
Log.e(TAG, "The given update doesn't exist");
return false;
return ERROR_NOT_FOUND;
}
long offset;
String[] headerKeyValuePairs;
try {
ZipFile zipFile = new ZipFile(file);
try (ZipFile zipFile = new ZipFile(file)) {
offset = getZipEntryOffset(zipFile, PAYLOAD_BIN_PATH);
ZipEntry payloadPropEntry = zipFile.getEntry(PAYLOAD_PROPERTIES_PATH);
try (InputStream is = zipFile.getInputStream(payloadPropEntry);
@ -188,21 +199,20 @@ class ABUpdate {
headerKeyValuePairs = new String[lines.size()];
headerKeyValuePairs = lines.toArray(headerKeyValuePairs);
}
zipFile.close();
} catch (IOException | IllegalArgumentException e) {
Log.e(TAG, "Could not prepare " + file, e);
return false;
return ERROR_CORRUPTED;
}
mUpdateEngine.setPerformanceMode(mEnableABPerfMode);
if (!bindCallbacks()) return false;
if (!bindCallbacks()) return ERROR_NOT_READY;
String zipFileUri = "file://" + file.getAbsolutePath();
mUpdateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs);
return true;
return -1;
}
static boolean isABUpdate(ZipFile zipFile) {
private static boolean isABUpdate(ZipFile zipFile) {
return zipFile.getEntry(PAYLOAD_BIN_PATH) != null &&
zipFile.getEntry(PAYLOAD_PROPERTIES_PATH) != null;
}

View File

@ -449,10 +449,11 @@ public class UpdateService extends Service implements OnSharedPreferenceChangeLi
mLastProgressTime = new long[] { 0, SystemClock.elapsedRealtime() };
mProgressListener.setStatus(_filename);
mState.update(State.ACTION_AB_FLASH, 0f, 0L, 100L, _filename, null);
mIsUpdateRunning = ABUpdate.getInstance(this).resume();
final int code = ABUpdate.getInstance(this).resume();
mIsUpdateRunning = code < 0;
if (!mIsUpdateRunning) {
mNotificationManager.cancel(NOTIFICATION_UPDATE);
mState.update(State.ERROR_AB_FLASH);
mState.update(State.ERROR_AB_FLASH, code);
} else {
newFlashNotification(_filename);
}
@ -1045,7 +1046,7 @@ public class UpdateService extends Service implements OnSharedPreferenceChangeLi
flashFilename = handleUpdateCleanup();
} catch (Exception ex) {
mIsUpdateRunning = false;
mState.update(State.ERROR_AB_FLASH);
mState.update(State.ERROR_AB_FLASH, ABUpdate.ERROR_NOT_FOUND);
Logger.ex(ex);
return;
}
@ -1061,29 +1062,16 @@ public class UpdateService extends Service implements OnSharedPreferenceChangeLi
newFlashNotification(_filename);
try {
ZipFile zipFile = new ZipFile(flashFilename);
boolean isABUpdate = ABUpdate.isABUpdate(zipFile);
zipFile.close();
if (isABUpdate) {
mLastProgressTime = new long[] { 0, SystemClock.elapsedRealtime() };
mProgressListener.setStatus(_filename);
mIsUpdateRunning = true;
if (!ABUpdate.getInstance(this).start(flashFilename, mProgressListener)) {
mNotificationManager.cancel(NOTIFICATION_UPDATE);
mIsUpdateRunning = false;
mState.update(State.ERROR_AB_FLASH);
}
} else {
mNotificationManager.cancel(NOTIFICATION_UPDATE);
mIsUpdateRunning = false;
mState.update(State.ERROR_AB_FLASH);
}
} catch (Exception ex) {
Logger.ex(ex);
mIsUpdateRunning = false;
mState.update(State.ERROR_AB_FLASH);
final int code = ABUpdate.getInstance(this).start(flashFilename, mProgressListener);
if (code < 0) {
mLastProgressTime = new long[] { 0, SystemClock.elapsedRealtime() };
mProgressListener.setStatus(_filename);
mIsUpdateRunning = true;
return;
}
mNotificationManager.cancel(NOTIFICATION_UPDATE);
mIsUpdateRunning = false;
mState.update(State.ERROR_AB_FLASH, code);
}
@SuppressLint({"SdCardPath", "SetWorldReadable"})