From 58527422f0e48ba6b0cb9aa1b2b14b5d3b9219f7 Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Wed, 1 Jun 2016 19:34:40 +0200 Subject: [PATCH] do not load folder-artwork if the file is saved in Environment.DIRECTORY_DOWNLOADS --- .../android/vanilla/CoverCache.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/CoverCache.java b/src/ch/blinkenlights/android/vanilla/CoverCache.java index 879f766a..5f8e97c5 100644 --- a/src/ch/blinkenlights/android/vanilla/CoverCache.java +++ b/src/ch/blinkenlights/android/vanilla/CoverCache.java @@ -27,6 +27,7 @@ import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.BitmapFactory; import android.net.Uri; +import android.os.Environment; import android.util.Log; import java.io.ByteArrayOutputStream; @@ -72,6 +73,11 @@ public class CoverCache { * Bitmask on how we are going to load coverart */ public static int mCoverLoadMode = 0; + /** + * The public downloads directory of this device + */ + public static final File sDownloadsDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); + /** * Constructs a new BitmapCache object @@ -398,19 +404,24 @@ public class CoverCache { int bestMatchIndex = COVER_MATCHES.length; // The best cover-index/priority found int loopCount = 0; // Directory items loop counter - for (final File entry : baseFile.getParentFile().listFiles()) { - for (int i=0; i < bestMatchIndex ; i++) { - // We are checking each file entry to see if it matches a known - // cover pattern. We abort on first hit as the Pattern array is sorted from good->meh - if (COVER_MATCHES[i].matcher(entry.toString()).matches()) { - bestMatchIndex = i; - bestMatchPath = entry.toString(); - break; + // Only start search if the base directory of this file is NOT the public + // downloads folder: Picking files from there would lead to a false positive + // in most cases + if (baseFile.getParentFile().equals(sDownloadsDir) == false) { + for (final File entry : baseFile.getParentFile().listFiles()) { + for (int i=0; i < bestMatchIndex ; i++) { + // We are checking each file entry to see if it matches a known + // cover pattern. We abort on first hit as the Pattern array is sorted from good->meh + if (COVER_MATCHES[i].matcher(entry.toString()).matches()) { + bestMatchIndex = i; + bestMatchPath = entry.toString(); + break; + } } + // Stop loop if we found the best match or if we looped 50 times + if (loopCount++ > 50 || bestMatchIndex == 0) + break; } - // Stop loop if we found the best match or if we looped 50 times - if (loopCount++ > 50 || bestMatchIndex == 0) - break; } if (bestMatchPath != null) {