Skip to content

Commit

Permalink
SibTool增加一个方法,用于判断手机ios系统是否>=17
Browse files Browse the repository at this point in the history
  • Loading branch information
caofengbin committed Aug 19, 2024
1 parent 02c5722 commit 2156377
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
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);
}
}

0 comments on commit 2156377

Please sign in to comment.