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

View File

@@ -625,10 +625,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>();

View File

@@ -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 {

View File

@@ -636,6 +636,7 @@ class CameraManager implements FocusOverlayManager.Listener {
}
}
mMediaRecorder.closeVideoFileDescriptor();
mMediaRecorder.release();
mMediaRecorder = null;

View File

@@ -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;
}
}
}

View File

@@ -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,