Skip to content

Commit ade0e79

Browse files
author
harry
committed
忘记提交了
1 parent 1bc6a8b commit ade0e79

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

src/main/java/com/yeetor/androidcontrol/client/LocalClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.android.ddmlib.IDevice;
3030
import com.android.ddmlib.SyncException;
3131
import com.android.ddmlib.TimeoutException;
32+
import com.yeetor.adb.AdbDevice;
3233
import com.yeetor.adb.AdbServer;
3334
import com.yeetor.androidcontrol.Command;
3435
import com.yeetor.androidcontrol.Protocol;
@@ -227,9 +228,9 @@ private void pushCommand(Command command) {
227228
String name = command.getString("name", null);
228229
String path = command.getString("path", null);
229230

230-
IDevice device = AdbServer.server().getDevice(protocol.getSn());
231+
AdbDevice device = AdbServer.server().getDevice(protocol.getSn());
231232
try {
232-
device.pushFile(Constant.getTmpFile(name).getAbsolutePath(), path + "/" + name);
233+
device.getIDevice().pushFile(Constant.getTmpFile(name).getAbsolutePath(), path + "/" + name);
233234
} catch (Exception e) {
234235
}
235236
if (protocol != null) {

src/main/java/com/yeetor/androidcontrol/client/RemoteClient.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.alibaba.fastjson.JSONObject;
2828
import com.android.ddmlib.IDevice;
2929
import com.neovisionaries.ws.client.*;
30+
import com.yeetor.adb.AdbDevice;
3031
import com.yeetor.adb.AdbServer;
3132
import com.yeetor.androidcontrol.Command;
3233
import com.yeetor.androidcontrol.message.BinaryMessage;
@@ -73,10 +74,10 @@ public RemoteClient(String ip, int port, String key, String serialNumber) throws
7374
this.key = key;
7475
this.serialNumber = serialNumber;
7576
if (serialNumber == null || serialNumber.isEmpty()) {
76-
IDevice device = AdbServer.server().getFirstDevice();
77+
AdbDevice device = AdbServer.server().getFirstDevice();
7778
if (device == null)
7879
throw new RuntimeException("未找到设备!");
79-
this.serialNumber = device.getSerialNumber();
80+
this.serialNumber = device.getIDevice().getSerialNumber();
8081
}
8182

8283
ws = new WebSocketFactory().createSocket("ws://" + ip + ":" + port);
@@ -236,9 +237,9 @@ private void pushCommand(Command command) {
236237
String name = command.getString("name", null);
237238
String path = command.getString("path", null);
238239

239-
IDevice device = AdbServer.server().getDevice(serialNumber);
240+
AdbDevice device = AdbServer.server().getDevice(serialNumber);
240241
try {
241-
device.pushFile(Constant.getTmpFile(name).getAbsolutePath(), path + "/" + name);
242+
device.getIDevice().pushFile(Constant.getTmpFile(name).getAbsolutePath(), path + "/" + name);
242243
} catch (Exception e) {
243244
}
244245
ws.sendText("message://pushfile success");

src/main/java/com/yeetor/androidcontrol/server/BaseServer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.alibaba.fastjson.JSON;
2828
import com.android.ddmlib.IDevice;
29+
import com.yeetor.adb.AdbDevice;
2930
import com.yeetor.adb.AdbServer;
3031
import com.yeetor.androidcontrol.DeviceInfo;
3132

@@ -41,9 +42,8 @@ public class BaseServer {
4142
* @return
4243
*/
4344
public String getDevicesJSON() {
44-
IDevice[] devices = AdbServer.server().getDevices();
4545
ArrayList<DeviceInfo> list = new ArrayList<DeviceInfo>();
46-
for (IDevice device : devices) {
46+
for (AdbDevice device : AdbServer.server().getDevices()) {
4747
list.add(new DeviceInfo(device)); // TODO 耗时长,需优化
4848
}
4949
return JSON.toJSONString(list);

src/main/java/com/yeetor/androidcontrol/server/LocalServer.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.alibaba.fastjson.JSONObject;
2828
import com.android.ddmlib.IDevice;
29+
import com.yeetor.adb.AdbDevice;
2930
import com.yeetor.adb.AdbServer;
3031
import com.yeetor.androidcontrol.*;
3132
import com.yeetor.androidcontrol.client.LocalClient;
@@ -43,6 +44,7 @@
4344
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
4445
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
4546
import org.apache.commons.lang3.StringUtils;
47+
import org.apache.log4j.Logger;
4648

4749
import java.io.File;
4850
import java.io.FileNotFoundException;
@@ -56,7 +58,8 @@
5658
* Created by harry on 2017/4/18.
5759
*/
5860
public class LocalServer extends BaseServer {
59-
61+
private static Logger logger = Logger.getLogger(LocalServer.class);
62+
6063
private int port = -1;
6164
List<Protocol> protocolList;
6265

@@ -115,7 +118,7 @@ public void onTextMessage(ChannelHandlerContext ctx, String text) {
115118
if (command.getSchem() != Command.Schem.WAITTING &&
116119
command.getSchem() != Command.Schem.INPUT &&
117120
command.getSchem() != Command.Schem.KEYEVENT) {
118-
System.out.println(command.getCommandString());
121+
logger.info(command.getCommandString());
119122
}
120123
if (command != null) {
121124
switch (command.getSchem()) {
@@ -186,12 +189,12 @@ void initLocalClient(final ChannelHandlerContext ctx, Command command) {
186189

187190
// 没有sn,默认第一个设备
188191
if (StringUtils.isEmpty(sn)) {
189-
IDevice iDevice = AdbServer.server().getFirstDevice();
192+
AdbDevice iDevice = AdbServer.server().getFirstDevice();
190193
if (iDevice == null) {
191194
ctx.channel().close();
192195
return;
193196
}
194-
sn = iDevice.getSerialNumber();
197+
sn = iDevice.getIDevice().getSerialNumber();
195198
}
196199

197200
JSONObject obj = new JSONObject();

src/main/java/com/yeetor/engine/EngineDevice.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.android.ddmlib.IDevice;
2828
import com.google.common.util.concurrent.ListenableFuture;
2929
import com.google.common.util.concurrent.SettableFuture;
30+
import com.yeetor.adb.AdbDevice;
3031
import com.yeetor.adb.AdbServer;
3132
import com.yeetor.minitouch.Minitouch;
3233
import com.yeetor.minitouch.MinitouchListener;
@@ -38,12 +39,12 @@
3839
*/
3940
public class EngineDevice {
4041

41-
private IDevice iDevice;
42+
private AdbDevice device;
4243
private Minitouch minitouch;
4344
private boolean minitouchOpen = false;
4445

4546
public static EngineDevice getDevice(String serialNumber) {
46-
IDevice iDevice = AdbServer.server().getDevice(serialNumber);
47+
AdbDevice iDevice = AdbServer.server().getDevice(serialNumber);
4748
if (iDevice != null) {
4849
EngineDevice device = new EngineDevice(iDevice);
4950
if (device.isMinitouchOpen()) {
@@ -53,8 +54,8 @@ public static EngineDevice getDevice(String serialNumber) {
5354
return null;
5455
}
5556

56-
public EngineDevice(IDevice iDevice) {
57-
this.iDevice = iDevice;
57+
public EngineDevice(AdbDevice iDevice) {
58+
this.device = iDevice;
5859
minitouch = new Minitouch(iDevice);
5960
SettableFuture future = SettableFuture.create();
6061

@@ -102,11 +103,11 @@ public void touchUp() {
102103
}
103104

104105
public String executeShellAndGetString(String command) {
105-
return AdbServer.executeShellCommand(iDevice, command);
106+
return AdbServer.executeShellCommand(device.getIDevice(), command);
106107
}
107108

108109
public void startApp(String str) {
109-
AdbServer.executeShellCommand(iDevice, "am start " + str);
110+
AdbServer.executeShellCommand(device.getIDevice(), "am start " + str);
110111
}
111112

112113
}

0 commit comments

Comments
 (0)