Fix android.os.strictmode.LeakedClosableViolation am: 050bc461fc am: 1a0c417aab

Change-Id: Ib8198cf7ead7c64d5be7790260eba015f42bdd59
This commit is contained in:
Automerger Merge Worker
2020-02-12 19:53:12 +00:00
5 changed files with 57 additions and 27 deletions
@@ -625,10 +625,13 @@ public abstract class MessageNotificationState extends NotificationState {
final Context context = Factory.get().getApplicationContext(); final Context context = Factory.get().getApplicationContext();
final Uri uri = final Uri uri =
MessagingContentProvider.buildConversationParticipantsUri(conversationId); MessagingContentProvider.buildConversationParticipantsUri(conversationId);
final Cursor participantsCursor = context.getContentResolver().query(
uri, ParticipantData.ParticipantsQuery.PROJECTION, null, null, null);
final ConversationParticipantsData participantsData = new ConversationParticipantsData(); 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 Iterator<ParticipantData> iter = participantsData.iterator();
final HashMap<String, Integer> firstNames = new HashMap<String, Integer>(); final HashMap<String, Integer> firstNames = new HashMap<String, Integer>();
@@ -156,25 +156,33 @@ public class ContactRecipientAutoCompleteView extends RecipientEditTextView {
ContactRecipientEntryUtils.isSendToDestinationContact(entry)) { ContactRecipientEntryUtils.isSendToDestinationContact(entry)) {
// This is a generated/send-to contact chip, try to look it up and // This is a generated/send-to contact chip, try to look it up and
// display a chip for the corresponding local contact. // display a chip for the corresponding local contact.
final Cursor lookupResult = ContactUtil.lookupDestination(getContext(), try (final Cursor lookupResult =
entry.getDestination()).performSynchronousQuery(); ContactUtil.lookupDestination(
if (lookupResult != null && lookupResult.moveToNext()) { getContext(), entry.getDestination())
// Found a match, remove the generated entry and replace with .performSynchronousQuery()) {
// a better local entry. if (lookupResult != null && lookupResult.moveToNext()) {
publishProgress(new ChipReplacementTuple(recipient, // Found a match, remove the generated entry and replace with a
ContactUtil.createRecipientEntryForPhoneQuery( // better local entry.
lookupResult, true))); publishProgress(
} else if (PhoneUtils.isValidSmsMmsDestination( new ChipReplacementTuple(
entry.getDestination())){ recipient,
// No match was found, but we have a valid destination so let's at ContactUtil.createRecipientEntryForPhoneQuery(
// least create an entry that shows an avatar. lookupResult, true)));
publishProgress(new ChipReplacementTuple(recipient, } else if (PhoneUtils.isValidSmsMmsDestination(
ContactRecipientEntryUtils.constructNumberWithAvatarEntry( entry.getDestination())) {
entry.getDestination()))); // No match was found, but we have a valid destination so let's
} else { // at least create an entry that shows an avatar.
// Not a valid contact. Remove and show an error. publishProgress(
publishProgress(new ChipReplacementTuple(recipient, null)); new ChipReplacementTuple(
invalidChipsRemoved++; recipient,
ContactRecipientEntryUtils
.constructNumberWithAvatarEntry(
entry.getDestination())));
} else {
// Not a valid contact. Remove and show an error.
publishProgress(new ChipReplacementTuple(recipient, null));
invalidChipsRemoved++;
}
} }
} }
} else { } else {
@@ -636,6 +636,7 @@ class CameraManager implements FocusOverlayManager.Listener {
} }
} }
mMediaRecorder.closeVideoFileDescriptor();
mMediaRecorder.release(); mMediaRecorder.release();
mMediaRecorder = null; mMediaRecorder = null;
@@ -20,6 +20,7 @@ import android.hardware.Camera;
import android.media.CamcorderProfile; import android.media.CamcorderProfile;
import android.media.MediaRecorder; import android.media.MediaRecorder;
import android.net.Uri; import android.net.Uri;
import android.os.ParcelFileDescriptor;
import com.android.messaging.Factory; import com.android.messaging.Factory;
import com.android.messaging.datamodel.MediaScratchFileProvider; import com.android.messaging.datamodel.MediaScratchFileProvider;
@@ -27,6 +28,7 @@ import com.android.messaging.util.ContentType;
import com.android.messaging.util.SafeAsyncTask; import com.android.messaging.util.SafeAsyncTask;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
class MmsVideoRecorder extends MediaRecorder { class MmsVideoRecorder extends MediaRecorder {
private static final float VIDEO_OVERSHOOT_SLOP = .85F; private static final float VIDEO_OVERSHOOT_SLOP = .85F;
@@ -39,6 +41,8 @@ class MmsVideoRecorder extends MediaRecorder {
/** The uri where video is being recorded to */ /** The uri where video is being recorded to */
private Uri mTempVideoUri; private Uri mTempVideoUri;
private ParcelFileDescriptor mVideoFD;
/** The settings used for video recording */ /** The settings used for video recording */
private final CamcorderProfile mCamcorderProfile; private final CamcorderProfile mCamcorderProfile;
@@ -75,9 +79,9 @@ class MmsVideoRecorder extends MediaRecorder {
setAudioSource(MediaRecorder.AudioSource.CAMCORDER); setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
setVideoSource(MediaRecorder.VideoSource.CAMERA); setVideoSource(MediaRecorder.VideoSource.CAMERA);
setOutputFormat(mCamcorderProfile.fileFormat); setOutputFormat(mCamcorderProfile.fileFormat);
setOutputFile( mVideoFD = Factory.get().getApplicationContext().getContentResolver()
Factory.get().getApplicationContext().getContentResolver().openFileDescriptor( .openFileDescriptor(mTempVideoUri, "w");
mTempVideoUri, "w").getFileDescriptor()); setOutputFile(mVideoFD.getFileDescriptor());
// Copy settings from CamcorderProfile to MediaRecorder // Copy settings from CamcorderProfile to MediaRecorder
setAudioEncodingBitRate(audioBitRate); setAudioEncodingBitRate(audioBitRate);
@@ -124,4 +128,15 @@ class MmsVideoRecorder extends MediaRecorder {
return ContentType.VIDEO_3GPP; return ContentType.VIDEO_3GPP;
} }
} }
public void closeVideoFileDescriptor() {
if (mVideoFD != null) {
try {
mVideoFD.close();
} catch (IOException e) {
// Ignore
}
mVideoFD = null;
}
}
} }
@@ -682,8 +682,11 @@ public class ImageUtils {
if (mScaled == null) { if (mScaled == null) {
if (mDecoded == null) { if (mDecoded == null) {
mOptions.inSampleSize = mSampleSize; mOptions.inSampleSize = mSampleSize;
final InputStream inputStream = cr.openInputStream(mUri); try (final InputStream inputStream = cr.openInputStream(mUri)) {
mDecoded = BitmapFactory.decodeStream(inputStream, null, mOptions); mDecoded = BitmapFactory.decodeStream(inputStream, null, mOptions);
} catch (IOException e) {
// Ignore
}
if (mDecoded == null) { if (mDecoded == null) {
if (logv) { if (logv) {
LogUtil.v(LogUtil.BUGLE_IMAGE_TAG, LogUtil.v(LogUtil.BUGLE_IMAGE_TAG,