SyncService
public
class
SyncService
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.device.server.SyncService |
Sync service class to push/pull to/from devices/emulators, through the debug bridge.
To get a SyncService object, use IDevice.getSyncService().
Summary
Nested classes | |
|---|---|
class |
SyncService.FileStat
|
interface |
SyncService.ISyncProgressMonitor
Classes which implement this interface provide methods that deal with displaying transfer progress. |
Public constructors | |
|---|---|
SyncService(InetSocketAddress address, IDevice device)
Creates a Sync service object. |
|
Public methods | |
|---|---|
void
|
close()
Closes the connection. |
static
SyncService.ISyncProgressMonitor
|
getNullProgressMonitor()
Returns a sync progress monitor that does nothing. |
boolean
|
openSync()
Opens the sync connection. |
void
|
pull(FileEntry[] entries, String localPath, SyncService.ISyncProgressMonitor monitor)
Pulls file(s) or folder(s). |
void
|
pullFile(FileListingService.FileEntry remote, String localFilename, SyncService.ISyncProgressMonitor monitor)
Pulls a single file. |
void
|
pullFile(String remoteFilepath, String localFilename, SyncService.ISyncProgressMonitor monitor)
Pulls a single file. |
void
|
push(String[] local, FileListingService.FileEntry remote, SyncService.ISyncProgressMonitor monitor)
Pushes several files or directories. |
void
|
push(String[] local, String remote, SyncService.ISyncProgressMonitor monitor)
Pushes several files or directories. |
void
|
pushFile(String local, String remote, SyncService.ISyncProgressMonitor monitor)
Push a single file. |
SyncService.FileStat
|
statFile(String path)
Returns the stat info of the remote file. |
Public constructors
SyncService
public SyncService (InetSocketAddress address,
IDevice device)Creates a Sync service object.
| Parameters | |
|---|---|
address |
InetSocketAddress: The address to connect to |
device |
IDevice: the IDevice that the service connects to. |
Public methods
close
public void close ()
Closes the connection.
getNullProgressMonitor
public static SyncService.ISyncProgressMonitor getNullProgressMonitor ()
Returns a sync progress monitor that does nothing. This allows background tasks that don't
want/need to display ui, to pass a valid ISyncProgressMonitor.
This object can be reused multiple times and can be used by concurrent threads.
| Returns | |
|---|---|
SyncService.ISyncProgressMonitor |
|
openSync
public boolean openSync ()
Opens the sync connection. This must be called before any calls to push[File] / pull[File].
| Returns | |
|---|---|
boolean |
true if the connection opened, false if adb refuse the connection. This can happen if
the IDevice is invalid. |
| Throws | |
|---|---|
TimeoutException |
in case of timeout on the connection. |
AdbCommandRejectedException |
if adb rejects the command |
|
If the connection to adb failed. |
pull
public void pull (FileEntry[] entries, String localPath, SyncService.ISyncProgressMonitor monitor)
Pulls file(s) or folder(s).
| Parameters | |
|---|---|
entries |
FileEntry: the remote item(s) to pull |
localPath |
String: The local destination. If the entries count is > 1 or if the unique entry
is a folder, this should be a folder. |
monitor |
SyncService.ISyncProgressMonitor: The progress monitor. Cannot be null. |
| Throws | |
|---|---|
|
com.android.ddmlib.SyncException |
|
IOException |
|
com.android.ddmlib.TimeoutException |
SyncException |
|
TimeoutException |
|
pullFile
public void pullFile (FileListingService.FileEntry remote, String localFilename, SyncService.ISyncProgressMonitor monitor)
Pulls a single file.
| Parameters | |
|---|---|
remote |
FileListingService.FileEntry: the remote file |
localFilename |
String: The local destination. |
monitor |
SyncService.ISyncProgressMonitor: The progress monitor. Cannot be null. |
| Throws | |
|---|---|
|
in case of an IO exception. |
TimeoutException |
in case of a timeout reading responses from the device. |
SyncException |
in case of a sync exception. |
pullFile
public void pullFile (String remoteFilepath,
String localFilename,
SyncService.ISyncProgressMonitor monitor)Pulls a single file.
Because this method just deals with a String for the remote file instead of a FileEntry, the size of the file being pulled is unknown and the ISyncProgressMonitor
will not properly show the progress
| Parameters | |
|---|---|
remoteFilepath |
String: the full path to the remote file |
localFilename |
String: The local destination. |
monitor |
SyncService.ISyncProgressMonitor: The progress monitor. Cannot be null. |
| Throws | |
|---|---|
|
in case of an IO exception. |
TimeoutException |
in case of a timeout reading responses from the device. |
SyncException |
in case of a sync exception. |
See also:
push
public void push (String[] local,
FileListingService.FileEntry remote,
SyncService.ISyncProgressMonitor monitor)Pushes several files or directories.
| Parameters | |
|---|---|
local |
String: the local files to push |
remote |
FileListingService.FileEntry: the remote FileEntry representing a directory |
monitor |
SyncService.ISyncProgressMonitor: The progress monitor |
| Throws | |
|---|---|
SyncException |
if some files could not be pushed |
|
in case of I/O error on the connection |
TimeoutException |
in case of a timeout reading responses from the device |
push
public void push (String[] local,
String remote,
SyncService.ISyncProgressMonitor monitor)Pushes several files or directories.
| Parameters | |
|---|---|
local |
String: the local files to push |
remote |
String: the remote path representing a directory |
monitor |
SyncService.ISyncProgressMonitor: The progress monitor |
| Throws | |
|---|---|
SyncException |
if some files could not be pushed |
|
in case of I/O error on the connection |
TimeoutException |
in case of a timeout reading responses from the device |
pushFile
public void pushFile (String local,
String remote,
SyncService.ISyncProgressMonitor monitor)Push a single file.
| Parameters | |
|---|---|
local |
String: the local filepath. |
remote |
String: The remote filepath. |
monitor |
SyncService.ISyncProgressMonitor: The progress monitor. Cannot be null. |
| Throws | |
|---|---|
SyncException |
if file could not be pushed |
|
in case of I/O error on the connection. |
TimeoutException |
in case of a timeout reading responses from the device. |
statFile
public SyncService.FileStat statFile (String path)
Returns the stat info of the remote file.
| Parameters | |
|---|---|
path |
String: the remote file |
| Returns | |
|---|---|
SyncService.FileStat |
an FileStat containing the mode, size and last modified info if all went well or null otherwise |
| Throws | |
|---|---|
|
IOException |
TimeoutException |
in case of a timeout reading responses from the device. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-12-04 UTC.