Extracted RepoProvider.DataColumns to Schema.RepoTable.Cols
This commit is contained in:
parent
0ea5325b81
commit
8a155aef89
@ -12,6 +12,7 @@ import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoPersister;
|
||||
import org.fdroid.fdroid.data.RepoProvider;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable;
|
||||
import org.fdroid.fdroid.net.Downloader;
|
||||
import org.fdroid.fdroid.net.DownloaderFactory;
|
||||
import org.xml.sax.InputSource;
|
||||
@ -253,32 +254,32 @@ public class RepoUpdater {
|
||||
private ContentValues prepareRepoDetailsForSaving(String name, String description, int maxAge, int version, long timestamp) {
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
values.put(RepoProvider.DataColumns.LAST_UPDATED, Utils.formatTime(new Date(), ""));
|
||||
values.put(RepoTable.Cols.LAST_UPDATED, Utils.formatTime(new Date(), ""));
|
||||
|
||||
if (repo.lastetag == null || !repo.lastetag.equals(cacheTag)) {
|
||||
values.put(RepoProvider.DataColumns.LAST_ETAG, cacheTag);
|
||||
values.put(RepoTable.Cols.LAST_ETAG, cacheTag);
|
||||
}
|
||||
|
||||
if (version != -1 && version != repo.version) {
|
||||
Utils.debugLog(TAG, "Repo specified a new version: from " + repo.version + " to " + version);
|
||||
values.put(RepoProvider.DataColumns.VERSION, version);
|
||||
values.put(RepoTable.Cols.VERSION, version);
|
||||
}
|
||||
|
||||
if (maxAge != -1 && maxAge != repo.maxage) {
|
||||
Utils.debugLog(TAG, "Repo specified a new maximum age - updated");
|
||||
values.put(RepoProvider.DataColumns.MAX_AGE, maxAge);
|
||||
values.put(RepoTable.Cols.MAX_AGE, maxAge);
|
||||
}
|
||||
|
||||
if (description != null && !description.equals(repo.description)) {
|
||||
values.put(RepoProvider.DataColumns.DESCRIPTION, description);
|
||||
values.put(RepoTable.Cols.DESCRIPTION, description);
|
||||
}
|
||||
|
||||
if (name != null && !name.equals(repo.name)) {
|
||||
values.put(RepoProvider.DataColumns.NAME, name);
|
||||
values.put(RepoTable.Cols.NAME, name);
|
||||
}
|
||||
|
||||
if (timestamp != repo.timestamp) {
|
||||
values.put(RepoProvider.DataColumns.TIMESTAMP, timestamp);
|
||||
values.put(RepoTable.Cols.TIMESTAMP, timestamp);
|
||||
}
|
||||
|
||||
return values;
|
||||
@ -354,8 +355,8 @@ public class RepoUpdater {
|
||||
|
||||
Utils.debugLog(TAG, "Saving new signing certificate in the database for " + repo.address);
|
||||
ContentValues values = new ContentValues(2);
|
||||
values.put(RepoProvider.DataColumns.LAST_UPDATED, Utils.formatDate(new Date(), ""));
|
||||
values.put(RepoProvider.DataColumns.SIGNING_CERT, Hasher.hex(rawCertFromJar));
|
||||
values.put(RepoTable.Cols.LAST_UPDATED, Utils.formatDate(new Date(), ""));
|
||||
values.put(RepoTable.Cols.SIGNING_CERT, Hasher.hex(rawCertFromJar));
|
||||
RepoProvider.Helper.update(context, repo, values);
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Schema.ApkTable.Cols;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -213,8 +214,8 @@ public class ApkProvider extends FDroidProvider {
|
||||
private static final Map<String, String> REPO_FIELDS = new HashMap<>();
|
||||
|
||||
static {
|
||||
REPO_FIELDS.put(Cols.REPO_VERSION, RepoProvider.DataColumns.VERSION);
|
||||
REPO_FIELDS.put(Cols.REPO_ADDRESS, RepoProvider.DataColumns.ADDRESS);
|
||||
REPO_FIELDS.put(Cols.REPO_VERSION, RepoTable.Cols.VERSION);
|
||||
REPO_FIELDS.put(Cols.REPO_ADDRESS, RepoTable.Cols.ADDRESS);
|
||||
|
||||
MATCHER.addURI(getAuthority(), PATH_REPO + "/#", CODE_REPO);
|
||||
MATCHER.addURI(getAuthority(), PATH_APK + "/#/*", CODE_SINGLE);
|
||||
|
@ -10,6 +10,7 @@ import android.util.Log;
|
||||
import org.fdroid.fdroid.R;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Schema.ApkTable;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -257,17 +258,17 @@ class DBHelper extends SQLiteOpenHelper {
|
||||
int priority) {
|
||||
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(RepoProvider.DataColumns.ADDRESS, address);
|
||||
values.put(RepoProvider.DataColumns.NAME, name);
|
||||
values.put(RepoProvider.DataColumns.DESCRIPTION, description);
|
||||
values.put(RepoProvider.DataColumns.SIGNING_CERT, pubKey);
|
||||
values.put(RepoProvider.DataColumns.FINGERPRINT, Utils.calcFingerprint(pubKey));
|
||||
values.put(RepoProvider.DataColumns.MAX_AGE, 0);
|
||||
values.put(RepoProvider.DataColumns.VERSION, version);
|
||||
values.put(RepoProvider.DataColumns.IN_USE, inUse);
|
||||
values.put(RepoProvider.DataColumns.PRIORITY, priority);
|
||||
values.put(RepoProvider.DataColumns.LAST_ETAG, (String) null);
|
||||
values.put(RepoProvider.DataColumns.TIMESTAMP, 0);
|
||||
values.put(RepoTable.Cols.ADDRESS, address);
|
||||
values.put(RepoTable.Cols.NAME, name);
|
||||
values.put(RepoTable.Cols.DESCRIPTION, description);
|
||||
values.put(RepoTable.Cols.SIGNING_CERT, pubKey);
|
||||
values.put(RepoTable.Cols.FINGERPRINT, Utils.calcFingerprint(pubKey));
|
||||
values.put(RepoTable.Cols.MAX_AGE, 0);
|
||||
values.put(RepoTable.Cols.VERSION, version);
|
||||
values.put(RepoTable.Cols.IN_USE, inUse);
|
||||
values.put(RepoTable.Cols.PRIORITY, priority);
|
||||
values.put(RepoTable.Cols.LAST_ETAG, (String) null);
|
||||
values.put(RepoTable.Cols.TIMESTAMP, 0);
|
||||
|
||||
Utils.debugLog(TAG, "Adding repository " + name);
|
||||
db.insert(TABLE_REPO, null, values);
|
||||
@ -518,10 +519,10 @@ class DBHelper extends SQLiteOpenHelper {
|
||||
if (oldVersion >= 55) {
|
||||
return;
|
||||
}
|
||||
if (!columnExists(db, TABLE_REPO, RepoProvider.DataColumns.TIMESTAMP)) {
|
||||
Utils.debugLog(TAG, "Adding " + RepoProvider.DataColumns.TIMESTAMP + " column to " + TABLE_REPO);
|
||||
if (!columnExists(db, TABLE_REPO, RepoTable.Cols.TIMESTAMP)) {
|
||||
Utils.debugLog(TAG, "Adding " + RepoTable.Cols.TIMESTAMP + " column to " + TABLE_REPO);
|
||||
db.execSQL("alter table " + TABLE_REPO + " add column "
|
||||
+ RepoProvider.DataColumns.TIMESTAMP + " integer not null default 0");
|
||||
+ RepoTable.Cols.TIMESTAMP + " integer not null default 0");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import android.database.Cursor;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable.Cols;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
@ -52,52 +53,52 @@ public class Repo extends ValueObject {
|
||||
|
||||
for (int i = 0; i < cursor.getColumnCount(); i++) {
|
||||
switch (cursor.getColumnName(i)) {
|
||||
case RepoProvider.DataColumns._ID:
|
||||
case Cols._ID:
|
||||
id = cursor.getInt(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.LAST_ETAG:
|
||||
case Cols.LAST_ETAG:
|
||||
lastetag = cursor.getString(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.ADDRESS:
|
||||
case Cols.ADDRESS:
|
||||
address = cursor.getString(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.DESCRIPTION:
|
||||
case Cols.DESCRIPTION:
|
||||
description = cursor.getString(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.FINGERPRINT:
|
||||
case Cols.FINGERPRINT:
|
||||
fingerprint = cursor.getString(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.IN_USE:
|
||||
case Cols.IN_USE:
|
||||
inuse = cursor.getInt(i) == 1;
|
||||
break;
|
||||
case RepoProvider.DataColumns.LAST_UPDATED:
|
||||
case Cols.LAST_UPDATED:
|
||||
lastUpdated = Utils.parseTime(cursor.getString(i), null);
|
||||
break;
|
||||
case RepoProvider.DataColumns.MAX_AGE:
|
||||
case Cols.MAX_AGE:
|
||||
maxage = cursor.getInt(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.VERSION:
|
||||
case Cols.VERSION:
|
||||
version = cursor.getInt(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.NAME:
|
||||
case Cols.NAME:
|
||||
name = cursor.getString(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.SIGNING_CERT:
|
||||
case Cols.SIGNING_CERT:
|
||||
signingCertificate = cursor.getString(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.PRIORITY:
|
||||
case Cols.PRIORITY:
|
||||
priority = cursor.getInt(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.IS_SWAP:
|
||||
case Cols.IS_SWAP:
|
||||
isSwap = cursor.getInt(i) == 1;
|
||||
break;
|
||||
case RepoProvider.DataColumns.USERNAME:
|
||||
case Cols.USERNAME:
|
||||
username = cursor.getString(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.PASSWORD:
|
||||
case Cols.PASSWORD:
|
||||
password = cursor.getString(i);
|
||||
break;
|
||||
case RepoProvider.DataColumns.TIMESTAMP:
|
||||
case Cols.TIMESTAMP:
|
||||
timestamp = cursor.getLong(i);
|
||||
break;
|
||||
}
|
||||
@ -158,69 +159,69 @@ public class Repo extends ValueObject {
|
||||
|
||||
public void setValues(ContentValues values) {
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns._ID)) {
|
||||
id = toInt(values.getAsInteger(RepoProvider.DataColumns._ID));
|
||||
if (values.containsKey(Cols._ID)) {
|
||||
id = toInt(values.getAsInteger(Cols._ID));
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.LAST_ETAG)) {
|
||||
lastetag = values.getAsString(RepoProvider.DataColumns.LAST_ETAG);
|
||||
if (values.containsKey(Cols.LAST_ETAG)) {
|
||||
lastetag = values.getAsString(Cols.LAST_ETAG);
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.ADDRESS)) {
|
||||
address = values.getAsString(RepoProvider.DataColumns.ADDRESS);
|
||||
if (values.containsKey(Cols.ADDRESS)) {
|
||||
address = values.getAsString(Cols.ADDRESS);
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.DESCRIPTION)) {
|
||||
description = values.getAsString(RepoProvider.DataColumns.DESCRIPTION);
|
||||
if (values.containsKey(Cols.DESCRIPTION)) {
|
||||
description = values.getAsString(Cols.DESCRIPTION);
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.FINGERPRINT)) {
|
||||
fingerprint = values.getAsString(RepoProvider.DataColumns.FINGERPRINT);
|
||||
if (values.containsKey(Cols.FINGERPRINT)) {
|
||||
fingerprint = values.getAsString(Cols.FINGERPRINT);
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.IN_USE)) {
|
||||
inuse = toInt(values.getAsInteger(RepoProvider.DataColumns.IN_USE)) == 1;
|
||||
if (values.containsKey(Cols.IN_USE)) {
|
||||
inuse = toInt(values.getAsInteger(Cols.IN_USE)) == 1;
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.LAST_UPDATED)) {
|
||||
final String dateString = values.getAsString(RepoProvider.DataColumns.LAST_UPDATED);
|
||||
if (values.containsKey(Cols.LAST_UPDATED)) {
|
||||
final String dateString = values.getAsString(Cols.LAST_UPDATED);
|
||||
lastUpdated = Utils.parseTime(dateString, null);
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.MAX_AGE)) {
|
||||
maxage = toInt(values.getAsInteger(RepoProvider.DataColumns.MAX_AGE));
|
||||
if (values.containsKey(Cols.MAX_AGE)) {
|
||||
maxage = toInt(values.getAsInteger(Cols.MAX_AGE));
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.VERSION)) {
|
||||
version = toInt(values.getAsInteger(RepoProvider.DataColumns.VERSION));
|
||||
if (values.containsKey(Cols.VERSION)) {
|
||||
version = toInt(values.getAsInteger(Cols.VERSION));
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.NAME)) {
|
||||
name = values.getAsString(RepoProvider.DataColumns.NAME);
|
||||
if (values.containsKey(Cols.NAME)) {
|
||||
name = values.getAsString(Cols.NAME);
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.SIGNING_CERT)) {
|
||||
signingCertificate = values.getAsString(RepoProvider.DataColumns.SIGNING_CERT);
|
||||
if (values.containsKey(Cols.SIGNING_CERT)) {
|
||||
signingCertificate = values.getAsString(Cols.SIGNING_CERT);
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.PRIORITY)) {
|
||||
priority = toInt(values.getAsInteger(RepoProvider.DataColumns.PRIORITY));
|
||||
if (values.containsKey(Cols.PRIORITY)) {
|
||||
priority = toInt(values.getAsInteger(Cols.PRIORITY));
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.IS_SWAP)) {
|
||||
isSwap = toInt(values.getAsInteger(RepoProvider.DataColumns.IS_SWAP)) == 1;
|
||||
if (values.containsKey(Cols.IS_SWAP)) {
|
||||
isSwap = toInt(values.getAsInteger(Cols.IS_SWAP)) == 1;
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.USERNAME)) {
|
||||
username = values.getAsString(RepoProvider.DataColumns.USERNAME);
|
||||
if (values.containsKey(Cols.USERNAME)) {
|
||||
username = values.getAsString(Cols.USERNAME);
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.PASSWORD)) {
|
||||
password = values.getAsString(RepoProvider.DataColumns.PASSWORD);
|
||||
if (values.containsKey(Cols.PASSWORD)) {
|
||||
password = values.getAsString(Cols.PASSWORD);
|
||||
}
|
||||
|
||||
if (values.containsKey(RepoProvider.DataColumns.TIMESTAMP)) {
|
||||
timestamp = toInt(values.getAsInteger(RepoProvider.DataColumns.TIMESTAMP));
|
||||
if (values.containsKey(Cols.TIMESTAMP)) {
|
||||
timestamp = toInt(values.getAsInteger(Cols.TIMESTAMP));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,11 +7,11 @@ import android.content.Context;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.provider.BaseColumns;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable.Cols;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -28,12 +28,12 @@ public class RepoProvider extends FDroidProvider {
|
||||
|
||||
public static Repo findByUri(Context context, Uri uri) {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
Cursor cursor = resolver.query(uri, DataColumns.ALL, null, null, null);
|
||||
Cursor cursor = resolver.query(uri, Cols.ALL, null, null, null);
|
||||
return cursorToRepo(cursor);
|
||||
}
|
||||
|
||||
public static Repo findById(Context context, long repoId) {
|
||||
return findById(context, repoId, DataColumns.ALL);
|
||||
return findById(context, repoId, Cols.ALL);
|
||||
}
|
||||
|
||||
public static Repo findById(Context context, long repoId,
|
||||
@ -45,18 +45,18 @@ public class RepoProvider extends FDroidProvider {
|
||||
}
|
||||
|
||||
public static Repo findByAddress(Context context, String address) {
|
||||
return findByAddress(context, address, DataColumns.ALL);
|
||||
return findByAddress(context, address, Cols.ALL);
|
||||
}
|
||||
|
||||
public static Repo findByAddress(Context context,
|
||||
String address, String[] projection) {
|
||||
List<Repo> repos = findBy(
|
||||
context, DataColumns.ADDRESS, address, projection);
|
||||
context, Cols.ADDRESS, address, projection);
|
||||
return repos.size() > 0 ? repos.get(0) : null;
|
||||
}
|
||||
|
||||
public static List<Repo> all(Context context) {
|
||||
return all(context, DataColumns.ALL);
|
||||
return all(context, Cols.ALL);
|
||||
}
|
||||
|
||||
public static List<Repo> all(Context context, String[] projection) {
|
||||
@ -113,10 +113,10 @@ public class RepoProvider extends FDroidProvider {
|
||||
// Change the name to the new address. Next time we update the repo
|
||||
// index file, it will populate the name field with the proper
|
||||
// name, but the best we can do is guess right now.
|
||||
if (values.containsKey(DataColumns.ADDRESS) &&
|
||||
!values.containsKey(DataColumns.NAME)) {
|
||||
String name = Repo.addressToName(values.getAsString(DataColumns.ADDRESS));
|
||||
values.put(DataColumns.NAME, name);
|
||||
if (values.containsKey(Cols.ADDRESS) &&
|
||||
!values.containsKey(Cols.NAME)) {
|
||||
String name = Repo.addressToName(values.getAsString(Cols.ADDRESS));
|
||||
values.put(Cols.NAME, name);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -129,14 +129,14 @@ public class RepoProvider extends FDroidProvider {
|
||||
* make sure it is correct. If the fingerprint is empty, then store
|
||||
* the calculated one.
|
||||
*/
|
||||
if (values.containsKey(DataColumns.SIGNING_CERT)) {
|
||||
String publicKey = values.getAsString(DataColumns.SIGNING_CERT);
|
||||
if (values.containsKey(Cols.SIGNING_CERT)) {
|
||||
String publicKey = values.getAsString(Cols.SIGNING_CERT);
|
||||
String calcedFingerprint = Utils.calcFingerprint(publicKey);
|
||||
if (values.containsKey(DataColumns.FINGERPRINT)) {
|
||||
String fingerprint = values.getAsString(DataColumns.FINGERPRINT);
|
||||
if (values.containsKey(Cols.FINGERPRINT)) {
|
||||
String fingerprint = values.getAsString(Cols.FINGERPRINT);
|
||||
if (!TextUtils.isEmpty(publicKey)) {
|
||||
if (TextUtils.isEmpty(fingerprint)) {
|
||||
values.put(DataColumns.FINGERPRINT, calcedFingerprint);
|
||||
values.put(Cols.FINGERPRINT, calcedFingerprint);
|
||||
} else if (!fingerprint.equals(calcedFingerprint)) {
|
||||
// TODO the UI should represent this error!
|
||||
Log.e(TAG, "The stored and calculated fingerprints do not match!");
|
||||
@ -146,20 +146,20 @@ public class RepoProvider extends FDroidProvider {
|
||||
}
|
||||
} else if (!TextUtils.isEmpty(publicKey)) {
|
||||
// no fingerprint in 'values', so put one there
|
||||
values.put(DataColumns.FINGERPRINT, calcedFingerprint);
|
||||
values.put(Cols.FINGERPRINT, calcedFingerprint);
|
||||
}
|
||||
}
|
||||
|
||||
if (values.containsKey(DataColumns.IN_USE)) {
|
||||
Integer inUse = values.getAsInteger(DataColumns.IN_USE);
|
||||
if (values.containsKey(Cols.IN_USE)) {
|
||||
Integer inUse = values.getAsInteger(Cols.IN_USE);
|
||||
if (inUse != null && inUse == 0) {
|
||||
values.put(DataColumns.LAST_ETAG, (String) null);
|
||||
values.put(Cols.LAST_ETAG, (String) null);
|
||||
}
|
||||
}
|
||||
|
||||
final Uri uri = getContentUri(repo.getId());
|
||||
final String[] args = {Long.toString(repo.getId())};
|
||||
resolver.update(uri, values, DataColumns._ID + " = ?", args);
|
||||
resolver.update(uri, values, Cols._ID + " = ?", args);
|
||||
repo.setValues(values);
|
||||
}
|
||||
|
||||
@ -209,31 +209,6 @@ public class RepoProvider extends FDroidProvider {
|
||||
}
|
||||
}
|
||||
|
||||
public interface DataColumns extends BaseColumns {
|
||||
|
||||
String ADDRESS = "address";
|
||||
String NAME = "name";
|
||||
String DESCRIPTION = "description";
|
||||
String IN_USE = "inuse";
|
||||
String PRIORITY = "priority";
|
||||
String SIGNING_CERT = "pubkey";
|
||||
String FINGERPRINT = "fingerprint";
|
||||
String MAX_AGE = "maxage";
|
||||
String LAST_ETAG = "lastetag";
|
||||
String LAST_UPDATED = "lastUpdated";
|
||||
String VERSION = "version";
|
||||
String IS_SWAP = "isSwap";
|
||||
String USERNAME = "username";
|
||||
String PASSWORD = "password";
|
||||
String TIMESTAMP = "timestamp";
|
||||
|
||||
String[] ALL = {
|
||||
_ID, ADDRESS, NAME, DESCRIPTION, IN_USE, PRIORITY, SIGNING_CERT,
|
||||
FINGERPRINT, MAX_AGE, LAST_UPDATED, LAST_ETAG, VERSION, IS_SWAP,
|
||||
USERNAME, PASSWORD, TIMESTAMP,
|
||||
};
|
||||
}
|
||||
|
||||
private static final String PROVIDER_NAME = "RepoProvider";
|
||||
private static final String PATH_ALL_EXCEPT_SWAP = "allExceptSwap";
|
||||
|
||||
@ -294,11 +269,11 @@ public class RepoProvider extends FDroidProvider {
|
||||
|
||||
case CODE_SINGLE:
|
||||
selection = (selection == null ? "" : selection + " AND ") +
|
||||
DataColumns._ID + " = " + uri.getLastPathSegment();
|
||||
Cols._ID + " = " + uri.getLastPathSegment();
|
||||
break;
|
||||
|
||||
case CODE_ALL_EXCEPT_SWAP:
|
||||
selection = DataColumns.IS_SWAP + " = 0 OR " + DataColumns.IS_SWAP + " IS NULL ";
|
||||
selection = Cols.IS_SWAP + " = 0 OR " + Cols.IS_SWAP + " IS NULL ";
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -314,32 +289,32 @@ public class RepoProvider extends FDroidProvider {
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
|
||||
if (!values.containsKey(DataColumns.ADDRESS)) {
|
||||
if (!values.containsKey(Cols.ADDRESS)) {
|
||||
throw new UnsupportedOperationException("Cannot add repo without an address.");
|
||||
}
|
||||
|
||||
// The following fields have NOT NULL constraints in the DB, so need
|
||||
// to be present.
|
||||
|
||||
if (!values.containsKey(DataColumns.IN_USE)) {
|
||||
values.put(DataColumns.IN_USE, 1);
|
||||
if (!values.containsKey(Cols.IN_USE)) {
|
||||
values.put(Cols.IN_USE, 1);
|
||||
}
|
||||
|
||||
if (!values.containsKey(DataColumns.PRIORITY)) {
|
||||
values.put(DataColumns.PRIORITY, 10);
|
||||
if (!values.containsKey(Cols.PRIORITY)) {
|
||||
values.put(Cols.PRIORITY, 10);
|
||||
}
|
||||
|
||||
if (!values.containsKey(DataColumns.MAX_AGE)) {
|
||||
values.put(DataColumns.MAX_AGE, 0);
|
||||
if (!values.containsKey(Cols.MAX_AGE)) {
|
||||
values.put(Cols.MAX_AGE, 0);
|
||||
}
|
||||
|
||||
if (!values.containsKey(DataColumns.VERSION)) {
|
||||
values.put(DataColumns.VERSION, 0);
|
||||
if (!values.containsKey(Cols.VERSION)) {
|
||||
values.put(Cols.VERSION, 0);
|
||||
}
|
||||
|
||||
if (!values.containsKey(DataColumns.NAME)) {
|
||||
final String address = values.getAsString(DataColumns.ADDRESS);
|
||||
values.put(DataColumns.NAME, Repo.addressToName(address));
|
||||
if (!values.containsKey(Cols.NAME)) {
|
||||
final String address = values.getAsString(Cols.ADDRESS);
|
||||
values.put(Cols.NAME, Repo.addressToName(address));
|
||||
}
|
||||
|
||||
long id = db().insertOrThrow(getTableName(), null, values);
|
||||
|
@ -34,6 +34,7 @@ import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.App;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoProvider;
|
||||
import org.fdroid.fdroid.data.Schema;
|
||||
import org.fdroid.fdroid.localrepo.peers.Peer;
|
||||
import org.fdroid.fdroid.localrepo.peers.PeerFinder;
|
||||
import org.fdroid.fdroid.localrepo.type.BluetoothSwap;
|
||||
@ -269,15 +270,15 @@ public class SwapService extends Service {
|
||||
// "Manage repos" UI on other device. Doesn't hurt to put something there though,
|
||||
// on the off chance that somebody is looking through the sqlite database which
|
||||
// contains the repos...
|
||||
values.put(RepoProvider.DataColumns.NAME, peer.getName());
|
||||
values.put(RepoProvider.DataColumns.ADDRESS, peer.getRepoAddress());
|
||||
values.put(RepoProvider.DataColumns.DESCRIPTION, "");
|
||||
values.put(Schema.RepoTable.Cols.NAME, peer.getName());
|
||||
values.put(Schema.RepoTable.Cols.ADDRESS, peer.getRepoAddress());
|
||||
values.put(Schema.RepoTable.Cols.DESCRIPTION, "");
|
||||
String fingerprint = peer.getFingerprint();
|
||||
if (!TextUtils.isEmpty(fingerprint)) {
|
||||
values.put(RepoProvider.DataColumns.FINGERPRINT, peer.getFingerprint());
|
||||
values.put(Schema.RepoTable.Cols.FINGERPRINT, peer.getFingerprint());
|
||||
}
|
||||
values.put(RepoProvider.DataColumns.IN_USE, true);
|
||||
values.put(RepoProvider.DataColumns.IS_SWAP, true);
|
||||
values.put(Schema.RepoTable.Cols.IN_USE, true);
|
||||
values.put(Schema.RepoTable.Cols.IS_SWAP, true);
|
||||
Uri uri = RepoProvider.Helper.insert(this, values);
|
||||
repo = RepoProvider.Helper.findByUri(this, uri);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import android.support.v4.content.LocalBroadcastManager;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoProvider;
|
||||
import org.fdroid.fdroid.data.Schema;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@ -47,7 +48,7 @@ public class DownloaderFactory {
|
||||
} else if (isLocalFile(url)) {
|
||||
downloader = new LocalFileDownloader(url, destFile);
|
||||
} else {
|
||||
final String[] projection = {RepoProvider.DataColumns.USERNAME, RepoProvider.DataColumns.PASSWORD};
|
||||
final String[] projection = {Schema.RepoTable.Cols.USERNAME, Schema.RepoTable.Cols.PASSWORD};
|
||||
String repoUrlString = FilenameUtils.getBaseName(url.toString());
|
||||
Repo repo = RepoProvider.Helper.findByAddress(context, repoUrlString, projection);
|
||||
if (repo == null) {
|
||||
|
@ -64,6 +64,7 @@ import org.fdroid.fdroid.compat.CursorAdapterCompat;
|
||||
import org.fdroid.fdroid.data.NewRepoConfig;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoProvider;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.HttpURLConnection;
|
||||
@ -612,14 +613,14 @@ public class ManageReposActivity extends ActionBarActivity {
|
||||
// Leave address as it was.
|
||||
}
|
||||
ContentValues values = new ContentValues(4);
|
||||
values.put(RepoProvider.DataColumns.ADDRESS, address);
|
||||
values.put(RepoTable.Cols.ADDRESS, address);
|
||||
if (!TextUtils.isEmpty(fingerprint)) {
|
||||
values.put(RepoProvider.DataColumns.FINGERPRINT, fingerprint.toUpperCase(Locale.ENGLISH));
|
||||
values.put(RepoTable.Cols.FINGERPRINT, fingerprint.toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)) {
|
||||
values.put(RepoProvider.DataColumns.USERNAME, username);
|
||||
values.put(RepoProvider.DataColumns.PASSWORD, password);
|
||||
values.put(RepoTable.Cols.USERNAME, username);
|
||||
values.put(RepoTable.Cols.PASSWORD, password);
|
||||
}
|
||||
|
||||
RepoProvider.Helper.insert(context, values);
|
||||
@ -643,8 +644,8 @@ public class ManageReposActivity extends ActionBarActivity {
|
||||
Utils.debugLog(TAG, "Enabling existing repo: " + url);
|
||||
Repo repo = RepoProvider.Helper.findByAddress(context, url);
|
||||
ContentValues values = new ContentValues(2);
|
||||
values.put(RepoProvider.DataColumns.IN_USE, 1);
|
||||
values.put(RepoProvider.DataColumns.FINGERPRINT, fingerprint);
|
||||
values.put(RepoTable.Cols.IN_USE, 1);
|
||||
values.put(RepoTable.Cols.FINGERPRINT, fingerprint);
|
||||
RepoProvider.Helper.update(context, repo, values);
|
||||
listFragment.notifyDataSetChanged();
|
||||
finishedAddingRepo();
|
||||
@ -710,11 +711,11 @@ public class ManageReposActivity extends ActionBarActivity {
|
||||
Uri uri = RepoProvider.allExceptSwapUri();
|
||||
Utils.debugLog(TAG, "Creating repo loader '" + uri + "'.");
|
||||
final String[] projection = {
|
||||
RepoProvider.DataColumns._ID,
|
||||
RepoProvider.DataColumns.NAME,
|
||||
RepoProvider.DataColumns.SIGNING_CERT,
|
||||
RepoProvider.DataColumns.FINGERPRINT,
|
||||
RepoProvider.DataColumns.IN_USE,
|
||||
RepoTable.Cols._ID,
|
||||
RepoTable.Cols.NAME,
|
||||
RepoTable.Cols.SIGNING_CERT,
|
||||
RepoTable.Cols.FINGERPRINT,
|
||||
RepoTable.Cols.IN_USE,
|
||||
};
|
||||
return new CursorLoader(getActivity(), uri, projection, null, null, null);
|
||||
}
|
||||
@ -748,7 +749,7 @@ public class ManageReposActivity extends ActionBarActivity {
|
||||
public void onSetEnabled(Repo repo, boolean isEnabled) {
|
||||
if (repo.inuse != isEnabled) {
|
||||
ContentValues values = new ContentValues(1);
|
||||
values.put(RepoProvider.DataColumns.IN_USE, isEnabled ? 1 : 0);
|
||||
values.put(RepoTable.Cols.IN_USE, isEnabled ? 1 : 0);
|
||||
RepoProvider.Helper.update(getActivity(), repo, values);
|
||||
|
||||
if (isEnabled) {
|
||||
|
@ -36,6 +36,7 @@ import org.fdroid.fdroid.UpdateService;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoProvider;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
@ -100,9 +101,9 @@ public class RepoDetailsActivity extends ActionBarActivity {
|
||||
|
||||
repoId = getIntent().getLongExtra(ARG_REPO_ID, 0);
|
||||
final String[] projection = {
|
||||
RepoProvider.DataColumns.NAME,
|
||||
RepoProvider.DataColumns.ADDRESS,
|
||||
RepoProvider.DataColumns.FINGERPRINT,
|
||||
RepoTable.Cols.NAME,
|
||||
RepoTable.Cols.ADDRESS,
|
||||
RepoTable.Cols.FINGERPRINT,
|
||||
};
|
||||
repo = RepoProvider.Helper.findById(this, repoId, projection);
|
||||
|
||||
@ -390,8 +391,8 @@ public class RepoDetailsActivity extends ActionBarActivity {
|
||||
if (!TextUtils.isEmpty(name)) {
|
||||
|
||||
final ContentValues values = new ContentValues(2);
|
||||
values.put(RepoProvider.DataColumns.USERNAME, name);
|
||||
values.put(RepoProvider.DataColumns.PASSWORD, password);
|
||||
values.put(RepoTable.Cols.USERNAME, name);
|
||||
values.put(RepoTable.Cols.PASSWORD, password);
|
||||
|
||||
RepoProvider.Helper.update(RepoDetailsActivity.this, repo, values);
|
||||
|
||||
|
@ -9,7 +9,6 @@ import junit.framework.AssertionFailedError;
|
||||
import org.fdroid.fdroid.data.ApkProvider;
|
||||
import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.InstalledAppProvider;
|
||||
import org.fdroid.fdroid.data.Schema;
|
||||
import org.fdroid.fdroid.data.Schema.ApkTable;
|
||||
import org.fdroid.fdroid.data.Schema.AppTable;
|
||||
import org.robolectric.shadows.ShadowContentResolver;
|
||||
|
@ -13,6 +13,7 @@ import org.fdroid.fdroid.data.AppProvider;
|
||||
import org.fdroid.fdroid.data.FDroidProviderTest;
|
||||
import org.fdroid.fdroid.data.Repo;
|
||||
import org.fdroid.fdroid.data.RepoProvider;
|
||||
import org.fdroid.fdroid.data.Schema;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
@ -163,9 +164,9 @@ public abstract class MultiRepoUpdaterTest extends FDroidProviderTest {
|
||||
repo.name = name;
|
||||
|
||||
ContentValues values = new ContentValues(2);
|
||||
values.put(RepoProvider.DataColumns.SIGNING_CERT, repo.signingCertificate);
|
||||
values.put(RepoProvider.DataColumns.ADDRESS, repo.address);
|
||||
values.put(RepoProvider.DataColumns.NAME, repo.name);
|
||||
values.put(Schema.RepoTable.Cols.SIGNING_CERT, repo.signingCertificate);
|
||||
values.put(Schema.RepoTable.Cols.ADDRESS, repo.address);
|
||||
values.put(Schema.RepoTable.Cols.NAME, repo.name);
|
||||
|
||||
RepoProvider.Helper.insert(context, values);
|
||||
|
||||
|
@ -8,6 +8,7 @@ import android.net.Uri;
|
||||
import org.fdroid.fdroid.Assert;
|
||||
import org.fdroid.fdroid.BuildConfig;
|
||||
import org.fdroid.fdroid.data.Schema.ApkTable.Cols;
|
||||
import org.fdroid.fdroid.data.Schema.RepoTable;
|
||||
import org.fdroid.fdroid.mock.MockApk;
|
||||
import org.fdroid.fdroid.mock.MockApp;
|
||||
import org.fdroid.fdroid.mock.MockRepo;
|
||||
@ -234,27 +235,27 @@ public class ApkProviderTest extends FDroidProviderTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInsertWithInvalidExtraFieldDescription() {
|
||||
assertInvalidExtraField(RepoProvider.DataColumns.DESCRIPTION);
|
||||
assertInvalidExtraField(RepoTable.Cols.DESCRIPTION);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInsertWithInvalidExtraFieldAddress() {
|
||||
assertInvalidExtraField(RepoProvider.DataColumns.ADDRESS);
|
||||
assertInvalidExtraField(RepoTable.Cols.ADDRESS);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInsertWithInvalidExtraFieldFingerprint() {
|
||||
assertInvalidExtraField(RepoProvider.DataColumns.FINGERPRINT);
|
||||
assertInvalidExtraField(RepoTable.Cols.FINGERPRINT);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInsertWithInvalidExtraFieldName() {
|
||||
assertInvalidExtraField(RepoProvider.DataColumns.NAME);
|
||||
assertInvalidExtraField(RepoTable.Cols.NAME);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInsertWithInvalidExtraFieldSigningCert() {
|
||||
assertInvalidExtraField(RepoProvider.DataColumns.SIGNING_CERT);
|
||||
assertInvalidExtraField(RepoTable.Cols.SIGNING_CERT);
|
||||
}
|
||||
|
||||
public void assertInvalidExtraField(String field) {
|
||||
|
@ -63,7 +63,7 @@ public class ProviderUriTests {
|
||||
@Test
|
||||
public void validRepoProviderUris() {
|
||||
ShadowContentResolver.registerProvider(RepoProvider.getAuthority(), new RepoProvider());
|
||||
String[] projection = new String[] {RepoProvider.DataColumns._ID};
|
||||
String[] projection = new String[] {Schema.RepoTable.Cols._ID};
|
||||
assertValidUri(resolver, RepoProvider.getContentUri(), projection);
|
||||
assertValidUri(resolver, RepoProvider.getContentUri(10000L), projection);
|
||||
assertValidUri(resolver, RepoProvider.allExceptSwapUri(), projection);
|
||||
|
Loading…
x
Reference in New Issue
Block a user