点击、滑动、点击home键之后获取一次ui节点

master
yineng.huang 2024-07-11 18:48:23 +08:00
parent 5bcb914139
commit e38f18a050
2 changed files with 63 additions and 23 deletions

View File

@ -24,7 +24,11 @@ public class GetNodeTreeThread extends Thread {
private CmdRequest request; private CmdRequest request;
private boolean keepPushNode = false; private boolean keepPushNode = true; //前端是否打开了获取ui节点
private boolean gettingNode = false; //正在获取ui树
private boolean longTimeGetNode = false; //是否长时间没有点击等操作,一直获取
private final Object lock = new Object(); private final Object lock = new Object();
@ -41,29 +45,39 @@ public class GetNodeTreeThread extends Thread {
public void run() { public void run() {
logger.info("开始获取设备【{}】的节点............................", deviceId); logger.info("开始获取设备【{}】的节点............................", deviceId);
while (!isInterrupted()) { while (!isInterrupted()) {
try { if (keepPushNode) {
Thread.sleep(1000); try {
} catch (InterruptedException e) { gettingNode = true; //正在获取uiNode
interrupt(); IosDeviceInitThread iosInitThread = IOSDeviceManager.getInstance().getIosInitThread(deviceId);
break; if (null == iosInitThread || iosInitThread.isInterrupted() || !iosInitThread.isAlive()) {
} logger.debug("设备【{}】掉线了,等一下,不要急........................", deviceId);
try { break;
IosDeviceInitThread iosInitThread = IOSDeviceManager.getInstance().getIosInitThread(deviceId); }
if (null == iosInitThread || iosInitThread.isInterrupted() || !iosInitThread.isAlive()) { UiNodeData uiNodeData = iosInitThread.getNkAgent().uiTreeNode();
logger.debug("设备【{}】掉线了,等一下,不要急........................", deviceId); logger.debug("获取结束nodeData空{}", uiNodeData == null);
continue; gettingNode = false; //uiNode获取完毕
SessionUtils.sendContinuousData(session, request, uiNodeData, "获取节点树成功");
} catch (IllegalStateException e) {
logger.warn("webSession已经关闭",e);
break;
} catch (Exception e) {
logger.warn("设备【{}】获取节点出了点问题,但是不影响,继续", deviceId, e);
} }
logger.debug("开始获取......"); synchronized (lock) {
UiNodeData uiNodeData = iosInitThread.getNkAgent().uiTreeNode(); logger.warn("设备【{}】等待下一次获取node节点.....................", deviceId);
logger.debug("获取结束nodeData空{}", uiNodeData == null); try {
SessionUtils.sendContinuousData(session, request, uiNodeData, "获取节点树成功"); if (longTimeGetNode) {
} catch (IllegalStateException e) { lock.wait(5*1000);
logger.warn("webSession已经关闭",e); } else {
break; lock.wait(2*1000);
} catch (Exception e) { longTimeGetNode = true;
logger.warn("设备【{}】获取节点出了点问题,但是不影响,继续", deviceId, e); }
} } catch (InterruptedException e) {
if (!keepPushNode) { interrupt();
break;
}
}
} else {
synchronized (lock) { synchronized (lock) {
logger.warn("设备【{}】等待获取node节点.....................", deviceId); logger.warn("设备【{}】等待获取node节点.....................", deviceId);
try { try {
@ -96,6 +110,8 @@ public class GetNodeTreeThread extends Thread {
public void startGetNodeTree(CmdRequest request) { public void startGetNodeTree(CmdRequest request) {
this.request = request; this.request = request;
this.keepPushNode = true; this.keepPushNode = true;
this.gettingNode = false;
this.longTimeGetNode = false;
synchronized (lock) { synchronized (lock) {
logger.debug("设备【{}】开始获取节点树...................", deviceId); logger.debug("设备【{}】开始获取节点树...................", deviceId);
lock.notify(); lock.notify();
@ -106,4 +122,20 @@ public class GetNodeTreeThread extends Thread {
public void exitGetNodeTree() { public void exitGetNodeTree() {
interrupt(); interrupt();
} }
public void getOnceNodeTree() {
longTimeGetNode = false;
if (keepPushNode) {
if (gettingNode) {
logger.warn("设备【{}】正在获取uiNode.............", deviceId);
} else {
synchronized (lock) {
logger.debug("设备【{}】操作了,获取一次节点树...................", deviceId);
lock.notify();
}
}
} else {
logger.warn("设备【{}】前端已经关闭了uiNode无需获取.............", deviceId);
}
}
} }

View File

@ -615,6 +615,10 @@ public class IosWindowsAndLinuxMessageHandlerThread extends AbstractIosMessageHa
SessionUtils.sendFailureMessage(session, request, "热键[" + key + "]不存在"); SessionUtils.sendFailureMessage(session, request, "热键[" + key + "]不存在");
return; return;
} }
if (null != nodeTreeThread && nodeTreeThread.isAlive()) {
logger.debug("手机【{}】操作了一次,准备获取node节点.................", phoneEntity.getUdid());
nodeTreeThread.getOnceNodeTree();
}
SessionUtils.sendSuccessData(session, request, null, "热键处理成功"); SessionUtils.sendSuccessData(session, request, null, "热键处理成功");
} }
@ -654,6 +658,10 @@ public class IosWindowsAndLinuxMessageHandlerThread extends AbstractIosMessageHa
handleWatch.reset(); handleWatch.reset();
} }
logger.debug("抬起实际位置x:{},y:{}", point.getX(), point.getY()); logger.debug("抬起实际位置x:{},y:{}", point.getX(), point.getY());
if (null != nodeTreeThread && nodeTreeThread.isAlive()) {
logger.debug("手机【{}】操作了一次,准备获取node节点.................", phoneEntity.getUdid());
nodeTreeThread.getOnceNodeTree();
}
SessionUtils.sendSuccessData(session, request, null, "抬起成功"); SessionUtils.sendSuccessData(session, request, null, "抬起成功");
} }