From 626433dca7834094fbaa824653d825e391a40e92 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Fri, 10 Jan 2020 15:12:20 +0200 Subject: [PATCH] fix: improve message for Android socket connection error In case there's a socket connection error during LiveSync for Android, we show a non-descriptive error message which confuses the users. Improve the messsage with suggestions what might cause the error. --- .../livesync/android-livesync-tool.ts | 22 +++++++++++++++---- .../livesync/android-livesync-tool.ts | 3 ++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/services/livesync/android-livesync-tool.ts b/lib/services/livesync/android-livesync-tool.ts index f2ad2880c3..ff7081d040 100644 --- a/lib/services/livesync/android-livesync-tool.ts +++ b/lib/services/livesync/android-livesync-tool.ts @@ -75,7 +75,7 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool { abstractPort: `localabstract:${configuration.appIdentifier}-livesync` }); - const connectionResult = await this.connectEventuallyUntilTimeout(this.createSocket.bind(this, port), connectTimeout); + const connectionResult = await this.connectEventuallyUntilTimeout(this.createSocket.bind(this, port), connectTimeout, configuration); this.handleConnection(connectionResult); } @@ -299,19 +299,33 @@ export class AndroidLivesyncTool implements IAndroidLivesyncTool { }); } - private connectEventuallyUntilTimeout(factory: () => ILiveSyncSocket, timeout: number): Promise<{ socket: ILiveSyncSocket, data: Buffer | string }> { + private connectEventuallyUntilTimeout(factory: () => ILiveSyncSocket, timeout: number, configuration: IAndroidLivesyncToolConfiguration): Promise<{ socket: ILiveSyncSocket, data: Buffer | string }> { return new Promise((resolve, reject) => { let lastKnownError: Error | string, isConnected = false; - const connectionTimer = setTimeout(() => { + const connectionTimer = setTimeout(async () => { if (!isConnected) { isConnected = true; if (this.pendingConnectionData && this.pendingConnectionData.socketTimer) { clearTimeout(this.pendingConnectionData.socketTimer); } - reject(lastKnownError || new Error(AndroidLivesyncTool.SOCKET_CONNECTION_TIMED_OUT_ERROR)); + const applicationPid = await this.$androidProcessService.getAppProcessId(configuration.deviceIdentifier, configuration.appIdentifier); + if (!applicationPid) { + this.$logger.trace("In Android LiveSync tool, lastKnownError is: ", lastKnownError); + this.$logger.info(`Application ${configuration.appIdentifier} is not running on device ${configuration.deviceIdentifier}.`.yellow); + this.$logger.info( + `This issue may be caused by: + * crash at startup (try \`tns debug android --debug-brk\` to check why it crashes) + * different application identifier in your package.json and in your gradle files (check your identifier in \`package.json\` and in all *.gradle files in your App_Resources directory) + * device is locked + * manual closing of the application`.cyan); + reject(new Error(`Application ${configuration.appIdentifier} is not running`)); + } else { + reject(lastKnownError || new Error(AndroidLivesyncTool.SOCKET_CONNECTION_TIMED_OUT_ERROR)); + } + this.pendingConnectionData = null; } }, timeout); diff --git a/test/services/livesync/android-livesync-tool.ts b/test/services/livesync/android-livesync-tool.ts index 25224f7a7e..2e058845a4 100644 --- a/test/services/livesync/android-livesync-tool.ts +++ b/test/services/livesync/android-livesync-tool.ts @@ -70,7 +70,8 @@ const createTestInjector = (socket: INetSocket, fileStreams: IDictionary Promise.resolve("") + forwardFreeTcpToAbstractPort: () => Promise.resolve(""), + getAppProcessId: () => Promise.resolve("1234") }); testInjector.register("LiveSyncSocket", () => socket); testInjector.register("devicePlatformsConstants", DevicePlatformsConstants);