FileBackend: close cursor after retrieving file size

This commit is contained in:
Daniel Gultsch 2017-09-30 15:50:01 +02:00
parent 56eb49d8cc
commit bbfabaf930
1 changed files with 10 additions and 4 deletions

View File

@ -138,12 +138,18 @@ public class FileBackend {
} }
private static long getFileSize(Context context, Uri uri) { private static long getFileSize(Context context, Uri uri) {
Cursor cursor = context.getContentResolver().query(uri, null, null, null, null); try {
final Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) { if (cursor != null && cursor.moveToFirst()) {
return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE)); long size = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
cursor.close();
return size;
} else { } else {
return -1; return -1;
} }
} catch (Exception e) {
return -1;
}
} }
public static boolean allFilesUnderSize(Context context, List<Uri> uris, long max) { public static boolean allFilesUnderSize(Context context, List<Uri> uris, long max) {