From a72b78c31e934bd87dcdcb24a7f40af345110d22 Mon Sep 17 00:00:00 2001 From: Gabriele M Date: Fri, 6 Apr 2018 21:39:53 +0200 Subject: [PATCH] Get file size from JSON The server now reports the size of the file, so use it and require it. Change-Id: I2248347431b65ae54dd7295872d70aba456ed8d8 --- README.md | 2 ++ src/org/lineageos/updater/misc/Utils.java | 1 + src/org/lineageos/updater/model/Update.java | 11 ----------- src/org/lineageos/updater/model/UpdateBase.java | 11 +++++++++++ src/org/lineageos/updater/model/UpdateBaseInfo.java | 2 ++ 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 1c60821..ecb06f4 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ a JSON with the following structure: "filename": "ota-package.zip", "id": "5eb63bbbe01eeed093cb22bb8f5acdc3", "romtype": "nightly", + "size": 314572800, "url": "https://example.com/ota-package.zip", "version": "15.1" } @@ -27,6 +28,7 @@ The `datetime` attribute is the build date expressed as UNIX timestamp. The `filename` attribute is the name of the file to be downloaded. The `id` attribute is a string that uniquely identifies the update. The `romtype` attribute is the string to be compared with the `ro.lineage.releasetype` property. +The `size` attribute is the size of the update expressed in bytes. The `url` attribute is the URL of the file to be downloaded. The `version` attribute is the string to be compared with the `ro.lineage.build.version` property. diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index c2c8df6..8ce368e 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -88,6 +88,7 @@ public class Utils { update.setName(object.getString("filename")); update.setDownloadId(object.getString("id")); update.setType(object.getString("romtype")); + update.setFileSize(object.getLong("size")); update.setDownloadUrl(object.getString("url")); update.setVersion(object.getString("version")); return update; diff --git a/src/org/lineageos/updater/model/Update.java b/src/org/lineageos/updater/model/Update.java index d9296c3..3ad17de 100644 --- a/src/org/lineageos/updater/model/Update.java +++ b/src/org/lineageos/updater/model/Update.java @@ -22,7 +22,6 @@ public class Update extends UpdateBase implements UpdateInfo { private UpdateStatus mStatus = UpdateStatus.UNKNOWN; private int mPersistentStatus = UpdateStatus.Persistent.UNKNOWN; private File mFile; - private long mFileSize; private int mProgress; private long mEta; private long mSpeed; @@ -42,7 +41,6 @@ public class Update extends UpdateBase implements UpdateInfo { mStatus = update.getStatus(); mPersistentStatus = update.getPersistentStatus(); mFile = update.getFile(); - mFileSize = update.getFileSize(); mProgress = update.getProgress(); mEta = update.getEta(); mSpeed = update.getSpeed(); @@ -78,15 +76,6 @@ public class Update extends UpdateBase implements UpdateInfo { mFile = file; } - @Override - public long getFileSize() { - return mFileSize; - } - - public void setFileSize(long fileSize) { - mFileSize = fileSize; - } - @Override public int getProgress() { return mProgress; diff --git a/src/org/lineageos/updater/model/UpdateBase.java b/src/org/lineageos/updater/model/UpdateBase.java index 12bc9fe..8fcf09c 100644 --- a/src/org/lineageos/updater/model/UpdateBase.java +++ b/src/org/lineageos/updater/model/UpdateBase.java @@ -23,6 +23,7 @@ public class UpdateBase implements UpdateBaseInfo { private long mTimestamp; private String mType; private String mVersion; + private long mFileSize; public UpdateBase() { } @@ -34,6 +35,7 @@ public class UpdateBase implements UpdateBaseInfo { mTimestamp = update.getTimestamp(); mType = update.getType(); mVersion = update.getVersion(); + mFileSize = update.getFileSize(); } @Override @@ -89,4 +91,13 @@ public class UpdateBase implements UpdateBaseInfo { public void setDownloadUrl(String downloadUrl) { mDownloadUrl = downloadUrl; } + + @Override + public long getFileSize() { + return mFileSize; + } + + public void setFileSize(long fileSize) { + mFileSize = fileSize; + } } diff --git a/src/org/lineageos/updater/model/UpdateBaseInfo.java b/src/org/lineageos/updater/model/UpdateBaseInfo.java index b5aad8b..2041582 100644 --- a/src/org/lineageos/updater/model/UpdateBaseInfo.java +++ b/src/org/lineageos/updater/model/UpdateBaseInfo.java @@ -27,4 +27,6 @@ public interface UpdateBaseInfo { String getVersion(); String getDownloadUrl(); + + long getFileSize(); }