From eb4a772539491719106cf8b494595ef2a592ae62 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Thu, 18 Sep 2014 00:20:53 -0700 Subject: [PATCH] Bug 816318 - Use Android DownloadManager for scanning downloads. r=mfinkle --- mobile/android/app/mobile.js | 1 + mobile/android/base/AndroidManifest.xml.in | 2 +- mobile/android/base/GeckoAppShell.java | 19 ++++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index b3bc57444934..bfb580d696b9 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -144,6 +144,7 @@ pref("browser.download.manager.openDelay", 0); pref("browser.download.manager.focusWhenStarting", false); pref("browser.download.manager.flashCount", 2); pref("browser.download.manager.displayedHistoryDays", 7); +pref("browser.download.manager.addToRecentDocs", true); /* download helper */ pref("browser.helperApps.deleteTempFileOnExit", false); diff --git a/mobile/android/base/AndroidManifest.xml.in b/mobile/android/base/AndroidManifest.xml.in index 6030334d98cc..f7a8a978dc88 100644 --- a/mobile/android/base/AndroidManifest.xml.in +++ b/mobile/android/base/AndroidManifest.xml.in @@ -40,7 +40,7 @@ - + #ifdef MOZ_WEBSMS_BACKEND diff --git a/mobile/android/base/GeckoAppShell.java b/mobile/android/base/GeckoAppShell.java index 51396327fa25..10e7e32ea0a9 100644 --- a/mobile/android/base/GeckoAppShell.java +++ b/mobile/android/base/GeckoAppShell.java @@ -60,6 +60,7 @@ import org.mozilla.gecko.util.ThreadUtils; import android.app.Activity; import android.app.ActivityManager; +import android.app.DownloadManager; import android.app.PendingIntent; import android.content.ActivityNotFoundException; import android.content.Context; @@ -1796,7 +1797,7 @@ public class GeckoAppShell } @WrapElementForJNI - public static void scanMedia(String aFile, String aMimeType) { + public static void scanMedia(final String aFile, String aMimeType) { // If the platform didn't give us a mimetype, try to guess one from the filename if (TextUtils.isEmpty(aMimeType)) { int extPosition = aFile.lastIndexOf("."); @@ -1805,8 +1806,20 @@ public class GeckoAppShell } } - Context context = getContext(); - GeckoMediaScannerClient.startScan(context, aFile, aMimeType); + final File f = new File(aFile); + if (AppConstants.Versions.feature12Plus) { + final DownloadManager dm = (DownloadManager) getContext().getSystemService(Context.DOWNLOAD_SERVICE); + dm.addCompletedDownload(f.getName(), + f.getName(), + !TextUtils.isEmpty(aMimeType), + aMimeType, + f.getAbsolutePath(), + f.length(), + false); + } else { + Context context = getContext(); + GeckoMediaScannerClient.startScan(context, aFile, aMimeType); + } } @WrapElementForJNI(stubName = "GetIconForExtensionWrapper")