diff options
author | Fred Quintana <fredq@google.com> | 2009-04-23 13:36:27 -0700 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2009-04-23 15:37:45 -0700 |
commit | d9d2f1140b52fd0c014e9deac59f6000564b7e84 (patch) | |
tree | 2c30edce5a148ef94400277f20619c821fd9da94 /packages | |
parent | 843bbb8597d561c2541f86d1f391ae65261cf743 (diff) | |
download | frameworks_base-d9d2f1140b52fd0c014e9deac59f6000564b7e84.zip frameworks_base-d9d2f1140b52fd0c014e9deac59f6000564b7e84.tar.gz frameworks_base-d9d2f1140b52fd0c014e9deac59f6000564b7e84.tar.bz2 |
change the sync framework and users to understand Account
Diffstat (limited to 'packages')
2 files changed, 38 insertions, 24 deletions
diff --git a/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsIntentService.java b/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsIntentService.java index 8268fee..de7b1d7 100644 --- a/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsIntentService.java +++ b/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsIntentService.java @@ -17,13 +17,15 @@ import android.database.sqlite.SQLiteFullException; import android.app.AlarmManager; import android.app.PendingIntent; import android.os.Bundle; -import android.os.Debug; import android.text.TextUtils; import android.net.Uri; +import android.accounts.Account; import java.util.ArrayList; import java.util.Calendar; +import com.google.android.collect.Lists; + /** * A service to handle various intents asynchronously. */ @@ -31,7 +33,8 @@ public class SubscribedFeedsIntentService extends IntentService { private static final String TAG = "Sync"; private static final String[] sAccountProjection = - new String[] {SubscribedFeeds.Accounts._SYNC_ACCOUNT}; + new String[] {SubscribedFeeds.Accounts._SYNC_ACCOUNT, + SubscribedFeeds.Accounts._SYNC_ACCOUNT_TYPE}; /** How often to refresh the subscriptions, in milliseconds */ private static final long SUBSCRIPTION_REFRESH_INTERVAL = 1000L * 60 * 60 * 24; // one day @@ -56,10 +59,10 @@ public class SubscribedFeedsIntentService extends IntentService { if (GTALK_DATA_MESSAGE_RECEIVED.equals(intent.getAction())) { boolean fromTrustedServer = intent.getBooleanExtra("from_trusted_server", false); if (fromTrustedServer) { - String account = intent.getStringExtra("account"); + String accountName = intent.getStringExtra("account"); String token = intent.getStringExtra("message_token"); - if (TextUtils.isEmpty(account) || TextUtils.isEmpty(token)) { + if (TextUtils.isEmpty(accountName) || TextUtils.isEmpty(token)) { if (Config.LOGD) { Log.d(TAG, "Ignoring malformed tickle -- missing account or token."); } @@ -68,10 +71,10 @@ public class SubscribedFeedsIntentService extends IntentService { if (Config.LOGD) { Log.d(TAG, "Received network tickle for " - + account + " - " + token); + + accountName + " - " + token); } - handleTickle(this, account, token); + handleTickle(this, accountName, token); } else { if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "Ignoring tickle -- not from trusted server."); @@ -103,20 +106,22 @@ public class SubscribedFeedsIntentService extends IntentService { alarmManager.set(AlarmManager.RTC, when, pendingIntent); } - private void handleTickle(Context context, String account, String feed) { + private void handleTickle(Context context, String accountName, String feed) { Cursor c = null; Sync.Settings.QueryMap syncSettings = new Sync.Settings.QueryMap(context.getContentResolver(), false /* don't keep updated */, null /* not needed since keep updated is false */); final String where = SubscribedFeeds.Feeds._SYNC_ACCOUNT + "= ? " + + "and " + SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE + "= ? " + "and " + SubscribedFeeds.Feeds.FEED + "= ?"; try { + // TODO(fredq) fix the hardcoded type c = context.getContentResolver().query(SubscribedFeeds.Feeds.CONTENT_URI, - null, where, new String[]{account, feed}, null); + null, where, new String[]{accountName, "com.google.GAIA", feed}, null); if (c.getCount() == 0) { Log.w(TAG, "received tickle for non-existent feed: " - + "account " + account + ", feed " + feed); + + "account " + accountName + ", feed " + feed); EventLog.writeEvent(LOG_TICKLE, "unknown"); } while (c.moveToNext()) { @@ -131,7 +136,8 @@ public class SubscribedFeedsIntentService extends IntentService { } Uri uri = Uri.parse("content://" + authority); Bundle extras = new Bundle(); - extras.putString(ContentResolver.SYNC_EXTRAS_ACCOUNT, account); + extras.putParcelable(ContentResolver.SYNC_EXTRAS_ACCOUNT, + new Account(accountName, "com.google.GAIA")); extras.putString("feed", feed); context.getContentResolver().startSync(uri, extras); } @@ -151,17 +157,15 @@ public class SubscribedFeedsIntentService extends IntentService { */ private void handleRefreshAlarm(Context context) { // retrieve the list of accounts from the subscribed feeds - ArrayList<String> accounts = new ArrayList<String>(); + ArrayList<Account> accounts = Lists.newArrayList(); ContentResolver contentResolver = context.getContentResolver(); Cursor c = contentResolver.query(SubscribedFeeds.Accounts.CONTENT_URI, sAccountProjection, null, null, null); try { while (c.moveToNext()) { - String account = c.getString(0); - if (TextUtils.isEmpty(account)) { - continue; - } - accounts.add(account); + String accountName = c.getString(0); + String accountType = c.getString(1); + accounts.add(new Account(accountName, accountType)); } } finally { c.close(); @@ -169,16 +173,19 @@ public class SubscribedFeedsIntentService extends IntentService { // Clear the auth tokens for all these accounts so that we are sure // they will still be valid until the next time we refresh them. - // TODO: add this when the google login service is done + // TODO(fredq): add this when the google login service is done // mark the feeds dirty, by setting the accounts to the same value, // which will trigger a sync. try { ContentValues values = new ContentValues(); - for (String account : accounts) { - values.put(SyncConstValue._SYNC_ACCOUNT, account); + for (Account account : accounts) { + values.put(SyncConstValue._SYNC_ACCOUNT, account.mName); + values.put(SyncConstValue._SYNC_ACCOUNT_TYPE, account.mType); contentResolver.update(SubscribedFeeds.Feeds.CONTENT_URI, values, - SubscribedFeeds.Feeds._SYNC_ACCOUNT + "=?", new String[] {account}); + SubscribedFeeds.Feeds._SYNC_ACCOUNT + "=? AND " + + SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE + "=?", + new String[] {account.mName, account.mType}); } } catch (SQLiteFullException e) { Log.w(TAG, "disk full while trying to mark the feeds as dirty, skipping"); diff --git a/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsProvider.java b/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsProvider.java index 9ecc3d6..d87f5e7 100644 --- a/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsProvider.java +++ b/packages/SubscribedFeedsProvider/src/com/android/providers/subscribedfeeds/SubscribedFeedsProvider.java @@ -39,7 +39,7 @@ import java.util.HashMap; public class SubscribedFeedsProvider extends AbstractSyncableContentProvider { private static final String TAG = "SubscribedFeedsProvider"; private static final String DATABASE_NAME = "subscribedfeeds.db"; - private static final int DATABASE_VERSION = 10; + private static final int DATABASE_VERSION = 11; private static final int FEEDS = 1; private static final int FEED_ID = 2; @@ -88,6 +88,7 @@ public class SubscribedFeedsProvider extends AbstractSyncableContentProvider { db.execSQL("CREATE TABLE feeds (" + "_id INTEGER PRIMARY KEY," + "_sync_account TEXT," + // From the sync source + "_sync_account_type TEXT," + // From the sync source "_sync_id TEXT," + // From the sync source "_sync_time TEXT," + // From the sync source "_sync_version TEXT," + // From the sync source @@ -106,8 +107,8 @@ public class SubscribedFeedsProvider extends AbstractSyncableContentProvider { "WHEN old._sync_id is not null " + "BEGIN " + "INSERT INTO _deleted_feeds " + - "(_sync_id, _sync_account, _sync_version) " + - "VALUES (old._sync_id, old._sync_account, " + + "(_sync_id, _sync_account, _sync_account_type, _sync_version) " + + "VALUES (old._sync_id, old._sync_account, old._sync_account_type, " + "old._sync_version);" + "END"); @@ -116,6 +117,7 @@ public class SubscribedFeedsProvider extends AbstractSyncableContentProvider { "_sync_id TEXT," + (isTemporary() ? "_sync_local_id INTEGER," : "") + // Used while syncing, "_sync_account TEXT," + + "_sync_account_type TEXT," + "_sync_mark INTEGER, " + // Used to filter out new rows "UNIQUE(_sync_id))"); } @@ -170,7 +172,8 @@ public class SubscribedFeedsProvider extends AbstractSyncableContentProvider { qb.setDistinct(true); qb.setProjectionMap(ACCOUNTS_PROJECTION_MAP); return qb.query(getDatabase(), projection, selection, selectionArgs, - SubscribedFeeds.Feeds._SYNC_ACCOUNT, null, sortOrder); + SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE + "," + + SubscribedFeeds.Feeds._SYNC_ACCOUNT, null, sortOrder); case FEED_ID: qb.setTables(sFeedsTable); qb.appendWhere(sFeedsTable + "._id="); @@ -310,6 +313,8 @@ public class SubscribedFeedsProvider extends AbstractSyncableContentProvider { DatabaseUtils.cursorStringToContentValues(diffsCursor, SubscribedFeeds.Feeds._SYNC_ACCOUNT, mValues); DatabaseUtils.cursorStringToContentValues(diffsCursor, + SubscribedFeeds.Feeds._SYNC_ACCOUNT_TYPE, mValues); + DatabaseUtils.cursorStringToContentValues(diffsCursor, SubscribedFeeds.Feeds._SYNC_VERSION, mValues); db.replace(mDeletedTable, SubscribedFeeds.Feeds._SYNC_ID, mValues); } @@ -369,5 +374,7 @@ public class SubscribedFeedsProvider extends AbstractSyncableContentProvider { ACCOUNTS_PROJECTION_MAP = map; map.put(SubscribedFeeds.Accounts._COUNT, "COUNT(*) AS _count"); map.put(SubscribedFeeds.Accounts._SYNC_ACCOUNT, SubscribedFeeds.Accounts._SYNC_ACCOUNT); + map.put(SubscribedFeeds.Accounts._SYNC_ACCOUNT_TYPE, + SubscribedFeeds.Accounts._SYNC_ACCOUNT_TYPE); } } |