From d2cc8327826f33e36308f18bd35f19adff3b56e0 Mon Sep 17 00:00:00 2001 From: Marc Blank Date: Thu, 29 Oct 2009 10:05:43 -0700 Subject: [PATCH] Fix folder deletion; add support for folder rename (#2118439) * Folder delete had a subtle error that could cause subsequent folder changes in the same sync to fail (using wrong end tag) * Folder change (rename, move) wasn't implemented; this was added and tested. The change is very straightforward and low risk. Change-Id: Id69cee9b99e9a988a176a6525ba9a1615b741c44 --- .../exchange/adapter/FolderSyncParser.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/com/android/exchange/adapter/FolderSyncParser.java b/src/com/android/exchange/adapter/FolderSyncParser.java index aa2f42aa7..337e329c6 100644 --- a/src/com/android/exchange/adapter/FolderSyncParser.java +++ b/src/com/android/exchange/adapter/FolderSyncParser.java @@ -152,7 +152,7 @@ public class FolderSyncParser extends AbstractSyncParser { } public void deleteParser(ArrayList ops) throws IOException { - while (nextTag(Tags.SYNC_DELETE) != END) { + while (nextTag(Tags.FOLDER_DELETE) != END) { switch (tag) { case Tags.FOLDER_SERVER_ID: String serverId = getValue(); @@ -258,16 +258,62 @@ public class FolderSyncParser extends AbstractSyncParser { return; } + public void updateParser(ArrayList ops) throws IOException { + String serverId = null; + String displayName = null; + String parentId = null; + while (nextTag(Tags.FOLDER_UPDATE) != END) { + switch (tag) { + case Tags.FOLDER_SERVER_ID: + serverId = getValue(); + break; + case Tags.FOLDER_DISPLAY_NAME: + displayName = getValue(); + break; + case Tags.FOLDER_PARENT_ID: + parentId = getValue(); + break; + default: + skipTag(); + break; + } + } + // We'll make a change if one of parentId or displayName are specified + // serverId is required, but let's be careful just the same + if (serverId != null && (displayName != null || parentId != null)) { + Cursor c = getServerIdCursor(serverId); + try { + // If we find the mailbox (using serverId), make the change + if (c.moveToFirst()) { + userLog("Updating ", serverId); + ContentValues cv = new ContentValues(); + if (displayName != null) { + cv.put(Mailbox.DISPLAY_NAME, displayName); + } + if (parentId != null) { + cv.put(Mailbox.PARENT_SERVER_ID, parentId); + } + ops.add(ContentProviderOperation.newUpdate( + ContentUris.withAppendedId(Mailbox.CONTENT_URI, + c.getLong(0))).withValues(cv).build()); + } + } finally { + c.close(); + } + } + } + public void changesParser() throws IOException { // Keep track of new boxes, deleted boxes, updated boxes ArrayList ops = new ArrayList(); while (nextTag(Tags.FOLDER_CHANGES) != END) { - // TODO Handle FOLDER_CHANGE and FOLDER_DELETE if (tag == Tags.FOLDER_ADD) { addParser(ops); } else if (tag == Tags.FOLDER_DELETE) { deleteParser(ops); + } else if (tag == Tags.FOLDER_UPDATE) { + updateParser(ops); } else if (tag == Tags.FOLDER_COUNT) { getValueInt(); } else