@@ -40,6 +40,7 @@ var ONE_SECOND = 1000; // in milliseconds
40
40
var ONE_MINUTE = 60 * ONE_SECOND ; // in milliseconds
41
41
var INSTALL_COMMAND_TIMEOUT = 5 * ONE_MINUTE ; // in milliseconds
42
42
var NUM_INSTALL_RETRIES = 3 ;
43
+ var CHECK_BOOTED_INTERVAL = 3 * ONE_SECOND ; // in milliseconds
43
44
var EXEC_KILL_SIGNAL = 'SIGKILL' ;
44
45
45
46
/**
@@ -146,10 +147,12 @@ module.exports.list_targets = function() {
146
147
* and returns the started ID of that emulator.
147
148
* If no ID is given it will use the first image available,
148
149
* if no image is available it will error out (maybe create one?).
150
+ * If no boot timeout is given or the value is negative it will wait forever for
151
+ * the emulator to boot
149
152
*
150
153
* Returns a promise.
151
154
*/
152
- module . exports . start = function ( emulator_ID ) {
155
+ module . exports . start = function ( emulator_ID , boot_timeout ) {
153
156
var self = this ;
154
157
155
158
return Q ( ) . then ( function ( ) {
@@ -186,14 +189,20 @@ module.exports.start = function(emulator_ID) {
186
189
187
190
//wait for emulator to boot up
188
191
process . stdout . write ( 'Booting up emulator (this may take a while)...' ) ;
189
- return self . wait_for_boot ( emulatorId )
190
- . then ( function ( ) {
191
- events . emit ( 'log' , 'BOOT COMPLETE' ) ;
192
- //unlock screen
193
- return Adb . shell ( emulatorId , 'input keyevent 82' ) ;
194
- } ) . then ( function ( ) {
195
- //return the new emulator id for the started emulators
196
- return emulatorId ;
192
+ return self . wait_for_boot ( emulatorId , boot_timeout )
193
+ . then ( function ( success ) {
194
+ if ( success ) {
195
+ events . emit ( 'log' , 'BOOT COMPLETE' ) ;
196
+ //unlock screen
197
+ return Adb . shell ( emulatorId , 'input keyevent 82' )
198
+ . then ( function ( ) {
199
+ //return the new emulator id for the started emulators
200
+ return emulatorId ;
201
+ } ) ;
202
+ } else {
203
+ // We timed out waiting for the boot to happen
204
+ return null ;
205
+ }
197
206
} ) ;
198
207
} ) ;
199
208
} ;
@@ -227,18 +236,25 @@ module.exports.wait_for_emulator = function(uuid) {
227
236
} ;
228
237
229
238
/*
230
- * Waits for the core android process of the emulator to start
239
+ * Waits for the core android process of the emulator to start. Returns a
240
+ * promise that resolves to a boolean indicating success. Not specifying a
241
+ * time_remaining or passing a negative value will cause it to wait forever
231
242
*/
232
- module . exports . wait_for_boot = function ( emulator_id ) {
243
+ module . exports . wait_for_boot = function ( emulator_id , time_remaining ) {
233
244
var self = this ;
234
245
return Adb . shell ( emulator_id , 'ps' )
235
246
. then ( function ( output ) {
236
247
if ( output . match ( / a n d r o i d \. p r o c e s s \. a c o r e / ) ) {
237
- return ;
248
+ return true ;
249
+ } else if ( time_remaining === 0 ) {
250
+ return false ;
238
251
} else {
239
252
process . stdout . write ( '.' ) ;
240
- return Q . delay ( 3000 ) . then ( function ( ) {
241
- return self . wait_for_boot ( emulator_id ) ;
253
+
254
+ // Check at regular intervals
255
+ return Q . delay ( time_remaining < CHECK_BOOTED_INTERVAL ? time_remaining : CHECK_BOOTED_INTERVAL ) . then ( function ( ) {
256
+ var updated_time = time_remaining >= 0 ? Math . max ( time_remaining - CHECK_BOOTED_INTERVAL , 0 ) : time_remaining ;
257
+ return self . wait_for_boot ( emulator_id , updated_time ) ;
242
258
} ) ;
243
259
}
244
260
} ) ;
0 commit comments