Bug 1332562 - OMA Downloads should go to the system Download directory. r=snorp
authorMichael Kaply <mozilla@kaply.com>
Thu, 23 Feb 2017 12:27:43 -0600
changeset 373653 564e1f5f214523adc78b1f5ee5a94428c8696343
parent 373652 d5bc4f182ec309b2d9577b5d7a0414d9d4ed7c0b
child 373654 391047948db40495f68c43421bb7263d10680b97
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1332562
milestone54.0a1
Bug 1332562 - OMA Downloads should go to the system Download directory. r=snorp MozReview-Commit-ID: 48fGzGYBoS6
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/components/HelperAppDialog.js
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -2065,18 +2065,18 @@ public class BrowserApp extends GeckoApp
                 final String uri = message.getString("uri");
                 final String filename = message.getString("filename");
                 final String mimeType = message.getString("mimeType");
 
                 final DownloadManager.Request request = new DownloadManager.Request(Uri.parse(uri));
                 request.setMimeType(mimeType);
 
                 try {
-                    request.setDestinationInExternalFilesDir(
-                            this, Environment.DIRECTORY_DOWNLOADS, filename);
+                    request.setDestinationInExternalPublicDir(
+                            Environment.DIRECTORY_DOWNLOADS, filename);
                 } catch (IllegalStateException e) {
                     Log.e(LOGTAG, "Cannot create download directory");
                     break;
                 }
 
                 request.allowScanningByMediaScanner();
                 request.setNotificationVisibility(
                         DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
--- a/mobile/android/components/HelperAppDialog.js
+++ b/mobile/android/components/HelperAppDialog.js
@@ -132,18 +132,26 @@ HelperAppLauncherDialog.prototype = {
 
   show: function hald_show(aLauncher, aContext, aReason) {
     if (!this._canDownload(aLauncher.source)) {
       this._refuseDownload(aLauncher);
       return;
     }
 
     if (this._shouldForwardToAndroidDownloadManager(aLauncher)) {
-      this._downloadWithAndroidDownloadManager(aLauncher);
-      aLauncher.cancel(Cr.NS_BINDING_ABORTED);
+      Task.spawn(function* () {
+        try {
+          let hasPermission = yield RuntimePermissions.waitForPermissions(RuntimePermissions.WRITE_EXTERNAL_STORAGE);
+          if (hasPermission) {
+            this._downloadWithAndroidDownloadManager(aLauncher);
+            aLauncher.cancel(Cr.NS_BINDING_ABORTED);
+          }
+        } finally {
+        }
+      }.bind(this)).catch(Cu.reportError);
       return;
     }
 
     let bundle = Services.strings.createBundle("chrome://browser/locale/browser.properties");
 
     let defaultHandler = new Object();
     let apps = HelperApps.getAppsForUri(aLauncher.source, {
       mimeType: aLauncher.MIMEInfo.MIMEType,