OSDN Git Service

Apollo: Prevent FC in cache initialization
authorJorge Ruesga <jorge@ruesga.com>
Sat, 31 Aug 2013 19:08:23 +0000 (21:08 +0200)
committerDvTonder <david.vantonder@gmail.com>
Sun, 1 Sep 2013 12:35:55 +0000 (08:35 -0400)
Patchset 2: Remove unnecessary sleep
Patchset 3: Revert original comment

Change-Id: I1594e2001bdfef282d010399e70f1f0066ec4c06
JIRA: CYAN-1996
Issue: https://jira.cyanogenmod.org/browse/CYAN-1996
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
src/com/andrew/apollo/cache/ImageCache.java

index 8472caf..90fd979 100644 (file)
@@ -153,7 +153,7 @@ public final class ImageCache {
      *
      * @param context The {@link Context} to use
      */
-    public void initDiskCache(final Context context) {
+    private synchronized void initDiskCache(final Context context) {
         // Set up disk cache
         if (mDiskCache == null || mDiskCache.isClosed()) {
             File diskCacheDir = getDiskCacheDir(context, TAG);
@@ -625,11 +625,11 @@ public final class ImageCache {
      * @return The cache directory
      */
     public static final File getDiskCacheDir(final Context context, final String uniqueName) {
-        final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment
-                .getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(
-                context).getPath() : context.getCacheDir().getPath();
-
-        return new File(cachePath + File.separator + uniqueName);
+        // getExternalCacheDir(context) returns null if external storage is not ready
+        final String cachePath = getExternalCacheDir(context) != null
+                                    ? getExternalCacheDir(context).getPath()
+                                    : context.getCacheDir().getPath();
+        return new File(cachePath, uniqueName);
     }
 
     /**