diff options
author | Jay Wang <jaywang@codeaurora.org> | 2016-08-22 20:17:37 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2016-09-27 11:15:34 -0700 |
commit | 035160fb849ed565fc419cd7deadb486338b755c (patch) | |
tree | 3492f4d575a0e1a4e254d9aca0efbc2fbfef6870 /src/com/android/camera | |
parent | 4b5b4aaaed98a4156beb1a6fa2f1e1ee124731b5 (diff) | |
download | android_packages_apps_Snap-035160fb849ed565fc419cd7deadb486338b755c.tar.gz android_packages_apps_Snap-035160fb849ed565fc419cd7deadb486338b755c.tar.bz2 android_packages_apps_Snap-035160fb849ed565fc419cd7deadb486338b755c.zip |
SnapdragonCamera: Fix memory leak when updating thumbnails.
Fix a memory leak with jpeg data buffers saved for
updating thumbnails. Ensure that all references are freed
and released when exiting.
CRs-Fixed: 1054441
Change-Id: Idc79f51f0e70b0b3e39d614ff3dd7f5d1f85aaad
Diffstat (limited to 'src/com/android/camera')
-rwxr-xr-x | src/com/android/camera/CameraActivity.java | 15 | ||||
-rw-r--r-- | src/com/android/camera/CaptureModule.java | 15 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index c7f0072ef..3579586e7 100755 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -758,8 +758,8 @@ public class CameraActivity extends Activity } private class UpdateThumbnailTask extends AsyncTask<Void, Void, Bitmap> { - private final byte[] mJpegData; - private final boolean mCheckOrientation; + private byte[] mJpegData; + private boolean mCheckOrientation; public UpdateThumbnailTask(final byte[] jpegData, boolean checkOrientation) { mJpegData = jpegData; @@ -802,6 +802,17 @@ public class CameraActivity extends Activity } else { updateThumbnail(bitmap); } + + mJpegData = null; + } + + @Override + protected void onCancelled(Bitmap bitmap) { + if(bitmap != null) + bitmap.recycle(); + + bitmap = null; + mJpegData = null; } private Bitmap decodeImageCenter(final String path) { diff --git a/src/com/android/camera/CaptureModule.java b/src/com/android/camera/CaptureModule.java index 92b95e5ec..85722457d 100644 --- a/src/com/android/camera/CaptureModule.java +++ b/src/com/android/camera/CaptureModule.java @@ -357,7 +357,6 @@ public class CaptureModule implements CameraModule, PhotoController, if (uri != null) { mActivity.notifyNewMedia(uri); } - if (mLastJpegData != null) mActivity.updateThumbnail(mLastJpegData); } } }; @@ -1353,7 +1352,6 @@ public class CaptureModule implements CameraModule, PhotoController, long date = (name == null) ? -1 : name.date; byte[] bytes = getJpegData(image); - mLastJpegData = bytes; ExifInterface exif = Exif.getExif(bytes); int orientation = Exif.getOrientation(exif); @@ -1361,6 +1359,12 @@ public class CaptureModule implements CameraModule, PhotoController, mActivity.getMediaSaveService().addImage(bytes, title, date, null, image.getWidth(), image.getHeight(), orientation, null, mOnMediaSavedListener, mContentResolver, "jpeg"); + + if(mLongshotActive) { + mLastJpegData = bytes; + } else { + mActivity.updateThumbnail(bytes); + } image.close(); } } @@ -1395,7 +1399,6 @@ public class CaptureModule implements CameraModule, PhotoController, ByteBuffer buffer = image.getPlanes()[0].getBuffer(); byte[] bytes = new byte[buffer.remaining()]; - mLastJpegData = bytes; buffer.get(bytes); ExifInterface exif = Exif.getExif(bytes); @@ -1404,6 +1407,8 @@ public class CaptureModule implements CameraModule, PhotoController, mActivity.getMediaSaveService().addImage(bytes, title, date, null, image.getWidth(), image.getHeight(), orientation, null, mOnMediaSavedListener, mContentResolver, "jpeg"); + + mActivity.updateThumbnail(bytes); image.close(); } }, mImageAvailableHandler); @@ -1716,6 +1721,7 @@ public class CaptureModule implements CameraModule, PhotoController, mUI.hideSurfaceView(); mFirstPreviewLoaded = false; stopBackgroundThread(); + mLastJpegData = null; } @Override @@ -3490,7 +3496,6 @@ public class CaptureModule implements CameraModule, PhotoController, byte[] bayerBytes = getJpegData(bayerImage); byte[] monoBytes = getJpegData(monoImage); - mLastJpegData = bayerBytes; ExifInterface exif = Exif.getExif(bayerBytes); int orientation = Exif.getOrientation(exif); @@ -3498,6 +3503,8 @@ public class CaptureModule implements CameraModule, PhotoController, null, bayerBytes, monoBytes, width, height, title, date, null, orientation, mOnMediaSavedListener, mContentResolver, "jpeg"); + mActivity.updateThumbnail(bayerBytes); + bayerImage.close(); bayerImage = null; monoImage.close(); |