private void initiatePropertiesQuery() { String threadName = String.format("query-prop-%s", mDevice.getSerialNumber()); Thread propThread = new Thread(threadName) { @Override public void run() { try { GetPropReceiver propReceiver = new GetPropReceiver(); mDevice.executeShellCommand(GETPROP_COMMAND, propReceiver, GETPROP_TIMEOUT_SEC, TimeUnit.SECONDS); populateCache(propReceiver.getCollectedProperties()); } catch (Exception e) { handleException(e); } } }; propThread.setDaemon(true); propThread.start(); }
public static void createForward(InetSocketAddress adbSockAddr, Device device, int localPort, int remotePort) throws TimeoutException, AdbCommandRejectedException, IOException { SocketChannel adbChan = null; try { adbChan = SocketChannel.open(adbSockAddr); adbChan.configureBlocking(false); byte[] request = formAdbRequest(String.format( "host-serial:%1$s:forward:tcp:%2$d;tcp:%3$d", //$NON-NLS-1$ device.getSerialNumber(), localPort, remotePort)); write(adbChan, request);
private synchronized void handleException(Exception e) { mCacheState = CacheState.UNPOPULATED; if (mDevice.logError) Log.w("PropertyFetcher", String.format("%s getting properties for device %s: %s", e.getClass().getSimpleName(), mDevice.getSerialNumber(), e.getMessage())); for (Map.Entry<String, SettableFuture<String>> entry : mPendingRequests.entrySet()) { entry.getValue().setException(e); } mPendingRequests.clear(); }
@Nullable private static Device find(@NonNull List<? extends Device> devices, @NonNull Device device) { for (Device d : devices) { if (d.getSerialNumber().equals(device.getSerialNumber())) { return d; } } return null; } }
device.getSerialNumber())); device.getSerialNumber(), e.getMessage())); device.getSerialNumber())); device.getSerialNumber()));
private String constructName() { String manufacturer = null; String model = null; try { manufacturer = cleanupStringForDisplay( getSystemProperty(PROP_DEVICE_MANUFACTURER).get()); model = cleanupStringForDisplay( getSystemProperty(PROP_DEVICE_MODEL).get()); } catch (Exception e) { // If there are exceptions thrown while attempting to get these properties, // we can just use the serial number, so ignore these exceptions. } StringBuilder sb = new StringBuilder(20); if (manufacturer != null) { sb.append(manufacturer); sb.append(SEPARATOR); } if (model != null) { sb.append(model); sb.append(SEPARATOR); } sb.append(getSerialNumber()); return sb.toString(); }
String avdName = getAvdName(); if (avdName != null) { return String.format("%s [%s]", avdName, getSerialNumber()); } else { return getSerialNumber(); sb.append(getSerialNumber()); return sb.toString();
public String syncPackageToDevice(String localFilePath) throws IOException, AdbCommandRejectedException, TimeoutException, SyncException { try { String packageFileName = getFileName(localFilePath); String remoteFilePath = String.format("/data/local/tmp/%1$s", packageFileName); //$NON-NLS-1$ Log.d(packageFileName, String.format("Uploading %1$s onto device '%2$s'", packageFileName, getSerialNumber())); SyncService sync = getSyncService(); if (sync != null) { String message = String.format("Uploading file onto device '%1$s'", getSerialNumber()); Log.d(LOG_TAG, message); sync.pushFile(localFilePath, remoteFilePath, SyncService.getNullProgressMonitor()); } else { throw new IOException("Unable to open sync connection!"); } return remoteFilePath; } catch (TimeoutException e) { Log.e(LOG_TAG, "Error during Sync: timeout."); throw e; } catch (SyncException e) { Log.e(LOG_TAG, String.format("Error during Sync: %1$s", e.getMessage())); throw e; } catch (IOException e) { Log.e(LOG_TAG, String.format("Error during Sync: %1$s", e.getMessage())); throw e; } }
device.getSerialNumber(), localPort, remotePort));
device.getSerialNumber(), localPort, remotePort));
device.getSerialNumber(), localPortSpec, remotePortSpec));
device.getSerialNumber(), localPortSpec));
device.getSerialNumber(), localPortSpec, remotePortSpec));
targetFileName, getSerialNumber())); getSerialNumber()); Log.d(LOG_TAG, message); sync.pushFile(local, remote, SyncService.getNullProgressMonitor());
packageFileName, getSerialNumber())); getSerialNumber()); Log.d(LOG_TAG, message); sync.pushFile(localFilePath, remoteFilePath, SyncService.getNullProgressMonitor());
targetFileName, getSerialNumber())); getSerialNumber()); Log.d(LOG_TAG, message); sync.pullFile(remote, local, SyncService.getNullProgressMonitor());
targetFileName, getSerialNumber())); getSerialNumber()); Log.d(LOG_TAG, message); sync.pushFile(local, remote, SyncService.getNullProgressMonitor());
targetFileName, getSerialNumber())); getSerialNumber()); Log.d(LOG_TAG, message); sync.pullFile(remote, local, SyncService.getNullProgressMonitor());
device.getSerialNumber())); device.getSerialNumber(), e.getMessage())); device.getSerialNumber())); device.getSerialNumber()));
/** * tells adb to talk to a specific device * * @param adbChan the socket connection to adb * @param device The device to talk to. * @throws TimeoutException in case of timeout on the connection. * @throws AdbCommandRejectedException if adb rejects the command * @throws IOException in case of I/O error on the connection. */ static void setDevice(SocketChannel adbChan, Device device) throws TimeoutException, AdbCommandRejectedException, IOException { // if the device is not -1, then we first tell adb we're looking to talk // to a specific device if (device != null) { String msg = "host:transport:" + device.getSerialNumber(); //$NON-NLS-1$ byte[] device_query = formAdbRequest(msg); write(adbChan, device_query); AdbResponse resp = readAdbResponse(adbChan, false /* readDiagString */); if (!resp.okay) { throw new AdbCommandRejectedException(resp.message, true/*errorDuringDeviceSelection*/); } } }