Fix invalid transportation options

1) Accounts in the directory that don't have supports_sms can't
   get encrypted SMS.
2) Push groups can't receive insecure SMS

// FREEBIE

Closes #2521
This commit is contained in:
Jake McGinty 2015-02-24 16:37:37 -08:00 committed by Moxie Marlinspike
parent ac0a1c0bc1
commit fcde642563
2 changed files with 35 additions and 9 deletions

View File

@ -68,6 +68,7 @@ import org.thoughtcrime.securesms.database.DraftDatabase.Draft;
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts;
import org.thoughtcrime.securesms.database.GroupDatabase;
import org.thoughtcrime.securesms.database.MmsSmsColumns.Types;
import org.thoughtcrime.securesms.database.TextSecureDirectory;
import org.thoughtcrime.securesms.database.ThreadDatabase;
import org.thoughtcrime.securesms.mms.AttachmentManager;
import org.thoughtcrime.securesms.mms.AttachmentTypeSelectorAdapter;
@ -684,10 +685,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
SessionStore sessionStore = new TextSecureSessionStore(this, masterSecret);
Recipient primaryRecipient = getRecipients() == null ? null : getRecipients().getPrimaryRecipient();
boolean isPushDestination = DirectoryHelper.isPushDestination(this, getRecipients());
boolean isSecureDestination = isSingleConversation() && sessionStore.containsSession(primaryRecipient.getRecipientId(),
boolean isSecureSmsAllowed = (!isPushDestination || DirectoryHelper.isSmsFallbackAllowed(this, getRecipients()));
boolean isSecureSmsDestination = isSecureSmsAllowed &&
isSingleConversation() &&
sessionStore.containsSession(primaryRecipient.getRecipientId(),
PushAddress.DEFAULT_DEVICE_ID);
if (isPushDestination || isSecureDestination) {
if (isPushDestination || isSecureSmsDestination) {
this.isEncryptedConversation = true;
} else {
this.isEncryptedConversation = false;
@ -695,11 +699,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
sendButton.initializeAvailableTransports(!recipients.isSingleRecipient() || attachmentManager.isAttachmentPresent());
if (!isPushDestination ) sendButton.disableTransport("textsecure");
if (!isSecureDestination) sendButton.disableTransport("secure_sms");
if (!isSecureSmsDestination ) sendButton.disableTransport("secure_sms");
if (recipients.isGroupRecipient()) sendButton.disableTransport("insecure_sms");
if (isPushDestination) {
sendButton.setDefaultTransport("textsecure");
} else if (isSecureDestination) {
} else if (isSecureSmsDestination) {
sendButton.setDefaultTransport("secure_sms");
} else {
sendButton.setDefaultTransport("insecure_sms");

View File

@ -115,6 +115,27 @@ public class DirectoryHelper {
}
}
public static boolean isSmsFallbackAllowed(Context context, Recipients recipients) {
try {
if (recipients == null || !recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
return false;
}
final String number = recipients.getPrimaryRecipient().getNumber();
if (number == null) {
return false;
}
final String e164number = Util.canonicalizeNumber(context, number);
return TextSecureDirectory.getInstance(context).isSmsFallbackSupported(e164number);
} catch (InvalidNumberException e) {
Log.w(TAG, e);
return false;
}
}
public static interface DirectoryUpdateFinishedListener {
public void onUpdateFinished();
}