From fc0df0dcf4dd0d5f13de82d7cd9254b2b48cb62d Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 5 Apr 2016 10:59:08 +0200 Subject: [PATCH] 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 --- app/src/main/java/org/fdroid/fdroid/data/Apk.java | 2 +- .../main/java/org/fdroid/fdroid/data/DBHelper.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/data/Apk.java b/app/src/main/java/org/fdroid/fdroid/data/Apk.java index 72f26c7d9..09f694bf0 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/Apk.java +++ b/app/src/main/java/org/fdroid/fdroid/data/Apk.java @@ -19,7 +19,7 @@ public class Apk extends ValueObject implements Comparable { 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 diff --git a/app/src/main/java/org/fdroid/fdroid/data/DBHelper.java b/app/src/main/java/org/fdroid/fdroid/data/DBHelper.java index 1f0fe24f3..200cdcb65 100644 --- a/app/src/main/java/org/fdroid/fdroid/data/DBHelper.java +++ b/app/src/main/java/org/fdroid/fdroid/data/DBHelper.java @@ -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