Skip to content

Commit

Permalink
Fix file crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
bpellin committed Sep 7, 2022
1 parent aa7661b commit 9582a35
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ public List<String> getDbList() {
String name = UriUtil.getFileName(Uri.parse(fileName), ctx);
if (EmptyUtils.isNullOrEmpty(name)) {
name = fileName;
} else {
name = name + " - " + fileName;
}

displayNames.add(name);
Expand Down
23 changes: 15 additions & 8 deletions app/src/main/java/com/keepassdroid/utils/UriUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,24 @@ public static String getFileName(Uri uri, Context context) {
String result = null;
if (uri != null) {
if (uri.getScheme().equals("content")) {
Cursor cursor = context.getContentResolver().query(uri, null,
null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
int index = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
if (index >= 0) {
result = cursor.getString(index);
Cursor cursor = context.getContentResolver().query(uri, null,
null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
int index = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
if (index >= 0) {
result = cursor.getString(index);
}
}
} finally {
if (cursor != null) {
cursor.close();
}
}
} finally {
cursor.close();
} catch (SecurityException e) {
// Fall through to using path
result = null;
}
}

Expand Down

0 comments on commit 9582a35

Please sign in to comment.