mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +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(//
|
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 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.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 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 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 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 2003", "windows nt 5\\.2", "windows nt (5\\.2)"), //
|
||||||
new OS("Windows XP", "windows nt 5\\.1", "windows nt (5\\.1)"), //
|
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 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 Phone", "windows (ce|phone|mobile)( os)?", "windows (?:ce|phone|mobile) (\\d+([._]\\d+)*)"), //
|
||||||
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", "XiaoMi|MI\\s+", "\\(X(\\d+([._]\\d+)*)"),//
|
new OS("Harmony", "OpenHarmony", "OpenHarmony (\\d+([._]\\d+)*)"), //
|
||||||
new OS("Linux", "linux"), //
|
new OS("Android", "XiaoMi|MI\\s+", "\\(X(\\d+([._]\\d+)*)"),//
|
||||||
new OS("Wii", "wii", "wii libnup/(\\d+([._]\\d+)*)"), //
|
new OS("Linux", "linux"), //
|
||||||
new OS("PS3", "playstation 3", "playstation 3; (\\d+([._]\\d+)*)"), //
|
new OS("Wii", "wii", "wii libnup/(\\d+([._]\\d+)*)"), //
|
||||||
new OS("PSP", "playstation portable", "Portable\\); (\\d+([._]\\d+)*)"), //
|
new OS("PS3", "playstation 3", "playstation 3; (\\d+([._]\\d+)*)"), //
|
||||||
new OS("iPad", "\\(iPad.*os (\\d+)[._](\\d+)", "\\(iPad.*os (\\d+([._]\\d+)*)"), //
|
new OS("PSP", "playstation portable", "Portable\\); (\\d+([._]\\d+)*)"), //
|
||||||
new OS("iPhone", "\\(iPhone.*os (\\d+)[._](\\d+)", "\\(iPhone.*os (\\d+([._]\\d+)*)"), //
|
new OS("iPad", "\\(iPad.*os (\\d+)[._](\\d+)", "\\(iPad.*os (\\d+([._]\\d+)*)"), //
|
||||||
new OS("YPod", "iPod touch[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPod touch[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
new OS("iPhone", "\\(iPhone.*os (\\d+)[._](\\d+)", "\\(iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||||
new OS("YPad", "iPad[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPad[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
new OS("YPod", "iPod touch[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPod touch[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||||
new OS("YPhone", "iPhone[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPhone[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
new OS("YPad", "iPad[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPad[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||||
new OS("Symbian", "symbian(os)?"), //
|
new OS("YPhone", "iPhone[\\s\\;]+iPhone.*os (\\d+)[._](\\d+)", "iPhone[\\s\\;]+iPhone.*os (\\d+([._]\\d+)*)"), //
|
||||||
new OS("Darwin", "Darwin\\/([\\d\\w\\.\\-]+)", "Darwin\\/([\\d\\w\\.\\-]+)"), //
|
new OS("Symbian", "symbian(os)?"), //
|
||||||
new OS("Adobe Air", "AdobeAir\\/([\\d\\w\\.\\-]+)", "AdobeAir\\/([\\d\\w\\.\\-]+)"), //
|
new OS("Darwin", "Darwin\\/([\\d\\w\\.\\-]+)", "Darwin\\/([\\d\\w\\.\\-]+)"), //
|
||||||
new OS("Java", "Java[\\s]+([\\d\\w\\.\\-]+)", "Java[\\s]+([\\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 版本
|
* @return 版本
|
||||||
*/
|
*/
|
||||||
public String getVersion(final String userAgentString) {
|
public String getVersion(final String userAgentString) {
|
||||||
if(isUnknown() || null == this.versionPattern){
|
if (isUnknown() || null == this.versionPattern) {
|
||||||
// 无版本信息
|
// 无版本信息
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -127,7 +128,7 @@ public class OS extends UserAgentInfo {
|
|||||||
* @return 是否为MacOS
|
* @return 是否为MacOS
|
||||||
* @since 5.8.29
|
* @since 5.8.29
|
||||||
*/
|
*/
|
||||||
public boolean isMacOS(){
|
public boolean isMacOS() {
|
||||||
return "OSX".equals(getName());
|
return "OSX".equals(getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,10 @@ public class Platform extends UserAgentInfo {
|
|||||||
* android
|
* android
|
||||||
*/
|
*/
|
||||||
public static final Platform ANDROID = new Platform("Android", "android");
|
public static final Platform ANDROID = new Platform("Android", "android");
|
||||||
|
/**
|
||||||
|
* harmony
|
||||||
|
*/
|
||||||
|
public static final Platform HARMONY = new Platform("Harmony", "OpenHarmony");
|
||||||
/**
|
/**
|
||||||
* android
|
* android
|
||||||
*/
|
*/
|
||||||
@ -66,28 +70,29 @@ public class Platform extends UserAgentInfo {
|
|||||||
* 支持的移动平台类型
|
* 支持的移动平台类型
|
||||||
*/
|
*/
|
||||||
public static final List<Platform> mobilePlatforms = ListUtil.view(//
|
public static final List<Platform> mobilePlatforms = ListUtil.view(//
|
||||||
WINDOWS_PHONE, //
|
WINDOWS_PHONE, //
|
||||||
IPAD, //
|
IPAD, //
|
||||||
IPOD, //
|
IPOD, //
|
||||||
IPHONE, //
|
IPHONE, //
|
||||||
new Platform("Android", "XiaoMi|MI\\s+"), //
|
new Platform("Android", "XiaoMi|MI\\s+"), //
|
||||||
ANDROID, //
|
ANDROID, //
|
||||||
GOOGLE_TV, //
|
HARMONY, //
|
||||||
new Platform("htcFlyer", "htc_flyer"), //
|
GOOGLE_TV, //
|
||||||
new Platform("Symbian", "symbian(os)?"), //
|
new Platform("htcFlyer", "htc_flyer"), //
|
||||||
new Platform("Blackberry", "blackberry") //
|
new Platform("Symbian", "symbian(os)?"), //
|
||||||
|
new Platform("Blackberry", "blackberry") //
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支持的桌面平台类型
|
* 支持的桌面平台类型
|
||||||
*/
|
*/
|
||||||
public static final List<Platform> desktopPlatforms = ListUtil.view(//
|
public static final List<Platform> desktopPlatforms = ListUtil.view(//
|
||||||
new Platform("Windows", "windows"), //
|
new Platform("Windows", "windows"), //
|
||||||
new Platform("Mac", "(macintosh|darwin)"), //
|
new Platform("Mac", "(macintosh|darwin)"), //
|
||||||
new Platform("Linux", "linux"), //
|
new Platform("Linux", "linux"), //
|
||||||
new Platform("Wii", "wii"), //
|
new Platform("Wii", "wii"), //
|
||||||
new Platform("Playstation", "playstation"), //
|
new Platform("Playstation", "playstation"), //
|
||||||
new Platform("Java", "java") //
|
new Platform("Java", "java") //
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,4 +165,13 @@ public class Platform extends UserAgentInfo {
|
|||||||
return this.equals(ANDROID) || this.equals(GOOGLE_TV);
|
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());
|
assertEquals("Mac", ua.getPlatform().toString());
|
||||||
assertFalse(ua.isMobile());
|
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