From 1ef4c6b7fdbc6e36c030e4a6fab3a8ccf8ba524b Mon Sep 17 00:00:00 2001 From: Mark Wei Date: Wed, 22 Jan 2014 18:30:18 -0800 Subject: Check if input stream is null first before blocking. This allows us to detect null cases without filling up the Executor queue. Bug: 11789572 Change-Id: Icef2f8da1239fdd8db9d74480a147081a15456bc --- src/com/android/bitmap/DecodeTask.java | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/com') diff --git a/src/com/android/bitmap/DecodeTask.java b/src/com/android/bitmap/DecodeTask.java index e227446..ac08c0b 100644 --- a/src/com/android/bitmap/DecodeTask.java +++ b/src/com/android/bitmap/DecodeTask.java @@ -120,20 +120,8 @@ public class DecodeTask extends AsyncTask { ReusableBitmap result = null; ParcelFileDescriptor fd = null; InputStream in = null; - try { - final boolean isJellyBeanOrAbove = android.os.Build.VERSION.SDK_INT - >= android.os.Build.VERSION_CODES.JELLY_BEAN; - // This blocks during fling when the pool is empty. We block early to avoid jank. - if (isJellyBeanOrAbove) { - Trace.beginSection("poll for reusable bitmap"); - mInBitmap = mCache.poll(); - Trace.endSection(); - - if (isCancelled()) { - return null; - } - } + try { if (mFactory != null) { Trace.beginSection("create fd"); fd = mFactory.createFileDescriptor(); @@ -143,6 +131,18 @@ public class DecodeTask extends AsyncTask { if (in == null) { return null; } + if (isCancelled()) { + return null; + } + } + + final boolean isJellyBeanOrAbove = android.os.Build.VERSION.SDK_INT + >= android.os.Build.VERSION_CODES.JELLY_BEAN; + // This blocks during fling when the pool is empty. We block early to avoid jank. + if (isJellyBeanOrAbove) { + Trace.beginSection("poll for reusable bitmap"); + mInBitmap = mCache.poll(); + Trace.endSection(); } if (isCancelled()) { -- cgit v1.2.3