diff options
-rwxr-xr-x | src/com/android/gallery3d/app/MoviePlayer.java | 1 | ||||
-rw-r--r-- | src/com/android/gallery3d/data/ImageCacheService.java | 6 | ||||
-rw-r--r-- | src/com/android/gallery3d/util/CacheManager.java | 26 |
3 files changed, 22 insertions, 11 deletions
diff --git a/src/com/android/gallery3d/app/MoviePlayer.java b/src/com/android/gallery3d/app/MoviePlayer.java index 4fea7f156..8bf0d0dbe 100755 --- a/src/com/android/gallery3d/app/MoviePlayer.java +++ b/src/com/android/gallery3d/app/MoviePlayer.java @@ -1703,6 +1703,7 @@ class Bookmarker { BlobCache cache = CacheManager.getCache(mContext, BOOKMARK_CACHE_FILE, BOOKMARK_CACHE_MAX_ENTRIES, BOOKMARK_CACHE_MAX_BYTES, BOOKMARK_CACHE_VERSION); + if (cache == null) return null; byte[] data = cache.lookup(uri.hashCode()); if (data == null) return null; diff --git a/src/com/android/gallery3d/data/ImageCacheService.java b/src/com/android/gallery3d/data/ImageCacheService.java index 129c113a6..861d4b766 100644 --- a/src/com/android/gallery3d/data/ImageCacheService.java +++ b/src/com/android/gallery3d/data/ImageCacheService.java @@ -56,6 +56,8 @@ public class ImageCacheService { * @return true if the image data is found; false if not found. */ public boolean getImageData(Path path, long timeModified, int type, BytesBuffer buffer) { + if (mCache == null) return false; + byte[] key = makeKey(path, timeModified, type); long cacheKey = Utils.crc64Long(key); try { @@ -81,6 +83,8 @@ public class ImageCacheService { } public void putImageData(Path path, long timeModified, int type, byte[] value) { + if (mCache == null) return; + byte[] key = makeKey(path, timeModified, type); long cacheKey = Utils.crc64Long(key); ByteBuffer buffer = ByteBuffer.allocate(key.length + value.length); @@ -99,6 +103,8 @@ public class ImageCacheService { } public void clearImageData(Path path, long timeModified, int type) { + if (mCache == null) return; + byte[] key = makeKey(path, timeModified, type); long cacheKey = Utils.crc64Long(key); if (mCache == null) { 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"); + } } } |