Allow DownloadProvider to upsert already downloaded file

Sometimes apps request DownloadManager to add existing file to Downloads
collection. In this case, since DownloadProvider can't find a db row
with is_download=1, DownloadProvider will try to insert a db row for
existing file. Upsert fails here because DownloadProvider doesn't own
the db row.

Changed MediaProvider#insertAllowingUpsert to allow DownloadProvider to
upsert a db row if app which requests download owns the existing db row.

Bug: 156971004, 155593247
Test: atest DownloadProviderTests
Test: atest DownloadProviderPermissionTests
Test: atest CtsDownloadManagerApi28
Test: atest CtsAppTestCases:DownloadManagerTest
Test: atest MediaStore_Images_MediaTest#testUpsert
Test: atest --test-mapping packages/providers/MediaProvider
Change-Id: I1c202b55b3f825d66d995d0398ff942fc80d7748
1 file changed