diff --git a/src/org/lineageos/updater/UpdatesActivity.java b/src/org/lineageos/updater/UpdatesActivity.java index 4bc9c319..1dea9f2a 100644 --- a/src/org/lineageos/updater/UpdatesActivity.java +++ b/src/org/lineageos/updater/UpdatesActivity.java @@ -166,7 +166,7 @@ public class UpdatesActivity extends AppCompatActivity { List updates = Utils.parseJson(jsonFile, true); - List updatesNotAvailable = LegacySupport.importDownloads(this, updates); + List importedNotAvailableOnline = LegacySupport.importDownloads(this, updates); List updatesOnline = new ArrayList<>(); for (UpdateDownload update : updates) { @@ -174,10 +174,9 @@ public class UpdatesActivity extends AppCompatActivity { updatesOnline.add(update.getDownloadId()); } - if (updatesNotAvailable != null) { - for (UpdateDownload update : updatesNotAvailable) { - update.setAvailableOnline(false); - } + if (importedNotAvailableOnline != null) { + updatesOnline.removeAll(importedNotAvailableOnline); + controller.setUpdatesNotAvailableOnline(importedNotAvailableOnline); } controller.setUpdatesAvailableOnline(updatesOnline, true); diff --git a/src/org/lineageos/updater/controller/UpdaterController.java b/src/org/lineageos/updater/controller/UpdaterController.java index c0c5d4b1..73f8c795 100644 --- a/src/org/lineageos/updater/controller/UpdaterController.java +++ b/src/org/lineageos/updater/controller/UpdaterController.java @@ -293,6 +293,16 @@ public class UpdaterController implements UpdaterControllerInt { return true; } + @Override + public void setUpdatesNotAvailableOnline(List downloadIds) { + for (String downloadId : downloadIds) { + DownloadEntry update = mDownloads.get(downloadId); + if (update != null) { + update.mUpdate.setAvailableOnline(false); + } + } + } + @Override public void setUpdatesAvailableOnline(List downloadIds, boolean purgeList) { List toRemove = new ArrayList<>(); diff --git a/src/org/lineageos/updater/controller/UpdaterControllerInt.java b/src/org/lineageos/updater/controller/UpdaterControllerInt.java index add5dd4d..e0dd8043 100644 --- a/src/org/lineageos/updater/controller/UpdaterControllerInt.java +++ b/src/org/lineageos/updater/controller/UpdaterControllerInt.java @@ -32,6 +32,8 @@ public interface UpdaterControllerInt { void setUpdatesAvailableOnline(List downloadIds, boolean purgeList); + void setUpdatesNotAvailableOnline(List downloadIds); + boolean startDownload(String downloadId); boolean pauseDownload(String downloadId); diff --git a/src/org/lineageos/updater/misc/LegacySupport.java b/src/org/lineageos/updater/misc/LegacySupport.java index 1e2a7163..3913da86 100644 --- a/src/org/lineageos/updater/misc/LegacySupport.java +++ b/src/org/lineageos/updater/misc/LegacySupport.java @@ -46,15 +46,17 @@ public final class LegacySupport { } /** - * This imports the updates downloaded with CMUpdater. It accepts in input a list of - * updates to be downloaded and updates its entries when it finds a matching imported - * update (i.e. same filename). + * This method imports the updates downloaded with CMUpdater and it adds them to the + * updates database. It accepts in input a list of updates which it updates with the + * data of matching imported updates (i.e. same filename). If for a given imported + * update this method can't find any matching update, it adds a new entry to the + * given list. * * @param context * @param updatesJson List of updates to be downloaded - * @return List of updates that weren't used to replace entries of updatesJson + * @return A list with the IDs of the imported updates with no matching updates */ - public static List importDownloads(Context context, + public static List importDownloads(Context context, List updatesJson) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); if (preferences.getBoolean(IMPORT_DONE, false)) { @@ -63,7 +65,7 @@ public final class LegacySupport { Log.d(TAG, "Importing downloads"); - List notReplacing = new ArrayList<>(); + List notReplacing = new ArrayList<>(); File updatesDir = new File(context.getDataDir(), "updates/"); if (updatesDir.isDirectory()) { UpdatesDbHelper dbHelper = new UpdatesDbHelper(context); @@ -93,7 +95,8 @@ public final class LegacySupport { } else { try { UpdateDownload update = createUpdateFromFile(file); - notReplacing.add(update); + notReplacing.add(update.getDownloadId()); + updatesJson.add(update); dbHelper.addUpdate(update); } catch (IllegalFilenameException e) { Log.e(TAG, "Deleting " + file.getAbsolutePath(), e);