使用wda关闭应用

master
yineng.huang 2024-09-27 15:53:37 +08:00
parent fe7f1cda9e
commit 6fb1c8765a
3 changed files with 40 additions and 6 deletions

View File

@ -276,6 +276,23 @@ public final class NKAgent {
return screenShotData;
}
/**
* app
* @param string bundleId
* @return
*/
public boolean terminateApp(String string) {
if (string.isEmpty()) {
throw new IllegalArgumentException("bundleId不能为空");
}
TextData data = new TextData();
data.setText(string);
ICommandPacket packet = packetTransfer.syncSend(34, data);
if (packet == null) return false;
BooleanCommandData bool = new BooleanCommandData();
packet.fillICommandData(bool);
return bool.isSuccess();
}
public boolean getStatus() {

View File

@ -15,13 +15,17 @@ public class ScreenShotData implements ICommandData {
@Override
public void buildFromInput(DataInput dataInput) throws IOException {
dataLength = dataInput.readInt();
data = new byte[dataLength];
dataInput.readFully(data);
if (dataLength > 0) {
data = new byte[dataLength];
dataInput.readFully(data);
}
}
@Override
public void encodeToOutput(DataOutput dataOutput) throws IOException {
dataOutput.writeInt(dataLength);
dataOutput.write(data);
if (dataLength > 0) {
dataOutput.writeInt(dataLength);
dataOutput.write(data);
}
}
}

View File

@ -7,6 +7,8 @@ import io.appium.java_client.AppiumDriver;
import net.northking.cctp.upperComputer.config.MobileProperty;
import net.northking.cctp.upperComputer.deviceManager.common.PyMobileDevice;
import net.northking.cctp.upperComputer.deviceManager.screen.IosScreenResponseThread;
import net.northking.cctp.upperComputer.deviceManager.thread.IosDeviceInitThread;
import net.northking.cctp.upperComputer.driver.ios.NKAgent;
import net.northking.cctp.upperComputer.entity.Attachment;
import net.northking.cctp.upperComputer.entity.DebuggerDeviceInfo;
import net.northking.cctp.upperComputer.entity.PhoneEntity;
@ -323,8 +325,8 @@ public class IosDebuggerServiceImpl extends AbstractDebuggerService {
public boolean terminateApp(String deviceId, String appPackage) {
boolean flag = deviceHandleHelper instanceof MacIosHandleHelper;
if (flag) {
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
boolean killFlag = PyMobileDevice.getInstance().pkill(specificAppleDeviceInfo, appPackage);
NKAgent nkAgent = getNkAgent(deviceId);
boolean killFlag = nkAgent.terminateApp(appPackage);
if (killFlag) {
logger.info("设备{},执行关闭应用 {} 命令成功", deviceId, appPackage);
} else {
@ -382,4 +384,15 @@ public class IosDebuggerServiceImpl extends AbstractDebuggerService {
queryDeviceInfoMap.put(info.getCaseId(), deviceAllInfoThread);
return true;
}
private NKAgent getNkAgent(String deviceId) {
IosDeviceInitThread iosInitThread = IOSDeviceManager.getInstance().getIosInitThread(deviceId);
if (null == iosInitThread || !iosInitThread.isAlive() || iosInitThread.isInterrupted()) {
throw new ExecuteException("设备已经掉线,请重新接入设备");
}
NKAgent nkAgent = iosInitThread.getNkAgent();
if (!nkAgent.getStatus()) {
throw new ExecuteException("设备Agent还未准备好稍后再试");
}
return nkAgent;
}
}