don't reuse mOptions across threads.
Bug: 7370134
Change-Id: If6e02c2095f5f70e4dd506e651efbbd5ad47fa07
diff --git a/src/com/android/dreams/phototable/PhotoCarousel.java b/src/com/android/dreams/phototable/PhotoCarousel.java
index 495e73c..70ba046 100644
--- a/src/com/android/dreams/phototable/PhotoCarousel.java
+++ b/src/com/android/dreams/phototable/PhotoCarousel.java
@@ -48,7 +48,6 @@
private final PhotoSourcePlexor mPhotoSource;
private final GestureDetector mGestureDetector;
private final View[] mPanel;
- private final BitmapFactory.Options mOptions;
private final int mFlipDuration;
private final int mDropPeriod;
private final int mBitmapQueueLimit;
@@ -100,8 +99,6 @@
mDropPeriod = resources.getInteger(R.integer.carousel_drop_period);
mBitmapQueueLimit = resources.getInteger(R.integer.num_images_to_preload);
mFlipDuration = resources.getInteger(R.integer.flip_duration);
- mOptions = new BitmapFactory.Options();
- mOptions.inTempStorage = new byte[32768];
mPhotoSource = new PhotoSourcePlexor(getContext(),
getContext().getSharedPreferences(FlipperDreamSettings.PREFS_NAME, 0));
mBitmapStore = new HashMap<View, Bitmap>();
@@ -130,6 +127,13 @@
}
private class PhotoLoadTask extends AsyncTask<Void, Void, Bitmap> {
+ private final BitmapFactory.Options mOptions;
+
+ public PhotoLoadTask () {
+ mOptions = new BitmapFactory.Options();
+ mOptions.inTempStorage = new byte[32768];
+ }
+
@Override
public Bitmap doInBackground(Void... unused) {
Bitmap decodedPhoto;
@@ -180,8 +184,8 @@
if (photo != null) {
ImageView destination = getBackface();
Bitmap old = mBitmapStore.get(destination);
- int width = mOptions.outWidth;
- int height = mOptions.outHeight;
+ int width = photo.getWidth();
+ int height = photo.getHeight();
int orientation = (width > height ? LANDSCAPE : PORTRAIT);
destination.setImageBitmap(photo);
diff --git a/src/com/android/dreams/phototable/PhotoTable.java b/src/com/android/dreams/phototable/PhotoTable.java
index ddf2f58..50212c9 100644
--- a/src/com/android/dreams/phototable/PhotoTable.java
+++ b/src/com/android/dreams/phototable/PhotoTable.java
@@ -85,7 +85,6 @@
private PhotoLaunchTask mPhotoLaunchTask;
private boolean mStarted;
private boolean mIsLandscape;
- private BitmapFactory.Options mOptions;
private int mLongSide;
private int mShortSide;
private int mWidth;
@@ -114,8 +113,6 @@
mDropInterpolator = new DecelerateInterpolator(
(float) mResources.getInteger(R.integer.drop_deceleration_exponent));
mOnTable = new LinkedList<View>();
- mOptions = new BitmapFactory.Options();
- mOptions.inTempStorage = new byte[32768];
mPhotoSource = new PhotoSourcePlexor(getContext(),
getContext().getSharedPreferences(PhotoTableDreamSettings.PREFS_NAME, 0));
mLauncher = new Launcher(this);
@@ -242,6 +239,13 @@
}
private class PhotoLaunchTask extends AsyncTask<Void, Void, View> {
+ private final BitmapFactory.Options mOptions;
+
+ public PhotoLaunchTask () {
+ mOptions = new BitmapFactory.Options();
+ mOptions.inTempStorage = new byte[32768];
+ }
+
@Override
public View doInBackground(Void... unused) {
log("load a new photo");
@@ -252,11 +256,11 @@
View photo = inflater.inflate(R.layout.photo, null);
ImageView image = (ImageView) photo;
Drawable[] layers = new Drawable[2];
- Bitmap decodedPhoto = table.mPhotoSource.next(table.mOptions,
+ Bitmap decodedPhoto = table.mPhotoSource.next(mOptions,
table.mLongSide, table.mShortSide);
- int photoWidth = table.mOptions.outWidth;
- int photoHeight = table.mOptions.outHeight;
- if (table.mOptions.outWidth <= 0 || table.mOptions.outHeight <= 0) {
+ int photoWidth = mOptions.outWidth;
+ int photoHeight = mOptions.outHeight;
+ if (mOptions.outWidth <= 0 || mOptions.outHeight <= 0) {
photo = null;
} else {
decodedPhoto.setHasMipMap(true);