Get file size from JSON

The server now reports the size of the file, so use it and
require it.

Change-Id: I2248347431b65ae54dd7295872d70aba456ed8d8
This commit is contained in:
Gabriele M
2018-04-06 21:39:53 +02:00
parent dbcccbbff0
commit e6e14dd7e2
5 changed files with 16 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ a JSON with the following structure:
"filename": "ota-package.zip", "filename": "ota-package.zip",
"id": "5eb63bbbe01eeed093cb22bb8f5acdc3", "id": "5eb63bbbe01eeed093cb22bb8f5acdc3",
"romtype": "nightly", "romtype": "nightly",
"size": 314572800,
"url": "https://example.com/ota-package.zip", "url": "https://example.com/ota-package.zip",
"version": "15.1" "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 `filename` attribute is the name of the file to be downloaded.
The `id` attribute is a string that uniquely identifies the update. The `id` attribute is a string that uniquely identifies the update.
The `romtype` attribute is the string to be compared with the `ro.cm.releasetype` property. The `romtype` attribute is the string to be compared with the `ro.cm.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 `url` attribute is the URL of the file to be downloaded.
The `version` attribute is the string to be compared with the `ro.cm.build.version` property. The `version` attribute is the string to be compared with the `ro.cm.build.version` property.

View File

@@ -88,6 +88,7 @@ public class Utils {
update.setName(object.getString("filename")); update.setName(object.getString("filename"));
update.setDownloadId(object.getString("id")); update.setDownloadId(object.getString("id"));
update.setType(object.getString("romtype")); update.setType(object.getString("romtype"));
update.setFileSize(object.getLong("size"));
update.setDownloadUrl(object.getString("url")); update.setDownloadUrl(object.getString("url"));
update.setVersion(object.getString("version")); update.setVersion(object.getString("version"));
return update; return update;

View File

@@ -22,7 +22,6 @@ public class Update extends UpdateBase implements UpdateInfo {
private UpdateStatus mStatus = UpdateStatus.UNKNOWN; private UpdateStatus mStatus = UpdateStatus.UNKNOWN;
private int mPersistentStatus = UpdateStatus.Persistent.UNKNOWN; private int mPersistentStatus = UpdateStatus.Persistent.UNKNOWN;
private File mFile; private File mFile;
private long mFileSize;
private int mProgress; private int mProgress;
private long mEta; private long mEta;
private long mSpeed; private long mSpeed;
@@ -42,7 +41,6 @@ public class Update extends UpdateBase implements UpdateInfo {
mStatus = update.getStatus(); mStatus = update.getStatus();
mPersistentStatus = update.getPersistentStatus(); mPersistentStatus = update.getPersistentStatus();
mFile = update.getFile(); mFile = update.getFile();
mFileSize = update.getFileSize();
mProgress = update.getProgress(); mProgress = update.getProgress();
mEta = update.getEta(); mEta = update.getEta();
mSpeed = update.getSpeed(); mSpeed = update.getSpeed();
@@ -78,15 +76,6 @@ public class Update extends UpdateBase implements UpdateInfo {
mFile = file; mFile = file;
} }
@Override
public long getFileSize() {
return mFileSize;
}
public void setFileSize(long fileSize) {
mFileSize = fileSize;
}
@Override @Override
public int getProgress() { public int getProgress() {
return mProgress; return mProgress;

View File

@@ -23,6 +23,7 @@ public class UpdateBase implements UpdateBaseInfo {
private long mTimestamp; private long mTimestamp;
private String mType; private String mType;
private String mVersion; private String mVersion;
private long mFileSize;
public UpdateBase() { public UpdateBase() {
} }
@@ -34,6 +35,7 @@ public class UpdateBase implements UpdateBaseInfo {
mTimestamp = update.getTimestamp(); mTimestamp = update.getTimestamp();
mType = update.getType(); mType = update.getType();
mVersion = update.getVersion(); mVersion = update.getVersion();
mFileSize = update.getFileSize();
} }
@Override @Override
@@ -89,4 +91,13 @@ public class UpdateBase implements UpdateBaseInfo {
public void setDownloadUrl(String downloadUrl) { public void setDownloadUrl(String downloadUrl) {
mDownloadUrl = downloadUrl; mDownloadUrl = downloadUrl;
} }
@Override
public long getFileSize() {
return mFileSize;
}
public void setFileSize(long fileSize) {
mFileSize = fileSize;
}
} }

View File

@@ -27,4 +27,6 @@ public interface UpdateBaseInfo {
String getVersion(); String getVersion();
String getDownloadUrl(); String getDownloadUrl();
long getFileSize();
} }