Skip to content

Commit

Permalink
Add support for missing build.prop on LOS15
Browse files Browse the repository at this point in the history
Fix #36
  • Loading branch information
julianxhokaxhiu committed Nov 10, 2017
1 parent 75aed4f commit 32ae382
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 @@ -292,16 +297,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

4 comments on commit 32ae382

@ALTracer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null coalescing operator was added only in PHP 7 as syntactic sugar.
I have just installed your LineageOTA on my Raspberry Pi 3 Raspbian 8 Jessie, and in the repos there's just php5-5.6.33, which throws Syntax error: unexpected '?' at line 79 Build.php.
Do I get a fresh PHP for Debian armhf or should I rewrite your code without language knowledge?

@julianxhokaxhiu
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest I don't see why I should "downgrade" my code to PHP 5.6 because of that, PHP 7.x is anyway considered a standard around. For that I would suggest to Google around. Maybe this can help you too https://raspberrypi.stackexchange.com/questions/70388/how-to-install-php-7-1

@ALTracer
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for nagging, I actually found how to install fresh php7 packages from stretch onto jessie using some manual on teh webs. My server is up and running at http://altracer.onthewifi.com/LineageOTA/ with api, which wasn't exactly obvoius to enable either. Now I only need some means to create delta updates.

@julianxhokaxhiu
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :) I'm happy it worked. Enjoy!

Please sign in to comment.