@Override
  public void deviceConnected(IDevice device) {
    if (device == null) {
      return;
    }
    if (device.isEmulator()) {
      String serial = device.getSerialNumber();
      Integer port = Integer.parseInt(serial.replace("emulator-", ""));
      String avdName = null;
      TelnetClient client = null;
      try {
        client = new TelnetClient(port);
        avdName = client.sendCommand("avd name");
      } catch (AndroidDeviceException e) {
        String logMessage = "Could not get avdName for device " + serial;
        log.log(Level.WARNING, logMessage, e);
      } finally {
        if (client != null) {
          client.close();
        }
      }
      virtualDevices.put(avdName, device);
      for (AndroidEmulatorPowerStateListener listener : emulatorPowerStateListener) {
        listener.onDeviceStarted(avdName, device.getSerialNumber());
      }
    } else {
      try {
        connectedDevices.put(device, new DefaultHardwareDevice(device));
        for (HardwareDeviceListener listener : deviceListeners) {
          listener.onDeviceConnected(connectedDevices.get(device));
        }
      } catch (DeviceOfflineException doe) {
        // skip devices that are currently "offline"
        log.warning("Skipping adding 'offline' hardware device");
      }
    }
  }
Shutdown the AndroidDebugBridge and clean up all connected devices.
selendroid-standalone/src/main/java/io/selendroid/standalone/android/impl/DefaultDeviceManager.java