Skip to content

Commit

Permalink
Adds detection for ASPLinux, SerenityOS, improves detection for Fire …
Browse files Browse the repository at this point in the history
…OS, improves version detection for Fire OS, Lineage OS and tvOS (matomo-org#7630)

* Improves detection for Fire OS
* Improves detection for Firefox Focus
* Improves version detection for Fire OS
* Improves version detection for Lineage OS
* Avoid detection of the Android version
* Improves version detection for Lineage OS
* Improves version detection for Lineage OS
* Improves version detection for tvOS
* Adds detection for SerenityOS
* Adds detection for ASPLinux
* Make fireOsVersionMapping and lineageOsVersionMapping private
  • Loading branch information
liviuconcioiu authored Mar 22, 2024
1 parent 1dab2b3 commit 19baec0
Show file tree
Hide file tree
Showing 7 changed files with 776 additions and 601 deletions.
85 changes: 67 additions & 18 deletions Parser/OperatingSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class OperatingSystem extends AbstractParser
'ARM' => 'Armadillo OS',
'ATV' => 'tvOS',
'ARL' => 'Arch Linux',
'ASP' => 'ASPLinux',
'BTR' => 'BackTrack',
'SBA' => 'Bada',
'BEO' => 'BeOS',
Expand Down Expand Up @@ -152,6 +153,7 @@ class OperatingSystem extends AbstractParser
'SSE' => 'SUSE',
'SAF' => 'Sailfish OS',
'SEE' => 'SeewoOS',
'SER' => 'SerenityOS',
'SIR' => 'Sirin OS',
'SLW' => 'Slackware',
'SOS' => 'Solaris',
Expand Down Expand Up @@ -219,7 +221,7 @@ class OperatingSystem extends AbstractParser
'LOS', 'DVK', 'ROK', 'OWR', 'OTV', 'KTV', 'PUR', 'PLA', 'FUC', 'PAR',
'FOR', 'MON', 'KAN', 'ZEN', 'LND', 'LNS', 'CHN', 'AMZ', 'TEN', 'CST',
'NOV', 'ROU', 'ZOR', 'RED', 'KAL', 'ORA', 'VID', 'TIV', 'BSN', 'RAS',
'UOS', 'PIO', 'FRI', 'LIR', 'WEB',
'UOS', 'PIO', 'FRI', 'LIR', 'WEB', 'SER', 'ASP',
],
'Mac' => ['MAC'],
'Mobile Gaming Console' => ['PSP', 'NDS', 'XBX'],
Expand Down Expand Up @@ -252,6 +254,55 @@ class OperatingSystem extends AbstractParser
'AmigaOS', 'IBM', 'GNU/Linux', 'Mac', 'Unix', 'Windows', 'BeOS', 'Chrome OS', 'Chromium OS',
];

/**
* Fire OS version mapping
*
* @var array
*/
private $fireOsVersionMapping = [
'11' => '8',
'10' => '8',
'9' => '7',
'7' => '6',
'5' => '5',
'4.4.3' => '4.5.1',
'4.4.2' => '4',
'4.2.2' => '3',
'4.0.3' => '3',
'4.0.2' => '3',
'4' => '2',
'2' => '1',
];

/**
* Lineage OS version mapping
*
* @var array
*/
private $lineageOsVersionMapping = [
'14' => '21.0',
'13' => '20.0',
'12.1' => '19.1',
'12' => '19.0',
'11' => '18.0',
'10' => '17.0',
'9' => '16.0',
'8.1.0' => '15.1',
'8.0.0' => '15.0',
'7.1.2' => '14.1',
'7.1.1' => '14.1',
'7.0' => '14.0',
'6.0.1' => '13.0',
'6.0' => '13.0',
'5.1.1' => '12.1',
'5.0.2' => '12.0',
'5.0' => '12.0',
'4.4.4' => '11.0',
'4.3' => '10.2',
'4.2.2' => '10.1',
'4.0.4' => '9.1.0',
];

/**
* Returns all available operating systems
*
Expand Down Expand Up @@ -332,22 +383,8 @@ public function parse(): ?array
if ('Fire OS' === $osFromUserAgent['name']) {
$majorVersion = (int) (\explode('.', $version, 1)[0] ?? '0');

$fireOsVersionMapping = [
'11' => '8',
'10' => '8',
'9' => '7',
'7' => '6',
'5' => '5',
'4.4.3' => '4.5.1',
'4.4.2' => '4',
'4.2.2' => '3',
'4.0.3' => '3',
'4.0.2' => '3',
'4' => '2',
'2' => '1',
];

$version = $fireOsVersionMapping[$version] ?? $fireOsVersionMapping[$majorVersion] ?? $version;
$version = $this->fireOsVersionMapping[$version]
?? $this->fireOsVersionMapping[$majorVersion] ?? '';
}
}

Expand Down Expand Up @@ -385,10 +422,22 @@ public function parse(): ?array
}

if ('org.lineageos.jelly' === $this->clientHints->getApp() && 'Lineage OS' !== $name) {
$majorVersion = (int) (\explode('.', $version, 1)[0] ?? '0');

$name = 'Lineage OS';
$family = 'Android';
$short = 'LEN';
$version = '';
$version = $this->lineageOsVersionMapping[$version]
?? $this->lineageOsVersionMapping[$majorVersion] ?? '';
}

if ('org.mozilla.tv.firefox' === $this->clientHints->getApp() && 'Fire OS' !== $name) {
$majorVersion = (int) (\explode('.', $version, 1)[0] ?? '0');

$name = 'Fire OS';
$family = 'Android';
$short = 'FIR';
$version = $this->fireOsVersionMapping[$version] ?? $this->fireOsVersionMapping[$majorVersion] ?? '';
}
}

Expand Down
11 changes: 11 additions & 0 deletions Tests/Parser/Client/fixtures/browser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9023,3 +9023,14 @@
engine: WebKit
engine_version: 605.1.15
family:
-
user_agent: Mozilla/5.0 (Linux; Android 11) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Focus/4.5 Chrome/83.0.4103.120 Safari/537.36
client:
type: browser
name: Firefox Focus
version: "4.5"
engine: Blink
engine_version: 83.0.4103.120
family:
headers:
http-x-requested-with: org.mozilla.tv.firefox
Loading

0 comments on commit 19baec0

Please sign in to comment.