diff options
author | Michael W <baddaemon87@gmail.com> | 2016-06-04 16:10:05 +0200 |
---|---|---|
committer | LuK1337 <priv.luk@gmail.com> | 2019-10-21 21:40:56 +0200 |
commit | a1bb50b955439fbe27c5c39c28b762617e58291d (patch) | |
tree | 32ef9b1a183b500046f5c55f32444c184c0fcede | |
parent | b04396354e5b1ec63e29b1d4456fc521502fb49e (diff) | |
download | android_packages_apps_Gallery2-a1bb50b955439fbe27c5c39c28b762617e58291d.tar.gz android_packages_apps_Gallery2-a1bb50b955439fbe27c5c39c28b762617e58291d.tar.bz2 android_packages_apps_Gallery2-a1bb50b955439fbe27c5c39c28b762617e58291d.zip |
Gallery2: Make sure no NPE happens
Author: Michael W <baddaemon87@gmail.com>
Date: Sat Jun 4 16:10:05 2016 +0200
Gallery2: Make sure no NPE happens
Fix for the case when getExternalCacheDir returns null
Change-Id: I15f4a4a37ac44d70d14ac08cd743d3327f91dde1
Author: Michael W <baddaemon87@gmail.com>
Date: Tue Jun 7 21:05:00 2016 +0200
Gallery2: Remove more possible NPEs
getCache can return null ->
check this before proceeding
Change-Id: I834780a4dafbe22f2d345fe5571cb20f3f3e5e2e
Change-Id: I820d8314f855329885f6b7ca710efa981b9d327c
-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"); + } } } |