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

Commit c8f08bd1 authored by Lixin Yue's avatar Lixin Yue Committed by Jaikumar Ganesh
Browse files

Enable vcard share in OPP

Bluetooth OPP to handle x-vcard MIME type from contacts share
Handle vcard size by content type instead of tightening with contacts
parent 690f8c30
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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" />
+25 −1
Original line number Diff line number Diff line
@@ -33,20 +33,29 @@
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);
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -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 */