Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a363253a authored by Alexandre Roux's avatar Alexandre Roux Committed by Mohammed Althaf T
Browse files

Updater: hide lower android versions



Change-Id: Ic2746aa8507ba770c52c3cdc666b0f03ad533842
Signed-off-by: default avataralthafvly <althafvly@murena.io>
parent 120d29f2
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -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();
+13 −1
Original line number Diff line number Diff line
@@ -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");
+10 −0
Original line number Diff line number Diff line
@@ -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;
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -31,4 +31,6 @@ public interface UpdateBaseInfo {
    String getDownloadUrl();

    long getFileSize();

    String getAndroidVersion();
}