Skip to content

Commit ace27d0

Browse files
author
harry
committed
添加对手表、电视等传输效率低下导致超时的处理方法
1 parent 2294e0d commit ace27d0

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

src/main/java/com/yeetor/adb/AdbServer.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,58 @@ public static String executeShellCommand(IDevice device, String command) {
129129
/**
130130
* TODO: 添加自定义adb命令,原因是安卓手表的传输速度太慢,导致adb push超时错误
131131
* @param device
132-
* @param command
133132
* @return
134133
*/
135-
public static String executeCommand(IDevice device, String command) {
136-
return "";
134+
public String executePushFile(IDevice device, String src, String dst) {
135+
final File adbFile = new File(AdbServer.server().adbPath);
136+
final SettableFuture future = SettableFuture.create();
137+
(new Thread(new Runnable() {
138+
public void run() {
139+
ProcessBuilder pb = new ProcessBuilder(new String[]{adbFile.getPath(), "push", src, dst});
140+
pb.redirectErrorStream(true);
141+
Process p = null;
142+
143+
try {
144+
p = pb.start();
145+
} catch (IOException e) {
146+
future.setException(e);
147+
return;
148+
}
149+
150+
StringBuilder sb = new StringBuilder();
151+
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
152+
153+
try {
154+
String line;
155+
try {
156+
while((line = br.readLine()) != null) {
157+
sb.append(line);
158+
}
159+
future.set(sb.toString());
160+
return;
161+
} catch (IOException ex) {
162+
future.setException(ex);
163+
return;
164+
}
165+
} finally {
166+
try {
167+
br.close();
168+
} catch (IOException ex) {
169+
future.setException(ex);
170+
}
171+
172+
}
173+
}
174+
}, "Obtaining adb version")).start();
175+
176+
String s = "";
177+
178+
try {
179+
s = (String) future.get(30, TimeUnit.SECONDS);
180+
} catch (Exception e) {
181+
return null;
182+
}
183+
return s;
137184
}
138185

139186
private ListenableFuture<List<AdbForward>> executeGetForwardList() {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.android.ddmlib.IDevice;
44
import com.google.common.util.concurrent.ListenableFuture;
55
import com.google.common.util.concurrent.SettableFuture;
6-
import com.sun.org.apache.xpath.internal.operations.Bool;
76
import com.yeetor.adb.AdbServer;
87
import com.yeetor.minitouch.Minitouch;
98
import com.yeetor.minitouch.MinitouchListener;

src/main/java/com/yeetor/minicap/Minicap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static void installMinicap(IDevice device) throws MinicapInstallException
6767
throw new MinicapInstallException("File: " + minicap_bin.getAbsolutePath() + " not exists!");
6868
}
6969
try {
70-
device.pushFile(minicap_bin.getAbsolutePath(), REMOTE_PATH + "/" + MINICAP_BIN);
70+
AdbServer.server().executePushFile(device, minicap_bin.getAbsolutePath(), REMOTE_PATH + "/" + MINICAP_BIN);
7171
} catch (Exception e) {
7272
throw new MinicapInstallException(e.getMessage());
7373
}
@@ -81,7 +81,7 @@ public static void installMinicap(IDevice device) throws MinicapInstallException
8181
}
8282

8383
try {
84-
device.pushFile(minicap_so.getAbsolutePath(), REMOTE_PATH + "/" + MINICAP_SO);
84+
AdbServer.server().executePushFile(device, minicap_so.getAbsolutePath(), REMOTE_PATH + "/" + MINICAP_SO);
8585
} catch (Exception e) {
8686
throw new MinicapInstallException(e.getMessage());
8787
}

src/main/java/com/yeetor/minitouch/Minitouch.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static void installMinitouch(IDevice device) throws MinitouchInstallExcep
5454
throw new MinitouchInstallException("File: " + minitouch_bin.getAbsolutePath() + " not exists!");
5555
}
5656
try {
57-
device.pushFile(minitouch_bin.getAbsolutePath(), REMOTE_PATH + "/" + MINITOUCH_BIN);
57+
AdbServer.server().executePushFile(device, minitouch_bin.getAbsolutePath(), REMOTE_PATH + "/" + MINITOUCH_BIN);
5858
} catch (Exception e) {
5959
throw new MinitouchInstallException(e.getMessage());
6060
}
@@ -112,6 +112,7 @@ public void start() {
112112
String command = "/data/local/tmp/minitouch" + " -n " + forward.getLocalabstract();
113113
minitouchThread = startMinitouchThread(command);
114114
minitouchInitialThread = startInitialThread("127.0.0.1", forward.getPort());
115+
System.out.println(command);
115116
}
116117

117118
public void kill() {

0 commit comments

Comments
 (0)