@@ -12,8 +12,9 @@ import { Config } from '../../Config';
12
12
import { Utils } from '../../Utils' ;
13
13
import axios from 'axios' ;
14
14
//
15
- // TODO: DEV-12826
15
+ // TODO: DEV-12826, DEV-13493
16
16
import qs from 'qs' ;
17
+ import KeyEvent from '../../../app/googDevice/android/KeyEvent' ;
17
18
//
18
19
19
20
export class WebsocketProxyOverAdb extends WebsocketProxy {
@@ -171,7 +172,7 @@ export class WebsocketProxyOverAdb extends WebsocketProxy {
171
172
return service ;
172
173
}
173
174
174
- // TODO: HBsmith DEV-12386
175
+ // TODO: HBsmith DEV-12386, DEV-13493
175
176
public release ( ) : void {
176
177
this . tearDownTest ( ) ;
177
178
super . release ( ) ;
@@ -198,48 +199,48 @@ export class WebsocketProxyOverAdb extends WebsocketProxy {
198
199
return ;
199
200
}
200
201
// send key event code 82 many times for deterministic unlock
201
- for ( let i = 0 ; i < 3 ; i += 1 ) {
202
- const cmdMenu = 'input keyevent 82' ;
203
- device
204
- . runShellCommandAdbKit ( cmdMenu )
205
- . then ( ( output ) => {
206
- console . log ( output ? output : `success to run a command: ${ cmdMenu } ` ) ;
207
- } )
208
- . catch ( ( e ) => {
209
- console . error ( e ) ;
210
- } ) ;
211
- }
212
-
213
- const cmdHome = 'input keyevent 3' ;
202
+ const cmdMenu = `input keyevent ${ KeyEvent . KEYCODE_MENU } ` ;
203
+ const cmdHome = `input keyevent ${ KeyEvent . KEYCODE_HOME } ` ;
214
204
device
215
- . runShellCommandAdbKit ( cmdHome )
205
+ . runShellCommandAdbKit ( cmdMenu )
206
+ . then ( ( output ) => {
207
+ console . log ( output ? output : `success to send 1st KEYCODE_MENU: ${ cmdMenu } ` ) ;
208
+ return device . runShellCommandAdbKit ( cmdMenu ) ;
209
+ } )
210
+ . then ( ( output ) => {
211
+ console . log ( output ? output : `success to send 2nd KEYCODE_MENU: ${ cmdMenu } ` ) ;
212
+ return device . runShellCommandAdbKit ( cmdMenu ) ;
213
+ } )
216
214
. then ( ( output ) => {
217
- console . log ( output ? output : `success to run a command: ${ cmdHome } ` ) ;
215
+ console . log ( output ? output : `success to send 3rd KEYCODE_MENU: ${ cmdMenu } ` ) ;
216
+ return device . runShellCommandAdbKit ( cmdHome ) ;
217
+ } )
218
+ . then ( ( output ) => {
219
+ console . log ( output ? output : `success to send KEYCODE_HOME: ${ cmdHome } ` ) ;
220
+
221
+ if ( ! this . appKey ) {
222
+ return ;
223
+ }
224
+
225
+ const cmdAppStop = `am force-stop '${ this . appKey } '` ;
226
+ const cmdAppStart = `monkey -p '${ this . appKey } ' -c android.intent.category.LAUNCHER 1` ;
227
+
228
+ device
229
+ . runShellCommandAdbKit ( cmdAppStop )
230
+ . then ( ( output ) => {
231
+ console . log ( output ? output : `success to stop the app: ${ cmdAppStop } ` ) ;
232
+ return device . runShellCommandAdbKit ( cmdAppStart ) ;
233
+ } )
234
+ . then ( ( output ) => {
235
+ console . log ( output ? output : `success to start the app: ${ cmdAppStart } ` ) ;
236
+ } )
237
+ . catch ( ( e ) => {
238
+ console . error ( e ) ;
239
+ } ) ;
218
240
} )
219
241
. catch ( ( e ) => {
220
242
console . error ( e ) ;
221
243
} ) ;
222
-
223
- if ( this . appKey ) {
224
- const cmdAppStop = `am force-stop '${ this . appKey } '` ;
225
- device
226
- . runShellCommandAdbKit ( cmdAppStop )
227
- . then ( ( output ) => {
228
- console . log ( output ? output : `success to run a command: ${ cmdAppStop } ` ) ;
229
- } )
230
- . catch ( ( e ) => {
231
- console . error ( e ) ;
232
- } ) ;
233
- const cmdAppStart = `monkey -p '${ this . appKey } ' -c android.intent.category.LAUNCHER 1` ;
234
- device
235
- . runShellCommandAdbKit ( cmdAppStart )
236
- . then ( ( output ) => {
237
- console . log ( output ? output : `success to run a command: ${ cmdAppStart } ` ) ;
238
- } )
239
- . catch ( ( e ) => {
240
- console . error ( e ) ;
241
- } ) ;
242
- }
243
244
}
244
245
245
246
private tearDownTest ( ) : void {
@@ -249,22 +250,25 @@ export class WebsocketProxyOverAdb extends WebsocketProxy {
249
250
250
251
const device = this . getDevice ( ) ;
251
252
if ( device ) {
252
- if ( this . appKey ) {
253
- const cc = `am force-stop '${ this . appKey } '` ;
254
- device
255
- . runShellCommandAdbKit ( cc )
256
- . then ( ( output ) => {
257
- console . log ( output ? output : `success to run a command: ${ cc } ` ) ;
258
- } )
259
- . catch ( ( e ) => {
260
- console . error ( e ) ;
261
- } ) ;
262
- }
263
- const cc = 'input keyevent 26' ;
253
+ const cmdPower = `input keyevent ${ KeyEvent . KEYCODE_POWER } ` ;
264
254
device
265
- . runShellCommandAdbKit ( cc )
255
+ . runShellCommandAdbKit ( cmdPower )
266
256
. then ( ( output ) => {
267
- console . log ( output ? output : `success to run a command: ${ cc } ` ) ;
257
+ console . log ( output ? output : `success to run a command: ${ cmdPower } ` ) ;
258
+
259
+ if ( ! this . appKey ) {
260
+ return ;
261
+ }
262
+
263
+ const cmdStopApp = `am force-stop '${ this . appKey } '` ;
264
+ device
265
+ . runShellCommandAdbKit ( cmdStopApp )
266
+ . then ( ( output ) => {
267
+ console . log ( output ? output : `success to stop app: ${ cmdStopApp } ` ) ;
268
+ } )
269
+ . catch ( ( e ) => {
270
+ console . error ( e ) ;
271
+ } ) ;
268
272
} )
269
273
. catch ( ( e ) => {
270
274
console . error ( e ) ;
@@ -273,6 +277,5 @@ export class WebsocketProxyOverAdb extends WebsocketProxy {
273
277
274
278
this . apiDeleteSession ( this . udid ) ;
275
279
}
276
-
277
280
//
278
281
}
0 commit comments