@@ -76,11 +76,11 @@ export class AndroidDeviceDebugService extends DebugServiceBase implements IDevi
7676 }
7777
7878 private async removePortForwarding ( packageName ?: string ) : Promise < void > {
79- const port = await this . getForwardedLocalDebugPortForPackageName ( this . device . deviceInfo . identifier , packageName || this . _packageName ) ;
79+ const port = await this . getForwardedDebugPort ( this . device . deviceInfo . identifier , packageName || this . _packageName ) ;
8080 return this . device . adb . executeCommand ( [ "forward" , "--remove" , `tcp:${ port } ` ] ) ;
8181 }
8282
83- private async getForwardedLocalDebugPortForPackageName ( deviceId : string , packageName : string ) : Promise < number > {
83+ private async getForwardedDebugPort ( deviceId : string , packageName : string ) : Promise < number > {
8484 let port = - 1 ;
8585 const forwardsResult = await this . device . adb . executeCommand ( [ "forward" , "--list" ] ) ;
8686
@@ -128,38 +128,33 @@ export class AndroidDeviceDebugService extends DebugServiceBase implements IDevi
128128 }
129129
130130 private async debugCore ( device : Mobile . IAndroidDevice , packageFile : string , appData : Mobile . IApplicationData , debugOptions : IDebugOptions ) : Promise < string > {
131- await this . printDebugPort ( device . deviceInfo . identifier , appData . appId ) ;
132-
133- if ( debugOptions . start ) {
134- return await this . attachDebugger ( device . deviceInfo . identifier , appData . appId , debugOptions ) ;
135- } else if ( debugOptions . stop ) {
131+ if ( debugOptions . stop ) {
136132 await this . removePortForwarding ( ) ;
137133 return null ;
138- } else {
134+ }
135+
136+ if ( ! debugOptions . start ) {
139137 await this . debugStartCore ( appData , debugOptions ) ;
140- return await this . attachDebugger ( device . deviceInfo . identifier , appData . appId , debugOptions ) ;
141138 }
139+
140+ await this . validateRunningApp ( device . deviceInfo . identifier , appData . appId ) ;
141+ const debugPort = await this . getForwardedDebugPort ( device . deviceInfo . identifier , appData . appId ) ;
142+ await this . printDebugPort ( device . deviceInfo . identifier , debugPort ) ;
143+
144+ return this . getChromeDebugUrl ( debugOptions , debugPort ) ;
142145 }
143146
144- private async printDebugPort ( deviceId : string , packageName : string ) : Promise < void > {
145- const port = await this . getForwardedLocalDebugPortForPackageName ( deviceId , packageName ) ;
147+ private async printDebugPort ( deviceId : string , port : number ) : Promise < void > {
146148 this . $logger . info ( "device: " + deviceId + " debug port: " + port + "\n" ) ;
147149 }
148150
149- private async attachDebugger ( deviceId : string , packageName : string , debugOptions : IDebugOptions ) : Promise < string > {
151+ private async validateRunningApp ( deviceId : string , packageName : string ) : Promise < void > {
150152 if ( ! ( await this . isAppRunning ( packageName , deviceId ) ) ) {
151153 this . $errors . failWithoutHelp ( `The application ${ packageName } does not appear to be running on ${ deviceId } or is not built with debugging enabled.` ) ;
152154 }
153-
154- const port = await this . getForwardedLocalDebugPortForPackageName ( deviceId , packageName ) ;
155-
156- return this . getChromeDebugUrl ( debugOptions , port ) ;
157155 }
158156
159157 private async debugStartCore ( appData : Mobile . IApplicationData , debugOptions : IDebugOptions ) : Promise < void > {
160- // Arguments passed to executeShellCommand must be in array ([]), but it turned out adb shell "arg with intervals" still works correctly.
161- // As we need to redirect output of a command on the device, keep using only one argument.
162- // 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.
163158 await this . device . applicationManager . stopApplication ( appData ) ;
164159
165160 if ( debugOptions . debugBrk ) {
0 commit comments