Skip to content

Commit

Permalink
Make sure no NPE happens
Browse files Browse the repository at this point in the history
Fix for the case when getExternalCacheDir returns null

Change-Id: Id57a7cf2bc4a8b50b6e8ce7ddb29974ea497a9c3
  • Loading branch information
BadDaemon authored and usmcamgrimm committed Mar 24, 2018
1 parent 1ccd8e3 commit 510359e
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/com/android/gallery3d/util/CacheManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@ public static BlobCache getCache(Context context, String filename,
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;
Expand All @@ -73,10 +75,12 @@ private static void removeOldFilesIfNecessary(Context context) {
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");
}
}
}

0 comments on commit 510359e

Please sign in to comment.