diff --git a/src/org/lineageos/updater/UpdatesDbHelper.java b/src/org/lineageos/updater/UpdatesDbHelper.java index 9dadd4b6095c84a209bca0548b95911cf7167e43..bf78b829f5009b85ef26692c85389fdaf154e088 100644 --- a/src/org/lineageos/updater/UpdatesDbHelper.java +++ b/src/org/lineageos/updater/UpdatesDbHelper.java @@ -30,7 +30,7 @@ import java.util.List; public class UpdatesDbHelper extends SQLiteOpenHelper { - public static final int DATABASE_VERSION = 2; + public static final int DATABASE_VERSION = 3; public static final String DATABASE_NAME = "updates.db"; public static class UpdateEntry implements BaseColumns { @@ -43,6 +43,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { public static final String COLUMN_NAME_VERSION = "version"; public static final String COLUMN_NAME_DISPLAY_VERSION = "display_version"; public static final String COLUMN_NAME_SIZE = "size"; + public static final String COLUMN_NAME_ANDROID_VERSION = "android_version"; } private static final String SQL_CREATE_ENTRIES = @@ -55,7 +56,8 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { UpdateEntry.COLUMN_NAME_TYPE + " TEXT," + UpdateEntry.COLUMN_NAME_VERSION + " TEXT," + UpdateEntry.COLUMN_NAME_DISPLAY_VERSION + " TEXT," + - UpdateEntry.COLUMN_NAME_SIZE + " INTEGER)"; + UpdateEntry.COLUMN_NAME_SIZE + " INTEGER," + + UpdateEntry.COLUMN_NAME_ANDROID_VERSION + " TEXT)"; private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + UpdateEntry.TABLE_NAME; @@ -93,6 +95,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { values.put(UpdateEntry.COLUMN_NAME_VERSION, update.getVersion()); values.put(UpdateEntry.COLUMN_NAME_DISPLAY_VERSION, update.getDisplayVersion()); values.put(UpdateEntry.COLUMN_NAME_SIZE, update.getFileSize()); + values.put(UpdateEntry.COLUMN_NAME_ANDROID_VERSION, update.getAndroidVersion()); } public void removeUpdate(String downloadId) { @@ -131,6 +134,7 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { UpdateEntry.COLUMN_NAME_DISPLAY_VERSION, UpdateEntry.COLUMN_NAME_STATUS, UpdateEntry.COLUMN_NAME_SIZE, + UpdateEntry.COLUMN_NAME_ANDROID_VERSION, }; String sort = UpdateEntry.COLUMN_NAME_TIMESTAMP + " DESC"; Cursor cursor = db.query(UpdateEntry.TABLE_NAME, projection, selection, selectionArgs, @@ -156,6 +160,8 @@ public class UpdatesDbHelper extends SQLiteOpenHelper { update.setPersistentStatus(cursor.getInt(index)); index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_SIZE); update.setFileSize(cursor.getLong(index)); + index = cursor.getColumnIndex(UpdateEntry.COLUMN_NAME_ANDROID_VERSION); + update.setAndroidVersion(cursor.getString(index)); updates.add(update); } cursor.close(); diff --git a/src/org/lineageos/updater/misc/Utils.java b/src/org/lineageos/updater/misc/Utils.java index 903714a4064d471ba3987316462ff3d12bb9d0f9..f21df4b6cc529dc9b003611f413e5a70b03e4e9e 100644 --- a/src/org/lineageos/updater/misc/Utils.java +++ b/src/org/lineageos/updater/misc/Utils.java @@ -22,6 +22,7 @@ import static android.os.SystemUpdateManager.STATUS_IDLE; import static android.os.SystemUpdateManager.STATUS_WAITING_DOWNLOAD; import android.app.AlarmManager; +import android.os.Build; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; @@ -107,6 +108,7 @@ public class Utils { update.setFileSize(object.getLong("size")); update.setDownloadUrl(object.getString("url")); update.setVersion(object.getString("version")); + update.setAndroidVersion(object.getString("android_version")); if (object.has("pre_version") && !object.getString("pre_version").isEmpty()) { update.setDisplayVersion(object.getString("version") + "-" + object.getString("pre_version")); } else { @@ -116,6 +118,17 @@ public class Utils { } public static boolean isCompatible(UpdateBaseInfo update) { + String updateAndroidVersion = update.getAndroidVersion(); + if (!updateAndroidVersion.isEmpty()) { + final int updateOSVersion = Float.valueOf(updateAndroidVersion).intValue(); + final int deviceOSVersion = Float.valueOf(Build.VERSION.RELEASE).intValue(); + if (deviceOSVersion > updateOSVersion) { + Log.d(TAG, "Update : Skipping " + update.getName() + " since the installed version " + + deviceOSVersion + " is newer than update " + updateOSVersion); + return false; + } + } + int[] updateVersionParts = parseSemVer(update.getVersion()); int updateMajorVersion = updateVersionParts[0]; int updateMinorVersion = updateVersionParts[1]; @@ -126,7 +139,6 @@ public class Utils { int deviceMinorVersion = deviceVersionParts[1]; Log.d(TAG, "Device : Major "+ deviceMajorVersion +" Minor "+ deviceMinorVersion ); - if (!SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) && update.getTimestamp() <= SystemProperties.getLong(Constants.PROP_BUILD_DATE, 0)) { Log.d(TAG, update.getName() + " is older than/equal to the current build"); diff --git a/src/org/lineageos/updater/model/UpdateBase.java b/src/org/lineageos/updater/model/UpdateBase.java index cfa2027ed82bec55334483be351c1447e195a00b..f1689bceb650eb4470c91c26c9d7b36044e41a59 100644 --- a/src/org/lineageos/updater/model/UpdateBase.java +++ b/src/org/lineageos/updater/model/UpdateBase.java @@ -24,6 +24,7 @@ public class UpdateBase implements UpdateBaseInfo { private String mType; private String mVersion; private String mDisplayVersion; + private String mAndroidVersion; private long mFileSize; public UpdateBase() { @@ -111,4 +112,13 @@ public class UpdateBase implements UpdateBaseInfo { public void setFileSize(long fileSize) { mFileSize = fileSize; } + + @Override + public String getAndroidVersion() { + return mAndroidVersion; + } + + public void setAndroidVersion(String androidVersion) { + mAndroidVersion = androidVersion; + } } diff --git a/src/org/lineageos/updater/model/UpdateBaseInfo.java b/src/org/lineageos/updater/model/UpdateBaseInfo.java index 2921e96fc57c93c510348eb301abdc961ca3bae9..aea17bd80661f3ce8cd99919c17cad79490d4a80 100644 --- a/src/org/lineageos/updater/model/UpdateBaseInfo.java +++ b/src/org/lineageos/updater/model/UpdateBaseInfo.java @@ -31,4 +31,6 @@ public interface UpdateBaseInfo { String getDownloadUrl(); long getFileSize(); + + String getAndroidVersion(); }