harmony录制红框时点击不生效
parent
b539f46899
commit
a3330deff9
|
@ -82,4 +82,6 @@ public interface RequestCmd {
|
|||
|
||||
String PERF_STOP = "device_stop_per_data";//结束性能数据
|
||||
|
||||
String TOUCH_CLICK = "touch_click"; //录制开启红框的时候用作点击
|
||||
|
||||
}
|
||||
|
|
|
@ -128,6 +128,30 @@ public class HarmonyDevice implements ICommandData {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击
|
||||
* <br>
|
||||
* 借助shell的实现,用于应对Agent无法准确执行点击效果时
|
||||
*
|
||||
* @param x 屏幕x坐标
|
||||
* @param y 屏幕y坐标
|
||||
* @return 是否执行成功
|
||||
*/
|
||||
public boolean click(int x, int y) {
|
||||
String shellBuilder = "uitest uiInput click " + x + " " + y;
|
||||
String outputText = "";
|
||||
try (HDCSession session = Hdc.getInstance().shell(hdcDevice, shellBuilder)) {
|
||||
outputText = session.readAllLines();
|
||||
log.debug("设备{}点击{},{}输出{}", hdcDevice.getConnectKey(), x, y, outputText);
|
||||
}
|
||||
boolean result = outputText.contains("No Error");
|
||||
if (!result) {
|
||||
log.debug("设备{}点击失败{},{},输出{}", hdcDevice.getConnectKey(), x, y, outputText);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取UI层级树
|
||||
*
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.northking.cctp.upperComputer.webSocket.thread;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import net.northking.cctp.upperComputer.constants.KeyBoardCodeEnum;
|
||||
import net.northking.cctp.upperComputer.deviceManager.IOSDeviceManager;
|
||||
import net.northking.cctp.upperComputer.deviceManager.screen.IosScreenResponseThread;
|
||||
|
@ -76,6 +77,27 @@ public abstract class AbstractIosMessageHandlerThread extends AbstractMessageHan
|
|||
initDeviceRequireParam();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchClick(CmdRequest request) {
|
||||
Map<String, Object> data = request.getData();
|
||||
ParamCheck xCheck = ParamCheck.build().name("x").type("double").withMin(0).withMax(catchParam.getWidth());
|
||||
ParamCheck yCheck = ParamCheck.build().name("y").type("double").withMin(0).withMax(catchParam.getHeight());
|
||||
Map<String, Object> params = null;
|
||||
try {
|
||||
params = checkParam(data, false, xCheck, yCheck);
|
||||
} catch (Exception e) {
|
||||
logger.error("参数校验失败!", e);
|
||||
if (e instanceof ParamMistakeException) {
|
||||
SessionUtils.sendFailureMessage(session, request, e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
Point point = calculatePoint(params);
|
||||
logger.debug("计算后操作的坐标:{}", JSON.toJSONString(point));
|
||||
function.click(point.getX(), point.getY());
|
||||
logger.debug("抬起实际位置x:{},y:{}", point.getX(), point.getY());
|
||||
SessionUtils.sendSuccessData(session, request, null, "抬起成功");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
|
|
|
@ -130,6 +130,8 @@ public abstract class AbstractMessageHandler extends Thread implements MessageHa
|
|||
startPerf(request);
|
||||
} else if (RequestCmd.PERF_STOP.equals(request.getCmd())) { //关闭性能获取
|
||||
stopPerf(request);
|
||||
} else if (RequestCmd.TOUCH_CLICK.equals(request.getCmd())){
|
||||
touchClick(request);
|
||||
} else {
|
||||
logger.warn("未知指令:{}", request.getCmd());
|
||||
SessionUtils.sendFailureMessage(session, request, "未知指令:" + request.getCmd());
|
||||
|
|
|
@ -94,6 +94,35 @@ public class AndroidMessageHandlerThread extends AbstractMessageHandler {
|
|||
initDeviceRequireParam();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchClick(CmdRequest request) {
|
||||
Map<String, Object> data = request.getData();
|
||||
ParamCheck xCheck = ParamCheck.build().name("x").type("double").withMin(0).withMax(catchParam.getWidth());
|
||||
ParamCheck yCheck = ParamCheck.build().name("y").type("double").withMin(0).withMax(catchParam.getHeight());
|
||||
Map<String, Object> params = null;
|
||||
try {
|
||||
params = checkParam(data, false, xCheck, yCheck);
|
||||
} catch (Exception e) {
|
||||
logger.error("参数校验失败!", e);
|
||||
if (e instanceof ParamMistakeException) {
|
||||
SessionUtils.sendFailureMessage(session, request, e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
Point point = calculatePoint(params);
|
||||
MotionEventCommand downCommand = new MotionEventCommand(4098, 0, point.getX(), point.getY());
|
||||
asyncSendCommand(downCommand);
|
||||
try {
|
||||
Thread.sleep(200);
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
MotionEventCommand upDommand = new MotionEventCommand(4098, 1, point.getX(), point.getY());
|
||||
asyncSendCommand(upDommand);
|
||||
SessionUtils.sendSuccessData(session, request, null, "点击成功");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void closeADBDebug(CmdRequest request) {
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.northking.cctp.upperComputer.deviceManager.HarmonyDeviceManager;
|
|||
import net.northking.cctp.upperComputer.deviceManager.screen.HarmonyScreenResponseThread;
|
||||
import net.northking.cctp.upperComputer.deviceManager.thread.HarmonyProvider;
|
||||
import net.northking.cctp.upperComputer.driver.harmony.HarmonyDevice;
|
||||
import net.northking.cctp.upperComputer.driver.harmony.hdc.HDCConnectStatus;
|
||||
import net.northking.cctp.upperComputer.driver.harmony.hdc.HarmonyKeyCode;
|
||||
import net.northking.cctp.upperComputer.driver.harmony.hyppium.data.DisplaySize;
|
||||
import net.northking.cctp.upperComputer.exception.ExecuteException;
|
||||
|
@ -560,6 +561,34 @@ public class HarmonyMessageHandlerThread extends AbstractMessageHandler{
|
|||
logger.info("手机【{}】的实际宽:{}高:{}............................", this.serial,catchParam.getRealWidth(), catchParam.getRealHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void touchClick(CmdRequest request) {
|
||||
Map<String, Object> data = request.getData();
|
||||
ParamCheck xCheck = ParamCheck.build().name("x").type("double").withMin(0).withMax(catchParam.getWidth());
|
||||
ParamCheck yCheck = ParamCheck.build().name("y").type("double").withMin(0).withMax(catchParam.getHeight());
|
||||
Map<String, Object> params = null;
|
||||
try {
|
||||
params = checkParam(data, false, xCheck, yCheck);
|
||||
} catch (Exception e) {
|
||||
logger.error("参数校验失败!", e);
|
||||
if (e instanceof ParamMistakeException) {
|
||||
SessionUtils.sendFailureMessage(session, request, e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
Point point = calculatePoint(params);
|
||||
HarmonyDevice currentDevice = HarmonyDeviceManager.getInstance().getCurrentDevice(serial);
|
||||
if (null == currentDevice || currentDevice.getHdcDevice().getConnectStatus() != HDCConnectStatus.CONNECTED){
|
||||
SessionUtils.sendFailureMessage(session, request, "当前设备已经掉线,请稍后再试");
|
||||
}
|
||||
boolean success = currentDevice.click(point.getX().intValue(), point.getY().intValue());
|
||||
if (success) {
|
||||
SessionUtils.sendSuccessData(session, request, null, "点击成功");
|
||||
} else {
|
||||
logger.warn("设备【{}】抬起失败............................", this.serial);
|
||||
}
|
||||
}
|
||||
|
||||
private HarmonyProvider getHarmonyProvider(){
|
||||
HarmonyProvider provider = HarmonyDeviceManager.getInstance().getCurrentDeviceProvider(this.serial);
|
||||
if (null == provider) {
|
||||
|
|
|
@ -91,6 +91,8 @@ public interface MessageHandler {
|
|||
|
||||
public void getNodeTreeOnce(CmdRequest request);
|
||||
|
||||
public void touchClick(CmdRequest request);
|
||||
|
||||
//掉线相关
|
||||
public void clearAndCloseDeviceAgentConnection(); //断开原有的设备agent的连接
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ public interface MobileConnectionConstants {
|
|||
String CMD_INPUT_TOUCHMOVE = "input_touchMove";
|
||||
//触控-抬起
|
||||
String CMD_INPUT_TOUCHUP = "input_touchUp";
|
||||
//录制时点
|
||||
String CMD_TOUCH_CLICK = "touch_click"; //录制时点击
|
||||
//发送热键
|
||||
String CMD_INPUT_KEYPRESS = "input_keyPress";
|
||||
//键盘按钮按下
|
||||
|
|
|
@ -125,6 +125,9 @@ public class ProcessMsgThread extends Thread{
|
|||
case MobileConnectionConstants.CommandConstants.CMD_DEVICE_NODE:
|
||||
handleMessageForward(msgRequest);
|
||||
break;
|
||||
case MobileConnectionConstants.CommandConstants.CMD_TOUCH_CLICK:
|
||||
handleMessageForward(msgRequest);
|
||||
break;
|
||||
case MobileConnectionConstants.CommandConstants.CMD_DEVICE_EXIT:
|
||||
exitMobile();
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue