Fix vCard importer so that it imports IM correctly.
Bug: 2944990
Change-Id: I9aba68f03569b9288c4286b73bf3e4e4b84e6d1a
diff --git a/java/com/android/vcard/VCardConstants.java b/java/com/android/vcard/VCardConstants.java
index 20cc093..ef0f7e3 100644
--- a/java/com/android/vcard/VCardConstants.java
+++ b/java/com/android/vcard/VCardConstants.java
@@ -61,8 +61,8 @@
public static final String PROPERTY_X_PHONETIC_MIDDLE_NAME = "X-PHONETIC-MIDDLE-NAME";
public static final String PROPERTY_X_PHONETIC_LAST_NAME = "X-PHONETIC-LAST-NAME";
- // Properties both ContactsStruct in Eclair and de-fact vCard extensions
- // shown in http://en.wikipedia.org/wiki/VCard support are defined here.
+ // Properties both ContactsStruct and de-fact vCard extensions
+ // Shown in http://en.wikipedia.org/wiki/VCard support are defined here.
public static final String PROPERTY_X_AIM = "X-AIM";
public static final String PROPERTY_X_MSN = "X-MSN";
public static final String PROPERTY_X_YAHOO = "X-YAHOO";
@@ -164,7 +164,8 @@
// SORT-STRING invCard 3.0.
/* package */ static final String PARAM_TYPE_X_IRMC_N = "X-IRMC-N";
- /* package */ static final int MAX_DATA_COLUMN = 15;
+ // Used in unit test.
+ public static final int MAX_DATA_COLUMN = 15;
/* package */ static final int MAX_CHARACTER_NUMS_QP = 76;
static final int MAX_CHARACTER_NUMS_BASE64_V30 = 75;
diff --git a/java/com/android/vcard/VCardEntry.java b/java/com/android/vcard/VCardEntry.java
index b7bd1ef..35dc9a0 100644
--- a/java/com/android/vcard/VCardEntry.java
+++ b/java/com/android/vcard/VCardEntry.java
@@ -1025,7 +1025,7 @@
}
}
if (type < 0) {
- type = Phone.TYPE_HOME;
+ type = Im.TYPE_HOME;
}
addIm(protocol, null, type, propValue, isPrimary);
} else if (propName.equals(VCardConstants.PROPERTY_NOTE)) {
@@ -1230,12 +1230,14 @@
builder.withValue(Data.MIMETYPE, Im.CONTENT_ITEM_TYPE);
builder.withValue(Im.TYPE, imData.type);
builder.withValue(Im.PROTOCOL, imData.protocol);
+ builder.withValue(Im.DATA, imData.data);
if (imData.protocol == Im.PROTOCOL_CUSTOM) {
builder.withValue(Im.CUSTOM_PROTOCOL, imData.customProtocol);
}
if (imData.isPrimary) {
builder.withValue(Data.IS_PRIMARY, 1);
}
+ operationList.add(builder.build());
}
}
diff --git a/tests/res/raw/v21_im.vcf b/tests/res/raw/v21_im.vcf
new file mode 100644
index 0000000..cc1aabb
--- /dev/null
+++ b/tests/res/raw/v21_im.vcf
@@ -0,0 +1,5 @@
+BEGIN:VCARD
+VERSION:2.1
+X-ANDROID-CUSTOM:vnd.android.cursor.item/nickname;Nick;1;;;;;;;;;;;;;
+X-GOOGLE-TALK:hhh@gmail.com
+END:VCARD
diff --git a/tests/src/com/android/vcard/tests/VCardExporterTests.java b/tests/src/com/android/vcard/tests/VCardExporterTests.java
index d61e6e7..4307214 100644
--- a/tests/src/com/android/vcard/tests/VCardExporterTests.java
+++ b/tests/src/com/android/vcard/tests/VCardExporterTests.java
@@ -384,11 +384,6 @@
testStructuredNameComplicatedCommon(V40);
}
- /*public void testStructuredNameUseSuperPrimaryV40() {
- // TODO: add appropriate SORT-AS
- // testStructuredNameUseSuperPrimaryCommon(V40);
- }*/
-
public void testNickNameV30() {
mVerifier.initForExportTest(V30);
mVerifier.addInputEntry().addContentValues(Nickname.CONTENT_ITEM_TYPE)
diff --git a/tests/src/com/android/vcard/tests/VCardImporterTests.java b/tests/src/com/android/vcard/tests/VCardImporterTests.java
index cf2c8b6..a8dcc52 100644
--- a/tests/src/com/android/vcard/tests/VCardImporterTests.java
+++ b/tests/src/com/android/vcard/tests/VCardImporterTests.java
@@ -18,6 +18,8 @@
import android.content.ContentValues;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Event;
+import android.provider.ContactsContract.CommonDataKinds.Im;
+import android.provider.ContactsContract.CommonDataKinds.Nickname;
import android.provider.ContactsContract.CommonDataKinds.Note;
import android.provider.ContactsContract.CommonDataKinds.Organization;
import android.provider.ContactsContract.CommonDataKinds.Phone;
@@ -1082,4 +1084,25 @@
.put(Organization.PHONETIC_NAME,
"\u3050\u30FC\u3050\u308B\u3051\u3093\u3055\u304F\u3076\u3082\u3093");
}
+
+ public void testIMV21_Parse() {
+ mVerifier.initForImportTest(V21, R.raw.v21_im);
+ mVerifier.addPropertyNodesVerifierElem()
+ .addExpectedNodeWithOrder("X-ANDROID-CUSTOM",
+ Arrays.asList("vnd.android.cursor.item/nickname", "Nick", "1",
+ "", "", "", "", "", "", "", "", "", "", "", "", "")) // 13
+ .addExpectedNodeWithOrder("X-GOOGLE-TALK", "hhh@gmail.com");
+ }
+
+ public void testIMV21() {
+ mVerifier.initForImportTest(V21, R.raw.v21_im);
+ final ContentValuesVerifierElem elem = mVerifier.addContentValuesVerifierElem();
+ elem.addExpected(Nickname.CONTENT_ITEM_TYPE)
+ .put(Nickname.NAME, "Nick")
+ .put(Nickname.TYPE, "1");
+ elem.addExpected(Im.CONTENT_ITEM_TYPE)
+ .put(Im.PROTOCOL, Im.PROTOCOL_GOOGLE_TALK)
+ .put(Im.TYPE, Im.TYPE_HOME)
+ .put(Im.DATA, "hhh@gmail.com");
+ }
}