Trigger mediascan after a download is completed.

When a media item is inserted, media_type will be
automatically updated but some of the other media
attributes will only be updated after a media scan.

Bug: 138419471
Test: manual
Test: atest DownloadProviderTests
Test: atest cts/tests/app/src/android/app/cts/DownloadManagerTest.java
Test: atest cts/tests/app/DownloadManagerLegacyTest/src/android/app/cts/DownloadManagerLegacyTest.java
Test: atest cts/tests/app/DownloadManagerApi28Test/src/android/app/cts/DownloadManagerApi28Test.java
Change-Id: If8192b31fb7da37425480e7afa53dd1304533b76
(cherry picked from commit 90de12ad0c76fa9e231b3864c4afb8f312b53dda)
diff --git a/src/com/android/providers/downloads/DownloadProvider.java b/src/com/android/providers/downloads/DownloadProvider.java
index 550c8fb..eb0313c 100644
--- a/src/com/android/providers/downloads/DownloadProvider.java
+++ b/src/com/android/providers/downloads/DownloadProvider.java
@@ -851,6 +851,8 @@
                             mediaStoreUri.toString());
                     filteredValues.put(COLUMN_MEDIA_SCANNED, MEDIA_SCANNED);
                 }
+                MediaStore.scanFile(getContext(),
+                        new File(filteredValues.getAsString(Downloads.Impl._DATA)));
             } finally {
                 restoreCallingIdentity(token);
             }
@@ -1551,6 +1553,9 @@
                                 qb.update(db, updateValues, Downloads.Impl._ID + "=?",
                                         new String[] { Long.toString(info.mId) });
                             }
+                            if (Downloads.Impl.isStatusSuccess(info.mStatus)) {
+                                MediaStore.scanFile(getContext(), new File(info.mFileName));
+                            }
                         }
                         if (updateSchedule) {
                             Helpers.scheduleJob(context, info);
diff --git a/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java b/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java
index 38bf4d6..6acdfed 100644
--- a/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java
+++ b/tests/src/com/android/providers/downloads/AbstractDownloadProviderFunctionalTest.java
@@ -33,6 +33,7 @@
 import android.database.MatrixCursor;
 import android.net.Uri;
 import android.os.Binder;
+import android.os.Bundle;
 import android.os.IBinder;
 import android.provider.Downloads;
 import android.provider.MediaStore;
@@ -123,6 +124,11 @@
         }
 
         @Override
+        public Bundle call(String method, String request, Bundle args) {
+          return new Bundle();
+        }
+
+        @Override
         public IBinder getIContentProviderBinder() {
             return new Binder();
         }