OPP: Handle abnormal behaviour while sharing file from Snapchat

Use case:
1. Take a pic in Snapchat
2. share this picture via BT

Expected Result:
Photo can be shared successfully via BT to remote device

Root Cause:
Android Content Resolver not able to find name column from
received URI of external app.

Fix:
Add extra check while fetching name value from provider,
to prevent cursor exception and make file transfer successful.

Test: No crash observed while sharing file from Snapchat

Fixes: 77167222
Change-Id: I26c6543a4276fd18496ec5479a99eda52dd403b5
(cherry picked from commit 826d86c34938a899f4d3af4f31c02ec306aafcf3)
diff --git a/android/app/src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java b/android/app/src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java
index bfa5337..6d7fe95 100644
--- a/android/app/src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java
+++ b/android/app/src/com/android/bluetooth/opp/BluetoothOppSendFileInfo.java
@@ -127,10 +127,14 @@
             if (metadataCursor != null) {
                 try {
                     if (metadataCursor.moveToFirst()) {
-                        fileName = metadataCursor.getString(
-                                metadataCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
-                        length = metadataCursor.getLong(
-                                metadataCursor.getColumnIndex(OpenableColumns.SIZE));
+                        int indexName = metadataCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
+                        int indexSize = metadataCursor.getColumnIndex(OpenableColumns.SIZE);
+                        if (indexName != -1) {
+                            fileName = metadataCursor.getString(indexName);
+                        }
+                        if (indexSize != -1) {
+                            length = metadataCursor.getLong(indexSize);
+                        }
                         if (D) {
                             Log.d(TAG, "fileName = " + fileName + " length = " + length);
                         }
@@ -142,6 +146,7 @@
             if (fileName == null) {
                 // use last segment of URI if DISPLAY_NAME query fails
                 fileName = uri.getLastPathSegment();
+                if (D) Log.d(TAG, "fileName from URI :" + fileName);
             }
         } else if ("file".equals(scheme)) {
             if (uri.getPath() == null) {