Java Code Examples for com.android.ddmlib.IDevice#isOnline()

The following examples show how to use com.android.ddmlib.IDevice#isOnline() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdbUtils.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public static Map<String,IDevice> getRunningEmulators(){
    Map<String,IDevice> tmp = new HashMap<>();
    AndroidDebugBridge debugBridge = AndroidSdkProvider.getAdb();
    if(debugBridge!=null){
        for (IDevice device : debugBridge.getDevices()) {
            if(device.isEmulator() && device.isOnline()){
                tmp.put(device.getAvdName(), device);
            }
        }
    }
    return tmp;
}
 
Example 2
Source File: InstallApkAction.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
private void refresh(Node[] activatedNodes) {
    menu.removeAll();
    AndroidDebugBridge debugBridge = AndroidSdkProvider.getAdb();
    if(debugBridge!=null){
        for (IDevice device : debugBridge.getDevices()) {
            if (device.isOnline()) {
                menu.add(new MenuItemWithDevice(device,activatedNodes[0]));
            }
        }
    }
}
 
Example 3
Source File: AdbHelper.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Returns list of devices that pass the filter. If there is an invalid combination or no devices
 * are left after filtering this function prints an error and returns null.
 */
@Nullable
@VisibleForTesting
List<IDevice> filterDevices(IDevice[] allDevices) {
  if (allDevices.length == 0) {
    printError("No devices are found.");
    return null;
  }

  List<IDevice> devices = new ArrayList<>();
  Optional<Boolean> emulatorsOnly = Optional.empty();
  if (deviceOptions.isEmulatorsOnlyModeEnabled() && options.isMultiInstallModeEnabled()) {
    emulatorsOnly = Optional.empty();
  } else if (deviceOptions.isEmulatorsOnlyModeEnabled()) {
    emulatorsOnly = Optional.of(true);
  } else if (deviceOptions.isRealDevicesOnlyModeEnabled()) {
    emulatorsOnly = Optional.of(false);
  }

  int onlineDevices = 0;
  for (IDevice device : allDevices) {
    boolean passed = false;
    if (device.isOnline()) {
      onlineDevices++;

      boolean serialMatches = true;
      if (deviceOptions.getSerialNumber().isPresent()) {
        serialMatches = device.getSerialNumber().equals(deviceOptions.getSerialNumber().get());
      } else if (getEnvironment().containsKey(SERIAL_NUMBER_ENV)) {
        serialMatches = device.getSerialNumber().equals(getEnvironment().get(SERIAL_NUMBER_ENV));
      }

      // Only devices of specific type are accepted:
      // either real devices only or emulators only.
      // All online devices match.
      boolean deviceTypeMatches =
          emulatorsOnly
              .map(isEmulatorOnly -> (isEmulatorOnly == createDevice(device).isEmulator()))
              .orElse(true);
      passed = serialMatches && deviceTypeMatches;
    }

    if (passed) {
      devices.add(device);
    }
  }

  // Filtered out all devices.
  if (onlineDevices == 0) {
    printError("No devices are found.");
    return null;
  }

  if (devices.isEmpty()) {
    printError(
        String.format(
            "Found %d connected device(s), but none of them matches specified filter.",
            onlineDevices));
    return null;
  }

  return devices;
}