From 0b4fe84a41a1275bc66b6eddf787ebea1eca18a8 Mon Sep 17 00:00:00 2001 From: Moxie Marlinspike Date: Fri, 7 Mar 2014 13:05:35 -0800 Subject: [PATCH] Format-neutral compare numbers in MMS group with local device. Closes #1018 --- .../securesms/database/MmsDatabase.java | 16 +++++++++++++--- .../securesms/service/MmsDownloader.java | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/org/thoughtcrime/securesms/database/MmsDatabase.java b/src/org/thoughtcrime/securesms/database/MmsDatabase.java index 7a7359c3c9..dd6a5025f4 100644 --- a/src/org/thoughtcrime/securesms/database/MmsDatabase.java +++ b/src/org/thoughtcrime/securesms/database/MmsDatabase.java @@ -22,9 +22,12 @@ import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import android.net.Uri; +import android.telephony.TelephonyManager; import android.util.Log; import android.util.Pair; +import com.google.i18n.phonenumbers.PhoneNumberUtil; + import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage; import org.thoughtcrime.securesms.mms.OutgoingMediaMessage; @@ -205,7 +208,8 @@ public class MmsDatabase extends Database implements MmsSmsColumns { } if (encodedToList != null && (encodedToList.length > 1 || group.size() > 1)) { - String localNumber = Util.getDeviceE164Number(context); + TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); + String localNumber = telephonyManager.getLine1Number(); if (localNumber == null) { localNumber = TextSecurePreferences.getLocalNumber(context); @@ -214,8 +218,14 @@ public class MmsDatabase extends Database implements MmsSmsColumns { for (EncodedStringValue encodedTo : encodedToList) { String to = new String(encodedTo.getTextString(), CharacterSets.MIMENAME_ISO_8859_1); - /// TODO format numbers before comparing. - if (localNumber == null || !localNumber.equals(to)) { + PhoneNumberUtil.MatchType match; + + if (localNumber == null) match = PhoneNumberUtil.MatchType.NO_MATCH; + else match = PhoneNumberUtil.getInstance().isNumberMatch(localNumber, to); + + if (match == PhoneNumberUtil.MatchType.NO_MATCH || + match == PhoneNumberUtil.MatchType.NOT_A_NUMBER) + { group.add(to); } } diff --git a/src/org/thoughtcrime/securesms/service/MmsDownloader.java b/src/org/thoughtcrime/securesms/service/MmsDownloader.java index a1befd2a24..88aaf6bc48 100644 --- a/src/org/thoughtcrime/securesms/service/MmsDownloader.java +++ b/src/org/thoughtcrime/securesms/service/MmsDownloader.java @@ -61,9 +61,9 @@ public class MmsDownloader { } public void process(MasterSecret masterSecret, Intent intent) { - if (intent.getAction().equals(SendReceiveService.DOWNLOAD_MMS_ACTION)) { + if (SendReceiveService.DOWNLOAD_MMS_ACTION.equals(intent.getAction())) { handleDownloadMms(masterSecret, intent); - } else if (intent.getAction().equals(SendReceiveService.DOWNLOAD_MMS_PENDING_APN_ACTION)) { + } else if (SendReceiveService.DOWNLOAD_MMS_PENDING_APN_ACTION.equals(intent.getAction())) { handleMmsPendingApnDownloads(masterSecret); } }