com.android.ddmlib.AndroidDebugBridge Java Examples
The following examples show how to use
com.android.ddmlib.AndroidDebugBridge.
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: DeviceConnectHelper.java From Android-Monkey-Adapter with Apache License 2.0 | 6 votes |
public IDevice waitForDeviceConnected(final String serialNumber, final long timeout) throws InterruptedException { id = serialNumber; Console.printLogMessage(serialNumber, "waitForDeviceConnected(" + serialNumber + " to be connected start"); IDevice [] devices = AndroidDebugBridge.getBridge().getDevices(); if (devices != null) { for (IDevice device : devices) { if (device.getSerialNumber() == serialNumber) { Console.printLogMessage("", device.getSerialNumber()); return device; } } } AndroidDebugBridge.addDebugBridgeChangeListener(DeviceConnectHelper.this); AndroidDebugBridge.addDeviceChangeListener(DeviceConnectHelper.this); synchronized (this) { while (getConnecedDevice(serialNumber) == null) { Console.printLogMessage("", "wait"); wait(60000); } } Console.printLogMessage(serialNumber, "waitForDeviceConnected(" + serialNumber + " to be connected end"); return getConnecedDevice(serialNumber); }
Example #2
Source File: MyDeviceChooser.java From ADB-Duang with MIT License | 6 votes |
@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 #3
Source File: RestartADBAction.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(ActionEvent e) { final AndroidDebugBridge debugBridge = AndroidSdkProvider.getAdb(); if (debugBridge != null) { RequestProcessor.getDefault().post(new Runnable() { @Override public void run() { StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(MobileDeviceNode.class, "MSG_restarting_ADB")); boolean status = debugBridge.restart(); StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage( MobileDeviceNode.class, status ? "MSG_ADB_restart_success" : "MSG_ADB_restart_fail")); } }); } else { StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(MobileDeviceNode.class, "ERR_cannot_restart_ADB")); } }
Example #4
Source File: MyDeviceChooser.java From ADBWIFI with Apache License 2.0 | 6 votes |
@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 #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: DevicesNode.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
@Override public PropertySet[] getPropertySets() { final Sheet.Set set = Sheet.createPropertiesSet(); set.put(new PropertySupport.ReadOnly<Boolean>( "PROP_DebugBridgeConnected", Boolean.class, NbBundle.getMessage(DevicesNode.class, "PROP_DebugBridgeConnected"), NbBundle.getMessage(DevicesNode.class, "DESC_DebugBridgeConnected")) { @Override public Boolean getValue() throws IllegalAccessException, InvocationTargetException { final AndroidDebugBridge jp = AndroidSdkProvider.getAdb(); return jp == null ? Boolean.FALSE : jp.isConnected(); } }); return new PropertySet[]{ set }; }
Example #7
Source File: LogSourceManager.java From logviewer with Apache License 2.0 | 6 votes |
@Override public void dispose() { AndroidDebugBridge.removeClientChangeListener(this); for (DeviceLogSource deviceLogSource : deviceLogSourcesMap.values()) { deviceLogSource.getLogProvider().dispose(); } for (LogSource fileLogSource : fileLogSourcesMap.values()) { fileLogSource.getLogProvider().dispose(); } if (myBridge != null) { AndroidDebugBridge.removeDeviceChangeListener(this); AndroidDebugBridge.removeDebugBridgeChangeListener(this); myBridge = null; } deviceLogSourcesMap.clear(); }
Example #8
Source File: LogSourceManager.java From logviewer with Apache License 2.0 | 6 votes |
/** * Observe for deviec state changes */ private void observeForDeviceChange() { deviceSelectionListener = new DeviceContext.DeviceSelectionListener() { @Override public void deviceSelected(@Nullable IDevice device) { notifyDeviceUpdated(device); } @Override public void deviceChanged(@NotNull IDevice device, int changeMask) { if ((changeMask & IDevice.CHANGE_STATE) == IDevice.CHANGE_STATE) { notifyDeviceUpdated(device); } } @Override public void clientSelected(@Nullable final Client c) { } }; deviceContext.addListener(deviceSelectionListener, this); AndroidDebugBridge.addClientChangeListener(this); AndroidDebugBridge.addDeviceChangeListener(this); AndroidDebugBridge.addDebugBridgeChangeListener(this); }
Example #9
Source File: AwoInstaller.java From atlas with Apache License 2.0 | 6 votes |
/** * 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 #10
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 #11
Source File: InstrumentationTestRunner.java From buck with Apache License 2.0 | 6 votes |
@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 #12
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 #13
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 #14
Source File: Main.java From FuzzDroid with Apache License 2.0 | 6 votes |
public static void main(String[] args) { Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { LoggerHelper.logEvent(MyLevel.TIMEOUT, "-1 | Complete analysis stopped due to timeout of 40 minutes"); System.exit(0); } }, 40 * 60000); try{ Main.v().run(args); AndroidDebugBridge.terminate(); }catch(Exception ex) { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); ex.printStackTrace(pw); LoggerHelper.logEvent(MyLevel.EXCEPTION_ANALYSIS, sw.toString()); UtilMain.writeToFile("mainException.txt", FrameworkOptions.apkPath + "\n"); } LoggerHelper.logEvent(MyLevel.EXECUTION_STOP, "Analysis successfully terminated"); //this is necessary otherwise we will wait for a max of 20 minutes for the TimerTask System.exit(0); }
Example #15
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 #16
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 #17
Source File: AdbNode.java From NBANDROID-V2 with Apache License 2.0 | 6 votes |
@Override public PropertySet[] getPropertySets() { final Sheet.Set set = Sheet.createPropertiesSet(); set.put(new PropertySupport.ReadOnly<Boolean>( "PROP_DebugBridgeConnected", Boolean.class, NbBundle.getMessage(DevicesNode.class, "PROP_DebugBridgeConnected"), NbBundle.getMessage(DevicesNode.class, "DESC_DebugBridgeConnected")) { @Override public Boolean getValue() throws IllegalAccessException, InvocationTargetException { final AndroidDebugBridge jp = AndroidSdkProvider.getAdb(); return jp == null ? Boolean.FALSE : jp.isConnected(); } }); return new PropertySet[]{ set }; }
Example #18
Source File: DeviceConnectHelper.java From Android-Monkey-Adapter with Apache License 2.0 | 5 votes |
public IDevice getConnecedDevice(final String serialNumber) { for (IDevice device : AndroidDebugBridge.getBridge().getDevices()) { if (serialNumber.equals(device.getSerialNumber()) && device.getState() == DeviceState.ONLINE) { return device; } } return null; }
Example #19
Source File: AdbNode.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private void updateDescription() { setName(NAME); setDisplayName(NAME); final AndroidDebugBridge debugBridge = AndroidSdkProvider.getAdb(); broken = debugBridge == null; String description = broken ? "Debugbridge broken! Please restart ADB!" : NAME; setShortDescription(description); }
Example #20
Source File: Installer.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
@Override public void close() { // TODO(radim): if we really need it then it belongs to core where ADBfactory lives AndroidDebugBridge adb = AndroidSdkProvider.getAdb(); if (adb != null && adb.isConnected()) { AndroidDebugBridge.disconnectBridge(); } }
Example #21
Source File: LogDevicesComboBoxSupport.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
protected LogDevicesComboBoxSupport(LogReader reader) { this.reader = reader; // get notification for logged devices reader.addPropertyChangeListener(WeakListeners.propertyChange(this, reader)); // get notifications for attached and detached devices AndroidDebugBridge.addDeviceChangeListener(this); Lookup lookup = Utilities.actionsGlobalContext(); deviceLookup = lookup.lookupResult(IDevice.class); deviceLookup.addLookupListener(this); update(); }
Example #22
Source File: MyDeviceChooser.java From ADB-Duang with MIT License | 5 votes |
@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 #23
Source File: ConnectBlazeTestDebuggerTask.java From intellij with Apache License 2.0 | 5 votes |
/** * Wires up listeners to automatically reconnect the debugger for each test method. When you * `blaze test` an android_test in debug mode, it kills the instrumentation process between each * test method, disconnecting the debugger. We listen for the start of a new method waiting for a * debugger, and reconnect. TODO: Support stopping Blaze from the UI. This is hard because we have * no way to distinguish process handler termination/debug session ending initiated by the user. */ private void setUpForReattachingDebugger( String targetPackage, LaunchInfo launchInfo, ProcessHandlerLaunchStatus launchStatus, ProcessHandlerConsolePrinter printer) { final AndroidDebugBridge.IClientChangeListener reattachingListener = new AndroidDebugBridge.IClientChangeListener() { // The target application can either // 1. Match our target name, and become available for debugging. // 2. Be available for debugging, and suddenly have its name changed to match. static final int CHANGE_MASK = Client.CHANGE_DEBUGGER_STATUS | Client.CHANGE_NAME; @Override public void clientChanged(@NotNull Client client, int changeMask) { ClientData data = client.getClientData(); String clientDescription = data.getClientDescription(); if (clientDescription != null && clientDescription.equals(targetPackage) && (changeMask & CHANGE_MASK) != 0 && data.getDebuggerConnectionStatus().equals(ClientData.DebuggerStatus.WAITING)) { reattachDebugger(launchInfo, client, launchStatus, printer); } } }; AndroidDebugBridge.addClientChangeListener(reattachingListener); runContext.addLaunchTaskCompleteListener( () -> { AndroidDebugBridge.removeClientChangeListener(reattachingListener); launchStatus.terminateLaunch("Test run completed.\n", true); }); }
Example #24
Source File: MyDeviceChooser.java From ADBWIFI with Apache License 2.0 | 5 votes |
@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 #25
Source File: AdbWifiConnect.java From ADBWIFI with Apache License 2.0 | 5 votes |
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 #26
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 #27
Source File: MonkeyTestDevice.java From Android-Monkey-Adapter with Apache License 2.0 | 5 votes |
public boolean connect() { boolean result = false; for (IDevice device : AndroidDebugBridge.getBridge().getDevices()) { if (mDevice.getSerialNumber().equals(device.getSerialNumber()) && mDevice.getState() == DeviceState.ONLINE) { mDevice = device; result = true; break; } } return result; }
Example #28
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 #29
Source File: RealAndroidDevice.java From buck with Apache License 2.0 | 5 votes |
private SocketChannel getSyncService() throws Exception { // Create a socket and send the necessary requests to adb daemon SocketChannel chan = SocketChannel.open(AndroidDebugBridge.getSocketAddress()); // Set a timeout for the blocking channel chan.socket().setSoTimeout(DEFAULT_TIMEOUT); // Set the channel to be blocking chan.configureBlocking(true); String msg = "host:transport:" + device.getSerialNumber(); byte[] device_query = formAdbRequest(msg); // req = length + command writeAllToChannel(chan, ByteBuffer.wrap(device_query)); byte[] resp = readResp(chan, 4); if (!isOkay(resp)) { throw new HumanReadableException( "ADB daemon rejected switching connection to " + device.getSerialNumber()); } byte[] sync_req = formAdbRequest("sync:"); ByteBuffer b = ByteBuffer.wrap(sync_req); writeAllToChannel(chan, b); if (!isOkay(readResp(chan, 4))) { throw new HumanReadableException( "ADB daemon rejected starting sync service to " + device.getSerialNumber()); } return chan; }
Example #30
Source File: DevicesNode.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private void updateDescription() { setName(NAME); setDisplayName(NAME); final AndroidDebugBridge debugBridge = AndroidSdkProvider.getAdb(); broken = debugBridge == null; String description = broken ? "Debugbridge broken! Please restart ADB!" : NAME; setShortDescription(description); }