diff options
author | Mark Wei <markwei@google.com> | 2014-01-22 18:30:18 -0800 |
---|---|---|
committer | Mark Wei <markwei@google.com> | 2014-01-22 18:30:18 -0800 |
commit | 1ef4c6b7fdbc6e36c030e4a6fab3a8ccf8ba524b (patch) | |
tree | 117082383e5e19ec5b5b58d1969aa0f24ccecb51 /src | |
parent | 8aa2d8601f6a97af4a329cfc3bfd5fb5fb5bcbf8 (diff) | |
download | bitmap-1ef4c6b7fdbc6e36c030e4a6fab3a8ccf8ba524b.tar.gz |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/bitmap/DecodeTask.java | 26 |
1 files changed, 13 insertions, 13 deletions
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<Void, Void, ReusableBitmap> { 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<Void, Void, ReusableBitmap> { 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()) { |