Skip to content

Commit 4b41c15

Browse files
committed
Merge pull request #775 from NativeScript/totev/fix-crash
Fixes for android related commands
2 parents 909f37e + 4b44240 commit 4b41c15

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

lib/services/android-debug-service.ts

+17-18
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@ class AndroidDebugService implements IDebugService {
9696

9797
private printDebugPort(packageName: string): IFuture<void> {
9898
return (() => {
99-
let res = this.$childProcess.spawnFromEvent(this.$staticConfig.getAdbFilePath().wait(), ["shell", "am", "broadcast", "-a", packageName + "-GetDgbPort"], "exit").wait();
100-
this.$logger.info(res.stdout);
99+
let res = this.device.adb.executeShellCommand(["am", "broadcast", "-a", packageName + "-GetDgbPort"]).wait();
100+
this.$logger.info(res);
101101
}).future<void>()();
102102
}
103103

104104
private attachDebugger(packageName: string): void {
105-
let startDebuggerCommand = `am broadcast -a \"${packageName}-Debug\" --ez enable true`;
105+
let startDebuggerCommand = ["am", "broadcast", "-a", '\"${packageName}-Debug\"', "--ez", "enable", "true"];
106106
let port = this.$options.debugPort;
107107

108108
if (port > 0) {
109-
startDebuggerCommand += " --ei debuggerPort " + port;
109+
startDebuggerCommand.push("--ei", "debuggerPort", port.toString());
110110
this.device.adb.executeShellCommand(startDebuggerCommand).wait();
111111
} else {
112-
let res = this.$childProcess.spawnFromEvent(this.$staticConfig.getAdbFilePath().wait(), ["shell", "am", "broadcast", "-a", packageName + "-Debug", "--ez", "enable", "true"], "exit").wait();
113-
let match = res.stdout.match(/result=(\d)+/);
112+
let res = this.device.adb.executeShellCommand(["am", "broadcast", "-a", packageName + "-Debug", "--ez", "enable", "true"]).wait();
113+
let match = res.match(/result=(\d)+/);
114114
if (match) {
115115
port = match[0].substring(7);
116116
} else {
@@ -127,7 +127,7 @@ class AndroidDebugService implements IDebugService {
127127
}
128128

129129
private detachDebugger(packageName: string): IFuture<void> {
130-
return this.device.adb.executeShellCommand(this.device.deviceInfo.identifier, `shell am broadcast -a \"${packageName}-Debug\" --ez enable false`);
130+
return this.device.adb.executeShellCommand(["am", "broadcast", "-a", `${packageName}-Debug`, "--ez", "enable", "false"]);
131131
}
132132

133133
private startAppWithDebugger(packageFile: string, packageName: string): IFuture<void> {
@@ -142,11 +142,11 @@ class AndroidDebugService implements IDebugService {
142142
let packageDir = util.format(AndroidDebugService.PACKAGE_EXTERNAL_DIR_TEMPLATE, packageName);
143143
let envDebugOutFullpath = this.$mobileHelper.buildDevicePath(packageDir, AndroidDebugService.ENV_DEBUG_OUT_FILENAME);
144144

145-
this.device.adb.executeShellCommand(`rm "${envDebugOutFullpath}"`).wait();
146-
this.device.adb.executeShellCommand(`mkdir -p "${packageDir}"`).wait();
145+
this.device.adb.executeShellCommand(["rm", `${envDebugOutFullpath}`]).wait();
146+
this.device.adb.executeShellCommand(["mkdir", "-p", `${packageDir}`]).wait();
147147

148148
let debugBreakPath = this.$mobileHelper.buildDevicePath(packageDir, "debugbreak");
149-
this.device.adb.executeShellCommand(`"cat /dev/null > ${debugBreakPath}"`).wait();
149+
this.device.adb.executeShellCommand([`cat /dev/null > ${debugBreakPath}`]).wait();
150150

151151
this.device.applicationManager.startApplication(packageName).wait();
152152

@@ -160,7 +160,7 @@ class AndroidDebugService implements IDebugService {
160160
}
161161

162162
private tcpForward(src: Number, dest: Number): IFuture<void> {
163-
return this.device.adb.executeCommand(`forward tcp:${src.toString()} tcp:${dest.toString()}`);
163+
return this.device.adb.executeCommand(["forward", `tcp:${src.toString()}`, `tcp:${dest.toString()}`]);
164164
}
165165

166166
private startDebuggerClient(port: Number): IFuture<void> {
@@ -190,9 +190,8 @@ class AndroidDebugService implements IDebugService {
190190

191191
private checkIfFileExists(filename: string): IFuture<boolean> {
192192
return (() => {
193-
let args = ["shell", "test", "-f", filename, "&&", "echo 'yes'", "||", "echo 'no'"];
194-
let res = this.$childProcess.spawnFromEvent(this.$staticConfig.getAdbFilePath().wait(), args, "exit").wait();
195-
let exists = res.stdout.indexOf('yes') > -1;
193+
let res = this.device.adb.executeShellCommand([`test -f ${filename} && echo 'yes' || echo 'no'`]).wait();
194+
let exists = res.indexOf('yes') > -1;
196195
return exists;
197196
}).future<boolean>()();
198197
}
@@ -204,7 +203,7 @@ class AndroidDebugService implements IDebugService {
204203

205204
let packageDir = util.format(AndroidDebugService.PACKAGE_EXTERNAL_DIR_TEMPLATE, packageName);
206205
let envDebugInFullpath = packageDir + AndroidDebugService.ENV_DEBUG_IN_FILENAME;
207-
this.device.adb.executeShellCommand(`rm "${envDebugInFullpath}"`).wait();
206+
this.device.adb.executeShellCommand(["rm", `${envDebugInFullpath}`]).wait();
208207

209208
let isRunning = false;
210209
for (let i = 0; i < timeout; i++) {
@@ -215,15 +214,15 @@ class AndroidDebugService implements IDebugService {
215214
}
216215

217216
if (isRunning) {
218-
this.device.adb.executeShellCommand(`"cat /dev/null > ${envDebugInFullpath}"`).wait();
217+
this.device.adb.executeShellCommand([`cat /dev/null > ${envDebugInFullpath}`]).wait();
219218

220219
for (let i = 0; i < timeout; i++) {
221220
helpers.sleep(1000 /* ms */);
222221
let envDebugOutFullpath = packageDir + AndroidDebugService.ENV_DEBUG_OUT_FILENAME;
223222
let exists = this.checkIfFileExists(envDebugOutFullpath).wait();
224223
if (exists) {
225-
let res = this.$childProcess.spawnFromEvent(this.$staticConfig.getAdbFilePath().wait(), ["shell", "cat", envDebugOutFullpath], "exit").wait();
226-
let match = res.stdout.match(/PORT=(\d)+/);
224+
let res = this.device.adb.executeShellCommand(["cat", envDebugOutFullpath]).wait();
225+
let match = res.match(/PORT=(\d)+/);
227226
if (match) {
228227
port = parseInt(match[0].substring(5), 10);
229228
break;

lib/services/usb-livesync-service.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
142142
let commands = [ this.liveSyncCommands.SyncFilesCommand() ];
143143
this.livesync(deviceAppData.appIdentifier, deviceAppData.deviceProjectRootPath, commands).wait();
144144
} else {
145-
let devicePathRoot = `/data/data/${deviceAppData.appIdentifier}/files`;
146-
this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb")}`).wait();
145+
let devicePathRoot = `/data/data/${deviceAppData.appIdentifier}/files`;
146+
let devicePath = this.$mobileHelper.buildDevicePath(devicePathRoot, "code_cache", "secondary_dexes", "proxyThumb");
147+
this.device.adb.executeShellCommand(["rm", "-rf", devicePath]).wait();
147148
}
148149

149150
this.device.applicationManager.restartApplication(deviceAppData.appIdentifier).wait();
@@ -153,9 +154,9 @@ export class AndroidUsbLiveSyncService extends androidLiveSyncServiceLib.Android
153154
public beforeLiveSyncAction(deviceAppData: Mobile.IDeviceAppData): IFuture<void> {
154155
return (() => {
155156
let deviceRootPath = `/data/local/tmp/${deviceAppData.appIdentifier}`;
156-
this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync")}`).wait();
157-
this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(deviceRootPath, "sync")}`).wait();
158-
this.device.adb.executeShellCommand(`rm -rf ${this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync")}`).wait();
157+
this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "fullsync")]).wait();
158+
this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "sync")]).wait();
159+
this.device.adb.executeShellCommand(["rm", "-rf", this.$mobileHelper.buildDevicePath(deviceRootPath, "removedsync")]).wait();
159160
}).future<void>()();
160161
}
161162
}

0 commit comments

Comments
 (0)