Skip to content

Commit

Permalink
添加对手表、电视等传输效率低下导致超时的处理方法
Browse files Browse the repository at this point in the history
  • Loading branch information
harry committed Jun 17, 2017
1 parent 2294e0d commit ace27d0
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 7 deletions.
53 changes: 50 additions & 3 deletions src/main/java/com/yeetor/adb/AdbServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,58 @@ public static String executeShellCommand(IDevice device, String command) {
/**
* TODO: 添加自定义adb命令,原因是安卓手表的传输速度太慢,导致adb push超时错误
* @param device
* @param command
* @return
*/
public static String executeCommand(IDevice device, String command) {
return "";
public String executePushFile(IDevice device, String src, String dst) {
final File adbFile = new File(AdbServer.server().adbPath);
final SettableFuture future = SettableFuture.create();
(new Thread(new Runnable() {
public void run() {
ProcessBuilder pb = new ProcessBuilder(new String[]{adbFile.getPath(), "push", src, dst});
pb.redirectErrorStream(true);
Process p = null;

try {
p = pb.start();
} catch (IOException e) {
future.setException(e);
return;
}

StringBuilder sb = new StringBuilder();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));

try {
String line;
try {
while((line = br.readLine()) != null) {
sb.append(line);
}
future.set(sb.toString());
return;
} catch (IOException ex) {
future.setException(ex);
return;
}
} finally {
try {
br.close();
} catch (IOException ex) {
future.setException(ex);
}

}
}
}, "Obtaining adb version")).start();

String s = "";

try {
s = (String) future.get(30, TimeUnit.SECONDS);
} catch (Exception e) {
return null;
}
return s;
}

private ListenableFuture<List<AdbForward>> executeGetForwardList() {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/yeetor/engine/EngineDevice.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.android.ddmlib.IDevice;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.sun.org.apache.xpath.internal.operations.Bool;
import com.yeetor.adb.AdbServer;
import com.yeetor.minitouch.Minitouch;
import com.yeetor.minitouch.MinitouchListener;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/yeetor/minicap/Minicap.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void installMinicap(IDevice device) throws MinicapInstallException
throw new MinicapInstallException("File: " + minicap_bin.getAbsolutePath() + " not exists!");
}
try {
device.pushFile(minicap_bin.getAbsolutePath(), REMOTE_PATH + "/" + MINICAP_BIN);
AdbServer.server().executePushFile(device, minicap_bin.getAbsolutePath(), REMOTE_PATH + "/" + MINICAP_BIN);
} catch (Exception e) {
throw new MinicapInstallException(e.getMessage());
}
Expand All @@ -81,7 +81,7 @@ public static void installMinicap(IDevice device) throws MinicapInstallException
}

try {
device.pushFile(minicap_so.getAbsolutePath(), REMOTE_PATH + "/" + MINICAP_SO);
AdbServer.server().executePushFile(device, minicap_so.getAbsolutePath(), REMOTE_PATH + "/" + MINICAP_SO);
} catch (Exception e) {
throw new MinicapInstallException(e.getMessage());
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/yeetor/minitouch/Minitouch.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void installMinitouch(IDevice device) throws MinitouchInstallExcep
throw new MinitouchInstallException("File: " + minitouch_bin.getAbsolutePath() + " not exists!");
}
try {
device.pushFile(minitouch_bin.getAbsolutePath(), REMOTE_PATH + "/" + MINITOUCH_BIN);
AdbServer.server().executePushFile(device, minitouch_bin.getAbsolutePath(), REMOTE_PATH + "/" + MINITOUCH_BIN);
} catch (Exception e) {
throw new MinitouchInstallException(e.getMessage());
}
Expand Down Expand Up @@ -112,6 +112,7 @@ public void start() {
String command = "/data/local/tmp/minitouch" + " -n " + forward.getLocalabstract();
minitouchThread = startMinitouchThread(command);
minitouchInitialThread = startInitialThread("127.0.0.1", forward.getPort());
System.out.println(command);
}

public void kill() {
Expand Down

0 comments on commit ace27d0

Please sign in to comment.