Class ShadowContentResolver
- java.lang.Object
-
- org.robolectric.shadows.ShadowContentResolver
-
@Implements(android.content.ContentResolver.class) public class ShadowContentResolver extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ShadowContentResolver.DeleteStatement
A statement used to delete content in aContentProvider
.static class
ShadowContentResolver.InsertStatement
A statement used to insert content into aContentProvider
.static class
ShadowContentResolver.NotifiedUri
static class
ShadowContentResolver.Statement
A statement used to modify content in aContentProvider
.static class
ShadowContentResolver.Status
static class
ShadowContentResolver.UpdateStatement
A statement used to update content in aContentProvider
.
-
Constructor Summary
Constructors Constructor Description ShadowContentResolver()
-
Method Summary
-
-
-
Method Detail
-
reset
@Resetter public static void reset()
-
registerInputStream
public void registerInputStream(Uri uri, InputStream inputStream)
-
registerInputStreamSupplier
public void registerInputStreamSupplier(Uri uri, Supplier<InputStream> supplier)
-
registerOutputStream
public void registerOutputStream(Uri uri, OutputStream outputStream)
-
registerOutputStreamSupplier
public void registerOutputStreamSupplier(Uri uri, Supplier<OutputStream> supplier)
-
openInputStream
@Implementation protected final InputStream openInputStream(Uri uri) throws FileNotFoundException
- Throws:
FileNotFoundException
-
openOutputStream
@Implementation protected final OutputStream openOutputStream(Uri uri)
-
insert
@Implementation protected final Uri insert(Uri url, ContentValues values)
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
@Implementation protected final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
-
query
@Implementation protected Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal)
-
getType
@Implementation protected String getType(Uri uri)
-
acquireContentProviderClient
@Implementation protected final ContentProviderClient acquireContentProviderClient(String name)
-
acquireContentProviderClient
@Implementation protected final ContentProviderClient acquireContentProviderClient(Uri uri)
-
acquireUnstableContentProviderClient
@Implementation protected final ContentProviderClient acquireUnstableContentProviderClient(String name)
-
acquireUnstableContentProviderClient
@Implementation protected final ContentProviderClient acquireUnstableContentProviderClient(Uri uri)
-
acquireProvider
@Implementation protected final IContentProvider acquireProvider(String name)
-
acquireProvider
@Implementation protected final IContentProvider acquireProvider(Uri uri)
-
acquireUnstableProvider
@Implementation protected final IContentProvider acquireUnstableProvider(String name)
-
acquireUnstableProvider
@Implementation protected final IContentProvider acquireUnstableProvider(Uri uri)
-
delete
@Implementation protected final int delete(Uri url, String where, String[] selectionArgs)
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
@Implementation protected final int bulkInsert(Uri url, ContentValues[] values)
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
@Implementation protected void notifyChange(Uri uri, ContentObserver observer)
-
applyBatch
@Implementation protected ContentProviderResult[] applyBatch(String authority, ArrayList<ContentProviderOperation> operations) throws OperationApplicationException
- Throws:
OperationApplicationException
-
requestSync
@Implementation protected static void requestSync(Account account, String authority, Bundle extras)
-
cancelSync
@Implementation protected static void cancelSync(Account account, String authority)
-
isSyncActive
@Implementation protected static boolean isSyncActive(Account account, String authority)
-
getCurrentSyncs
@Implementation protected static List<SyncInfo> getCurrentSyncs()
-
setIsSyncable
@Implementation protected static void setIsSyncable(Account account, String authority, int syncable)
-
getIsSyncable
@Implementation protected static int getIsSyncable(Account account, String authority)
-
getSyncAutomatically
@Implementation protected static boolean getSyncAutomatically(Account account, String authority)
-
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
@Implementation protected static void validateSyncExtrasBundle(Bundle extras)
-
setMasterSyncAutomatically
@Implementation protected static void setMasterSyncAutomatically(boolean sync)
-
getMasterSyncAutomatically
@Implementation protected static boolean getMasterSyncAutomatically()
-
takePersistableUriPermission
@Implementation(minSdk=19) protected void takePersistableUriPermission(Uri uri, int modeFlags)
-
releasePersistableUriPermission
@Implementation(minSdk=19) protected void releasePersistableUriPermission(Uri uri, int modeFlags)
-
getPersistedUriPermissions
@Implementation(minSdk=19) protected List<UriPermission> getPersistedUriPermissions()
-
getProvider
public static ContentProvider getProvider(Uri uri)
-
registerProviderInternal
public static void registerProviderInternal(String authority, ContentProvider provider)
Internal-only method, do not use!Instead, use
ProviderInfo info = new ProviderInfo(); info.authority = authority; Robolectric.buildContentProvider(ContentProvider.class).create(info);
-
getStatus
public static ShadowContentResolver.Status getStatus(Account account, String authority)
-
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 public void setCursor(BaseCursor cursor)
Deprecated.This method affects all calls, and does not work withContentResolver.acquireContentProviderClient(android.net.Uri)
-
setCursor
@Deprecated public void setCursor(Uri uri, BaseCursor cursorForUri)
Deprecated.This method does not work withContentResolver.acquireContentProviderClient(android.net.Uri)
-
setNextDatabaseIdForInserts
@Deprecated public void setNextDatabaseIdForInserts(int nextId)
Deprecated.This method affects all calls, and does not work withContentResolver.acquireContentProviderClient(android.net.Uri)
-
getStatements
@Deprecated public List<ShadowContentResolver.Statement> 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 public List<ShadowContentResolver.InsertStatement> 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 public List<ShadowContentResolver.UpdateStatement> 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 public List<Uri> getDeletedUris()
Deprecated.
-
getDeleteStatements
@Deprecated public List<ShadowContentResolver.DeleteStatement> getDeleteStatements()
Deprecated.Returns the list ofShadowContentResolver.DeleteStatement
s for corresponding calls toContentResolver.delete(Uri, String, String[])
.- Returns:
- a list of delete statements
-
getNotifiedUris
@Deprecated public List<ShadowContentResolver.NotifiedUri> getNotifiedUris()
Deprecated.
-
getContentProviderOperations
@Deprecated public List<ContentProviderOperation> getContentProviderOperations(String authority)
Deprecated.
-
setContentProviderResult
@Deprecated public void setContentProviderResult(ContentProviderResult[] contentProviderResults)
Deprecated.
-
setRegisterContentProviderException
public void setRegisterContentProviderException(Uri uri, RuntimeException exception)
MakesregisterContentObserver(android.net.Uri, boolean, android.database.ContentObserver)
throw the specified exception for the specified URI.
-
clearRegisterContentProviderException
public void clearRegisterContentProviderException(Uri uri)
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
@Implementation protected void unregisterContentObserver(ContentObserver observer)
-
getSyncAdapterTypes
@Implementation protected static SyncAdapterType[] getSyncAdapterTypes()
-
setSyncAdapterTypes
public static void setSyncAdapterTypes(SyncAdapterType[] syncAdapterTypes)
Sets the SyncAdapterType array which will be returned bygetSyncAdapterTypes()
.
-
getContentObservers
public Collection<ContentObserver> getContentObservers(Uri uri)
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)
-
-