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

This commit is contained in:
xhal 2022-03-22 13:37:16 +08:00
parent f52ec39d44
commit d48d1bab25
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\\.\\-]+)\\)"), new Browser("Taobao", "taobao", "AliApp\\(TB\\/([\\d\\w\\.\\-]+)\\)"),
// UC浏览器 // UC浏览器
new Browser("UCBrowser", "UC?Browser", "UC?Browser\\/([\\d\\w\\.\\-]+)"), new Browser("UCBrowser", "UC?Browser", "UC?Browser\\/([\\d\\w\\.\\-]+)"),
// XiaoMi 浏览器
new Browser("MiuiBrowser", "MiuiBrowser|mibrowser", "MiuiBrowser\\/([\\d\\w\\.\\-]+)"),
// 夸克浏览器 // 夸克浏览器
new Browser("Quark", "Quark", Other_Version), new Browser("Quark", "Quark", Other_Version),
// 联想浏览器 // 联想浏览器

View File

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

View File

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

View File

@ -389,4 +389,19 @@ public class UserAgentUtilTest {
Assert.assertEquals("Windows", ua.getPlatform().toString()); Assert.assertEquals("Windows", ua.getPlatform().toString());
Assert.assertFalse(ua.isMobile()); 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());
}
} }