Make vCard importer code use Account information if possible.

Internal isssue: 2116216, 2102720
diff --git a/core/java/android/pim/vcard/ContactStruct.java b/core/java/android/pim/vcard/ContactStruct.java
index 0064bf2..06b0636 100644
--- a/core/java/android/pim/vcard/ContactStruct.java
+++ b/core/java/android/pim/vcard/ContactStruct.java
@@ -15,6 +15,7 @@
  */
 package android.pim.vcard;
 
+import android.accounts.Account;
 import android.content.ContentProviderOperation;
 import android.content.ContentResolver;
 import android.content.ContentValues;
@@ -416,7 +417,8 @@
     private List<String> mWebsiteList;
     
     private final int mVCardType;
-    
+    private final Account mAccount;
+
     // Each Column of four properties has ISPRIMARY field
     // (See android.provider.Contacts)
     // If false even after the parsing loop, we choose the first entry as a "primary"
@@ -429,9 +431,14 @@
     public ContactStruct() {
         this(VCardConfig.VCARD_TYPE_V21_GENERIC);
     }
-    
+
     public ContactStruct(int vcardType) {
+        this(vcardType, null);
+    }
+
+    public ContactStruct(int vcardType, Account account) {
         mVCardType = vcardType;
+        mAccount = account;
     }
 
     /**
@@ -1021,7 +1028,12 @@
             new ArrayList<ContentProviderOperation>();  
         ContentProviderOperation.Builder builder =
             ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
-        builder.withValues(new ContentValues());
+        if (mAccount != null) {
+            builder.withValue(RawContacts.ACCOUNT_NAME, mAccount.name);
+            builder.withValue(RawContacts.ACCOUNT_TYPE, mAccount.type);
+        } else {
+            builder.withValues(new ContentValues());
+        }
         operationList.add(builder.build());
 
         {
@@ -1183,7 +1195,7 @@
             builder.withValue(Miscellaneous.BIRTHDAY, mBirthday);
             operationList.add(builder.build());
         }
-        
+
         try {
             resolver.applyBatch(ContactsContract.AUTHORITY, operationList);
         } catch (RemoteException e) {
diff --git a/core/java/android/pim/vcard/VCardDataBuilder.java b/core/java/android/pim/vcard/VCardDataBuilder.java
index fd165e9..d2026d0 100644
--- a/core/java/android/pim/vcard/VCardDataBuilder.java
+++ b/core/java/android/pim/vcard/VCardDataBuilder.java
@@ -15,6 +15,7 @@
  */
 package android.pim.vcard;
 
+import android.accounts.Account;
 import android.util.CharsetUtils;
 import android.util.Log;
 
@@ -59,7 +60,8 @@
     private String mTargetCharset;
     private boolean mStrictLineBreakParsing;
     
-    private int mVCardType;
+    final private int mVCardType;
+    final private Account mAccount;
     
     // Just for testing.
     private long mTimePushIntoContentResolver;
@@ -67,21 +69,22 @@
     private List<EntryHandler> mEntryHandlers = new ArrayList<EntryHandler>();
     
     public VCardDataBuilder() {
-        this(null, null, false, VCardConfig.VCARD_TYPE_V21_GENERIC);
+        this(null, null, false, VCardConfig.VCARD_TYPE_V21_GENERIC, null);
     }
 
     /**
      * @hide 
      */
     public VCardDataBuilder(int vcardType) {
-        this(null, null, false, vcardType);
+        this(null, null, false, vcardType, null);
     }
 
     /**
      * @hide 
      */
-    public VCardDataBuilder(String charset, boolean strictLineBreakParsing, int vcardType) {
-        this(null, charset, strictLineBreakParsing, vcardType);
+    public VCardDataBuilder(String charset,
+            boolean strictLineBreakParsing, int vcardType, Account account) {
+        this(null, charset, strictLineBreakParsing, vcardType, account);
     }
     
     /**
@@ -90,7 +93,8 @@
     public VCardDataBuilder(String sourceCharset,
             String targetCharset,
             boolean strictLineBreakParsing,
-            int vcardType) {
+            int vcardType,
+            Account account) {
         if (sourceCharset != null) {
             mSourceCharset = sourceCharset;
         } else {
@@ -103,6 +107,7 @@
         }
         mStrictLineBreakParsing = strictLineBreakParsing;
         mVCardType = vcardType;
+        mAccount = account;
     }
     
     public void addEntryHandler(EntryHandler entryHandler) {
@@ -136,7 +141,7 @@
             Log.e(LOG_TAG, "This is not VCARD!");
         }
 
-        mCurrentContactStruct = new ContactStruct(mVCardType);
+        mCurrentContactStruct = new ContactStruct(mVCardType, mAccount);
     }
 
     public void endRecord() {