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

Commit 76ad10a1 authored by Jake Hamby's avatar Jake Hamby
Browse files

Fix crash in Bluetooth when sharing MMS video.

Some content providers, such as MMS, don't support the DISPLAY_NAME
or SIZE columns for content URIs. Fall back to using the last segment
of the URI as the filename for Bluetooth file transfers if the query
for DISPLAY_NAME fails.

Bug: 7343310
Change-Id: Ie048c5eea3ba9994259c9e07beabd72622d6b669
parent 9667aaed
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.database.Cursor;
import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.provider.OpenableColumns;
import android.util.Log;
@@ -108,9 +109,15 @@ public class BluetoothOppSendFileInfo {
        // bluetooth
        if ("content".equals(scheme)) {
            contentType = contentResolver.getType(uri);
            Cursor metadataCursor = contentResolver.query(uri, new String[] {
            Cursor metadataCursor;
            try {
                metadataCursor = contentResolver.query(uri, new String[] {
                        OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE
                }, null, null, null);
            } catch (SQLiteException e) {
                // some content providers don't support the DISPLAY_NAME or SIZE columns
                metadataCursor = null;
            }
            if (metadataCursor != null) {
                try {
                    if (metadataCursor.moveToFirst()) {
@@ -122,6 +129,10 @@ public class BluetoothOppSendFileInfo {
                    metadataCursor.close();
                }
            }
            if (fileName == null) {
                // use last segment of URI if DISPLAY_NAME query fails
                fileName = uri.getLastPathSegment();
            }
        } else if ("file".equals(scheme)) {
            fileName = uri.getLastPathSegment();
            contentType = type;