From a8aedb2f374ef88a433857d78e71c651425bcce0 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Thu, 20 Aug 2009 12:51:28 -0700 Subject: [PATCH] Add "contacts" option to EasAuthenticator, which determines whether Contacts should be synced * The state of Contacts syncing can be changed from various places in the UI * In a future CL, SyncManager will respect this setting --- .../email/service/EasAuthenticatorService.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/com/android/email/service/EasAuthenticatorService.java b/src/com/android/email/service/EasAuthenticatorService.java index ee3c81808..660533617 100644 --- a/src/com/android/email/service/EasAuthenticatorService.java +++ b/src/com/android/email/service/EasAuthenticatorService.java @@ -27,10 +27,12 @@ import android.accounts.AccountManager; import android.accounts.Constants; import android.accounts.NetworkErrorException; import android.app.Service; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.os.IBinder; +import android.provider.ContactsContract; /** * A very basic authenticator service for EAS. At the moment, it has no UI hooks. When called @@ -40,6 +42,7 @@ import android.os.IBinder; public class EasAuthenticatorService extends Service { public static final String OPTIONS_USERNAME = "username"; public static final String OPTIONS_PASSWORD = "password"; + public static final String OPTIONS_CONTACTS_SYNC_ENABLED = "contacts"; class EasAuthenticator extends AbstractAccountAuthenticator { public EasAuthenticator(Context context) { @@ -60,6 +63,18 @@ public class EasAuthenticatorService extends Service { AccountManager.get(EasAuthenticatorService.this).addAccountExplicitly( account, options.getString(OPTIONS_PASSWORD), null); + // Set up contacts syncing. SyncManager will use information from ContentResolver + // to determine syncability of Contacts for Exchange + boolean syncContacts = false; + if (options.containsKey(OPTIONS_CONTACTS_SYNC_ENABLED) && + options.getBoolean(OPTIONS_CONTACTS_SYNC_ENABLED)) { + syncContacts = true; + } + ContentResolver.setIsSyncable(account, + ContactsContract.AUTHORITY, syncContacts ? 1 : 0); + ContentResolver.setSyncAutomatically(account, + ContactsContract.AUTHORITY, syncContacts); + // Make sure the SyncManager is running Service service = EasAuthenticatorService.this; service.startService(new Intent(service, SyncManager.class));