diff --git a/core/java/android/pim/vcard/VCardBuilder.java b/core/java/android/pim/vcard/VCardBuilder.java
index 377e20155bf17..51701c6f50268 100644
--- a/core/java/android/pim/vcard/VCardBuilder.java
+++ b/core/java/android/pim/vcard/VCardBuilder.java
@@ -95,7 +95,7 @@ public class VCardBuilder {
private final boolean mUsesUtf8;
private final boolean mUsesShiftJis;
private final boolean mAppendTypeParamName;
- private final boolean mRefrainsQPToPrimaryProperties;
+ private final boolean mRefrainsQPToNameProperties;
private final boolean mNeedsToConvertPhoneticString;
private final boolean mShouldAppendCharsetParam;
@@ -118,7 +118,7 @@ public class VCardBuilder {
mUsesDefactProperty = VCardConfig.usesDefactProperty(vcardType);
mUsesUtf8 = VCardConfig.usesUtf8(vcardType);
mUsesShiftJis = VCardConfig.usesShiftJis(vcardType);
- mRefrainsQPToPrimaryProperties = VCardConfig.refrainsQPToPrimaryProperties(vcardType);
+ mRefrainsQPToNameProperties = VCardConfig.shouldRefrainQPToNameProperties(vcardType);
mAppendTypeParamName = VCardConfig.appendTypeParamName(vcardType);
mNeedsToConvertPhoneticString = VCardConfig.needsToConvertPhoneticString(vcardType);
@@ -255,7 +255,7 @@ public class VCardBuilder {
final boolean reallyAppendCharsetParameterToName =
shouldAppendCharsetParam(familyName, givenName, middleName, prefix, suffix);
final boolean reallyUseQuotedPrintableToName =
- (!mRefrainsQPToPrimaryProperties &&
+ (!mRefrainsQPToNameProperties &&
!(VCardUtils.containsOnlyNonCrLfPrintableAscii(familyName) &&
VCardUtils.containsOnlyNonCrLfPrintableAscii(givenName) &&
VCardUtils.containsOnlyNonCrLfPrintableAscii(middleName) &&
@@ -273,7 +273,7 @@ public class VCardBuilder {
final boolean reallyAppendCharsetParameterToFN =
shouldAppendCharsetParam(formattedName);
final boolean reallyUseQuotedPrintableToFN =
- !mRefrainsQPToPrimaryProperties &&
+ !mRefrainsQPToNameProperties &&
!VCardUtils.containsOnlyNonCrLfPrintableAscii(formattedName);
final String encodedFamily;
@@ -353,7 +353,7 @@ public class VCardBuilder {
mBuilder.append(VCARD_END_OF_LINE);
} else if (!TextUtils.isEmpty(displayName)) {
final boolean reallyUseQuotedPrintableToDisplayName =
- (!mRefrainsQPToPrimaryProperties &&
+ (!mRefrainsQPToNameProperties &&
!VCardUtils.containsOnlyNonCrLfPrintableAscii(displayName));
final String encodedDisplayName =
reallyUseQuotedPrintableToDisplayName ?
@@ -471,7 +471,7 @@ public class VCardBuilder {
mBuilder.append(VCardConstants.PARAM_TYPE_X_IRMC_N);
boolean reallyUseQuotedPrintable =
- (!mRefrainsQPToPrimaryProperties
+ (!mRefrainsQPToNameProperties
&& !(VCardUtils.containsOnlyNonCrLfPrintableAscii(
phoneticFamilyName)
&& VCardUtils.containsOnlyNonCrLfPrintableAscii(
@@ -976,12 +976,8 @@ public class VCardBuilder {
// Note: vCard 3.0 does not allow any parameter addition toward "URL"
// property, while there's no document in vCard 2.1.
- //
- // TODO: Should we allow adding it when appropriate?
- // (Actually, we drop some data. Using "group.X-URL-TYPE" or something
- // may help)
if (!TextUtils.isEmpty(website)) {
- appendLine(VCardConstants.PROPERTY_URL, website);
+ appendLineWithCharsetAndQPDetection(VCardConstants.PROPERTY_URL, website);
}
}
}
@@ -1041,23 +1037,9 @@ public class VCardBuilder {
if (data == null) {
continue;
}
- final String photoType;
- // Use some heuristics for guessing the format of the image.
- // TODO: there should be some general API for detecting the file format.
- if (data.length >= 3 && data[0] == 'G' && data[1] == 'I'
- && data[2] == 'F') {
- photoType = "GIF";
- } else if (data.length >= 4 && data[0] == (byte) 0x89
- && data[1] == 'P' && data[2] == 'N' && data[3] == 'G') {
- // Note: vCard 2.1 officially does not support PNG, but we may have it and
- // using X- word like "X-PNG" may not let importers know it is PNG.
- // So we use the String "PNG" as is...
- photoType = "PNG";
- } else if (data.length >= 2 && data[0] == (byte) 0xff
- && data[1] == (byte) 0xd8) {
- photoType = "JPEG";
- } else {
- Log.d(LOG_TAG, "Unknown photo type. Ignore.");
+ final String photoType = VCardUtils.guessImageType(data);
+ if (photoType == null) {
+ Log.d(LOG_TAG, "Unknown photo type. Ignored.");
continue;
}
final String photoString = new String(Base64.encodeBase64(data));
@@ -1762,7 +1744,6 @@ public class VCardBuilder {
return builder.toString();
}
-
/**
* Append '\' to the characters which should be escaped. The character set is different
* not only between vCard 2.1 and vCard 3.0 but also among each device.
diff --git a/core/java/android/pim/vcard/VCardComposer.java b/core/java/android/pim/vcard/VCardComposer.java
index c2d628feb6114..2037bc3ad1a3d 100644
--- a/core/java/android/pim/vcard/VCardComposer.java
+++ b/core/java/android/pim/vcard/VCardComposer.java
@@ -144,11 +144,6 @@ public class VCardComposer {
private static final Uri sDataRequestUri;
private static final Map
* We added this Android-specific notion since some (incomplete) vCard exporters for vCard 2.1 - * do NOT use Quoted-Printable encoding toward some properties like "N", "FN", etc. even when - * their values contain non-ascii or/and CR/LF, while they use the encoding in the other - * properties like "ADR", "ORG", etc. + * do NOT use Quoted-Printable encoding toward some properties related names like "N", "FN", etc. + * even when their values contain non-ascii or/and CR/LF, while they use the encoding in the + * other properties like "ADR", "ORG", etc. *
* We are afraid of the case where some vCard importer also forget handling QP presuming QP is * not used in such fields. *
** This flag is useful when some target importer you are going to focus on does not accept - * such "primary" property values with Quoted-Printable encoding. + * such properties with Quoted-Printable encoding. *
** Again, we should not use this flag at all for complying vCard 2.1 spec. *
*- * We will change the behavior around this flag in the future, after understanding the other - * real vCard cases around this problem. Please use this flag with extreme caution even when - * needed. - *
- ** In vCard 3.0, Quoted-Printable is explicitly "prohibitted", so we don't need to care this * kind of problem (hopefully). *
*/ - public static final int FLAG_REFRAIN_QP_TO_PRIMARY_PROPERTIES = 0x10000000; + public static final int FLAG_REFRAIN_QP_TO_NAME_PROPERTIES = 0x10000000; /** *
@@ -311,7 +312,7 @@ public class VCardConfig {
public static final int VCARD_TYPE_V21_JAPANESE_MOBILE =
(FLAG_V21 | NAME_ORDER_JAPANESE | FLAG_CHARSET_SHIFT_JIS |
FLAG_CONVERT_PHONETIC_NAME_STRINGS |
- FLAG_REFRAIN_QP_TO_PRIMARY_PROPERTIES);
+ FLAG_REFRAIN_QP_TO_NAME_PROPERTIES);
/* package */ static final String VCARD_TYPE_V21_JAPANESE_MOBILE_STR = "v21_japanese_mobile";
@@ -400,9 +401,9 @@ public class VCardConfig {
return (VCardConfig.LOG_LEVEL & VCardConfig.LOG_LEVEL_PERFORMANCE_MEASUREMENT) != 0;
}
- public static boolean refrainsQPToPrimaryProperties(final int vcardType) {
+ public static boolean shouldRefrainQPToNameProperties(final int vcardType) {
return (!shouldUseQuotedPrintable(vcardType) ||
- ((vcardType & FLAG_REFRAIN_QP_TO_PRIMARY_PROPERTIES) != 0));
+ ((vcardType & FLAG_REFRAIN_QP_TO_NAME_PROPERTIES) != 0));
}
public static boolean appendTypeParamName(final int vcardType) {
diff --git a/core/java/android/pim/vcard/VCardParser.java b/core/java/android/pim/vcard/VCardParser.java
index 6afb95e577fab..57c52a646cdde 100644
--- a/core/java/android/pim/vcard/VCardParser.java
+++ b/core/java/android/pim/vcard/VCardParser.java
@@ -21,21 +21,15 @@ import java.io.IOException;
import java.io.InputStream;
public abstract class VCardParser {
- public static final int PARSER_MODE_DEFAULT = 0;
- /**
- * The parser should ignore "AGENT" properties and nested vCard structure.
- */
- public static final int PARSER_MODE_SCAN = 1;
-
- protected final int mParserMode;
+ protected final int mParseType;
protected boolean mCanceled;
public VCardParser() {
- mParserMode = PARSER_MODE_DEFAULT;
+ this(VCardConfig.PARSE_TYPE_UNKNOWN);
}
- public VCardParser(int parserMode) {
- mParserMode = parserMode;
+ public VCardParser(int parseType) {
+ mParseType = parseType;
}
/**
diff --git a/core/java/android/pim/vcard/VCardParser_V21.java b/core/java/android/pim/vcard/VCardParser_V21.java
index ef3fb8d66370a..ec569d4f6089b 100644
--- a/core/java/android/pim/vcard/VCardParser_V21.java
+++ b/core/java/android/pim/vcard/VCardParser_V21.java
@@ -95,12 +95,6 @@ public class VCardParser_V21 extends VCardParser {
protected Set