summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaesu Lee <taesu82.lee@samsung.com>2020-02-10 17:10:25 +0900
committerLuca Stefani <luca.stefani.ge1@gmail.com>2020-02-12 20:27:33 +0100
commitcfe7ce38240712ab07c77b1f8ba930e84404d493 (patch)
tree4cf820c4807ae6956cdb7270172966c667fb511b
parent4a832963637111731df630d14796e883ef3a4c23 (diff)
downloadpackages_apps_Messaging-cfe7ce38240712ab07c77b1f8ba930e84404d493.tar.gz
packages_apps_Messaging-cfe7ce38240712ab07c77b1f8ba930e84404d493.tar.bz2
packages_apps_Messaging-cfe7ce38240712ab07c77b1f8ba930e84404d493.zip
Fix android.os.strictmode.LeakedClosableViolation
Test: Check log. Change-Id: I488fc6c4288bc3843a2be35a8e2988738441263e Signed-off-by: Taesu Lee <taesu82.lee@samsung.com>
-rw-r--r--src/com/android/messaging/datamodel/MessageNotificationState.java9
-rw-r--r--src/com/android/messaging/ui/contact/ContactRecipientAutoCompleteView.java46
-rw-r--r--src/com/android/messaging/ui/mediapicker/CameraManager.java1
-rw-r--r--src/com/android/messaging/ui/mediapicker/MmsVideoRecorder.java21
-rw-r--r--src/com/android/messaging/util/ImageUtils.java7
5 files changed, 57 insertions, 27 deletions
diff --git a/src/com/android/messaging/datamodel/MessageNotificationState.java b/src/com/android/messaging/datamodel/MessageNotificationState.java
index 4f62599..53c6aeb 100644
--- a/src/com/android/messaging/datamodel/MessageNotificationState.java
+++ b/src/com/android/messaging/datamodel/MessageNotificationState.java
@@ -618,10 +618,13 @@ public abstract class MessageNotificationState extends NotificationState {
final Context context = Factory.get().getApplicationContext();
final Uri uri =
MessagingContentProvider.buildConversationParticipantsUri(conversationId);
- final Cursor participantsCursor = context.getContentResolver().query(
- uri, ParticipantData.ParticipantsQuery.PROJECTION, null, null, null);
final ConversationParticipantsData participantsData = new ConversationParticipantsData();
- participantsData.bind(participantsCursor);
+
+ try (final Cursor participantsCursor = context.getContentResolver().query(
+ uri, ParticipantData.ParticipantsQuery.PROJECTION, null, null, null)) {
+ participantsData.bind(participantsCursor);
+ }
+
final Iterator<ParticipantData> iter = participantsData.iterator();
final HashMap<String, Integer> firstNames = new HashMap<String, Integer>();
diff --git a/src/com/android/messaging/ui/contact/ContactRecipientAutoCompleteView.java b/src/com/android/messaging/ui/contact/ContactRecipientAutoCompleteView.java
index dc13f22..35641b2 100644
--- a/src/com/android/messaging/ui/contact/ContactRecipientAutoCompleteView.java
+++ b/src/com/android/messaging/ui/contact/ContactRecipientAutoCompleteView.java
@@ -156,25 +156,33 @@ public class ContactRecipientAutoCompleteView extends RecipientEditTextView {
ContactRecipientEntryUtils.isSendToDestinationContact(entry)) {
// This is a generated/send-to contact chip, try to look it up and
// display a chip for the corresponding local contact.
- final Cursor lookupResult = ContactUtil.lookupDestination(getContext(),
- entry.getDestination()).performSynchronousQuery();
- if (lookupResult != null && lookupResult.moveToNext()) {
- // Found a match, remove the generated entry and replace with
- // a better local entry.
- publishProgress(new ChipReplacementTuple(recipient,
- ContactUtil.createRecipientEntryForPhoneQuery(
- lookupResult, true)));
- } else if (PhoneUtils.isValidSmsMmsDestination(
- entry.getDestination())){
- // No match was found, but we have a valid destination so let's at
- // least create an entry that shows an avatar.
- publishProgress(new ChipReplacementTuple(recipient,
- ContactRecipientEntryUtils.constructNumberWithAvatarEntry(
- entry.getDestination())));
- } else {
- // Not a valid contact. Remove and show an error.
- publishProgress(new ChipReplacementTuple(recipient, null));
- invalidChipsRemoved++;
+ try (final Cursor lookupResult =
+ ContactUtil.lookupDestination(
+ getContext(), entry.getDestination())
+ .performSynchronousQuery()) {
+ if (lookupResult != null && lookupResult.moveToNext()) {
+ // Found a match, remove the generated entry and replace with a
+ // better local entry.
+ publishProgress(
+ new ChipReplacementTuple(
+ recipient,
+ ContactUtil.createRecipientEntryForPhoneQuery(
+ lookupResult, true)));
+ } else if (PhoneUtils.isValidSmsMmsDestination(
+ entry.getDestination())) {
+ // No match was found, but we have a valid destination so let's
+ // at least create an entry that shows an avatar.
+ publishProgress(
+ new ChipReplacementTuple(
+ recipient,
+ ContactRecipientEntryUtils
+ .constructNumberWithAvatarEntry(
+ entry.getDestination())));
+ } else {
+ // Not a valid contact. Remove and show an error.
+ publishProgress(new ChipReplacementTuple(recipient, null));
+ invalidChipsRemoved++;
+ }
}
}
} else {
diff --git a/src/com/android/messaging/ui/mediapicker/CameraManager.java b/src/com/android/messaging/ui/mediapicker/CameraManager.java
index 835fab3..fb5c9bf 100644
--- a/src/com/android/messaging/ui/mediapicker/CameraManager.java
+++ b/src/com/android/messaging/ui/mediapicker/CameraManager.java
@@ -636,6 +636,7 @@ class CameraManager implements FocusOverlayManager.Listener {
}
}
+ mMediaRecorder.closeVideoFileDescriptor();
mMediaRecorder.release();
mMediaRecorder = null;
diff --git a/src/com/android/messaging/ui/mediapicker/MmsVideoRecorder.java b/src/com/android/messaging/ui/mediapicker/MmsVideoRecorder.java
index 7ac7871..89241b7 100644
--- a/src/com/android/messaging/ui/mediapicker/MmsVideoRecorder.java
+++ b/src/com/android/messaging/ui/mediapicker/MmsVideoRecorder.java
@@ -20,6 +20,7 @@ import android.hardware.Camera;
import android.media.CamcorderProfile;
import android.media.MediaRecorder;
import android.net.Uri;
+import android.os.ParcelFileDescriptor;
import com.android.messaging.Factory;
import com.android.messaging.datamodel.MediaScratchFileProvider;
@@ -27,6 +28,7 @@ import com.android.messaging.util.ContentType;
import com.android.messaging.util.SafeAsyncTask;
import java.io.FileNotFoundException;
+import java.io.IOException;
class MmsVideoRecorder extends MediaRecorder {
private static final float VIDEO_OVERSHOOT_SLOP = .85F;
@@ -39,6 +41,8 @@ class MmsVideoRecorder extends MediaRecorder {
/** The uri where video is being recorded to */
private Uri mTempVideoUri;
+ private ParcelFileDescriptor mVideoFD;
+
/** The settings used for video recording */
private final CamcorderProfile mCamcorderProfile;
@@ -75,9 +79,9 @@ class MmsVideoRecorder extends MediaRecorder {
setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
setVideoSource(MediaRecorder.VideoSource.CAMERA);
setOutputFormat(mCamcorderProfile.fileFormat);
- setOutputFile(
- Factory.get().getApplicationContext().getContentResolver().openFileDescriptor(
- mTempVideoUri, "w").getFileDescriptor());
+ mVideoFD = Factory.get().getApplicationContext().getContentResolver()
+ .openFileDescriptor(mTempVideoUri, "w");
+ setOutputFile(mVideoFD.getFileDescriptor());
// Copy settings from CamcorderProfile to MediaRecorder
setAudioEncodingBitRate(audioBitRate);
@@ -124,4 +128,15 @@ class MmsVideoRecorder extends MediaRecorder {
return ContentType.VIDEO_3GPP;
}
}
+
+ public void closeVideoFileDescriptor() {
+ if (mVideoFD != null) {
+ try {
+ mVideoFD.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ mVideoFD = null;
+ }
+ }
}
diff --git a/src/com/android/messaging/util/ImageUtils.java b/src/com/android/messaging/util/ImageUtils.java
index 5e20e7b..a228417 100644
--- a/src/com/android/messaging/util/ImageUtils.java
+++ b/src/com/android/messaging/util/ImageUtils.java
@@ -682,8 +682,11 @@ public class ImageUtils {
if (mScaled == null) {
if (mDecoded == null) {
mOptions.inSampleSize = mSampleSize;
- final InputStream inputStream = cr.openInputStream(mUri);
- mDecoded = BitmapFactory.decodeStream(inputStream, null, mOptions);
+ try (final InputStream inputStream = cr.openInputStream(mUri)) {
+ mDecoded = BitmapFactory.decodeStream(inputStream, null, mOptions);
+ } catch (IOException e) {
+ // Ignore
+ }
if (mDecoded == null) {
if (logv) {
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,