Apk.versionName can be null, and the code should handle it

closes #1418
This commit is contained in:
Hans-Christoph Steiner 2018-04-17 14:20:28 +02:00
parent 94818e36bf
commit 36c76070e5
5 changed files with 73 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import android.os.Environment;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import com.fasterxml.jackson.annotation.JacksonInject;
@ -65,6 +66,7 @@ public class Apk extends ValueObject implements Comparable<Apk>, Parcelable {
// these come directly from the index metadata
public String packageName;
@Nullable
public String versionName;
public int versionCode;
public int size; // Size in bytes - 0 means we don't know!

View File

@ -95,7 +95,7 @@ public class DBHelper extends SQLiteOpenHelper {
static final String CREATE_TABLE_APK =
"CREATE TABLE " + ApkTable.NAME + " ( "
+ ApkTable.Cols.APP_ID + " integer not null, "
+ ApkTable.Cols.VERSION_NAME + " text not null, "
+ ApkTable.Cols.VERSION_NAME + " text, "
+ ApkTable.Cols.REPO_ID + " integer not null, "
+ ApkTable.Cols.HASH + " text not null, "
+ ApkTable.Cols.VERSION_CODE + " int not null,"
@ -215,7 +215,7 @@ public class DBHelper extends SQLiteOpenHelper {
+ "primary key(" + ApkAntiFeatureJoinTable.Cols.APK_ID + ", " + ApkAntiFeatureJoinTable.Cols.ANTI_FEATURE_ID + ") "
+ " );";
protected static final int DB_VERSION = 78;
protected static final int DB_VERSION = 79;
private final Context context;
@ -323,6 +323,16 @@ public class DBHelper extends SQLiteOpenHelper {
addIgnoreVulnPref(db, oldVersion);
addLiberapayID(db, oldVersion);
addUserMirrorsFields(db, oldVersion);
removeNotNullFromVersionName(db, oldVersion);
}
private void removeNotNullFromVersionName(SQLiteDatabase db, int oldVersion) {
if (oldVersion >= 79) {
return;
}
Log.i(TAG, "Forcing repo refresh to remove NOT NULL from " + ApkTable.Cols.VERSION_NAME);
resetTransient(db);
}
private void addUserMirrorsFields(SQLiteDatabase db, int oldVersion) {

View File

@ -50,6 +50,7 @@ import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@ -419,6 +420,8 @@ public class IndexV1UpdaterTest extends FDroidProviderTest {
assertEquals(1, apps.length);
assertEquals(1, packages.size());
List<Apk> cacerts = packages.get("info.guardianproject.cacert");
assertEquals(2, cacerts.size());
assertEquals(1488828510109L, repo.timestamp);
assertEquals("GPLv3", apps[0].license);
@ -427,12 +430,16 @@ public class IndexV1UpdaterTest extends FDroidProviderTest {
assertNotEquals("secret", field);
}
Apk apk = packages.get("info.guardianproject.cacert").get(0);
Apk apk = cacerts.get(0);
assertEquals("e013db095e8da843fae5ac44be6152e51377ee717e5c8a7b6d913d7720566b5a", apk.hash);
Set<String> packageFields = getFields(apk);
for (String field : packageFields) {
assertNotEquals("secret", field);
}
apk = cacerts.get(1);
assertEquals("2353d1235e8da843fae5ac44be6152e513123e717e5c8a7b6d913d7720566b5a", apk.hash);
assertNull(apk.versionName);
}
private Set<String> getFields(Object instance) {

View File

@ -87,6 +87,56 @@
],
"versionCode": 14,
"versionName": "0.1.8"
},
{
"added": 1400014500000,
"apkName": "Courier-0.0.apk",
"hash": "2353d1235e8da843fae5ac44be6152e513123e717e5c8a7b6d913d7720566b5a",
"hashType": "sha256",
"minSdkVersion": "9",
"nativecode": [
"armeabi",
"x86"
],
"packageName": "info.guardianproject.courier",
"sig": "d70ac6a02b53ebdd1354ea7af7b9ceee",
"size": 16536125,
"targetSdkVersion": "15",
"uses-permission": [
[
"android.permission.READ_EXTERNAL_STORAGE",
null
],
[
"android.permission.INTERNET",
null
],
[
"android.permission.BLUETOOTH",
null
],
[
"android.permission.BLUETOOTH_ADMIN",
null
],
[
"android.permission.VIBRATE",
null
],
[
"android.permission.ACCESS_NETWORK_STATE",
null
],
[
"android.permission.WRITE_EXTERNAL_STORAGE",
null
],
[
"android.permission.ACCESS_WIFI_STATE",
null
]
],
"versionCode": 0
}
]
}

File diff suppressed because one or more lines are too long