Class ShadowContentResolver
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A statement used to delete content in aContentProvider
.static class
A statement used to insert content into aContentProvider
.static class
static class
A statement used to modify content in aContentProvider
.static class
static class
A statement used to update content in aContentProvider
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected final ContentProviderClient
protected final ContentProviderClient
protected final IContentProvider
acquireProvider
(Uri uri) protected final IContentProvider
acquireProvider
(String name) protected final ContentProviderClient
protected final ContentProviderClient
protected final IContentProvider
protected final IContentProvider
protected static void
addPeriodicSync
(Account account, String authority, Bundle extras, long pollFrequency) protected ContentProviderResult[]
applyBatch
(String authority, ArrayList<ContentProviderOperation> operations) protected final int
bulkInsert
(Uri url, ContentValues[] values) If aContentProvider
is registered for the givenUri
, itsContentProvider.bulkInsert(Uri, ContentValues[])
method will be invoked.protected Bundle
protected static void
cancelSync
(Account account, String authority) void
Clears an exception previously set withsetRegisterContentProviderException(Uri, RuntimeException)
.protected final int
If aContentProvider
is 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 int
getIsSyncable
(Account account, String authority) protected static boolean
Deprecated.protected static List<PeriodicSync>
getPeriodicSyncs
(Account account, String authority) protected List<UriPermission>
static ContentProvider
getProvider
(Uri uri) Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)
static ShadowContentResolver.Status
static ShadowContentResolver.Status
Retrieve information on the status of the given account.protected static SyncAdapterType[]
protected static boolean
getSyncAutomatically
(Account account, String authority) protected String
Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)
protected final Uri
insert
(Uri url, ContentValues values) If aContentProvider
is registered for the givenUri
, itsContentProvider.insert(Uri, ContentValues)
method will be invoked.protected static boolean
isSyncActive
(Account account, String authority) protected void
notifyChange
(Uri uri, ContentObserver observer) protected void
notifyChange
(Uri uri, ContentObserver observer, boolean syncToNetwork) protected static void
onDbCorruption
(String tag, String message, Throwable stacktrace) protected final InputStream
openInputStream
(Uri uri) protected final OutputStream
openOutputStream
(Uri uri) protected final OutputStream
openOutputStream
(Uri uri, String mode) protected final Cursor
query
(Uri uri, String[] projection, Bundle queryArgs, CancellationSignal cancellationSignal) protected final Cursor
protected Cursor
query
(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal) protected void
registerContentObserver
(Uri uri, boolean notifyForDescendents, ContentObserver observer) protected void
registerContentObserver
(Uri uri, boolean notifyForDescendents, ContentObserver observer, int userHandle) void
registerInputStream
(Uri uri, InputStream inputStream) void
registerInputStreamSupplier
(Uri uri, Supplier<InputStream> supplier) void
registerOutputStream
(Uri uri, OutputStream outputStream) void
registerOutputStreamSupplier
(Uri uri, Supplier<OutputStream> supplier) static void
registerProviderInternal
(String authority, ContentProvider provider) Internal-only method, do not use!protected void
releasePersistableUriPermission
(Uri uri, int modeFlags) protected static void
removePeriodicSync
(Account account, String authority, Bundle extras) protected static void
requestSync
(Account account, String authority, Bundle extras) static void
reset()
void
setContentProviderResult
(ContentProviderResult[] contentProviderResults) Deprecated.void
setCursor
(Uri uri, BaseCursor cursorForUri) Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)
void
setCursor
(BaseCursor cursor) Deprecated.This method affects all calls, and does not work withContentResolver.acquireContentProviderClient(android.net.Uri)
protected static void
setIsSyncable
(Account account, String authority, int syncable) protected static void
setMasterSyncAutomatically
(boolean sync) void
setNextDatabaseIdForInserts
(int nextId) Deprecated.This method affects all calls, and does not work withContentResolver.acquireContentProviderClient(android.net.Uri)
void
setRegisterContentProviderException
(Uri uri, RuntimeException exception) MakesregisterContentObserver(android.net.Uri, boolean, android.database.ContentObserver)
throw the specified exception for the specified URI.static void
setSyncAdapterTypes
(SyncAdapterType[] syncAdapterTypes) Sets the SyncAdapterType array which will be returned bygetSyncAdapterTypes()
.protected static void
setSyncAutomatically
(Account account, String authority, boolean sync) protected void
takePersistableUriPermission
(Uri uri, int modeFlags) protected void
unregisterContentObserver
(ContentObserver observer) protected int
update
(Uri uri, ContentValues values, String where, String[] selectionArgs) If aContentProvider
is registered for the givenUri
, itsContentProvider.update(Uri, ContentValues, String, String[])
method will be invoked.protected static void
validateSyncExtrasBundle
(Bundle extras)
-
Constructor Details
-
ShadowContentResolver
public ShadowContentResolver()
-
-
Method Details
-
reset
-
registerInputStream
-
registerInputStreamSupplier
-
registerOutputStream
-
registerOutputStreamSupplier
-
openInputStream
- Throws:
FileNotFoundException
-
openOutputStream
- Throws:
FileNotFoundException
-
openOutputStream
@Implementation protected final OutputStream openOutputStream(Uri uri, String mode) throws FileNotFoundException - Throws:
FileNotFoundException
-
insert
If aContentProvider
is 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
ContentProvider
is found, no action will be taken and aUri
including the incremented value set withsetNextDatabaseIdForInserts(int)
will returned. -
update
@Implementation protected int update(Uri uri, ContentValues values, String where, String[] selectionArgs) If aContentProvider
is 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
ContentProvider
is 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
@Implementation protected final ContentProviderClient acquireUnstableContentProviderClient(String name) -
acquireUnstableContentProviderClient
-
acquireProvider
-
acquireProvider
-
acquireUnstableProvider
-
acquireUnstableProvider
-
delete
If aContentProvider
is 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
ContentProvider
is found, no action will be taken and1
will be returned. -
bulkInsert
If aContentProvider
is 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
ContentProvider
is found, no action will be taken and the number of rows invalues
will 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.InsertStatement
s,ShadowContentResolver.UpdateStatement
s, andShadowContentResolver.DeleteStatement
s invoked on thisContentResolver
.- Returns:
- a list of statements
-
getInsertStatements
Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)
Returns the list ofShadowContentResolver.InsertStatement
s 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.UpdateStatement
s for corresponding calls toContentResolver.update(Uri, ContentValues, String, String[])
.- Returns:
- a list of update statements
-
getDeletedUris
Deprecated. -
getDeleteStatements
Deprecated.Returns the list ofShadowContentResolver.DeleteStatement
s for corresponding calls toContentResolver.delete(Uri, String, String[])
.- Returns:
- a list of delete statements
-
getNotifiedUris
Deprecated. -
getContentProviderOperations
Deprecated. -
setContentProviderResult
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(minSdk=17) 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)