diff --git a/hutool-http/src/main/java/cn/hutool/http/useragent/OS.java b/hutool-http/src/main/java/cn/hutool/http/useragent/OS.java index 38a956c58..d6f964421 100755 --- a/hutool-http/src/main/java/cn/hutool/http/useragent/OS.java +++ b/hutool-http/src/main/java/cn/hutool/http/useragent/OS.java @@ -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("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+)*)"), // diff --git a/hutool-http/src/main/java/cn/hutool/http/useragent/Platform.java b/hutool-http/src/main/java/cn/hutool/http/useragent/Platform.java index 960ee18f9..17a4380b4 100644 --- a/hutool-http/src/main/java/cn/hutool/http/useragent/Platform.java +++ b/hutool-http/src/main/java/cn/hutool/http/useragent/Platform.java @@ -36,6 +36,11 @@ 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 */ @@ -59,7 +64,8 @@ public class Platform extends UserAgentInfo { GOOGLE_TV, // new Platform("htcFlyer", "htc_flyer"), // new Platform("Symbian", "symbian(os)?"), // - new Platform("Blackberry", "blackberry") // + new Platform("Blackberry", "blackberry"), // + HARMONY ); /** @@ -144,4 +150,13 @@ public class Platform extends UserAgentInfo { return this.equals(ANDROID) || this.equals(GOOGLE_TV); } + /** + * 是否为Harmony平台 + * + * @return 是否为Harmony平台 + */ + public boolean isHarmony() { + return this.equals(HARMONY); + } + } diff --git a/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java b/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java index 323948308..700177e64 100644 --- a/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java +++ b/hutool-http/src/test/java/cn/hutool/http/useragent/UserAgentUtilTest.java @@ -413,6 +413,16 @@ public class UserAgentUtilTest { assertEquals("Linux", ua.getOs().toString()); } + @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()); + } + @Test public void issueI60UOPTest() { final String uaStr = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36 dingtalk-win/1.0.0 nw(0.14.7) DingTalk(6.5.40-Release.9059101) Mojo/1.0.0 Native AppType(release) Channel/201200";