Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1d707fcd authored by Daisuke Miyakawa's avatar Daisuke Miyakawa Committed by Android (Google) Code Review
Browse files

Merge "Let vCard importer/exporter select charset. There are some other bug...

Merge "Let vCard importer/exporter select charset. There are some other bug where charset for import/export is used during vCard handling."
parents 7a3a6dba 82b8b686
Loading
Loading
Loading
Loading
+142 −78
Original line number Diff line number Diff line
@@ -47,7 +47,22 @@ import java.util.Map;
import java.util.Set;

/**
 * The class which lets users create their own vCard String.
 * <p>
 * The class which lets users create their own vCard String. Typical usage is as follows:
 * </p>
 * <pre class="prettyprint">final VCardBuilder builder = new VCardBuilder(vcardType);
 * builder.appendNameProperties(contentValuesListMap.get(StructuredName.CONTENT_ITEM_TYPE))
 *     .appendNickNames(contentValuesListMap.get(Nickname.CONTENT_ITEM_TYPE))
 *     .appendPhones(contentValuesListMap.get(Phone.CONTENT_ITEM_TYPE))
 *     .appendEmails(contentValuesListMap.get(Email.CONTENT_ITEM_TYPE))
 *     .appendPostals(contentValuesListMap.get(StructuredPostal.CONTENT_ITEM_TYPE))
 *     .appendOrganizations(contentValuesListMap.get(Organization.CONTENT_ITEM_TYPE))
 *     .appendWebsites(contentValuesListMap.get(Website.CONTENT_ITEM_TYPE))
 *     .appendPhotos(contentValuesListMap.get(Photo.CONTENT_ITEM_TYPE))
 *     .appendNotes(contentValuesListMap.get(Note.CONTENT_ITEM_TYPE))
 *     .appendEvents(contentValuesListMap.get(Event.CONTENT_ITEM_TYPE))
 *     .appendIms(contentValuesListMap.get(Im.CONTENT_ITEM_TYPE))
 *     .appendRelation(contentValuesListMap.get(Relation.CONTENT_ITEM_TYPE)); </pre>
 */
