Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
Add support for missing build.prop on LOS15
Browse files Browse the repository at this point in the history
  • Loading branch information
julianxhokaxhiu authored and vince2678 committed Jun 11, 2018
1 parent fe76129 commit 69b0331
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/Helpers/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,16 @@ public function __construct($fileName, $physicalPath) {
$this->filePath = $physicalPath . '/' . $fileName;
$this->channel = $this->_getChannel( str_replace( range( 0 , 9 ), '', $tokens[4] ), $tokens[1], $tokens[2] );
$this->filename = $fileName;
$this->buildProp = explode( "\n", @file_get_contents('zip://'.$this->filePath.'#system/build.prop') );

// Try to load the build.prop from two possible paths:
// - builds/CURRENT_ZIP_FILE.zip/system/build.prop
// - builds/CURRENT_ZIP_FILE.zip.prop ( which must exist )
$this->buildProp = explode( "\n", @file_get_contents('zip://'.$this->filePath.'#system/build.prop') ?? @file_get_contents($filePath.'.prop') );
// Try to fetch build.prop values. In some cases, we can provide a fallback, in other a null value will be given
$this->timestamp = $this->getBuildPropValue( 'ro.build.date.utc' ) ?? '';
$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' );
$this->model = $this->getBuildPropValue( 'ro.lineage.device' ) ?? $this->getBuildPropValue( 'ro.cm.device' ) ?? ( $tokens[1] == 'cm' ? $tokens[6] : $tokens[5] );
$this->version = $tokens[2];
$this->uid = hash( 'sha256', $this->timestamp.$this->model.$this->apiLevel, false );

Expand Down Expand Up @@ -299,16 +304,19 @@ private function _getChangelogUrl(){
* Get a property value based on the $key value.
* It does it by searching inside the file build.prop of the current build.
* @param string $key The key for the wanted value
* @param string $fallback The fallback value if not found in build.prop
* @return string The value for the specified key
*/
private function getBuildPropValue($key){
$ret = null;

foreach ($this->buildProp as $line) {
if ( strpos($line, $key) !== false ) {
$tmp = explode('=', $line);
$ret = $tmp[1];
break;
private function getBuildPropValue($key, $fallback){
$ret = $fallback ?: null;

if ($this->buildProp) {
foreach ($this->buildProp as $line) {
if ( strpos($line, $key) !== false ) {
$tmp = explode('=', $line);
$ret = $tmp[1];
break;
}
}
}

Expand Down

0 comments on commit 69b0331

Please sign in to comment.