private void adbPullFile(IDevice device, String remoteFile, String localDir) { try { device.getSyncService() .pullFile(remoteFile, localDir, getNullProgressMonitor()); } catch (Exception e) { logDebug(debug, e.getMessage(), e); } }
+ DeviceHelper.getDescriptiveName( device ); syncService.pushFile( sourcePath, destinationPath, new LogSyncProgressMonitor( getLog() ) );
private void adbPull(IDevice device, FileEntry remoteDirName, String localDirName) { try { device.getSyncService().pull(new FileEntry[]{remoteDirName}, localDirName, getNullProgressMonitor()); } catch (Exception e) { logDebug(debug, e.getMessage(), e); } }
msg = createSendFileReq(ID_SEND, remotePathContent, 0644); System.arraycopy(ID_DATA, 0, getBuffer(), 0, ID_DATA.length); int readCount = fis.read(getBuffer(), 8, SYNC_DATA_MAX); ArrayHelper.swap32bitsToArray(readCount, getBuffer(), 4); AdbHelper.write(mChannel, getBuffer(), readCount+8, timeOut); msg = createReq(ID_DONE, (int)time); AdbHelper.read(mChannel, result, -1 /* full length */, timeOut); if (!checkResult(result, ID_OKAY)) { throw new SyncException(SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(result, timeOut));
getSerialNumber()); Log.d(LOG_TAG, message); sync.pushFile(local, remote, SyncService.getNullProgressMonitor()); } else { throw new IOException("Unable to open sync connection!"); sync.close();
getSerialNumber()); Log.d(LOG_TAG, message); sync.pullFile(remote, local, SyncService.getNullProgressMonitor()); } else { throw new IOException("Unable to open sync connection!"); sync.close();
msg = createFileReq(ID_RECV, remotePathContent); if (checkResult(pullResult, ID_DATA) == false && checkResult(pullResult, ID_DONE) == false) { throw new SyncException(SyncError.TRANSFER_PROTOCOL_ERROR, readErrorMessage(pullResult, timeOut)); if (checkResult(pullResult, ID_DONE)) { break; if (checkResult(pullResult, ID_DATA) == false) { readErrorMessage(pullResult, timeOut));
@Override public void pushFile(final File localFrom, final String remoteTo) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("pushFile(File, String) - start"); } try { if (device.getSyncService() == null) throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?"); device.getSyncService().pushFile(localFrom.getAbsolutePath(), remoteTo, SyncService.getNullProgressMonitor()); } catch (final Exception ex) { LOGGER.error("pushFile(File, String)", ex); throw new AndroidScreenCastRuntimeException(ex); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("pushFile(File, String) - end"); } }
public SyncService getSyncService() throws TimeoutException, AdbCommandRejectedException, IOException { SyncService syncService = new SyncService(AndroidDebugBridge.getSocketAddress(), this); if (syncService.openSync()) { return syncService; } return null; }
/** * Returns the mode of the remote file. * @param path the remote file * @return an Integer containing the mode if all went well or null * otherwise * @throws IOException * @throws TimeoutException in case of a timeout reading responses from the device. */ private Integer readMode(String path) throws TimeoutException, IOException { // create the stat request message. byte[] msg = createFileReq(ID_STAT, path); AdbHelper.write(mChannel, msg, -1 /* full length */, DdmPreferences.getTimeOut()); // read the result, in a byte array containing 4 ints // (id, mode, size, time) byte[] statResult = new byte[16]; AdbHelper.read(mChannel, statResult, -1 /* full length */, DdmPreferences.getTimeOut()); // check we have the proper data back if (checkResult(statResult, ID_STAT) == false) { return null; } // we return the mode (2nd int in the array) return ArrayHelper.swap32bitFromArray(statResult, 4); }
/** * Reads an error message from the opened {@link #mChannel}. * @param result the current adb result. Must contain both FAIL and the length of the message. * @param timeOut * @return * @throws TimeoutException in case of a timeout reading responses from the device. * @throws IOException */ private String readErrorMessage(byte[] result, final int timeOut) throws TimeoutException, IOException { if (checkResult(result, ID_FAIL)) { int len = ArrayHelper.swap32bitFromArray(result, 4); if (len > 0) { AdbHelper.read(mChannel, getBuffer(), len, timeOut); String message = new String(getBuffer(), 0, len); Log.e("ddms", "transfer error: " + message); return message; } } return null; }
/** * Pulls a single file. * <p/>The size of the file being pulled is unknown and the * {@link ISyncProgressMonitor} will not properly show the progress * @param remoteFilepath the full path to the remote file * @param localFilename The local destination. * @param monitor The progress monitor. Cannot be null. * * @throws IOException in case of an IO exception. * @throws TimeoutException in case of a timeout reading responses from the device. * @throws SyncException in case of a sync exception. * * @see #getNullProgressMonitor() */ public void pullFile(String remoteFilepath, String localFilename, ISyncProgressMonitor monitor) throws TimeoutException, IOException, SyncException { Integer mode = readMode(remoteFilepath); if (mode == null) { // attempts to download anyway } else if (mode == 0) { throw new SyncException(SyncError.NO_REMOTE_OBJECT); } monitor.start(0); doPullFile(remoteFilepath, localFilename, monitor); monitor.stop(); }
doPush(f.listFiles(), dest, monitor); doPushFile(f.getAbsolutePath(), remoteFile, monitor);
doPull(children, dest, fileListingService, monitor); monitor.advance(1); } else if (type == FileListingService.TYPE_FILE) { monitor.startSubTask(e.getFullPath()); String dest = localPath + File.separator + e.getName(); doPullFile(e.getFullPath(), dest, monitor);
@Override public void pullFile(final String removeFrom, final File localTo) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("pullFile(String, File) - start"); } // ugly hack to call the method without FileEntry try { if (device.getSyncService() == null) throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?"); final Method m = device.getSyncService().getClass().getDeclaredMethod("doPullFile", String.class, String.class, ISyncProgressMonitor.class); m.setAccessible(true); device.getSyncService(); m.invoke(device.getSyncService(), removeFrom, localTo.getAbsolutePath(), SyncService.getNullProgressMonitor()); } catch (final Exception ex) { LOGGER.error("pullFile(String, File)", ex); throw new AndroidScreenCastRuntimeException(ex); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("pullFile(String, File) - end"); } }
/** * Creates the data array for a stat request. * @param command the 4 byte command (ID_STAT, ID_RECV, ...) * @param path The path of the remote file on which to execute the command * @return the byte[] to send to the device through adb */ private static byte[] createFileReq(byte[] command, String path) { byte[] pathContent; try { pathContent = path.getBytes(AdbHelper.DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { return null; } return createFileReq(command, pathContent); }
/** * Push a single file. * @param local the local filepath. * @param remote The remote filepath. * @param monitor The progress monitor. Cannot be null. * * @throws SyncException if file could not be pushed * @throws IOException in case of I/O error on the connection. * @throws TimeoutException in case of a timeout reading responses from the device. */ public void pushFile(String local, String remote, ISyncProgressMonitor monitor) throws SyncException, IOException, TimeoutException { File f = new File(local); if (!f.exists()) { throw new SyncException(SyncError.NO_LOCAL_FILE); } if (f.isDirectory()) { throw new SyncException(SyncError.LOCAL_IS_DIRECTORY); } monitor.start((int)f.length()); doPushFile(local, remote, monitor); monitor.stop(); }
/** * Pulls a single file. * @param remote the remote file * @param localFilename The local destination. * @param monitor The progress monitor. Cannot be null. * * @throws IOException in case of an IO exception. * @throws TimeoutException in case of a timeout reading responses from the device. * @throws SyncException in case of a sync exception. * * @see FileListingService.FileEntry * @see #getNullProgressMonitor() */ public void pullFile(FileEntry remote, String localFilename, ISyncProgressMonitor monitor) throws IOException, SyncException, TimeoutException { int total = remote.getSizeValue(); monitor.start(total); doPullFile(remote.getFullPath(), localFilename, monitor); monitor.stop(); }
/** * Pulls a single file. * <p>Because this method just deals with a String for the remote file instead of a * {@link FileEntry}, the size of the file being pulled is unknown and the * {@link ISyncProgressMonitor} will not properly show the progress * @param remoteFilepath the full path to the remote file * @param localFilename The local destination. * @param monitor The progress monitor. Cannot be null. * * @throws IOException in case of an IO exception. * @throws TimeoutException in case of a timeout reading responses from the device. * @throws SyncException in case of a sync exception. * * @see #getNullProgressMonitor() */ public void pullFile(String remoteFilepath, String localFilename, ISyncProgressMonitor monitor) throws TimeoutException, IOException, SyncException { FileStat fileStat = statFile(remoteFilepath); if (fileStat == null) { // attempts to download anyway } else if (fileStat.getMode() == 0) { throw new SyncException(SyncError.NO_REMOTE_OBJECT); } monitor.start(0); //TODO: use the {@link FileListingService} to get the file size. doPullFile(remoteFilepath, localFilename, monitor); monitor.stop(); }