2222package processing .mode .android ;
2323
2424import processing .app .Base ;
25- import processing .app .Platform ;
2625import processing .app .RunnerListener ;
2726import processing .app .exec .LineProcessor ;
2827import processing .app .exec .ProcessRegistry ;
3130import processing .core .PApplet ;
3231import processing .mode .android .LogEntry .Severity ;
3332
34- import java .io .File ;
3533import java .io .IOException ;
3634import java .util .*;
3735import java .util .regex .Matcher ;
@@ -73,8 +71,8 @@ public Device(final Devices env, final String id) {
7371 public void bringLauncherToFront () {
7472 try {
7573 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" );
7876 } catch (final Exception e ) {
7977 e .printStackTrace (System .err );
8078 }
@@ -88,12 +86,12 @@ public String getName() {
8886 String name = "" ;
8987
9088 try {
91- ProcessResult result = env . getSDK (). runADB ( "-s" , id , "shell" , "getprop" , "ro.product.brand" );
89+ ProcessResult result = adb ( "shell" , "getprop" , "ro.product.brand" );
9290 if (result .succeeded ()) {
9391 name += result .getStdout () + " " ;
9492 }
9593
96- result = env . getSDK (). runADB ( "-s" , id , "shell" , "getprop" , "ro.product.model" );
94+ result = adb ( "shell" , "getprop" , "ro.product.model" );
9795 if (result .succeeded ()) {
9896 name += result .getStdout ();
9997 }
@@ -208,7 +206,6 @@ public boolean launchApp(final String packageName, boolean isDebuggerEnabled)
208206 };
209207 pr = adb (cmd );
210208 }
211- // PApplet.println(cmd);
212209
213210 if (Base .DEBUG ) {
214211 System .out .println (pr .toString ());
@@ -226,8 +223,9 @@ public boolean launchApp(final String packageName, boolean isDebuggerEnabled)
226223 public void forwardPort (int tcpPort ) throws IOException , InterruptedException {
227224 // Start ADB Server
228225 adb ("start-server" );
229- final String [] jdwpcmd = generateAdbCommand ("jdwp" );
230- Process deviceId = Runtime .getRuntime ().exec (jdwpcmd );
226+
227+ Process deviceId = adbProc ("jdwp" );
228+
231229 // Get Process ID from ADB command `adb jdwp`
232230 JDWPProcessor pIDProcessor = new JDWPProcessor ();
233231 new StreamPump (deviceId .getInputStream (), "jdwp: " ).addTarget (
@@ -236,7 +234,8 @@ public void forwardPort(int tcpPort) throws IOException, InterruptedException {
236234 System .err ).start ();
237235
238236 Thread .sleep (1000 );
239- // forward to tcp port
237+
238+ // Forward to tcp port
240239 adb ("forward" , "tcp:" + tcpPort , "jdwp:" + pIDProcessor .getId ());
241240 }
242241
@@ -389,9 +388,11 @@ private void reportStackTrace(final LogEntry entry) {
389388
390389 void initialize () throws IOException , InterruptedException {
391390 adb ("logcat" , "-c" );
392- final String [] cmd = generateAdbCommand ("logcat" , "-v" , "brief" );
391+
392+ final String [] cmd = {"-s" , id , "logcat" , "-v" , "brief" };
393393 final String title = PApplet .join (cmd , ' ' );
394- logcat = Runtime .getRuntime ().exec (cmd );
394+ logcat = adbProc (cmd );
395+
395396 ProcessRegistry .watch (logcat );
396397 new StreamPump (logcat .getInputStream (), "log: " + title ).addTarget (
397398 new LogLineProcessor ()).start ();
@@ -465,15 +466,17 @@ public void removeListener(final DeviceListener listener) {
465466 }
466467
467468 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 );
470476 }
471477
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 );
477480 }
478481
479482 @ Override
0 commit comments