!581 [新增] UserAgentUtil 解析,增加 MiUI/XiaoMi 浏览器 判断逻辑

Merge pull request !581 from xhal/v5-master
This commit is contained in:
Looly 2022-03-22 10:33:40 +00:00 committed by Gitee
commit 04e0faddf4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 19 additions and 0 deletions

View File

@ -45,6 +45,8 @@ public class Browser extends UserAgentInfo {
new Browser("Taobao", "taobao", "AliApp\\(TB\\/([\\d\\w\\.\\-]+)\\)"),
// UC浏览器
new Browser("UCBrowser", "UC?Browser", "UC?Browser\\/([\\d\\w\\.\\-]+)"),
// XiaoMi 浏览器
new Browser("MiuiBrowser", "MiuiBrowser|mibrowser", "MiuiBrowser\\/([\\d\\w\\.\\-]+)"),
// 夸克浏览器
new Browser("Quark", "Quark", Other_Version),
// 联想浏览器

View File

@ -36,6 +36,7 @@ public class OS extends UserAgentInfo {
new OS("Windows", "windows"), //
new OS("OSX", "os x (\\d+)[._](\\d+)", "os x (\\d+([._]\\d+)*)"), //
new OS("Android", "Android", "Android (\\d+([._]\\d+)*)"),//
new OS("Android", "\\(X\\d+; Linux", "\\(X(\\d+([._]\\d+)*)"),//
new OS("Linux", "linux"), //
new OS("Wii", "wii", "wii libnup/(\\d+([._]\\d+)*)"), //
new OS("PS3", "playstation 3", "playstation 3; (\\d+([._]\\d+)*)"), //

View File

@ -54,6 +54,7 @@ public class Platform extends UserAgentInfo {
IPAD, //
IPOD, //
IPHONE, //
new Platform("Android", "XiaoMi|MI "), //
ANDROID, //
GOOGLE_TV, //
new Platform("htcFlyer", "htc_flyer"), //

View File

@ -389,4 +389,19 @@ public class UserAgentUtilTest {
Assert.assertEquals("Windows", ua.getPlatform().toString());
Assert.assertFalse(ua.isMobile());
}
@Test
public void parseXiaoMiTest(){
String uaStr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/89.0.4389.116 Safari/534.24 XiaoMi/MiuiBrowser/16.0.18 swan-mibrowser";
final UserAgent ua = UserAgentUtil.parse(uaStr);
Assert.assertEquals("MiuiBrowser", ua.getBrowser().toString());
Assert.assertEquals("16.0.18", ua.getVersion());
Assert.assertEquals("Webkit", ua.getEngine().toString());
Assert.assertEquals("534.24", ua.getEngineVersion());
Assert.assertEquals("Android", ua.getOs().toString());
Assert.assertEquals("11", ua.getOsVersion());
Assert.assertEquals("Android", ua.getPlatform().toString());
Assert.assertTrue(ua.isMobile());
}
}