Java Code Examples for com.android.ddmlib.AndroidDebugBridge#getDevices()

The following examples show how to use com.android.ddmlib.AndroidDebugBridge#getDevices() . 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: InstrumentationTestRunner.java    From buck with Apache License 2.0 6 votes vote down vote up
@Nullable
private IDevice getDevice(String serial) throws InterruptedException {
  AndroidDebugBridge adb = createAdb();

  if (adb == null) {
    System.err.println("Unable to set up adb.");
    System.exit(1);
  }

  IDevice[] allDevices = adb.getDevices();
  for (IDevice device : allDevices) {
    if (device.getSerialNumber().equals(serial)) {
      return device;
    }
  }
  return null;
}
 
Example 2
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 3
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 4
Source File: MyDeviceChooser.java    From ADB-Duang with MIT License 5 votes vote down vote up
@NotNull
private IDevice[] getFilteredDevices(AndroidDebugBridge bridge) {
  final List<IDevice> filteredDevices = new ArrayList<IDevice>();
  for (IDevice device : bridge.getDevices()) {
    if (myFilter == null || myFilter.value(device)) {
      filteredDevices.add(device);
    }
  }
  // Do not filter launching cloud device as they are just unselectable progress markers
  // that are replaced with the actual cloud device as soon as they are up and the actual cloud device will be filtered above.
  return filteredDevices.toArray(new IDevice[filteredDevices.size()]);
}
 
Example 5
Source File: MyDeviceChooser.java    From ADBWIFI with Apache License 2.0 5 votes vote down vote up
@NotNull
private IDevice[] getFilteredDevices(AndroidDebugBridge bridge) {
  final List<IDevice> filteredDevices = new ArrayList<IDevice>();
  for (IDevice device : bridge.getDevices()) {
    if (myFilter == null || myFilter.value(device)) {
      filteredDevices.add(device);
    }
  }
  // Do not filter launching cloud devices as they are just unselectable progress markers
  // that are replaced with the actual cloud devices as soon as they are up and the actual cloud devices will be filtered above.
  return filteredDevices.toArray(new IDevice[filteredDevices.size()]);
}
 
Example 6
Source File: AdbWifiConnect.java    From ADBWIFI with Apache License 2.0 5 votes vote down vote up
private static DeviceResult getDevice(Project project) {
    List<AndroidFacet> facets = getApplicationFacets(project);
    if (!facets.isEmpty()) {
        AndroidFacet facet = facets.get(0);
        String packageName = AdbUtil.computePackageName(facet);
        AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(project);
        if (bridge == null) {
            error("No platform configured");
            return null;
        }
        int count = 0;
        while (!bridge.isConnected() || !bridge.hasInitialDeviceList()) {
            try {
                Thread.sleep(100);
                count++;
            } catch (InterruptedException e) {
                // pass
            }

            // let's not wait > 10 sec.
            if (count > 100) {
                error("Timeout getting device list!");
                return null;
            }
        }

        IDevice[] devices = bridge.getDevices();
        if (devices.length == 1) {
            return new DeviceResult(devices, facet, packageName);
        } else if (devices.length > 1) {
            return askUserForDevice(facet, packageName);
        } else {
            return null;
        }

    }
    error("No devices found");
    return null;
}
 
Example 7
Source File: BaseAction.java    From ADB-Duang with MIT License 4 votes vote down vote up
private DeviceResult getDevice(AnActionEvent anActionEvent) {
    List<AndroidFacet> facets = getApplicationFacets(anActionEvent.getProject());
    if (!facets.isEmpty()) {

        AndroidFacet facet = null;

        String androidFacetName = getAndroidFacetName(anActionEvent);

        if (androidFacetName != null) {
            for (AndroidFacet androidFacet : facets) {
                if (androidFacet.getModule().getName().equals(androidFacetName)) {
                    facet = androidFacet;
                }
            }
            if (facet == null) {
                return null;
            }

        } else {

            if (facets.size() > 1) {
                facet = ModuleChooserDialogHelper.showDialogForFacets(anActionEvent.getProject(), facets);
                if (facet == null) {
                    return null;
                }
            } else {
                facet = facets.get(0);
            }
        }
        String packageName =facet.getAndroidModuleInfo().getPackage();
        AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(anActionEvent.getProject());
        if (bridge == null) {
            error("No platform configured");
            return null;
        }

        if (bridge.isConnected() && bridge.hasInitialDeviceList()) {

            IDevice[] devices = bridge.getDevices();
            if (devices.length == 1) {
                return new DeviceResult(anActionEvent, devices[0], facet, packageName);
            } else if (devices.length > 1) {
                return askUserForDevice(anActionEvent, facet, packageName);
            } else {
                return new DeviceResult(anActionEvent, null, facet, null);
            }
        }
    }
    return new DeviceResult(anActionEvent, null, null, null);
}