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

Commit 28a972b4 authored by Sooraj S's avatar Sooraj S 👽 Committed by Mohammed Althaf T
Browse files

Updater: Use helper function for parsing version code



Fix: Handle use case 1.0 is bigger than 0.9 Semantic versioning
Signed-off-by: default avatarAlexandre Roux D'Anzi <alexandre.roux.danzi@lostpod.me>
Signed-off-by: Aayush Gupta's avatarAayush Gupta <theimpulson@e.email>
Change-Id: Id107366ebf38f1e269101b4baeac10f3991fe1bb
Signed-off-by: default avataralthafvly <althafvly@gmail.com>
parent 471482b2
Loading
Loading
Loading
Loading
+31 −4
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ import java.util.Locale;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.regex.Pattern;

public class Utils {

@@ -85,10 +86,16 @@ public class Utils {
    }

    public static boolean isCompatible(UpdateBaseInfo update) {
        if (update.getVersion().compareTo(SystemProperties.get(Constants.PROP_BUILD_VERSION)) < 0) {
            Log.d(TAG, update.getName() + " is older than current Android version");
            return false;
        }
        int[] updateVersionParts = parseSemVer(update.getVersion());
        int updateMajorVersion = updateVersionParts[0];
        int updateMinorVersion = updateVersionParts[1];
        Log.d(TAG, "Update : Major "+updateMajorVersion +" Minor "+ updateMinorVersion );

        int[] deviceVersionParts = parseSemVer(SystemProperties.get(Constants.PROP_BUILD_VERSION));
        int deviceMajorVersion = deviceVersionParts[0];
        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");
@@ -98,8 +105,28 @@ public class Utils {
            Log.d(TAG, update.getName() + " has type " + update.getType());
            return false;
        }
        if(updateMajorVersion > deviceMajorVersion){
            Log.d(TAG, update.getName() + " is Newer to current Major version");
            return true;
        }
        if(updateMajorVersion < deviceMajorVersion){
            Log.d(TAG, update.getName() + " is Older to current Major version");
            return false;
        }
        if(updateMinorVersion < deviceMinorVersion){
            Log.d(TAG, update.getName() + " is Older to current Minor version");
            return false;
        }

        return true;
    }

    public static int[] parseSemVer(String versionCode) {
        String[] versionParts = versionCode.split(Pattern.quote("."));
        int major = Integer.parseInt(versionParts[0]);
        int minor = Integer.parseInt(versionParts[1]);
        return new int[]{ major, minor };
    }

    public static boolean canInstall(UpdateBaseInfo update) {
        return (SystemProperties.getBoolean(Constants.PROP_UPDATER_ALLOW_DOWNGRADING, false) ||