21
21
22
22
package processing .mode .android ;
23
23
24
+ import processing .app .Messages ;
24
25
import processing .app .Platform ;
25
26
import processing .app .Preferences ;
26
27
import processing .app .exec .ProcessHelper ;
@@ -429,8 +430,15 @@ static public File selectFolder(String prompt, File folder, Frame frame) {
429
430
private static final String ADB_DAEMON_MSG_1 = "daemon not running" ;
430
431
private static final String ADB_DAEMON_MSG_2 = "daemon started successfully" ;
431
432
433
+ public static boolean adbDisabled = false ;
434
+
432
435
public static ProcessResult runADB (final String ... cmd )
433
- throws InterruptedException , IOException {
436
+ throws InterruptedException , IOException {
437
+
438
+ if (adbDisabled ) {
439
+ throw new IOException ("adb is currently disabled" );
440
+ }
441
+
434
442
final String [] adbCmd ;
435
443
if (!cmd [0 ].equals ("adb" )) {
436
444
adbCmd = PApplet .splice (cmd , "adb" , 0 );
@@ -441,29 +449,37 @@ public static ProcessResult runADB(final String... cmd)
441
449
if (processing .app .Base .DEBUG ) {
442
450
PApplet .printArray (adbCmd );
443
451
}
444
- // try {
445
- ProcessResult adbResult = new ProcessHelper (adbCmd ).execute ();
446
- // Ignore messages about starting up an adb daemon
447
- String out = adbResult .getStdout ();
448
- if (out .contains (ADB_DAEMON_MSG_1 ) && out .contains (ADB_DAEMON_MSG_2 )) {
449
- StringBuilder sb = new StringBuilder ();
450
- for (String line : out .split ("\n " )) {
451
- if (!out .contains (ADB_DAEMON_MSG_1 ) &&
452
- !out .contains (ADB_DAEMON_MSG_2 )) {
453
- sb .append (line ).append ("\n " );
452
+ try {
453
+ ProcessResult adbResult = new ProcessHelper (adbCmd ).execute ();
454
+ // Ignore messages about starting up an adb daemon
455
+ String out = adbResult .getStdout ();
456
+ if (out .contains (ADB_DAEMON_MSG_1 ) && out .contains (ADB_DAEMON_MSG_2 )) {
457
+ StringBuilder sb = new StringBuilder ();
458
+ for (String line : out .split ("\n " )) {
459
+ if (!out .contains (ADB_DAEMON_MSG_1 ) &&
460
+ !out .contains (ADB_DAEMON_MSG_2 )) {
461
+ sb .append (line ).append ("\n " );
462
+ }
454
463
}
464
+ return new ProcessResult (adbResult .getCmd (),
465
+ adbResult .getResult (),
466
+ sb .toString (),
467
+ adbResult .getStderr (),
468
+ adbResult .getTime ());
469
+ }
470
+ return adbResult ;
471
+ } catch (IOException ioe ) {
472
+ if (-1 < ioe .getMessage ().indexOf ("Permission denied" )) {
473
+ Messages .showWarning ("Trouble with adb!" ,
474
+ "Could not run the adb tool from the Android SDK.\n " +
475
+ "One possibility is that its executable permission\n " +
476
+ "is not properly set. You can try setting this\n " +
477
+ "permission manually, or re-installing the SDK.\n \n " +
478
+ "The mode will be disabled until this problem is fixed.\n " );
479
+ adbDisabled = true ;
455
480
}
456
- return new ProcessResult (adbResult .getCmd (),
457
- adbResult .getResult (),
458
- sb .toString (),
459
- adbResult .getStderr (),
460
- adbResult .getTime ());
481
+ throw ioe ;
461
482
}
462
- return adbResult ;
463
- // } catch (IOException ioe) {
464
- // ioe.printStackTrace();
465
- // throw ioe;
466
- // }
467
483
}
468
484
469
485
static class SDKTarget {
0 commit comments