FileListingService

public final class FileListingService
extends Object

java.lang.Object
   ↳ com.android.ddmlib.FileListingService


Provides IDevice side file listing service.

Summary

Nested classes

class FileListingService.FileEntry

Represents an entry in a directory. 

interface FileListingService.IListingReceiver

Classes which implement this interface provide a method that deals with asynchronous result from ls command on the device. 

Constants

String DIRECTORY_APP

Application folder.

String DIRECTORY_DATA

Top level data folder.

String DIRECTORY_MNT

Top level mount folder.

String DIRECTORY_SDCARD

Top level sdcard folder.

String DIRECTORY_SYSTEM

Top level system folder.

String DIRECTORY_TEMP

Top level temp folder.

String FILE_SEPARATOR

Device side file separator.

long REFRESH_RATE

int TYPE_BLOCK

Entry type: Block

int TYPE_CHARACTER

Entry type: Character

int TYPE_DIRECTORY

Entry type: Directory

int TYPE_DIRECTORY_LINK

Entry type: Directory Link

int TYPE_FIFO

Entry type: FIFO

int TYPE_FILE

Entry type: File

int TYPE_LINK

Entry type: Link

int TYPE_OTHER

Entry type: Other

int TYPE_SOCKET

Entry type: Socket

Fields

public static final Pattern LS_LD_PATTERN

public static final Pattern LS_L_PATTERN

Regexp pattern to parse the result from ls.

public static final Pattern STAT_PATTERN

Regexp pattern to parse the result from stat.

Public constructors

FileListingService(IDevice device)

Creates a File Listing Service for a specified IDevice.

Public methods

FileEntry[] getChildren(FileListingService.FileEntry entry, boolean useCache, FileListingService.IListingReceiver receiver)

Returns the children of a FileEntry.

FileEntry[] getChildrenSync(FileListingService.FileEntry entry)

Returns the children of a FileEntry.

FileListingService.FileEntry getRoot()

Returns the root element.

Constants

DIRECTORY_APP

public static final String DIRECTORY_APP

Application folder.

Constant Value: "app"

DIRECTORY_DATA

public static final String DIRECTORY_DATA

Top level data folder.

Constant Value: "data"

DIRECTORY_MNT

public static final String DIRECTORY_MNT

Top level mount folder.

Constant Value: "mnt"

DIRECTORY_SDCARD

public static final String DIRECTORY_SDCARD

Top level sdcard folder.

Constant Value: "sdcard"

DIRECTORY_SYSTEM

public static final String DIRECTORY_SYSTEM

Top level system folder.

Constant Value: "system"

DIRECTORY_TEMP

public static final String DIRECTORY_TEMP

Top level temp folder.

Constant Value: "tmp"

FILE_SEPARATOR

public static final String FILE_SEPARATOR

Device side file separator.

Constant Value: "/"

REFRESH_RATE

public static final long REFRESH_RATE

Constant Value: 5000 (0x0000000000001388)

TYPE_BLOCK

public static final int TYPE_BLOCK

Entry type: Block

Constant Value: 3 (0x00000003)

TYPE_CHARACTER

public static final int TYPE_CHARACTER

Entry type: Character

Constant Value: 4 (0x00000004)

TYPE_DIRECTORY

public static final int TYPE_DIRECTORY

Entry type: Directory

Constant Value: 1 (0x00000001)

public static final int TYPE_DIRECTORY_LINK

Entry type: Directory Link

Constant Value: 2 (0x00000002)

TYPE_FIFO

public static final int TYPE_FIFO

Entry type: FIFO

Constant Value: 7 (0x00000007)

TYPE_FILE

public static final int TYPE_FILE

Entry type: File

Constant Value: 0 (0x00000000)

public static final int TYPE_LINK

Entry type: Link

Constant Value: 5 (0x00000005)

TYPE_OTHER

public static final int TYPE_OTHER

Entry type: Other

Constant Value: 8 (0x00000008)

TYPE_SOCKET

public static final int TYPE_SOCKET

Entry type: Socket

Constant Value: 6 (0x00000006)

Fields

LS_LD_PATTERN

public static final Pattern LS_LD_PATTERN

LS_L_PATTERN

public static final Pattern LS_L_PATTERN

Regexp pattern to parse the result from ls.

STAT_PATTERN

public static final Pattern STAT_PATTERN

Regexp pattern to parse the result from stat. Ex. drwxr-xr-x root root 2021-08-02 09:20:53.000000000 -0700 4096 /

Public constructors

FileListingService

public FileListingService (IDevice device)

Creates a File Listing Service for a specified IDevice.

Parameters
device IDevice: The Device the service is connected to.

Public methods

getChildren

public FileEntry[] getChildren (FileListingService.FileEntry entry, 
                boolean useCache, 
                FileListingService.IListingReceiver receiver)

Returns the children of a FileEntry.

This method supports a cache mechanism and synchronous and asynchronous modes.

If receiver is null, the device side ls command is done synchronously, and the method will return upon completion of the command.
If receiver is non null, the command is launched is a separate thread and upon completion, the receiver will be notified of the result.

The result for each ls command is cached in the parent FileEntry . useCache allows usage of this cache, but only if the cache is valid. The cache is valid only for FileListingService.REFRESH_RATE ms. After that a new ls command is always executed.

If the cache is valid and useCache == true, the method will always simply return the value of the cache, whether a IListingReceiver has been provided or not.

Parameters
entry FileListingService.FileEntry: The parent entry.

useCache boolean: A flag to use the cache or to force a new ls command.

receiver FileListingService.IListingReceiver: A receiver for asynchronous calls.

Returns
FileEntry[] The list of children or null for asynchronous calls.

getChildrenSync

public FileEntry[] getChildrenSync (FileListingService.FileEntry entry)

Returns the children of a FileEntry.

This method is the explicit synchronous version of getChildren(com.android.ddmlib.FileListingService.FileEntry, boolean, com.android.ddmlib.FileListingService.IListingReceiver). It is roughly equivalent to calling getChildren(FileEntry, false, null)

Parameters
entry FileListingService.FileEntry: The parent entry.

Returns
FileEntry[] The list of children

Throws
TimeoutException in case of timeout on the connection when sending the command.
AdbCommandRejectedException if adb rejects the command.
ShellCommandUnresponsiveException in case the shell command doesn't send any output for a period longer than maxTimeToOutputResponse.
in case of I/O error on the connection.

getRoot

public FileListingService.FileEntry getRoot ()

Returns the root element.

Returns
FileListingService.FileEntry the FileEntry object representing the root element or null if the device is invalid.