diff --git a/Parser/Device/AbstractDeviceParser.php b/Parser/Device/AbstractDeviceParser.php index aab3fbc11d..63e9d22f52 100644 --- a/Parser/Device/AbstractDeviceParser.php +++ b/Parser/Device/AbstractDeviceParser.php @@ -1870,6 +1870,16 @@ public function parse(): ?array $resultClientHint = $this->parseClientHints(); $deviceModel = $resultClientHint['model'] ?? ''; + // is freeze user-agent then restoring the original UA for the device definition + if ('' !== $deviceModel && \preg_match('~Android 10[.\d]*; K(?: Build/|[;)])~i', $this->userAgent)) { + $osVersion = $this->clientHints->getOperatingSystemVersion(); + $this->setUserAgent(\preg_replace( + '(Android 10[.\d]*; K)', + \sprintf('Android %s; %s', '' !== $osVersion ? $osVersion : '10', $deviceModel), + $this->userAgent + )); + } + if ('' === $deviceModel && $this->hasDesktopFragment()) { return $this->getResult(); } diff --git a/Tests/fixtures/clienthints.yml b/Tests/fixtures/clienthints.yml index 62619309fc..ec9fb8d72a 100644 --- a/Tests/fixtures/clienthints.yml +++ b/Tests/fixtures/clienthints.yml @@ -815,3 +815,107 @@ model: Quest 2 os_family: GNU/Linux browser_family: Chrome +- + user_agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36 + headers: + Sec-CH-UA: '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"' + Sec-CH-UA-Platform: "Android" + Sec-CH-UA-Mobile: "?1" + Sec-CH-UA-Full-Version: "114.0.5735.196" + Sec-CH-UA-Platform-Version: "10.0.0" + Sec-CH-UA-Model: "Mi 9 SE" + Sec-CH-Prefers-Color-Scheme: "light" + os: + name: Android + version: "10.0.0" + platform: + client: + type: browser + name: Chrome Mobile + version: 114.0.5735.196 + engine: Blink + engine_version: 114.0.0.0 + device: + type: smartphone + brand: Xiaomi + model: Mi 9 SE + os_family: Android + browser_family: Chrome +- + user_agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36 + headers: + Sec-CH-UA: '"Not.A/Brand";v="8", "Chromium";v="114", "Google Chrome";v="114"' + Sec-CH-UA-Platform: "Android" + Sec-CH-UA-Mobile: "?1" + Sec-CH-UA-Full-Version: "114.0.5735.196" + Sec-CH-UA-Platform-Version: "11.0.0" + Sec-CH-UA-Model: "SM-A105F" + Sec-CH-Prefers-Color-Scheme: "light" + os: + name: Android + version: "11.0.0" + platform: + client: + type: browser + name: Chrome Mobile + version: 114.0.5735.196 + engine: Blink + engine_version: 114.0.0.0 + device: + type: smartphone + brand: Samsung + model: Galaxy A10 + os_family: Android + browser_family: Chrome +- + user_agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Mobile Safari/537.36 + headers: + Sec-CH-UA: '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"' + Sec-CH-UA-Platform: "Android" + Sec-CH-UA-Mobile: "?1" + Sec-CH-UA-Full-Version: "111.0.5563.116" + Sec-CH-UA-Platform-Version: "13.0.0" + Sec-CH-UA-Model: "22071219CG" + Sec-CH-Prefers-Color-Scheme: "light" + os: + name: Android + version: "13.0.0" + platform: + client: + type: browser + name: Chrome Mobile + version: 111.0.5563.116 + engine: Blink + engine_version: 111.0.0.0 + device: + type: smartphone + brand: POCO + model: M5 + os_family: Android + browser_family: Chrome +- + user_agent: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Mobile Safari/537.36 + headers: + Sec-CH-UA: '"Google Chrome";v="111", "Not(A:Brand";v="8", "Chromium";v="111"' + Sec-CH-UA-Platform: "Android" + Sec-CH-UA-Mobile: "?1" + Sec-CH-UA-Full-Version: "111.0.5563.116" + Sec-CH-UA-Platform-Version: "" + Sec-CH-UA-Model: "22071219CG" + Sec-CH-Prefers-Color-Scheme: "light" + os: + name: Android + version: "10" + platform: + client: + type: browser + name: Chrome Mobile + version: 111.0.5563.116 + engine: Blink + engine_version: 111.0.0.0 + device: + type: smartphone + brand: POCO + model: M5 + os_family: Android + browser_family: Chrome