public class VCardBuilder {
    private static final String LOG_TAG = "VCardBuilder";
@@ -81,7 +96,6 @@ public class VCardBuilder {
    private static final String VCARD_PARAM_ENCODING_BASE64_V30 = "ENCODING=b";

    private static final String SHIFT_JIS = "SHIFT_JIS";
    private static final String UTF_8 = "UTF-8";

    private final int mVCardType;

@@ -92,21 +106,28 @@ public class VCardBuilder {
    private final boolean mShouldUseQuotedPrintable;
    private final boolean mUsesAndroidProperty;
    private final boolean mUsesDefactProperty;
    private final boolean mUsesUtf8;
    private final boolean mUsesShiftJis;
    private final boolean mAppendTypeParamName;
    private final boolean mRefrainsQPToNameProperties;
    private final boolean mNeedsToConvertPhoneticString;

    private final boolean mShouldAppendCharsetParam;

    private final String mCharsetString;
    private final String mCharset;
    private final String mVCardCharsetParameter;

    private StringBuilder mBuilder;
    private boolean mEndAppended;

    public VCardBuilder(final int vcardType) {
        // Default charset should be used
        this(vcardType, null);
    }

    /**
     * @param vcardType
     * @param charset If null, we use default charset for export.
     */
    public VCardBuilder(final int vcardType, String charset) {
        mVCardType = vcardType;

        mIsV30 = VCardConfig.isV30(vcardType);
@@ -116,40 +137,77 @@ public class VCardBuilder {
        mOnlyOneNoteFieldIsAvailable = VCardConfig.onlyOneNoteFieldIsAvailable(vcardType);
        mUsesAndroidProperty = VCardConfig.usesAndroidSpecificProperty(vcardType);
        mUsesDefactProperty = VCardConfig.usesDefactProperty(vcardType);
        mUsesUtf8 = VCardConfig.usesUtf8(vcardType);
        mUsesShiftJis = VCardConfig.usesShiftJis(vcardType);
        mRefrainsQPToNameProperties = VCardConfig.shouldRefrainQPToNameProperties(vcardType);
        mAppendTypeParamName = VCardConfig.appendTypeParamName(vcardType);
        mNeedsToConvertPhoneticString = VCardConfig.needsToConvertPhoneticString(vcardType);

        mShouldAppendCharsetParam = !(mIsV30 && mUsesUtf8);

        final boolean shouldUseUtf8 = VCardConfig.shouldUseUtf8ForExport(vcardType);
        final boolean shouldUseShiftJis = VCardConfig.shouldUseShiftJisForExport(vcardType);

        // vCard 2.1 requires charset.
        // vCard 3.0 does not allow it but we found some devices use it to determine
        // the exact charset.
        // We currently append it only when charset other than UTF_8 is used.
        mShouldAppendCharsetParam = !(mIsV30 && shouldUseUtf8);

        if (VCardConfig.isDoCoMo(vcardType) || shouldUseShiftJis) {
            if (!SHIFT_JIS.equalsIgnoreCase(charset)) {
                Log.w(LOG_TAG,
                        "The charset \"" + charset + "\" is used while "
                        + SHIFT_JIS + " is needed to be used.");
                if (TextUtils.isEmpty(charset)) {
                    mCharset = SHIFT_JIS;
                } else {
                    try {
                        charset = CharsetUtils.charsetForVendor(charset).name();
                    } catch (UnsupportedCharsetException e) {
                        Log.i(LOG_TAG,
                                "Career-specific \"" + charset + "\" was not found (as usual). "
                                + "Use it as is.");
                    }
                    mCharset = charset;
                }
            } else {
                if (mIsDoCoMo) {
            String charset;
                    try {
                        charset = CharsetUtils.charsetForVendor(SHIFT_JIS, "docomo").name();
                    } catch (UnsupportedCharsetException e) {
                Log.e(LOG_TAG, "DoCoMo-specific SHIFT_JIS was not found. Use SHIFT_JIS as is.");
                        Log.e(LOG_TAG,
                                "DoCoMo-specific SHIFT_JIS was not found. "
                                + "Use SHIFT_JIS as is.");
                        charset = SHIFT_JIS;
                    }
            mCharsetString = charset;
            // Do not use mCharsetString bellow since it is different from "SHIFT_JIS" but
            // may be "DOCOMO_SHIFT_JIS" or something like that (internal expression used in
            // Android, not shown to the public).
            mVCardCharsetParameter = "CHARSET=" + SHIFT_JIS;
        } else if (mUsesShiftJis) {
            String charset;
                } else {
                    try {
                        charset = CharsetUtils.charsetForVendor(SHIFT_JIS).name();
                    } catch (UnsupportedCharsetException e) {
                Log.e(LOG_TAG, "Vendor-specific SHIFT_JIS was not found. Use SHIFT_JIS as is.");
                        Log.e(LOG_TAG,
                                "Career-specific SHIFT_JIS was not found. "
                                + "Use SHIFT_JIS as is.");
                        charset = SHIFT_JIS;
                    }
            mCharsetString = charset;
                }
                mCharset = charset;
            }
            mVCardCharsetParameter = "CHARSET=" + SHIFT_JIS;
        } else {
            mCharsetString = UTF_8;
            mVCardCharsetParameter = "CHARSET=" + UTF_8;
            if (TextUtils.isEmpty(charset)) {
                Log.i(LOG_TAG,
                        "Use the charset \"" + VCardConfig.DEFAULT_EXPORT_CHARSET
                        + "\" for export.");
                mCharset = VCardConfig.DEFAULT_EXPORT_CHARSET;
                mVCardCharsetParameter = "CHARSET=" + VCardConfig.DEFAULT_EXPORT_CHARSET;
            } else {
                try {
                    charset = CharsetUtils.charsetForVendor(charset).name();
                } catch (UnsupportedCharsetException e) {
                    Log.i(LOG_TAG,
                            "Career-specific \"" + charset + "\" was not found (as usual). "
                            + "Use it as is.");
                }
                mCharset = charset;
                mVCardCharsetParameter = "CHARSET=" + charset;
            }
        }
        clear();
    }
@@ -379,8 +437,8 @@ public class VCardBuilder {
            mBuilder.append(VCardConstants.PROPERTY_FN);

            // Note: "CHARSET" param is not allowed in vCard 3.0, but we may add it
            //       when it would be useful for external importers, assuming no external
            //       importer allows this vioration.
            //       when it would be useful or necessary for external importers,
            //       assuming the external importer allows this vioration of the spec.
            if (shouldAppendCharsetParam(displayName)) {
                mBuilder.append(VCARD_PARAM_SEPARATOR);
                mBuilder.append(mVCardCharsetParameter);
@@ -454,18 +512,18 @@ public class VCardBuilder {
            mBuilder.append(VCARD_END_OF_LINE);
        } else if (mIsJapaneseMobilePhone) {
            // Note: There is no appropriate property for expressing
            //       phonetic name in vCard 2.1, while there is in
            //       phonetic name (Yomigana in Japanese) in vCard 2.1, while there is in
            //       vCard 3.0 (SORT-STRING).
            //       We chose to use DoCoMo's way when the device is Japanese one
            //       since it is supported by
            //       a lot of Japanese mobile phones. This is "X-" property, so
            //       any parser hopefully would not get confused with this.
            //       We use DoCoMo's way when the device is Japanese one since it is already
            //       supported by a lot of Japanese mobile phones.
            //       This is "X-" property, so any parser hopefully would not get
            //       confused with this.
            //
            //       Also, DoCoMo's specification requires vCard composer to use just the first
            //       column.
            //       i.e.
            //       o  SOUND;X-IRMC-N:Miyakawa Daisuke;;;;
            //       x  SOUND;X-IRMC-N:Miyakawa;Daisuke;;;
            //       good:  SOUND;X-IRMC-N:Miyakawa Daisuke;;;;
            //       bad :  SOUND;X-IRMC-N:Miyakawa;Daisuke;;;
            mBuilder.append(VCardConstants.PROPERTY_SOUND);
            mBuilder.append(VCARD_PARAM_SEPARATOR);
            mBuilder.append(VCardConstants.PARAM_TYPE_X_IRMC_N);
@@ -519,10 +577,10 @@ public class VCardBuilder {
                    mBuilder.append(encodedPhoneticGivenName);
                }
            }
            mBuilder.append(VCARD_ITEM_SEPARATOR);
            mBuilder.append(VCARD_ITEM_SEPARATOR);
            mBuilder.append(VCARD_ITEM_SEPARATOR);
            mBuilder.append(VCARD_ITEM_SEPARATOR);
            mBuilder.append(VCARD_ITEM_SEPARATOR);  // family;given
            mBuilder.append(VCARD_ITEM_SEPARATOR);  // given;middle
            mBuilder.append(VCARD_ITEM_SEPARATOR);  // middle;prefix
            mBuilder.append(VCARD_ITEM_SEPARATOR);  // prefix;suffix
            mBuilder.append(VCARD_END_OF_LINE);
        }

@@ -549,7 +607,7 @@ public class VCardBuilder {
                mBuilder.append(VCARD_DATA_SEPARATOR);
                mBuilder.append(encodedPhoneticGivenName);
                mBuilder.append(VCARD_END_OF_LINE);
            }
            }  // if (!TextUtils.isEmpty(phoneticGivenName))
            if (!TextUtils.isEmpty(phoneticMiddleName)) {
                final boolean reallyUseQuotedPrintable =
                    (mShouldUseQuotedPrintable &&
@@ -572,7 +630,7 @@ public class VCardBuilder {
                mBuilder.append(VCARD_DATA_SEPARATOR);
                mBuilder.append(encodedPhoneticMiddleName);
                mBuilder.append(VCARD_END_OF_LINE);
            }
            }  // if (!TextUtils.isEmpty(phoneticGivenName))
            if (!TextUtils.isEmpty(phoneticFamilyName)) {
                final boolean reallyUseQuotedPrintable =
                    (mShouldUseQuotedPrintable &&
@@ -595,7 +653,7 @@ public class VCardBuilder {
                mBuilder.append(VCARD_DATA_SEPARATOR);
                mBuilder.append(encodedPhoneticFamilyName);
                mBuilder.append(VCARD_END_OF_LINE);
            }
            }  // if (!TextUtils.isEmpty(phoneticFamilyName))
        }
    }

@@ -903,21 +961,21 @@ public class VCardBuilder {
                encodedCountry = escapeCharacters(rawCountry);
                encodedNeighborhood = escapeCharacters(rawNeighborhood);
            }
            final StringBuffer addressBuffer = new StringBuffer();
            addressBuffer.append(encodedPoBox);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(encodedStreet);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(encodedLocality);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(encodedRegion);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(encodedPostalCode);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(encodedCountry);
            final StringBuilder addressBuilder = new StringBuilder();
            addressBuilder.append(encodedPoBox);
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // PO BOX ; Extended Address
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Extended Address : Street
            addressBuilder.append(encodedStreet);
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Street : Locality
            addressBuilder.append(encodedLocality);
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Locality : Region
            addressBuilder.append(encodedRegion);
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Region : Postal Code
            addressBuilder.append(encodedPostalCode);
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Postal Code : Country
            addressBuilder.append(encodedCountry);
            return new PostalStruct(
                    reallyUseQuotedPrintable, appendCharset, addressBuffer.toString());
                    reallyUseQuotedPrintable, appendCharset, addressBuilder.toString());
        } else {  // VCardUtils.areAllEmpty(rawAddressArray) == true
            // Try to use FORMATTED_ADDRESS instead.
            final String rawFormattedAddress =
@@ -940,16 +998,16 @@ public class VCardBuilder {
            // We use the second value ("Extended Address") just because Japanese mobile phones
            // do so. If the other importer expects the value be in the other field, some flag may
            // be needed.
            final StringBuffer addressBuffer = new StringBuffer();
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(encodedFormattedAddress);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            addressBuffer.append(VCARD_ITEM_SEPARATOR);
            final StringBuilder addressBuilder = new StringBuilder();
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // PO BOX ; Extended Address
            addressBuilder.append(encodedFormattedAddress);
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Extended Address : Street
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Street : Locality
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Locality : Region
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Region : Postal Code
            addressBuilder.append(VCARD_ITEM_SEPARATOR);  // Postal Code : Country
            return new PostalStruct(
                    reallyUseQuotedPrintable, appendCharset, addressBuffer.toString());
                    reallyUseQuotedPrintable, appendCharset, addressBuilder.toString());
        }
    }

@@ -1146,6 +1204,8 @@ public class VCardBuilder {
    }

