diff --git a/pom.xml b/pom.xml old mode 100644 new mode 100755 index 28408fb8..ff6c23ee --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ io.github.soniccloudorg sonic-driver-core - 1.1.24 + 1.1.25 net.coobird diff --git a/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandler.java b/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandler.java index 8c207ff6..d12cf02b 100755 --- a/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandler.java +++ b/src/main/java/org/cloud/sonic/agent/tests/handlers/AndroidTouchHandler.java @@ -23,7 +23,10 @@ import org.cloud.sonic.agent.bridge.android.AndroidDeviceBridgeTool; import org.cloud.sonic.agent.common.enums.AndroidKey; import org.cloud.sonic.agent.common.maps.AndroidDeviceManagerMap; +import org.cloud.sonic.agent.common.maps.HandlerMap; import org.cloud.sonic.agent.tools.PortTool; +import org.cloud.sonic.driver.android.AndroidDriver; +import org.cloud.sonic.driver.common.tool.SonicRespException; import java.io.IOException; import java.io.OutputStream; @@ -45,7 +48,7 @@ public class AndroidTouchHandler { public enum TouchMode { SONIC_APK, ADB, - APPIUM_SERVER; + APPIUM_UIAUTOMATOR2_SERVER; } public static void switchTouchMode(IDevice iDevice, TouchMode mode) { @@ -56,7 +59,7 @@ public static TouchMode getTouchMode(IDevice iDevice) { return touchModeMap.get(iDevice.getSerialNumber()) == null ? TouchMode.ADB : touchModeMap.get(iDevice.getSerialNumber()); } - public static void tap(IDevice iDevice, int x, int y) { + public static void tap(IDevice iDevice, int x, int y) throws SonicRespException { switch (getTouchMode(iDevice)) { case SONIC_APK -> { int[] re = transferWithRotation(iDevice, x, y); @@ -69,11 +72,17 @@ public static void tap(IDevice iDevice, int x, int y) { writeToOutputStream(iDevice, "up\n"); } case ADB -> AndroidDeviceBridgeTool.executeCommand(iDevice, String.format("input tap %d %d", x, y)); + case APPIUM_UIAUTOMATOR2_SERVER -> { + AndroidStepHandler curStepHandler = HandlerMap.getAndroidMap().get(iDevice.getSerialNumber()); + if (curStepHandler != null && curStepHandler.getAndroidDriver() != null) { + curStepHandler.getAndroidDriver().tap(x, y); + } + } default -> throw new IllegalStateException("Unexpected value: " + getTouchMode(iDevice)); } } - public static void longPress(IDevice iDevice, int x, int y, int time) { + public static void longPress(IDevice iDevice, int x, int y, int time) throws SonicRespException { switch (getTouchMode(iDevice)) { case SONIC_APK -> { int[] re = transferWithRotation(iDevice, x, y); @@ -85,13 +94,18 @@ public static void longPress(IDevice iDevice, int x, int y, int time) { } writeToOutputStream(iDevice, "up\n"); } - case ADB -> - AndroidDeviceBridgeTool.executeCommand(iDevice, String.format("input swipe %d %d %d %d %d", x, y, x, y, time)); + case ADB -> AndroidDeviceBridgeTool.executeCommand(iDevice, String.format("input swipe %d %d %d %d %d", x, y, x, y, time)); + case APPIUM_UIAUTOMATOR2_SERVER -> { + AndroidStepHandler curStepHandler = HandlerMap.getAndroidMap().get(iDevice.getSerialNumber()); + if (curStepHandler != null && curStepHandler.getAndroidDriver() != null) { + curStepHandler.getAndroidDriver().longPress(x, y, time); + } + } default -> throw new IllegalStateException("Unexpected value: " + getTouchMode(iDevice)); } } - public static void swipe(IDevice iDevice, int x1, int y1, int x2, int y2) { + public static void swipe(IDevice iDevice, int x1, int y1, int x2, int y2) throws SonicRespException { switch (getTouchMode(iDevice)) { case SONIC_APK -> { int[] re1 = transferWithRotation(iDevice, x1, y1); @@ -110,8 +124,13 @@ public static void swipe(IDevice iDevice, int x1, int y1, int x2, int y2) { } writeToOutputStream(iDevice, "up\n"); } - case ADB -> - AndroidDeviceBridgeTool.executeCommand(iDevice, String.format("input swipe %d %d %d %d %d", x1, y1, x2, y2, 300)); + case ADB -> AndroidDeviceBridgeTool.executeCommand(iDevice, String.format("input swipe %d %d %d %d %d", x1, y1, x2, y2, 300)); + case APPIUM_UIAUTOMATOR2_SERVER -> { + AndroidStepHandler curStepHandler = HandlerMap.getAndroidMap().get(iDevice.getSerialNumber()); + if (curStepHandler != null && curStepHandler.getAndroidDriver() != null) { + curStepHandler.getAndroidDriver().swipe(x1, y1, x2, y2); + } + } default -> throw new IllegalStateException("Unexpected value: " + getTouchMode(iDevice)); } } diff --git a/src/main/java/org/cloud/sonic/agent/transport/TransportClient.java b/src/main/java/org/cloud/sonic/agent/transport/TransportClient.java index 24c5aec7..e1a61161 100755 --- a/src/main/java/org/cloud/sonic/agent/transport/TransportClient.java +++ b/src/main/java/org/cloud/sonic/agent/transport/TransportClient.java @@ -194,7 +194,7 @@ public void onMessage(String s) { } if (session.isOpen()) { if (ss.equals("IOSWSServer")) { - IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(session.getUserProperties().get("id").toString()); + IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(udId); if (iosStepHandler != null) { try { iosStepHandler.getIOSDriver().pressButton("home"); @@ -372,7 +372,7 @@ public void onError(Exception e) { private void runAndroidStep(JSONObject jsonObject) { AndroidPasswordMap.getMap().put(jsonObject.getString("udId"), jsonObject.getString("pwd")); - AndroidStepHandler androidStepHandler = HandlerMap.getAndroidMap().get(jsonObject.getString("sessionId")); + AndroidStepHandler androidStepHandler = HandlerMap.getAndroidMap().get(jsonObject.getString("udId")); if (androidStepHandler == null) { return; } @@ -394,7 +394,7 @@ public void run() { * IOS步骤调试 */ private void runIOSStep(JSONObject jsonObject) { - IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(jsonObject.getString("sessionId")); + IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(jsonObject.getString("udId")); if (iosStepHandler == null) { return; } diff --git a/src/main/java/org/cloud/sonic/agent/websockets/AndroidWSServer.java b/src/main/java/org/cloud/sonic/agent/websockets/AndroidWSServer.java index 37a6b107..1b96a2f1 100755 --- a/src/main/java/org/cloud/sonic/agent/websockets/AndroidWSServer.java +++ b/src/main/java/org/cloud/sonic/agent/websockets/AndroidWSServer.java @@ -256,7 +256,7 @@ public void onMessage(String message, Session session) { BytesTool.sendText(session, result.toJSONString()); } case "debug" -> { - AndroidStepHandler androidStepHandler = HandlerMap.getAndroidMap().get(session.getUserProperties().get("id").toString()); + AndroidStepHandler androidStepHandler = HandlerMap.getAndroidMap().get(iDevice.getSerialNumber()); switch (msg.getString("detail")) { case "poco" -> AndroidDeviceThreadPool.cachedThreadPool.execute(() -> { androidStepHandler.startPocoDriver(new HandleContext(), msg.getString("engine"), msg.getInteger("port")); @@ -337,7 +337,7 @@ public void onMessage(String message, Session session) { case "closeDriver" -> { if (androidStepHandler != null && androidStepHandler.getAndroidDriver() != null) { androidStepHandler.closeAndroidDriver(); - HandlerMap.getAndroidMap().remove(session.getUserProperties().get("id").toString()); + HandlerMap.getAndroidMap().remove(iDevice.getSerialNumber()); } } case "tree" -> { @@ -408,7 +408,7 @@ private void openDriver(IDevice iDevice, Session session) { androidStepHandler.startAndroidDriver(iDevice, port); result.put("status", "success"); result.put("port", port); - HandlerMap.getAndroidMap().put(session.getUserProperties().get("id").toString(), androidStepHandler); + HandlerMap.getAndroidMap().put(iDevice.getSerialNumber(), androidStepHandler); } catch (Exception e) { log.error(e.getMessage()); result.put("status", "error"); @@ -428,14 +428,14 @@ private void exit(Session session) { AndroidDeviceLocalStatus.finish(session.getUserProperties().get("udId") + ""); IDevice iDevice = udIdMap.get(session); try { - AndroidStepHandler androidStepHandler = HandlerMap.getAndroidMap().get(session.getUserProperties().get("id").toString()); + AndroidStepHandler androidStepHandler = HandlerMap.getAndroidMap().get(iDevice.getSerialNumber()); if (androidStepHandler != null) { androidStepHandler.closeAndroidDriver(); } } catch (Exception e) { log.info("close driver failed."); } finally { - HandlerMap.getAndroidMap().remove(session.getUserProperties().get("id").toString()); + HandlerMap.getAndroidMap().remove(iDevice.getSerialNumber()); } if (iDevice != null) { AndroidDeviceBridgeTool.clearProxy(iDevice); diff --git a/src/main/java/org/cloud/sonic/agent/websockets/IOSWSServer.java b/src/main/java/org/cloud/sonic/agent/websockets/IOSWSServer.java index 542fd86c..f8c7147d 100755 --- a/src/main/java/org/cloud/sonic/agent/websockets/IOSWSServer.java +++ b/src/main/java/org/cloud/sonic/agent/websockets/IOSWSServer.java @@ -110,7 +110,7 @@ public void onOpen(Session session, @PathParam("key") String secretKey, session.getUserProperties().put("schedule", ScheduleTool.schedule(() -> { log.info("time up!"); if (session.isOpen()) { - IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(session.getUserProperties().get("id").toString()); + IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(udId); if (iosStepHandler != null) { try { iosStepHandler.getIOSDriver().pressButton("home"); @@ -149,7 +149,7 @@ public void onOpen(Session session, @PathParam("key") String secretKey, appiumSettings.put("mjpegScalingFactor", 100); appiumSettings.put("mjpegServerScreenshotQuality", 50); iosStepHandler.appiumSettings(appiumSettings); - HandlerMap.getIOSMap().put(session.getUserProperties().get("id").toString(), iosStepHandler); + HandlerMap.getIOSMap().put(udId, iosStepHandler); } catch (Exception e) { log.error(e.getMessage()); result.put("status", "error"); @@ -190,7 +190,7 @@ public void onMessage(String message, Session session) { String udId = udIdMap.get(session); IOSDeviceThreadPool.cachedThreadPool.execute(() -> { IOSDriver iosDriver = null; - IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(session.getUserProperties().get("id").toString()); + IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(udId); if (iosStepHandler != null && iosStepHandler.getIOSDriver() != null) { iosDriver = iosStepHandler.getIOSDriver(); } @@ -465,14 +465,14 @@ private void exit(Session session) { screenMap.remove(udId); SibTool.stopOrientationWatcher(udId); try { - IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(session.getUserProperties().get("id").toString()); + IOSStepHandler iosStepHandler = HandlerMap.getIOSMap().get(udId); if (iosStepHandler != null) { iosStepHandler.closeIOSDriver(); } } catch (Exception e) { log.info("close driver failed."); } finally { - HandlerMap.getIOSMap().remove(session.getUserProperties().get("id").toString()); + HandlerMap.getIOSMap().remove(udId); } SibTool.stopWebInspector(udId); SibTool.stopPerfmon(udId);