You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
6393: Closesmozilla-mobile#6317: Prevent inserting duplicate record into content resolver r=Amejia481 a=csadilek
OK, this hole was deep :). The cause of this crash is that we were unconditionally inserting into the content resolver which may already have a row / record of the download URI: mozilla-mobile#6317 (comment)
This can happen if a download fails or gets cancelled before we write the file. We will have a unique file name generated based on existing files, but also need to check if we have a record of the file in the resolver. If so, use it, otherwise create a new record.
I've tried for a few hours to write a meaningful test for this, but there are simply too many static methods involved here and the resulting refactoring was terrible: `ContentUris.withAppendedId`, `MediaStore.setIncludePending`, `MediaStore.Downloads.getContentUri` etc. That's properly the reason we don't have an existing test for this method :(
This also makes sure we now won't crash if for some reason there's another problem inserting into the content resolver, but fail the download instead.
Co-authored-by: Christian Sadilek <[email protected]>
Copy file name to clipboardExpand all lines: components/feature/downloads/src/main/java/mozilla/components/feature/downloads/AbstractFetchDownloadService.kt
0 commit comments