ContentProviderHandler
public
class
ContentProviderHandler
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.device.contentprovider.ContentProviderHandler |
Handler that abstract the content provider interactions and allow to use the device side content provider for different operations.
All implementation in this class should be mindful of the user currently running on the device.
Summary
Constants | |
|---|---|
String |
COLUMN_ABSOLUTE_PATH
|
String |
COLUMN_DIRECTORY
|
String |
COLUMN_METADATA
|
String |
COLUMN_MIME_TYPE
|
String |
COLUMN_NAME
|
String |
CONTENT_PROVIDER_URI
|
String |
NO_RESULTS_STRING
|
String |
PACKAGE_NAME
|
String |
QUERY_INFO_VALUE
|
Fields | |
|---|---|
public
static
final
String[] |
COLUMNS
|
Public constructors | |
|---|---|
ContentProviderHandler(ITestDevice device)
Constructor. |
|
ContentProviderHandler(ITestDevice device, Integer userId)
|
|
Public methods | |
|---|---|
boolean
|
contentProviderNotFound()
Returns True if one of the operation failed with Content provider not found. |
static
String
|
createEscapedContentUri(String deviceFilePath)
Returns the full URI string for the given device path, escaped and encoded to avoid non-URL characters. |
boolean
|
deleteFile(String deviceFilePath)
Content provider callback that delete a file at the URI location. |
boolean
|
doesFileExist(String deviceFilePath)
Determines if the file or non-empty directory exists on the device. |
IRunUtil
|
getRunUtil()
|
Integer
|
getUserId()
Returns the userId that this instance is initialized with. |
boolean
|
pullDir(String deviceFilePath, File localDir)
Recursively pull directory contents from device using content provider. |
boolean
|
pullFile(String deviceFilePath, File localFile)
Content provider callback that pulls a file from the URI location into a local file. |
boolean
|
pushDir(File localFileDir, String deviceFilePath,
Content provider callback that push a dir to the URI location. |
boolean
|
pushFile(File fileToPush, String deviceFilePath)
Content provider callback that push a file to the URI location. |
void
|
setRunUtil(IRunUtil runUtil)
|
boolean
|
setUp()
Ensure the content provider helper apk is installed and ready to be used. |
void
|
tearDown()
Clean the device from the content provider helper. |
Constants
COLUMN_ABSOLUTE_PATH
public static final String COLUMN_ABSOLUTE_PATH
Constant Value: "absolute_path"
COLUMN_DIRECTORY
public static final String COLUMN_DIRECTORY
Constant Value: "is_directory"
COLUMN_METADATA
public static final String COLUMN_METADATA
Constant Value: "metadata"
COLUMN_MIME_TYPE
public static final String COLUMN_MIME_TYPE
Constant Value: "mime_type"
COLUMN_NAME
public static final String COLUMN_NAME
Constant Value: "name"
CONTENT_PROVIDER_URI
public static final String CONTENT_PROVIDER_URI
Constant Value: "content://android.tradefed.contentprovider"
NO_RESULTS_STRING
public static final String NO_RESULTS_STRING
Constant Value: "No result found."
PACKAGE_NAME
public static final String PACKAGE_NAME
Constant Value: "android.tradefed.contentprovider"
QUERY_INFO_VALUE
public static final String QUERY_INFO_VALUE
Constant Value: "INFO"
Fields
COLUMNS
public static final String[] COLUMNS
Public constructors
ContentProviderHandler
public ContentProviderHandler (ITestDevice device)
Constructor.
| Parameters | |
|---|---|
device |
ITestDevice |
| Throws | |
|---|---|
DeviceNotAvailableException |
|
ContentProviderHandler
public ContentProviderHandler (ITestDevice device, Integer userId)
| Parameters | |
|---|---|
device |
ITestDevice |
userId |
Integer |
Public methods
contentProviderNotFound
public boolean contentProviderNotFound ()
Returns True if one of the operation failed with Content provider not found. Can be cleared
by running setUp() successfully again.
| Returns | |
|---|---|
boolean |
|
createEscapedContentUri
public static String createEscapedContentUri (String deviceFilePath)
Returns the full URI string for the given device path, escaped and encoded to avoid non-URL characters.
| Parameters | |
|---|---|
deviceFilePath |
String |
| Returns | |
|---|---|
String |
|
deleteFile
public boolean deleteFile (String deviceFilePath)
Content provider callback that delete a file at the URI location. File will be deleted from the device content.
| Parameters | |
|---|---|
deviceFilePath |
String: The path on the device of the file to delete. |
| Returns | |
|---|---|
boolean |
True if successful, False otherwise |
| Throws | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
doesFileExist
public boolean doesFileExist (String deviceFilePath)
Determines if the file or non-empty directory exists on the device.
| Parameters | |
|---|---|
deviceFilePath |
String: The absolute file path on device to check for existence. |
| Returns | |
|---|---|
boolean |
True if file/directory exists, False otherwise. If directory is empty, it will return False as well. |
| Throws | |
|---|---|
DeviceNotAvailableException |
|
getUserId
public Integer getUserId ()
Returns the userId that this instance is initialized with.
| Returns | |
|---|---|
Integer |
|
pullDir
public boolean pullDir (String deviceFilePath,
File localDir)Recursively pull directory contents from device using content provider.
| Parameters | |
|---|---|
deviceFilePath |
String: the absolute file path of the remote source |
localDir |
File: the local directory to pull files into |
| Returns | |
|---|---|
boolean |
true if file was pulled successfully. false otherwise. |
| Throws | |
|---|---|
DeviceNotAvailableException |
if connection with device is lost and cannot be recovered. |
pullFile
public boolean pullFile (String deviceFilePath,
File localFile)Content provider callback that pulls a file from the URI location into a local file.
| Parameters | |
|---|---|
deviceFilePath |
String: The path on the device where to pull the file from. |
localFile |
File: The ERROR(/File) to store the contents in. If non-empty, contents will be
replaced. |
| Returns | |
|---|---|
boolean |
True if successful, False otherwise |
| Throws | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
pushDir
public boolean pushDir (File localFileDir,
String deviceFilePath,
excludedDirectories) Content provider callback that push a dir to the URI location.
| Parameters | |
|---|---|
localFileDir |
File: The directory to push |
deviceFilePath |
String: The on device location |
excludedDirectories |
: Directories not included in the push. |
| Returns | |
|---|---|
boolean |
True if successful |
| Throws | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
DeviceNotAvailableException |
|
pushFile
public boolean pushFile (File fileToPush,
String deviceFilePath)Content provider callback that push a file to the URI location.
| Parameters | |
|---|---|
fileToPush |
File: The ERROR(/File) to be pushed to the device. |
deviceFilePath |
String: The path on the device where to push the file. |
| Returns | |
|---|---|
boolean |
True if successful, False otherwise |
| Throws | |
|---|---|
|
com.android.tradefed.device.DeviceNotAvailableException |
|
IllegalArgumentException |
DeviceNotAvailableException |
|
setUp
public boolean setUp ()
Ensure the content provider helper apk is installed and ready to be used.
| Returns | |
|---|---|
boolean |
True if ready to be used, False otherwise. |
| Throws | |
|---|---|
DeviceNotAvailableException |
|
tearDown
public void tearDown ()
Clean the device from the content provider helper.
| Throws | |
|---|---|
DeviceNotAvailableException |
|