/*
* Copyright (C) 2006 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.content;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.AssetFileDescriptor;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.database.IContentObserver;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.text.TextUtils;
import android.accounts.Account;
import android.util.Config;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import java.util.ArrayList;
/**
* This class provides applications access to the content model.
*/
public abstract class ContentResolver {
/**
* @deprecated instead use
* {@link #requestSync(android.accounts.Account, String, android.os.Bundle)}
*/
public static final String SYNC_EXTRAS_ACCOUNT = "account";
public static final String SYNC_EXTRAS_EXPEDITED = "expedited";
/**
* @deprecated instead use
* {@link #SYNC_EXTRAS_MANUAL}
*/
public static final String SYNC_EXTRAS_FORCE = "force";
public static final String SYNC_EXTRAS_MANUAL = "force";
public static final String SYNC_EXTRAS_UPLOAD = "upload";
public static final String SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS = "deletions_override";
public static final String SYNC_EXTRAS_DISCARD_LOCAL_DELETIONS = "discard_deletions";
public static final String SCHEME_CONTENT = "content";
public static final String SCHEME_ANDROID_RESOURCE = "android.resource";
public static final String SCHEME_FILE = "file";
/**
* This is the Android platform's base MIME type for a content: URI
* containing a Cursor of a single item. Applications should use this
* as the base type along with their own sub-type of their content: URIs
* that represent a particular item. For example, hypothetical IMAP email
* client may have a URI
* content://com.company.provider.imap/inbox/1
for a particular
* message in the inbox, whose MIME type would be reported as
* CURSOR_ITEM_BASE_TYPE + "/vnd.company.imap-msg"
*
*
Compare with {@link #CURSOR_DIR_BASE_TYPE}.
*/
public static final String CURSOR_ITEM_BASE_TYPE = "vnd.android.cursor.item";
/**
* This is the Android platform's base MIME type for a content: URI
* containing a Cursor of zero or more items. Applications should use this
* as the base type along with their own sub-type of their content: URIs
* that represent a directory of items. For example, hypothetical IMAP email
* client may have a URI
* content://com.company.provider.imap/inbox
for all of the
* messages in its inbox, whose MIME type would be reported as
* CURSOR_DIR_BASE_TYPE + "/vnd.company.imap-msg"
*
*
Note how the base MIME type varies between this and * {@link #CURSOR_ITEM_BASE_TYPE} depending on whether there is * one single item or multiple items in the data set, while the sub-type * remains the same because in either case the data structure contained * in the cursor is the same. */ public static final String CURSOR_DIR_BASE_TYPE = "vnd.android.cursor.dir"; /** @hide */ public static final int SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS = 1; /** @hide */ public static final int SYNC_ERROR_AUTHENTICATION = 2; /** @hide */ public static final int SYNC_ERROR_IO = 3; /** @hide */ public static final int SYNC_ERROR_PARSE = 4; /** @hide */ public static final int SYNC_ERROR_CONFLICT = 5; /** @hide */ public static final int SYNC_ERROR_TOO_MANY_DELETIONS = 6; /** @hide */ public static final int SYNC_ERROR_TOO_MANY_RETRIES = 7; /** @hide */ public static final int SYNC_ERROR_INTERNAL = 8; /** @hide */ public static final int SYNC_OBSERVER_TYPE_SETTINGS = 1<<0; /** @hide */ public static final int SYNC_OBSERVER_TYPE_PENDING = 1<<1; /** @hide */ public static final int SYNC_OBSERVER_TYPE_ACTIVE = 1<<2; /** @hide */ public static final int SYNC_OBSERVER_TYPE_STATUS = 1<<3; /** @hide */ public static final int SYNC_OBSERVER_TYPE_ALL = 0x7fffffff; public ContentResolver(Context context) { mContext = context; } /** @hide */ protected abstract IContentProvider acquireProvider(Context c, String name); /** @hide */ public abstract boolean releaseProvider(IContentProvider icp); /** * Return the MIME type of the given content URL. * * @param url A Uri identifying content (either a list or specific type), * using the content:// scheme. * @return A MIME type for the content, or null if the URL is invalid or the type is unknown */ public final String getType(Uri url) { IContentProvider provider = acquireProvider(url); if (provider == null) { return null; } try { return provider.getType(url); } catch (RemoteException e) { return null; } catch (java.lang.Exception e) { return null; } finally { releaseProvider(provider); } } /** * Query the given URI, returning a {@link Cursor} over the result set. * * @param uri The URI, using the content:// scheme, for the content to * retrieve. * @param projection A list of which columns to return. Passing null will * return all columns, which is discouraged to prevent reading data * from storage that isn't going to be used. * @param selection A filter declaring which rows to return, formatted as an * SQL WHERE clause (excluding the WHERE itself). Passing null will * return all rows for the given URI. * @param selectionArgs You may include ?s in selection, which will be * replaced by the values from selectionArgs, in the order that they * appear in the selection. The values will be bound as Strings. * @param sortOrder How to order the rows, formatted as an SQL ORDER BY * clause (excluding the ORDER BY itself). Passing null will use the * default sort order, which may be unordered. * @return A Cursor object, which is positioned before the first entry, or null * @see Cursor */ public final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { IContentProvider provider = acquireProvider(uri); if (provider == null) { return null; } try { Cursor qCursor = provider.query(uri, projection, selection, selectionArgs, sortOrder); if(qCursor == null) { releaseProvider(provider); return null; } //Wrap the cursor object into CursorWrapperInner object return new CursorWrapperInner(qCursor, provider); } catch (RemoteException e) { releaseProvider(provider); return null; } catch(RuntimeException e) { releaseProvider(provider); throw e; } } /** * EntityIterator wrapper that releases the associated ContentProviderClient when the * iterator is closed. */ private class EntityIteratorWrapper implements EntityIterator { private final EntityIterator mInner; private final ContentProviderClient mClient; private volatile boolean mClientReleased; EntityIteratorWrapper(EntityIterator inner, ContentProviderClient client) { mInner = inner; mClient = client; mClientReleased = false; } public boolean hasNext() throws RemoteException { if (mClientReleased) { throw new IllegalStateException("this iterator is already closed"); } return mInner.hasNext(); } public Entity next() throws RemoteException { if (mClientReleased) { throw new IllegalStateException("this iterator is already closed"); } return mInner.next(); } public void close() { mClient.release(); mInner.close(); mClientReleased = true; } protected void finalize() throws Throwable { if (!mClientReleased) { mClient.release(); } super.finalize(); } } /** * Query the given URI, returning an {@link EntityIterator} over the result set. * * @param uri The URI, using the content:// scheme, for the content to * retrieve. * @param selection A filter declaring which rows to return, formatted as an * SQL WHERE clause (excluding the WHERE itself). Passing null will * return all rows for the given URI. * @param selectionArgs You may include ?s in selection, which will be * replaced by the values from selectionArgs, in the order that they * appear in the selection. The values will be bound as Strings. * @param sortOrder How to order the rows, formatted as an SQL ORDER BY * clause (excluding the ORDER BY itself). Passing null will use the * default sort order, which may be unordered. * @return An EntityIterator object * @throws RemoteException thrown if a RemoteException is encountered while attempting * to communicate with a remote provider. * @throws IllegalArgumentException thrown if there is no provider that matches the uri */ public final EntityIterator queryEntities(Uri uri, String selection, String[] selectionArgs, String sortOrder) throws RemoteException { ContentProviderClient provider = acquireContentProviderClient(uri); if (provider == null) { throw new IllegalArgumentException("Unknown URL " + uri); } try { EntityIterator entityIterator = provider.queryEntities(uri, selection, selectionArgs, sortOrder); return new EntityIteratorWrapper(entityIterator, provider); } catch(RuntimeException e) { provider.release(); throw e; } catch(RemoteException e) { provider.release(); throw e; } } /** * Open a stream on to the content associated with a content URI. If there * is no data associated with the URI, FileNotFoundException is thrown. * *
See {@link #openAssetFileDescriptor(Uri, String)} for more information * on these schemes. * * @param uri The desired URI. * @return InputStream * @throws FileNotFoundException if the provided URI could not be opened. * @see #openAssetFileDescriptor(Uri, String) */ public final InputStream openInputStream(Uri uri) throws FileNotFoundException { String scheme = uri.getScheme(); if (SCHEME_ANDROID_RESOURCE.equals(scheme)) { // Note: left here to avoid breaking compatibility. May be removed // with sufficient testing. OpenResourceIdResult r = getResourceId(uri); try { InputStream stream = r.r.openRawResource(r.id); return stream; } catch (Resources.NotFoundException ex) { throw new FileNotFoundException("Resource does not exist: " + uri); } } else if (SCHEME_FILE.equals(scheme)) { // Note: left here to avoid breaking compatibility. May be removed // with sufficient testing. return new FileInputStream(uri.getPath()); } else { AssetFileDescriptor fd = openAssetFileDescriptor(uri, "r"); try { return fd != null ? fd.createInputStream() : null; } catch (IOException e) { throw new FileNotFoundException("Unable to create stream"); } } } /** * Synonym for {@link #openOutputStream(Uri, String) * openOutputStream(uri, "w")}. * @throws FileNotFoundException if the provided URI could not be opened. */ public final OutputStream openOutputStream(Uri uri) throws FileNotFoundException { return openOutputStream(uri, "w"); } /** * Open a stream on to the content associated with a content URI. If there * is no data associated with the URI, FileNotFoundException is thrown. * *
See {@link #openAssetFileDescriptor(Uri, String)} for more information * on these schemes. * * @param uri The desired URI. * @param mode May be "w", "wa", "rw", or "rwt". * @return OutputStream * @throws FileNotFoundException if the provided URI could not be opened. * @see #openAssetFileDescriptor(Uri, String) */ public final OutputStream openOutputStream(Uri uri, String mode) throws FileNotFoundException { AssetFileDescriptor fd = openAssetFileDescriptor(uri, mode); try { return fd != null ? fd.createOutputStream() : null; } catch (IOException e) { throw new FileNotFoundException("Unable to create stream"); } } /** * Open a raw file descriptor to access data under a "content:" URI. This * is like {@link #openAssetFileDescriptor(Uri, String)}, but uses the * underlying {@link ContentProvider#openFile} * ContentProvider.openFile()} method, so will not work with * providers that return sub-sections of files. If at all possible, * you should use {@link #openAssetFileDescriptor(Uri, String)}. You * will receive a FileNotFoundException exception if the provider returns a * sub-section of a file. * *
See {@link #openAssetFileDescriptor(Uri, String)} for more information * on these schemes. * * @param uri The desired URI to open. * @param mode The file mode to use, as per {@link ContentProvider#openFile * ContentProvider.openFile}. * @return Returns a new ParcelFileDescriptor pointing to the file. You * own this descriptor and are responsible for closing it when done. * @throws FileNotFoundException Throws FileNotFoundException of no * file exists under the URI or the mode is invalid. * @see #openAssetFileDescriptor(Uri, String) */ public final ParcelFileDescriptor openFileDescriptor(Uri uri, String mode) throws FileNotFoundException { AssetFileDescriptor afd = openAssetFileDescriptor(uri, mode); if (afd == null) { return null; } if (afd.getDeclaredLength() < 0) { // This is a full file! return afd.getParcelFileDescriptor(); } // Client can't handle a sub-section of a file, so close what // we got and bail with an exception. try { afd.close(); } catch (IOException e) { } throw new FileNotFoundException("Not a whole file"); } /** * Open a raw file descriptor to access data under a "content:" URI. This * interacts with the underlying {@link ContentProvider#openAssetFile} * ContentProvider.openAssetFile()} method of the provider associated with the * given URI, to retrieve any file stored there. * *
* A Uri object can be used to reference a resource in an APK file. The * Uri should be one of the following formats: *
android.resource://package_name/id_number
package_name
is your package name as listed in your AndroidManifest.xml.
* For example com.example.myapp
id_number
is the int form of the ID.Uri uri = Uri.parse("android.resource://com.example.myapp/" + R.raw.my_resource");*
android.resource://package_name/type/name
package_name
is your package name as listed in your AndroidManifest.xml.
* For example com.example.myapp
type
is the string form of the resource type. For example, raw
* or drawable
.
* name
is the string form of the resource name. That is, whatever the file
* name was in your res directory, without the type extension.
* The easiest way to construct this form is
* Uri uri = Uri.parse("android.resource://com.example.myapp/raw/my_resource");*
true
changes to URIs beginning with uri
* will also cause notifications to be sent. If false
only changes to the exact URI
* specified by uri will cause notifications to be sent. If true, than any URI values
* at or below the specified URI will also trigger a match.
* @param observer The object that receives callbacks when changes occur.
* @see #unregisterContentObserver
*/
public final void registerContentObserver(Uri uri, boolean notifyForDescendents,
ContentObserver observer)
{
try {
getContentService().registerContentObserver(uri, notifyForDescendents,
observer.getContentObserver());
} catch (RemoteException e) {
}
}
/**
* Unregisters a change observer.
*
* @param observer The previously registered observer that is no longer needed.
* @see #registerContentObserver
*/
public final void unregisterContentObserver(ContentObserver observer) {
try {
IContentObserver contentObserver = observer.releaseContentObserver();
if (contentObserver != null) {
getContentService().unregisterContentObserver(
contentObserver);
}
} catch (RemoteException e) {
}
}
/**
* Notify registered observers that a row was updated.
* To register, call {@link #registerContentObserver(android.net.Uri , boolean, android.database.ContentObserver) registerContentObserver()}.
* By default, CursorAdapter objects will get this notification.
*
* @param uri
* @param observer The observer that originated the change, may be null
*/
public void notifyChange(Uri uri, ContentObserver observer) {
notifyChange(uri, observer, true /* sync to network */);
}
/**
* Notify registered observers that a row was updated.
* To register, call {@link #registerContentObserver(android.net.Uri , boolean, android.database.ContentObserver) registerContentObserver()}.
* By default, CursorAdapter objects will get this notification.
*
* @param uri
* @param observer The observer that originated the change, may be null
* @param syncToNetwork If true, attempt to sync the change to the network.
*/
public void notifyChange(Uri uri, ContentObserver observer, boolean syncToNetwork) {
try {
getContentService().notifyChange(
uri, observer == null ? null : observer.getContentObserver(),
observer != null && observer.deliverSelfNotifications(), syncToNetwork);
} catch (RemoteException e) {
}
}
/**
* Start an asynchronous sync operation. If you want to monitor the progress
* of the sync you may register a SyncObserver. Only values of the following
* types may be used in the extras bundle:
*
* - Integer
* - Long
* - Boolean
* - Float
* - Double
* - String
*
*
* @param uri the uri of the provider to sync or null to sync all providers.
* @param extras any extras to pass to the SyncAdapter.
* @deprecated instead use
* {@link #requestSync(android.accounts.Account, String, android.os.Bundle)}
*/
public void startSync(Uri uri, Bundle extras) {
Account account = null;
if (extras != null) {
String accountName = extras.getString(SYNC_EXTRAS_ACCOUNT);
if (!TextUtils.isEmpty(accountName)) {
account = new Account(accountName, "com.google.GAIA");
}
extras.remove(SYNC_EXTRAS_ACCOUNT);
}
requestSync(account, uri != null ? uri.getAuthority() : null, extras);
}
/**
* Start an asynchronous sync operation. If you want to monitor the progress
* of the sync you may register a SyncObserver. Only values of the following
* types may be used in the extras bundle:
*
* - Integer
* - Long
* - Boolean
* - Float
* - Double
* - String
*
*
* @param account which account should be synced
* @param authority which authority should be synced
* @param extras any extras to pass to the SyncAdapter.
*/
public static void requestSync(Account account, String authority, Bundle extras) {
validateSyncExtrasBundle(extras);
try {
getContentService().requestSync(account, authority, extras);
} catch (RemoteException e) {
}
}
/**
* Check that only values of the following types are in the Bundle:
*
* - Integer
* - Long
* - Boolean
* - Float
* - Double
* - String
* - Account
* - null
*
* @param extras the Bundle to check
*/
public static void validateSyncExtrasBundle(Bundle extras) {
try {
for (String key : extras.keySet()) {
Object value = extras.get(key);
if (value == null) continue;
if (value instanceof Long) continue;
if (value instanceof Integer) continue;
if (value instanceof Boolean) continue;
if (value instanceof Float) continue;
if (value instanceof Double) continue;
if (value instanceof String) continue;
if (value instanceof Account) continue;
throw new IllegalArgumentException("unexpected value type: "
+ value.getClass().getName());
}
} catch (IllegalArgumentException e) {
throw e;
} catch (RuntimeException exc) {
throw new IllegalArgumentException("error unparceling Bundle", exc);
}
}
/**
* Cancel any active or pending syncs that match the Uri. If the uri is null then
* all syncs will be canceled.
*
* @param uri the uri of the provider to sync or null to sync all providers.
* @deprecated instead use {@link #cancelSync(android.accounts.Account, String)}
*/
public void cancelSync(Uri uri) {
cancelSync(null /* all accounts */, uri != null ? uri.getAuthority() : null);
}
/**
* Cancel any active or pending syncs that match account and authority. The account and
* authority can each independently be set to null, which means that syncs with any account
* or authority, respectively, will match.
*
* @param account filters the syncs that match by this account
* @param authority filters the syncs that match by this authority
*/
public static void cancelSync(Account account, String authority) {
try {
getContentService().cancelSync(account, authority);
} catch (RemoteException e) {
}
}
/**
* Get information about the SyncAdapters that are known to the system.
* @return an array of SyncAdapters that have registered with the system
*/
public static SyncAdapterType[] getSyncAdapterTypes() {
try {
return getContentService().getSyncAdapterTypes();
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
/**
* Check if the provider should be synced when a network tickle is received
*
* @param account the account whose setting we are querying
* @param authority the provider whose setting we are querying
* @return true if the provider should be synced when a network tickle is received
*/
public static boolean getSyncAutomatically(Account account, String authority) {
try {
return getContentService().getSyncAutomatically(account, authority);
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
/**
* Set whether or not the provider is synced when it receives a network tickle.
*
* @param account the account whose setting we are querying
* @param authority the provider whose behavior is being controlled
* @param sync true if the provider should be synced when tickles are received for it
*/
public static void setSyncAutomatically(Account account, String authority, boolean sync) {
try {
getContentService().setSyncAutomatically(account, authority, sync);
} catch (RemoteException e) {
// exception ignored; if this is thrown then it means the runtime is in the midst of
// being restarted
}
}
/**
* Check if this account/provider is syncable.
* @return >0 if it is syncable, 0 if not, and <0 if the state isn't known yet.
*/
public int getIsSyncable(Account account, String authority) {
try {
return getContentService().getIsSyncable(account, authority);
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
/**
* Set whether this account/provider is syncable.
* @param syncable >0 denotes syncable, 0 means not syncable, <0 means unknown
*/
public void setIsSyncable(Account account, String authority, int syncable) {
try {
getContentService().setIsSyncable(account, authority, syncable);
} catch (RemoteException e) {
// exception ignored; if this is thrown then it means the runtime is in the midst of
// being restarted
}
}
/**
* Gets the master auto-sync setting that applies to all the providers and accounts.
* If this is false then the per-provider auto-sync setting is ignored.
*
* @return the master auto-sync setting that applies to all the providers and accounts
*/
public static boolean getMasterSyncAutomatically() {
try {
return getContentService().getMasterSyncAutomatically();
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
/**
* Sets the master auto-sync setting that applies to all the providers and accounts.
* If this is false then the per-provider auto-sync setting is ignored.
*
* @param sync the master auto-sync setting that applies to all the providers and accounts
*/
public static void setMasterSyncAutomatically(boolean sync) {
try {
getContentService().setMasterSyncAutomatically(sync);
} catch (RemoteException e) {
// exception ignored; if this is thrown then it means the runtime is in the midst of
// being restarted
}
}
/**
* Returns true if there is currently a sync operation for the given
* account or authority in the pending list, or actively being processed.
* @param account the account whose setting we are querying
* @param authority the provider whose behavior is being queried
* @return true if a sync is active for the given account or authority.
*/
public static boolean isSyncActive(Account account, String authority) {
try {
return getContentService().isSyncActive(account, authority);
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
/**
* If a sync is active returns the information about it, otherwise returns false.
* @return the ActiveSyncInfo for the currently active sync or null if one is not active.
* @hide
*/
public static ActiveSyncInfo getActiveSync() {
try {
return getContentService().getActiveSync();
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
/**
* Returns the status that matches the authority. If there are multiples accounts for
* the authority, the one with the latest "lastSuccessTime" status is returned.
* @param account the account whose setting we are querying
* @param authority the provider whose behavior is being queried
* @return the SyncStatusInfo for the authority, or null if none exists
* @hide
*/
public static SyncStatusInfo getSyncStatus(Account account, String authority) {
try {
return getContentService().getSyncStatus(account, authority);
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
/**
* Return true if the pending status is true of any matching authorities.
* @param account the account whose setting we are querying
* @param authority the provider whose behavior is being queried
* @return true if there is a pending sync with the matching account and authority
*/
public static boolean isSyncPending(Account account, String authority) {
try {
return getContentService().isSyncPending(account, authority);
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
public static Object addStatusChangeListener(int mask, final SyncStatusObserver callback) {
try {
ISyncStatusObserver.Stub observer = new ISyncStatusObserver.Stub() {
public void onStatusChanged(int which) throws RemoteException {
callback.onStatusChanged(which);
}
};
getContentService().addStatusChangeListener(mask, observer);
return observer;
} catch (RemoteException e) {
throw new RuntimeException("the ContentService should always be reachable", e);
}
}
public static void removeStatusChangeListener(Object handle) {
try {
getContentService().removeStatusChangeListener((ISyncStatusObserver.Stub) handle);
} catch (RemoteException e) {
// exception ignored; if this is thrown then it means the runtime is in the midst of
// being restarted
}
}
private final class CursorWrapperInner extends CursorWrapper {
private IContentProvider mContentProvider;
public static final String TAG="CursorWrapperInner";
private boolean mCloseFlag = false;
CursorWrapperInner(Cursor cursor, IContentProvider icp) {
super(cursor);
mContentProvider = icp;
}
@Override
public void close() {
super.close();
ContentResolver.this.releaseProvider(mContentProvider);
mCloseFlag = true;
}
@Override
protected void finalize() throws Throwable {
try {
if(!mCloseFlag) {
ContentResolver.this.releaseProvider(mContentProvider);
}
} finally {
super.finalize();
}
}
}
private final class ParcelFileDescriptorInner extends ParcelFileDescriptor {
private IContentProvider mContentProvider;
public static final String TAG="ParcelFileDescriptorInner";
private boolean mReleaseProviderFlag = false;
ParcelFileDescriptorInner(ParcelFileDescriptor pfd, IContentProvider icp) {
super(pfd);
mContentProvider = icp;
}
@Override
public void close() throws IOException {
if(!mReleaseProviderFlag) {
super.close();
ContentResolver.this.releaseProvider(mContentProvider);
mReleaseProviderFlag = true;
}
}
@Override
protected void finalize() throws Throwable {
if (!mReleaseProviderFlag) {
close();
}
}
}
/** @hide */
public static final String CONTENT_SERVICE_NAME = "content";
/** @hide */
public static IContentService getContentService() {
if (sContentService != null) {
return sContentService;
}
IBinder b = ServiceManager.getService(CONTENT_SERVICE_NAME);
if (Config.LOGV) Log.v("ContentService", "default service binder = " + b);
sContentService = IContentService.Stub.asInterface(b);
if (Config.LOGV) Log.v("ContentService", "default service = " + sContentService);
return sContentService;
}
private static IContentService sContentService;
private final Context mContext;
private static final String TAG = "ContentResolver";
}