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
--- 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);