Class ShadowContentResolver
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA statement used to delete content in aContentProvider.static classA statement used to insert content into aContentProvider.static classstatic classA statement used to modify content in aContentProvider.static classstatic classA statement used to update content in aContentProvider. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ContentProviderClientprotected ContentProviderClientprotected IContentProvideracquireProvider(Uri uri) protected IContentProvideracquireProvider(String name) protected ContentProviderClientprotected ContentProviderClientprotected final IContentProviderprotected IContentProviderprotected static voidaddPeriodicSync(Account account, String authority, Bundle extras, long pollFrequency) protected ContentProviderResult[]applyBatch(String authority, ArrayList<ContentProviderOperation> operations) protected intbulkInsert(Uri url, ContentValues[] values) If aContentProvideris registered for the givenUri, itsContentProvider.bulkInsert(Uri, ContentValues[])method will be invoked.protected Bundleprotected static voidcancelSync(Account account, String authority) voidClears an exception previously set withsetRegisterContentProviderException(Uri, RuntimeException).protected intIf aContentProvideris registered for the givenUri, itsContentProvider.delete(Uri, String, String[])method will be invoked.getContentObservers(Uri uri) Returns the content observers registered for updates under the given URI.getContentProviderOperations(String authority) Deprecated.Deprecated.Deprecated.Deprecated.protected static intgetIsSyncable(Account account, String authority) protected static booleanDeprecated.protected static List<PeriodicSync>getPeriodicSyncs(Account account, String authority) protected List<UriPermission>static ContentProvidergetProvider(Uri uri) Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)static ShadowContentResolver.Statusstatic ShadowContentResolver.StatusRetrieve information on the status of the given account.protected static SyncAdapterType[]protected static booleangetSyncAutomatically(Account account, String authority) protected StringDeprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)protected Uriinsert(Uri url, ContentValues values) If aContentProvideris registered for the givenUri, itsContentProvider.insert(Uri, ContentValues)method will be invoked.protected static booleanisSyncActive(Account account, String authority) protected voidnotifyChange(Uri uri, ContentObserver observer) protected voidnotifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork) protected static voidonDbCorruption(String tag, String message, Throwable stacktrace) protected InputStreamopenInputStream(Uri uri) protected OutputStreamopenOutputStream(Uri uri) protected OutputStreamopenOutputStream(Uri uri, String mode) protected final Cursorquery(Uri uri, String[] projection, Bundle queryArgs, CancellationSignal cancellationSignal) protected Cursorprotected Cursorquery(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) protected voidregisterContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer) protected voidregisterContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer, int userHandle) voidregisterInputStream(Uri uri, InputStream inputStream) voidregisterInputStreamSupplier(Uri uri, Supplier<InputStream> supplier) voidregisterOutputStream(Uri uri, OutputStream outputStream) voidregisterOutputStreamSupplier(Uri uri, Supplier<OutputStream> supplier) static voidregisterProviderInternal(String authority, ContentProvider provider) Internal-only method, do not use!protected voidreleasePersistableUriPermission(Uri uri, int modeFlags) protected static voidremovePeriodicSync(Account account, String authority, Bundle extras) protected static voidrequestSync(Account account, String authority, Bundle extras) static voidreset()voidsetCursor(Uri uri, BaseCursor cursorForUri) Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)voidsetCursor(BaseCursor cursor) Deprecated.This method affects all calls, and does not work withContentResolver.acquireContentProviderClient(android.net.Uri)protected static voidsetIsSyncable(Account account, String authority, int syncable) protected static voidsetMasterSyncAutomatically(boolean sync) voidsetNextDatabaseIdForInserts(int nextId) Deprecated.This method affects all calls, and does not work withContentResolver.acquireContentProviderClient(android.net.Uri)voidsetRegisterContentProviderException(Uri uri, RuntimeException exception) MakesregisterContentObserver(android.net.Uri, boolean, android.database.ContentObserver)throw the specified exception for the specified URI.static voidsetSyncAdapterTypes(SyncAdapterType[] syncAdapterTypes) Sets the SyncAdapterType array which will be returned bygetSyncAdapterTypes().protected static voidsetSyncAutomatically(Account account, String authority, boolean sync) protected voidtakePersistableUriPermission(Uri uri, int modeFlags) protected voidunregisterContentObserver(ContentObserver observer) protected intupdate(Uri uri, ContentValues values, String where, String[] selectionArgs) If aContentProvideris registered for the givenUri, itsContentProvider.update(Uri, ContentValues, String, String[])method will be invoked.protected static voidvalidateSyncExtrasBundle(Bundle extras)
-
Constructor Details
-
ShadowContentResolver
public ShadowContentResolver()
-
-
Method Details
-
reset
-
registerInputStream
-
registerInputStreamSupplier
-
registerOutputStream
-
registerOutputStreamSupplier
-
openInputStream
- Throws:
FileNotFoundException
-
openOutputStream
- Throws:
FileNotFoundException
-
openOutputStream
@Implementation protected OutputStream openOutputStream(Uri uri, String mode) throws FileNotFoundException - Throws:
FileNotFoundException
-
insert
If aContentProvideris registered for the givenUri, itsContentProvider.insert(Uri, ContentValues)method will be invoked.Tests can verify that this method was called using
getStatements()orgetInsertStatements().If no appropriate
ContentProvideris found, no action will be taken and aUriincluding the incremented value set withsetNextDatabaseIdForInserts(int)will returned. -
update
@Implementation protected int update(Uri uri, ContentValues values, String where, String[] selectionArgs) If aContentProvideris registered for the givenUri, itsContentProvider.update(Uri, ContentValues, String, String[])method will be invoked.Tests can verify that this method was called using
getStatements()orgetUpdateStatements().- Returns:
- If no appropriate
ContentProvideris found, no action will be taken and 1 will be returned.
-
query
@Implementation(minSdk=26) protected final Cursor query(Uri uri, String[] projection, Bundle queryArgs, CancellationSignal cancellationSignal) -
query
-
query
@Implementation protected Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) -
getType
-
call
-
acquireContentProviderClient
-
acquireContentProviderClient
-
acquireUnstableContentProviderClient
-
acquireUnstableContentProviderClient
-
acquireProvider
-
acquireProvider
-
acquireUnstableProvider
-
acquireUnstableProvider
-
delete
If aContentProvideris registered for the givenUri, itsContentProvider.delete(Uri, String, String[])method will be invoked.Tests can verify that this method was called using
getDeleteStatements()orgetDeletedUris().If no appropriate
ContentProvideris found, no action will be taken and1will be returned. -
bulkInsert
If aContentProvideris registered for the givenUri, itsContentProvider.bulkInsert(Uri, ContentValues[])method will be invoked.Tests can verify that this method was called using
getStatements()orgetInsertStatements().If no appropriate
ContentProvideris found, no action will be taken and the number of rows invalueswill be returned. -
notifyChange
@Implementation protected void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork) -
notifyChange
-
applyBatch
@Implementation protected ContentProviderResult[] applyBatch(String authority, ArrayList<ContentProviderOperation> operations) throws OperationApplicationException - Throws:
OperationApplicationException
-
requestSync
-
cancelSync
-
isSyncActive
-
getCurrentSyncs
-
setIsSyncable
@Implementation protected static void setIsSyncable(Account account, String authority, int syncable) -
getIsSyncable
-
getSyncAutomatically
-
setSyncAutomatically
@Implementation protected static void setSyncAutomatically(Account account, String authority, boolean sync) -
addPeriodicSync
@Implementation protected static void addPeriodicSync(Account account, String authority, Bundle extras, long pollFrequency) -
removePeriodicSync
@Implementation protected static void removePeriodicSync(Account account, String authority, Bundle extras) -
getPeriodicSyncs
@Implementation protected static List<PeriodicSync> getPeriodicSyncs(Account account, String authority) -
validateSyncExtrasBundle
-
setMasterSyncAutomatically
-
getMasterSyncAutomatically
-
takePersistableUriPermission
-
releasePersistableUriPermission
-
getPersistedUriPermissions
-
getProvider
-
registerProviderInternal
Internal-only method, do not use!Instead, use
ProviderInfo info = new ProviderInfo(); info.authority = authority; Robolectric.buildContentProvider(ContentProvider.class).create(info);
-
getStatus
-
getStatus
public static ShadowContentResolver.Status getStatus(Account account, String authority, boolean create) Retrieve information on the status of the given account.- Parameters:
account- the accountauthority- the authoritycreate- whether to create if no such account is found- Returns:
- the account's status
-
setCursor
Deprecated.This method affects all calls, and does not work withContentResolver.acquireContentProviderClient(android.net.Uri) -
setCursor
Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri) -
setNextDatabaseIdForInserts
Deprecated.This method affects all calls, and does not work withContentResolver.acquireContentProviderClient(android.net.Uri) -
getStatements
Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)Returns the list ofShadowContentResolver.InsertStatements,ShadowContentResolver.UpdateStatements, andShadowContentResolver.DeleteStatements invoked on thisContentResolver.- Returns:
- a list of statements
-
getInsertStatements
Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)Returns the list ofShadowContentResolver.InsertStatements for corresponding calls toContentResolver.insert(Uri, ContentValues)orContentResolver.bulkInsert(Uri, ContentValues[]).- Returns:
- a list of insert statements
-
getUpdateStatements
Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)Returns the list ofShadowContentResolver.UpdateStatements for corresponding calls toContentResolver.update(Uri, ContentValues, String, String[]).- Returns:
- a list of update statements
-
getDeletedUris
Deprecated. -
getDeleteStatements
Deprecated.Returns the list ofShadowContentResolver.DeleteStatements for corresponding calls toContentResolver.delete(Uri, String, String[]).- Returns:
- a list of delete statements
-
getNotifiedUris
Deprecated. -
getContentProviderOperations
Deprecated. -
setRegisterContentProviderException
MakesregisterContentObserver(android.net.Uri, boolean, android.database.ContentObserver)throw the specified exception for the specified URI. -
clearRegisterContentProviderException
Clears an exception previously set withsetRegisterContentProviderException(Uri, RuntimeException). -
registerContentObserver
@Implementation protected void registerContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer) -
registerContentObserver
@Implementation protected void registerContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer, int userHandle) -
unregisterContentObserver
-
getSyncAdapterTypes
-
setSyncAdapterTypes
Sets the SyncAdapterType array which will be returned bygetSyncAdapterTypes(). -
getContentObservers
Returns the content observers registered for updates under the given URI.Will be empty if no observer is registered.
- Parameters:
uri- Given URI- Returns:
- The content observers, or null
-
onDbCorruption
@Implementation(minSdk=29) protected static void onDbCorruption(String tag, String message, Throwable stacktrace)
-
ContentResolver.acquireContentProviderClient(android.net.Uri)