diff options
author | Wei-Ning Huang <azhuang@0xlab.org> | 2011-08-05 05:11:08 +0800 |
---|---|---|
committer | Wei-Ning Huang <azhuang@0xlab.org> | 2011-08-05 05:11:08 +0800 |
commit | c90c897b4a1ff9e42f50ae3e419f88342c7914a5 (patch) | |
tree | 1b1e36f3e6e31bde0b629b4e34693b146e56adaf | |
parent | b8104b4bb73c80b41179bcd603b26037deb84ac2 (diff) | |
download | sdk-c90c897b4a1ff9e42f50ae3e419f88342c7914a5.zip sdk-c90c897b4a1ff9e42f50ae3e419f88342c7914a5.tar.gz sdk-c90c897b4a1ff9e42f50ae3e419f88342c7914a5.tar.bz2 |
Add pushFile/pullFile interface for IDevice.
Implement pushFile/pullFile methods for Device.
Change-Id: I8491f98fc46bbfd5f476b72e002cd97f63c56228
-rw-r--r-- | ddms/libs/ddmlib/src/com/android/ddmlib/Device.java | 64 | ||||
-rw-r--r-- | ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java | 27 |
2 files changed, 91 insertions, 0 deletions
diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java index bb61e5f..c5b6669 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/Device.java @@ -406,6 +406,70 @@ final class Device implements IDevice { mMountPoints.put(name, value); } + public void pushFile(String local, String remote) + throws IOException, AdbCommandRejectedException, TimeoutException, SyncException { + try { + String targetFileName = getFileName(local); + + Log.d(targetFileName, String.format("Uploading %1$s onto device '%2$s'", + targetFileName, 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(local, remote, SyncService.getNullProgressMonitor()); + } else { + throw new IOException("Unable to open sync connection!"); + } + } 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; + + } + } + + public void pullFile(String remote, String local) + throws IOException, AdbCommandRejectedException, TimeoutException, SyncException { + try { + String targetFileName = getFileName(remote); + + Log.d(targetFileName, String.format("Downloading %1$s from device '%2$s'", + targetFileName, getSerialNumber())); + + SyncService sync = getSyncService(); + if (sync != null) { + String message = String.format("Downloding file from device '%1$s'", + getSerialNumber()); + Log.d(LOG_TAG, message); + sync.pullFile(remote, local, SyncService.getNullProgressMonitor()); + } else { + throw new IOException("Unable to open sync connection!"); + } + } 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; + + } + } + public String installPackage(String packageFilePath, boolean reinstall) throws InstallException { try { diff --git a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java index e408fdd..7b51c03 100644 --- a/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java +++ b/ddms/libs/ddmlib/src/com/android/ddmlib/IDevice.java @@ -316,6 +316,33 @@ public interface IDevice { public String getClientName(int pid); /** + * Push a single file. + * @param local the local filepath. + * @param remote The remote filepath. + * + * @throws IOException in case of I/O error on the connection. + * @throws AdbCommandRejectedException if adb rejects the command + * @throws TimeoutException in case of a timeout reading responses from the device. + * @throws SyncException if file could not be pushed + */ + public void pushFile(String local, String remote) + throws IOException, AdbCommandRejectedException, TimeoutException, SyncException; + + /** + * Pulls a single file. + * + * @param remote the full path to the remote file + * @param local The local destination. + * + * @throws IOException in case of an IO exception. + * @throws AdbCommandRejectedException if adb rejects the command + * @throws TimeoutException in case of a timeout reading responses from the device. + * @throws SyncException in case of a sync exception. + */ + public void pullFile(String remote, String local) + throws IOException, AdbCommandRejectedException, TimeoutException, SyncException; + + /** * Installs an Android application on device. * This is a helper method that combines the syncPackageToDevice, installRemotePackage, * and removePackage steps |