FileDocCategorySizeDatePackage
ContentService.javaAPI DocAndroid 1.5 API14485Wed May 06 22:41:54 BST 2009android.content

ContentService

public final class ContentService extends ContentServiceNative
{@hide}

Fields Summary
private static final String
TAG
private Context
mContext
private boolean
mFactoryTest
private final ObserverNode
mRootNode
private SyncManager
mSyncManager
private final Object
mSyncManagerLock
Constructors Summary
ContentService(Context context, boolean factoryTest)

        mContext = context;
        mFactoryTest = factoryTest;
        getSyncManager();
    
Methods Summary
public voidcancelSync(android.net.Uri uri)
Clear all scheduled sync operations that match the uri and cancel the active sync if it matches the uri. If the uri is null, clear all scheduled syncs and cancel the active one, if there is one.

param
uri Filter on the sync operations to cancel, or all if null.

        // This makes it so that future permission checks will be in the context of this
        // process rather than the caller's process. We will restore this before returning.
        long identityToken = clearCallingIdentity();
        try {
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) {
                syncManager.clearScheduledSyncOperations(uri);
                syncManager.cancelActiveSync(uri);
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    
protected synchronized voiddump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)

        mContext.enforceCallingOrSelfPermission(Manifest.permission.DUMP,
                "caller doesn't have the DUMP permission");

        // This makes it so that future permission checks will be in the context of this
        // process rather than the caller's process. We will restore this before returning.
        long identityToken = clearCallingIdentity();
        try {
            if (mSyncManager == null) {
                pw.println("No SyncManager created!  (Disk full?)");
            } else {
                mSyncManager.dump(fd, pw);
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    
private SyncManagergetSyncManager()


       
        synchronized(mSyncManagerLock) {
            try {
                // Try to create the SyncManager, return null if it fails (e.g. the disk is full).
                if (mSyncManager == null) mSyncManager = new SyncManager(mContext, mFactoryTest);
            } catch (SQLiteException e) {
                Log.e(TAG, "Can't create SyncManager", e);
            }
            return mSyncManager;
        }
    
public static IContentServicemain(Context context, boolean factoryTest)

        ContentService service = new ContentService(context, factoryTest);
        ServiceManager.addService("content", service);
        return service;
    
public voidnotifyChange(android.net.Uri uri, android.database.IContentObserver observer, boolean observerWantsSelfNotifications, boolean syncToNetwork)

        if (Log.isLoggable(TAG, Log.VERBOSE)) {
            Log.v(TAG, "Notifying update of " + uri + " from observer " + observer
                    + ", syncToNetwork " + syncToNetwork);
        }
        // This makes it so that future permission checks will be in the context of this
        // process rather than the caller's process. We will restore this before returning.
        long identityToken = clearCallingIdentity();
        try {
            ArrayList<ObserverCall> calls = new ArrayList<ObserverCall>();
            synchronized (mRootNode) {
                mRootNode.collectObservers(uri, 0, observer, observerWantsSelfNotifications,
                        calls);
            }
            final int numCalls = calls.size();
            for (int i=0; i<numCalls; i++) {
                ObserverCall oc = calls.get(i);
                try {
                    oc.mObserver.onChange(oc.mSelfNotify);
                    if (Log.isLoggable(TAG, Log.VERBOSE)) {
                        Log.v(TAG, "Notified " + oc.mObserver + " of " + "update at " + uri);
                    }
                } catch (RemoteException ex) {
                    synchronized (mRootNode) {
                        Log.w(TAG, "Found dead observer, removing");
                        IBinder binder = oc.mObserver.asBinder();
                        final ArrayList<ObserverNode.ObserverEntry> list
                                = oc.mNode.mObservers;
                        int numList = list.size();
                        for (int j=0; j<numList; j++) {
                            ObserverNode.ObserverEntry oe = list.get(j);
                            if (oe.observer.asBinder() == binder) {
                                list.remove(j);
                                j--;
                                numList--;
                            }
                        }
                    }
                }
            }
            if (syncToNetwork) {
                SyncManager syncManager = getSyncManager();
                if (syncManager != null) syncManager.scheduleLocalSync(uri);
            }
        } finally {
            restoreCallingIdentity(identityToken);
        }
    
public voidregisterContentObserver(android.net.Uri uri, boolean notifyForDescendents, android.database.IContentObserver observer)

        if (observer == null || uri == null) {
            throw new IllegalArgumentException("You must pass a valid uri and observer");
        }
        synchronized (mRootNode) {
            mRootNode.addObserver(uri, observer, notifyForDescendents);
            if (Config.LOGV) Log.v(TAG, "Registered observer " + observer + " at " + uri +
                    " with notifyForDescendents " + notifyForDescendents);
        }
    
public voidstartSync(android.net.Uri url, android.os.Bundle extras)

        ContentResolver.validateSyncExtrasBundle(extras);
        // This makes it so that future permission checks will be in the context of this
        // process rather than the caller's process. We will restore this before returning.
        long identityToken = clearCallingIdentity();
        try {
            SyncManager syncManager = getSyncManager();
            if (syncManager != null) syncManager.startSync(url, extras);
        } finally {
            restoreCallingIdentity(identityToken);
        }
    
public voidunregisterContentObserver(android.database.IContentObserver observer)

        if (observer == null) {
            throw new IllegalArgumentException("You must pass a valid observer");
        }
        synchronized (mRootNode) {
            mRootNode.removeObserver(observer);
            if (Config.LOGV) Log.v(TAG, "Unregistered observer " + observer);
        }