Bug 723295 - Prevent startup crash on devices with API level >= 8 and no SD card. r=wesj
☠☠ backed out by e2db006298c2 ☠ ☠
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 06 Feb 2012 19:02:50 -0500
changeset 89151 a8a93012f4745e9897dd7cacf1a6a09bce22c83e
parent 89150 c0e5acc9b04495830b48d0cd0d7bd67735a22888
child 89152 0c9c30297fadc3e78ac22af3bd25005c46f57d95
push idunknown
push userunknown
push dateunknown
reviewerswesj
bugs723295
milestone13.0a1
Bug 723295 - Prevent startup crash on devices with API level >= 8 and no SD card. r=wesj
mobile/android/base/GeckoDirProvider.java
--- a/mobile/android/base/GeckoDirProvider.java
+++ b/mobile/android/base/GeckoDirProvider.java
@@ -132,17 +132,17 @@ abstract public class GeckoDirProvider
             throws IOException, IllegalArgumentException {
         if (aContext == null)
             throw new IllegalArgumentException("Must provide a valid context");
         File filesDir = GeckoDirProvider.getFilesDir(aContext);
 
         File mozDir = new File(filesDir, "mozilla");
         if (!mozDir.exists()) {
             if (!mozDir.mkdir())
-                throw new IOException("Unable to create mozilla directory at " + mozDir.getPath());
+                throw new IOException("Unable to create mozilla directory at " + mozDir.getAbsolutePath());
         }
         return mozDir;
     }
 
     static final char kTable[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
                                    'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
                                    '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
 
@@ -200,16 +200,19 @@ abstract public class GeckoDirProvider
         salt.append(".");
         return salt.append(aName).toString();
     }
 
     public static File getFilesDir(final Context aContext) {
         if (aContext == null)
             throw new IllegalArgumentException("Must provide a valid context");
 
-        if (Build.VERSION.SDK_INT < 8 ||
-            aContext.getPackageResourcePath().startsWith("/data") ||
-            aContext.getPackageResourcePath().startsWith("/system")) {
+        if (Build.VERSION.SDK_INT < 8)
             return aContext.getFilesDir();
-        }
-        return aContext.getExternalFilesDir(null);
+
+        String resourcePath = aContext.getPackageResourcePath();
+        File externalDir = aContext.getExternalFilesDir(null);
+        if (resourcePath.startsWith("/data") || resourcePath.startsWith("/system") || externalDir == null)
+            return aContext.getFilesDir();
+
+        return externalDir;
     }
 }