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
This commit is contained in:
Marc Blank 2010-03-31 10:04:26 -07:00
parent a3235209b0
commit 53031a59a6

View File

@ -58,8 +58,8 @@ import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.CommonDataKinds.Website; import android.provider.ContactsContract.CommonDataKinds.Website;
import android.text.util.Rfc822Token; import android.text.util.Rfc822Token;
import android.text.util.Rfc822Tokenizer; import android.text.util.Rfc822Tokenizer;
import android.util.Log;
import android.util.Base64; import android.util.Base64;
import android.util.Log;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -1633,6 +1633,9 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
byte[] bytes = cv.getAsByteArray(Photo.PHOTO); byte[] bytes = cv.getAsByteArray(Photo.PHOTO);
String pic = Base64.encodeToString(bytes, Base64.NO_WRAP); String pic = Base64.encodeToString(bytes, Base64.NO_WRAP);
s.data(Tags.CONTACTS_PICTURE, pic); 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,9 +1667,13 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
} }
private void sendNote(Serializer s, ContentValues cv) throws IOException { 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)) { if (cv.containsKey(Note.NOTE)) {
// EAS won't accept note data with raw newline characters // EAS won't accept note data with raw newline characters
String note = cv.getAsString(Note.NOTE).replaceAll("\n", "\r\n"); note = cv.getAsString(Note.NOTE).replaceAll("\n", "\r\n");
}
// Format of upsync data depends on protocol version // Format of upsync data depends on protocol version
if (mService.mProtocolVersionDouble >= Eas.SUPPORTED_PROTOCOL_EX2007_DOUBLE) { if (mService.mProtocolVersionDouble >= Eas.SUPPORTED_PROTOCOL_EX2007_DOUBLE) {
s.start(Tags.BASE_BODY); s.start(Tags.BASE_BODY);
@ -1676,7 +1683,6 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter {
s.data(Tags.CONTACTS_BODY, note); s.data(Tags.CONTACTS_BODY, note);
} }
} }
}
private void sendChildren(Serializer s, ContentValues cv) throws IOException { private void sendChildren(Serializer s, ContentValues cv) throws IOException {
boolean first = true; boolean first = true;