Protect the data of UpdaterController
Create copies of the objects not to allow other classes change them, excluding those of controller package.
This commit is contained in:
@@ -53,13 +53,13 @@ class ABUpdateInstaller {
|
||||
case UpdateEngine.UpdateStatusConstants.DOWNLOADING:
|
||||
case UpdateEngine.UpdateStatusConstants.FINALIZING: {
|
||||
int progress = Math.round(percent * 100);
|
||||
mUpdaterController.getUpdate(mDownloadId).setInstallProgress(progress);
|
||||
mUpdaterController.getActualUpdate(mDownloadId).setInstallProgress(progress);
|
||||
mUpdaterController.notifyInstallProgress(mDownloadId);
|
||||
}
|
||||
break;
|
||||
|
||||
case UpdateEngine.UpdateStatusConstants.REPORTING_ERROR_EVENT: {
|
||||
UpdateDownload update = mUpdaterController.getUpdate(mDownloadId);
|
||||
UpdateDownload update = mUpdaterController.getActualUpdate(mDownloadId);
|
||||
update.setInstallProgress(0);
|
||||
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
||||
mUpdaterController.notifyUpdateChange(mDownloadId);;
|
||||
@@ -73,7 +73,7 @@ class ABUpdateInstaller {
|
||||
sIsInstallingUpdate = false;
|
||||
switch (errorCode) {
|
||||
case UpdateEngine.ErrorCodeConstants.SUCCESS: {
|
||||
UpdateDownload update = mUpdaterController.getUpdate(mDownloadId);
|
||||
UpdateDownload update = mUpdaterController.getActualUpdate(mDownloadId);
|
||||
update.setInstallProgress(0);
|
||||
update.setStatus(UpdateStatus.INSTALLED);
|
||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||
@@ -81,7 +81,7 @@ class ABUpdateInstaller {
|
||||
break;
|
||||
|
||||
default: {
|
||||
UpdateDownload update = mUpdaterController.getUpdate(mDownloadId);
|
||||
UpdateDownload update = mUpdaterController.getActualUpdate(mDownloadId);
|
||||
update.setInstallProgress(0);
|
||||
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||
@@ -111,13 +111,13 @@ class ABUpdateInstaller {
|
||||
}
|
||||
|
||||
private boolean startUpdate() {
|
||||
File file = mUpdaterController.getUpdate(mDownloadId).getFile();
|
||||
File file = mUpdaterController.getActualUpdate(mDownloadId).getFile();
|
||||
if (!file.exists()) {
|
||||
Log.e(TAG, "The given update doesn't exist");
|
||||
return false;
|
||||
}
|
||||
|
||||
mUpdaterController.getUpdate(mDownloadId).setStatus(UpdateStatus.INSTALLING);
|
||||
mUpdaterController.getActualUpdate(mDownloadId).setStatus(UpdateStatus.INSTALLING);
|
||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||
|
||||
long offset;
|
||||
@@ -139,7 +139,8 @@ class ABUpdateInstaller {
|
||||
zipFile.close();
|
||||
} catch (IOException | IllegalArgumentException e) {
|
||||
Log.e(TAG, "Could not prepare " + file, e);
|
||||
mUpdaterController.getUpdate(mDownloadId).setStatus(UpdateStatus.INSTALLATION_FAILED);
|
||||
mUpdaterController.getActualUpdate(mDownloadId)
|
||||
.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||
return false;
|
||||
}
|
||||
|
@@ -212,11 +212,12 @@ public class UpdaterController implements UpdaterControllerInt {
|
||||
@Override
|
||||
public void update(long bytesRead, long contentLength, long speed, long eta,
|
||||
boolean done) {
|
||||
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
||||
if (contentLength <= 0) {
|
||||
if (getUpdate(downloadId).getFileSize() <= 0) {
|
||||
if (update.getFileSize() <= 0) {
|
||||
return;
|
||||
} else {
|
||||
contentLength = getUpdate(downloadId).getFileSize();
|
||||
contentLength = update.getFileSize();
|
||||
}
|
||||
}
|
||||
if (contentLength <= 0) {
|
||||
@@ -227,9 +228,9 @@ public class UpdaterController implements UpdaterControllerInt {
|
||||
if (progress != mProgress || mLastUpdate - now > MAX_REPORT_INTERVAL_MS) {
|
||||
mProgress = progress;
|
||||
mLastUpdate = now;
|
||||
getUpdate(downloadId).setProgress(progress);
|
||||
getUpdate(downloadId).setEta(eta);
|
||||
getUpdate(downloadId).setSpeed(speed);
|
||||
update.setProgress(progress);
|
||||
update.setEta(eta);
|
||||
update.setSpeed(speed);
|
||||
notifyDownloadProgress(downloadId);
|
||||
}
|
||||
}
|
||||
@@ -341,8 +342,9 @@ public class UpdaterController implements UpdaterControllerInt {
|
||||
Log.d(TAG, update.getDownloadId() + " had an invalid status and is not online");
|
||||
return false;
|
||||
}
|
||||
mDownloads.put(update.getDownloadId(), new DownloadEntry(update));
|
||||
mDownloads.get(update.getDownloadId()).mUpdate.setAvailableOnline(availableOnline);
|
||||
update.setAvailableOnline(availableOnline);
|
||||
UpdateDownload updateCopy = new UpdateDownload(update);
|
||||
mDownloads.put(update.getDownloadId(), new DownloadEntry(updateCopy));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -458,13 +460,18 @@ public class UpdaterController implements UpdaterControllerInt {
|
||||
public List<UpdateDownload> getUpdates() {
|
||||
List<UpdateDownload> updates = new ArrayList<>();
|
||||
for (DownloadEntry entry : mDownloads.values()) {
|
||||
updates.add(entry.mUpdate);
|
||||
updates.add(new UpdateDownload(entry.mUpdate));
|
||||
}
|
||||
return updates;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateDownload getUpdate(String downloadId) {
|
||||
DownloadEntry entry = mDownloads.get(downloadId);
|
||||
return entry != null ? new UpdateDownload(entry.mUpdate) : null;
|
||||
}
|
||||
|
||||
UpdateDownload getActualUpdate(String downloadId) {
|
||||
DownloadEntry entry = mDownloads.get(downloadId);
|
||||
return entry != null ? entry.mUpdate : null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user