Skip to content

Commit f796df0

Browse files
authored
Merge pull request NetrisTV#24 from HardBoiledSmith/DEV-13493
DEV-13493 [Ramiel] 간헐적으로 앱 실행이 되지 않는 이슈
2 parents d008885 + 386f424 commit f796df0

File tree

1 file changed

+56
-53
lines changed

1 file changed

+56
-53
lines changed

src/server/goog-device/mw/WebsocketProxyOverAdb.ts

+56-53
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { Config } from '../../Config';
1212
import { Utils } from '../../Utils';
1313
import axios from 'axios';
1414
//
15-
// TODO: DEV-12826
15+
// TODO: DEV-12826, DEV-13493
1616
import qs from 'qs';
17+
import KeyEvent from '../../../app/googDevice/android/KeyEvent';
1718
//
1819

1920
export class WebsocketProxyOverAdb extends WebsocketProxy {
@@ -171,7 +172,7 @@ export class WebsocketProxyOverAdb extends WebsocketProxy {
171172
return service;
172173
}
173174

174-
// TODO: HBsmith DEV-12386
175+
// TODO: HBsmith DEV-12386, DEV-13493
175176
public release(): void {
176177
this.tearDownTest();
177178
super.release();
@@ -198,48 +199,48 @@ export class WebsocketProxyOverAdb extends WebsocketProxy {
198199
return;
199200
}
200201
// 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}`;
214204
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+
})
216214
.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+
});
218240
})
219241
.catch((e) => {
220242
console.error(e);
221243
});
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-
}
243244
}
244245

245246
private tearDownTest(): void {
@@ -249,22 +250,25 @@ export class WebsocketProxyOverAdb extends WebsocketProxy {
249250

250251
const device = this.getDevice();
251252
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}`;
264254
device
265-
.runShellCommandAdbKit(cc)
255+
.runShellCommandAdbKit(cmdPower)
266256
.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+
});
268272
})
269273
.catch((e) => {
270274
console.error(e);
@@ -273,6 +277,5 @@ export class WebsocketProxyOverAdb extends WebsocketProxy {
273277

274278
this.apiDeleteSession(this.udid);
275279
}
276-
277280
//
278281
}

0 commit comments

Comments
 (0)