@@ -8,93 +8,98 @@ import { injector } from "../../yok";
88import * as semver from "semver" ;
99
1010export class AndroidEmulatorServices
11- implements Mobile . IEmulatorPlatformService {
11+ implements Mobile . IEmulatorPlatformService
12+ {
1213 constructor (
1314 private $androidGenymotionService : Mobile . IAndroidVirtualDeviceService ,
1415 private $androidVirtualDeviceService : Mobile . IAndroidVirtualDeviceService ,
1516 private $adb : Mobile . IAndroidDebugBridge ,
1617 private $childProcess : IChildProcess ,
1718 private $emulatorHelper : Mobile . IEmulatorHelper ,
1819 private $logger : ILogger ,
19- private $utils : IUtils
20+ private $utils : IUtils ,
2021 ) { }
2122
2223 public async getEmulatorImages ( ) : Promise < Mobile . IEmulatorImagesOutput > {
2324 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 ) ;
3031 const devices = _ . concat (
3132 avdAvailableEmulatorsOutput . devices ,
32- genyAvailableDevicesOutput . devices
33+ genyAvailableDevicesOutput . devices ,
3334 ) . filter ( ( item ) => ! ! item ) ;
3435
3536 return {
3637 devices,
3738 errors : avdAvailableEmulatorsOutput . errors . concat (
38- genyAvailableDevicesOutput . errors
39+ genyAvailableDevicesOutput . errors ,
3940 ) ,
4041 } ;
4142 }
4243
4344 public async getRunningEmulatorIds ( ) : Promise < string [ ] > {
4445 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+ ) ;
5154 return avds . concat ( genies ) ;
5255 }
5356
5457 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 ,
6161 ) ;
62+ if ( ! result ) {
63+ result =
64+ await this . $androidGenymotionService . getRunningEmulatorName ( emulatorId ) ;
6265 }
6366
6467 return result ;
6568 }
6669
6770 public async getRunningEmulatorImageIdentifier (
68- emulatorId : string
71+ emulatorId : string ,
6972 ) : 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 ,
7676 ) ;
77+ if ( ! result ) {
78+ result =
79+ await this . $androidGenymotionService . getRunningEmulatorImageIdentifier (
80+ emulatorId ,
81+ ) ;
7782 }
7883
7984 return result ;
8085 }
8186
8287 public async startEmulator (
83- options : Mobile . IAndroidStartEmulatorOptions
88+ options : Mobile . IAndroidStartEmulatorOptions ,
8489 ) : Promise < Mobile . IStartEmulatorOutput > {
8590 const output = await this . startEmulatorCore ( options ) ;
8691 let bootToCompleteOutput = null ;
8792 if ( output && output . runningEmulator ) {
8893 bootToCompleteOutput = await this . waitForEmulatorBootToComplete (
8994 output . runningEmulator ,
9095 output . endTimeEpoch ,
91- options . timeout
96+ options . timeout ,
9297 ) ;
9398 }
9499
95100 return {
96101 errors : ( ( output && output . errors ) || [ ] ) . concat (
97- ( bootToCompleteOutput && bootToCompleteOutput . errors ) || [ ]
102+ ( bootToCompleteOutput && bootToCompleteOutput . errors ) || [ ] ,
98103 ) ,
99104 } ;
100105 }
@@ -104,7 +109,7 @@ export class AndroidEmulatorServices
104109 }
105110
106111 private async startEmulatorCore (
107- options : Mobile . IAndroidStartEmulatorOptions
112+ options : Mobile . IAndroidStartEmulatorOptions ,
108113 ) : Promise < {
109114 runningEmulator : Mobile . IDeviceInfo ;
110115 errors : string [ ] ;
@@ -118,7 +123,7 @@ export class AndroidEmulatorServices
118123
119124 let emulator = this . $emulatorHelper . getEmulatorByStartEmulatorOptions (
120125 options ,
121- availableEmulators
126+ availableEmulators ,
122127 ) ;
123128 if (
124129 ! emulator &&
@@ -158,7 +163,7 @@ export class AndroidEmulatorServices
158163 const emulators = ( await this . getEmulatorImages ( ) ) . devices ;
159164 const newEmulator = _ . find (
160165 emulators ,
161- ( e ) => e . imageIdentifier === emulator . imageIdentifier
166+ ( e ) => e . imageIdentifier === emulator . imageIdentifier ,
162167 ) ;
163168 if ( newEmulator && this . $emulatorHelper . isEmulatorRunning ( newEmulator ) ) {
164169 return {
@@ -185,29 +190,29 @@ export class AndroidEmulatorServices
185190 let pathToEmulatorExecutable = null ;
186191 let startEmulatorArgs = null ;
187192 if ( emulator . vendor === AndroidVirtualDevice . AVD_VENDOR_NAME ) {
188- pathToEmulatorExecutable = this . $androidVirtualDeviceService
189- . pathToEmulatorExecutable ;
193+ pathToEmulatorExecutable =
194+ this . $androidVirtualDeviceService . pathToEmulatorExecutable ;
190195 startEmulatorArgs = this . $androidVirtualDeviceService . startEmulatorArgs (
191- emulator . imageIdentifier
196+ emulator . imageIdentifier ,
192197 ) ;
193198 } else if (
194199 emulator . vendor === AndroidVirtualDevice . GENYMOTION_VENDOR_NAME
195200 ) {
196- pathToEmulatorExecutable = this . $androidGenymotionService
197- . pathToEmulatorExecutable ;
201+ pathToEmulatorExecutable =
202+ this . $androidGenymotionService . pathToEmulatorExecutable ;
198203 startEmulatorArgs = this . $androidGenymotionService . startEmulatorArgs (
199- emulator . imageIdentifier
204+ emulator . imageIdentifier ,
200205 ) ;
201206 }
202207
203208 this . $logger . info (
204- `Starting Android emulator with image ${ emulator . imageIdentifier } `
209+ `Starting Android emulator with image ${ emulator . imageIdentifier } ` ,
205210 ) ;
206211
207212 const childProcess = this . $childProcess . spawn (
208213 pathToEmulatorExecutable ,
209214 startEmulatorArgs ,
210- { stdio : "ignore" , detached : true }
215+ { stdio : "ignore" , detached : true } ,
211216 ) ;
212217 childProcess . unref ( ) ;
213218 childProcess . on ( "error" , ( err : Error ) => {
@@ -235,25 +240,25 @@ export class AndroidEmulatorServices
235240 const minVersion = semver . coerce ( AndroidVirtualDevice . MIN_ANDROID_VERSION ) ;
236241 const bestVersion = best && best . version && semver . coerce ( best . version ) ;
237242
238- return bestVersion && semver . gte ( bestVersion , minVersion ) ? best : null ;
243+ return ! bestVersion || semver . gte ( bestVersion , minVersion ) ? best : null ;
239244 }
240245
241246 private async waitForEmulatorBootToComplete (
242247 emulator : Mobile . IDeviceInfo ,
243248 endTimeEpoch : number ,
244- timeout : number
249+ timeout : number ,
245250 ) : Promise < { runningEmulator : Mobile . IDeviceInfo ; errors : string [ ] } > {
246251 this . $logger . info ( "Waiting for emulator device initialization..." , {
247252 [ LoggerConfigData . skipNewLine ] : true ,
248253 } ) ;
249254
250255 const isInfiniteWait =
251256 this . $utils . getMilliSecondsTimeout (
252- timeout || AndroidVirtualDevice . TIMEOUT_SECONDS
257+ timeout || AndroidVirtualDevice . TIMEOUT_SECONDS ,
253258 ) === 0 ;
254259 while ( getCurrentEpochTime ( ) < endTimeEpoch || isInfiniteWait ) {
255260 const isEmulatorBootCompleted = await this . isEmulatorBootCompleted (
256- emulator . identifier
261+ emulator . identifier ,
257262 ) ;
258263 if ( isEmulatorBootCompleted ) {
259264 this . $logger . info ( EOL , { [ LoggerConfigData . skipNewLine ] : true } ) ;
@@ -276,7 +281,7 @@ export class AndroidEmulatorServices
276281 private async isEmulatorBootCompleted ( emulatorId : string ) : Promise < boolean > {
277282 const output = await this . $adb . getPropertyValue (
278283 emulatorId ,
279- "dev.bootcomplete"
284+ "dev.bootcomplete" ,
280285 ) ;
281286 const matches = output . match ( "1" ) ;
282287 return matches && matches . length > 0 ;
0 commit comments