diff --git a/embedding/android/GeckoApp.java b/embedding/android/GeckoApp.java index 17d0009b4987..6bbe1de7dd43 100644 --- a/embedding/android/GeckoApp.java +++ b/embedding/android/GeckoApp.java @@ -425,10 +425,16 @@ abstract public class GeckoApp Log.i("GeckoAppJava", "Checking for an update"); int statusCode = 8; // UNEXPECTED_ERROR + File downloadDir = null; + if (Build.VERSION.SDK_INT >= 8) + downloadDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); + else + downloadDir = new File(Environment.getExternalStorageDirectory().getPath(), "download"); - String updateDir = Environment.getExternalStorageDirectory().getPath() + "/downloads/updates/0/"; - File updateFile = new File(updateDir + "update.apk"); - File statusFile = new File(updateDir + "update.status"); + File updateDir = new File(new File(downloadDir, "updates"),"0"); + + File updateFile = new File(updateDir, "update.apk"); + File statusFile = new File(updateDir, "update.status"); if (!statusFile.exists() || !readUpdateStatus(statusFile).equals("pending")) return; diff --git a/embedding/android/GeckoAppShell.java b/embedding/android/GeckoAppShell.java index e3e2b7382de3..e23cb92439a6 100644 --- a/embedding/android/GeckoAppShell.java +++ b/embedding/android/GeckoAppShell.java @@ -118,8 +118,13 @@ class GeckoAppShell GeckoAppShell.putenv("TMPDIR=" + f.getPath()); f = Environment.getDownloadCacheDirectory(); - GeckoAppShell.putenv("EXTERNAL_STORAGE" + f.getPath()); - + GeckoAppShell.putenv("EXTERNAL_STORAGE=" + f.getPath()); + File downloadDir = null; + if (Build.VERSION.SDK_INT >= 8) + downloadDir = GeckoApp.mAppContext.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); + else + downloadDir = new File(Environment.getExternalStorageDirectory().getPath(), "download"); + GeckoAppShell.putenv("DOWNLOADS_DIRECTORY=" + downloadDir.getPath()); GeckoAppShell.putenv("LANG=" + Locale.getDefault().toString()); loadLibs(apkName); diff --git a/toolkit/components/downloads/src/nsDownloadManager.cpp b/toolkit/components/downloads/src/nsDownloadManager.cpp index f72fdcbdcfee..48dc63177811 100644 --- a/toolkit/components/downloads/src/nsDownloadManager.cpp +++ b/toolkit/components/downloads/src/nsDownloadManager.cpp @@ -1183,13 +1183,11 @@ nsDownloadManager::GetDefaultDownloadsDirectory(nsILocalFile **aResult) #elif defined(ANDROID) // Android doesn't have a $HOME directory, and by default we only have // write access to /data/data/org.mozilla.{$APP} and /sdcard - char* sdcard = getenv("EXTERNAL_STORAGE"); - if (sdcard) { - rv = NS_NewNativeLocalFile(nsDependentCString(sdcard), + char* downloadDirPath = getenv("DOWNLOADS_DIRECTORY"); + if (downloadDirPath) { + rv = NS_NewNativeLocalFile(nsDependentCString(downloadDirPath), PR_TRUE, getter_AddRefs(downloadDir)); NS_ENSURE_SUCCESS(rv, rv); - rv = downloadDir->Append(NS_LITERAL_STRING("downloads")); - NS_ENSURE_SUCCESS(rv, rv); } else { rv = NS_ERROR_FAILURE; diff --git a/uriloader/exthandler/nsExternalHelperAppService.cpp b/uriloader/exthandler/nsExternalHelperAppService.cpp index 41dfcbd9ec30..7ff51cf26e77 100644 --- a/uriloader/exthandler/nsExternalHelperAppService.cpp +++ b/uriloader/exthandler/nsExternalHelperAppService.cpp @@ -468,16 +468,14 @@ static nsresult GetDownloadDirectory(nsIFile **_directory) // system, and don't save downloads to temp directories // On Android we only return something if we have and SD-card - char* sdcard = getenv("EXTERNAL_STORAGE"); + char* downloadDir = getenv("DOWNLOADS_DIRECTORY"); nsresult rv; - if (sdcard) { + if (downloadDir) { nsCOMPtr ldir; - rv = NS_NewNativeLocalFile(nsDependentCString(sdcard), + rv = NS_NewNativeLocalFile(nsDependentCString(downloadDir), PR_TRUE, getter_AddRefs(ldir)); NS_ENSURE_SUCCESS(rv, rv); - rv = ldir->Append(NS_LITERAL_STRING("downloads")); - NS_ENSURE_SUCCESS(rv, rv); - dir = ldir; + dir = do_QueryInterface(ldir); } else { return NS_ERROR_FAILURE;