diff --git a/src/com/android/exchange/adapter/ContactsSyncAdapter.java b/src/com/android/exchange/adapter/ContactsSyncAdapter.java index 3348755ea..3557edc9b 100644 --- a/src/com/android/exchange/adapter/ContactsSyncAdapter.java +++ b/src/com/android/exchange/adapter/ContactsSyncAdapter.java @@ -1330,20 +1330,21 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter { public void addUntyped(Entity entity, ArrayList rows, String mimeType, int type, int maxRows) { // Make a list of all same type rows in the existing entity - ArrayList oldAccounts = new ArrayList(); + ArrayList oldValues = new ArrayList(); + ArrayList entityValues = entity.getSubValues(); if (entity != null) { - oldAccounts = findUntypedData(entity.getSubValues(), type, mimeType); + oldValues = findUntypedData(entityValues, type, mimeType); } // These will be rows needing replacement with new values ArrayList rowsToReplace = new ArrayList(); // The count of existing rows - int numRows = oldAccounts.size(); + int numRows = oldValues.size(); for (UntypedRow row: rows) { boolean found = false; - // If we already have this IM address, mark it - for (NamedContentValues ncv: oldAccounts) { + // If we already have this row, mark it + for (NamedContentValues ncv: oldValues) { ContentValues cv = ncv.values; String data = cv.getAsString(COMMON_DATA_ROW); int rowType = -1; @@ -1352,6 +1353,8 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter { } if (row.isSameAs(rowType, data)) { cv.put(FOUND_DATA_ROW, true); + // Remove this to indicate it's still being used + entityValues.remove(ncv); found = true; break; } @@ -1373,7 +1376,7 @@ public class ContactsSyncAdapter extends AbstractSyncAdapter { // Go through rows needing replacement for (UntypedRow row: rowsToReplace) { - for (NamedContentValues ncv: oldAccounts) { + for (NamedContentValues ncv: oldValues) { ContentValues cv = ncv.values; // Find a row that hasn't been used (i.e. doesn't match current rows) if (!cv.containsKey(FOUND_DATA_ROW)) {