public class StressProvider extends DocumentsProvider
ContentProvider.PipeDataWriter<T>
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_AUTHORITY |
static String |
STRESS_ROOT_0_ID |
static String |
STRESS_ROOT_1_ID |
static String |
STRESS_ROOT_2_ID |
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
Constructor and Description |
---|
StressProvider() |
Modifier and Type | Method and Description |
---|---|
void |
attachInfo(Context context,
ProviderInfo info)
Implementation is provided by the parent class.
|
boolean |
onCreate()
Implement this to initialize your content provider on startup.
|
ParcelFileDescriptor |
openDocument(String docId,
String mode,
CancellationSignal signal)
Open and return the requested document.
|
AssetFileDescriptor |
openDocumentThumbnail(String docId,
Point sizeHint,
CancellationSignal signal)
Open and return a thumbnail of the requested document.
|
Cursor |
queryChildDocuments(String parentDocumentId,
String[] projection,
String sortOrder)
Return the children documents contained in the requested directory.
|
Cursor |
queryDocument(String documentId,
String[] projection)
Return metadata for the single requested document.
|
Cursor |
queryRoots(String[] projection)
Return all roots currently provided.
|
call, canonicalize, copyDocument, createDocument, delete, deleteDocument, getDocumentStreamTypes, getDocumentType, getStreamTypes, getType, insert, isChildDocument, mimeTypeMatches, moveDocument, openAssetFile, openAssetFile, openFile, openFile, openTypedAssetFile, openTypedAssetFile, openTypedDocument, query, queryChildDocumentsForManage, queryRecentDocuments, querySearchDocuments, removeDocument, renameDocument, revokeDocumentPermission, update
applyBatch, attachInfoForTesting, bulkInsert, coerceToLocalContentProvider, dump, enforceReadPermissionInner, enforceWritePermissionInner, getAppOpsManager, getAuthorityWithoutUserId, getCallingPackage, getContext, getIContentProvider, getPathPermissions, getReadPermission, getUriWithoutUserId, getUserIdFromAuthority, getUserIdFromAuthority, getUserIdFromUri, getUserIdFromUri, getWritePermission, isTemporary, matchesOurAuthorities, maybeAddUserId, onConfigurationChanged, onLowMemory, onTrimMemory, openFileHelper, openPipeHelper, query, rejectInsert, setAppOps, setAuthorities, setPathPermissions, setReadPermission, setWritePermission, shutdown, uncanonicalize, uriHasUserId
public static final String DEFAULT_AUTHORITY
public static final String STRESS_ROOT_0_ID
public static final String STRESS_ROOT_1_ID
public static final String STRESS_ROOT_2_ID
public void attachInfo(Context context, ProviderInfo info)
DocumentsProvider
attachInfo
in class DocumentsProvider
context
- The context this provider is running ininfo
- Registered information about this content providerpublic boolean onCreate()
ContentProvider
You should defer nontrivial initialization (such as opening,
upgrading, and scanning databases) until the content provider is used
(via ContentProvider.query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)
, ContentProvider.insert(android.net.Uri, android.content.ContentValues)
, etc). Deferred initialization
keeps application startup fast, avoids unnecessary work if the provider
turns out not to be needed, and stops database errors (such as a full
disk) from halting application launch.
If you use SQLite, SQLiteOpenHelper
is a helpful utility class that makes it easy to manage databases,
and will automatically defer opening until first use. If you do use
SQLiteOpenHelper, make sure to avoid calling
SQLiteOpenHelper.getReadableDatabase()
or
SQLiteOpenHelper.getWritableDatabase()
from this method. (Instead, override
SQLiteOpenHelper.onOpen(android.database.sqlite.SQLiteDatabase)
to initialize the
database when it is first opened.)
onCreate
in class ContentProvider
public Cursor queryRoots(String[] projection) throws FileNotFoundException
DocumentsProvider
Each root is defined by the metadata columns described in DocumentsContract.Root
,
including DocumentsContract.Root.COLUMN_DOCUMENT_ID
which points to a directory
representing a tree of documents to display under that root.
If this set of roots changes, you must call ContentResolver.notifyChange(Uri,
android.database.ContentObserver, boolean)
with
DocumentsContract.buildRootsUri(String)
to notify the system.
queryRoots
in class DocumentsProvider
projection
- list of DocumentsContract.Root
columns to put into the cursor. If
null
all supported columns should be included.FileNotFoundException
public Cursor queryDocument(String documentId, String[] projection) throws FileNotFoundException
DocumentsProvider
queryDocument
in class DocumentsProvider
documentId
- the document to return.projection
- list of DocumentsContract.Document
columns to put into the
cursor. If null
all supported columns should be
included.FileNotFoundException
public Cursor queryChildDocuments(String parentDocumentId, String[] projection, String sortOrder) throws FileNotFoundException
DocumentsProvider
If your provider is cloud-based, and you have some data cached or pinned
locally, you may return the local data immediately, setting
DocumentsContract.EXTRA_LOADING
on the Cursor to indicate that
you are still fetching additional data. Then, when the network data is
available, you can send a change notification to trigger a requery and
return the complete contents. To return a Cursor with extras, you need to
extend and override Cursor.getExtras()
.
To support change notifications, you must
Cursor.setNotificationUri(ContentResolver, Uri)
with a relevant
Uri, such as
DocumentsContract.buildChildDocumentsUri(String, String)
. Then
you can call ContentResolver.notifyChange(Uri,
android.database.ContentObserver, boolean)
with that Uri to send change
notifications.
queryChildDocuments
in class DocumentsProvider
parentDocumentId
- the directory to return children for.projection
- list of DocumentsContract.Document
columns to put into the
cursor. If null
all supported columns should be
included.sortOrder
- how to order the rows, formatted as an SQL
ORDER BY
clause (excluding the ORDER BY itself).
Passing null
will use the default sort order, which
may be unordered. This ordering is a hint that can be used to
prioritize how data is fetched from the network, but UI may
always enforce a specific ordering.FileNotFoundException
DocumentsContract.EXTRA_LOADING
,
DocumentsContract.EXTRA_INFO
,
DocumentsContract.EXTRA_ERROR
public AssetFileDescriptor openDocumentThumbnail(String docId, Point sizeHint, CancellationSignal signal) throws FileNotFoundException
DocumentsProvider
A provider should return a thumbnail closely matching the hinted size, attempting to serve from a local cache if possible. A provider should never return images more than double the hinted size.
If you perform expensive operations to download or generate a thumbnail,
you should periodically check CancellationSignal.isCanceled()
to
abort abandoned thumbnail requests.
openDocumentThumbnail
in class DocumentsProvider
docId
- the document to return.sizeHint
- hint of the optimal thumbnail dimensions.signal
- used by the caller to signal if the request should be
cancelled. May be null.FileNotFoundException
DocumentsContract.Document.FLAG_SUPPORTS_THUMBNAIL
public ParcelFileDescriptor openDocument(String docId, String mode, CancellationSignal signal) throws FileNotFoundException
DocumentsProvider
Your provider should return a reliable ParcelFileDescriptor
to
detect when the remote caller has finished reading or writing the
document. You may return a pipe or socket pair if the mode is exclusively
"r" or "w", but complex modes like "rw" imply a normal file on disk that
supports seeking.
If you block while downloading content, you should periodically check
CancellationSignal.isCanceled()
to abort abandoned open requests.
openDocument
in class DocumentsProvider
docId
- the document to return.mode
- the mode to open with, such as 'r', 'w', or 'rw'.signal
- used by the caller to signal if the request should be
cancelled. May be null.FileNotFoundException
ParcelFileDescriptor.open(java.io.File, int, android.os.Handler,
OnCloseListener)
,
ParcelFileDescriptor.createReliablePipe()
,
ParcelFileDescriptor.createReliableSocketPair()
,
ParcelFileDescriptor.parseMode(String)