@Implements(value=android.content.ContentResolver.class) public class ShadowContentResolver extends Object
Modifier and Type | Class and Description |
---|---|
static class |
ShadowContentResolver.DeleteStatement
A statement used to delete content in a
ContentProvider . |
static class |
ShadowContentResolver.InsertStatement
A statement used to insert content into a
ContentProvider . |
static class |
ShadowContentResolver.NotifiedUri |
static class |
ShadowContentResolver.Statement
A statement used to modify content in a
ContentProvider . |
static class |
ShadowContentResolver.Status |
static class |
ShadowContentResolver.UpdateStatement
A statement used to update content in a
ContentProvider . |
Constructor and Description |
---|
ShadowContentResolver() |
@Resetter public static void reset()
public void registerInputStream(Uri uri, InputStream inputStream)
public void registerOutputStream(Uri uri, OutputStream outputStream)
@Implementation protected final InputStream openInputStream(Uri uri)
@Implementation protected final OutputStream openOutputStream(Uri uri)
@Implementation protected final Uri insert(Uri url, ContentValues values)
If a ContentProvider
is registered for the given Uri
, its ContentProvider.insert(Uri, ContentValues)
method will be invoked.
Tests can verify that this method was called using getStatements()
or getInsertStatements()
.
If no appropriate ContentProvider
is found, no action will be taken and a Uri
including the incremented value set with setNextDatabaseIdForInserts(int)
will returned.
@Implementation protected int update(Uri uri, ContentValues values, String where, String[] selectionArgs)
If a ContentProvider
is registered for the given Uri
, its ContentProvider.update(Uri, ContentValues, String, String[])
method will be invoked.
Tests can verify that this method was called using getStatements()
or getUpdateStatements()
.
ContentProvider
is found, no action will be taken and 1 will be returned.@Implementation protected final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)
@Implementation protected Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder, CancellationSignal cancellationSignal)
@Implementation protected String getType(Uri uri)
@Implementation protected final ContentProviderClient acquireContentProviderClient(String name)
@Implementation protected final ContentProviderClient acquireContentProviderClient(Uri uri)
@Implementation protected final ContentProviderClient acquireUnstableContentProviderClient(String name)
@Implementation protected final ContentProviderClient acquireUnstableContentProviderClient(Uri uri)
@Implementation protected final IContentProvider acquireProvider(String name)
@Implementation protected final IContentProvider acquireProvider(Uri uri)
@Implementation protected final IContentProvider acquireUnstableProvider(String name)
@Implementation protected final IContentProvider acquireUnstableProvider(Uri uri)
@Implementation protected final int delete(Uri url, String where, String[] selectionArgs)
If a ContentProvider
is registered for the given Uri
, its ContentProvider.delete(Uri, String, String[])
method will be invoked.
Tests can verify that this method was called using getDeleteStatements()
or getDeletedUris()
.
If no appropriate ContentProvider
is found, no action will be taken and 1
will be returned.
@Implementation protected final int bulkInsert(Uri url, ContentValues[] values)
If a ContentProvider
is registered for the given Uri
, its ContentProvider.bulkInsert(Uri, ContentValues[])
method will be invoked.
Tests can verify that this method was called using getStatements()
or getInsertStatements()
.
If no appropriate ContentProvider
is found, no action will be taken and the number of rows in values
will be returned.
@Implementation protected void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork)
@Implementation protected void notifyChange(Uri uri, ContentObserver observer)
@Implementation protected ContentProviderResult[] applyBatch(String authority, ArrayList<ContentProviderOperation> operations) throws OperationApplicationException
OperationApplicationException
@Implementation protected static void requestSync(Account account, String authority, Bundle extras)
@Implementation protected static void cancelSync(Account account, String authority)
@Implementation protected static boolean isSyncActive(Account account, String authority)
@Implementation protected static void setIsSyncable(Account account, String authority, int syncable)
@Implementation protected static int getIsSyncable(Account account, String authority)
@Implementation protected static boolean getSyncAutomatically(Account account, String authority)
@Implementation protected static void setSyncAutomatically(Account account, String authority, boolean sync)
@Implementation protected static void addPeriodicSync(Account account, String authority, Bundle extras, long pollFrequency)
@Implementation protected static void removePeriodicSync(Account account, String authority, Bundle extras)
@Implementation protected static List<PeriodicSync> getPeriodicSyncs(Account account, String authority)
@Implementation protected static void validateSyncExtrasBundle(Bundle extras)
@Implementation protected static void setMasterSyncAutomatically(boolean sync)
@Implementation protected static boolean getMasterSyncAutomatically()
@Implementation(minSdk=19) protected void takePersistableUriPermission(Uri uri, int modeFlags)
@Implementation(minSdk=19) protected void releasePersistableUriPermission(Uri uri, int modeFlags)
@Implementation(minSdk=19) protected List<UriPermission> getPersistedUriPermissions()
public static ContentProvider getProvider(Uri uri)
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);
public static ShadowContentResolver.Status getStatus(Account account, String authority)
public static ShadowContentResolver.Status getStatus(Account account, String authority, boolean create)
Retrieve information on the status of the given account.
account
- the accountauthority
- the authoritycreate
- whether to create if no such account is foundpublic void setCursor(BaseCursor cursor)
public void setCursor(Uri uri, BaseCursor cursorForUri)
public void setNextDatabaseIdForInserts(int nextId)
public List<ShadowContentResolver.Statement> getStatements()
Returns the list of ShadowContentResolver.InsertStatement
s, ShadowContentResolver.UpdateStatement
s, and ShadowContentResolver.DeleteStatement
s invoked on this ContentResolver
.
public List<ShadowContentResolver.InsertStatement> getInsertStatements()
Returns the list of ShadowContentResolver.InsertStatement
s for corresponding calls to ContentResolver.insert(Uri, ContentValues)
or ContentResolver.bulkInsert(Uri, ContentValues[])
.
public List<ShadowContentResolver.UpdateStatement> getUpdateStatements()
Returns the list of ShadowContentResolver.UpdateStatement
s for corresponding calls to ContentResolver.update(Uri, ContentValues, String, String[])
.
public List<ShadowContentResolver.DeleteStatement> getDeleteStatements()
Returns the list of ShadowContentResolver.DeleteStatement
s for corresponding calls to ContentResolver.delete(Uri, String, String[])
.
public List<ShadowContentResolver.NotifiedUri> getNotifiedUris()
public List<ContentProviderOperation> getContentProviderOperations(String authority)
public void setContentProviderResult(ContentProviderResult[] contentProviderResults)
@Implementation protected void registerContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer)
@Implementation(minSdk=17) protected void registerContentObserver(Uri uri, boolean notifyForDescendents, ContentObserver observer, int userHandle)
@Implementation protected void unregisterContentObserver(ContentObserver observer)
@Implementation protected static SyncAdapterType[] getSyncAdapterTypes()
public static void setSyncAdapterTypes(SyncAdapterType[] syncAdapterTypes)
Sets the SyncAdapterType array which will be returned by getSyncAdapterTypes()
.
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.
uri
- Given URI