
Yay! As expected, a lot of the stuff in DB class is due to UpdateService requiring it to process the downloaded indexes and insert data into the database. Thus, this change is about removing that stuff from the DB class and migrating to ContentProviders. This required a bit of a change to the way that UpdateService decides what to do with the data from indexes, but I hope it will make understanding and changing UpdateService easier in the long term. For example, it used to read the app details from database, then if a repo wasn't updated (due to unchanged index) then it would take the app details for that repo from the list of apps, and re-update the database (or something like that). Now, it has been refactored into the following methods: * updateOrInsertApps(appsToUpdate); * updateOrInsertApks(apksToUpdate); * removeApksFromRepos(disabledRepos); * removeApksNoLongerInRepo(appsToUpdate, updatedRepos); * removeAppsWithoutApks(); * and probably some others... Which hopefully are self-explanitory. The recent change to implement single repo updates was re-implemented with in light of the methods above. The interface to UpdateService for scheduling a single repo update is the same as it was before, but the implementation is completely different. Still works though. Using batch content provider operations for repo updates, but they suffer from the problem of not all being under the same transaction, so if an insert/update stuffs up half way through, we are left with only half of the update being complete. In the future, if there is some way to implement notifications from the content provider's applyBatch method, then we can do it all in the one transaction, and still have notifications. Currently we break it into several calls to applyBatch (and hence several transactions) to inform the user of the progress. Also adding the beginnings of some tests for AppProvider. In the future, I'll work on adding better coverage, including instrumentation to test UI features. ========================== Below is a list of many of the minor changes that also happened along the way ========================== Make "Can update" tab stay up to date using content observer, rather than manually deciding when to refresh the tab label as before. The installed app list is now cached in Utils, because it is invoked quite a few times, especially when rendering the app lists. The cache is invalidated when PackageReceiver is notified of new apps. The content providers don't notify changes if we are in batch mode. I've left the notification at the end of the batch updates as the responsibility of the UpdateService. However, it would be nice if this was somehow handled by the content, as they are really the ones who should worry about it. Made curVersion, curVercode and curApk work with providers. This was done by removing curApk (otherwise we'd need to query the db each time we fetched one app to get a reference to that apk (resulting in hundreds of queries). Instead, UpdateService now calculates curVercode and curVersion and saves them to the database. We then use these where possible. If we really need curApk (because we want info other than its version and code) we still have the option of ApkProvider.Helper.find(app.id, app.curVercode). I considered putting this inside the app value object, e.g. in getCurApk() but thought better of it as it will likely result in people invoking it all the time, without realising it causes a DB query. incompatibleReasons required a minor UI tweak, removing the "min sdk" ui element from the Apk list. It is replaced by the "Requires: %s" view (which only appears when the app is incompatible). In the process, and in response to some feedback from mvdan, I left the min sdk in there, but only made it show when in "expert mode", just like the architecture. In order to make the "installed apps" query work under test conditions, needed to change the way the InstalledApkCache be replaceable with a mock object. Pause UIL loading on fast scroll of list, as the list was very choppy for some reason. Re-added "Last repo scan" info to the Manage Repo list view. Fixed up some misc TODO's, removed some unused/empty functions.
168 lines
5.8 KiB
Java
168 lines
5.8 KiB
Java
package org.fdroid.fdroid.data;
|
|
|
|
import android.content.ContentValues;
|
|
import android.database.Cursor;
|
|
import android.util.Log;
|
|
import org.fdroid.fdroid.Utils;
|
|
|
|
import java.net.MalformedURLException;
|
|
import java.net.URL;
|
|
import java.text.ParseException;
|
|
import java.util.Date;
|
|
|
|
public class Repo extends ValueObject {
|
|
|
|
public static final int VERSION_DENSITY_SPECIFIC_ICONS = 11;
|
|
|
|
private long id;
|
|
|
|
public String address;
|
|
public String name;
|
|
public String description;
|
|
public int version; // index version, i.e. what fdroidserver built it - 0 if not specified
|
|
public boolean inuse;
|
|
public int priority;
|
|
public String pubkey; // null for an unsigned repo
|
|
public String fingerprint; // always null for an unsigned repo
|
|
public int maxage; // maximum age of index that will be accepted - 0 for any
|
|
public String lastetag; // last etag we updated from, null forces update
|
|
public Date lastUpdated;
|
|
|
|
public Repo() {
|
|
|
|
}
|
|
|
|
public Repo(Cursor cursor) {
|
|
|
|
checkCursorPosition(cursor);
|
|
|
|
for(int i = 0; i < cursor.getColumnCount(); i ++ ) {
|
|
String column = cursor.getColumnName(i);
|
|
if (column.equals(RepoProvider.DataColumns._ID)) {
|
|
id = cursor.getInt(i);
|
|
} else if (column.equals(RepoProvider.DataColumns.LAST_ETAG)) {
|
|
lastetag = cursor.getString(i);
|
|
} else if (column.equals(RepoProvider.DataColumns.ADDRESS)) {
|
|
address = cursor.getString(i);
|
|
} else if (column.equals(RepoProvider.DataColumns.DESCRIPTION)) {
|
|
description = cursor.getString(i);
|
|
} else if (column.equals(RepoProvider.DataColumns.FINGERPRINT)) {
|
|
fingerprint = cursor.getString(i);
|
|
} else if (column.equals(RepoProvider.DataColumns.IN_USE)) {
|
|
inuse = cursor.getInt(i) == 1;
|
|
} else if (column.equals(RepoProvider.DataColumns.LAST_UPDATED)) {
|
|
lastUpdated = toDate(cursor.getString(i));
|
|
} else if (column.equals(RepoProvider.DataColumns.MAX_AGE)) {
|
|
maxage = cursor.getInt(i);
|
|
} else if (column.equals(RepoProvider.DataColumns.VERSION)) {
|
|
version = cursor.getInt(i);
|
|
} else if (column.equals(RepoProvider.DataColumns.NAME)) {
|
|
name = cursor.getString(i);
|
|
} else if (column.equals(RepoProvider.DataColumns.PUBLIC_KEY)) {
|
|
pubkey = cursor.getString(i);
|
|
} else if (column.equals(RepoProvider.DataColumns.PRIORITY)) {
|
|
priority = cursor.getInt(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
public long getId() { return id; }
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public String toString() {
|
|
return address;
|
|
}
|
|
|
|
public boolean isSigned() {
|
|
return this.pubkey != null && this.pubkey.length() > 0;
|
|
}
|
|
|
|
public boolean hasBeenUpdated() {
|
|
return this.lastetag != null;
|
|
}
|
|
/**
|
|
* If we haven't run an update for this repo yet, then the name
|
|
* will be unknown, in which case we will just take a guess at an
|
|
* appropriate name based on the url (e.g. "fdroid.org/archive")
|
|
*/
|
|
public static String addressToName(String address) {
|
|
String tempName;
|
|
try {
|
|
URL url = new URL(address);
|
|
tempName = url.getHost() + url.getPath();
|
|
} catch (MalformedURLException e) {
|
|
tempName = address;
|
|
}
|
|
return tempName;
|
|
}
|
|
|
|
private static int toInt(Integer value) {
|
|
if (value == null) {
|
|
return 0;
|
|
} else {
|
|
return value;
|
|
}
|
|
}
|
|
|
|
public void setValues(ContentValues values) {
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns._ID)) {
|
|
id = toInt(values.getAsInteger(RepoProvider.DataColumns._ID));
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.LAST_ETAG)) {
|
|
lastetag = values.getAsString(RepoProvider.DataColumns.LAST_ETAG);
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.ADDRESS)) {
|
|
address = values.getAsString(RepoProvider.DataColumns.ADDRESS);
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.DESCRIPTION)) {
|
|
description = values.getAsString(RepoProvider.DataColumns.DESCRIPTION);
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.FINGERPRINT)) {
|
|
fingerprint = values.getAsString(RepoProvider.DataColumns.FINGERPRINT);
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.IN_USE)) {
|
|
inuse = toInt(values.getAsInteger(RepoProvider.DataColumns.FINGERPRINT)) == 1;
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.LAST_UPDATED)) {
|
|
String dateString = values.getAsString(RepoProvider.DataColumns.LAST_UPDATED);
|
|
if (dateString != null) {
|
|
try {
|
|
lastUpdated = Utils.DATE_FORMAT.parse(dateString);
|
|
} catch (ParseException e) {
|
|
Log.e("FDroid", "Error parsing date " + dateString);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.MAX_AGE)) {
|
|
maxage = toInt(values.getAsInteger(RepoProvider.DataColumns.MAX_AGE));
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.VERSION)) {
|
|
version = toInt(values.getAsInteger(RepoProvider.DataColumns.VERSION));
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.NAME)) {
|
|
name = values.getAsString(RepoProvider.DataColumns.NAME);
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.PUBLIC_KEY)) {
|
|
pubkey = values.getAsString(RepoProvider.DataColumns.PUBLIC_KEY);
|
|
}
|
|
|
|
if (values.containsKey(RepoProvider.DataColumns.PRIORITY)) {
|
|
priority = toInt(values.getAsInteger(RepoProvider.DataColumns.PRIORITY));
|
|
}
|
|
}
|
|
}
|