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

The following examples show how to use com.android.ddmlib.AndroidDebugBridge#hasInitialDeviceList() . 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: AwoInstaller.java    From atlas with Apache License 2.0 6 votes vote down vote up
/**
 * Wait for the Android Debug Bridge to return an initial device list.
 */
protected static void waitForInitialDeviceList(final AndroidDebugBridge androidDebugBridge, Logger logger) {
    if (!androidDebugBridge.hasInitialDeviceList()) {
        logger.info("Waiting for initial device list from the Android Debug Bridge");
        long limitTime = System.currentTimeMillis() + ADB_TIMEOUT_MS;
        while (!androidDebugBridge.hasInitialDeviceList() && (System.currentTimeMillis() < limitTime)) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException("Interrupted waiting for initial device list from Android Debug Bridge");
            }
        }
        if (!androidDebugBridge.hasInitialDeviceList()) {
            logger.error("Did not receive initial device list from the Android Debug Bridge.");
        }
    }
}
 
Example 2
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 3
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);
}
 
Example 4
Source File: InstrumentationTestRunner.java    From buck with Apache License 2.0 4 votes vote down vote up
private boolean isAdbInitialized(AndroidDebugBridge adb) {
  return adb.isConnected() && adb.hasInitialDeviceList();
}
 
Example 5
Source File: AdbHelper.java    From buck with Apache License 2.0 4 votes vote down vote up
private static boolean isAdbInitialized(AndroidDebugBridge adb) {
  return adb.isConnected() && adb.hasInitialDeviceList();
}