    public VCardBuilder appendEvents(final List<ContentValues> contentValuesList) {
        // There's possibility where a given object may have more than one birthday, which
        // is inappropriate. We just build one birthday.
        if (contentValuesList != null) {
            String primaryBirthday = null;
            String secondaryBirthday = null;
@@ -1213,16 +1273,19 @@ public class VCardBuilder {
        return this;
    }

    /**
     * @param emitEveryTime If true, builder builds the line even when there's no entry.
     */
    public void appendPostalLine(final int type, final String label,
            final ContentValues contentValues,
            final boolean isPrimary, final boolean emitLineEveryTime) {
            final boolean isPrimary, final boolean emitEveryTime) {
        final boolean reallyUseQuotedPrintable;
        final boolean appendCharset;
        final String addressValue;
        {
            PostalStruct postalStruct = tryConstructPostalStruct(contentValues);
            if (postalStruct == null) {
                if (emitLineEveryTime) {
                if (emitEveryTime) {
                    reallyUseQuotedPrintable = false;
                    appendCharset = false;
                    addressValue = "";
@@ -1537,7 +1600,8 @@ public class VCardBuilder {
        mBuilder.append(VCARD_END_OF_LINE);
    }

    public void appendAndroidSpecificProperty(final String mimeType, ContentValues contentValues) {
    public void appendAndroidSpecificProperty(
            final String mimeType, ContentValues contentValues) {
        if (!sAllowedAndroidPropertySet.contains(mimeType)) {
            return;
        }
@@ -1659,7 +1723,7 @@ public class VCardBuilder {
            encodedValue = encodeQuotedPrintable(rawValue);
        } else {
            // TODO: one line may be too huge, which may be invalid in vCard spec, though
            //       several (even well-known) applications do not care this.
            //       several (even well-known) applications do not care that violation.
            encodedValue = escapeCharacters(rawValue);
        }

@@ -1794,9 +1858,9 @@ public class VCardBuilder {
        byte[] strArray = null;

        try {
            strArray = str.getBytes(mCharsetString);
            strArray = str.getBytes(mCharset);
        } catch (UnsupportedEncodingException e) {
            Log.e(LOG_TAG, "Charset " + mCharsetString + " cannot be used. "
            Log.e(LOG_TAG, "Charset " + mCharset + " cannot be used. "
                    + "Try default charset");
            strArray = str.getBytes();
        }
+153 −69

File changed.

Preview size limit exceeded, changes collapsed.

+47 −21
Original line number Diff line number Diff line
@@ -43,9 +43,27 @@ public class VCardConfig {
    /* package */ static final int PARSE_TYPE_FOMA = 3;  // For Japanese FOMA mobile phones.
    /* package */ static final int PARSE_TYPE_WINDOWS_MOBILE_JP = 4;

    // Assumes that "iso-8859-1" is able to map "all" 8bit characters to some unicode and
    // decode the unicode to the original charset. If not, this setting will cause some bug. 
    public static final String DEFAULT_CHARSET = "iso-8859-1";
    /**
     * <P>
     * The charset used during import.
     * </P>
     * <P>
     * We cannot determine which charset should be used to interpret a given vCard file,
     * while we have to decode sime encoded data (e.g. BASE64) to binary.
     * In order to avoid "misinterpretation" of charset as much as possible,
     * "ISO-8859-1" (a.k.a Latin-1) is first used for reading a stream.
     * When charset is specified in a property (with "CHARSET=..." parameter),
     * the string is decoded to raw bytes and encoded into the specific charset,
     * assuming "ISO-8859-1" is able to map "all" 8bit characters to some unicode,
     * and it has 1 to 1 mapping in all 8bit characters.
     * If the assumption is not correct, this setting will cause some bug.
     * </P>
     */
    /* package */ static final String DEFAULT_TEMPORARY_CHARSET = "ISO-8859-1";

    // TODO: still intermediate procedures uses this charset. Fix it.
    public static final String DEFAULT_IMPORT_CHARSET = "ISO-8859-1";
    public static final String DEFAULT_EXPORT_CHARSET = "UTF-8";

    public static final int FLAG_V21 = 0;
    public static final int FLAG_V30 = 1;
@@ -59,9 +77,12 @@ public class VCardConfig {

    // 0x10 is reserved for safety

    private static final int FLAG_CHARSET_UTF8 = 0;
    private static final int FLAG_CHARSET_SHIFT_JIS = 0x100;
    private static final int FLAG_CHARSET_MASK = 0xF00;
    /*
     * These flags are ignored when charset is explicitly given by a caller.
     */
    private static final int FLAG_USE_UTF8_FOR_EXPORT = 0;
    private static final int FLAG_USE_SHIFT_JIS_FOR_EXPORT = 0x100;
    private static final int FLAG_CHARSET_MASK_FOR_EKPORT = 0xF00;

    /**
     * The flag indicating the vCard composer will add some "X-" properties used only in Android
@@ -196,7 +217,7 @@ public class VCardConfig {
     * </P>
     */
    public static final int VCARD_TYPE_V21_GENERIC_UTF8 =
        (FLAG_V21 | NAME_ORDER_DEFAULT | FLAG_CHARSET_UTF8 |
        (FLAG_V21 | NAME_ORDER_DEFAULT | FLAG_USE_UTF8_FOR_EXPORT |
                FLAG_USE_DEFACT_PROPERTY | FLAG_USE_ANDROID_PROPERTY);

    /* package */ static String VCARD_TYPE_V21_GENERIC_UTF8_STR = "v21_generic";
@@ -210,7 +231,7 @@ public class VCardConfig {
     * </P>
     */
    public static final int VCARD_TYPE_V30_GENERIC_UTF8 =
        (FLAG_V30 | NAME_ORDER_DEFAULT | FLAG_CHARSET_UTF8 |
        (FLAG_V30 | NAME_ORDER_DEFAULT | FLAG_USE_UTF8_FOR_EXPORT |
                FLAG_USE_DEFACT_PROPERTY | FLAG_USE_ANDROID_PROPERTY);

    /* package */ static final String VCARD_TYPE_V30_GENERIC_UTF8_STR = "v30_generic";
@@ -222,7 +243,7 @@ public class VCardConfig {
     * </P>
     */
    public static final int VCARD_TYPE_V21_EUROPE_UTF8 =
        (FLAG_V21 | NAME_ORDER_EUROPE | FLAG_CHARSET_UTF8 |
        (FLAG_V21 | NAME_ORDER_EUROPE | FLAG_USE_UTF8_FOR_EXPORT |
                FLAG_USE_DEFACT_PROPERTY | FLAG_USE_ANDROID_PROPERTY);
    
    /* package */ static final String VCARD_TYPE_V21_EUROPE_UTF8_STR = "v21_europe";
@@ -236,7 +257,7 @@ public class VCardConfig {
     * </P>
     */
    public static final int VCARD_TYPE_V30_EUROPE_UTF8 =
        (FLAG_V30 | NAME_ORDER_EUROPE | FLAG_CHARSET_UTF8 |
        (FLAG_V30 | NAME_ORDER_EUROPE | FLAG_USE_UTF8_FOR_EXPORT |
                FLAG_USE_DEFACT_PROPERTY | FLAG_USE_ANDROID_PROPERTY);
    
    /* package */ static final String VCARD_TYPE_V30_EUROPE_STR = "v30_europe";
@@ -250,7 +271,7 @@ public class VCardConfig {
     * </P>
     */
    public static final int VCARD_TYPE_V21_JAPANESE_UTF8 =
        (FLAG_V21 | NAME_ORDER_JAPANESE | FLAG_CHARSET_UTF8 |
        (FLAG_V21 | NAME_ORDER_JAPANESE | FLAG_USE_UTF8_FOR_EXPORT |
                FLAG_USE_DEFACT_PROPERTY | FLAG_USE_ANDROID_PROPERTY);

    /* package */ static final String VCARD_TYPE_V21_JAPANESE_UTF8_STR = "v21_japanese_utf8";
@@ -265,7 +286,7 @@ public class VCardConfig {
     * </P>
     */
    public static final int VCARD_TYPE_V21_JAPANESE_SJIS =
        (FLAG_V21 | NAME_ORDER_JAPANESE | FLAG_CHARSET_SHIFT_JIS |
        (FLAG_V21 | NAME_ORDER_JAPANESE | FLAG_USE_SHIFT_JIS_FOR_EXPORT |
                FLAG_USE_DEFACT_PROPERTY | FLAG_USE_ANDROID_PROPERTY);

    /* package */ static final String VCARD_TYPE_V21_JAPANESE_SJIS_STR = "v21_japanese_sjis";
@@ -280,7 +301,7 @@ public class VCardConfig {
     * </P>
     */
    public static final int VCARD_TYPE_V30_JAPANESE_SJIS =
        (FLAG_V30 | NAME_ORDER_JAPANESE | FLAG_CHARSET_SHIFT_JIS |
        (FLAG_V30 | NAME_ORDER_JAPANESE | FLAG_USE_SHIFT_JIS_FOR_EXPORT |
                FLAG_USE_DEFACT_PROPERTY | FLAG_USE_ANDROID_PROPERTY);
        
    /* package */ static final String VCARD_TYPE_V30_JAPANESE_SJIS_STR = "v30_japanese_sjis";
@@ -294,7 +315,7 @@ public class VCardConfig {
     * </P>
     */
    public static final int VCARD_TYPE_V30_JAPANESE_UTF8 =
        (FLAG_V30 | NAME_ORDER_JAPANESE | FLAG_CHARSET_UTF8 |
        (FLAG_V30 | NAME_ORDER_JAPANESE | FLAG_USE_UTF8_FOR_EXPORT |
                FLAG_USE_DEFACT_PROPERTY | FLAG_USE_ANDROID_PROPERTY);

    /* package */ static final String VCARD_TYPE_V30_JAPANESE_UTF8_STR = "v30_japanese_utf8";
@@ -310,7 +331,7 @@ public class VCardConfig {
     * </P>
     */
    public static final int VCARD_TYPE_V21_JAPANESE_MOBILE =
        (FLAG_V21 | NAME_ORDER_JAPANESE | FLAG_CHARSET_SHIFT_JIS |
        (FLAG_V21 | NAME_ORDER_JAPANESE | FLAG_USE_SHIFT_JIS_FOR_EXPORT |
                FLAG_CONVERT_PHONETIC_NAME_STRINGS |
                FLAG_REFRAIN_QP_TO_NAME_PROPERTIES);

@@ -379,12 +400,17 @@ public class VCardConfig {
        return !isV30(vcardType);
    }

    public static boolean usesUtf8(final int vcardType) {
        return ((vcardType & FLAG_CHARSET_MASK) == FLAG_CHARSET_UTF8);
    /* package */ static boolean shouldUseUtf8ForExport(final int vcardType) {
        return ((vcardType & FLAG_CHARSET_MASK_FOR_EKPORT) == FLAG_USE_UTF8_FOR_EXPORT);
    }

    public static boolean usesShiftJis(final int vcardType) {
        return ((vcardType & FLAG_CHARSET_MASK) == FLAG_CHARSET_SHIFT_JIS);
    /**
     * Shift_JIS (a charset for Japanese text files) needs special handling to select
     * carrer specific variants.
     * @hide just for test
     */
    public static boolean shouldUseShiftJisForExport(final int vcardType) {
        return ((vcardType & FLAG_CHARSET_MASK_FOR_EKPORT) == FLAG_USE_SHIFT_JIS_FOR_EXPORT);
    }

    public static int getNameOrderType(final int vcardType) {
+1 −1
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ public class VCardEntryConstructor implements VCardInterpreter {
        if (inputCharset != null) {
            mInputCharset = inputCharset;
        } else {
            mInputCharset = VCardConfig.DEFAULT_CHARSET;
            mInputCharset = VCardConfig.DEFAULT_TEMPORARY_CHARSET;
        }
        if (charsetForDetodedBytes != null) {
            mCharsetForDecodedBytes = charsetForDetodedBytes;
+13 −25

File changed.

Preview size limit exceeded, changes collapsed.

Loading