Fix bugs related to Contacts sync behavior in Exchange

* Respect the UPLOAD extra from SyncManager and check for changes before starting
  a sync.
* Failure to do this was causing looping behavior

Change-Id: Idfb1c35782b6d3771f9455c6fe86489572a871c5
This commit is contained in:
Marc Blank 2009-08-29 12:55:55 -07:00
parent a7927a874b
commit ebda784732

View File

@ -31,8 +31,10 @@ import android.content.Context;
import android.content.Intent;
import android.content.SyncResult;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.ContactsContract.RawContacts;
import android.util.Log;
public class ContactsSyncAdapterService extends Service {
@ -88,10 +90,28 @@ public class ContactsSyncAdapterService extends Service {
* The missing piece at this point is integration with the push/ping mechanism in EAS; this will
* be put in place at a later time.
*/
private static void performSync(Context context, Account account, Bundle extras, String authority,
ContentProviderClient provider, SyncResult syncResult)
private static void performSync(Context context, Account account, Bundle extras,
String authority, ContentProviderClient provider, SyncResult syncResult)
throws OperationCanceledException {
ContentResolver cr = context.getContentResolver();
Log.i(TAG, "performSync");
if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD)) {
Uri uri = RawContacts.CONTENT_URI.buildUpon()
.appendQueryParameter(RawContacts.ACCOUNT_NAME, account.name)
.appendQueryParameter(RawContacts.ACCOUNT_TYPE, Eas.ACCOUNT_MANAGER_TYPE)
.build();
Cursor c = cr.query(uri,
new String[] {RawContacts._ID}, RawContacts.DIRTY + "=1", null, null);
try {
if (!c.moveToFirst()) {
Log.i(TAG, "Upload sync; no changes");
return;
}
} finally {
c.close();
}
}
// Find the (EmailProvider) account associated with this email address
Cursor accountCursor =
cr.query(com.android.email.provider.EmailContent.Account.CONTENT_URI, ID_PROJECTION,
@ -103,7 +123,7 @@ public class ContactsSyncAdapterService extends Service {
Cursor mailboxCursor = cr.query(Mailbox.CONTENT_URI, ID_PROJECTION,
ACCOUNT_AND_TYPE_CONTACTS, new String[] {Long.toString(accountId)}, null);
try {
if (mailboxCursor.moveToFirst()) {
if (mailboxCursor.moveToFirst()) {
Log.i(TAG, "Contact sync requested for " + account.name);
// Ask for a sync from our sync manager
SyncManager.serviceRequest(mailboxCursor.getLong(0),