diff options
author | Fred Quintana <fredq@google.com> | 2009-08-16 23:13:53 -0700 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2009-08-17 13:02:42 -0700 |
commit | 5e787c42f2a6b3afc8ec8320a08d51b2d44b8614 (patch) | |
tree | f9aeb3e37f12d679a8f48a05c8c8be1328c46f35 /core/java/android/content/SyncStorageEngine.java | |
parent | 76c830b229fc21d5ea0ea28955084cc187e25fc6 (diff) | |
download | frameworks_base-5e787c42f2a6b3afc8ec8320a08d51b2d44b8614.zip frameworks_base-5e787c42f2a6b3afc8ec8320a08d51b2d44b8614.tar.gz frameworks_base-5e787c42f2a6b3afc8ec8320a08d51b2d44b8614.tar.bz2 |
- add a "isSyncable" flag to a given account/authority pair that
indicates whether or not syncs should be attempted for it.
- add public methods to get and set this parameter
Diffstat (limited to 'core/java/android/content/SyncStorageEngine.java')
-rw-r--r-- | core/java/android/content/SyncStorageEngine.java | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/core/java/android/content/SyncStorageEngine.java b/core/java/android/content/SyncStorageEngine.java index b3f9bbb..2647962 100644 --- a/core/java/android/content/SyncStorageEngine.java +++ b/core/java/android/content/SyncStorageEngine.java @@ -155,12 +155,15 @@ public class SyncStorageEngine extends Handler { final String authority; final int ident; boolean enabled; + int syncable; AuthorityInfo(Account account, String authority, int ident) { this.account = account; this.authority = authority; this.ident = ident; enabled = SYNC_ENABLED_DEFAULT; + // TODO: change the default to -1 when the syncadapters are changed to set this + syncable = 1; } } @@ -392,6 +395,44 @@ public class SyncStorageEngine extends Handler { reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS); } + public int getIsSyncable(Account account, String providerName) { + synchronized (mAuthorities) { + if (account != null) { + AuthorityInfo authority = getAuthorityLocked(account, providerName, + "getIsSyncable"); + if (authority == null) { + return -1; + } + return authority.syncable; + } + + int i = mAuthorities.size(); + while (i > 0) { + i--; + AuthorityInfo authority = mAuthorities.get(i); + if (authority.authority.equals(providerName)) { + return authority.syncable; + } + } + return -1; + } + } + + public void setIsSyncable(Account account, String providerName, int syncable) { + int oldState; + synchronized (mAuthorities) { + AuthorityInfo authority = getOrCreateAuthorityLocked(account, providerName, -1, false); + oldState = authority.syncable; + authority.syncable = syncable; + writeAccountInfoLocked(); + } + + if (oldState <= 0 && syncable > 0) { + mContext.getContentResolver().requestSync(account, providerName, new Bundle()); + } + reportChange(ContentResolver.SYNC_OBSERVER_TYPE_SETTINGS); + } + public void setMasterSyncAutomatically(boolean flag) { boolean old; synchronized (mAuthorities) { @@ -1064,10 +1105,12 @@ public class SyncStorageEngine extends Handler { null, "authority"); String enabled = parser.getAttributeValue( null, "enabled"); - AuthorityInfo authority = mAuthorities.get(id); + String syncable = parser.getAttributeValue(null, "syncable"); + AuthorityInfo authority = mAuthorities.get(id); if (DEBUG_FILE) Log.v(TAG, "Adding authority: account=" + accountName + " auth=" + authorityName - + " enabled=" + enabled); + + " enabled=" + enabled + + " syncable=" + syncable); if (authority == null) { if (DEBUG_FILE) Log.v(TAG, "Creating entry"); authority = getOrCreateAuthorityLocked( @@ -1077,10 +1120,19 @@ public class SyncStorageEngine extends Handler { if (authority != null) { authority.enabled = enabled == null || Boolean.parseBoolean(enabled); + if ("unknown".equals(syncable)) { + authority.syncable = -1; + } else { + authority.syncable = + (syncable == null || Boolean.parseBoolean(enabled)) + ? 1 + : 0; + } } else { Log.w(TAG, "Failure adding authority: account=" + accountName + " auth=" + authorityName - + " enabled=" + enabled); + + " enabled=" + enabled + + " syncable=" + syncable); } } } @@ -1133,6 +1185,11 @@ public class SyncStorageEngine extends Handler { if (!authority.enabled) { out.attribute(null, "enabled", "false"); } + if (authority.syncable < 0) { + out.attribute(null, "syncable", "unknown"); + } else if (authority.syncable == 0) { + out.attribute(null, "syncable", "false"); + } out.endTag(null, "authority"); } @@ -1268,6 +1325,7 @@ public class SyncStorageEngine extends Handler { AuthorityInfo authority = mAuthorities.get(i); if (authority.authority.equals(provider)) { authority.enabled = value == null || Boolean.parseBoolean(value); + authority.syncable = 1; } } } |