Rename UpdateDownload and Update classes
This commit is contained in:
@@ -22,7 +22,7 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.database.sqlite.SQLiteOpenHelper;
|
import android.database.sqlite.SQLiteOpenHelper;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
|
||||||
import org.lineageos.updater.model.UpdateDownload;
|
import org.lineageos.updater.model.Update;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -75,7 +75,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
|
|||||||
onUpgrade(db, oldVersion, newVersion);
|
onUpgrade(db, oldVersion, newVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long addUpdate(UpdateDownload update) {
|
public long addUpdate(Update update) {
|
||||||
SQLiteDatabase db = getWritableDatabase();
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(UpdateEntry.COLUMN_NAME_STATUS, update.getPersistentStatus());
|
values.put(UpdateEntry.COLUMN_NAME_STATUS, update.getPersistentStatus());
|
||||||
@@ -88,7 +88,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
|
|||||||
return db.insert(UpdateEntry.TABLE_NAME, null, values);
|
return db.insert(UpdateEntry.TABLE_NAME, null, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long addUpdateWithOnConflict(UpdateDownload update, int conflictAlgorithm) {
|
public long addUpdateWithOnConflict(Update update, int conflictAlgorithm) {
|
||||||
SQLiteDatabase db = getWritableDatabase();
|
SQLiteDatabase db = getWritableDatabase();
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(UpdateEntry.COLUMN_NAME_STATUS, update.getPersistentStatus());
|
values.put(UpdateEntry.COLUMN_NAME_STATUS, update.getPersistentStatus());
|
||||||
@@ -114,7 +114,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
|
|||||||
return db.delete(UpdateEntry.TABLE_NAME, selection, null) != 0;
|
return db.delete(UpdateEntry.TABLE_NAME, selection, null) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean changeUpdateStatus(UpdateDownload update) {
|
public boolean changeUpdateStatus(Update update) {
|
||||||
String selection = UpdateEntry.COLUMN_NAME_DOWNLOAD_ID + " = ?";
|
String selection = UpdateEntry.COLUMN_NAME_DOWNLOAD_ID + " = ?";
|
||||||
String[] selectionArgs = {update.getDownloadId()};
|
String[] selectionArgs = {update.getDownloadId()};
|
||||||
return changeUpdateStatus(selection, selectionArgs, update.getPersistentStatus());
|
return changeUpdateStatus(selection, selectionArgs, update.getPersistentStatus());
|
||||||
@@ -133,27 +133,27 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
|
|||||||
return db.update(UpdateEntry.TABLE_NAME, values, selection, selectionArgs) != 0;
|
return db.update(UpdateEntry.TABLE_NAME, values, selection, selectionArgs) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateDownload getUpdate(long rowId) {
|
public Update getUpdate(long rowId) {
|
||||||
String selection = UpdateEntry._ID + " = " + rowId;
|
String selection = UpdateEntry._ID + " = " + rowId;
|
||||||
return getUpdate(selection, null);
|
return getUpdate(selection, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateDownload getUpdate(String downloadId) {
|
public Update getUpdate(String downloadId) {
|
||||||
String selection = UpdateEntry.COLUMN_NAME_DOWNLOAD_ID + " = ?";
|
String selection = UpdateEntry.COLUMN_NAME_DOWNLOAD_ID + " = ?";
|
||||||
String[] selectionArgs = {downloadId};
|
String[] selectionArgs = {downloadId};
|
||||||
return getUpdate(selection, selectionArgs);
|
return getUpdate(selection, selectionArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private UpdateDownload getUpdate(String selection, String[] selectionArgs) {
|
private Update getUpdate(String selection, String[] selectionArgs) {
|
||||||
List<UpdateDownload> updates = getUpdates(selection, selectionArgs);
|
List<Update> updates = getUpdates(selection, selectionArgs);
|
||||||
return updates != null ? updates.get(0) : null;
|
return updates != null ? updates.get(0) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UpdateDownload> getUpdates() {
|
public List<Update> getUpdates() {
|
||||||
return getUpdates(null, null);
|
return getUpdates(null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UpdateDownload> getUpdates(String selection, String[] selectionArgs) {
|
public List<Update> getUpdates(String selection, String[] selectionArgs) {
|
||||||
SQLiteDatabase db = getReadableDatabase();
|
SQLiteDatabase db = getReadableDatabase();
|
||||||
String[] projection = {
|
String[] projection = {
|
||||||
UpdateEntry.COLUMN_NAME_PATH,
|
UpdateEntry.COLUMN_NAME_PATH,
|
||||||
@@ -167,10 +167,10 @@ public class UpdatesDbHelper extends SQLiteOpenHelper {
|
|||||||
String sort = UpdateEntry.COLUMN_NAME_TIMESTAMP + " DESC";
|
String sort = UpdateEntry.COLUMN_NAME_TIMESTAMP + " DESC";
|
||||||
Cursor cursor = db.query(UpdateEntry.TABLE_NAME, projection, selection, selectionArgs,
|
Cursor cursor = db.query(UpdateEntry.TABLE_NAME, projection, selection, selectionArgs,
|
||||||
null, null, sort);
|
null, null, sort);
|
||||||
List<UpdateDownload> updates = new ArrayList<>();
|
List<Update> updates = new ArrayList<>();
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
UpdateDownload update = new UpdateDownload();
|
Update update = new Update();
|
||||||
int index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_PATH);
|
int index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_PATH);
|
||||||
update.setFile(new File(cursor.getString(index)));
|
update.setFile(new File(cursor.getString(index)));
|
||||||
update.setName(update.getFile().getName());
|
update.setName(update.getFile().getName());
|
||||||
|
@@ -21,7 +21,7 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.lineageos.updater.misc.Constants;
|
import org.lineageos.updater.misc.Constants;
|
||||||
import org.lineageos.updater.misc.Utils;
|
import org.lineageos.updater.misc.Utils;
|
||||||
import org.lineageos.updater.model.UpdateDownload;
|
import org.lineageos.updater.model.Update;
|
||||||
import org.lineageos.updater.model.UpdateStatus;
|
import org.lineageos.updater.model.UpdateStatus;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -57,7 +57,7 @@ class ABUpdateInstaller {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case UpdateEngine.UpdateStatusConstants.REPORTING_ERROR_EVENT: {
|
case UpdateEngine.UpdateStatusConstants.REPORTING_ERROR_EVENT: {
|
||||||
UpdateDownload update = mUpdaterController.getActualUpdate(mDownloadId);
|
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
||||||
update.setInstallProgress(0);
|
update.setInstallProgress(0);
|
||||||
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
||||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||||
@@ -71,7 +71,7 @@ class ABUpdateInstaller {
|
|||||||
sDownloadId = null;
|
sDownloadId = null;
|
||||||
switch (errorCode) {
|
switch (errorCode) {
|
||||||
case UpdateEngine.ErrorCodeConstants.SUCCESS: {
|
case UpdateEngine.ErrorCodeConstants.SUCCESS: {
|
||||||
UpdateDownload update = mUpdaterController.getActualUpdate(mDownloadId);
|
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
||||||
update.setInstallProgress(0);
|
update.setInstallProgress(0);
|
||||||
update.setStatus(UpdateStatus.INSTALLED);
|
update.setStatus(UpdateStatus.INSTALLED);
|
||||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||||
@@ -79,7 +79,7 @@ class ABUpdateInstaller {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
UpdateDownload update = mUpdaterController.getActualUpdate(mDownloadId);
|
Update update = mUpdaterController.getActualUpdate(mDownloadId);
|
||||||
update.setInstallProgress(0);
|
update.setInstallProgress(0);
|
||||||
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
update.setStatus(UpdateStatus.INSTALLATION_FAILED);
|
||||||
mUpdaterController.notifyUpdateChange(mDownloadId);
|
mUpdaterController.notifyUpdateChange(mDownloadId);
|
||||||
|
@@ -26,7 +26,7 @@ import android.util.Log;
|
|||||||
import org.lineageos.updater.UpdatesDbHelper;
|
import org.lineageos.updater.UpdatesDbHelper;
|
||||||
import org.lineageos.updater.download.DownloadClient;
|
import org.lineageos.updater.download.DownloadClient;
|
||||||
import org.lineageos.updater.misc.Utils;
|
import org.lineageos.updater.misc.Utils;
|
||||||
import org.lineageos.updater.model.UpdateDownload;
|
import org.lineageos.updater.model.Update;
|
||||||
import org.lineageos.updater.model.UpdateInfo;
|
import org.lineageos.updater.model.UpdateInfo;
|
||||||
import org.lineageos.updater.model.UpdateStatus;
|
import org.lineageos.updater.model.UpdateStatus;
|
||||||
|
|
||||||
@@ -83,15 +83,15 @@ public class UpdaterController implements Controller {
|
|||||||
|
|
||||||
Utils.cleanupDownloadsDir(context);
|
Utils.cleanupDownloadsDir(context);
|
||||||
|
|
||||||
for (UpdateDownload update : mUpdatesDbHelper.getUpdates()) {
|
for (Update update : mUpdatesDbHelper.getUpdates()) {
|
||||||
addUpdate(update, false);
|
addUpdate(update, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DownloadEntry {
|
private class DownloadEntry {
|
||||||
final UpdateDownload mUpdate;
|
final Update mUpdate;
|
||||||
DownloadClient mDownloadClient;
|
DownloadClient mDownloadClient;
|
||||||
private DownloadEntry(UpdateDownload update) {
|
private DownloadEntry(Update update) {
|
||||||
mUpdate = update;
|
mUpdate = update;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -153,7 +153,7 @@ public class UpdaterController implements Controller {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(int statusCode, String url, DownloadClient.Headers headers) {
|
public void onResponse(int statusCode, String url, DownloadClient.Headers headers) {
|
||||||
final UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
final Update update = mDownloads.get(downloadId).mUpdate;
|
||||||
if (update.getFileSize() <= 0) {
|
if (update.getFileSize() <= 0) {
|
||||||
String contentLength = headers.get("Content-Length");
|
String contentLength = headers.get("Content-Length");
|
||||||
if (contentLength != null) {
|
if (contentLength != null) {
|
||||||
@@ -182,7 +182,7 @@ public class UpdaterController implements Controller {
|
|||||||
@Override
|
@Override
|
||||||
public void onSuccess(File destination) {
|
public void onSuccess(File destination) {
|
||||||
Log.d(TAG, "Download complete");
|
Log.d(TAG, "Download complete");
|
||||||
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
Update update = mDownloads.get(downloadId).mUpdate;
|
||||||
update.setStatus(UpdateStatus.VERIFYING);
|
update.setStatus(UpdateStatus.VERIFYING);
|
||||||
removeDownloadClient(mDownloads.get(downloadId));
|
removeDownloadClient(mDownloads.get(downloadId));
|
||||||
verifyUpdateAsync(downloadId);
|
verifyUpdateAsync(downloadId);
|
||||||
@@ -192,7 +192,7 @@ public class UpdaterController implements Controller {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(boolean cancelled) {
|
public void onFailure(boolean cancelled) {
|
||||||
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
Update update = mDownloads.get(downloadId).mUpdate;
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
Log.d(TAG, "Download cancelled");
|
Log.d(TAG, "Download cancelled");
|
||||||
update.setStatus(UpdateStatus.PAUSED);
|
update.setStatus(UpdateStatus.PAUSED);
|
||||||
@@ -216,7 +216,7 @@ public class UpdaterController implements Controller {
|
|||||||
@Override
|
@Override
|
||||||
public void update(long bytesRead, long contentLength, long speed, long eta,
|
public void update(long bytesRead, long contentLength, long speed, long eta,
|
||||||
boolean done) {
|
boolean done) {
|
||||||
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
Update update = mDownloads.get(downloadId).mUpdate;
|
||||||
if (contentLength <= 0) {
|
if (contentLength <= 0) {
|
||||||
if (update.getFileSize() <= 0) {
|
if (update.getFileSize() <= 0) {
|
||||||
return;
|
return;
|
||||||
@@ -246,7 +246,7 @@ public class UpdaterController implements Controller {
|
|||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
Update update = mDownloads.get(downloadId).mUpdate;
|
||||||
File file = update.getFile();
|
File file = update.getFile();
|
||||||
if (file.exists() && verifyPackage(file)) {
|
if (file.exists() && verifyPackage(file)) {
|
||||||
update.setPersistentStatus(UpdateStatus.Persistent.VERIFIED);
|
update.setPersistentStatus(UpdateStatus.Persistent.VERIFIED);
|
||||||
@@ -281,7 +281,7 @@ public class UpdaterController implements Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean fixUpdateStatus(UpdateDownload update) {
|
private boolean fixUpdateStatus(Update update) {
|
||||||
switch (update.getPersistentStatus()) {
|
switch (update.getPersistentStatus()) {
|
||||||
case UpdateStatus.Persistent.VERIFIED:
|
case UpdateStatus.Persistent.VERIFIED:
|
||||||
case UpdateStatus.Persistent.INCOMPLETE:
|
case UpdateStatus.Persistent.INCOMPLETE:
|
||||||
@@ -336,12 +336,12 @@ public class UpdaterController implements Controller {
|
|||||||
Log.d(TAG, "Adding download: " + updateInfo.getDownloadId());
|
Log.d(TAG, "Adding download: " + updateInfo.getDownloadId());
|
||||||
if (mDownloads.containsKey(updateInfo.getDownloadId())) {
|
if (mDownloads.containsKey(updateInfo.getDownloadId())) {
|
||||||
Log.d(TAG, "Download (" + updateInfo.getDownloadId() + ") already added");
|
Log.d(TAG, "Download (" + updateInfo.getDownloadId() + ") already added");
|
||||||
UpdateDownload updateAdded = mDownloads.get(updateInfo.getDownloadId()).mUpdate;
|
Update updateAdded = mDownloads.get(updateInfo.getDownloadId()).mUpdate;
|
||||||
updateAdded.setAvailableOnline(availableOnline && updateAdded.getAvailableOnline());
|
updateAdded.setAvailableOnline(availableOnline && updateAdded.getAvailableOnline());
|
||||||
updateAdded.setDownloadUrl(updateInfo.getDownloadUrl());
|
updateAdded.setDownloadUrl(updateInfo.getDownloadUrl());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UpdateDownload update = new UpdateDownload(updateInfo);
|
Update update = new Update(updateInfo);
|
||||||
if (!fixUpdateStatus(update) && !availableOnline) {
|
if (!fixUpdateStatus(update) && !availableOnline) {
|
||||||
update.setPersistentStatus(UpdateStatus.Persistent.UNKNOWN);
|
update.setPersistentStatus(UpdateStatus.Persistent.UNKNOWN);
|
||||||
deleteUpdateAsync(update);
|
deleteUpdateAsync(update);
|
||||||
@@ -359,7 +359,7 @@ public class UpdaterController implements Controller {
|
|||||||
if (!mDownloads.containsKey(downloadId) || isDownloading(downloadId)) {
|
if (!mDownloads.containsKey(downloadId) || isDownloading(downloadId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
Update update = mDownloads.get(downloadId).mUpdate;
|
||||||
File destination = new File(mDownloadRoot, update.getName());
|
File destination = new File(mDownloadRoot, update.getName());
|
||||||
if (destination.exists()) {
|
if (destination.exists()) {
|
||||||
destination = Utils.appendSequentialNumber(destination);
|
destination = Utils.appendSequentialNumber(destination);
|
||||||
@@ -386,7 +386,7 @@ public class UpdaterController implements Controller {
|
|||||||
if (!mDownloads.containsKey(downloadId) || isDownloading(downloadId)) {
|
if (!mDownloads.containsKey(downloadId) || isDownloading(downloadId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
Update update = mDownloads.get(downloadId).mUpdate;
|
||||||
File file = update.getFile();
|
File file = update.getFile();
|
||||||
if (file == null || !file.exists()) {
|
if (file == null || !file.exists()) {
|
||||||
Log.e(TAG, "The destination file of " + downloadId + " doesn't exist, can't resume");
|
Log.e(TAG, "The destination file of " + downloadId + " doesn't exist, can't resume");
|
||||||
@@ -432,7 +432,7 @@ public class UpdaterController implements Controller {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteUpdateAsync(final UpdateDownload update) {
|
private void deleteUpdateAsync(final Update update) {
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -451,7 +451,7 @@ public class UpdaterController implements Controller {
|
|||||||
if (!mDownloads.containsKey(downloadId) || isDownloading(downloadId)) {
|
if (!mDownloads.containsKey(downloadId) || isDownloading(downloadId)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
UpdateDownload update = mDownloads.get(downloadId).mUpdate;
|
Update update = mDownloads.get(downloadId).mUpdate;
|
||||||
update.setStatus(UpdateStatus.DELETED);
|
update.setStatus(UpdateStatus.DELETED);
|
||||||
update.setProgress(0);
|
update.setProgress(0);
|
||||||
update.setPersistentStatus(UpdateStatus.Persistent.UNKNOWN);
|
update.setPersistentStatus(UpdateStatus.Persistent.UNKNOWN);
|
||||||
@@ -488,7 +488,7 @@ public class UpdaterController implements Controller {
|
|||||||
return entry != null ? entry.mUpdate : null;
|
return entry != null ? entry.mUpdate : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateDownload getActualUpdate(String downloadId) {
|
Update getActualUpdate(String downloadId) {
|
||||||
DownloadEntry entry = mDownloads.get(downloadId);
|
DownloadEntry entry = mDownloads.get(downloadId);
|
||||||
return entry != null ? entry.mUpdate : null;
|
return entry != null ? entry.mUpdate : null;
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ import android.preference.PreferenceManager;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.lineageos.updater.UpdatesDbHelper;
|
import org.lineageos.updater.UpdatesDbHelper;
|
||||||
import org.lineageos.updater.model.UpdateDownload;
|
import org.lineageos.updater.model.Update;
|
||||||
import org.lineageos.updater.model.UpdateInfo;
|
import org.lineageos.updater.model.UpdateInfo;
|
||||||
import org.lineageos.updater.model.UpdateStatus;
|
import org.lineageos.updater.model.UpdateStatus;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public final class LegacySupport {
|
|||||||
Log.d(TAG, "Importing " + file.getAbsolutePath());
|
Log.d(TAG, "Importing " + file.getAbsolutePath());
|
||||||
Integer index = updatesMap.get(file.getName());
|
Integer index = updatesMap.get(file.getName());
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
UpdateDownload update = new UpdateDownload(updatesJson.get(index));
|
Update update = new Update(updatesJson.get(index));
|
||||||
update.setFile(file);
|
update.setFile(file);
|
||||||
update.setFileSize(file.length());
|
update.setFileSize(file.length());
|
||||||
update.setStatus(UpdateStatus.DOWNLOADED);
|
update.setStatus(UpdateStatus.DOWNLOADED);
|
||||||
@@ -95,7 +95,7 @@ public final class LegacySupport {
|
|||||||
dbHelper.addUpdate(update);
|
dbHelper.addUpdate(update);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
UpdateDownload update = createUpdateFromFile(file);
|
Update update = createUpdateFromFile(file);
|
||||||
notReplacing.add(update.getDownloadId());
|
notReplacing.add(update.getDownloadId());
|
||||||
updatesJson.add(update);
|
updatesJson.add(update);
|
||||||
dbHelper.addUpdate(update);
|
dbHelper.addUpdate(update);
|
||||||
@@ -112,8 +112,8 @@ public final class LegacySupport {
|
|||||||
return notReplacing;
|
return notReplacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static UpdateDownload createUpdateFromFile(File file) throws IllegalFilenameException {
|
private static Update createUpdateFromFile(File file) throws IllegalFilenameException {
|
||||||
UpdateDownload update = new UpdateDownload();
|
Update update = new Update();
|
||||||
update.setDownloadId(UUID.randomUUID().toString());
|
update.setDownloadId(UUID.randomUUID().toString());
|
||||||
update.setFile(file);
|
update.setFile(file);
|
||||||
update.setFileSize(file.length());
|
update.setFileSize(file.length());
|
||||||
|
@@ -36,7 +36,7 @@ import org.lineageos.updater.R;
|
|||||||
import org.lineageos.updater.UpdatesDbHelper;
|
import org.lineageos.updater.UpdatesDbHelper;
|
||||||
import org.lineageos.updater.controller.UpdaterService;
|
import org.lineageos.updater.controller.UpdaterService;
|
||||||
import org.lineageos.updater.model.UpdateBaseInfo;
|
import org.lineageos.updater.model.UpdateBaseInfo;
|
||||||
import org.lineageos.updater.model.UpdateDownload;
|
import org.lineageos.updater.model.Update;
|
||||||
import org.lineageos.updater.model.UpdateInfo;
|
import org.lineageos.updater.model.UpdateInfo;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -80,7 +80,7 @@ public class Utils {
|
|||||||
// This should really return an UpdateBaseInfo object, but currently this only
|
// This should really return an UpdateBaseInfo object, but currently this only
|
||||||
// used to initialize UpdateInfo objects
|
// used to initialize UpdateInfo objects
|
||||||
private static UpdateInfo parseJsonUpdate(JSONObject object) throws JSONException {
|
private static UpdateInfo parseJsonUpdate(JSONObject object) throws JSONException {
|
||||||
UpdateDownload update = new UpdateDownload();
|
Update update = new Update();
|
||||||
update.setTimestamp(object.getLong("datetime"));
|
update.setTimestamp(object.getLong("datetime"));
|
||||||
update.setName(object.getString("filename"));
|
update.setName(object.getString("filename"));
|
||||||
update.setDownloadId(object.getString("id"));
|
update.setDownloadId(object.getString("id"));
|
||||||
|
@@ -15,78 +15,118 @@
|
|||||||
*/
|
*/
|
||||||
package org.lineageos.updater.model;
|
package org.lineageos.updater.model;
|
||||||
|
|
||||||
public class Update implements UpdateBaseInfo {
|
import java.io.File;
|
||||||
|
|
||||||
private String mName;
|
public class Update extends UpdateBase implements UpdateInfo {
|
||||||
private String mDownloadUrl;
|
|
||||||
private String mDownloadId;
|
private UpdateStatus mStatus = UpdateStatus.UNKNOWN;
|
||||||
private long mTimestamp;
|
private int mPersistentStatus = UpdateStatus.Persistent.UNKNOWN;
|
||||||
private String mType;
|
private File mFile;
|
||||||
private String mVersion;
|
private long mFileSize;
|
||||||
|
private int mProgress;
|
||||||
|
private long mEta;
|
||||||
|
private long mSpeed;
|
||||||
|
private int mInstallProgress;
|
||||||
|
private boolean mAvailableOnline;
|
||||||
|
|
||||||
public Update() {
|
public Update() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Update(UpdateBaseInfo update) {
|
public Update(UpdateBaseInfo update) {
|
||||||
mName = update.getName();
|
super(update);
|
||||||
mDownloadUrl = update.getDownloadUrl();
|
}
|
||||||
mDownloadId = update.getDownloadId();
|
|
||||||
mTimestamp = update.getTimestamp();
|
public Update(UpdateInfo update) {
|
||||||
mType = update.getType();
|
super(update);
|
||||||
mVersion = update.getVersion();
|
mStatus = update.getStatus();
|
||||||
|
mPersistentStatus = update.getPersistentStatus();
|
||||||
|
mFile = update.getFile();
|
||||||
|
mFileSize = update.getFileSize();
|
||||||
|
mProgress = update.getProgress();
|
||||||
|
mEta = update.getEta();
|
||||||
|
mSpeed = update.getSpeed();
|
||||||
|
mInstallProgress = update.getInstallProgress();
|
||||||
|
mAvailableOnline = update.getAvailableOnline();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public UpdateStatus getStatus() {
|
||||||
return mName;
|
return mStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setStatus(UpdateStatus status) {
|
||||||
mName = name;
|
mStatus = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDownloadId() {
|
public int getPersistentStatus() {
|
||||||
return mDownloadId;
|
return mPersistentStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDownloadId(String downloadId) {
|
public void setPersistentStatus(int status) {
|
||||||
mDownloadId = downloadId;
|
mPersistentStatus = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getTimestamp() {
|
public File getFile() {
|
||||||
return mTimestamp;
|
return mFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimestamp(long timestamp) {
|
public void setFile(File file) {
|
||||||
mTimestamp = timestamp;
|
mFile = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType() {
|
public long getFileSize() {
|
||||||
return mType;
|
return mFileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(String type) {
|
public void setFileSize(long fileSize) {
|
||||||
mType = type;
|
mFileSize = fileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getVersion() {
|
public int getProgress() {
|
||||||
return mVersion;
|
return mProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(String version) {
|
public void setProgress(int progress) {
|
||||||
mVersion = version;
|
mProgress = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDownloadUrl() {
|
public long getEta() {
|
||||||
return mDownloadUrl;
|
return mEta;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDownloadUrl(String downloadUrl) {
|
public void setEta(long eta) {
|
||||||
mDownloadUrl = downloadUrl;
|
mEta = eta;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSpeed() {
|
||||||
|
return mSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeed(long speed) {
|
||||||
|
mSpeed = speed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getInstallProgress() {
|
||||||
|
return mInstallProgress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInstallProgress(int progress) {
|
||||||
|
mInstallProgress = progress;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean getAvailableOnline() {
|
||||||
|
return mAvailableOnline;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvailableOnline(boolean availableOnline) {
|
||||||
|
mAvailableOnline = availableOnline;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
92
src/org/lineageos/updater/model/UpdateBase.java
Normal file
92
src/org/lineageos/updater/model/UpdateBase.java
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 The LineageOS Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.lineageos.updater.model;
|
||||||
|
|
||||||
|
public class UpdateBase implements UpdateBaseInfo {
|
||||||
|
|
||||||
|
private String mName;
|
||||||
|
private String mDownloadUrl;
|
||||||
|
private String mDownloadId;
|
||||||
|
private long mTimestamp;
|
||||||
|
private String mType;
|
||||||
|
private String mVersion;
|
||||||
|
|
||||||
|
public UpdateBase() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public UpdateBase(UpdateBaseInfo update) {
|
||||||
|
mName = update.getName();
|
||||||
|
mDownloadUrl = update.getDownloadUrl();
|
||||||
|
mDownloadId = update.getDownloadId();
|
||||||
|
mTimestamp = update.getTimestamp();
|
||||||
|
mType = update.getType();
|
||||||
|
mVersion = update.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return mName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
mName = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDownloadId() {
|
||||||
|
return mDownloadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadId(String downloadId) {
|
||||||
|
mDownloadId = downloadId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getTimestamp() {
|
||||||
|
return mTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimestamp(long timestamp) {
|
||||||
|
mTimestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return mType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
mType = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVersion() {
|
||||||
|
return mVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
mVersion = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDownloadUrl() {
|
||||||
|
return mDownloadUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDownloadUrl(String downloadUrl) {
|
||||||
|
mDownloadUrl = downloadUrl;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 The LineageOS Project
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.lineageos.updater.model;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class UpdateDownload extends Update 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;
|
|
||||||
private int mInstallProgress;
|
|
||||||
private boolean mAvailableOnline;
|
|
||||||
|
|
||||||
public UpdateDownload() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateDownload(UpdateBaseInfo update) {
|
|
||||||
super(update);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UpdateDownload(UpdateInfo update) {
|
|
||||||
super(update);
|
|
||||||
mStatus = update.getStatus();
|
|
||||||
mPersistentStatus = update.getPersistentStatus();
|
|
||||||
mFile = update.getFile();
|
|
||||||
mFileSize = update.getFileSize();
|
|
||||||
mProgress = update.getProgress();
|
|
||||||
mEta = update.getEta();
|
|
||||||
mSpeed = update.getSpeed();
|
|
||||||
mInstallProgress = update.getInstallProgress();
|
|
||||||
mAvailableOnline = update.getAvailableOnline();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public UpdateStatus getStatus() {
|
|
||||||
return mStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStatus(UpdateStatus status) {
|
|
||||||
mStatus = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getPersistentStatus() {
|
|
||||||
return mPersistentStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPersistentStatus(int status) {
|
|
||||||
mPersistentStatus = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public File getFile() {
|
|
||||||
return mFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFile(File file) {
|
|
||||||
mFile = file;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getFileSize() {
|
|
||||||
return mFileSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFileSize(long fileSize) {
|
|
||||||
mFileSize = fileSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getProgress() {
|
|
||||||
return mProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProgress(int progress) {
|
|
||||||
mProgress = progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getEta() {
|
|
||||||
return mEta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEta(long eta) {
|
|
||||||
mEta = eta;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getSpeed() {
|
|
||||||
return mSpeed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSpeed(long speed) {
|
|
||||||
mSpeed = speed;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getInstallProgress() {
|
|
||||||
return mInstallProgress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInstallProgress(int progress) {
|
|
||||||
mInstallProgress = progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean getAvailableOnline() {
|
|
||||||
return mAvailableOnline;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAvailableOnline(boolean availableOnline) {
|
|
||||||
mAvailableOnline = availableOnline;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user