Skip to content

Commit 2708444

Browse files
committed
support debug started flag
refactored debug start of applications improved debug command speed by 500 ms
1 parent 3afa813 commit 2708444

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

lib/services/android-debug-service.ts

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,6 @@ class AndroidDebugService implements IDebugService {
138138
this.startAppWithDebugger(packageFile, packageName).wait();
139139
} else {
140140
this.startAppWithDebugger(packageFile, packageName).wait();
141-
//TODO: Find different way to make sure that the app is started.
142-
sleep(500);
143141
this.attachDebugger(device.deviceInfo.identifier, packageName).wait();
144142
}
145143
}).future<void>()();
@@ -202,41 +200,46 @@ class AndroidDebugService implements IDebugService {
202200
// As we need to redirect output of a command on the device, keep using only one argument.
203201
// 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.
204202

203+
this.device.applicationManager.stopApplication(packageName).wait();
204+
205205
if(this.$options.debugBrk) {
206206
this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${packageName}-debugbreak`]).wait();
207207
}
208+
this.device.adb.executeShellCommand([`cat /dev/null > /data/local/tmp/${packageName}-debugger-started`]).wait();
208209

209-
this.device.applicationManager.stopApplication(packageName).wait();
210210
this.device.applicationManager.startApplication(packageName).wait();
211211

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-
}
224-
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+
this.waitForDebugger(packageName);
230213

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-
}
214+
if (this.$options.client) {
215+
let localDebugPort = this.getForwardedLocalDebugPortForPackageName(this.device.deviceInfo.identifier, packageName).wait();
216+
this.startDebuggerClient(localDebugPort).wait();
217+
this.openDebuggerClient(AndroidDebugService.DEFAULT_NODE_INSPECTOR_URL + "?port=" + localDebugPort);
236218
}
219+
237220
}).future<void>()();
238221
}
239222

223+
private waitForDebugger(packageName: String) {
224+
let waitText: string = `0 /data/local/tmp/${packageName}-debugger-started`;
225+
let maxWait = 12;
226+
let debugerStarted: boolean = false;
227+
while (maxWait > 0 && !debugerStarted) {
228+
let forwardsResult = this.device.adb.executeShellCommand(["ls", "-s", `/data/local/tmp/${packageName}-debugger-started`]).wait();
229+
maxWait--;
230+
debugerStarted = forwardsResult.indexOf(waitText) === -1;
231+
if (!debugerStarted) {
232+
sleep(500);
233+
}
234+
}
235+
236+
if (debugerStarted) {
237+
this.$logger.info("# NativeScript Debugger started #");
238+
} else {
239+
this.$logger.warn("# NativeScript Debugger did not start in time #");
240+
}
241+
}
242+
240243
private startDebuggerClient(port: Number): IFuture<void> {
241244
return (() => {
242245
let nodeInspectorModuleFilePath = require.resolve("node-inspector");

0 commit comments

Comments
 (0)