support new Liberapay: field, with migration support for LiberapayID:

Liberapay was originally included using a numeric ID, since they had not yet
finalized the public URLs.  Now it is a username.  So this logic prefers
the username in Liberapay: field, and uses the old LiberapayID: as a
fallback.  LiberapayID: will not override Liberapay: if it is already set.
This reuses the old database key since it is stored and processed as a
String anyway.
This commit is contained in:
Hans-Christoph Steiner 2020-06-16 10:12:24 +02:00
parent 1061929fb4
commit 23bd3b81dd
6 changed files with 52 additions and 19 deletions

View File

@ -163,7 +163,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
public String flattrID;
public String liberapayID;
public String liberapay;
public String openCollective;
@ -311,8 +311,8 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
case Cols.FLATTR_ID:
flattrID = cursor.getString(i);
break;
case Cols.LIBERAPAY_ID:
liberapayID = cursor.getString(i);
case Cols.LIBERAPAY:
liberapay = cursor.getString(i);
break;
case Cols.OPEN_COLLECTIVE:
openCollective = cursor.getString(i);
@ -450,6 +450,25 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
}
}
/**
* {@link #liberapay} was originally included using a numeric ID, now it is a
* username. This should not override {@link #liberapay} if that is already set.
*/
@JsonProperty("liberapayID")
void setLiberapayID(String liberapayId) { // NOPMD
if (TextUtils.isEmpty(liberapayId) || !TextUtils.isEmpty(liberapay)) {
return;
}
try {
int id = Integer.parseInt(liberapayId);
if (id > 0) {
liberapay = "~" + liberapayId;
}
} catch (NumberFormatException e) {
// ignored
}
}
/**
* Parses the {@code localized} block in the incoming index metadata,
* choosing the best match in terms of locale/language while filling as
@ -995,7 +1014,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
values.put(Cols.BITCOIN, bitcoin);
values.put(Cols.LITECOIN, litecoin);
values.put(Cols.FLATTR_ID, flattrID);
values.put(Cols.LIBERAPAY_ID, liberapayID);
values.put(Cols.LIBERAPAY, liberapay);
values.put(Cols.OPEN_COLLECTIVE, openCollective);
values.put(Cols.ADDED, Utils.formatDate(added, ""));
values.put(Cols.LAST_UPDATED, Utils.formatDate(lastUpdated, ""));
@ -1123,7 +1142,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
@Nullable
public String getLiberapayUri() {
return TextUtils.isEmpty(liberapayID) ? null : "https://liberapay.com/~" + liberapayID;
return TextUtils.isEmpty(liberapay) ? null : "https://liberapay.com/" + liberapay;
}
@ -1231,7 +1250,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
dest.writeString(this.bitcoin);
dest.writeString(this.litecoin);
dest.writeString(this.flattrID);
dest.writeString(this.liberapayID);
dest.writeString(this.liberapay);
dest.writeString(this.openCollective);
dest.writeString(this.preferredSigner);
dest.writeString(this.suggestedVersionName);
@ -1283,7 +1302,7 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
this.bitcoin = in.readString();
this.litecoin = in.readString();
this.flattrID = in.readString();
this.liberapayID = in.readString();
this.liberapay = in.readString();
this.openCollective = in.readString();
this.preferredSigner = in.readString();
this.suggestedVersionName = in.readString();

View File

@ -156,7 +156,7 @@ public class DBHelper extends SQLiteOpenHelper {
+ AppMetadataTable.Cols.BITCOIN + " string,"
+ AppMetadataTable.Cols.LITECOIN + " string,"
+ AppMetadataTable.Cols.FLATTR_ID + " string,"
+ AppMetadataTable.Cols.LIBERAPAY_ID + " string,"
+ AppMetadataTable.Cols.LIBERAPAY + " string,"
+ AppMetadataTable.Cols.OPEN_COLLECTIVE + " string,"
+ AppMetadataTable.Cols.REQUIREMENTS + " string,"
+ AppMetadataTable.Cols.ADDED + " string,"
@ -573,11 +573,11 @@ public class DBHelper extends SQLiteOpenHelper {
return;
}
if (!columnExists(db, AppMetadataTable.NAME, AppMetadataTable.Cols.LIBERAPAY_ID)) {
Utils.debugLog(TAG, "Adding " + AppMetadataTable.Cols.LIBERAPAY_ID + " field to "
if (!columnExists(db, AppMetadataTable.NAME, AppMetadataTable.Cols.LIBERAPAY)) {
Utils.debugLog(TAG, "Adding " + AppMetadataTable.Cols.LIBERAPAY + " field to "
+ AppMetadataTable.NAME + " table in db.");
db.execSQL("alter table " + AppMetadataTable.NAME + " add column "
+ AppMetadataTable.Cols.LIBERAPAY_ID + " string;");
+ AppMetadataTable.Cols.LIBERAPAY + " string;");
}
}

View File

@ -257,7 +257,7 @@ public class RepoXMLHandler extends DefaultHandler {
curapp.flattrID = str;
break;
case "liberapay":
curapp.liberapayID = str;
curapp.liberapay = str;
break;
case "web":
curapp.webSite = str;

View File

@ -189,7 +189,7 @@ public interface Schema {
String BITCOIN = "bitcoinAddr";
String LITECOIN = "litecoinAddr";
String FLATTR_ID = "flattrID";
String LIBERAPAY_ID = "liberapayID";
String LIBERAPAY = "liberapayID";
String OPEN_COLLECTIVE = "openCollective";
String PREFERRED_SIGNER = "preferredSigner";
String AUTO_INSTALL_VERSION_CODE = "suggestedVercode"; // name mismatch from issue #1063
@ -244,7 +244,7 @@ public interface Schema {
String[] ALL_COLS = {
ROW_ID, PACKAGE_ID, REPO_ID, IS_COMPATIBLE, NAME, SUMMARY, ICON, DESCRIPTION,
WHATSNEW, LICENSE, AUTHOR_NAME, AUTHOR_EMAIL, WEBSITE, ISSUE_TRACKER, SOURCE_CODE,
TRANSLATION, VIDEO, CHANGELOG, DONATE, BITCOIN, LITECOIN, FLATTR_ID, LIBERAPAY_ID,
TRANSLATION, VIDEO, CHANGELOG, DONATE, BITCOIN, LITECOIN, FLATTR_ID, LIBERAPAY,
OPEN_COLLECTIVE, SUGGESTED_VERSION_NAME, SUGGESTED_VERSION_CODE, ADDED, LAST_UPDATED,
ANTI_FEATURES, REQUIREMENTS, ICON_URL,
FEATURE_GRAPHIC, PROMO_GRAPHIC, TV_BANNER, PHONE_SCREENSHOTS,
@ -261,7 +261,7 @@ public interface Schema {
String[] ALL = {
_ID, ROW_ID, REPO_ID, IS_COMPATIBLE, NAME, SUMMARY, ICON, DESCRIPTION,
WHATSNEW, LICENSE, AUTHOR_NAME, AUTHOR_EMAIL, WEBSITE, ISSUE_TRACKER, SOURCE_CODE,
TRANSLATION, VIDEO, CHANGELOG, DONATE, BITCOIN, LITECOIN, FLATTR_ID, LIBERAPAY_ID,
TRANSLATION, VIDEO, CHANGELOG, DONATE, BITCOIN, LITECOIN, FLATTR_ID, LIBERAPAY,
OPEN_COLLECTIVE, SUGGESTED_VERSION_NAME, SUGGESTED_VERSION_CODE, ADDED, LAST_UPDATED,
ANTI_FEATURES, REQUIREMENTS, ICON_URL,
FEATURE_GRAPHIC, PROMO_GRAPHIC, TV_BANNER, PHONE_SCREENSHOTS,

View File

@ -266,6 +266,17 @@ public class IndexV1UpdaterTest extends FDroidProviderTest {
}
parser.close(); // ensure resources get cleaned up timely and properly
// test LiberapayID: -> Liberapay: migration
for (App app : apps) {
if ("org.witness.informacam.app".equals(app.packageName)) {
assertEquals("GuardianProject", app.liberapay);
} else if ("info.guardianproject.cacert".equals(app.packageName)) {
assertEquals("~1337", app.liberapay);
} else {
assertNull(app.liberapay);
}
}
RepoDetails indexV0Details = getFromFile("guardianproject_index.xml",
Repo.PUSH_REQUEST_ACCEPT_ALWAYS);
indexV0Details.apps.size();
@ -325,7 +336,7 @@ public class IndexV1UpdaterTest extends FDroidProviderTest {
"iconUrl",
"issueTracker",
"lastUpdated",
"liberapayID",
"liberapay",
"license",
"litecoin",
"name",

View File

@ -28,6 +28,7 @@
"suggestedVersionCode": "999999999",
"description": "<p>Android 4+ allows you to disable certificates from the system Settings and root isn't required, so try that first if you want to manually mess with the certificates. The app won't work with Android 4+ anyway.</p><p>An app to manage security certificates on your phone also containing a version of the Android CACert keystore derived from Mozilla. If a certificate has recently become untrusted you can either install an update to this app or you can backup and remove certificates by yourself.</p><p>Requires root: Yes, it writes to the system partition. You will need a device that has the \u2018grep\u2019 command on it (via busybox: present on most custom ROMs). If the \u2018save\u2019 doesn\u2019t work, then you will need to make your /system partition read-write by using a file explorer like <a href=\"fdroid.app:com.ghostsq.commander\">Ghost Commander</a> or via a command in <a href=\"fdroid.app:jackpal.androidterm\">Terminal Emulator</a>.</p>",
"issueTracker": "https://github.com/guardianproject/cacert/issues",
"liberapayID": "1337",
"license": "GPLv3",
"name": "CACertMan",
"sourceCode": "https://github.com/guardianproject/cacert",
@ -47,6 +48,8 @@
"suggestedVersionCode": "9999999",
"description": "<p>An InformaCam app to generate verifiable media.</p>",
"issueTracker": "https://dev.guardianproject.info/projects/informacam/issues",
"liberapay": "GuardianProject",
"liberapayID": "27859",
"license": "GPLv3",
"name": "CameraV",
"openCollective": "GuardianProject",