From 53031a59a64abda404d8943bb83d65cb38574fe3 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Wed, 31 Mar 2010 10:04:26 -0700 Subject: [PATCH] Allow upsync of photo/note deletion for Exchange contacts * Always send up something when upsyncing photo and note fields * This allows the client to delete the data, as these fields are NOT deleted if skipped in an upsync (unlike other fields) Bug: 2558998 Change-Id: I9c874432108eedd84a351918f818c32e6e579dd7 --- .../exchange/adapter/ContactsSyncAdapter.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/com/android/exchange/adapter/ContactsSyncAdapter.java b/src/com/android/exchange/adapter/ContactsSyncAdapter.java index 75893ec74..1b9b1f7c8 100644 --- a/src/com/android/exchange/adapter/ContactsSyncAdapter.java +++ b/src/com/android/exchange/adapter/ContactsSyncAdapter.java @@ -58,8 +58,8 @@ import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; import android.provider.ContactsContract.CommonDataKinds.Website; import android.text.util.Rfc822Token; import android.text.util.Rfc822Tokenizer; -import android.util.Log; import android.util.Base64; +import android.util.Log; import java.io.IOException; import java.io.InputStream; @@ -1633,6 +1633,9 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter { byte[] bytes = cv.getAsByteArray(Photo.PHOTO); String pic = Base64.encodeToString(bytes, Base64.NO_WRAP); s.data(Tags.CONTACTS_PICTURE, pic); + } else { + // Send an empty tag, which signals the server to delete any pre-existing photo + s.tag(Tags.CONTACTS_PICTURE); } } @@ -1664,17 +1667,20 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter { } private void sendNote(Serializer s, ContentValues cv) throws IOException { + // Even when there is no local note, we must explicitly upsync an empty note, + // which is the only way to force the server to delete any pre-existing note. + String note = ""; if (cv.containsKey(Note.NOTE)) { // EAS won't accept note data with raw newline characters - String note = cv.getAsString(Note.NOTE).replaceAll("\n", "\r\n"); - // Format of upsync data depends on protocol version - if (mService.mProtocolVersionDouble >= Eas.SUPPORTED_PROTOCOL_EX2007_DOUBLE) { - s.start(Tags.BASE_BODY); - s.data(Tags.BASE_TYPE, Eas.BODY_PREFERENCE_TEXT).data(Tags.BASE_DATA, note); - s.end(); - } else { - s.data(Tags.CONTACTS_BODY, note); - } + note = cv.getAsString(Note.NOTE).replaceAll("\n", "\r\n"); + } + // Format of upsync data depends on protocol version + if (mService.mProtocolVersionDouble >= Eas.SUPPORTED_PROTOCOL_EX2007_DOUBLE) { + s.start(Tags.BASE_BODY); + s.data(Tags.BASE_TYPE, Eas.BODY_PREFERENCE_TEXT).data(Tags.BASE_DATA, note); + s.end(); + } else { + s.data(Tags.CONTACTS_BODY, note); } }