Bug 1280184 - Use getExternalStorageDirectory() to avoid files being deleted automatically when app is uninstalled in Android 6.0.1 r=sebastian draft
authorNevin Chen <cnevinchen@gmail.com>
Thu, 10 Nov 2016 15:47:30 +0800
changeset 437030 e308a69d1ddce36e916ec9a7b535ef3a028d021f
parent 430694 23f92954349863643543975a05ca8f229dfcbf23
child 536526 2fa1b128f2b10a50d130846042a6fc76a9fa0512
push id35295
push userbmo:cnevinchen@gmail.com
push dateThu, 10 Nov 2016 08:19:18 +0000
reviewerssebastian
bugs1280184
milestone52.0a1
Bug 1280184 - Use getExternalStorageDirectory() to avoid files being deleted automatically when app is uninstalled in Android 6.0.1 r=sebastian MozReview-Commit-ID: JibtpRplO2U
mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
--- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
+++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/mozglue/GeckoLoader.java
@@ -79,23 +79,25 @@ public final class GeckoLoader {
 
         } catch (Exception ex) {
             Log.w(LOGTAG, "Caught exception getting plugin dirs.", ex);
         }
     }
 
     private static void setupDownloadEnvironment(final Context context) {
         try {
-            File downloadDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
+
+            // In Android 6.0.1, files saved with getExternalStoragePublicDirectory() will be automatically deleted when app is uninstalled (bug 1280184)
+            // So we use  getExternalStorageDirectory() instead
+            File downloadDir = new File(Environment.getExternalStorageDirectory().getPath(), "Download");
             File updatesDir  = context.getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
-            if (downloadDir == null) {
-                downloadDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");
-            }
+
             if (updatesDir == null) {
                 updatesDir = downloadDir;
+
             }
             putenv("DOWNLOADS_DIRECTORY=" + downloadDir.getPath());
             putenv("UPDATES_DIRECTORY="   + updatesDir.getPath());
         } catch (Exception e) {
             Log.w(LOGTAG, "No download directory found.", e);
         }
     }
 
@@ -189,17 +191,17 @@ public final class GeckoLoader {
             putenv("MOZ_LINKER_CACHE=" + linkerCache);
         }
 
         // Disable on-demand decompression of the linker on devices where it
         // is known to cause crashes.
         String forced_ondemand = System.getenv("MOZ_LINKER_ONDEMAND");
         if (forced_ondemand == null) {
             if ("HTC".equals(android.os.Build.MANUFACTURER) &&
-                "HTC Vision".equals(android.os.Build.MODEL)) {
+                    "HTC Vision".equals(android.os.Build.MODEL)) {
                 putenv("MOZ_LINKER_ONDEMAND=0");
             }
         }
 
         if (AppConstants.MOZ_LINKER_EXTRACT) {
             putenv("MOZ_LINKER_EXTRACT=1");
             // Ensure that the cache dir is world-writable
             File cacheDir = new File(linkerCache);
@@ -535,17 +537,17 @@ public final class GeckoLoader {
             super(msg);
         }
     }
 
     @JNITarget
     public static void abort(final String msg) {
         final Thread thread = Thread.currentThread();
         final Thread.UncaughtExceptionHandler uncaughtHandler =
-            thread.getUncaughtExceptionHandler();
+                thread.getUncaughtExceptionHandler();
         if (uncaughtHandler != null) {
             uncaughtHandler.uncaughtException(thread, new AbortException(msg));
         }
     }
 
     // These methods are implemented in mozglue/android/nsGeckoUtils.cpp
     private static native void putenv(String map);