@@ -76,11 +76,11 @@ export class AndroidDeviceDebugService extends DebugServiceBase implements IDevi
76
76
}
77
77
78
78
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 ) ;
80
80
return this . device . adb . executeCommand ( [ "forward" , "--remove" , `tcp:${ port } ` ] ) ;
81
81
}
82
82
83
- private async getForwardedLocalDebugPortForPackageName ( deviceId : string , packageName : string ) : Promise < number > {
83
+ private async getForwardedDebugPort ( deviceId : string , packageName : string ) : Promise < number > {
84
84
let port = - 1 ;
85
85
const forwardsResult = await this . device . adb . executeCommand ( [ "forward" , "--list" ] ) ;
86
86
@@ -128,38 +128,33 @@ export class AndroidDeviceDebugService extends DebugServiceBase implements IDevi
128
128
}
129
129
130
130
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 ) {
136
132
await this . removePortForwarding ( ) ;
137
133
return null ;
138
- } else {
134
+ }
135
+
136
+ if ( ! debugOptions . start ) {
139
137
await this . debugStartCore ( appData , debugOptions ) ;
140
- return await this . attachDebugger ( device . deviceInfo . identifier , appData . appId , debugOptions ) ;
141
138
}
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 ) ;
142
145
}
143
146
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 > {
146
148
this . $logger . info ( "device: " + deviceId + " debug port: " + port + "\n" ) ;
147
149
}
148
150
149
- private async attachDebugger ( deviceId : string , packageName : string , debugOptions : IDebugOptions ) : Promise < string > {
151
+ private async validateRunningApp ( deviceId : string , packageName : string ) : Promise < void > {
150
152
if ( ! ( await this . isAppRunning ( packageName , deviceId ) ) ) {
151
153
this . $errors . failWithoutHelp ( `The application ${ packageName } does not appear to be running on ${ deviceId } or is not built with debugging enabled.` ) ;
152
154
}
153
-
154
- const port = await this . getForwardedLocalDebugPortForPackageName ( deviceId , packageName ) ;
155
-
156
- return this . getChromeDebugUrl ( debugOptions , port ) ;
157
155
}
158
156
159
157
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.
163
158
await this . device . applicationManager . stopApplication ( appData ) ;
164
159
165
160
if ( debugOptions . debugBrk ) {
0 commit comments