22
22
package processing .mode .android ;
23
23
24
24
import processing .app .Base ;
25
- import processing .app .Platform ;
26
25
import processing .app .RunnerListener ;
27
26
import processing .app .exec .LineProcessor ;
28
27
import processing .app .exec .ProcessRegistry ;
31
30
import processing .core .PApplet ;
32
31
import processing .mode .android .LogEntry .Severity ;
33
32
34
- import java .io .File ;
35
33
import java .io .IOException ;
36
34
import java .util .*;
37
35
import java .util .regex .Matcher ;
@@ -73,8 +71,8 @@ public Device(final Devices env, final String id) {
73
71
public void bringLauncherToFront () {
74
72
try {
75
73
adb ("shell" , "am" , "start" ,
76
- "-a" , "android.intent.action.MAIN" ,
77
- "-c" , "android.intent.category.HOME" );
74
+ "-a" , "android.intent.action.MAIN" ,
75
+ "-c" , "android.intent.category.HOME" );
78
76
} catch (final Exception e ) {
79
77
e .printStackTrace (System .err );
80
78
}
@@ -88,12 +86,12 @@ public String getName() {
88
86
String name = "" ;
89
87
90
88
try {
91
- ProcessResult result = env . getSDK (). runADB ( "-s" , id , "shell" , "getprop" , "ro.product.brand" );
89
+ ProcessResult result = adb ( "shell" , "getprop" , "ro.product.brand" );
92
90
if (result .succeeded ()) {
93
91
name += result .getStdout () + " " ;
94
92
}
95
93
96
- result = env . getSDK (). runADB ( "-s" , id , "shell" , "getprop" , "ro.product.model" );
94
+ result = adb ( "shell" , "getprop" , "ro.product.model" );
97
95
if (result .succeeded ()) {
98
96
name += result .getStdout ();
99
97
}
@@ -208,7 +206,6 @@ public boolean launchApp(final String packageName, boolean isDebuggerEnabled)
208
206
};
209
207
pr = adb (cmd );
210
208
}
211
- // PApplet.println(cmd);
212
209
213
210
if (Base .DEBUG ) {
214
211
System .out .println (pr .toString ());
@@ -226,8 +223,9 @@ public boolean launchApp(final String packageName, boolean isDebuggerEnabled)
226
223
public void forwardPort (int tcpPort ) throws IOException , InterruptedException {
227
224
// Start ADB Server
228
225
adb ("start-server" );
229
- final String [] jdwpcmd = generateAdbCommand ("jdwp" );
230
- Process deviceId = Runtime .getRuntime ().exec (jdwpcmd );
226
+
227
+ Process deviceId = adbProc ("jdwp" );
228
+
231
229
// Get Process ID from ADB command `adb jdwp`
232
230
JDWPProcessor pIDProcessor = new JDWPProcessor ();
233
231
new StreamPump (deviceId .getInputStream (), "jdwp: " ).addTarget (
@@ -236,7 +234,8 @@ public void forwardPort(int tcpPort) throws IOException, InterruptedException {
236
234
System .err ).start ();
237
235
238
236
Thread .sleep (1000 );
239
- // forward to tcp port
237
+
238
+ // Forward to tcp port
240
239
adb ("forward" , "tcp:" + tcpPort , "jdwp:" + pIDProcessor .getId ());
241
240
}
242
241
@@ -389,9 +388,11 @@ private void reportStackTrace(final LogEntry entry) {
389
388
390
389
void initialize () throws IOException , InterruptedException {
391
390
adb ("logcat" , "-c" );
392
- final String [] cmd = generateAdbCommand ("logcat" , "-v" , "brief" );
391
+
392
+ final String [] cmd = {"-s" , id , "logcat" , "-v" , "brief" };
393
393
final String title = PApplet .join (cmd , ' ' );
394
- logcat = Runtime .getRuntime ().exec (cmd );
394
+ logcat = adbProc (cmd );
395
+
395
396
ProcessRegistry .watch (logcat );
396
397
new StreamPump (logcat .getInputStream (), "log: " + title ).addTarget (
397
398
new LogLineProcessor ()).start ();
@@ -465,15 +466,17 @@ public void removeListener(final DeviceListener listener) {
465
466
}
466
467
467
468
private ProcessResult adb (final String ... cmd ) throws InterruptedException , IOException {
468
- final String [] adbCmd = generateAdbCommand (cmd );
469
- return env .getSDK ().runADB (adbCmd );
469
+ final String [] adbCmd = genAdbCommand (cmd );
470
+ return env .getSDK ().runAdb (adbCmd );
471
+ }
472
+
473
+ private Process adbProc (final String ... cmd ) throws IOException {
474
+ final String [] adbCmd = genAdbCommand (cmd );
475
+ return env .getSDK ().getAdbProcess (adbCmd );
470
476
}
471
477
472
- private String [] generateAdbCommand (final String ... cmd ) throws IOException {
473
- File toolsPath = env .getSDK ().getPlatformToolsFolder ();
474
- File abdPath = Platform .isWindows () ? new File (toolsPath , "adb.exe" ) :
475
- new File (toolsPath , "adb" );
476
- return PApplet .concat (new String [] { abdPath .getCanonicalPath (), "-s" , getId () }, cmd );
478
+ private String [] genAdbCommand (final String ... cmd ) {
479
+ return PApplet .concat (new String [] { "-s" , getId () }, cmd );
477
480
}
478
481
479
482
@ Override
0 commit comments