Don't allow to install older builds

In some cases, installing an update older than the one currently
installed requires a data wipe, so don't allow it. However, allow
to verify old updates if not verified yet (e.g. when imported).
This commit is contained in:
Gabriele M
2017-07-08 21:39:10 +02:00
parent 1c1bac67b4
commit c0bf32c097
2 changed files with 9 additions and 6 deletions

View File

@@ -116,20 +116,21 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter.
viewHolder.mButton2.setEnabled(false); viewHolder.mButton2.setEnabled(false);
} else { } else {
// Allow one active download // Allow one active download
boolean enabled = !mUpdaterController.hasActiveDownloads() && boolean busy = mUpdaterController.hasActiveDownloads() ||
Utils.canInstall(update) && !mUpdaterController.isVerifyingUpdate(); mUpdaterController.isVerifyingUpdate();
boolean enabled = !busy && Utils.canInstall(update);
int persistentStatus = update.getPersistentStatus(); int persistentStatus = update.getPersistentStatus();
if (persistentStatus == UpdateStatus.Persistent.INCOMPLETE) { if (persistentStatus == UpdateStatus.Persistent.INCOMPLETE) {
if (update.getFile().length() == update.getFileSize()) { if (update.getFile().length() == update.getFileSize()) {
setButtonAction(viewHolder.mButton1, Action.VERIFY, downloadId, enabled); setButtonAction(viewHolder.mButton1, Action.VERIFY, downloadId, !busy);
} else { } else {
setButtonAction(viewHolder.mButton1, Action.RESUME, downloadId, setButtonAction(viewHolder.mButton1, Action.RESUME, downloadId,
enabled && update.getAvailableOnline()); enabled && update.getAvailableOnline());
} }
setButtonAction(viewHolder.mButton2, Action.CANCEL, downloadId, enabled); setButtonAction(viewHolder.mButton2, Action.CANCEL, downloadId, !busy);
} else if (persistentStatus == UpdateStatus.Persistent.VERIFIED) { } else if (persistentStatus == UpdateStatus.Persistent.VERIFIED) {
setButtonAction(viewHolder.mButton1, Action.INSTALL, downloadId, enabled); setButtonAction(viewHolder.mButton1, Action.INSTALL, downloadId, enabled);
setButtonAction(viewHolder.mButton2, Action.CANCEL, downloadId, enabled); setButtonAction(viewHolder.mButton2, Action.CANCEL, downloadId, !busy);
} else { } else {
setButtonAction(viewHolder.mButton1, Action.DOWNLOAD, downloadId, enabled); setButtonAction(viewHolder.mButton1, Action.DOWNLOAD, downloadId, enabled);
setButtonAction(viewHolder.mButton2, Action.CANCEL, downloadId, false); setButtonAction(viewHolder.mButton2, Action.CANCEL, downloadId, false);

View File

@@ -85,7 +85,9 @@ public class Utils {
} }
public static boolean canInstall(Update update) { public static boolean canInstall(Update update) {
return update.getVersion().equalsIgnoreCase(SystemProperties.get(Constants.PROP_BUILD_VERSION)); return update.getTimestamp() > SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0) &&
update.getVersion().equalsIgnoreCase(
SystemProperties.get(Constants.PROP_BUILD_VERSION));
} }
public static List<UpdateDownload> parseJson(File file, boolean compatibleOnly) public static List<UpdateDownload> parseJson(File file, boolean compatibleOnly)