device-api/src/main/java/com/github/cosysoft/device/android/impl/AndroidDeviceStore.java
protected void initializeAdbConnection() {
    // Get a device bridge instance. Initialize, create and restart.
    try {
      AndroidDebugBridge.init(true);
    } catch (IllegalStateException e) {
      // When we keep the adb connection alive the AndroidDebugBridge may
      // have been already
      // initialized at this point and it generates an exception. Do not
      // print it.
      if (!shouldKeepAdbAlive) {
        logger.error(
            "The IllegalStateException is not a show "
                + "stopper. It has been handled. This is just debug spew. Please proceed.",
            e);
        throw new NestedException("ADB init failed", e);
      }
    }

    bridge = AndroidDebugBridge.getBridge();

    if (bridge == null) {
      bridge = AndroidDebugBridge.createBridge(AndroidSdk.adb()
          .getAbsolutePath(), false);
    }

    long timeout = System.currentTimeMillis() + 60000;
    while (!bridge.hasInitialDeviceList()
        && System.currentTimeMillis() < timeout) {
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
    // Add the existing devices to the list of devices we are tracking.
    IDevice[] devices = bridge.getDevices();
    logger.info("initialDeviceList size {}", devices.length);
    for (int i = 0; i < devices.length; i++) {
      logger.info("devices state: {},{} ", devices[i].getName(),
          devices[i].getState());
      connectedDevices.put(devices[i], new DefaultHardwareDevice(
          devices[i]));
    }

    bridge.addDeviceChangeListener(new DeviceChangeListener(connectedDevices));
  }
protected void initializeAdbConnection() {
    // Get a device bridge instance. Initialize, create and restart.
    try {
      AndroidDebugBridge.init(true);
    } catch (IllegalStateException e) {
      // When we keep the adb connection alive the AndroidDebugBridge may
      // have been already
      // initialized at this point and it generates an exception. Do not
      // print it.
      if (!shouldKeepAdbAlive) {
        logger.error(
            "The IllegalStateException is not a show "
                + "stopper. It has been handled. This is just debug spew. Please proceed.",
            e);
        throw new NestedException("ADB init failed", e);
      }
    }

    bridge = AndroidDebugBridge.getBridge();

    if (bridge == null) {
      bridge = AndroidDebugBridge.createBridge(AndroidSdk.adb()
          .getAbsolutePath(), false);
    }

    long timeout = System.currentTimeMillis() + 60000;
    while (!bridge.hasInitialDeviceList()
        && System.currentTimeMillis() < timeout) {
      try {
        Thread.sleep(50);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
    }
    // Add the existing devices to the list of devices we are tracking.
    IDevice[] devices = bridge.getDevices();
    logger.info("initialDeviceList size {}", devices.length);
    for (int i = 0; i < devices.length; i++) {
      logger.info("devices state: {},{} ", devices[i].getName(),
          devices[i].getState());
      connectedDevices.put(devices[i], new DefaultHardwareDevice(
          devices[i]));
    }

    bridge.addDeviceChangeListener(new DeviceChangeListener(connectedDevices));
  }
protected void initializeAdbConnection ( ) { // Get a device bridge instance. Initialize, create and restart. try { AndroidDebugBridge . init ( true ) ; } catch ( IllegalStateException e ) { // When we keep the adb connection alive the AndroidDebugBridge may // have been already // initialized at this point and it generates an exception. Do not // print it. if ( ! shouldKeepAdbAlive ) { logger . error ( "The IllegalStateException is not a show " + "stopper. It has been handled. This is just debug spew. Please proceed." , e ) ; throw new NestedException ( "ADB init failed" , e ) ; } } bridge = AndroidDebugBridge . getBridge ( ) ; if ( bridge == null ) { bridge = AndroidDebugBridge . createBridge ( AndroidSdk . adb ( ) . getAbsolutePath ( ) , false ) ; } long timeout = System . currentTimeMillis ( ) + 60000 ; while ( ! bridge . hasInitialDeviceList ( ) && System . currentTimeMillis ( ) < timeout ) { try { Thread . sleep ( 50 ) ; } catch ( InterruptedException e ) { throw new RuntimeException ( e ) ; } } // Add the existing devices to the list of devices we are tracking. IDevice [ ] devices = bridge . getDevices ( ) ; logger . info ( "initialDeviceList size {}" , devices . length ) ; for ( int i = 0 ; i < devices . length ; i ++ ) { logger . info ( "devices state: {},{} " , devices [ i ] . getName ( ) , devices [ i ] . getState ( ) ) ; connectedDevices . put ( devices [ i ] , new DefaultHardwareDevice ( devices [ i ] ) ) ; } bridge . addDeviceChangeListener ( new DeviceChangeListener ( connectedDevices ) ) ; }
Initializes the AndroidDebugBridge and registers the DefaultHardwareDeviceManager with the
AndroidDebugBridge device change listener.
Initializes the AndroidDebugBridge and registers the DefaultHardwareDeviceManager with the AndroidDebugBridge device change listener .