Merge #6393
6393: Closes #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: https://github.com/mozilla-mobile/android-components/issues/6317#issuecomment-601119812 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 <christian.sadilek@gmail.com>
Please register or sign in to comment