Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【feature】SibTool增加一个方法,用于判断手机ios系统是否>=17 #458

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.cloud.sonic.agent.bridge.ios;

/**
* Created by fengbincao on 2024/08/19
*/
public class CompareVersionUtil {

/**
* 比较版本号的大小,前者大则返回一个正数,后者大返回一个负数,相等则返回0
*
* @param version1 第一个版本号
* @param version2 第二个版本号
* @return 前者大则返回一个正数, 后者大返回一个负数, 相等则返回0
*/
public static int compareVersion(String version1, String version2) {
String[] v1 = version1.split("\\."), v2 = version2.split("\\.");
int index = 0;
for (; index < v1.length && index < v2.length; index++) {
int v1n = Integer.parseInt(v1[index]), v2n = Integer.parseInt(v2[index]);
if (v1n > v2n) return 1;
if (v1n < v2n) return -1;
}
if (index < v1.length) {
for (; index < v1.length; index++) {
int v1n = Integer.parseInt(v1[index]);
if (v1n > 0) return 1;
}
}
if (index < v2.length) {
for (; index < v2.length; index++) {
int v2n = Integer.parseInt(v2[index]);
if (v2n > 0) return -1;
}
}
return 0;
}
}
10 changes: 10 additions & 0 deletions src/main/java/org/cloud/sonic/agent/bridge/ios/SibTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -1005,4 +1005,14 @@ public static void startShare(String udId, int port) {
e.printStackTrace();
}
}

public static boolean isUpperThanIos17(String udId) {
JSONObject deviceInfoObj = IOSInfoMap.getDetailMap().get(udId);
if (deviceInfoObj != null && deviceInfoObj.containsKey("productVersion")) {
String productVersion = deviceInfoObj.getString("productVersion");
return CompareVersionUtil.compareVersion(productVersion, "17.0") >= 0;
}
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.cloud.sonic.agent.bridge.ios;

import org.junit.Assert;
import org.junit.Test;

import static org.junit.Assert.*;

/**
* Created by fengbincao on 2024/08/19
*/
public class CompareVersionUtilTest {
@Test
public void compareVersion1() {
String version1 = "17.1.0";
String version2 = "17.0.0";
Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) > 0);
}

@Test
public void compareVersion2() {
String version1 = "17.1.0";
String version2 = "17";
Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) > 0);
}

@Test
public void compareVersion3() {
String version1 = "17.1";
String version2 = "17.0";
Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) > 0);
}

@Test
public void compareVersion4() {
String version1 = "17.0.0";
String version2 = "17";
assertEquals(0, CompareVersionUtil.compareVersion(version1, version2));
}

@Test
public void compareVersion5() {
String version1 = "16.8";
String version2 = "17.0";
Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) < 0);
}

@Test
public void compareVersion6() {
String version1 = "16";
String version2 = "17";
Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) < 0);
}

@Test
public void compareVersion7() {
String version1 = "18.0.1";
String version2 = "17.0";
Assert.assertTrue(CompareVersionUtil.compareVersion(version1, version2) > 0);
}
}
Loading