FileDocCategorySizeDatePackage
ContentProviderClient.javaAPI DocAndroid 5.1 API16868Thu Mar 12 22:22:10 GMT 2015android.content

ContentProviderClient

public class ContentProviderClient extends Object
The public interface object used to interact with a {@link ContentProvider}. This is obtained by calling {@link ContentResolver#acquireContentProviderClient}. This object must be released using {@link #release} in order to indicate to the system that the {@link ContentProvider} is no longer needed and can be killed to free up resources.

Note that you should generally create a new ContentProviderClient instance for each thread that will be performing operations. Unlike {@link ContentResolver}, the methods here such as {@link #query} and {@link #openFile} are not thread safe -- you must not call {@link #release()} on the ContentProviderClient those calls are made from until you are finished with the data they have returned.

Fields Summary
private static final String
TAG
private static android.os.Handler
sAnrHandler
private final ContentResolver
mContentResolver
private final IContentProvider
mContentProvider
private final String
mPackageName
private final boolean
mStable
private final dalvik.system.CloseGuard
mGuard
private long
mAnrTimeout
private NotRespondingRunnable
mAnrRunnable
private boolean
mReleased
Constructors Summary
ContentProviderClient(ContentResolver contentResolver, IContentProvider contentProvider, boolean stable)
{@hide}


      
    
                  
        mContentResolver = contentResolver;
        mContentProvider = contentProvider;
        mPackageName = contentResolver.mPackageName;
        mStable = stable;

        mGuard.open("release");
    
Methods Summary
private voidafterRemote()

        if (mAnrRunnable != null) {
            sAnrHandler.removeCallbacks(mAnrRunnable);
        }
    
public ContentProviderResult[]applyBatch(java.util.ArrayList operations)
See {@link ContentProvider#applyBatch ContentProvider.applyBatch}

        beforeRemote();
        try {
            return mContentProvider.applyBatch(mPackageName, operations);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
private voidbeforeRemote()

        if (mAnrRunnable != null) {
            sAnrHandler.postDelayed(mAnrRunnable, mAnrTimeout);
        }
    
public intbulkInsert(android.net.Uri url, ContentValues[] initialValues)
See {@link ContentProvider#bulkInsert ContentProvider.bulkInsert}

        beforeRemote();
        try {
            return mContentProvider.bulkInsert(mPackageName, url, initialValues);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public android.os.Bundlecall(java.lang.String method, java.lang.String arg, android.os.Bundle extras)
See {@link ContentProvider#call(String, String, Bundle)}

        beforeRemote();
        try {
            return mContentProvider.call(mPackageName, method, arg, extras);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public final android.net.Uricanonicalize(android.net.Uri url)
See {@link ContentProvider#canonicalize}

        beforeRemote();
        try {
            return mContentProvider.canonicalize(mPackageName, url);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public intdelete(android.net.Uri url, java.lang.String selection, java.lang.String[] selectionArgs)
See {@link ContentProvider#delete ContentProvider.delete}

        beforeRemote();
        try {
            return mContentProvider.delete(mPackageName, url, selection, selectionArgs);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
protected voidfinalize()

        if (mGuard != null) {
            mGuard.warnIfOpen();
        }
    
public ContentProvidergetLocalContentProvider()
Get a reference to the {@link ContentProvider} that is associated with this client. If the {@link ContentProvider} is running in a different process then null will be returned. This can be used if you know you are running in the same process as a provider, and want to get direct access to its implementation details.

return
If the associated {@link ContentProvider} is local, returns it. Otherwise returns null.

        return ContentProvider.coerceToLocalContentProvider(mContentProvider);
    
public java.lang.String[]getStreamTypes(android.net.Uri url, java.lang.String mimeTypeFilter)
See {@link ContentProvider#getStreamTypes ContentProvider.getStreamTypes}

        beforeRemote();
        try {
            return mContentProvider.getStreamTypes(url, mimeTypeFilter);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public java.lang.StringgetType(android.net.Uri url)
See {@link ContentProvider#getType ContentProvider.getType}

        beforeRemote();
        try {
            return mContentProvider.getType(url);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public android.net.Uriinsert(android.net.Uri url, ContentValues initialValues)
See {@link ContentProvider#insert ContentProvider.insert}

        beforeRemote();
        try {
            return mContentProvider.insert(mPackageName, url, initialValues);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public android.content.res.AssetFileDescriptoropenAssetFile(android.net.Uri url, java.lang.String mode)
See {@link ContentProvider#openAssetFile ContentProvider.openAssetFile}. Note that this does not take care of non-content: URIs such as file:. It is strongly recommended you use the {@link ContentResolver#openAssetFileDescriptor ContentResolver.openAssetFileDescriptor} API instead.

        return openAssetFile(url, mode, null);
    
public android.content.res.AssetFileDescriptoropenAssetFile(android.net.Uri url, java.lang.String mode, android.os.CancellationSignal signal)
See {@link ContentProvider#openAssetFile ContentProvider.openAssetFile}. Note that this does not take care of non-content: URIs such as file:. It is strongly recommended you use the {@link ContentResolver#openAssetFileDescriptor ContentResolver.openAssetFileDescriptor} API instead.

        beforeRemote();
        try {
            ICancellationSignal remoteSignal = null;
            if (signal != null) {
                signal.throwIfCanceled();
                remoteSignal = mContentProvider.createCancellationSignal();
                signal.setRemote(remoteSignal);
            }
            return mContentProvider.openAssetFile(mPackageName, url, mode, remoteSignal);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public android.os.ParcelFileDescriptoropenFile(android.net.Uri url, java.lang.String mode)
See {@link ContentProvider#openFile ContentProvider.openFile}. Note that this does not take care of non-content: URIs such as file:. It is strongly recommended you use the {@link ContentResolver#openFileDescriptor ContentResolver.openFileDescriptor} API instead.

        return openFile(url, mode, null);
    
public android.os.ParcelFileDescriptoropenFile(android.net.Uri url, java.lang.String mode, android.os.CancellationSignal signal)
See {@link ContentProvider#openFile ContentProvider.openFile}. Note that this does not take care of non-content: URIs such as file:. It is strongly recommended you use the {@link ContentResolver#openFileDescriptor ContentResolver.openFileDescriptor} API instead.

        beforeRemote();
        try {
            ICancellationSignal remoteSignal = null;
            if (signal != null) {
                signal.throwIfCanceled();
                remoteSignal = mContentProvider.createCancellationSignal();
                signal.setRemote(remoteSignal);
            }
            return mContentProvider.openFile(mPackageName, url, mode, remoteSignal, null);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public final android.content.res.AssetFileDescriptoropenTypedAssetFileDescriptor(android.net.Uri uri, java.lang.String mimeType, android.os.Bundle opts)
See {@link ContentProvider#openTypedAssetFile ContentProvider.openTypedAssetFile}

        return openTypedAssetFileDescriptor(uri, mimeType, opts, null);
    
public final android.content.res.AssetFileDescriptoropenTypedAssetFileDescriptor(android.net.Uri uri, java.lang.String mimeType, android.os.Bundle opts, android.os.CancellationSignal signal)
See {@link ContentProvider#openTypedAssetFile ContentProvider.openTypedAssetFile}

        beforeRemote();
        try {
            ICancellationSignal remoteSignal = null;
            if (signal != null) {
                signal.throwIfCanceled();
                remoteSignal = mContentProvider.createCancellationSignal();
                signal.setRemote(remoteSignal);
            }
            return mContentProvider.openTypedAssetFile(
                    mPackageName, uri, mimeType, opts, remoteSignal);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public android.database.Cursorquery(android.net.Uri url, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sortOrder)
See {@link ContentProvider#query ContentProvider.query}

        return query(url, projection, selection,  selectionArgs, sortOrder, null);
    
public android.database.Cursorquery(android.net.Uri url, java.lang.String[] projection, java.lang.String selection, java.lang.String[] selectionArgs, java.lang.String sortOrder, android.os.CancellationSignal cancellationSignal)
See {@link ContentProvider#query ContentProvider.query}

        beforeRemote();
        try {
            ICancellationSignal remoteCancellationSignal = null;
            if (cancellationSignal != null) {
                cancellationSignal.throwIfCanceled();
                remoteCancellationSignal = mContentProvider.createCancellationSignal();
                cancellationSignal.setRemote(remoteCancellationSignal);
            }
            return mContentProvider.query(mPackageName, url, projection, selection, selectionArgs,
                    sortOrder, remoteCancellationSignal);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public booleanrelease()
Call this to indicate to the system that the associated {@link ContentProvider} is no longer needed by this {@link ContentProviderClient}.

return
true if this was release, false if it was already released

        synchronized (this) {
            if (mReleased) {
                throw new IllegalStateException("Already released");
            }
            mReleased = true;
            mGuard.close();
            if (mStable) {
                return mContentResolver.releaseProvider(mContentProvider);
            } else {
                return mContentResolver.releaseUnstableProvider(mContentProvider);
            }
        }
    
public static voidreleaseQuietly(android.content.ContentProviderClient client)
{@hide}

        if (client != null) {
            try {
                client.release();
            } catch (Exception ignored) {
            }
        }
    
public voidsetDetectNotResponding(long timeoutMillis)
{@hide}

        synchronized (ContentProviderClient.class) {
            mAnrTimeout = timeoutMillis;

            if (timeoutMillis > 0) {
                if (mAnrRunnable == null) {
                    mAnrRunnable = new NotRespondingRunnable();
                }
                if (sAnrHandler == null) {
                    sAnrHandler = new Handler(Looper.getMainLooper(), null, true /* async */);
                }
            } else {
                mAnrRunnable = null;
            }
        }
    
public final android.net.Uriuncanonicalize(android.net.Uri url)
See {@link ContentProvider#uncanonicalize}

        beforeRemote();
        try {
            return mContentProvider.uncanonicalize(mPackageName, url);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }
    
public intupdate(android.net.Uri url, ContentValues values, java.lang.String selection, java.lang.String[] selectionArgs)
See {@link ContentProvider#update ContentProvider.update}

        beforeRemote();
        try {
            return mContentProvider.update(mPackageName, url, values, selection, selectionArgs);
        } catch (DeadObjectException e) {
            if (!mStable) {
                mContentResolver.unstableProviderDied(mContentProvider);
            }
            throw e;
        } finally {
            afterRemote();
        }