Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a1bb50b9 authored by Michael W's avatar Michael W Committed by LuK1337
Browse files

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
parent b0439635
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -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;
+6 −0
Original line number Diff line number Diff line
@@ -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) {
+15 −11
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public class CacheManager {
            BlobCache cache = sCacheMap.get(filename);
            if (cache == null) {
                File cacheDir = context.getExternalCacheDir();
                if (cacheDir != null) {
                    String path = cacheDir.getAbsolutePath() + "/" + filename;
                    try {
                        cache = new BlobCache(path, maxEntries, maxBytes, false,
@@ -55,6 +56,7 @@ public class CacheManager {
                        Log.e(TAG, "Cannot instantiate cache!", e);
                    }
                }
            }
            return cache;
        }
    }
@@ -73,6 +75,7 @@ public class CacheManager {
        pref.edit().putInt(KEY_CACHE_UP_TO_DATE, 1).commit();

        File cacheDir = context.getExternalCacheDir();
        if (cacheDir != null) {
            String prefix = cacheDir.getAbsolutePath() + "/";

            BlobCache.deleteFiles(prefix + "imgcache");
@@ -80,3 +83,4 @@ public class CacheManager {
            BlobCache.deleteFiles(prefix + "bookmark");
        }
    }
}