Insert downloaded file to MediaStore db only after Download is complete

While inserting a MediaStore db row for incomplete files, apps should
set IS_PENDING=1 and use RELATIVE_PATH and DISPLAY_NAME in insert
operation. As DownloadProvider uses DATA column to insert the db row
to MediaStore db, IS_PENDING will not be respected by MediaStore.
Inserting a db row without IS_PENDING=1 makes other apps consider the
file as published. So to solve this, DownloadProvider should insert the
db row only when download is complete.

Changed DownloadProvider#update method to insert/update MediaStore db
row only when download is complete. We can't allow DownloadProvider to
update the existing db row before download is complete because this
will overwrite IS_PENDING set by FUSE.

Bug: 156971004, 157171910
Test: atest DownloadProviderTests
Test: atest DownloadProviderPermissionTests
Test: atest CtsDownloadManagerApi28
Test: atest CtsAppTestCases:DownloadManagerTest
Change-Id: Ieefffb575606b836fbee5767064d72748e4bba27
1 file changed