截图改为wda截图
parent
8551afb5cf
commit
fe7f1cda9e
|
@ -250,6 +250,33 @@ public final class NKAgent {
|
||||||
return bool.isSuccess();
|
return bool.isSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动app
|
||||||
|
* @param string bundleId
|
||||||
|
* @return 是否设置成功
|
||||||
|
*/
|
||||||
|
public boolean launchApp(String string) {
|
||||||
|
if (string.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("bundleId不能为空");
|
||||||
|
}
|
||||||
|
TextData data = new TextData();
|
||||||
|
data.setText(string);
|
||||||
|
ICommandPacket packet = packetTransfer.syncSend(32, data);
|
||||||
|
if (packet == null) return false;
|
||||||
|
BooleanCommandData bool = new BooleanCommandData();
|
||||||
|
packet.fillICommandData(bool);
|
||||||
|
return bool.isSuccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ScreenShotData screenShot() {
|
||||||
|
ICommandPacket packet = packetTransfer.syncSend(33);
|
||||||
|
if (packet == null) return null;
|
||||||
|
ScreenShotData screenShotData = new ScreenShotData();
|
||||||
|
packet.fillICommandData(screenShotData);
|
||||||
|
return screenShotData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public boolean getStatus() {
|
public boolean getStatus() {
|
||||||
return this.packetTransfer.isConnected();
|
return this.packetTransfer.isConnected();
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package net.northking.cctp.upperComputer.driver.ios.command.data;
|
||||||
|
|
||||||
|
|
||||||
|
import net.northking.cctp.upperComputer.driver.ios.packet.ICommandData;
|
||||||
|
|
||||||
|
import java.io.DataInput;
|
||||||
|
import java.io.DataOutput;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class ScreenShotData implements ICommandData {
|
||||||
|
public int dataLength;
|
||||||
|
|
||||||
|
public byte[] data;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void buildFromInput(DataInput dataInput) throws IOException {
|
||||||
|
dataLength = dataInput.readInt();
|
||||||
|
data = new byte[dataLength];
|
||||||
|
dataInput.readFully(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void encodeToOutput(DataOutput dataOutput) throws IOException {
|
||||||
|
dataOutput.writeInt(dataLength);
|
||||||
|
dataOutput.write(data);
|
||||||
|
}
|
||||||
|
}
|
|
@ -344,7 +344,7 @@ public class IosDebuggerServiceImpl extends AbstractDebuggerService {
|
||||||
stringBuilder.append(line);
|
stringBuilder.append(line);
|
||||||
}
|
}
|
||||||
String result = stringBuilder.toString();
|
String result = stringBuilder.toString();
|
||||||
if (result.trim().startsWith("Kill pid:")) {
|
if (result.trim().startsWith("Kill pid:") || result.trim().contains("No app killed")) {
|
||||||
logger.debug("手机【{}】应用【{}】已关闭,关闭消息:{}", deviceId, appPackage, result);
|
logger.debug("手机【{}】应用【{}】已关闭,关闭消息:{}", deviceId, appPackage, result);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,14 +2,21 @@ package net.northking.cctp.upperComputer.utils.ios;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.IOSDeviceManager;
|
import net.northking.cctp.upperComputer.deviceManager.IOSDeviceManager;
|
||||||
|
import net.northking.cctp.upperComputer.deviceManager.UpperComputerManager;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.common.PyMobileDevice;
|
import net.northking.cctp.upperComputer.deviceManager.common.PyMobileDevice;
|
||||||
import net.northking.cctp.upperComputer.deviceManager.entity.AppleApplicationInfo;
|
import net.northking.cctp.upperComputer.deviceManager.entity.AppleApplicationInfo;
|
||||||
|
import net.northking.cctp.upperComputer.deviceManager.thread.IosDeviceInitThread;
|
||||||
|
import net.northking.cctp.upperComputer.driver.ios.NKAgent;
|
||||||
|
import net.northking.cctp.upperComputer.driver.ios.command.data.ScreenShotData;
|
||||||
import net.northking.cctp.upperComputer.exception.ExecuteException;
|
import net.northking.cctp.upperComputer.exception.ExecuteException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author : yineng.huang
|
* @author : yineng.huang
|
||||||
|
@ -24,13 +31,13 @@ public class MacIosHandleHelper extends IosDeviceHandleHelper {
|
||||||
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
||||||
HashMap<String, AppleApplicationInfo> appMap = PyMobileDevice.getInstance().listApp(specificAppleDeviceInfo, false, true);
|
HashMap<String, AppleApplicationInfo> appMap = PyMobileDevice.getInstance().listApp(specificAppleDeviceInfo, false, true);
|
||||||
if (null == appMap) {
|
if (null == appMap) {
|
||||||
logger.warn("没有在设备【{}】上找到app【{}】信息",deviceId,appPackage);
|
logger.warn("没有在设备【{}】上找到app【{}】信息", deviceId, appPackage);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean contain = appMap.containsKey(appPackage);
|
boolean contain = appMap.containsKey(appPackage);
|
||||||
if (contain) {
|
if (contain) {
|
||||||
AppleApplicationInfo appleApplicationInfo = appMap.get(appPackage);
|
AppleApplicationInfo appleApplicationInfo = appMap.get(appPackage);
|
||||||
logger.debug("设备【{}】上的app信息:{}",deviceId,JSON.toJSONString(appleApplicationInfo));
|
logger.debug("设备【{}】上的app信息:{}", deviceId, JSON.toJSONString(appleApplicationInfo));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -40,7 +47,7 @@ public class MacIosHandleHelper extends IosDeviceHandleHelper {
|
||||||
public boolean removeApp(String deviceId, String appPackage) {
|
public boolean removeApp(String deviceId, String appPackage) {
|
||||||
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
||||||
boolean success = PyMobileDevice.getInstance().uninstallApp(specificAppleDeviceInfo, appPackage, null);
|
boolean success = PyMobileDevice.getInstance().uninstallApp(specificAppleDeviceInfo, appPackage, null);
|
||||||
logger.debug("设备【{}】卸载app【{}】的结果:{}",deviceId,appPackage,success);
|
logger.debug("设备【{}】卸载app【{}】的结果:{}", deviceId, appPackage, success);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,16 +56,16 @@ public class MacIosHandleHelper extends IosDeviceHandleHelper {
|
||||||
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
||||||
HashMap<String, AppleApplicationInfo> appMap = PyMobileDevice.getInstance().listApp(specificAppleDeviceInfo, false, true);
|
HashMap<String, AppleApplicationInfo> appMap = PyMobileDevice.getInstance().listApp(specificAppleDeviceInfo, false, true);
|
||||||
if (null == appMap) {
|
if (null == appMap) {
|
||||||
logger.warn("没有在设备【{}】上找到app【{}】信息",deviceId,appPackage);
|
logger.warn("没有在设备【{}】上找到app【{}】信息", deviceId, appPackage);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
boolean contain = appMap.containsKey(appPackage);
|
boolean contain = appMap.containsKey(appPackage);
|
||||||
if (contain) {
|
if (contain) {
|
||||||
AppleApplicationInfo appleApplicationInfo = appMap.get(appPackage);
|
AppleApplicationInfo appleApplicationInfo = appMap.get(appPackage);
|
||||||
logger.debug("设备【{}】上的app信息:{}",deviceId,JSON.toJSONString(appleApplicationInfo));
|
logger.debug("设备【{}】上的app信息:{}", deviceId, JSON.toJSONString(appleApplicationInfo));
|
||||||
return appleApplicationInfo.getCFBundleShortVersionString();
|
return appleApplicationInfo.getCFBundleShortVersionString();
|
||||||
} else {
|
} else {
|
||||||
logger.warn("没有在设备【{}】上找到app【{}】信息",deviceId,appPackage);
|
logger.warn("没有在设备【{}】上找到app【{}】信息", deviceId, appPackage);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -67,48 +74,83 @@ public class MacIosHandleHelper extends IosDeviceHandleHelper {
|
||||||
public boolean installApp(String deviceId, String appPath) {
|
public boolean installApp(String deviceId, String appPath) {
|
||||||
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
||||||
boolean success = PyMobileDevice.getInstance().installApp(specificAppleDeviceInfo, appPath, null);
|
boolean success = PyMobileDevice.getInstance().installApp(specificAppleDeviceInfo, appPath, null);
|
||||||
logger.debug("设备【{}】安装app【{}】的结果:{}",deviceId,appPath,success);
|
logger.debug("设备【{}】安装app【{}】的结果:{}", deviceId, appPath, success);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean activateApp(String deviceId, String appPackage) {
|
public boolean activateApp(String deviceId, String appPackage) {
|
||||||
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
||||||
boolean success = PyMobileDevice.getInstance().launchApp(specificAppleDeviceInfo,appPackage);
|
boolean success = PyMobileDevice.getInstance().launchApp(specificAppleDeviceInfo, appPackage);
|
||||||
logger.debug("设备【{}】启动app【{}】的结果:{}",deviceId,appPackage,success);
|
logger.debug("设备【{}】启动app【{}】的结果:{}", deviceId, appPackage, success);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public File getScreenShotFile(String deviceId, Integer startX, Integer startY, Integer cutWidth, Integer cutHeight, Integer screenWidth, Integer screenHeight) {
|
public File getScreenShotFile(String deviceId, Integer startX, Integer startY, Integer cutWidth, Integer cutHeight, Integer screenWidth, Integer screenHeight) {
|
||||||
PyMobileDevice.SpecificAppleDeviceInfo specificAppleDeviceInfo = IOSDeviceManager.getInstance().getSpecificAppleDeviceInfo(deviceId);
|
if (cutWidth <= 0 || cutHeight <= 0) {
|
||||||
File file = null;
|
throw new ExecuteException("截取图片的宽高不满足要求");
|
||||||
File screenShotFile = null;
|
}
|
||||||
try {
|
int screenShotTime = 1;
|
||||||
screenShotFile = PyMobileDevice.getInstance().takeScreenshotSaveAsFile(specificAppleDeviceInfo,System.getProperty("user.dir") + "/tempPic");
|
while (screenShotTime <= 3) {
|
||||||
if (screenShotFile == null) {
|
logger.debug("设备【{}】第{}次截图开始.................", deviceId, screenShotTime);
|
||||||
logger.error("设备【{}】未截出来图...............", deviceId);
|
NKAgent nkAgent = getNkAgent(deviceId);
|
||||||
throw new ExecuteException(String.format("设备【%s】截图失败", deviceId));
|
ScreenShotData screenShotData = nkAgent.screenShot();
|
||||||
} else {
|
logger.debug("设备【{}】第{}次截图的大小:{}", deviceId, screenShotTime, screenShotData.dataLength);
|
||||||
logger.debug("设备【{}】截图的结果:{}",deviceId,screenShotFile.getAbsolutePath());
|
if (screenShotData.dataLength > 0) {
|
||||||
}
|
File file = null;
|
||||||
if (null != startX || null != startY) {
|
File screenShotFile = null;
|
||||||
if (cutWidth <= 0 || cutHeight <= 0) {
|
FileOutputStream fileOutputStream = null;
|
||||||
throw new ExecuteException("截取图片的宽高不满足要求");
|
try {
|
||||||
|
File picDir = new File(UpperComputerManager.getInstance().getApplicationPath() + "/tempPic");
|
||||||
|
if (!picDir.exists()) {
|
||||||
|
picDir.mkdirs();
|
||||||
|
}
|
||||||
|
screenShotFile = new File(picDir.getAbsolutePath() + "/" + UUID.randomUUID() + ".jpg");
|
||||||
|
fileOutputStream = new FileOutputStream(screenShotFile);
|
||||||
|
fileOutputStream.write(screenShotData.data);
|
||||||
|
fileOutputStream.flush();
|
||||||
|
logger.debug("设备【】第{}次截图在磁盘的位置为:{}", deviceId, screenShotTime, screenShotFile.getAbsolutePath());
|
||||||
|
file = cutImageFile(screenShotFile, deviceId, startX, startY, cutWidth, cutHeight, screenWidth, screenHeight);
|
||||||
|
logger.debug("截取出来的图像为:{}", file.getAbsolutePath());
|
||||||
|
return file;
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("截图写入磁盘失败", e);
|
||||||
|
} finally {
|
||||||
|
if (null != fileOutputStream) {
|
||||||
|
try {
|
||||||
|
fileOutputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null != screenShotFile) {
|
||||||
|
//删除
|
||||||
|
}
|
||||||
|
if (null != file) {
|
||||||
|
//删除
|
||||||
|
}
|
||||||
}
|
}
|
||||||
file = cutImageFile(screenShotFile, deviceId, startX, startY, cutWidth, cutHeight, screenWidth, screenHeight);
|
|
||||||
logger.debug("截取出来的图像为:{}", file.getAbsolutePath());
|
|
||||||
} else {
|
|
||||||
file = screenShotFile;
|
|
||||||
}
|
}
|
||||||
} finally {
|
screenShotTime++;
|
||||||
if (null != screenShotFile) {
|
try {
|
||||||
//删除
|
Thread.sleep(2000);
|
||||||
}
|
} catch (InterruptedException e) {
|
||||||
if (null != file) {
|
e.printStackTrace();
|
||||||
//删除
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return file;
|
throw new ExecuteException("设备截图失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue