diff options
author | Gabriele M <moto.falcon.git@gmail.com> | 2017-07-21 01:17:19 +0200 |
---|---|---|
committer | Gabriele M <moto.falcon.git@gmail.com> | 2017-07-21 16:52:24 +0200 |
commit | 28b8774db60cc0ec063e2f70f99bc320e770da21 (patch) | |
tree | b236f93b3297a12a10f84ecc6da8e6d581b6ddb8 | |
parent | 11f82cfb8780303c0da6b4a379637c0dd7654cea (diff) | |
download | android_packages_apps_Updater-28b8774db60cc0ec063e2f70f99bc320e770da21.tar.gz android_packages_apps_Updater-28b8774db60cc0ec063e2f70f99bc320e770da21.tar.bz2 android_packages_apps_Updater-28b8774db60cc0ec063e2f70f99bc320e770da21.zip |
Define interfaces with only getters for the updates
This also changes the code to use the new interfaces wherever the
update is not supposed to change.
-rw-r--r-- | src/org/lineageos/updater/UpdatesActivity.java | 17 | ||||
-rw-r--r-- | src/org/lineageos/updater/UpdatesListAdapter.java | 20 | ||||
-rw-r--r-- | src/org/lineageos/updater/controller/Controller.java | 8 | ||||
-rw-r--r-- | src/org/lineageos/updater/controller/UpdaterController.java | 29 | ||||
-rw-r--r-- | src/org/lineageos/updater/controller/UpdaterService.java | 18 | ||||
-rw-r--r-- | src/org/lineageos/updater/misc/LegacySupport.java | 7 | ||||
-rw-r--r-- | src/org/lineageos/updater/misc/Utils.java | 29 | ||||
-rw-r--r-- | src/org/lineageos/updater/model/Update.java | 10 | ||||
-rw-r--r-- | src/org/lineageos/updater/model/UpdateBaseInfo.java | 30 | ||||
-rw-r--r-- | src/org/lineageos/updater/model/UpdateDownload.java | 15 | ||||
-rw-r--r-- | src/org/lineageos/updater/model/UpdateInfo.java | 38 |
11 files changed, 153 insertions, 68 deletions
diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java index 3eb2459..6d6c1b4 100644 --- a/src/org/lineageos/updater/UpdatesActivity.java +++ b/src/org/lineageos/updater/UpdatesActivity.java @@ -52,8 +52,7 @@ import org.lineageos.updater.misc.Constants; import org.lineageos.updater.misc.LegacySupport; import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.Utils; -import org.lineageos.updater.model.Update; -import org.lineageos.updater.model.UpdateDownload; +import org.lineageos.updater.model.UpdateInfo; import java.io.File; import java.io.IOException; @@ -233,12 +232,12 @@ public class UpdatesActivity extends UpdatesListActivity { Controller controller = mUpdaterService.getUpdaterController(); boolean newUpdates = false; - List<UpdateDownload> updates = Utils.parseJson(jsonFile, true); + List<UpdateInfo> updates = Utils.parseJson(jsonFile, true); List<String> importedNotAvailableOnline = LegacySupport.importDownloads(this, updates); List<String> updatesOnline = new ArrayList<>(); - for (UpdateDownload update : updates) { + for (UpdateInfo update : updates) { newUpdates |= controller.addUpdate(update); updatesOnline.add(update.getDownloadId()); } @@ -257,14 +256,14 @@ public class UpdatesActivity extends UpdatesListActivity { } List<String> updateIds = new ArrayList<>(); - List<UpdateDownload> sortedUpdates = controller.getUpdates(); - Collections.sort(sortedUpdates, new Comparator<UpdateDownload>() { + List<UpdateInfo> sortedUpdates = controller.getUpdates(); + Collections.sort(sortedUpdates, new Comparator<UpdateInfo>() { @Override - public int compare(UpdateDownload u1, UpdateDownload u2) { + public int compare(UpdateInfo u1, UpdateInfo u2) { return Long.compare(u2.getTimestamp(), u1.getTimestamp()); } }); - for (Update update : sortedUpdates) { + for (UpdateInfo update : sortedUpdates) { updateIds.add(update.getDownloadId()); } mAdapter.setData(updateIds); @@ -371,7 +370,7 @@ public class UpdatesActivity extends UpdatesListActivity { } private void handleDownloadStatusChange(String downloadId) { - UpdateDownload update = mUpdaterService.getUpdaterController().getUpdate(downloadId); + UpdateInfo update = mUpdaterService.getUpdaterController().getUpdate(downloadId); switch (update.getStatus()) { case PAUSED_ERROR: showSnackbar(R.string.snack_download_failed, Snackbar.LENGTH_LONG); diff --git a/src/org/lineageos/updater/UpdatesListAdapter.java b/src/org/lineageos/updater/UpdatesListAdapter.java index daa0504..3721256 100644 --- a/src/org/lineageos/updater/UpdatesListAdapter.java +++ b/src/org/lineageos/updater/UpdatesListAdapter.java @@ -39,7 +39,7 @@ import org.lineageos.updater.misc.FileUtils; import org.lineageos.updater.misc.PermissionsUtils; import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.Utils; -import org.lineageos.updater.model.UpdateDownload; +import org.lineageos.updater.model.UpdateInfo; import org.lineageos.updater.model.UpdateStatus; import java.io.File; @@ -117,7 +117,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. notifyDataSetChanged(); } - private void handleActiveStatus(ViewHolder viewHolder, UpdateDownload update) { + private void handleActiveStatus(ViewHolder viewHolder, UpdateInfo update) { String buildDate = StringGenerator.getDateLocalizedUTC(mActivity, DateFormat.MEDIUM, update.getTimestamp()); String buildInfoText = mActivity.getString(R.string.list_build_version_date, @@ -170,7 +170,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. viewHolder.itemView.setOnLongClickListener(getLongClickListener(update, canDelete)); } - private void handleNotActiveStatus(ViewHolder viewHolder, UpdateDownload update) { + private void handleNotActiveStatus(ViewHolder viewHolder, UpdateInfo update) { String buildDate = StringGenerator.getDateLocalizedUTC(mActivity, DateFormat.LONG, update.getTimestamp()); String buildVersion = mActivity.getString(R.string.list_build_version, @@ -195,7 +195,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. } final String downloadId = mDownloadIds.get(i); - UpdateDownload update = mUpdaterController.getUpdate(downloadId); + UpdateInfo update = mUpdaterController.getUpdate(downloadId); if (update == null) { // The update was deleted viewHolder.mAction.setEnabled(false); @@ -284,7 +284,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. button.setContentDescription( mActivity.getString(R.string.action_description_resume)); button.setEnabled(enabled); - UpdateDownload update = mUpdaterController.getUpdate(downloadId); + UpdateInfo update = mUpdaterController.getUpdate(downloadId); final boolean canInstall = Utils.canInstall(update) || update.getFile().length() == update.getFileSize(); clickListener = !enabled ? null : new View.OnClickListener() { @@ -305,7 +305,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. button.setContentDescription( mActivity.getString(R.string.action_description_install)); button.setEnabled(enabled); - UpdateDownload update = mUpdaterController.getUpdate(downloadId); + UpdateInfo update = mUpdaterController.getUpdate(downloadId); final boolean canInstall = Utils.canInstall(update); clickListener = !enabled ? null : new View.OnClickListener() { @Override @@ -356,7 +356,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. .setNegativeButton(android.R.string.cancel, null); } - private View.OnLongClickListener getLongClickListener(final UpdateDownload update, + private View.OnLongClickListener getLongClickListener(final UpdateInfo update, final boolean canDelete) { return new View.OnLongClickListener() { @Override @@ -370,7 +370,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. } private AlertDialog.Builder getInstallDialog(final String downloadId) { - UpdateDownload update = mUpdaterController.getUpdate(downloadId); + UpdateInfo update = mUpdaterController.getUpdate(downloadId); int resId; try { if (Utils.isABUpdate(update.getFile())) { @@ -407,7 +407,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. } } - private void startActionMode(final UpdateDownload update, final boolean canDelete) { + private void startActionMode(final UpdateInfo update, final boolean canDelete) { if (mActionMode != null) { Log.d(TAG, "Action mode already enabled"); return; @@ -488,7 +488,7 @@ public class UpdatesListAdapter extends RecyclerView.Adapter<UpdatesListAdapter. }); } - private void exportUpdate(UpdateDownload update) { + private void exportUpdate(UpdateInfo update) { try { File dest = new File(Utils.getExportPath(mActivity), update.getName()); if (dest.exists()) { diff --git a/src/org/lineageos/updater/controller/Controller.java b/src/org/lineageos/updater/controller/Controller.java index 7005a70..4989d2a 100644 --- a/src/org/lineageos/updater/controller/Controller.java +++ b/src/org/lineageos/updater/controller/Controller.java @@ -15,20 +15,20 @@ */ package org.lineageos.updater.controller; -import org.lineageos.updater.model.UpdateDownload; +import org.lineageos.updater.model.UpdateInfo; import java.util.List; import java.util.Set; public interface Controller { - boolean addUpdate(UpdateDownload update); + boolean addUpdate(UpdateInfo update); - List<UpdateDownload> getUpdates(); + List<UpdateInfo> getUpdates(); Set<String> getIds(); - UpdateDownload getUpdate(String downloadId); + UpdateInfo getUpdate(String downloadId); void setUpdatesAvailableOnline(List<String> downloadIds, boolean purgeList); diff --git a/src/org/lineageos/updater/controller/UpdaterController.java b/src/org/lineageos/updater/controller/UpdaterController.java index 487cf51..a0992a4 100644 --- a/src/org/lineageos/updater/controller/UpdaterController.java +++ b/src/org/lineageos/updater/controller/UpdaterController.java @@ -27,6 +27,7 @@ import org.lineageos.updater.UpdatesDbHelper; import org.lineageos.updater.download.DownloadClient; import org.lineageos.updater.misc.Utils; import org.lineageos.updater.model.UpdateDownload; +import org.lineageos.updater.model.UpdateInfo; import org.lineageos.updater.model.UpdateStatus; import java.io.File; @@ -327,19 +328,20 @@ public class UpdaterController implements Controller { } @Override - public boolean addUpdate(UpdateDownload update) { + public boolean addUpdate(UpdateInfo update) { return addUpdate(update, true); } - private boolean addUpdate(final UpdateDownload update, boolean availableOnline) { - Log.d(TAG, "Adding download: " + update.getDownloadId()); - if (mDownloads.containsKey(update.getDownloadId())) { - Log.d(TAG, "Download (" + update.getDownloadId() + ") already added"); - UpdateDownload updateAdded = mDownloads.get(update.getDownloadId()).mUpdate; + private boolean addUpdate(final UpdateInfo updateInfo, boolean availableOnline) { + Log.d(TAG, "Adding download: " + updateInfo.getDownloadId()); + if (mDownloads.containsKey(updateInfo.getDownloadId())) { + Log.d(TAG, "Download (" + updateInfo.getDownloadId() + ") already added"); + UpdateDownload updateAdded = mDownloads.get(updateInfo.getDownloadId()).mUpdate; updateAdded.setAvailableOnline(availableOnline && updateAdded.getAvailableOnline()); - updateAdded.setDownloadUrl(update.getDownloadUrl()); + updateAdded.setDownloadUrl(updateInfo.getDownloadUrl()); return false; } + UpdateDownload update = new UpdateDownload(updateInfo); if (!fixUpdateStatus(update) && !availableOnline) { update.setPersistentStatus(UpdateStatus.Persistent.UNKNOWN); deleteUpdateAsync(update); @@ -347,8 +349,7 @@ public class UpdaterController implements Controller { return false; } update.setAvailableOnline(availableOnline); - UpdateDownload updateCopy = new UpdateDownload(update); - mDownloads.put(update.getDownloadId(), new DownloadEntry(updateCopy)); + mDownloads.put(update.getDownloadId(), new DownloadEntry(update)); return true; } @@ -473,18 +474,18 @@ public class UpdaterController implements Controller { } @Override - public List<UpdateDownload> getUpdates() { - List<UpdateDownload> updates = new ArrayList<>(); + public List<UpdateInfo> getUpdates() { + List<UpdateInfo> updates = new ArrayList<>(); for (DownloadEntry entry : mDownloads.values()) { - updates.add(new UpdateDownload(entry.mUpdate)); + updates.add(entry.mUpdate); } return updates; } @Override - public UpdateDownload getUpdate(String downloadId) { + public UpdateInfo getUpdate(String downloadId) { DownloadEntry entry = mDownloads.get(downloadId); - return entry != null ? new UpdateDownload(entry.mUpdate) : null; + return entry != null ? entry.mUpdate : null; } UpdateDownload getActualUpdate(String downloadId) { diff --git a/src/org/lineageos/updater/controller/UpdaterService.java b/src/org/lineageos/updater/controller/UpdaterService.java index 3164dd6..57e2371 100644 --- a/src/org/lineageos/updater/controller/UpdaterService.java +++ b/src/org/lineageos/updater/controller/UpdaterService.java @@ -36,7 +36,7 @@ import org.lineageos.updater.UpdatesActivity; import org.lineageos.updater.misc.BuildInfoUtils; import org.lineageos.updater.misc.StringGenerator; import org.lineageos.updater.misc.Utils; -import org.lineageos.updater.model.UpdateDownload; +import org.lineageos.updater.model.UpdateInfo; import org.lineageos.updater.model.UpdateStatus; import java.io.IOException; @@ -90,17 +90,17 @@ public class UpdaterService extends Service { public void onReceive(Context context, Intent intent) { String downloadId = intent.getStringExtra(UpdaterController.EXTRA_DOWNLOAD_ID); if (UpdaterController.ACTION_UPDATE_STATUS.equals(intent.getAction())) { - UpdateDownload update = mUpdaterController.getUpdate(downloadId); + UpdateInfo update = mUpdaterController.getUpdate(downloadId); setNotificationTitle(update); Bundle extras = new Bundle(); extras.putString(UpdaterController.EXTRA_DOWNLOAD_ID, downloadId); mNotificationBuilder.setExtras(extras); handleUpdateStatusChange(update); } else if (UpdaterController.ACTION_DOWNLOAD_PROGRESS.equals(intent.getAction())) { - UpdateDownload update = mUpdaterController.getUpdate(downloadId); + UpdateInfo update = mUpdaterController.getUpdate(downloadId); handleDownloadProgressChange(update); } else if (UpdaterController.ACTION_INSTALL_PROGRESS.equals(intent.getAction())) { - UpdateDownload update = mUpdaterController.getUpdate(downloadId); + UpdateInfo update = mUpdaterController.getUpdate(downloadId); setNotificationTitle(update); handleInstallProgress(update); } else if (UpdaterController.ACTION_UPDATE_REMOVED.equals(intent.getAction())) { @@ -161,7 +161,7 @@ public class UpdaterService extends Service { } } else if (ACTION_INSTALL_UPDATE.equals(intent.getAction())) { String downloadId = intent.getStringExtra(EXTRA_DOWNLOAD_ID); - UpdateDownload update = mUpdaterController.getUpdate(downloadId); + UpdateInfo update = mUpdaterController.getUpdate(downloadId); if (update.getPersistentStatus() != UpdateStatus.Persistent.VERIFIED) { throw new IllegalArgumentException(update.getDownloadId() + " is not verified"); } @@ -191,7 +191,7 @@ public class UpdaterService extends Service { } } - private void handleUpdateStatusChange(UpdateDownload update) { + private void handleUpdateStatusChange(UpdateInfo update) { switch (update.getStatus()) { case DELETED: { stopForeground(STOP_FOREGROUND_DETACH); @@ -326,7 +326,7 @@ public class UpdaterService extends Service { } } - private void handleDownloadProgressChange(UpdateDownload update) { + private void handleDownloadProgressChange(UpdateInfo update) { int progress = update.getProgress(); mNotificationBuilder.setProgress(100, progress, false); @@ -343,7 +343,7 @@ public class UpdaterService extends Service { mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); } - private void handleInstallProgress(UpdateDownload update) { + private void handleInstallProgress(UpdateInfo update) { int progress = update.getInstallProgress(); mNotificationBuilder.setProgress(100, progress, false); @@ -361,7 +361,7 @@ public class UpdaterService extends Service { mNotificationManager.notify(NOTIFICATION_ID, mNotificationBuilder.build()); } - private void setNotificationTitle(UpdateDownload update) { + private void setNotificationTitle(UpdateInfo update) { String buildDate = StringGenerator.getDateLocalizedUTC(this, DateFormat.MEDIUM, update.getTimestamp()); String buildInfo = getString(R.string.list_build_version_date, diff --git a/src/org/lineageos/updater/misc/LegacySupport.java b/src/org/lineageos/updater/misc/LegacySupport.java index 39f216b..586daa8 100644 --- a/src/org/lineageos/updater/misc/LegacySupport.java +++ b/src/org/lineageos/updater/misc/LegacySupport.java @@ -22,6 +22,7 @@ import android.util.Log; import org.lineageos.updater.UpdatesDbHelper; import org.lineageos.updater.model.UpdateDownload; +import org.lineageos.updater.model.UpdateInfo; import org.lineageos.updater.model.UpdateStatus; import java.io.File; @@ -57,7 +58,7 @@ public final class LegacySupport { * @return A list with the IDs of the imported updates with no matching updates */ public static List<String> importDownloads(Context context, - List<UpdateDownload> updatesJson) { + List<UpdateInfo> updatesJson) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (preferences.getBoolean(IMPORT_DONE, false)) { return null; @@ -73,7 +74,7 @@ public final class LegacySupport { if (files != null) { Map<String, Integer> updatesMap = new HashMap<>(); - for (UpdateDownload update : updatesJson) { + for (UpdateInfo update : updatesJson) { updatesMap.put(update.getName(), updatesJson.indexOf(update)); } @@ -86,7 +87,7 @@ public final class LegacySupport { Log.d(TAG, "Importing " + file.getAbsolutePath()); Integer index = updatesMap.get(file.getName()); if (index != null) { - UpdateDownload update = updatesJson.get(index); + UpdateDownload update = new UpdateDownload(updatesJson.get(index)); update.setFile(file); update.setFileSize(file.length()); update.setStatus(UpdateStatus.DOWNLOADED); diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 7c90e68..353e65e 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -35,8 +35,9 @@ import org.json.JSONObject; import org.lineageos.updater.R; import org.lineageos.updater.UpdatesDbHelper; import org.lineageos.updater.controller.UpdaterService; -import org.lineageos.updater.model.Update; +import org.lineageos.updater.model.UpdateBaseInfo; import org.lineageos.updater.model.UpdateDownload; +import org.lineageos.updater.model.UpdateInfo; import java.io.BufferedReader; import java.io.File; @@ -76,9 +77,9 @@ public class Utils { return new File(context.getCacheDir(), "updates.json"); } - // This should really return an Update object, but currently this only - // used to initialize UpdateDownload objects - private static UpdateDownload parseJsonUpdate(JSONObject object) throws JSONException { + // This should really return an UpdateBaseInfo object, but currently this only + // used to initialize UpdateInfo objects + private static UpdateInfo parseJsonUpdate(JSONObject object) throws JSONException { UpdateDownload update = new UpdateDownload(); update.setTimestamp(object.getLong("datetime")); update.setName(object.getString("filename")); @@ -89,7 +90,7 @@ public class Utils { return update; } - public static boolean isCompatible(Update update) { + public static boolean isCompatible(UpdateBaseInfo update) { if (update.getTimestamp() < SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { Log.d(TAG, update.getName() + " is older than current build"); return false; @@ -101,15 +102,15 @@ public class Utils { return true; } - public static boolean canInstall(Update update) { + public static boolean canInstall(UpdateBaseInfo update) { 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<UpdateInfo> parseJson(File file, boolean compatibleOnly) throws IOException, JSONException { - List<UpdateDownload> updates = new ArrayList<>(); + List<UpdateInfo> updates = new ArrayList<>(); String json = ""; try (BufferedReader br = new BufferedReader(new FileReader(file))) { @@ -125,7 +126,7 @@ public class Utils { continue; } try { - UpdateDownload update = parseJsonUpdate(updatesList.getJSONObject(i)); + UpdateInfo update = parseJsonUpdate(updatesList.getJSONObject(i)); if (compatibleOnly && isCompatible(update)) { updates.add(update); } else { @@ -175,15 +176,15 @@ public class Utils { */ public static boolean checkForNewUpdates(File oldJson, File newJson) throws IOException, JSONException { - List<UpdateDownload> oldList = parseJson(oldJson, true); - List<UpdateDownload> newList = parseJson(newJson, true); + List<UpdateInfo> oldList = parseJson(oldJson, true); + List<UpdateInfo> newList = parseJson(newJson, true); Set<String> oldIds = new HashSet<>(); - for (Update update : oldList) { + for (UpdateInfo update : oldList) { oldIds.add(update.getDownloadId()); } // In case of no new updates, the old list should // have all (if not more) the updates - for (Update update : newList) { + for (UpdateInfo update : newList) { if (!oldIds.contains(update.getDownloadId())) { return true; } @@ -249,7 +250,7 @@ public class Utils { // Ideally the database is empty when we get here UpdatesDbHelper dbHelper = new UpdatesDbHelper(context); List<String> knownPaths = new ArrayList<>(); - for (UpdateDownload update : dbHelper.getUpdates()) { + for (UpdateInfo update : dbHelper.getUpdates()) { knownPaths.add(update.getFile().getAbsolutePath()); } for (File file : files) { diff --git a/src/org/lineageos/updater/model/Update.java b/src/org/lineageos/updater/model/Update.java index c225feb..da894c2 100644 --- a/src/org/lineageos/updater/model/Update.java +++ b/src/org/lineageos/updater/model/Update.java @@ -15,7 +15,7 @@ */ package org.lineageos.updater.model; -public class Update { +public class Update implements UpdateBaseInfo { private String mName; private String mDownloadUrl; @@ -27,7 +27,7 @@ public class Update { public Update() { } - public Update(Update update) { + public Update(UpdateBaseInfo update) { mName = update.getName(); mDownloadUrl = update.getDownloadUrl(); mDownloadId = update.getDownloadId(); @@ -36,6 +36,7 @@ public class Update { mVersion = update.getVersion(); } + @Override public String getName() { return mName; } @@ -44,6 +45,7 @@ public class Update { mName = name; } + @Override public String getDownloadId() { return mDownloadId; } @@ -52,6 +54,7 @@ public class Update { mDownloadId = downloadId; } + @Override public long getTimestamp() { return mTimestamp; } @@ -60,6 +63,7 @@ public class Update { mTimestamp = timestamp; } + @Override public String getType() { return mType; } @@ -68,6 +72,7 @@ public class Update { mType = type; } + @Override public String getVersion() { return mVersion; } @@ -76,6 +81,7 @@ public class Update { mVersion = version; } + @Override public String getDownloadUrl() { return mDownloadUrl; } diff --git a/src/org/lineageos/updater/model/UpdateBaseInfo.java b/src/org/lineageos/updater/model/UpdateBaseInfo.java new file mode 100644 index 0000000..b5aad8b --- /dev/null +++ b/src/org/lineageos/updater/model/UpdateBaseInfo.java @@ -0,0 +1,30 @@ +/* + * 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 interface UpdateBaseInfo { + String getName(); + + String getDownloadId(); + + long getTimestamp(); + + String getType(); + + String getVersion(); + + String getDownloadUrl(); +} diff --git a/src/org/lineageos/updater/model/UpdateDownload.java b/src/org/lineageos/updater/model/UpdateDownload.java index c10c9cf..a42f231 100644 --- a/src/org/lineageos/updater/model/UpdateDownload.java +++ b/src/org/lineageos/updater/model/UpdateDownload.java @@ -17,7 +17,7 @@ package org.lineageos.updater.model; import java.io.File; -public class UpdateDownload extends Update { +public class UpdateDownload extends Update implements UpdateInfo { private UpdateStatus mStatus = UpdateStatus.UNKNOWN; private int mPersistentStatus = UpdateStatus.Persistent.UNKNOWN; @@ -32,11 +32,11 @@ public class UpdateDownload extends Update { public UpdateDownload() { } - public UpdateDownload(Update update) { + public UpdateDownload(UpdateBaseInfo update) { super(update); } - public UpdateDownload(UpdateDownload update) { + public UpdateDownload(UpdateInfo update) { super(update); mStatus = update.getStatus(); mPersistentStatus = update.getPersistentStatus(); @@ -49,6 +49,7 @@ public class UpdateDownload extends Update { mAvailableOnline = update.getAvailableOnline(); } + @Override public UpdateStatus getStatus() { return mStatus; } @@ -57,6 +58,7 @@ public class UpdateDownload extends Update { mStatus = status; } + @Override public int getPersistentStatus() { return mPersistentStatus; } @@ -65,6 +67,7 @@ public class UpdateDownload extends Update { mPersistentStatus = status; } + @Override public File getFile() { return mFile; } @@ -73,6 +76,7 @@ public class UpdateDownload extends Update { mFile = file; } + @Override public long getFileSize() { return mFileSize; } @@ -81,6 +85,7 @@ public class UpdateDownload extends Update { mFileSize = fileSize; } + @Override public int getProgress() { return mProgress; } @@ -89,6 +94,7 @@ public class UpdateDownload extends Update { mProgress = progress; } + @Override public long getEta() { return mEta; } @@ -97,6 +103,7 @@ public class UpdateDownload extends Update { mEta = eta; } + @Override public long getSpeed() { return mSpeed; } @@ -105,6 +112,7 @@ public class UpdateDownload extends Update { mSpeed = speed; } + @Override public int getInstallProgress() { return mInstallProgress; } @@ -113,6 +121,7 @@ public class UpdateDownload extends Update { mInstallProgress = progress; } + @Override public boolean getAvailableOnline() { return mAvailableOnline; } diff --git a/src/org/lineageos/updater/model/UpdateInfo.java b/src/org/lineageos/updater/model/UpdateInfo.java new file mode 100644 index 0000000..62cb310 --- /dev/null +++ b/src/org/lineageos/updater/model/UpdateInfo.java @@ -0,0 +1,38 @@ +/* + * 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 interface UpdateInfo extends UpdateBaseInfo { + UpdateStatus getStatus(); + + int getPersistentStatus(); + + File getFile(); + + long getFileSize(); + + int getProgress(); + + long getEta(); + + long getSpeed(); + + int getInstallProgress(); + + boolean getAvailableOnline(); +} |