selwin / python-user-agents

A Python library that provides an easy way to identify devices like mobile phones, tablets and their capabilities by parsing (browser) user agent strings.
MIT License
1.44k stars 197 forks source link

Samsung Galaxy S6 SM-G920T identified as tablet #73

Open emmettbutler opened 7 years ago

emmettbutler commented 7 years ago
In [1]: import user_agents
In [2]: agent = "Dalvik/2.1.0 (Linux; U; Android 6.0.1; SM-G920T Build/MMB29K)"
In [3]: parsed = user_agents.parse(agent)
In [4]: parsed.os
Out[4]: OperatingSystem(family='Android', version=(6, 0, 1), version_string='6.0.1')
In [5]: parsed.device
Out[5]: Device(family='Samsung SM-G920T', brand='Samsung', model='SM-G920T')
In [6]: parsed.browser
Out[6]: Browser(family='Android', version=(6, 0, 1), version_string='6.0.1')
In [7]: parsed.is_tablet
Out[7]: True
In [8]: parsed.is_mobile
Out[8]: False

The S6 should be identified as mobile instead of tablet. From my read of the code, it looks like _is_android_tablet could use some updates.

I discovered this while investigating this issue on Parse.ly's open source Android SDK.

drlatech commented 7 years ago

There are also 2 more models which are shown as tablets.

  1. Samsung-SGH-I527, with this user agent Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; SAMSUNG-SGH-I527 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30 FB_IAB/FB4A;FBAV/104.0.0.17.71;

  2. Samsung-SPH-L600 Mozilla/5.0 (Linux; U; Android 4.2.2; en-us; SPH-L600 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30 FB_IAB/FB4A;FBAV/85.0.0.15.70;

I debugged function parse in parsers, the problem is that there is no 'Mobile' in user agent, before Safari, so this automatically becomes tablet. I thought that this could be related with screen size and resolution. They are 6.3 inches.

emmettbutler commented 7 years ago

Another user agent shown as a tablet that should parse as mobile:

Dalvik/2.1.0 (Linux; U; Android 7.1.2; Nexus 6P Build/N2G47O)
UdayVarkhedkar commented 7 years ago

Attached is a txt file of multiple mobile user agents that are incorrectly being parsed as tablets. Misclassified_Mobile_UserAgents.txt