@@ -915,7 +915,9 @@ def connectToDeviceOrExit(timeout=60, verbose=False, ignoresecuredevice=False):
915915 # eat all the extra options the invoking script may have added
916916 while len (sys .argv ) > 1 and sys .argv [1 ][0 ] == '-' :
917917 sys .argv .pop (1 )
918- serialno = sys .argv [1 ] if len (sys .argv ) > 1 else '.*'
918+ serialno = sys .argv [1 ] if len (sys .argv ) > 1 else \
919+ os .environ ['ANDROID_SERIAL' ] if os .environ .has_key ('ANDROID_SERIAL' ) \
920+ else '.*'
919921 if verbose :
920922 print 'Connecting to a device with serialno=%s with a timeout of %d secs...' % (serialno , timeout )
921923 # Sometimes MonkeyRunner doesn't even timeout (i.e. two connections from same process), so let's
@@ -934,14 +936,14 @@ def connectToDeviceOrExit(timeout=60, verbose=False, ignoresecuredevice=False):
934936 device .wake ()
935937 except java .lang .NullPointerException , e :
936938 print >> sys .stderr , "%s: ERROR: Couldn't connect to %s: %s" % (progname , serialno , e )
937- sys .exit (1 )
939+ sys .exit (3 )
938940 if verbose :
939941 print 'Connected to device with serialno=%s' % serialno
940942 secure = device .getSystemProperty ('ro.secure' )
941943 debuggable = device .getSystemProperty ('ro.debuggable' )
942944 if secure == '1' and debuggable == '0' and not ignoresecuredevice :
943945 print >> sys .stderr , "%s: ERROR: Device is secure, AndroidViewClient won't work." % progname
944- sys .exit (1 )
946+ sys .exit (2 )
945947 if re .search ("[.*()+]" , serialno ):
946948 # if a regex was used we have to determine the serialno used
947949 serialno = ViewClient .__obtainDeviceSerialNumber (device )
0 commit comments