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

Commit c0198a26 authored by Arnau Vàzquez's avatar Arnau Vàzquez
Browse files

Merge branch 'version_compare_fix' into 'master'

Version compare fix

See merge request e/os/LineageOTA!17
parents 64cccc85 98ae4bac
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@
    else
        $protocol = 'http://';
    $logger = new Logger('main');
    $logger->pushHandler(new StreamHandler('LineageOTA.log', Logger::WARNING));
    $logger->pushHandler(new StreamHandler('LineageOTA.log', Logger::INFO));

    $app = new CmOta($logger);
    $app
+15 −7
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@
            $this->incremental = $this->getBuildPropValue('ro.build.version.incremental') ?? '';
            $this->apiLevel = $this->getBuildPropValue('ro.build.version.sdk') ?? '';
            $this->model = $this->getBuildPropValue('ro.lineage.device') ?? $this->getBuildPropValue('ro.cm.device') ?? ($tokens[1] == 'cm' ? $tokens[6] : $tokens[5]);
            $this->version = $tokens[2];
            $this->version = $tokens[2][0];
            $this->displayVersion = $this->getBuildPropValue('ro.cm.display.version') ?? $this->getBuildPropValue('ro.lineage.display.version') ?? '';
            $this->androidVersion = $this->getBuildPropValue('ro.build.version.release') ?? '';
            $this->uid = hash('sha256', $this->timestamp.$this->model.$this->apiLevel, false);
@@ -187,7 +187,7 @@
                return false; // Invalid build if timestamp older
            }

            return(version_compare($currentBuild->getVersion(), $this->getVersion(),  "<"));
            return(version_compare($currentBuild->getVersion(), $this->getVersion(),  "<="));
        }

        /**
@@ -244,7 +244,9 @@
        */
        public function getIsUpgradeSupported($compareVersion)
        {   
            $isSameVersion = boolval(!strcmp($this->androidVersion, $compareVersion)); // Check if Android version is same
            $thisMajorVersion = explode(".", $this->androidVersion)[0];
            $compareMajorVersion = explode(".", $compareVersion)[0];
            $isSameVersion = boolval(!strcmp($thisMajorVersion, $compareMajorVersion)); // Check if Android version is same
            $migrationContents = NULL;
            if(file_exists($this->migrationFilePath)) {
                $migrationContents = file_get_contents($this->migrationFilePath);
@@ -252,8 +254,8 @@
            if (!empty($migrationContents)) {
                $migrations = json_decode($migrationContents, true); // Contains migration rules

                if (!empty($migrations[$compareVersion]) && is_array($migrations[$compareVersion])) {
                    return in_array($this->androidVersion, $migrations[$compareVersion]);
                if (!empty($migrations[$compareMajorVersion]) && is_array($migrations[$compareMajorVersion])) {
                    return in_array(intval($thisMajorVersion), $migrations[$compareMajorVersion]);
                }
            }
            return $isSameVersion;
@@ -392,8 +394,14 @@
        private function removeTrailingDashes($token)
        {
            foreach ($token as $key => $value) {
                if(isset($value[0]) && !empty($value[0])) {
                    $token[$key] = trim($value[0], '-');
                }
                else {
                    $this->logger->warning("Token value null or not array for build located at: " . $this->filePath );
                    continue;
                }
            }
            return $token;
        }