Class UnstableContentResolverClient


  • public class UnstableContentResolverClient
    extends Object
    For internal use only.

    Using this class to communicate with providers in other processes ensures that if the provider process dies your process will not die with it. This class also automatically retries for several seconds any operations that fail due to the provider process not being available, such as when the provider process has crashed or is being reinstalled.

    Unlike the standard ContentProviderClient this class does not require you to release/close instances you obtain, instead this class acquires and releases the internal ContentProviderClient for each method invocation.

    Note that methods in this class eat all usage exceptions and return null (or the default value as with the call method) instead.

    • Constructor Detail

      • UnstableContentResolverClient

        public UnstableContentResolverClient​(ContentResolver contentResolver,
                                             Uri uri)
    • Method Detail

      • insert

        public Uri insert​(ContentValues values)
        Perform ContentProvider.insert(Uri, ContentValues) while allowing for a provider that may not be available momentarily.

        Note this implementation eats all exceptions, including ones resulting from improper usage of the provider such as SecurityException, IllegalArgumentException, etc. See full list at Parcel.writeException(Exception). Watch logs accordingly for errors.

        Returns:
        The result (may be null) upon a successful invocation of insert, or null if the content provider wasn't available even after waiting a few seconds or the insert generated any other type of exception
      • update

        public int update​(ContentValues values,
                          String selection,
                          String[] selectionArgs)
        Perform ContentProvider.update(Uri, ContentValues, String, String[]) while allowing for a provider that may not be available momentarily.

        Note this implementation eats all exceptions, including ones resulting from improper usage of the provider such as SecurityException, IllegalArgumentException, etc. See full list at Parcel.writeException(Exception). Watch logs accordingly for errors.

        Returns:
        The number of rows updated (may be 0) upon a successful invocation of update, or 0 if the content provider wasn't available even after waiting a few seconds or the update generated any other type of exception
      • delete

        public int delete​(String selection,
                          String[] selectionArgs)
        Perform ContentProvider.delete(Uri, String, String[]) while allowing for a provider that may not be available momentarily.

        Note this implementation eats all exceptions, including ones resulting from improper usage of the provider such as SecurityException, IllegalArgumentException, etc. See full list at Parcel.writeException(Exception). Watch logs accordingly for errors.

        Returns:
        The number of rows deleted (may be 0) upon a successful invocation of delete, or 0 if the content provider wasn't available even after waiting a few seconds or the delete generated any other type of exception
      • query

        public Cursor query​(String[] projection,
                            String selection,
                            String[] selectionArgs,
                            String sortOrder)
        Perform ContentProvider.query(Uri, String[], String, String[], String) while allowing for a provider that may not be available momentarily.

        Note this implementation eats all exceptions, including ones resulting from improper usage of the provider such as SecurityException, IllegalArgumentException, etc. See full list at Parcel.writeException(Exception). Watch logs accordingly for errors.

        The caller must close the cursor when it is no longer needed.

        Returns:
        The Cursor (may be null) upon a successful invocation of query, or null if the content provider wasn't available even after retrying a few seconds or the query generated any other type of exception
      • call

        public Bundle call​(String method,
                           String arg,
                           Bundle extras,
                           Bundle defaultResult)
        Perform ContentProvider.call(String, String, String, Bundle) while allowing for a provider that may not be available momentarily.

        Note this implementation eats all exceptions, including ones resulting from improper usage of the provider such as SecurityException, IllegalArgumentException, etc. See full list at Parcel.writeException(Exception). Watch logs accordingly for errors.

        Returns:
        The call result (may be null) upon a successful invocation of call, or defaultResult if the content provider wasn't available even after waiting a few seconds or the call generated any other type of exception