Skip to content
This repository was archived by the owner on Feb 2, 2021. It is now read-only.

Commit 0e7c0ae

Browse files
FatmeFatme
Fatme
authored and
Fatme
committed
Merge pull request #354 from telerik/fix-android-debugger
Fix android debugger
2 parents 872965c + 0e43b67 commit 0e7c0ae

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

mobile/android/android-device.ts

+19-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
6464
private $opener: IOpener,
6565
private $devicePlatformsConstants: Mobile.IDevicePlatformsConstants,
6666
private $options: IOptions,
67-
private $logcatHelper: Mobile.ILogcatHelper) {
67+
private $logcatHelper: Mobile.ILogcatHelper,
68+
private $hostInfo: IHostInfo) {
6869
let details: IAndroidDeviceDetails = this.getDeviceDetails().wait();
6970

7071
this.model = details.model;
@@ -209,7 +210,12 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
209210
}
210211

211212
private openDebuggerClient(url: string): void {
212-
this.$opener.open(url, "chrome");
213+
let chrome = this.$hostInfo.isDarwin ? "Google\ Chrome" : "chrome";
214+
let child = this.$opener.open(url, chrome);
215+
if(!child) {
216+
this.$errors.fail(`Unable to open ${chrome}.`);
217+
}
218+
return child;
213219
}
214220

215221
private printDebugPort(packageName: string): void {
@@ -257,17 +263,20 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
257263
let port = this.$options.debugPort;
258264

259265
let packageDir = util.format(AndroidDevice.PACKAGE_EXTERNAL_DIR_TEMPLATE, packageName);
260-
let envDebugOutFullpath = packageDir + AndroidDevice.ENV_DEBUG_OUT_FILENAME;
266+
let envDebugOutFullpath = this.buildDevicePath(packageDir, AndroidDevice.ENV_DEBUG_OUT_FILENAME);
261267
let clearDebugEnvironmentCommand = this.composeCommand('shell rm "%s"', envDebugOutFullpath);
262268
this.$childProcess.exec(clearDebugEnvironmentCommand).wait();
263269

264-
let setDebugBreakEnvironmentCommand = this.composeCommand('shell echo "" > "%s"', "debugbreak");
265-
this.$childProcess.exec(setDebugBreakEnvironmentCommand).wait();
270+
let createPackageDir = this.composeCommand('shell mkdir -p "%s"', packageDir);
271+
this.$childProcess.exec(createPackageDir).wait();
272+
273+
let debugBreakPath = this.buildDevicePath(packageDir, "debugbreak");
274+
let setDebugBreakEnvironmentCommand = this.composeCommand('shell "cat /dev/null > %s"', debugBreakPath);
275+
this.$childProcess.exec(setDebugBreakEnvironmentCommand).wait();
266276

267277
this.startPackageOnDevice(packageName).wait();
268278

269279
let dbgPort = this.startAndGetPort(packageName).wait();
270-
271280
if (dbgPort > 0) {
272281
this.tcpForward(dbgPort, dbgPort);
273282
this.startDebuggerClient(dbgPort).wait();
@@ -310,25 +319,26 @@ export class AndroidDevice implements Mobile.IAndroidDevice {
310319
private startAndGetPort(packageName: string): IFuture<number> {
311320
return (() => {
312321
let port = -1;
322+
let timeout = 60;
313323

314324
let packageDir = util.format(AndroidDevice.PACKAGE_EXTERNAL_DIR_TEMPLATE, packageName);
315325
let envDebugInFullpath = packageDir + AndroidDevice.ENV_DEBUG_IN_FILENAME;
316326
let clearDebugEnvironmentCommand = this.composeCommand('shell rm "%s"', envDebugInFullpath);
317327
this.$childProcess.exec(clearDebugEnvironmentCommand).wait();
318328

319329
let isRunning = false;
320-
for (let i = 0; i < 60; i++) {
330+
for (let i = 0; i < timeout; i++) {
321331
helpers.sleep(1000 /* ms */);
322332
isRunning = this.checkIfRunning(packageName);
323333
if (isRunning)
324334
break;
325335
}
326-
336+
327337
if (isRunning) {
328338
let setEnvironmentCommand = this.composeCommand('shell "cat /dev/null > %s"', envDebugInFullpath);
329339
this.$childProcess.exec(setEnvironmentCommand).wait();
330340

331-
for (let i = 0; i < 10; i++) {
341+
for (let i = 0; i < timeout; i++) {
332342
helpers.sleep(1000 /* ms */);
333343
let envDebugOutFullpath = packageDir + AndroidDevice.ENV_DEBUG_OUT_FILENAME;
334344
let exists = this.checkIfFileExists(envDebugOutFullpath).wait();

opener.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import xopen = require("open");
66

77
export class Opener implements IOpener {
88

9-
public open(target: string, appname?: string): void {
10-
xopen(target, appname);
9+
public open(target: string, appname?: string): any {
10+
return xopen(target, appname);
1111
}
1212
}
1313
$injector.register("opener", Opener);

0 commit comments

Comments
 (0)