Skip to content

Commit d171f4b

Browse files
authored
Merge pull request #1999 from NativeScript/debug-started-flag
support debug started flag
2 parents 7f42a69 + 912a6f9 commit d171f4b

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

lib/services/android-debug-service.ts

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,8 @@ class AndroidDebugService implements IDebugService {
134134
this.attachDebugger(device.deviceInfo.identifier, packageName).wait();
135135
} else if (this.$options.stop) {
136136
this.detachDebugger(packageName).wait();
137-
} else if (this.$options.debugBrk) {
138-
this.startAppWithDebugger(packageFile, packageName).wait();
139137
} else {
140138
this.startAppWithDebugger(packageFile, packageName).wait();
141-
//TODO: Find different way to make sure that the app is started.
142-
sleep(500);
143139
this.attachDebugger(device.deviceInfo.identifier, packageName).wait();
144140
}
145141
}).future<void>()();
@@ -202,39 +198,38 @@ class AndroidDebugService implements IDebugService {
202198
// As we need to redirect output of a command on the device, keep using only one argument.
203199
// We could rewrite this with two calls - touch and rm -f , but -f flag is not available on old Android, so rm call will fail when file does not exist.
204200

201+
this.device.applicationManager.stopApplication(packageName).wait();
202+
205203
if(this.$options.debugBrk) {
206204
this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${packageName}-debugbreak`]).wait();
207205
}
206+
this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${packageName}-debugger-started`]).wait();
208207

209-
this.device.applicationManager.stopApplication(packageName).wait();
210208
this.device.applicationManager.startApplication(packageName).wait();
211209

212-
if(this.$options.debugBrk) {
213-
let waitText: string = `0 /data/local/tmp/${packageName}-debugbreak`;
214-
let maxWait = 12;
215-
let debugerStarted: boolean = false;
216-
while (maxWait > 0 && !debugerStarted) {
217-
let forwardsResult = this.device.adb.executeShellCommand(["ls", "-s", `/data/local/tmp/${packageName}-debugbreak`]).wait();
218-
maxWait--;
219-
debugerStarted = forwardsResult.indexOf(waitText) === -1;
220-
if (!debugerStarted) {
221-
sleep(500);
222-
}
223-
}
210+
this.waitForDebugger(packageName);
224211

225-
if (debugerStarted) {
226-
this.$logger.info("# NativeScript Debugger started #");
227-
} else {
228-
this.$logger.warn("# NativeScript Debugger did not start in time #");
229-
}
212+
}).future<void>()();
213+
}
230214

231-
if (this.$options.client) {
232-
let localDebugPort = this.getForwardedLocalDebugPortForPackageName(this.device.deviceInfo.identifier, packageName).wait();
233-
this.startDebuggerClient(localDebugPort).wait();
234-
this.openDebuggerClient(AndroidDebugService.DEFAULT_NODE_INSPECTOR_URL + "?port=" + localDebugPort);
235-
}
215+
private waitForDebugger(packageName: String) {
216+
let waitText: string = `0 /data/local/tmp/${packageName}-debugger-started`;
217+
let maxWait = 12;
218+
let debugerStarted: boolean = false;
219+
while (maxWait > 0 && !debugerStarted) {
220+
let forwardsResult = this.device.adb.executeShellCommand(["ls", "-s", `/data/local/tmp/${packageName}-debugger-started`]).wait();
221+
maxWait--;
222+
debugerStarted = forwardsResult.indexOf(waitText) === -1;
223+
if (!debugerStarted) {
224+
sleep(500);
236225
}
237-
}).future<void>()();
226+
}
227+
228+
if (debugerStarted) {
229+
this.$logger.info("# NativeScript Debugger started #");
230+
} else {
231+
this.$logger.warn("# NativeScript Debugger did not start in time #");
232+
}
238233
}
239234

240235
private startDebuggerClient(port: Number): IFuture<void> {

0 commit comments

Comments
 (0)