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 --> <!-- 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_60">Not enough free space</string>
<string name="error_ab_61">Device corruption\nA clean install through recovery is advised</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="long_press_info_toast">Long press to hide</string>
<string name="hide_info_toast">Info hidden. Undo in settings</string> <string name="hide_info_toast">Info hidden. Undo in settings</string>
</resources> </resources>

View File

@ -42,6 +42,12 @@ class ABUpdate {
private static final String PREFS_IS_INSTALLING_UPDATE = "prefs_is_installing_update"; private static final String PREFS_IS_INSTALLING_UPDATE = "prefs_is_installing_update";
private static final long WAKELOCK_TIMEOUT = 60 * 60 * 1000; /* 1 hour */ 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 static ABUpdate mInstance;
private final UpdateService mUpdateService; 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; mZipPath = zipPath;
mProgressListener = listener; mProgressListener = listener;
if (isInstallingUpdate(mUpdateService)) { if (isInstallingUpdate(mUpdateService)) {
return true; return -1;
} }
final boolean installing = startUpdate(); final int installing = startUpdate();
setInstallingUpdate(installing, mUpdateService); setInstallingUpdate(installing < 0, mUpdateService);
return installing; return installing;
} }
public boolean resume() { public int resume() {
final boolean installing = bindCallbacks(); final boolean installing = bindCallbacks();
setInstallingUpdate(installing, mUpdateService); setInstallingUpdate(installing, mUpdateService);
return installing; return installing ? -1 : ERROR_NOT_READY;
} }
public void pokeStatus() { public void pokeStatus() {
@ -165,17 +177,16 @@ class ABUpdate {
return true; return true;
} }
private boolean startUpdate() { private int startUpdate() {
File file = new File(mZipPath); File file = new File(mZipPath);
if (!file.exists()) { if (!file.exists()) {
Log.e(TAG, "The given update doesn't exist"); Log.e(TAG, "The given update doesn't exist");
return false; return ERROR_NOT_FOUND;
} }
long offset; long offset;
String[] headerKeyValuePairs; String[] headerKeyValuePairs;
try { try (ZipFile zipFile = new ZipFile(file)) {
ZipFile zipFile = new ZipFile(file);
offset = getZipEntryOffset(zipFile, PAYLOAD_BIN_PATH); offset = getZipEntryOffset(zipFile, PAYLOAD_BIN_PATH);
ZipEntry payloadPropEntry = zipFile.getEntry(PAYLOAD_PROPERTIES_PATH); ZipEntry payloadPropEntry = zipFile.getEntry(PAYLOAD_PROPERTIES_PATH);
try (InputStream is = zipFile.getInputStream(payloadPropEntry); try (InputStream is = zipFile.getInputStream(payloadPropEntry);
@ -188,21 +199,20 @@ class ABUpdate {
headerKeyValuePairs = new String[lines.size()]; headerKeyValuePairs = new String[lines.size()];
headerKeyValuePairs = lines.toArray(headerKeyValuePairs); headerKeyValuePairs = lines.toArray(headerKeyValuePairs);
} }
zipFile.close();
} catch (IOException | IllegalArgumentException e) { } catch (IOException | IllegalArgumentException e) {
Log.e(TAG, "Could not prepare " + file, e); Log.e(TAG, "Could not prepare " + file, e);
return false; return ERROR_CORRUPTED;
} }
mUpdateEngine.setPerformanceMode(mEnableABPerfMode); mUpdateEngine.setPerformanceMode(mEnableABPerfMode);
if (!bindCallbacks()) return false; if (!bindCallbacks()) return ERROR_NOT_READY;
String zipFileUri = "file://" + file.getAbsolutePath(); String zipFileUri = "file://" + file.getAbsolutePath();
mUpdateEngine.applyPayload(zipFileUri, offset, 0, headerKeyValuePairs); 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 && return zipFile.getEntry(PAYLOAD_BIN_PATH) != null &&
zipFile.getEntry(PAYLOAD_PROPERTIES_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() }; mLastProgressTime = new long[] { 0, SystemClock.elapsedRealtime() };
mProgressListener.setStatus(_filename); mProgressListener.setStatus(_filename);
mState.update(State.ACTION_AB_FLASH, 0f, 0L, 100L, _filename, null); 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) { if (!mIsUpdateRunning) {
mNotificationManager.cancel(NOTIFICATION_UPDATE); mNotificationManager.cancel(NOTIFICATION_UPDATE);
mState.update(State.ERROR_AB_FLASH); mState.update(State.ERROR_AB_FLASH, code);
} else { } else {
newFlashNotification(_filename); newFlashNotification(_filename);
} }
@ -1045,7 +1046,7 @@ public class UpdateService extends Service implements OnSharedPreferenceChangeLi
flashFilename = handleUpdateCleanup(); flashFilename = handleUpdateCleanup();
} catch (Exception ex) { } catch (Exception ex) {
mIsUpdateRunning = false; mIsUpdateRunning = false;
mState.update(State.ERROR_AB_FLASH); mState.update(State.ERROR_AB_FLASH, ABUpdate.ERROR_NOT_FOUND);
Logger.ex(ex); Logger.ex(ex);
return; return;
} }
@ -1061,29 +1062,16 @@ public class UpdateService extends Service implements OnSharedPreferenceChangeLi
newFlashNotification(_filename); newFlashNotification(_filename);
try { final int code = ABUpdate.getInstance(this).start(flashFilename, mProgressListener);
ZipFile zipFile = new ZipFile(flashFilename); if (code < 0) {
boolean isABUpdate = ABUpdate.isABUpdate(zipFile); mLastProgressTime = new long[] { 0, SystemClock.elapsedRealtime() };
zipFile.close(); mProgressListener.setStatus(_filename);
if (isABUpdate) { mIsUpdateRunning = true;
mLastProgressTime = new long[] { 0, SystemClock.elapsedRealtime() }; return;
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);
} }
mNotificationManager.cancel(NOTIFICATION_UPDATE);
mIsUpdateRunning = false;
mState.update(State.ERROR_AB_FLASH, code);
} }
@SuppressLint({"SdCardPath", "SetWorldReadable"}) @SuppressLint({"SdCardPath", "SetWorldReadable"})