code: public synchronized AndroidDevice findAndroidDevice(SelendroidCapabilities caps) throws DeviceStoreException {
  
      Preconditions.checkArgument(caps != null, "Error: capabilities are null");
  
      if (androidDevices.isEmpty()) {
        throw new DeviceStoreException("Fatal Error: Device Store does not contain any Android Device.");
      }
  
      String platformVersion = caps.getPlatformVersion();
  
      Iterable<AndroidDevice> candidateDevices = Strings.isNullOrEmpty(platformVersion) ?
          Iterables.concat(androidDevices.values()) : androidDevices.get(DeviceTargetPlatform.fromPlatformVersion(platformVersion));
  
      candidateDevices = MoreObjects.firstNonNull(candidateDevices, Collections.EMPTY_LIST);
  
      FluentIterable<AndroidDevice> allMatchingDevices = FluentIterable.from(candidateDevices)
          .filter(deviceNotInUse())
          .filter(deviceSatisfiesCapabilities(caps));
  
      if (!allMatchingDevices.isEmpty()) {
  
        AndroidDevice matchingDevice = allMatchingDevices.filter(deviceRunning()).first()
            .or(allMatchingDevices.first()).get();
  
        if (!deviceRunning().apply(matchingDevice)) {
          log.info("Using potential match: " + matchingDevice);
        }
  
        devicesInUse.add(matchingDevice);
        return matchingDevice;
  
      } else {
        throw new DeviceStoreException("No devices are found. "
            + "This can happen if the devices are in use or no device screen "
            + "matches the required capabilities.");
      }
    }
docs: Finds a device for the requested capabilities. <b>important note:</b> if the device is not any
  longer used, call the {@link #release(AndroidDevice, AndroidApp)} method.
  
  @param caps The desired test session capabilities.
  @return Matching device for a test session.
  @throws DeviceStoreException
  @see {@link #release(AndroidDevice, AndroidApp)}