Java Code Examples for org.jetbrains.android.sdk.AndroidSdkUtils#getDebugBridge()

The following examples show how to use org.jetbrains.android.sdk.AndroidSdkUtils#getDebugBridge() . 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: MyDeviceChooser.java    From ADB-Duang with MIT License 6 votes vote down vote up
@NotNull
public IDevice[] getSelectedDevices() {
  int[] rows = mySelectedRows != null ? mySelectedRows : myDeviceTable.getSelectedRows();
  List<IDevice> result = new ArrayList<IDevice>();
  for (int row : rows) {
    if (row >= 0) {
      Object serial = myDeviceTable.getValueAt(row, SERIAL_COLUMN_INDEX);
      final AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(myFacet.getModule().getProject());
      if (bridge == null) {
        return EMPTY_DEVICE_ARRAY;
      }
      IDevice[] devices = getFilteredDevices(bridge);
      for (IDevice device : devices) {
        if (device.getSerialNumber().equals(serial.toString())) {
          result.add(device);
          break;
        }
      }
    }
  }
  return result.toArray(new IDevice[result.size()]);
}
 
Example 2
Source File: ToolWindowFactory.java    From adc with Apache License 2.0 6 votes vote down vote up
public void createToolWindowContent(@NotNull final Project project, @NotNull final ToolWindow toolWindow) {
    ContentFactory contentFactory = ContentFactory.SERVICE.getInstance();
    JPanel framePanel = createPanel(project);
    disableAll();

    AndroidDebugBridge adb = AndroidSdkUtils.getDebugBridge(project);
    if (adb == null) {
        return;
    }

    if(adb.isConnected()){
        ToolWindowFactory.this.adBridge = adb;
        Logger.getInstance(ToolWindowFactory.class).info("Successfully obtained debug bridge");
        AndroidDebugBridge.addDeviceChangeListener(deviceChangeListener);
        updateDeviceComboBox();
    } else {
        Logger.getInstance(ToolWindowFactory.class).info("Unable to obtain debug bridge");
        String msg = MessageFormat.format(resourceBundle.getString("error.message.adb"), "");
        Messages.showErrorDialog(msg, resourceBundle.getString("error.title.adb"));
    }

    Content content = contentFactory.createContent(framePanel, "", false);
    toolWindow.getContentManager().addContent(content);
}
 
Example 3
Source File: MyDeviceChooser.java    From ADBWIFI with Apache License 2.0 6 votes vote down vote up
@NotNull
public IDevice[] getSelectedDevices() {
  int[] rows = mySelectedRows != null ? mySelectedRows : myDeviceTable.getSelectedRows();
  List<IDevice> result = new ArrayList<IDevice>();
  for (int row : rows) {
    if (row >= 0) {
      Object serial = myDeviceTable.getValueAt(row, SERIAL_COLUMN_INDEX);
      final AndroidDebugBridge bridge = AndroidSdkUtils.getDebugBridge(myFacet.getModule().getProject());
      if (bridge == null) {
        return EMPTY_DEVICE_ARRAY;
      }
      IDevice[] devices = getFilteredDevices(bridge);
      for (IDevice device : devices) {
        if (device.getSerialNumber().equals(serial.toString())) {
          result.add(device);
          break;
        }
      }
    }
  }
  return result.toArray(new IDevice[result.size()]);
}
 
Example 4
Source File: WindowTool.java    From ADB-Duang with MIT License 5 votes vote down vote up
private boolean initDevices(Project project) {
    boolean update = true;
    if (bridge == null) {
        bridge = AndroidSdkUtils.getDebugBridge(project);
    }
    deviceList.clear();
    if (bridge != null) {
        IDevice[] devices = bridge.getDevices();
        if (devices != null) {
            for (IDevice device : devices) {
                if (selectDevice != null) {
                    if (device.getName().equals(selectDevice.getName()) && device.getSerialNumber().equals(selectDevice.getSerialNumber())) {
                        selectDevice = device;
                        update = false;
                    }
                }
                deviceList.add(device);
            }
        }
        if (deviceList.size() > 0 && selectDevice == null) {
            selectDevice = deviceList.get(0);
            update = true;
        }
    } else {
        update = false;
    }
    return update;
}
 
Example 5
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 6
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);
}