make db maxSdkValues values use Byte.MAX_VALUE as max not 0
Having 0 mean max makes the logic confusing when maxSdkValue is used in variable. This sanitizes the data so that maxSdkValue is always just a plain int value that can be used to test against. It does this by defaulting to Byte.MAX_VALUE (127) if it is not explicitly set. At the rate of 24 SDK numbers in 8 years, that gives us about 24 years before we have to think about setting it to Short.MAX_VALUE. This fixes an issue created by e021eb5ca7e8f05dbce7c1b87833722542138302
This commit is contained in:
parent
74713810dd
commit
fc0df0dcf4
app/src/main/java/org/fdroid/fdroid/data
@ -19,7 +19,7 @@ public class Apk extends ValueObject implements Comparable<Apk> {
|
||||
public String hash;
|
||||
public String hashType;
|
||||
public int minSdkVersion; // 0 if unknown
|
||||
public int maxSdkVersion; // 0 if none
|
||||
public int maxSdkVersion = Byte.MAX_VALUE; // "infinity" if not set
|
||||
public Date added;
|
||||
public Utils.CommaSeparatedList permissions; // null if empty or
|
||||
// unknown
|
||||
|
@ -106,7 +106,7 @@ class DBHelper extends SQLiteOpenHelper {
|
||||
+ " );";
|
||||
private static final String DROP_TABLE_INSTALLED_APP = "DROP TABLE " + TABLE_INSTALLED_APP + ";";
|
||||
|
||||
private static final int DB_VERSION = 53;
|
||||
private static final int DB_VERSION = 54;
|
||||
|
||||
private final Context context;
|
||||
|
||||
@ -291,6 +291,7 @@ class DBHelper extends SQLiteOpenHelper {
|
||||
recreateInstalledCache(db, oldVersion);
|
||||
addCredentialsToRepo(db, oldVersion);
|
||||
addAuthorToApp(db, oldVersion);
|
||||
useMaxValueInMaxSdkVersion(db, oldVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -475,6 +476,15 @@ class DBHelper extends SQLiteOpenHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private void useMaxValueInMaxSdkVersion(SQLiteDatabase db, int oldVersion) {
|
||||
if (oldVersion < 54) {
|
||||
Utils.debugLog(TAG, "Converting maxSdkVersion value 0 to " + Byte.MAX_VALUE);
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ApkProvider.DataColumns.MAX_SDK_VERSION, Byte.MAX_VALUE);
|
||||
db.update(TABLE_APK, values, ApkProvider.DataColumns.MAX_SDK_VERSION + " < 1", null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* By clearing the etags stored in the repo table, it means that next time the user updates
|
||||
* their repos (either manually or on a scheduled task), they will update regardless of whether
|
||||
|
Loading…
x
Reference in New Issue
Block a user