From 97e333cf52c7fd2cf34429f89fe28cb33f1b34e2 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Thu, 29 Oct 2015 17:40:27 -0700 Subject: Fix checking for invalid numbers. Some of the checking for invalid numbers was broken by code cleanups yesterday, and blocking of numbers which can't be normalized had been allowed (which is no good). Fixing this, by unifying checks for whether or not a number can be blocked. Bug: 25343277 Change-Id: Ia631a3e53e3f9ed58e173055a5e18086d95c9d02 --- src/com/android/dialer/CallDetailActivity.java | 5 ++--- src/com/android/dialer/calllog/CallLogListItemViewHolder.java | 2 +- .../android/dialer/filterednumber/BlockNumberDialogFragment.java | 2 +- src/com/android/dialer/filterednumber/FilteredNumbersUtil.java | 8 ++++---- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 47c3cf0ea..4e7e7b3c0 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -196,7 +196,6 @@ public class CallDetailActivity extends AppCompatActivity private PhoneCallDetails mDetails; protected String mNumber; private Uri mVoicemailUri; - private String mDefaultCountryIso; private String mDisplayNumber; private ListView mHistoryList; @@ -242,7 +241,6 @@ public class CallDetailActivity extends AppCompatActivity mCallerName = (TextView) findViewById(R.id.caller_name); mCallerNumber = (TextView) findViewById(R.id.caller_number); mAccountLabel = (TextView) findViewById(R.id.phone_account_label); - mDefaultCountryIso = GeoUtil.getCurrentCountryIso(this); mContactPhotoManager = ContactPhotoManager.getInstance(this); mCallButton = findViewById(R.id.call_back_button); @@ -391,7 +389,8 @@ public class CallDetailActivity extends AppCompatActivity } private void updatePhotoAndBlockActionItem() { - if (mDetails == null || !FilteredNumbersUtil.canBlockNumber(this, mNumber)) { + if (mDetails == null || + !FilteredNumbersUtil.canBlockNumber(this, mNumber, mDetails.countryIso)) { return; } diff --git a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java index c6337bc67..28e406fd5 100644 --- a/src/com/android/dialer/calllog/CallLogListItemViewHolder.java +++ b/src/com/android/dialer/calllog/CallLogListItemViewHolder.java @@ -303,7 +303,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder .setOnMenuItemClickListener(this); } - if (FilteredNumbersUtil.canBlockNumber(mContext, number)) { + if (FilteredNumbersUtil.canBlockNumber(mContext, number, countryIso)) { mFilteredNumberAsyncQueryHandler.startBlockedQuery( new FilteredNumberAsyncQueryHandler.OnCheckBlockedListener() { @Override diff --git a/src/com/android/dialer/filterednumber/BlockNumberDialogFragment.java b/src/com/android/dialer/filterednumber/BlockNumberDialogFragment.java index 425a729db..7a94eebb5 100644 --- a/src/com/android/dialer/filterednumber/BlockNumberDialogFragment.java +++ b/src/com/android/dialer/filterednumber/BlockNumberDialogFragment.java @@ -151,7 +151,7 @@ public class BlockNumberDialogFragment extends DialogFragment { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - if (!FilteredNumbersUtil.canBlockNumber(getActivity(), mNumber)) { + if (!FilteredNumbersUtil.canBlockNumber(getActivity(), mNumber, mCountryIso)) { dismiss(); Toast.makeText(getContext(), getString(R.string.invalidNumber, mDisplayNumber), Toast.LENGTH_SHORT).show(); diff --git a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java index 8a0d79233..e7097f4ff 100644 --- a/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java +++ b/src/com/android/dialer/filterednumber/FilteredNumbersUtil.java @@ -37,7 +37,6 @@ import java.util.LinkedList; import java.util.List; import com.android.contacts.common.testing.NeededForTesting; -import com.android.contacts.common.util.PhoneNumberHelper; import com.android.dialer.R; import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener; @@ -357,9 +356,10 @@ public class FilteredNumbersUtil { }); } - public static boolean canBlockNumber(Context context, String number) { - return !TextUtils.isEmpty(number) && !PhoneNumberUtils.isEmergencyNumber(number) - && !PhoneNumberHelper.isUriNumber(number); + public static boolean canBlockNumber(Context context, String number, String countryIso) { + final String normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso); + return !TextUtils.isEmpty(normalizedNumber) + && !PhoneNumberUtils.isEmergencyNumber(normalizedNumber); } private static long getRecentEmergencyCallThresholdMs(Context context) { -- cgit v1.2.3