Skip to content

Commit 37cdc33

Browse files
authored
Merge pull request #14 from ItzNotABug/fix-accessor-crash
Fix init crash if the underlying uri is no longer available or valid
2 parents ad35e99 + 230be0d commit 37cdc33

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

dfc/src/main/java/com/lazygeniouz/dfc/resolver/ResolverCompat.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,20 @@ internal object ResolverCompat {
150150
* Get [Cursor] from [ContentResolver.query] with given [projection] on a given [uri].
151151
*/
152152
fun getCursor(context: Context, uri: Uri, projection: Array<String>): Cursor? {
153-
return context.contentResolver.query(
154-
uri, projection, null, null, null
155-
)
153+
return try {
154+
context.contentResolver.query(
155+
uri, projection, null, null, null
156+
)
157+
} catch (exception: Exception) {
158+
/**
159+
* This exception can occur in scenarios such as -
160+
*
161+
* - The Uri became invalid due to external changes (e.g., permissions revoked, storage unmounted, etc).
162+
* - The file or directory represented by this Uri was probably deleted or became `inaccessible` after the Uri was obtained but before this operation was performed.
163+
*/
164+
ErrorLogger.logError("Exception while building the Cursor", exception)
165+
null
166+
}
156167
}
157168

158169
// Make children uri for query.

0 commit comments

Comments
 (0)