Stay organized with collections Save and categorize content based on your preferences.

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

Fields

public static final String[] COLUMNS

public static final String COLUMN_ABSOLUTE_PATH

public static final String COLUMN_DIRECTORY

public static final String COLUMN_METADATA

public static final String COLUMN_MIME_TYPE

public static final String COLUMN_NAME

public static final String CONTENT_PROVIDER_URI

public static final String NO_RESULTS_STRING

public static final String PACKAGE_NAME

public static final String QUERY_INFO_VALUE

Public constructors

ContentProviderHandler(ITestDevice device)

Constructor.

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.

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, excludedDirectories)

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.

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.

Fields

COLUMNS

public static final String[] COLUMNS

COLUMN_ABSOLUTE_PATH

public static final String COLUMN_ABSOLUTE_PATH

COLUMN_DIRECTORY

public static final String COLUMN_DIRECTORY

COLUMN_METADATA

public static final String COLUMN_METADATA

COLUMN_MIME_TYPE

public static final String COLUMN_MIME_TYPE

COLUMN_NAME

public static final String COLUMN_NAME

CONTENT_PROVIDER_URI

public static final String CONTENT_PROVIDER_URI

NO_RESULTS_STRING

public static final String NO_RESULTS_STRING

PACKAGE_NAME

public static final String PACKAGE_NAME

QUERY_INFO_VALUE

public static final String QUERY_INFO_VALUE

Public constructors

ContentProviderHandler

public ContentProviderHandler (ITestDevice device)

Constructor.

Parameters
device ITestDevice

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
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

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
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
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