public class BugreportStorageProvider extends DocumentsProvider
ContentProvider.PipeDataWriter<T>
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 |
---|
BugreportStorageProvider() |
Modifier and Type | Method and Description |
---|---|
void |
deleteDocument(String documentId)
Delete the requested document.
|
protected static Uri |
getNotificationUri() |
boolean |
onCreate()
Implement this to initialize your content provider on startup.
|
ParcelFileDescriptor |
openDocument(String documentId,
String mode,
CancellationSignal signal)
Open and return 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.
|
attachInfo, call, canonicalize, copyDocument, createDocument, delete, getDocumentStreamTypes, getDocumentType, getStreamTypes, getType, insert, isChildDocument, mimeTypeMatches, moveDocument, openAssetFile, openAssetFile, openDocumentThumbnail, 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 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 ParcelFileDescriptor openDocument(String documentId, 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
documentId
- 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)
public void deleteDocument(String documentId) throws FileNotFoundException
DocumentsProvider
Upon returning, any URI permission grants for the given document will be
revoked. If additional documents were deleted as a side effect of this
call (such as documents inside a directory) the implementor is
responsible for revoking those permissions using
DocumentsProvider.revokeDocumentPermission(String)
.
deleteDocument
in class DocumentsProvider
documentId
- the document to delete.FileNotFoundException
protected static Uri getNotificationUri()