am a8aedb2f: Add "contacts" option to EasAuthenticator, which determines whether Contacts should be synced

Merge commit 'a8aedb2f374ef88a433857d78e71c651425bcce0'

* commit 'a8aedb2f374ef88a433857d78e71c651425bcce0':
  Add "contacts" option to EasAuthenticator, which determines whether Contacts should be synced
This commit is contained in:
Marc Blank 2009-08-20 13:57:13 -07:00 committed by Android Git Automerger
commit fc4e9ed3ba

View File

@ -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));