Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android device info is not detected correctly #485

Open
itsalongstory opened this issue Jul 14, 2020 · 5 comments
Open

Android device info is not detected correctly #485

itsalongstory opened this issue Jul 14, 2020 · 5 comments

Comments

@itsalongstory
Copy link
Contributor

itsalongstory commented Jul 14, 2020

2.6.5 :001 > browser = Browser.new("Mozilla/5.0 (Linux; Android 7.1.2; Redmi 4X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36")
 => #<Browser::Chrome:0x000055f37d32fb38 @ua="Mozilla/5.0 (Linux; Android 7.1.2; Redmi 4X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36", @accept_language=[]>
2.6.5 :002 > browser.device.id
 => :unknown
2.6.5 :003 > browser.device.name
 => "Unknown"
2.6.5 :001 > browser = Browser.new "Mozilla/5.0 (Linux; Android 10; HMA-AL00; HMSCore 5.0.0.304; GMSCore 19.6.29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 HuaweiBrowser/10.1.2.300 Mobile Safari/537.36"
 => #<Browser::Chrome:0x00007f71f4345748 @ua="Mozilla/5.0 (Linux; Android 10; HMA-AL00; HMSCore 5.0.0.304; GMSCore 19.6.29) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 HuaweiBrowser/10.1.2.300 Mobile Safari/537.36", @accept_language=[]> 
2.6.5 :002 > browser.device.id
 => :unknown 
2.6.5 :003 > browser.device.name
 => "Unknown" 
2.6.5 :001 > browser = Browser.new "Mozilla/5.0 (Linux; Android 10; SAMSUNG SM-N960U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36"
 => #<Browser::SamsungBrowser:0x00007f71f5a6d9c0 @ua="Mozilla/5.0 (Linux; Android 10; SAMSUNG SM-N960U) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/11.1 Chrome/75.0.3770.143 Mobile Safari/537.36", @accept_language=[]> 
2.6.5 :002 > browser.device.id
 => :unknown 
2.6.5 :003 > browser.device.name
 => "Unknown" 
@itsalongstory
Copy link
Contributor Author

related to #232

@itsalongstory
Copy link
Contributor Author

module Browser
class Device
class Android < Base
def id
:unknown
end
def name
ua[/\(Linux.*?; Android.*?; ([-_a-z0-9 ]+) Build[^)]+\)/i, 1] ||
"Unknown"
end
def match?
ua =~ /Android/
end
end
end
end


{
"ANDROID_CUPCAKE" => "T-Mobile G1",
"ANDROID_DONUT" => "SonyEricssonX10i",
"ANDROID_ECLAIR_21" => "Nexus One",
"ANDROID_FROYO" => "HTC_DesireHD_A9191",
"ANDROID_GINGERBREAD" => "Sensation_4G",
"ANDROID_HONEYCOMB_30" => "Xoom",
"ANDROID_ICECREAM" => "sdk",
"ANDROID_JELLYBEAN_41" => "Nexus S",
"ANDROID_JELLYBEAN_42" => "Nexus 10",
"ANDROID_JELLYBEAN_43" => "Nexus 7",
"CUSTOM_APP" => "HTC Ruby",
"NOOK" => "NOOK BNTV250A"
}.each do |key, name|
test "detect device name of #{key} as #{name}" do
device = Browser::Device.new(Browser[key])
assert_equal name, device.name
end
end

@itsalongstory
Copy link
Contributor Author

itsalongstory commented Jul 14, 2020

List of Android smartphones

https://en.wikipedia.org/wiki/List_of_Android_smartphones

With so many Android device manufacturers, we probably don't need to identify every model exactly. Maybe it's enough that we recognize it as Android!

@itsalongstory
Copy link
Contributor Author

itsalongstory commented Jul 14, 2020

It's really hard to detect device information from UA, except for Apple devices.

@pppp606
Copy link

pppp606 commented May 21, 2021

@itsalongstory
Android UA is implemented thinking that it always contains build information. This is the cause of the issue. The UA you presented also does not contains build information

Contains build information

Mozilla/5.0 (Linux; Android 11; Pixel 5 Build/RQ2A.210305.006; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/89.0.4389.86 Mobile Safari/537.36

Not contains build information

Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.105 Mobile Safari/537.36

There are actually UAs that don't include Build. Therefore, the current processing is incorrect.

def name
ua[/\(Linux.*?; Android.*?; ([-_a-z0-9 ]+) Build[^)]+\)/i, 1] ||
"Unknown"
end

@fnando
Ar we on the same page? If so, I will PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants