OSDN Git Service

Enable vcard share in OPP
authorLixin Yue <L.X.YUE@motorola.com>
Thu, 17 Dec 2009 08:31:22 +0000 (16:31 +0800)
committerJaikumar Ganesh <jaikumar@google.com>
Tue, 22 Dec 2009 17:50:05 +0000 (09:50 -0800)
Bluetooth OPP to handle x-vcard MIME type from contacts share
Handle vcard size by content type instead of tightening with contacts

AndroidManifest.xml
src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java
src/com/android/bluetooth/opp/Constants.java

index 1b5d30e..cb9d29a 100644 (file)
@@ -41,6 +41,7 @@
                 <data android:mimeType="image/*" />
                 <data android:mimeType="video/*" />
                 <data android:mimeType="audio/*" />
+                <data android:mimeType="text/x-vcard" />
                 <data android:mimeType="text/plain" />
                 <data android:mimeType="text/html" />
                 <data android:mimeType="application/zip" />
@@ -55,6 +56,7 @@
                 <data android:mimeType="image/*" />
                 <data android:mimeType="video/*" />
                 <data android:mimeType="x-mixmedia/*" />
+                <data android:mimeType="text/x-vcard" />
             </intent-filter>
             <intent-filter>
                 <action android:name="android.btopp.intent.action.OPEN" />
index 0ccfe7f..7450456 100644 (file)
 package com.android.bluetooth.opp;
 
 import java.io.File;
+import java.io.IOException;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 
+import android.util.Log;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.database.Cursor;
 import android.net.Uri;
 import android.provider.OpenableColumns;
+import android.provider.ContactsContract.Contacts;
 
 /**
  * This class stores information about a single sending file It will only be
  * used for outbound share.
  */
 public class BluetoothOppSendFileInfo {
+    private static final String TAG = "BluetoothOppSendFileInfo";
+
+    private static final boolean D = Constants.DEBUG;
+
+    private static final boolean V = Constants.VERBOSE;
+
     /** readable media file name */
     public final String mFileName;
 
@@ -98,7 +107,8 @@ public class BluetoothOppSendFileInfo {
         String fileName = null;
         String contentType = null;
         long length = 0;
-        if (scheme.equals("content") && authority.equals("media")) {
+        if (scheme.equals("content") && authority.equals("media")
+                || type.equals(Contacts.CONTENT_VCARD_TYPE)) {
 
             contentType = contentResolver.getType(u);
             Cursor metadataCursor = contentResolver.query(u, new String[] {
@@ -131,6 +141,20 @@ public class BluetoothOppSendFileInfo {
             return new BluetoothOppSendFileInfo(null, null, 0, null,
                     BluetoothShare.STATUS_FILE_ERROR, dest);
         }
+
+        // VCard stream length got from content provider is 0, we can only get
+        // the real value after the real encoding process complete
+        if (type.equals(Contacts.CONTENT_VCARD_TYPE)) {
+            try {
+                length = is.available();
+                if (V) Log.v(TAG, "Contacts file length is " + length);
+            } catch (IOException e) {
+                Log.e(TAG, "Read contacts vcard stream exception: ", e);
+                return new BluetoothOppSendFileInfo(null, null, 0, null,
+                        BluetoothShare.STATUS_FILE_ERROR, dest);
+            }
+        }
+
         return new BluetoothOppSendFileInfo(fileName, contentType, length, is, 0, dest);
     }
 }
index 69b86b1..2356ead 100644 (file)
@@ -94,7 +94,7 @@ public class Constants {
      * TODO: define correct type list
      */
     public static final String[] ACCEPTABLE_SHARE_OUTBOUND_TYPES = new String[] {
-        "image/*",
+        "image/*", "text/x-vcard",
     };
 
     /**
@@ -114,6 +114,7 @@ public class Constants {
         "image/*",
         "video/*",
         "audio/*",
+        "text/x-vcard",
         "text/plain",
         "text/html",
         "application/zip",
@@ -129,7 +130,6 @@ public class Constants {
      */
     public static final String[] UNACCEPTABLE_SHARE_INBOUND_TYPES = new String[] {
         "text/x-vcalendar",
-        "text/x-vcard",
     };
 
     /** Where we store Bluetooth received files on the external storage */