FileDocCategorySizeDatePackage
SubscribedFeedsSyncAdapter.javaAPI DocAndroid 1.5 API9903Wed May 06 22:42:48 BST 2009com.android.providers.subscribedfeeds

SubscribedFeedsSyncAdapter

public class SubscribedFeedsSyncAdapter extends com.google.android.providers.AbstractGDataSyncAdapter
Implements a SyncAdapter for SubscribedFeeds

Fields Summary
private final com.google.wireless.gdata.subscribedfeeds.client.SubscribedFeedsClient
mSubscribedFeedsClient
private static final String
FEED_URL
private static final String
ROUTINGINFO_PARAMETER
Constructors Summary
protected SubscribedFeedsSyncAdapter(android.content.Context context, android.content.SyncableContentProvider provider)


         
        super(context, provider);
        mSubscribedFeedsClient =
            new SubscribedFeedsClient(
                    new AndroidGDataClient(context),
                    new XmlSubscribedFeedsGDataParserFactory(
                            new AndroidXmlParserFactory()));
    
Methods Summary
protected java.lang.StringcursorToEntry(android.content.SyncContext context, android.database.Cursor c, com.google.wireless.gdata.data.Entry baseEntry, java.lang.Object syncInfo)

        final String account = c.getString(c.getColumnIndex(SubscribedFeeds.Feeds._SYNC_ACCOUNT));
        final String service = c.getString(c.getColumnIndex(SubscribedFeeds.Feeds.SERVICE));
        final String id = c.getString(c.getColumnIndex(SubscribedFeeds.Feeds._SYNC_ID));
        final String feed = c.getString(c.getColumnIndex(SubscribedFeeds.Feeds.FEED));

        String authToken;
        try {
            authToken =
                    GoogleLoginServiceBlockingHelper.getAuthToken(getContext(), account, service);
        } catch (GoogleLoginServiceBlockingHelper.AuthenticationException e) {
            Log.e("Sync", "caught exception while attempting to get an " +
                    "authtoken for account " + account +
                    ", service " + service + ": " + e.toString());
            throw new ParseException(e.getMessage(), e);
        } catch (GoogleLoginServiceNotFoundException e) {
            Log.e("Sync", "caught exception while attempting to get an " +
                    "authtoken for account " + account +
                    ", service " + service + ": " + e.toString());
            throw new ParseException(e.getMessage(), e);
        }

        FeedUrl subscribedFeedUrl = new FeedUrl(feed, service, authToken);
        SubscribedFeedsEntry entry = (SubscribedFeedsEntry) baseEntry;
        if (id != null) {
            entry.setId(getFeedUrl(account) + "/" + id);
            entry.setEditUri(entry.getId());
        }
        entry.setRoutingInfo(getRoutingInfoForAccount(account));
        entry.setSubscribedFeed(subscribedFeedUrl);
        entry.setClientToken(subscribedFeedUrl.getFeed());

        String createUrl = null;
        if (id == null) {
            createUrl = getFeedUrl(account);    
        }
        return createUrl;
    
protected voiddeletedCursorToEntry(android.content.SyncContext context, android.database.Cursor c, com.google.wireless.gdata.data.Entry entry)

        final String id = c.getString(c.getColumnIndexOrThrow(SubscribedFeeds.Feeds._SYNC_ID));
        entry.setId(id);
        entry.setEditUri(getFeedUrl(getAccount()) + "/" + id);
    
protected android.database.CursorgetCursorForDeletedTable(android.content.ContentProvider cp, java.lang.Class entryClass)

        if (entryClass != SubscribedFeedsEntry.class) {
            throw new IllegalArgumentException("unexpected entry class, " + entryClass.getName());
        }
        return cp.query(SubscribedFeeds.Feeds.DELETED_CONTENT_URI, null, null, null, null);
    
protected android.database.CursorgetCursorForTable(android.content.ContentProvider cp, java.lang.Class entryClass)

        if (entryClass != SubscribedFeedsEntry.class) {
            throw new IllegalArgumentException("unexpected entry class, " + entryClass.getName());
        }
        return cp.query(SubscribedFeeds.Feeds.CONTENT_URI, null, null, null, null);
    
