Class ShadowContentResolver


  • @Implements(android.content.ContentResolver.class)
    public class ShadowContentResolver
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      protected android.content.ContentProviderClient acquireContentProviderClient​(android.net.Uri uri)  
      protected android.content.ContentProviderClient acquireContentProviderClient​(java.lang.String name)  
      protected android.content.IContentProvider acquireProvider​(android.net.Uri uri)  
      protected android.content.IContentProvider acquireProvider​(java.lang.String name)  
      protected android.content.ContentProviderClient acquireUnstableContentProviderClient​(android.net.Uri uri)  
      protected android.content.ContentProviderClient acquireUnstableContentProviderClient​(java.lang.String name)  
      protected android.content.IContentProvider acquireUnstableProvider​(android.net.Uri uri)  
      protected android.content.IContentProvider acquireUnstableProvider​(java.lang.String name)  
      protected static void addPeriodicSync​(android.accounts.Account account, java.lang.String authority, android.os.Bundle extras, long pollFrequency)  
      protected android.content.ContentProviderResult[] applyBatch​(java.lang.String authority, java.util.ArrayList<android.content.ContentProviderOperation> operations)  
      protected int bulkInsert​(android.net.Uri url, android.content.ContentValues[] values)
      If a ContentProvider is registered for the given Uri, its ContentProvider.bulkInsert(Uri, ContentValues[]) method will be invoked.
      protected android.os.Bundle call​(android.net.Uri uri, java.lang.String method, java.lang.String arg, android.os.Bundle extras)  
      protected static void cancelSync​(android.accounts.Account account, java.lang.String authority)  
      void clearRegisterContentProviderException​(android.net.Uri uri)
      Clears an exception previously set with setRegisterContentProviderException(Uri, RuntimeException).
      protected int delete​(android.net.Uri url, java.lang.String where, java.lang.String[] selectionArgs)
      If a ContentProvider is registered for the given Uri, its ContentProvider.delete(Uri, String, String[]) method will be invoked.
      java.util.Collection<android.database.ContentObserver> getContentObservers​(android.net.Uri uri)
      Returns the content observers registered for updates under the given URI.
      java.util.List<android.content.ContentProviderOperation> getContentProviderOperations​(java.lang.String authority)
      Deprecated.
      java.util.List<android.net.Uri> getDeletedUris()
      Deprecated.
      java.util.List<ShadowContentResolver.DeleteStatement> getDeleteStatements()
      Deprecated.
      java.util.List<ShadowContentResolver.InsertStatement> getInsertStatements()
      Deprecated.
      This method does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
      protected static int getIsSyncable​(android.accounts.Account account, java.lang.String authority)  
      protected static boolean getMasterSyncAutomatically()  
      java.util.List<ShadowContentResolver.NotifiedUri> getNotifiedUris()
      Deprecated.
      protected static java.util.List<android.content.PeriodicSync> getPeriodicSyncs​(android.accounts.Account account, java.lang.String authority)  
      protected java.util.List<android.content.UriPermission> getPersistedUriPermissions()  
      static android.content.ContentProvider getProvider​(android.net.Uri uri)  
      java.util.List<ShadowContentResolver.Statement> getStatements()
      Deprecated.
      This method does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
      static ShadowContentResolver.Status getStatus​(android.accounts.Account account, java.lang.String authority)  
      static ShadowContentResolver.Status getStatus​(android.accounts.Account account, java.lang.String authority, boolean create)
      Retrieve information on the status of the given account.
      protected static android.content.SyncAdapterType[] getSyncAdapterTypes()  
      protected static boolean getSyncAutomatically​(android.accounts.Account account, java.lang.String authority)  
      protected java.lang.String getType​(android.net.Uri uri)  
      java.util.List<ShadowContentResolver.UpdateStatement> getUpdateStatements()
      Deprecated.
      This method does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
      protected android.net.Uri insert​(android.net.Uri url, android.content.ContentValues values)
      If a ContentProvider is registered for the given Uri, its ContentProvider.insert(Uri, ContentValues) method will be invoked.
      protected static boolean isSyncActive​(android.accounts.Account account, java.lang.String authority)  
      protected void notifyChange​(android.net.Uri uri, android.database.ContentObserver observer)  
      protected void notifyChange​(android.net.Uri uri, android.database.ContentObserver observer, boolean syncToNetwork)  
      protected java.io.InputStream openInputStream​(android.net.Uri uri)  
      protected java.io.OutputStream openOutputStream​(android.net.Uri uri)  
      protected android.database.Cursor query​(android.net.Uri uri, java.lang.String[] projection, android.os.Bundle queryArgs, android.os.CancellationSignal cancellationSignal)  
      protected android.database.Cursor query​(android.net.Uri uri, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sortOrder)  
      protected android.database.Cursor query​(android.net.Uri uri, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sortOrder, android.os.CancellationSignal cancellationSignal)  
      protected void registerContentObserver​(android.net.Uri uri, boolean notifyForDescendents, android.database.ContentObserver observer)  
      protected void registerContentObserver​(android.net.Uri uri, boolean notifyForDescendents, android.database.ContentObserver observer, int userHandle)  
      void registerInputStream​(android.net.Uri uri, java.io.InputStream inputStream)  
      void registerInputStreamSupplier​(android.net.Uri uri, java.util.function.Supplier<java.io.InputStream> supplier)  
      void registerOutputStream​(android.net.Uri uri, java.io.OutputStream outputStream)  
      void registerOutputStreamSupplier​(android.net.Uri uri, java.util.function.Supplier<java.io.OutputStream> supplier)  
      static void registerProviderInternal​(java.lang.String authority, android.content.ContentProvider provider)
      Internal-only method, do not use!
      protected void releasePersistableUriPermission​(android.net.Uri uri, int modeFlags)  
      protected static void removePeriodicSync​(android.accounts.Account account, java.lang.String authority, android.os.Bundle extras)  
      protected static void requestSync​(android.accounts.Account account, java.lang.String authority, android.os.Bundle extras)  
      static void reset()  
      void setContentProviderResult​(android.content.ContentProviderResult[] contentProviderResults)
      Deprecated.
      void setCursor​(android.net.Uri uri, BaseCursor cursorForUri)
      Deprecated.
      This method does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
      void setCursor​(BaseCursor cursor)
      Deprecated.
      This method affects all calls, and does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
      protected static void setIsSyncable​(android.accounts.Account account, java.lang.String authority, int syncable)  
      protected static void setMasterSyncAutomatically​(boolean sync)  
      void setNextDatabaseIdForInserts​(int nextId)
      Deprecated.
      This method affects all calls, and does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
      void setRegisterContentProviderException​(android.net.Uri uri, java.lang.RuntimeException exception)
      Makes registerContentObserver(android.net.Uri, boolean, android.database.ContentObserver) throw the specified exception for the specified URI.
      static void setSyncAdapterTypes​(android.content.SyncAdapterType[] syncAdapterTypes)
      Sets the SyncAdapterType array which will be returned by getSyncAdapterTypes().
      protected static void setSyncAutomatically​(android.accounts.Account account, java.lang.String authority, boolean sync)  
      protected void takePersistableUriPermission​(android.net.Uri uri, int modeFlags)  
      protected void unregisterContentObserver​(android.database.ContentObserver observer)  
      protected int update​(android.net.Uri uri, android.content.ContentValues values, java.lang.String where, java.lang.String[] selectionArgs)
      If a ContentProvider is registered for the given Uri, its ContentProvider.update(Uri, ContentValues, String, String[]) method will be invoked.
      protected static void validateSyncExtrasBundle​(android.os.Bundle extras)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ShadowContentResolver

        public ShadowContentResolver()
    • Method Detail

      • reset

        @Resetter
        public static void reset()
      • registerInputStream

        public void registerInputStream​(android.net.Uri uri,
                                        java.io.InputStream inputStream)
      • registerInputStreamSupplier

        public void registerInputStreamSupplier​(android.net.Uri uri,
                                                java.util.function.Supplier<java.io.InputStream> supplier)
      • registerOutputStream

        public void registerOutputStream​(android.net.Uri uri,
                                         java.io.OutputStream outputStream)
      • registerOutputStreamSupplier

        public void registerOutputStreamSupplier​(android.net.Uri uri,
                                                 java.util.function.Supplier<java.io.OutputStream> supplier)
      • openInputStream

        @Implementation
        protected final java.io.InputStream openInputStream​(android.net.Uri uri)
      • openOutputStream

        @Implementation
        protected final java.io.OutputStream openOutputStream​(android.net.Uri uri)
      • insert

        @Implementation
        protected final android.net.Uri insert​(android.net.Uri url,
                                               android.content.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.
      • update

        @Implementation
        protected int update​(android.net.Uri uri,
                             android.content.ContentValues values,
                             java.lang.String where,
                             java.lang.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().
        Returns:
        If no appropriate ContentProvider is found, no action will be taken and 1 will be returned.
      • query

        @Implementation(minSdk=26)
        protected final android.database.Cursor query​(android.net.Uri uri,
                                                      java.lang.String[] projection,
                                                      android.os.Bundle queryArgs,
                                                      android.os.CancellationSignal cancellationSignal)
      • query

        @Implementation
        protected final android.database.Cursor query​(android.net.Uri uri,
                                                      java.lang.String[] projection,
                                                      java.lang.String selection,
                                                      java.lang.String[] selectionArgs,
                                                      java.lang.String sortOrder)
      • query

        @Implementation
        protected android.database.Cursor query​(android.net.Uri uri,
                                                java.lang.String[] projection,
                                                java.lang.String selection,
                                                java.lang.String[] selectionArgs,
                                                java.lang.String sortOrder,
                                                android.os.CancellationSignal cancellationSignal)
      • getType

        @Implementation
        protected java.lang.String getType​(android.net.Uri uri)
      • call

        @Implementation
        protected android.os.Bundle call​(android.net.Uri uri,
                                         java.lang.String method,
                                         java.lang.String arg,
                                         android.os.Bundle extras)
      • acquireContentProviderClient

        @Implementation
        protected final android.content.ContentProviderClient acquireContentProviderClient​(java.lang.String name)
      • acquireContentProviderClient

        @Implementation
        protected final android.content.ContentProviderClient acquireContentProviderClient​(android.net.Uri uri)
      • acquireUnstableContentProviderClient

        @Implementation
        protected final android.content.ContentProviderClient acquireUnstableContentProviderClient​(java.lang.String name)
      • acquireUnstableContentProviderClient

        @Implementation
        protected final android.content.ContentProviderClient acquireUnstableContentProviderClient​(android.net.Uri uri)
      • acquireProvider

        @Implementation
        protected final android.content.IContentProvider acquireProvider​(java.lang.String name)
      • acquireProvider

        @Implementation
        protected final android.content.IContentProvider acquireProvider​(android.net.Uri uri)
      • acquireUnstableProvider

        @Implementation
        protected final android.content.IContentProvider acquireUnstableProvider​(java.lang.String name)
      • acquireUnstableProvider

        @Implementation
        protected final android.content.IContentProvider acquireUnstableProvider​(android.net.Uri uri)
      • delete

        @Implementation
        protected final int delete​(android.net.Uri url,
                                   java.lang.String where,
                                   java.lang.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.
      • bulkInsert

        @Implementation
        protected final int bulkInsert​(android.net.Uri url,
                                       android.content.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.
      • notifyChange

        @Implementation
        protected void notifyChange​(android.net.Uri uri,
                                    android.database.ContentObserver observer,
                                    boolean syncToNetwork)
      • notifyChange

        @Implementation
        protected void notifyChange​(android.net.Uri uri,
                                    android.database.ContentObserver observer)
      • applyBatch

        @Implementation
        protected android.content.ContentProviderResult[] applyBatch​(java.lang.String authority,
                                                                     java.util.ArrayList<android.content.ContentProviderOperation> operations)
                                                              throws android.content.OperationApplicationException
        Throws:
        android.content.OperationApplicationException
      • requestSync

        @Implementation
        protected static void requestSync​(android.accounts.Account account,
                                          java.lang.String authority,
                                          android.os.Bundle extras)
      • cancelSync

        @Implementation
        protected static void cancelSync​(android.accounts.Account account,
                                         java.lang.String authority)
      • isSyncActive

        @Implementation
        protected static boolean isSyncActive​(android.accounts.Account account,
                                              java.lang.String authority)
      • setIsSyncable

        @Implementation
        protected static void setIsSyncable​(android.accounts.Account account,
                                            java.lang.String authority,
                                            int syncable)
      • getIsSyncable

        @Implementation
        protected static int getIsSyncable​(android.accounts.Account account,
                                           java.lang.String authority)
      • getSyncAutomatically

        @Implementation
        protected static boolean getSyncAutomatically​(android.accounts.Account account,
                                                      java.lang.String authority)
      • setSyncAutomatically

        @Implementation
        protected static void setSyncAutomatically​(android.accounts.Account account,
                                                   java.lang.String authority,
                                                   boolean sync)
      • addPeriodicSync

        @Implementation
        protected static void addPeriodicSync​(android.accounts.Account account,
                                              java.lang.String authority,
                                              android.os.Bundle extras,
                                              long pollFrequency)
      • removePeriodicSync

        @Implementation
        protected static void removePeriodicSync​(android.accounts.Account account,
                                                 java.lang.String authority,
                                                 android.os.Bundle extras)
      • getPeriodicSyncs

        @Implementation
        protected static java.util.List<android.content.PeriodicSync> getPeriodicSyncs​(android.accounts.Account account,
                                                                                       java.lang.String authority)
      • validateSyncExtrasBundle

        @Implementation
        protected static void validateSyncExtrasBundle​(android.os.Bundle extras)
      • setMasterSyncAutomatically

        @Implementation
        protected static void setMasterSyncAutomatically​(boolean sync)
      • getMasterSyncAutomatically

        @Implementation
        protected static boolean getMasterSyncAutomatically()
      • takePersistableUriPermission

        @Implementation(minSdk=19)
        protected void takePersistableUriPermission​(android.net.Uri uri,
                                                    int modeFlags)
      • releasePersistableUriPermission

        @Implementation(minSdk=19)
        protected void releasePersistableUriPermission​(android.net.Uri uri,
                                                       int modeFlags)
      • getPersistedUriPermissions

        @Implementation(minSdk=19)
        protected java.util.List<android.content.UriPermission> getPersistedUriPermissions()
      • getProvider

        public static android.content.ContentProvider getProvider​(android.net.Uri uri)
      • registerProviderInternal

        public static void registerProviderInternal​(java.lang.String authority,
                                                    android.content.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​(android.accounts.Account account,
                                                             java.lang.String authority,
                                                             boolean create)
        Retrieve information on the status of the given account.
        Parameters:
        account - the account
        authority - the authority
        create - 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 with ContentResolver.acquireContentProviderClient(android.net.Uri)
      • setCursor

        @Deprecated
        public void setCursor​(android.net.Uri uri,
                              BaseCursor cursorForUri)
        Deprecated.
        This method does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
      • setNextDatabaseIdForInserts

        @Deprecated
        public void setNextDatabaseIdForInserts​(int nextId)
        Deprecated.
        This method affects all calls, and does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
      • getInsertStatements

        @Deprecated
        public java.util.List<ShadowContentResolver.InsertStatement> getInsertStatements()
        Deprecated.
        This method does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
        Returns the list of ShadowContentResolver.InsertStatements for corresponding calls to ContentResolver.insert(Uri, ContentValues) or ContentResolver.bulkInsert(Uri, ContentValues[]).
        Returns:
        a list of insert statements
      • getUpdateStatements

        @Deprecated
        public java.util.List<ShadowContentResolver.UpdateStatement> getUpdateStatements()
        Deprecated.
        This method does not work with ContentResolver.acquireContentProviderClient(android.net.Uri)
        Returns the list of ShadowContentResolver.UpdateStatements for corresponding calls to ContentResolver.update(Uri, ContentValues, String, String[]).
        Returns:
        a list of update statements
      • getDeletedUris

        @Deprecated
        public java.util.List<android.net.Uri> getDeletedUris()
        Deprecated.
      • getContentProviderOperations

        @Deprecated
        public java.util.List<android.content.ContentProviderOperation> getContentProviderOperations​(java.lang.String authority)
        Deprecated.
      • setContentProviderResult

        @Deprecated
        public void setContentProviderResult​(android.content.ContentProviderResult[] contentProviderResults)
        Deprecated.
      • registerContentObserver

        @Implementation
        protected void registerContentObserver​(android.net.Uri uri,
                                               boolean notifyForDescendents,
                                               android.database.ContentObserver observer)
      • registerContentObserver

        @Implementation(minSdk=17)
        protected void registerContentObserver​(android.net.Uri uri,
                                               boolean notifyForDescendents,
                                               android.database.ContentObserver observer,
                                               int userHandle)
      • unregisterContentObserver

        @Implementation
        protected void unregisterContentObserver​(android.database.ContentObserver observer)
      • getSyncAdapterTypes

        @Implementation
        protected static android.content.SyncAdapterType[] getSyncAdapterTypes()
      • setSyncAdapterTypes

        public static void setSyncAdapterTypes​(android.content.SyncAdapterType[] syncAdapterTypes)
        Sets the SyncAdapterType array which will be returned by getSyncAdapterTypes().
      • getContentObservers

        public java.util.Collection<android.database.ContentObserver> getContentObservers​(android.net.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