Skip to content

Commit f7984ed

Browse files
committed
Avoiding crash from some users when pasting an image from the clipboard
1 parent 2ff57ba commit f7984ed

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

app/src/main/java/org/thoughtcrime/securesms/util/FilenameUtils.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,18 @@ object FilenameUtils {
9292
val projection = arrayOf(OpenableColumns.DISPLAY_NAME)
9393
val contentRes = context.contentResolver
9494
if (contentRes != null) {
95-
val cursor = contentRes.query(uri, projection, null, null, null)
96-
cursor?.use {
97-
if (it.moveToFirst()) {
98-
val nameIndex = it.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)
99-
extractedFilename = it.getString(nameIndex)
95+
try {
96+
val cursor = contentRes.query(uri, projection, null, null, null)
97+
cursor?.use {
98+
if (it.moveToFirst()) {
99+
val nameIndex = it.getColumnIndex(OpenableColumns.DISPLAY_NAME)
100+
if (nameIndex != -1) {
101+
extractedFilename = it.getString(nameIndex)
102+
}
103+
}
100104
}
105+
} catch (e: Exception) {
106+
Log.w(TAG, "Unable to query display name for uri: $uri", e)
101107
}
102108
}
103109
}

0 commit comments

Comments
 (0)