Skip to content

Commit

Permalink
Remove the Canonical Address Database
Browse files Browse the repository at this point in the history
This was a holdover from Signal's origins as a pure SMS app.
It causes problems, depends on undefined device specific behavior,
and should no longer be necessary now that we have all the
information we need to E164 all numbers.

// FREEBIE
  • Loading branch information
moxie0 committed Jul 31, 2017
1 parent e452862 commit 7378104
Show file tree
Hide file tree
Showing 113 changed files with 2,029 additions and 2,130 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ android {
}

defaultConfig {
versionCode 275
versionCode 276
versionName "4.8.1"

minSdkVersion 9
Expand Down
11 changes: 8 additions & 3 deletions src/org/thoughtcrime/securesms/BlockedContactsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
import android.widget.ListView;

import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.loaders.BlockedContactsLoader;
import org.thoughtcrime.securesms.preferences.BlockedContactListItem;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.util.DynamicLanguage;
import org.thoughtcrime.securesms.util.DynamicTheme;

import java.util.List;

public class BlockedContactsActivity extends PassphraseRequiredActionBarActivity {

private final DynamicTheme dynamicTheme = new DynamicTheme();
Expand Down Expand Up @@ -105,7 +108,7 @@ public void onLoaderReset(Loader<Cursor> loader) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Recipients recipients = ((BlockedContactListItem)view).getRecipients();
Intent intent = new Intent(getActivity(), RecipientPreferenceActivity.class);
intent.putExtra(RecipientPreferenceActivity.RECIPIENTS_EXTRA, recipients.getIds());
intent.putExtra(RecipientPreferenceActivity.ADDRESSES_EXTRA, recipients.getAddresses());

startActivity(intent);
}
Expand All @@ -124,8 +127,10 @@ public View newView(Context context, Cursor cursor, ViewGroup parent) {

@Override
public void bindView(View view, Context context, Cursor cursor) {
String recipientIds = cursor.getString(1);
Recipients recipients = RecipientFactory.getRecipientsForIds(context, recipientIds, true);
String addressesConcat = cursor.getString(1);
List<Address> addresses = Address.fromSerializedList(addressesConcat, " ");

Recipients recipients = RecipientFactory.getRecipientsFor(context, addresses.toArray(new Address[0]), true);

((BlockedContactListItem) view).set(recipients);
}
Expand Down
36 changes: 13 additions & 23 deletions src/org/thoughtcrime/securesms/ConfirmIdentityDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import android.text.SpannableString;
import android.text.Spanned;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.widget.TextView;

import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.crypto.storage.TextSecureIdentityKeyStore;
import org.thoughtcrime.securesms.crypto.storage.TextSecureSessionStore;
import org.thoughtcrime.securesms.database.Address;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.MmsAddressDatabase;
import org.thoughtcrime.securesms.database.MmsDatabase;
Expand All @@ -28,12 +27,9 @@
import org.thoughtcrime.securesms.recipients.Recipients;
import org.thoughtcrime.securesms.sms.MessageSender;
import org.thoughtcrime.securesms.util.Base64;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.VerifySpan;
import org.whispersystems.libsignal.SignalProtocolAddress;
import org.whispersystems.libsignal.state.IdentityKeyStore;
import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope;
import org.whispersystems.signalservice.api.util.InvalidNumberException;
import org.whispersystems.signalservice.internal.push.SignalServiceProtos;

import java.io.IOException;
Expand All @@ -53,10 +49,8 @@ public ConfirmIdentityDialog(Context context,
{
super(context);

try {
Recipient recipient = RecipientFactory.getRecipientForId(context, mismatch.getRecipientId(), false);
Recipient recipient = RecipientFactory.getRecipientFor(context, mismatch.getAddress(), false);
String name = recipient.toShortString();
String number = Util.canonicalizeNumber(context, recipient.getNumber());
String introduction = String.format(context.getString(R.string.ConfirmIdentityDialog_your_safety_number_with_s_has_changed), name, name);
SpannableString spannableString = new SpannableString(introduction + " " +
context.getString(R.string.ConfirmIdentityDialog_you_may_wish_to_verify_your_safety_number_with_this_contact));
Expand All @@ -68,11 +62,8 @@ public ConfirmIdentityDialog(Context context,
setTitle(name);
setMessage(spannableString);

setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.ConfirmIdentityDialog_accept), new AcceptListener(masterSecret, messageRecord, mismatch, number));
setButton(AlertDialog.BUTTON_POSITIVE, context.getString(R.string.ConfirmIdentityDialog_accept), new AcceptListener(masterSecret, messageRecord, mismatch, recipient.getAddress()));
setButton(AlertDialog.BUTTON_NEGATIVE, context.getString(android.R.string.cancel), new CancelListener());
} catch (InvalidNumberException e) {
throw new AssertionError(e);
}
}

@Override
Expand All @@ -91,13 +82,13 @@ private class AcceptListener implements OnClickListener {
private final MasterSecret masterSecret;
private final MessageRecord messageRecord;
private final IdentityKeyMismatch mismatch;
private final String number;
private final Address address;

private AcceptListener(MasterSecret masterSecret, MessageRecord messageRecord, IdentityKeyMismatch mismatch, String number) {
private AcceptListener(MasterSecret masterSecret, MessageRecord messageRecord, IdentityKeyMismatch mismatch, Address address) {
this.masterSecret = masterSecret;
this.messageRecord = messageRecord;
this.mismatch = mismatch;
this.number = number;
this.address = address;
}

@Override
Expand All @@ -107,7 +98,7 @@ public void onClick(DialogInterface dialog, int which) {
@Override
protected Void doInBackground(Void... params) {
synchronized (SESSION_LOCK) {
SignalProtocolAddress mismatchAddress = new SignalProtocolAddress(number, 1);
SignalProtocolAddress mismatchAddress = new SignalProtocolAddress(address.toPhoneString(), 1);
TextSecureIdentityKeyStore identityKeyStore = new TextSecureIdentityKeyStore(getContext());

identityKeyStore.saveIdentity(mismatchAddress, mismatch.getIdentityKey(), true);
Expand Down Expand Up @@ -151,16 +142,16 @@ private void processOutgoingMessageRecord(MessageRecord messageRecord) {

if (messageRecord.isMms()) {
mmsDatabase.removeMismatchedIdentity(messageRecord.getId(),
mismatch.getRecipientId(),
mismatch.getAddress(),
mismatch.getIdentityKey());

Recipients recipients = mmsAddressDatabase.getRecipientsForId(messageRecord.getId());

if (recipients.isGroupRecipient()) MessageSender.resendGroupMessage(getContext(), masterSecret, messageRecord, mismatch.getRecipientId());
if (recipients.isGroupRecipient()) MessageSender.resendGroupMessage(getContext(), masterSecret, messageRecord, mismatch.getAddress());
else MessageSender.resend(getContext(), masterSecret, messageRecord);
} else {
smsDatabase.removeMismatchedIdentity(messageRecord.getId(),
mismatch.getRecipientId(),
mismatch.getAddress(),
mismatch.getIdentityKey());

MessageSender.resend(getContext(), masterSecret, messageRecord);
Expand All @@ -173,13 +164,13 @@ private void processIncomingMessageRecord(MessageRecord messageRecord) {
SmsDatabase smsDatabase = DatabaseFactory.getSmsDatabase(getContext());

smsDatabase.removeMismatchedIdentity(messageRecord.getId(),
mismatch.getRecipientId(),
mismatch.getAddress(),
mismatch.getIdentityKey());

boolean legacy = !messageRecord.isContentBundleKeyExchange();

SignalServiceEnvelope envelope = new SignalServiceEnvelope(SignalServiceProtos.Envelope.Type.PREKEY_BUNDLE_VALUE,
messageRecord.getIndividualRecipient().getNumber(),
messageRecord.getIndividualRecipient().getAddress().toPhoneString(),
messageRecord.getRecipientDeviceId(), "",
messageRecord.getDateSent(),
legacy ? Base64.decode(messageRecord.getBody().getBody()) : null,
Expand All @@ -189,8 +180,7 @@ private void processIncomingMessageRecord(MessageRecord messageRecord) {

ApplicationContext.getInstance(getContext())
.getJobManager()
.add(new PushDecryptJob(getContext(), pushId, messageRecord.getId(),
messageRecord.getIndividualRecipient().getNumber()));
.add(new PushDecryptJob(getContext(), pushId, messageRecord.getId()));
} catch (IOException e) {
throw new AssertionError(e);
}
Expand Down
Loading

0 comments on commit 7378104

Please sign in to comment.