summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael W <baddaemon87@gmail.com>2016-06-04 14:10:05 (GMT)
committerMichael W <baddaemon87@gmail.com>2016-06-04 14:10:05 (GMT)
commit20be19923f218494ff42f7c300a74855f61495e9 (patch)
tree2085fc0380beb2a7878da24e1721325f77c41d99
parentd5e574a606fbccec88c32e43c4e0d216b597d1c1 (diff)
downloadandroid_packages_apps_Gallery2-20be19923f218494ff42f7c300a74855f61495e9.zip
android_packages_apps_Gallery2-20be19923f218494ff42f7c300a74855f61495e9.tar.gz
android_packages_apps_Gallery2-20be19923f218494ff42f7c300a74855f61495e9.tar.bz2
Gallery: Make sure no NPE happens
Fix for the case when getExternalCacheDir returns null Change-Id: I15f4a4a37ac44d70d14ac08cd743d3327f91dde1
-rw-r--r--src/com/android/gallery3d/util/CacheManager.java26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/com/android/gallery3d/util/CacheManager.java b/src/com/android/gallery3d/util/CacheManager.java
index ba466f7..0e8f3e7 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");
+ }
}
}