Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20be1992 authored by Michael W's avatar Michael W
Browse files

Gallery: Make sure no NPE happens

Fix for the case when getExternalCacheDir returns null

Change-Id: I15f4a4a37ac44d70d14ac08cd743d3327f91dde1
parent d5e574a6
Loading
Loading
Loading
Loading
+15 −11
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ public class CacheManager {
            BlobCache cache = sCacheMap.get(filename);
            BlobCache cache = sCacheMap.get(filename);
            if (cache == null) {
            if (cache == null) {
                File cacheDir = context.getExternalCacheDir();
                File cacheDir = context.getExternalCacheDir();
                if (cacheDir != null) {
                    String path = cacheDir.getAbsolutePath() + "/" + filename;
                    String path = cacheDir.getAbsolutePath() + "/" + filename;
                    try {
                    try {
                        cache = new BlobCache(path, maxEntries, maxBytes, false,
                        cache = new BlobCache(path, maxEntries, maxBytes, false,
@@ -55,6 +56,7 @@ public class CacheManager {
                        Log.e(TAG, "Cannot instantiate cache!", e);
                        Log.e(TAG, "Cannot instantiate cache!", e);
                    }
                    }
                }
                }
            }
            return cache;
            return cache;
        }
        }
    }
    }
@@ -73,6 +75,7 @@ public class CacheManager {
        pref.edit().putInt(KEY_CACHE_UP_TO_DATE, 1).commit();
        pref.edit().putInt(KEY_CACHE_UP_TO_DATE, 1).commit();


        File cacheDir = context.getExternalCacheDir();
        File cacheDir = context.getExternalCacheDir();
        if (cacheDir != null) {
            String prefix = cacheDir.getAbsolutePath() + "/";
            String prefix = cacheDir.getAbsolutePath() + "/";


            BlobCache.deleteFiles(prefix + "imgcache");
            BlobCache.deleteFiles(prefix + "imgcache");
@@ -80,3 +83,4 @@ public class CacheManager {
            BlobCache.deleteFiles(prefix + "bookmark");
            BlobCache.deleteFiles(prefix + "bookmark");
        }
        }
    }
    }
}