Explicitly send ICS files in UTF-8.

- In memory attachments are now stored as byte[], not String.
  We can store any type of contents now.
- Added blob content_bytes to the Attachment table.
  The content field is now deprecated and not used.
- Explicitly convert ICS files to UTF-8.

- Added Utility.to/fromUtf8().

Bug 2509287
Change-Id: I3785a365a9a34039ec12ba82bd857dcdbc4de92d
diff --git a/src/com/android/exchange/utility/CalendarUtilities.java b/src/com/android/exchange/utility/CalendarUtilities.java
index 8b27eae..db1a2b9 100644
--- a/src/com/android/exchange/utility/CalendarUtilities.java
+++ b/src/com/android/exchange/utility/CalendarUtilities.java
@@ -18,6 +18,7 @@
 
 import com.android.email.Email;
 import com.android.email.R;
+import com.android.email.Utility;
 import com.android.email.mail.Address;
 import com.android.email.provider.EmailContent;
 import com.android.email.provider.EmailContent.Account;
@@ -1458,10 +1459,13 @@
 
             // Create the ics attachment using the "content" field
             Attachment att = new Attachment();
-            att.mContent = ics.toString();
+
+            // TODO UTF-8 conversion should be done in SimpleIcsWriter, as it should count line
+            // length for folding in bytes in UTF-8.
+            att.mContentBytes = Utility.toUtf8(ics.toString());
             att.mMimeType = "text/calendar; method=" + method;
             att.mFileName = "invite.ics";
-            att.mSize = att.mContent.length();
+            att.mSize = att.mContentBytes.length;
             // We don't send content-disposition with this attachment
             att.mFlags = Attachment.FLAG_SUPPRESS_DISPOSITION;
 
diff --git a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
index a558a3b..b766800 100644
--- a/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
+++ b/tests/src/com/android/exchange/utility/CalendarUtilitiesTests.java
@@ -18,6 +18,7 @@
 
 import com.android.email.R;
 import com.android.email.Utility;
+import com.android.email.TestUtils;
 import com.android.email.mail.Address;
 import com.android.email.provider.EmailContent.Account;
 import com.android.email.provider.EmailContent.Attachment;
@@ -231,7 +232,8 @@
         assertEquals(Attachment.FLAG_SUPPRESS_DISPOSITION,
                 att.mFlags & Attachment.FLAG_SUPPRESS_DISPOSITION);
         assertEquals("text/calendar; method=REPLY", att.mMimeType);
-        assertNotNull(att.mContent);
+        assertNotNull(att.mContentBytes);
+        assertEquals(att.mSize, att.mContentBytes.length);
 
         //TODO Check the contents of the attachment using an iCalendar parser
     }
@@ -271,10 +273,11 @@
         assertEquals(Attachment.FLAG_SUPPRESS_DISPOSITION,
                 att.mFlags & Attachment.FLAG_SUPPRESS_DISPOSITION);
         assertEquals("text/calendar; method=REQUEST", att.mMimeType);
-        assertNotNull(att.mContent);
+        assertNotNull(att.mContentBytes);
+        assertEquals(att.mSize, att.mContentBytes.length);
 
         // We'll check the contents of the ics file here
-        BlockHash vcalendar = parseIcsContent(att.mContent);
+        BlockHash vcalendar = parseIcsContent(att.mContentBytes);
         assertNotNull(vcalendar);
 
         // We should have a VCALENDAR with a REQUEST method
@@ -338,10 +341,10 @@
         assertEquals(Attachment.FLAG_SUPPRESS_DISPOSITION,
                 att.mFlags & Attachment.FLAG_SUPPRESS_DISPOSITION);
         assertEquals("text/calendar; method=REQUEST", att.mMimeType);
-        assertNotNull(att.mContent);
+        assertNotNull(att.mContentBytes);
 
         // We'll check the contents of the ics file here
-        BlockHash vcalendar = parseIcsContent(att.mContent);
+        BlockHash vcalendar = parseIcsContent(att.mContentBytes);
         assertNotNull(vcalendar);
 
         // We should have a VCALENDAR with a REQUEST method
@@ -537,8 +540,8 @@
         }
     }
 
-    private BlockHash parseIcsContent(String s) throws IOException {
-        BufferedReader reader = new BufferedReader(new StringReader(s));
+    private BlockHash parseIcsContent(byte[] bytes) throws IOException {
+        BufferedReader reader = new BufferedReader(new StringReader(TestUtils.fromUtf8(bytes)));
         String line = reader.readLine();
         if (!line.equals("BEGIN:VCALENDAR")) {
             throw new IllegalArgumentException();