Make vCard composer use ContentValues object with non-empty name unless the object is not marked as IS_SUPER_PRIMARY.
Previous change selected the first ContactValues object even when its name fields are all empty. This time, vCard composer checks the name fields and skip the object withouth valid name. One exception is the object with IS_SUPER_PRIMARY flag. If IS_SUPER_PRIMARY flag is set, the object will be selected even when the object does not have valid name. Add a unit test for this fix. Internal issue number: 2252304
This commit is contained in:
@@ -676,6 +676,18 @@ public class VCardComposer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean containsNonEmptyName(ContentValues contentValues) {
|
||||||
|
final String familyName = contentValues.getAsString(StructuredName.FAMILY_NAME);
|
||||||
|
final String middleName = contentValues.getAsString(StructuredName.MIDDLE_NAME);
|
||||||
|
final String givenName = contentValues.getAsString(StructuredName.GIVEN_NAME);
|
||||||
|
final String prefix = contentValues.getAsString(StructuredName.PREFIX);
|
||||||
|
final String suffix = contentValues.getAsString(StructuredName.SUFFIX);
|
||||||
|
final String displayName = contentValues.getAsString(StructuredName.DISPLAY_NAME);
|
||||||
|
return !(TextUtils.isEmpty(familyName) && TextUtils.isEmpty(middleName) &&
|
||||||
|
TextUtils.isEmpty(givenName) && TextUtils.isEmpty(prefix) &&
|
||||||
|
TextUtils.isEmpty(suffix) && TextUtils.isEmpty(displayName));
|
||||||
|
}
|
||||||
|
|
||||||
private void appendStructuredNamesInternal(final StringBuilder builder,
|
private void appendStructuredNamesInternal(final StringBuilder builder,
|
||||||
final List<ContentValues> contentValuesList) {
|
final List<ContentValues> contentValuesList) {
|
||||||
// For safety, we'll emit just one value around StructuredName, as external importers
|
// For safety, we'll emit just one value around StructuredName, as external importers
|
||||||
@@ -695,12 +707,14 @@ public class VCardComposer {
|
|||||||
} else if (primaryContentValues == null) {
|
} else if (primaryContentValues == null) {
|
||||||
// We choose the first "primary" ContentValues
|
// We choose the first "primary" ContentValues
|
||||||
// if "super primary" ContentValues does not exist.
|
// if "super primary" ContentValues does not exist.
|
||||||
Integer primary = contentValues.getAsInteger(StructuredName.IS_PRIMARY);
|
Integer isPrimary = contentValues.getAsInteger(StructuredName.IS_PRIMARY);
|
||||||
if (primary != null && primary > 0) {
|
if (isPrimary != null && isPrimary > 0 &&
|
||||||
|
containsNonEmptyName(contentValues)) {
|
||||||
primaryContentValues = contentValues;
|
primaryContentValues = contentValues;
|
||||||
// Do not break, since there may be ContentValues with "super primary"
|
// Do not break, since there may be ContentValues with "super primary"
|
||||||
// afterword.
|
// afterword.
|
||||||
} else if (subprimaryContentValues == null) {
|
} else if (subprimaryContentValues == null &&
|
||||||
|
containsNonEmptyName(contentValues)) {
|
||||||
subprimaryContentValues = contentValues;
|
subprimaryContentValues = contentValues;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -903,4 +903,34 @@ public class VCardExporterTests extends VCardTestsBase {
|
|||||||
.addNodeWithoutOrder("TEL", "777-888-9999", new TypeSet("HOME"));
|
.addNodeWithoutOrder("TEL", "777-888-9999", new TypeSet("HOME"));
|
||||||
verifier.verify();
|
verifier.verify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void testPickUpNonEmptyContentValuesCommon(int version) {
|
||||||
|
ExportTestResolver resolver = new ExportTestResolver();
|
||||||
|
ContactEntry entry = resolver.buildContactEntry();
|
||||||
|
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||||
|
.put(StructuredName.IS_PRIMARY, 1); // Empty name. Should be ignored.
|
||||||
|
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||||
|
.put(StructuredName.FAMILY_NAME, "family1"); // Not primary. Should be ignored.
|
||||||
|
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||||
|
.put(StructuredName.IS_PRIMARY, 1)
|
||||||
|
.put(StructuredName.FAMILY_NAME, "family2"); // This entry is what we want.
|
||||||
|
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||||
|
.put(StructuredName.IS_PRIMARY, 1)
|
||||||
|
.put(StructuredName.FAMILY_NAME, "family3");
|
||||||
|
entry.buildData(StructuredName.CONTENT_ITEM_TYPE)
|
||||||
|
.put(StructuredName.FAMILY_NAME, "family4");
|
||||||
|
VCardVerifier verifier = new VCardVerifier(resolver, version);
|
||||||
|
verifier.addPropertyNodesVerifierElem()
|
||||||
|
.addNodeWithoutOrder("N", Arrays.asList("family2", "", "", "", ""))
|
||||||
|
.addNodeWithoutOrder("FN", "family2");
|
||||||
|
verifier.verify();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPickUpNonEmptyContentValuesV21() {
|
||||||
|
testPickUpNonEmptyContentValuesCommon(V21);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPickUpNonEmptyContentValuesV30() {
|
||||||
|
testPickUpNonEmptyContentValuesCommon(V30);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user