From b88e470594a8f76b02ef1cce9b554f0b4f0f1748 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Tue, 10 Feb 2015 03:15:50 -0800 Subject: [PATCH] prevent recipient listener Activity context leak Resolves #2372 Resolves #2425 // FREEBIE --- .../securesms/ConversationActivity.java | 16 +++++++++------- .../securesms/MediaPreviewActivity.java | 18 ++++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationActivity.java b/src/org/thoughtcrime/securesms/ConversationActivity.java index 9a1e7c3c9e..06dcf48870 100644 --- a/src/org/thoughtcrime/securesms/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/ConversationActivity.java @@ -126,7 +126,8 @@ import static org.whispersystems.textsecure.internal.push.PushMessageProtos.Push */ public class ConversationActivity extends PassphraseRequiredActionBarActivity implements ConversationFragment.ConversationFragmentListener, - AttachmentManager.AttachmentListener + AttachmentManager.AttachmentListener, + RecipientModifiedListener { private static final String TAG = ConversationActivity.class.getSimpleName(); @@ -232,6 +233,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override protected void onDestroy() { saveDraft(); + recipients.removeListener(this); unregisterReceiver(securityUpdateReceiver); unregisterReceiver(groupUpdateReceiver); MemoryCleaner.clean(masterSecret); @@ -764,12 +766,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity distributionType = getIntent().getIntExtra(DISTRIBUTION_TYPE_EXTRA, ThreadDatabase.DistributionTypes.DEFAULT); masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA); - recipients.addListener(new RecipientModifiedListener() { - @Override - public void onModified(Recipient recipient) { - initializeTitleBar(); - } - }); + recipients.addListener(this); + } + + @Override + public void onModified(Recipient recipient) { + initializeTitleBar(); } private void initializeReceivers() { diff --git a/src/org/thoughtcrime/securesms/MediaPreviewActivity.java b/src/org/thoughtcrime/securesms/MediaPreviewActivity.java index ac6b6af30f..0b5f2047e7 100644 --- a/src/org/thoughtcrime/securesms/MediaPreviewActivity.java +++ b/src/org/thoughtcrime/securesms/MediaPreviewActivity.java @@ -64,6 +64,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im private final DynamicLanguage dynamicLanguage = new DynamicLanguage(); private MasterSecret masterSecret; + private boolean paused; private View loadingView; private TextView errorText; @@ -114,13 +115,14 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im } else { relativeTimeSpan = null; } - getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you) : recipient.getName()); + getSupportActionBar().setTitle(recipient == null ? getString(R.string.MediaPreviewActivity_you) : recipient.toShortString()); getSupportActionBar().setSubtitle(relativeTimeSpan); } @Override public void onResume() { super.onResume(); + paused = false; dynamicLanguage.onResume(this); if (recipient != null) recipient.addListener(this); initializeMedia(); @@ -129,6 +131,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im @Override public void onPause() { super.onPause(); + paused = true; if (recipient != null) recipient.removeListener(this); cleanupMedia(); } @@ -140,7 +143,6 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im setIntent(intent); initializeResources(); initializeActionBar(); - initializeMedia(); } private void initializeViews() { @@ -154,9 +156,9 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im final long recipientId = getIntent().getLongExtra(RECIPIENT_EXTRA, -1); masterSecret = getIntent().getParcelableExtra(MASTER_SECRET_EXTRA); - mediaUri = getIntent().getData(); - mediaType = getIntent().getType(); - date = getIntent().getLongExtra(DATE_EXTRA, -1); + mediaUri = getIntent().getData(); + mediaType = getIntent().getType(); + date = getIntent().getLongExtra(DATE_EXTRA, -1); if (recipientId > -1) { recipient = RecipientFactory.getRecipientForId(this, recipientId, true); @@ -211,8 +213,12 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im @Override protected void onPostExecute(Bitmap bitmap) { - loadingView.setVisibility(View.GONE); + if (paused) { + if (bitmap != null) bitmap.recycle(); + return; + } + loadingView.setVisibility(View.GONE); if (bitmap == null) { errorText.setText(R.string.MediaPreviewActivity_cant_display); errorText.setVisibility(View.VISIBLE);