summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaisuke Miyakawa <dmiyakawa@google.com>2009-11-11 08:41:31 +0900
committerDaisuke Miyakawa <dmiyakawa@google.com>2009-11-11 10:03:10 +0900
commit0cda59112526c03f3b8be0eb885926b7515df756 (patch)
tree52eb797ee227994222cc8326618614312e19627f
parent6780d8c006c9381919c0ee4de3d2bdc6d7a728d6 (diff)
downloadframeworks_base-0cda59112526c03f3b8be0eb885926b7515df756.zip
frameworks_base-0cda59112526c03f3b8be0eb885926b7515df756.tar.gz
frameworks_base-0cda59112526c03f3b8be0eb885926b7515df756.tar.bz2
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
-rw-r--r--core/java/android/pim/vcard/VCardComposer.java20
-rw-r--r--tests/AndroidTests/src/com/android/unit_tests/vcard/VCardExporterTests.java30
2 files changed, 47 insertions, 3 deletions
diff --git a/core/java/android/pim/vcard/VCardComposer.java b/core/java/android/pim/vcard/VCardComposer.java
index 5a14f5f..980dd05 100644
--- a/core/java/android/pim/vcard/VCardComposer.java
+++ b/core/java/android/pim/vcard/VCardComposer.java
@@ -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,
final List<ContentValues> contentValuesList) {
// For safety, we'll emit just one value around StructuredName, as external importers
@@ -695,12 +707,14 @@ public class VCardComposer {
} else if (primaryContentValues == null) {
// We choose the first "primary" ContentValues
// if "super primary" ContentValues does not exist.
- Integer primary = contentValues.getAsInteger(StructuredName.IS_PRIMARY);
- if (primary != null && primary > 0) {
+ Integer isPrimary = contentValues.getAsInteger(StructuredName.IS_PRIMARY);
+ if (isPrimary != null && isPrimary > 0 &&
+ containsNonEmptyName(contentValues)) {
primaryContentValues = contentValues;
// Do not break, since there may be ContentValues with "super primary"
// afterword.
- } else if (subprimaryContentValues == null) {
+ } else if (subprimaryContentValues == null &&
+ containsNonEmptyName(contentValues)) {
subprimaryContentValues = contentValues;
}
}
diff --git a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardExporterTests.java b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardExporterTests.java
index cdecd3b..6dabd01 100644
--- a/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardExporterTests.java
+++ b/tests/AndroidTests/src/com/android/unit_tests/vcard/VCardExporterTests.java
@@ -903,4 +903,34 @@ public class VCardExporterTests extends VCardTestsBase {
.addNodeWithoutOrder("TEL", "777-888-9999", new TypeSet("HOME"));
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);
+ }
}