protected void initializeAdbConnection ( ) { // Get a device bridge instance. Initialize, create and restart. try { AndroidDebugBridge . init ( false ) ; } catch ( IllegalStateException e ) { if ( ! shouldKeepAdbAlive ) { log . log ( Level . WARNING , "AndroidDebugBridge may have been already initialized at this point. It is OK to proceed." , e ) ; } } bridge = AndroidDebugBridge . getBridge ( ) ; if ( bridge == null ) { bridge = AndroidDebugBridge . createBridge ( adbPath , false ) ; } IDevice [ ] devices = bridge . getDevices ( ) ; AndroidDebugBridge . addDeviceChangeListener ( this ) ; // Add the existing devices to the list of devices we are tracking. if ( devices . length > 0 ) { for ( int i = 0 ; i < devices . length ; i ++ ) { deviceConnected ( devices [ i ] ) ; log . info ( "my devices: " + devices [ i ] . getAvdName ( ) ) ; } } else { long timeout = System . currentTimeMillis ( ) + 2000 ; while ( ( devices = bridge . getDevices ( ) ) . length == 0 && System . currentTimeMillis ( ) < timeout ) { try { Thread . sleep ( 50 ) ; } catch ( InterruptedException e ) { throw new RuntimeException ( e ) ; } } if ( devices . length > 0 ) { for ( int i = 0 ; i < devices . length ; i ++ ) { deviceConnected ( devices [ i ] ) ; log . info ( "my devices: " + devices [ i ] . getAvdName ( ) ) ; } } } }
Initializes the AndroidDebugBridge and registers the DefaultHardwareDeviceManager with the AndroidDebugBridge device change listener .