diff --git a/src/Helpers/Build.php b/src/Helpers/Build.php index cce36ffe7d7f51148666b42eabb69dc227f0027e..87bcf4d060c4786af944b5923eb2b611c51d9aaa 100644 --- a/src/Helpers/Build.php +++ b/src/Helpers/Build.php @@ -51,7 +51,7 @@ * @param type $fileName The current filename of the build * @param type $physicalPath The current path where the build lives */ - public function __construct($fileName, $physicalPath, $logger) + public function __construct($fileName, $physicalPath, $logger, $shouldDisplayPatch = false) { $this->logger = $logger; @@ -90,6 +90,9 @@ $this->apiLevel = $this->getBuildPropValue('ro.build.version.sdk') ?? ''; $this->model = $this->getBuildPropValue('ro.lineage.device') ?? $this->getBuildPropValue('ro.cm.device') ?? ($tokens[1] == 'cm' ? $tokens[9] : $tokens[8]); $this->version = $tokens[2]; + if(substr_count($this->version, ".") > 1 && !$shouldDisplayPatch) { + $this->version = substr($this->version, 0, strrpos($this->version, '.'));//remove maintenance number when using an old updater to avoid crash + } $this->preversion = $tokens[3]; $this->displayVersion = $this->getBuildPropValue('ro.cm.display.version') ?? $this->getBuildPropValue('ro.lineage.display.version') ?? ''; $this->androidVersion = $this->getBuildPropValue('ro.build.version.release') ?? ''; @@ -400,6 +403,15 @@ private function parseSemVer($versionString) { $versionArray = explode(".", $versionString); + if(empty($versionArray[0])) { + $versionArray[0] = 0; + } + if(empty($versionArray[1])) { + $versionArray[1] = 0; + } + if(empty($versionArray[2])) { + $versionArray[2] = 0; + } return array_map("intval", $versionArray); } @@ -529,9 +541,9 @@ * @param type $params The params dictionary inside the current POST request * @return boolean True if valid, False if not. */ - public function includeInResults($params) + public function includeInResults($params, $currenteOSVersion) { - return $this->isValid($params) && $this->checkRollout() && $this->getSize() > 0; + return $this->isValid($params) && $this->checkRollout() && $this->checkRequirements($currenteOSVersion) && $this->getSize() > 0; } /** @@ -552,10 +564,36 @@ return ($configFilePath) ? json_decode( file_get_contents($configFilePath) , true) : array(); } + /** + * Return if requirements are met or not for a build + * @return boolean + */ + public function checkRequirements($currenteOSVersion="") + { + $minimalVersion = isset($this->confProp['requirements']) ? $this->confProp['requirements']['minOSVersion'] : null; + $isCompatible = true; + if(isset($minimalVersion)){ + $currenteOSVersionSemantic = $this->parseSemVer($currenteOSVersion); + $minimalSemanticVersion = $this->parseSemVer($minimalVersion); + $isCompatible = false; + if($currenteOSVersionSemantic[0] == $minimalSemanticVersion[0]){ + if($currenteOSVersionSemantic[1] == $minimalSemanticVersion[1]){ + $isCompatible = $currenteOSVersionSemantic[2] >= $minimalSemanticVersion[2]; + } + else + $isCompatible = $currenteOSVersionSemantic[1] > $minimalSemanticVersion[1]; + } + else + $isCompatible = $currenteOSVersionSemantic[0] > $minimalSemanticVersion[0]; + } + return $isCompatible; + } + /** * Return if rollout successful or not for a build * @return boolean */ + public function checkRollout() { $rolloutpercentage = isset($this->confProp['rollout']['percentage']) ? (int) $this->confProp['rollout']['percentage'] : 100; diff --git a/src/Helpers/Builds.php b/src/Helpers/Builds.php index dc0a413b7a0c1ed7b6b45d80839e02deb7eb98fa..b7e84b44fa29272fa8258344d052ec0b1f65b7a9 100644 --- a/src/Helpers/Builds.php +++ b/src/Helpers/Builds.php @@ -160,7 +160,15 @@ private function getBuilds() { $params = $this->postData['params']; - + preg_match_all('/.*(eOS) v([0-9\.]+)-?((alpha|beta|rc)(\.\d)?)?.*/', $_SERVER['HTTP_USER_AGENT'], $currentTokens); + $shouldDisplayPatch=false; + $this->currenteOSVersion = -1; + if(isset($currentTokens[2]) && count($currentTokens[2])>0){ + $this->currenteOSVersion = $currentTokens[2][0]; + $versionArray = explode(".", $this->currenteOSVersion); + if($versionArray[0] > 1 || $versionArray[0] == 1 && $versionArray[1] > 5) + $shouldDisplayPatch = true; + } $device = isset($params['device']) ? $params['device'] : ''; $channels = isset($params['channels']) ? $params['channels'][0] : ''; @@ -189,15 +197,15 @@ // If not found there, we have to find it with the old fashion method... if ($build === false) { - $build = new Build($file, $dir, $this->logger); + $build = new Build($file, $dir, $this->logger, $shouldDisplayPatch); // ...and then save it for 72h until it expires again apcu_store($file, $build, 72*60*60); } } else { - $build = new Build($file, $dir, $this->logger); + $build = new Build($file, $dir, $this->logger, $shouldDisplayPatch); } - if ($build->includeInResults($this->postData['params'])) { + if ($build->includeInResults($this->postData['params'], $this->currenteOSVersion)) { array_push($this->builds, $build); }