protected java.lang.ClassgetFeedEntryClass()

        return SubscribedFeedsEntry.class;
    
protected java.lang.StringgetFeedUrl(java.lang.String account)

        return FEED_URL;
    
protected com.google.wireless.gdata.client.GDataServiceClientgetGDataServiceClient()

        return mSubscribedFeedsClient;
    
public java.lang.StringgetRoutingInfoForAccount(java.lang.String account)
Returns a string that can be used by the GSyncSubscriptionServer to route messages back to this account via GTalkService. TODO: this should eventually move into a general place so that others can use it.

param
account the account whose routing info we want
return
the GSyncSubscriptionServer routing string for this account

        long androidId;
        try {
            androidId = GoogleLoginServiceBlockingHelper.getAndroidId(getContext());
        } catch (GoogleLoginServiceNotFoundException e) {
            Log.e(TAG, "Could not get routing info for account", e);
            return null;
        }
        return Uri.parse("gtalk://" + account
                + "#" + Settings.getGTalkDeviceId(androidId)).toString();
    
public voidgetServerDiffs(android.content.SyncContext context, SyncData syncData, android.content.SyncableContentProvider tempProvider, android.os.Bundle extras, java.lang.Object syncInfo, android.content.SyncResult syncResult)

        tempProvider.setContainsDiffs(false /* the server returns all records, not just diffs */);
        super.getServerDiffs(context, syncData, tempProvider, extras, syncInfo, syncResult);
    
protected booleanhandleAllDeletedUnavailable(GDataSyncData syncData, java.lang.String feed)

        Log.w(TAG, "subscribed feeds don't use tombstones");

        // this should never happen, but if it does pretend that we are able to handle it.
        return true;
    
protected booleanhasTooManyDeletions(android.content.SyncStats stats)

        // allow subscribed feeds to delete any number of entries,
        // since the client is the authority on which entries
        // should exist.
        return false;
    
protected com.google.wireless.gdata.data.EntrynewEntry()

        return new SubscribedFeedsEntry();
    
public voidonAccountsChanged(java.lang.String[] accounts)

        // no need to do anything
    
protected voidupdateProvider(com.google.wireless.gdata.data.Feed feed, java.lang.Long syncLocalId, com.google.wireless.gdata.data.Entry baseEntry, android.content.ContentProvider provider, java.lang.Object syncInfo)

        ContentValues values = new ContentValues();
        values.put(SubscribedFeeds.Feeds._SYNC_ACCOUNT, getAccount());
        values.put(SubscribedFeeds.Feeds._SYNC_LOCAL_ID, syncLocalId);
        final SubscribedFeedsEntry entry = (SubscribedFeedsEntry) baseEntry;
        final String id = entry.getId();
        final String editUri = entry.getEditUri();
        String version = null;
        if (!TextUtils.isEmpty(id) && !TextUtils.isEmpty(editUri)) {
            final String serverId = id.substring(id.lastIndexOf('/") + 1);
            version = editUri.substring(editUri.lastIndexOf('/") + 1);
            values.put(SubscribedFeeds.Feeds._SYNC_ID, serverId);
            values.put(SubscribedFeeds.Feeds._SYNC_VERSION, version);
        }
        if (baseEntry.isDeleted()) {
            provider.insert(SubscribedFeeds.Feeds.DELETED_CONTENT_URI, values);
        } else {
            values.put(SubscribedFeeds.Feeds.FEED, entry.getSubscribedFeed().getFeed());
            if (!TextUtils.isEmpty(version)) {
                values.put(SubscribedFeeds.Feeds._SYNC_TIME, version);
            }
            values.put(SubscribedFeeds.Feeds._SYNC_DIRTY, "0");
            provider.insert(SubscribedFeeds.Feeds.CONTENT_URI, values);
        }
    
protected voidupdateQueryParameters(com.google.wireless.gdata.client.QueryParams params)

        params.setParamValue(ROUTINGINFO_PARAMETER, getRoutingInfoForAccount(getAccount()));