Skip to content

Commit 26df14a

Browse files
committed
Fix : waiting-for-debugger dialog shown every-time
1 parent d8e84a0 commit 26df14a

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

mode/src/processing/mode/android/AndroidRunner.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,16 @@ public class AndroidRunner implements DeviceListener {
5555

5656
private VirtualMachine vm;
5757

58+
private boolean isDebugEnabled;
59+
5860
public AndroidRunner(AndroidBuild build, RunnerListener listener) {
5961
this.build = build;
6062
this.listener = listener;
6163

64+
if (listener instanceof AndroidEditor){
65+
isDebugEnabled = ((AndroidEditor) listener).isDebuggerEnabled();
66+
}
67+
6268
if (listener instanceof Editor) {
6369
Editor editor = (Editor) listener;
6470
sketchErr = editor.getConsole().getErr();
@@ -131,11 +137,9 @@ public boolean launch(Future<Device> deviceFuture, int comp, boolean emu) {
131137
}
132138
}
133139

134-
if (listener instanceof AndroidEditor){
135-
AndroidDebugger debugger = ((AndroidEditor) listener).getDebugger();
136-
if (debugger.isEnabled()) {
137-
debugger.startDebug(this, device);
138-
}
140+
if (isDebugEnabled){
141+
((AndroidEditor) listener).getDebugger()
142+
.startDebug(this, device);
139143
}
140144

141145
listener.stopIndeterminate();
@@ -190,7 +194,7 @@ public VirtualMachine vm(){
190194
private boolean startSketch(AndroidBuild build, final Device device) {
191195
final String packageName = build.getPackageName();
192196
try {
193-
if (device.launchApp(packageName)) {
197+
if (device.launchApp(packageName, isDebugEnabled)) {
194198
return true;
195199
}
196200
} catch (final Exception e) {

mode/src/processing/mode/android/Device.java

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,32 @@ public boolean removeApp(String packageName) throws IOException, InterruptedExce
184184

185185
// different version that actually runs through JDI:
186186
// http://asantoso.wordpress.com/2009/09/26/using-jdb-with-adb-to-debugging-of-android-app-on-a-real-device/
187-
public boolean launchApp(final String packageName)
187+
public boolean launchApp(final String packageName, boolean isDebuggerEnabled)
188188
throws IOException, InterruptedException {
189189
if (!isAlive()) {
190190
return false;
191191
}
192-
193-
String[] cmd = {
194-
"shell", "am", "start",
195-
"-e", "debugEnabled", "true",
196-
"-a", "android.intent.action.MAIN",
197-
"-c", "android.intent.category.LAUNCHER", "-D",
198-
"-n", packageName + "/.MainActivity"
199-
};
192+
ProcessResult pr;
193+
if (isDebuggerEnabled){
194+
String[] cmd = {
195+
"shell", "am", "start",
196+
"-e", "debugEnabled", "true",
197+
"-a", "android.intent.action.MAIN",
198+
"-c", "android.intent.category.LAUNCHER", "-D",
199+
"-n", packageName + "/.MainActivity"
200+
};
201+
pr = adb(cmd);
202+
}else {
203+
String[] cmd = {
204+
"shell", "am", "start",
205+
"-e", "debugEnabled", "true",
206+
"-a", "android.intent.action.MAIN",
207+
"-c", "android.intent.category.LAUNCHER",
208+
"-n", packageName + "/.MainActivity"
209+
};
210+
pr = adb(cmd);
211+
}
200212
// PApplet.println(cmd);
201-
ProcessResult pr = adb(cmd);
202213

203214
if (Base.DEBUG) {
204215
System.out.println(pr.toString());

0 commit comments

Comments
 (0)