Fix up security initialization stuff in ConversationActivity

// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-09-23 15:47:48 -07:00
parent a0fc948519
commit d9a3f5a3b8
5 changed files with 31 additions and 57 deletions

View File

@ -215,7 +215,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
initializeActionBar(); initializeActionBar();
initializeViews(); initializeViews();
initializeResources(); initializeResources();
initializeSecurity(); initializeSecurity(false);
initializeDraft(); initializeDraft();
} }
@ -231,7 +231,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
setIntent(intent); setIntent(intent);
initializeResources(); initializeResources();
initializeSecurity(); initializeSecurity(false);
initializeDraft(); initializeDraft();
if (fragment != null) { if (fragment != null) {
@ -267,7 +267,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
quickAttachmentDrawer.onPause(); quickAttachmentDrawer.onPause();
} }
@Override public void onConfigurationChanged(Configuration newConfig) { @Override
public void onConfigurationChanged(Configuration newConfig) {
Log.w(TAG, "onConfigurationChanged(" + newConfig.orientation + ")"); Log.w(TAG, "onConfigurationChanged(" + newConfig.orientation + ")");
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
composeText.setTransport(sendButton.getSelectedTransport()); composeText.setTransport(sendButton.getSelectedTransport());
@ -293,10 +294,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
switch (reqCode) { switch (reqCode) {
case PICK_IMAGE: case PICK_IMAGE:
setMedia(data.getData(), boolean isGif = MediaUtil.isGif(MediaUtil.getMimeType(this, data.getData()));
MediaUtil.isGif(MediaUtil.getMimeType(this, data.getData())) ? MediaType.GIF setMedia(data.getData(), isGif ? MediaType.GIF : MediaType.IMAGE, false);
: MediaType.IMAGE,
false);
break; break;
case PICK_VIDEO: case PICK_VIDEO:
setMedia(data.getData(), MediaType.VIDEO, false); setMedia(data.getData(), MediaType.VIDEO, false);
@ -704,6 +703,22 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
startActivity(intent); startActivity(intent);
} }
private void handleSecurityChange(boolean encryptedConversation) {
boolean isMediaMessage = !recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent();
this.isEncryptedConversation = encryptedConversation;
sendButton.resetAvailableTransports(isMediaMessage);
if (!isEncryptedConversation) sendButton.disableTransport(Type.TEXTSECURE);
if (recipients.isGroupRecipient()) sendButton.disableTransport(Type.SMS);
if (isEncryptedConversation) sendButton.setDefaultTransport(Type.TEXTSECURE);
else sendButton.setDefaultTransport(Type.SMS);
calculateCharactersRemaining();
supportInvalidateOptionsMenu();
}
///// Initializers ///// Initializers
private void initializeDraft() { private void initializeDraft() {
@ -763,8 +778,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}.execute(); }.execute();
} }
private void initializeSecurity() { private void initializeSecurity(final boolean current) {
initializeSecurity(false); handleSecurityChange(current);
new AsyncTask<Recipients, Void, Boolean>() { new AsyncTask<Recipients, Void, Boolean>() {
@Override @Override
@ -785,28 +800,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override @Override
protected void onPostExecute(Boolean result) { protected void onPostExecute(Boolean result) {
if (result != isEncryptedConversation) { if (current != result) {
initializeSecurity(result); handleSecurityChange(result);
} }
} }
}.execute(recipients); }.execute(recipients);
} }
private void initializeSecurity(boolean encryptedConversation) {
boolean isMediaMessage = !recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent();
this.isEncryptedConversation = encryptedConversation;
sendButton.resetAvailableTransports(isMediaMessage);
if (!isEncryptedConversation) sendButton.disableTransport(Type.TEXTSECURE);
if (recipients.isGroupRecipient()) sendButton.disableTransport(Type.SMS);
if (isEncryptedConversation) sendButton.setDefaultTransport(Type.TEXTSECURE);
else sendButton.setDefaultTransport(Type.SMS);
calculateCharactersRemaining();
supportInvalidateOptionsMenu();
}
private void initializeMmsEnabledCheck() { private void initializeMmsEnabledCheck() {
new AsyncTask<Void, Void, Boolean>() { new AsyncTask<Void, Void, Boolean>() {
@ -944,13 +944,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
securityUpdateReceiver = new BroadcastReceiver() { securityUpdateReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
long eventThreadId = intent.getLongExtra("thread_id", -1); initializeSecurity(isEncryptedConversation);
if (eventThreadId == threadId || eventThreadId == -2) {
initializeSecurity();
calculateCharactersRemaining(); calculateCharactersRemaining();
} }
}
}; };
groupUpdateReceiver = new BroadcastReceiver() { groupUpdateReceiver = new BroadcastReceiver() {
@ -1188,8 +1184,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
if (refreshFragment) { if (refreshFragment) {
fragment.reload(recipients, threadId); fragment.reload(recipients, threadId);
initializeSecurity();
} }
fragment.scrollToBottom(); fragment.scrollToBottom();
@ -1439,7 +1433,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override @Override
public void onAttachmentChanged() { public void onAttachmentChanged() {
initializeSecurity();
updateToggleButtonState(); updateToggleButtonState();
} }

View File

@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.crypto;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.service.KeyCachingService;
/** /**
@ -16,12 +17,7 @@ public class SecurityEvent {
public static final String SECURITY_UPDATE_EVENT = "org.thoughtcrime.securesms.KEY_EXCHANGE_UPDATE"; public static final String SECURITY_UPDATE_EVENT = "org.thoughtcrime.securesms.KEY_EXCHANGE_UPDATE";
public static void broadcastSecurityUpdateEvent(Context context) { public static void broadcastSecurityUpdateEvent(Context context) {
broadcastSecurityUpdateEvent(context, -2);
}
public static void broadcastSecurityUpdateEvent(Context context, long threadId) {
Intent intent = new Intent(SECURITY_UPDATE_EVENT); Intent intent = new Intent(SECURITY_UPDATE_EVENT);
intent.putExtra("thread_id", threadId);
intent.setPackage(context.getPackageName()); intent.setPackage(context.getPackageName());
context.sendBroadcast(intent, KeyCachingService.KEY_PERMISSION); context.sendBroadcast(intent, KeyCachingService.KEY_PERMISSION);
} }

View File

@ -195,7 +195,7 @@ public class PushDecryptJob extends ContextJob {
SessionStore sessionStore = new TextSecureSessionStore(context); SessionStore sessionStore = new TextSecureSessionStore(context);
sessionStore.deleteAllSessions(envelope.getSource()); sessionStore.deleteAllSessions(envelope.getSource());
SecurityEvent.broadcastSecurityUpdateEvent(context, threadId); SecurityEvent.broadcastSecurityUpdateEvent(context);
MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId); MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), threadId);
} }

View File

@ -79,14 +79,6 @@ public class SmsSentJob extends MasterSecretJob {
switch (result) { switch (result) {
case Activity.RESULT_OK: case Activity.RESULT_OK:
database.markAsSent(messageId); database.markAsSent(messageId);
if (record != null && record.isEndSession()) {
Log.w(TAG, "Ending session...");
SessionStore sessionStore = new TextSecureSessionStore(context, masterSecret);
sessionStore.deleteAllSessions(record.getIndividualRecipient().getNumber());
SecurityEvent.broadcastSecurityUpdateEvent(context, record.getThreadId());
}
break; break;
case SmsManager.RESULT_ERROR_NO_SERVICE: case SmsManager.RESULT_ERROR_NO_SERVICE:
case SmsManager.RESULT_ERROR_RADIO_OFF: case SmsManager.RESULT_ERROR_RADIO_OFF:
@ -94,7 +86,6 @@ public class SmsSentJob extends MasterSecretJob {
ApplicationContext.getInstance(context) ApplicationContext.getInstance(context)
.getJobManager() .getJobManager()
.add(new SmsSendJob(context, messageId, record.getIndividualRecipient().getNumber())); .add(new SmsSendJob(context, messageId, record.getIndividualRecipient().getNumber()));
break; break;
default: default:
database.markAsSentFailed(messageId); database.markAsSentFailed(messageId);

View File

@ -3,9 +3,6 @@ package org.thoughtcrime.securesms.push;
import android.content.Context; import android.content.Context;
import org.thoughtcrime.securesms.crypto.SecurityEvent; import org.thoughtcrime.securesms.crypto.SecurityEvent;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.whispersystems.textsecure.api.TextSecureMessageSender; import org.whispersystems.textsecure.api.TextSecureMessageSender;
import org.whispersystems.textsecure.api.push.TextSecureAddress; import org.whispersystems.textsecure.api.push.TextSecureAddress;
@ -21,9 +18,6 @@ public class SecurityEventListener implements TextSecureMessageSender.EventListe
@Override @Override
public void onSecurityEvent(TextSecureAddress textSecureAddress) { public void onSecurityEvent(TextSecureAddress textSecureAddress) {
Recipients recipients = RecipientFactory.getRecipientsFromString(context, textSecureAddress.getNumber(), false); SecurityEvent.broadcastSecurityUpdateEvent(context);
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
SecurityEvent.broadcastSecurityUpdateEvent(context, threadId);
} }
} }