@@ -8,93 +8,98 @@ import { injector } from "../../yok";
8
8
import * as semver from "semver" ;
9
9
10
10
export class AndroidEmulatorServices
11
- implements Mobile . IEmulatorPlatformService {
11
+ implements Mobile . IEmulatorPlatformService
12
+ {
12
13
constructor (
13
14
private $androidGenymotionService : Mobile . IAndroidVirtualDeviceService ,
14
15
private $androidVirtualDeviceService : Mobile . IAndroidVirtualDeviceService ,
15
16
private $adb : Mobile . IAndroidDebugBridge ,
16
17
private $childProcess : IChildProcess ,
17
18
private $emulatorHelper : Mobile . IEmulatorHelper ,
18
19
private $logger : ILogger ,
19
- private $utils : IUtils
20
+ private $utils : IUtils ,
20
21
) { }
21
22
22
23
public async getEmulatorImages ( ) : Promise < Mobile . IEmulatorImagesOutput > {
23
24
const adbDevicesOutput = await this . $adb . getDevicesSafe ( ) ;
24
- const avdAvailableEmulatorsOutput = await this . $androidVirtualDeviceService . getEmulatorImages (
25
- adbDevicesOutput
26
- ) ;
27
- const genyAvailableDevicesOutput = await this . $androidGenymotionService . getEmulatorImages (
28
- adbDevicesOutput
29
- ) ;
25
+ const avdAvailableEmulatorsOutput =
26
+ await this . $androidVirtualDeviceService . getEmulatorImages (
27
+ adbDevicesOutput ,
28
+ ) ;
29
+ const genyAvailableDevicesOutput =
30
+ await this . $androidGenymotionService . getEmulatorImages ( adbDevicesOutput ) ;
30
31
const devices = _ . concat (
31
32
avdAvailableEmulatorsOutput . devices ,
32
- genyAvailableDevicesOutput . devices
33
+ genyAvailableDevicesOutput . devices ,
33
34
) . filter ( ( item ) => ! ! item ) ;
34
35
35
36
return {
36
37
devices,
37
38
errors : avdAvailableEmulatorsOutput . errors . concat (
38
- genyAvailableDevicesOutput . errors
39
+ genyAvailableDevicesOutput . errors ,
39
40
) ,
40
41
} ;
41
42
}
42
43
43
44
public async getRunningEmulatorIds ( ) : Promise < string [ ] > {
44
45
const adbDevicesOutput = await this . $adb . getDevicesSafe ( ) ;
45
- const avds = await this . $androidVirtualDeviceService . getRunningEmulatorIds (
46
- adbDevicesOutput
47
- ) ;
48
- const genies = await this . $androidGenymotionService . getRunningEmulatorIds (
49
- adbDevicesOutput
50
- ) ;
46
+ const avds =
47
+ await this . $androidVirtualDeviceService . getRunningEmulatorIds (
48
+ adbDevicesOutput ,
49
+ ) ;
50
+ const genies =
51
+ await this . $androidGenymotionService . getRunningEmulatorIds (
52
+ adbDevicesOutput ,
53
+ ) ;
51
54
return avds . concat ( genies ) ;
52
55
}
53
56
54
57
public async getRunningEmulatorName ( emulatorId : string ) : Promise < string > {
55
- let result = await this . $androidVirtualDeviceService . getRunningEmulatorName (
56
- emulatorId
57
- ) ;
58
- if ( ! result ) {
59
- result = await this . $androidGenymotionService . getRunningEmulatorName (
60
- emulatorId
58
+ let result =
59
+ await this . $androidVirtualDeviceService . getRunningEmulatorName (
60
+ emulatorId ,
61
61
) ;
62
+ if ( ! result ) {
63
+ result =
64
+ await this . $androidGenymotionService . getRunningEmulatorName ( emulatorId ) ;
62
65
}
63
66
64
67
return result ;
65
68
}
66
69
67
70
public async getRunningEmulatorImageIdentifier (
68
- emulatorId : string
71
+ emulatorId : string ,
69
72
) : Promise < string > {
70
- let result = await this . $androidVirtualDeviceService . getRunningEmulatorImageIdentifier (
71
- emulatorId
72
- ) ;
73
- if ( ! result ) {
74
- result = await this . $androidGenymotionService . getRunningEmulatorImageIdentifier (
75
- emulatorId
73
+ let result =
74
+ await this . $androidVirtualDeviceService . getRunningEmulatorImageIdentifier (
75
+ emulatorId ,
76
76
) ;
77
+ if ( ! result ) {
78
+ result =
79
+ await this . $androidGenymotionService . getRunningEmulatorImageIdentifier (
80
+ emulatorId ,
81
+ ) ;
77
82
}
78
83
79
84
return result ;
80
85
}
81
86
82
87
public async startEmulator (
83
- options : Mobile . IAndroidStartEmulatorOptions
88
+ options : Mobile . IAndroidStartEmulatorOptions ,
84
89
) : Promise < Mobile . IStartEmulatorOutput > {
85
90
const output = await this . startEmulatorCore ( options ) ;
86
91
let bootToCompleteOutput = null ;
87
92
if ( output && output . runningEmulator ) {
88
93
bootToCompleteOutput = await this . waitForEmulatorBootToComplete (
89
94
output . runningEmulator ,
90
95
output . endTimeEpoch ,
91
- options . timeout
96
+ options . timeout ,
92
97
) ;
93
98
}
94
99
95
100
return {
96
101
errors : ( ( output && output . errors ) || [ ] ) . concat (
97
- ( bootToCompleteOutput && bootToCompleteOutput . errors ) || [ ]
102
+ ( bootToCompleteOutput && bootToCompleteOutput . errors ) || [ ] ,
98
103
) ,
99
104
} ;
100
105
}
@@ -104,7 +109,7 @@ export class AndroidEmulatorServices
104
109
}
105
110
106
111
private async startEmulatorCore (
107
- options : Mobile . IAndroidStartEmulatorOptions
112
+ options : Mobile . IAndroidStartEmulatorOptions ,
108
113
) : Promise < {
109
114
runningEmulator : Mobile . IDeviceInfo ;
110
115
errors : string [ ] ;
@@ -118,7 +123,7 @@ export class AndroidEmulatorServices
118
123
119
124
let emulator = this . $emulatorHelper . getEmulatorByStartEmulatorOptions (
120
125
options ,
121
- availableEmulators
126
+ availableEmulators ,
122
127
) ;
123
128
if (
124
129
! emulator &&
@@ -158,7 +163,7 @@ export class AndroidEmulatorServices
158
163
const emulators = ( await this . getEmulatorImages ( ) ) . devices ;
159
164
const newEmulator = _ . find (
160
165
emulators ,
161
- ( e ) => e . imageIdentifier === emulator . imageIdentifier
166
+ ( e ) => e . imageIdentifier === emulator . imageIdentifier ,
162
167
) ;
163
168
if ( newEmulator && this . $emulatorHelper . isEmulatorRunning ( newEmulator ) ) {
164
169
return {
@@ -185,29 +190,29 @@ export class AndroidEmulatorServices
185
190
let pathToEmulatorExecutable = null ;
186
191
let startEmulatorArgs = null ;
187
192
if ( emulator . vendor === AndroidVirtualDevice . AVD_VENDOR_NAME ) {
188
- pathToEmulatorExecutable = this . $androidVirtualDeviceService
189
- . pathToEmulatorExecutable ;
193
+ pathToEmulatorExecutable =
194
+ this . $androidVirtualDeviceService . pathToEmulatorExecutable ;
190
195
startEmulatorArgs = this . $androidVirtualDeviceService . startEmulatorArgs (
191
- emulator . imageIdentifier
196
+ emulator . imageIdentifier ,
192
197
) ;
193
198
} else if (
194
199
emulator . vendor === AndroidVirtualDevice . GENYMOTION_VENDOR_NAME
195
200
) {
196
- pathToEmulatorExecutable = this . $androidGenymotionService
197
- . pathToEmulatorExecutable ;
201
+ pathToEmulatorExecutable =
202
+ this . $androidGenymotionService . pathToEmulatorExecutable ;
198
203
startEmulatorArgs = this . $androidGenymotionService . startEmulatorArgs (
199
- emulator . imageIdentifier
204
+ emulator . imageIdentifier ,
200
205
) ;
201
206
}
202
207
203
208
this . $logger . info (
204
- `Starting Android emulator with image ${ emulator . imageIdentifier } `
209
+ `Starting Android emulator with image ${ emulator . imageIdentifier } ` ,
205
210
) ;
206
211
207
212
const childProcess = this . $childProcess . spawn (
208
213
pathToEmulatorExecutable ,
209
214
startEmulatorArgs ,
210
- { stdio : "ignore" , detached : true }
215
+ { stdio : "ignore" , detached : true } ,
211
216
) ;
212
217
childProcess . unref ( ) ;
213
218
childProcess . on ( "error" , ( err : Error ) => {
@@ -235,25 +240,25 @@ export class AndroidEmulatorServices
235
240
const minVersion = semver . coerce ( AndroidVirtualDevice . MIN_ANDROID_VERSION ) ;
236
241
const bestVersion = best && best . version && semver . coerce ( best . version ) ;
237
242
238
- return bestVersion && semver . gte ( bestVersion , minVersion ) ? best : null ;
243
+ return ! bestVersion || semver . gte ( bestVersion , minVersion ) ? best : null ;
239
244
}
240
245
241
246
private async waitForEmulatorBootToComplete (
242
247
emulator : Mobile . IDeviceInfo ,
243
248
endTimeEpoch : number ,
244
- timeout : number
249
+ timeout : number ,
245
250
) : Promise < { runningEmulator : Mobile . IDeviceInfo ; errors : string [ ] } > {
246
251
this . $logger . info ( "Waiting for emulator device initialization..." , {
247
252
[ LoggerConfigData . skipNewLine ] : true ,
248
253
} ) ;
249
254
250
255
const isInfiniteWait =
251
256
this . $utils . getMilliSecondsTimeout (
252
- timeout || AndroidVirtualDevice . TIMEOUT_SECONDS
257
+ timeout || AndroidVirtualDevice . TIMEOUT_SECONDS ,
253
258
) === 0 ;
254
259
while ( getCurrentEpochTime ( ) < endTimeEpoch || isInfiniteWait ) {
255
260
const isEmulatorBootCompleted = await this . isEmulatorBootCompleted (
256
- emulator . identifier
261
+ emulator . identifier ,
257
262
) ;
258
263
if ( isEmulatorBootCompleted ) {
259
264
this . $logger . info ( EOL , { [ LoggerConfigData . skipNewLine ] : true } ) ;
@@ -276,7 +281,7 @@ export class AndroidEmulatorServices
276
281
private async isEmulatorBootCompleted ( emulatorId : string ) : Promise < boolean > {
277
282
const output = await this . $adb . getPropertyValue (
278
283
emulatorId ,
279
- "dev.bootcomplete"
284
+ "dev.bootcomplete" ,
280
285
) ;
281
286
const matches = output . match ( "1" ) ;
282
287
return matches && matches . length > 0 ;
0 commit comments