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

Commit 449e7a2c authored by Sooraj S's avatar Sooraj S 👽
Browse files

updater: add support for android version upgrades

parent 82ef1134
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -38,9 +38,11 @@ zip_name=`basename "$zip_path"`
id=`echo "$zip_name" | sha1sum | cut -d' ' -f1`
version=`echo "$zip_name" | cut -d'-' -f2`
type=`echo "$zip_name" | cut -d'-' -f4`
build_date=`echo "$zip_name" | cut -d'-' -f3 | cut -d'_' -f1`
build_date=`echo "$zip_name" | cut -d'-' -f4 | cut -d'_' -f1`
timestamp=`date --date="$build_date 23:59:59" +%s`
size=`stat -c "%s" "$zip_path"`
display_version=
android_version='10'

adb push "$zip_path" "$zip_path_device"
adb shell chgrp cache "$zip_path_device"
@@ -52,5 +54,9 @@ adb shell "sqlite3 /data/data/org.lineageos.updater/databases/updates.db" \
    "\"INSERT INTO updates (status, path, download_id, timestamp, type, version, size)" \
    "  VALUES ($status, '$zip_path_device', '$id', $timestamp, '$type', '$version', $size)\""

# adb shell "sqlite3 /data/data/org.lineageos.updater/databases/updates.db" \
#     "\"INSERT INTO updates (status, path, download_id, timestamp, type, version, display_version, android_version, size)" \
#     "  VALUES ($status, '$zip_path_device', '$id', $timestamp, '$type', '$version', '$display_version', '$android_version', $size)\""

# Exit root mode
adb unroot
+4 −0
Original line number Diff line number Diff line
@@ -33,4 +33,8 @@ public final class BuildInfoUtils {
    public static String getDisplayVersion() {
        return SystemProperties.get(Constants.PROP_BUILD_DISPLAY_VERSION);
    }

    public static String getReleaseVersion() {
        return SystemProperties.get(Constants.PROP_BUILD_RELEASE_VERSION);
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ public final class Constants {
    public static final String PROP_BUILD_DATE = "ro.build.date.utc";
    public static final String PROP_BUILD_VERSION = "ro.lineage.build.version";
    public static final String PROP_BUILD_DISPLAY_VERSION = "ro.lineage.display.version";
    public static final String PROP_BUILD_RELEASE_VERSION = "ro.build.version.release";
    public static final String PROP_BUILD_VERSION_INCREMENTAL = "ro.build.version.incremental";
    public static final String PROP_DEVICE = "ro.lineage.device";
    public static final String PROP_NEXT_DEVICE = "ro.updater.next_device";
+18 −0
Original line number Diff line number Diff line
@@ -92,6 +92,8 @@ public class Utils {
        update.setDownloadUrl(object.getString("url"));
        update.setVersion(object.getString("version"));
        update.setDisplayVersion(object.getString("display_version"));
        update.setReleaseVersion(object.getString("android_version"));
        update.setUpgradeSupported(object.getBoolean("is_upgrade_supported"));
        return update;
    }

@@ -105,6 +107,22 @@ public class Utils {
            Log.d(TAG, update.getName() + " has type " + update.getType());
            return false;
        }
        if (update.getUpgradeSupported()) {
            Log.d(TAG, " is_upgrade_supported :" + update.getUpgradeSupported());
            Log.d(TAG, " Check for newer Android version ");

            if (!update.getReleaseVersion().equals(SystemProperties.get(Constants.PROP_BUILD_RELEASE_VERSION))) {
                Log.d(TAG, update.getName() + " android_version :" + update.getReleaseVersion());
                Version deviceAndroidVersion = new Version(SystemProperties.get(Constants.PROP_BUILD_RELEASE_VERSION));
                Version updateAndroidVersion = new Version(update.getReleaseVersion());
                if (updateAndroidVersion.compareTo(deviceAndroidVersion)==1){
                    Log.d(TAG, " newer Android version is available");
                    return true;
                }
                Log.d(TAG, " Same or old Android version ");
            }
        }

        return true;
    }

+49 −0
Original line number Diff line number Diff line
package org.lineageos.updater.misc;


public class Version implements Comparable<Version> {

    private String version;

    public final String get() {
        return this.version;
    }

    public Version(String version) {
        if(version == null)
            throw new IllegalArgumentException("Version can not be null");
        if(!version.matches("[0-9]+(\\.[0-9]+)*"))
            throw new IllegalArgumentException("Invalid version format");
        this.version = version;
    }

    @Override public int compareTo(Version that) {
        if(that == null)
            return 1;
        String[] thisParts = this.get().split("\\.");
        String[] thatParts = that.get().split("\\.");
        int length = Math.max(thisParts.length, thatParts.length);
        for(int i = 0; i < length; i++) {
            int thisPart = i < thisParts.length ?
                Integer.parseInt(thisParts[i]) : 0;
            int thatPart = i < thatParts.length ?
                Integer.parseInt(thatParts[i]) : 0;
            if(thisPart < thatPart)
                return -1;
            if(thisPart > thatPart)
                return 1;
        }
        return 0;
    }

    @Override public boolean equals(Object that) {
        if(this == that)
            return true;
        if(that == null)
            return false;
        if(this.getClass() != that.getClass())
            return false;
        return this.compareTo((Version) that) == 0;
    }

}
 No newline at end of file
Loading