Java Code Examples for com.android.ddmlib.AndroidDebugBridge#createBridge()
The following examples show how to use
com.android.ddmlib.AndroidDebugBridge#createBridge() .
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: HJAdb.java From HJMirror with MIT License | 6 votes |
/** * Start and find Devices. */ public IDevice[] startAndFind() throws Exception { if (adb == null) { AndroidDebugBridge.init(false); DdmPreferences.setTimeOut(20000); adb = AndroidDebugBridge.createBridge(getAdbExec(), true); if (adb == null) { throw new Exception("Adb initilized failed!"); } } if (adb.hasInitialDeviceList()) { IDevice[] devices = adb.getDevices(); if (devices != null) { return devices; } else { return new IDevice[]{}; } } return new IDevice[]{}; }
Example 2
Source File: DdmlibAdbServer.java From bundletool with Apache License 2.0 | 6 votes |
/** * Initializes ADB server, optionally restarting it if it points at a different location. * * <p>Can be called multiple times. * * @param pathToAdb location of the ADB server to start. */ @Override public synchronized void init(Path pathToAdb) { checkState(state != State.CLOSED, "Android Debug Bridge has been closed."); if (state.equals(State.INITIALIZED)) { checkState( pathToAdb.equals(this.pathToAdb), "Re-initializing DdmlibAdbServer with a different ADB path. Expected: '%s', got '%s'.", this.pathToAdb, pathToAdb); return; } AndroidDebugBridge.initIfNeeded(/* clientSupport= */ false); this.adb = AndroidDebugBridge.createBridge(pathToAdb.toString(), /* forceNewBridge= */ false); if (adb == null) { throw CommandExecutionException.builder() .withInternalMessage("Failed to start ADB server.") .build(); } this.pathToAdb = pathToAdb; this.state = State.INITIALIZED; }
Example 3
Source File: FrameworkEventManager.java From FuzzDroid with Apache License 2.0 | 6 votes |
public void connectToAndroidDevice() { LoggerHelper.logEvent(MyLevel.RUNTIME, "Connecting to ADB..."); if(adb == null) { AndroidDebugBridge.init(false); // AndroidDebugBridge bridge = AndroidDebugBridge.createBridge( // FrameworkOptions.PLATFORM_TOOLS + File.separator + "adb", true); adb = AndroidDebugBridge.createBridge(); } waitForDevice(); this.device = getDevice(FrameworkOptions.devicePort); if(this.device == null) { LoggerHelper.logEvent(MyLevel.EXCEPTION_RUNTIME, String.format("Device with port %s not found! -- retry it", FrameworkOptions.devicePort)); connectToAndroidDevice(); } LoggerHelper.logEvent(MyLevel.RUNTIME, "Successfully connected to ADB..."); }
Example 4
Source File: AndroidSdkProvider.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
protected void updateAdb() { AndroidSdk sdk = defaultSdk.get(); if (sdk != null) { final FileObject path = sdk.findTool(ADB_TOOL); if (path != null) { ClientData.class.getClassLoader().clearAssertionStatus(); //qattern DebugPortManager.setProvider(DebugPortProvider.getDefault()); AndroidDebugBridge.initIfNeeded(true); String adbLocation = FileUtil.toFile(path).getAbsolutePath(); String lastLocation = adbPath.getAndSet(adbLocation); pcs.firePropertyChange(PROP_DEFAULT_ADB_PATH, lastLocation, adbLocation); AndroidDebugBridge bridge = AndroidDebugBridge.createBridge(adbLocation, false); AndroidDebugBridge lastAdb = adb.getAndSet(bridge); pcs.firePropertyChange(PROP_DEFAULT_ADB, lastAdb, bridge); } } }
Example 5
Source File: AdbDevice.java From AndroidRobot with Apache License 2.0 | 6 votes |
private void initDebugBridge() { if (bridge == null) { AndroidDebugBridge.init(false); } if ((bridge == null) || (!bridge.isConnected())) { String adbLocation = System.getProperty("user.dir"); System.out.println(adbLocation); if ((adbLocation != null) && (adbLocation.length() != 0)) { adbLocation = adbLocation + File.separator + "adb"; File file= new File(adbLocation); if(!file.exists()) adbLocation = "adb"; }else{ adbLocation = "adb"; } bridge = AndroidDebugBridge.createBridge(adbLocation, false); } }
Example 6
Source File: InstrumentationTestRunner.java From buck with Apache License 2.0 | 6 votes |
/** * Creates connection to adb and waits for this connection to be initialized and receive initial * list of devices. */ @Nullable @SuppressWarnings("PMD.EmptyCatchBlock") private AndroidDebugBridge createAdb() throws InterruptedException { AndroidDebugBridge.initIfNeeded(/* clientSupport */ false); AndroidDebugBridge adb = AndroidDebugBridge.createBridge(this.adbExecutablePath, false); if (adb == null) { System.err.println("Failed to connect to adb. Make sure adb server is running."); return null; } long start = System.currentTimeMillis(); while (!isAdbInitialized(adb)) { long timeLeft = start + ADB_CONNECT_TIMEOUT_MS - System.currentTimeMillis(); if (timeLeft <= 0) { break; } Thread.sleep(ADB_CONNECT_TIME_STEP_MS); } return isAdbInitialized(adb) ? adb : null; }
Example 7
Source File: ADB.java From MiniCapAndMiniTouch with Apache License 2.0 | 5 votes |
/** * 初始化adb连接 * @return */ private boolean init() { boolean success = false; if (!hasInitAdb){ String adbPath = getADBPath(); if (adbPath != null) { AndroidDebugBridge.init(false); mAndroidDebugBridge = AndroidDebugBridge.createBridge(adbPath, true); if (mAndroidDebugBridge != null) { success = true; hasInitAdb = true; } // 延时处理adb获取设备信息 if (success) { int loopCount = 0; while (mAndroidDebugBridge.hasInitialDeviceList() == false) { try { Thread.sleep(100); loopCount++; } catch (InterruptedException e) { } if (loopCount > 100) { success = false; break; } } } } } return success; }
Example 8
Source File: AwoInstaller.java From atlas with Apache License 2.0 | 5 votes |
protected static AndroidDebugBridge initAndroidDebugBridge(AndroidBuilder androidBuilder) { synchronized (ADB_LOCK) { if (!adbInitialized) { DdmPreferences.setTimeOut(adbConnectionTimeout); AndroidDebugBridge.init(false); adbInitialized = true; } AndroidDebugBridge androidDebugBridge = AndroidDebugBridge.createBridge( androidBuilder.getSdkInfo().getAdb().getAbsolutePath(), false); waitUntilConnected(androidDebugBridge); return androidDebugBridge; } }
Example 9
Source File: AdbHelper.java From buck with Apache License 2.0 | 5 votes |
/** * Creates connection to adb and waits for this connection to be initialized and receive initial * list of devices. */ @Nullable @SuppressWarnings("PMD.EmptyCatchBlock") private static AndroidDebugBridge createAdb( AndroidPlatformTarget androidPlatformTarget, ExecutionContext context, int adbTimeout) throws InterruptedException { DdmPreferences.setTimeOut(adbTimeout); try { AndroidDebugBridge.init(/* clientSupport */ false); } catch (IllegalStateException ex) { // ADB was already initialized, we're fine, so just ignore. } String adbExecutable = androidPlatformTarget.getAdbExecutable().toString(); log.debug("Using %s to create AndroidDebugBridge", adbExecutable); AndroidDebugBridge adb = AndroidDebugBridge.createBridge(adbExecutable, false); if (adb == null) { context .getConsole() .printBuildFailure("Failed to connect to adb. Make sure adb server is running."); return null; } long start = System.currentTimeMillis(); while (!isAdbInitialized(adb)) { long timeLeft = start + ADB_CONNECT_TIMEOUT_MS - System.currentTimeMillis(); if (timeLeft <= 0) { break; } Thread.sleep(ADB_CONNECT_TIME_STEP_MS); } return isAdbInitialized(adb) ? adb : null; }
Example 10
Source File: ADB.java From agent with MIT License | 4 votes |
public static void addDeviceChangeListener(AndroidDebugBridge.IDeviceChangeListener deviceChangeListener) { AndroidDebugBridge.init(false); AndroidDebugBridge.createBridge(getPath(), false); AndroidDebugBridge.addDeviceChangeListener(deviceChangeListener); }
Example 11
Source File: DeviceConnectHelper.java From Android-Monkey-Adapter with Apache License 2.0 | 4 votes |
public static void init(final String adbLocation) { AndroidDebugBridge.init(false); AndroidDebugBridge.createBridge(adbLocation, true); }
Example 12
Source File: ADB.java From android-screen-monitor with Apache License 2.0 | 4 votes |
public boolean initialize(String[] args) { boolean success = true; String adbLocation = System .getProperty("com.android.screenshot.bindir"); // You can specify android sdk directory using first argument // A) If you lunch jar from eclipse, set arguments in Run/Debug configurations to android sdk directory . // /Applications/adt-bundle-mac-x86_64/sdk // A) If you lunch jar from terminal, set arguments to android sdk directory or $ANDROID_HOME environment variable. // java -jar ./jar/asm.jar $ANDROID_HOME if (adbLocation == null) { if ((args != null) && (args.length > 0)) { adbLocation = args[0]; } else { adbLocation = System.getenv("ANDROID_HOME"); } // Here, adbLocation may be android sdk directory if (adbLocation != null) { adbLocation += File.separator + "platform-tools"; } } // for debugging (follwing line is a example) // adbLocation = "C:\\ ... \\android-sdk-windows\\platform-tools"; // Windows // adbLocation = "/ ... /adt-bundle-mac-x86_64/sdk/platform-tools"; // MacOS X if (success) { if ((adbLocation != null) && (adbLocation.length() != 0)) { adbLocation += File.separator + "adb"; } else { adbLocation = "adb"; } System.out.println("adb path is " + adbLocation); AndroidDebugBridge.init(false); mAndroidDebugBridge = AndroidDebugBridge.createBridge(adbLocation, true); if (mAndroidDebugBridge == null) { success = false; } } if (success) { int count = 0; while (mAndroidDebugBridge.hasInitialDeviceList() == false) { try { Thread.sleep(100); count++; } catch (InterruptedException e) { } if (count > 100) { success = false; break; } } } if (!success) { terminate(); } return success; }