mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
支持鸿蒙设备 UA 解析(pr#1301@Gitee)
This commit is contained in:
parent
1b468245c5
commit
b7b5fbea71
@ -40,32 +40,33 @@ public class OS extends UserAgentInfo {
|
||||
* 支持的引擎类型
|
||||
*/
|
||||
public static final List<OS> oses = ListUtil.view(//
|
||||
new OS("Windows 10 or Windows Server 2016", "windows nt 10\\.0", "windows nt (10\\.0)"),//
|
||||
new OS("Windows 8.1 or Windows Server 2012R2", "windows nt 6\\.3", "windows nt (6\\.3)"),//
|
||||
new OS("Windows 8 or Windows Server 2012", "windows nt 6\\.2", "windows nt (6\\.2)"),//
|
||||
new OS("Windows Vista", "windows nt 6\\.0", "windows nt (6\\.0)"), //
|
||||
new OS("Windows 7 or Windows Server 2008R2", "windows nt 6\\.1", "windows nt (6\\.1)"), //
|
||||
new OS("Windows 2003", "windows nt 5\\.2", "windows nt (5\\.2)"), //
|
||||
new OS("Windows XP", "windows nt 5\\.1", "windows nt (5\\.1)"), //
|
||||
new OS("Windows 2000", "windows nt 5\\.0", "windows nt (5\\.0)"), //
|
||||
new OS("Windows Phone", "windows (ce|phone|mobile)( os)?", "windows (?:ce|phone|mobile) (\\d+([._]\\d+)*)"), //
|
||||
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", "XiaoMi|MI\\s+", "\\(X(\\d+([._]\\d+)*)"),//
|
||||
new OS("Linux", "linux"), //
|
||||
new OS("Wii", "wii", "wii libnup/(\\d+([._]\\d+)*)"), //
|
||||
new OS("PS3", "playstation 3", "playstation 3; (\\d+([._]\\d+)*)"), //
|
||||
new OS("PSP", "playstation portable", "Portable\\); (\\d+([._]\\d+)*)"), //
|
||||
new OS("iPad", "\\(iPad.*os (\\d+)[._](\\d+)", "\\(iPad.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("iPhone", "\\(iPhone.*os (\\d+)[._](\\d+)", "\\(iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("YPod", "iPod touch[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPod touch[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("YPad", "iPad[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPad[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("YPhone", "iPhone[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPhone[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("Symbian", "symbian(os)?"), //
|
||||
new OS("Darwin", "Darwin\\/([\\d\\w\\.\\-]+)", "Darwin\\/([\\d\\w\\.\\-]+)"), //
|
||||
new OS("Adobe Air", "AdobeAir\\/([\\d\\w\\.\\-]+)", "AdobeAir\\/([\\d\\w\\.\\-]+)"), //
|
||||
new OS("Java", "Java[\\s]+([\\d\\w\\.\\-]+)", "Java[\\s]+([\\d\\w\\.\\-]+)")//
|
||||
new OS("Windows 10 or Windows Server 2016", "windows nt 10\\.0", "windows nt (10\\.0)"),//
|
||||
new OS("Windows 8.1 or Windows Server 2012R2", "windows nt 6\\.3", "windows nt (6\\.3)"),//
|
||||
new OS("Windows 8 or Windows Server 2012", "windows nt 6\\.2", "windows nt (6\\.2)"),//
|
||||
new OS("Windows Vista", "windows nt 6\\.0", "windows nt (6\\.0)"), //
|
||||
new OS("Windows 7 or Windows Server 2008R2", "windows nt 6\\.1", "windows nt (6\\.1)"), //
|
||||
new OS("Windows 2003", "windows nt 5\\.2", "windows nt (5\\.2)"), //
|
||||
new OS("Windows XP", "windows nt 5\\.1", "windows nt (5\\.1)"), //
|
||||
new OS("Windows 2000", "windows nt 5\\.0", "windows nt (5\\.0)"), //
|
||||
new OS("Windows Phone", "windows (ce|phone|mobile)( os)?", "windows (?:ce|phone|mobile) (\\d+([._]\\d+)*)"), //
|
||||
new OS("Windows", "windows"), //
|
||||
new OS("OSX", "os x (\\d+)[._](\\d+)", "os x (\\d+([._]\\d+)*)"), //
|
||||
new OS("Android", "Android", "Android (\\d+([._]\\d+)*)"),//
|
||||
new OS("Harmony", "OpenHarmony", "OpenHarmony (\\d+([._]\\d+)*)"), //
|
||||
new OS("Android", "XiaoMi|MI\\s+", "\\(X(\\d+([._]\\d+)*)"),//
|
||||
new OS("Linux", "linux"), //
|
||||
new OS("Wii", "wii", "wii libnup/(\\d+([._]\\d+)*)"), //
|
||||
new OS("PS3", "playstation 3", "playstation 3; (\\d+([._]\\d+)*)"), //
|
||||
new OS("PSP", "playstation portable", "Portable\\); (\\d+([._]\\d+)*)"), //
|
||||
new OS("iPad", "\\(iPad.*os (\\d+)[._](\\d+)", "\\(iPad.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("iPhone", "\\(iPhone.*os (\\d+)[._](\\d+)", "\\(iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("YPod", "iPod touch[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPod touch[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("YPad", "iPad[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPad[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("YPhone", "iPhone[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPhone[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||
new OS("Symbian", "symbian(os)?"), //
|
||||
new OS("Darwin", "Darwin\\/([\\d\\w\\.\\-]+)", "Darwin\\/([\\d\\w\\.\\-]+)"), //
|
||||
new OS("Adobe Air", "AdobeAir\\/([\\d\\w\\.\\-]+)", "AdobeAir\\/([\\d\\w\\.\\-]+)"), //
|
||||
new OS("Java", "Java[\\s]+([\\d\\w\\.\\-]+)", "Java[\\s]+([\\d\\w\\.\\-]+)")//
|
||||
);
|
||||
|
||||
/**
|
||||
@ -114,7 +115,7 @@ public class OS extends UserAgentInfo {
|
||||
* @return 版本
|
||||
*/
|
||||
public String getVersion(final String userAgentString) {
|
||||
if(isUnknown() || null == this.versionPattern){
|
||||
if (isUnknown() || null == this.versionPattern) {
|
||||
// 无版本信息
|
||||
return null;
|
||||
}
|
||||
@ -127,7 +128,7 @@ public class OS extends UserAgentInfo {
|
||||
* @return 是否为MacOS
|
||||
* @since 5.8.29
|
||||
*/
|
||||
public boolean isMacOS(){
|
||||
public boolean isMacOS() {
|
||||
return "OSX".equals(getName());
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,10 @@ public class Platform extends UserAgentInfo {
|
||||
* android
|
||||
*/
|
||||
public static final Platform ANDROID = new Platform("Android", "android");
|
||||
/**
|
||||
* harmony
|
||||
*/
|
||||
public static final Platform HARMONY = new Platform("Harmony", "OpenHarmony");
|
||||
/**
|
||||
* android
|
||||
*/
|
||||
@ -66,28 +70,29 @@ public class Platform extends UserAgentInfo {
|
||||
* 支持的移动平台类型
|
||||
*/
|
||||
public static final List<Platform> mobilePlatforms = ListUtil.view(//
|
||||
WINDOWS_PHONE, //
|
||||
IPAD, //
|
||||
IPOD, //
|
||||
IPHONE, //
|
||||
new Platform("Android", "XiaoMi|MI\\s+"), //
|
||||
ANDROID, //
|
||||
GOOGLE_TV, //
|
||||
new Platform("htcFlyer", "htc_flyer"), //
|
||||
new Platform("Symbian", "symbian(os)?"), //
|
||||
new Platform("Blackberry", "blackberry") //
|
||||
WINDOWS_PHONE, //
|
||||
IPAD, //
|
||||
IPOD, //
|
||||
IPHONE, //
|
||||
new Platform("Android", "XiaoMi|MI\\s+"), //
|
||||
ANDROID, //
|
||||
HARMONY, //
|
||||
GOOGLE_TV, //
|
||||
new Platform("htcFlyer", "htc_flyer"), //
|
||||
new Platform("Symbian", "symbian(os)?"), //
|
||||
new Platform("Blackberry", "blackberry") //
|
||||
);
|
||||
|
||||
/**
|
||||
* 支持的桌面平台类型
|
||||
*/
|
||||
public static final List<Platform> desktopPlatforms = ListUtil.view(//
|
||||
new Platform("Windows", "windows"), //
|
||||
new Platform("Mac", "(macintosh|darwin)"), //
|
||||
new Platform("Linux", "linux"), //
|
||||
new Platform("Wii", "wii"), //
|
||||
new Platform("Playstation", "playstation"), //
|
||||
new Platform("Java", "java") //
|
||||
new Platform("Windows", "windows"), //
|
||||
new Platform("Mac", "(macintosh|darwin)"), //
|
||||
new Platform("Linux", "linux"), //
|
||||
new Platform("Wii", "wii"), //
|
||||
new Platform("Playstation", "playstation"), //
|
||||
new Platform("Java", "java") //
|
||||
);
|
||||
|
||||
/**
|
||||
@ -160,4 +165,13 @@ public class Platform extends UserAgentInfo {
|
||||
return this.equals(ANDROID) || this.equals(GOOGLE_TV);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为Harmony平台
|
||||
*
|
||||
* @return 是否为Harmony平台
|
||||
*/
|
||||
public boolean isHarmony() {
|
||||
return this.equals(HARMONY);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -505,4 +505,15 @@ public class UserAgentUtilTest {
|
||||
assertEquals("Mac", ua.getPlatform().toString());
|
||||
assertFalse(ua.isMobile());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseHarmonyUATest() {
|
||||
final String uaStr = "Mozilla/5.0 (Phone; OpenHarmony 4.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ArkWeb/4.1.6.1 Mobile ";
|
||||
final UserAgent ua = UserAgentUtil.parse(uaStr);
|
||||
assertEquals("Harmony", ua.getPlatform().toString());
|
||||
assertTrue(ua.getPlatform().isHarmony());
|
||||
assertEquals("Harmony", ua.getOs().toString());
|
||||
assertEquals("4.1", ua.getOsVersion());
|
||||
assertTrue(ua.isMobile());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user