From 20be19923f218494ff42f7c300a74855f61495e9 Mon Sep 17 00:00:00 2001 From: Michael W Date: Sat, 4 Jun 2016 16:10:05 +0200 Subject: Gallery: Make sure no NPE happens Fix for the case when getExternalCacheDir returns null Change-Id: I15f4a4a37ac44d70d14ac08cd743d3327f91dde1 --- src/com/android/gallery3d/util/CacheManager.java | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/com/android/gallery3d/util/CacheManager.java b/src/com/android/gallery3d/util/CacheManager.java index ba466f79b..0e8f3e7d3 100644 --- a/src/com/android/gallery3d/util/CacheManager.java +++ b/src/com/android/gallery3d/util/CacheManager.java @@ -46,13 +46,15 @@ public class CacheManager { BlobCache cache = sCacheMap.get(filename); if (cache == null) { File cacheDir = context.getExternalCacheDir(); - String path = cacheDir.getAbsolutePath() + "/" + filename; - try { - cache = new BlobCache(path, maxEntries, maxBytes, false, - version); - sCacheMap.put(filename, cache); - } catch (IOException e) { - Log.e(TAG, "Cannot instantiate cache!", e); + if (cacheDir != null) { + String path = cacheDir.getAbsolutePath() + "/" + filename; + try { + cache = new BlobCache(path, maxEntries, maxBytes, false, + version); + sCacheMap.put(filename, cache); + } catch (IOException e) { + Log.e(TAG, "Cannot instantiate cache!", e); + } } } return cache; @@ -73,10 +75,12 @@ public class CacheManager { pref.edit().putInt(KEY_CACHE_UP_TO_DATE, 1).commit(); File cacheDir = context.getExternalCacheDir(); - String prefix = cacheDir.getAbsolutePath() + "/"; + if (cacheDir != null) { + String prefix = cacheDir.getAbsolutePath() + "/"; - BlobCache.deleteFiles(prefix + "imgcache"); - BlobCache.deleteFiles(prefix + "rev_geocoding"); - BlobCache.deleteFiles(prefix + "bookmark"); + BlobCache.deleteFiles(prefix + "imgcache"); + BlobCache.deleteFiles(prefix + "rev_geocoding"); + BlobCache.deleteFiles(prefix + "bookmark"); + } } } -- cgit v1.2.3