Updating logic for isBlockedNumber
In the framework blocking, both the e164 and non-e164 formats of a
number can be blocked at the same time; these two formats will still
have the same e164 value. Since the original code expected the e164
column to be unique, in this situation the Dialer thought the number
was not blocked, resulting in a crash when attempting to block the
number a second time.
This CL changes the logic so multiple rows with the same e164 value
are expected.
Change-Id: I90995046df74b8ec2198eab1ef56a13f20dc1398
Fixes: 27724726
diff --git a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
index 7af1a13..52ef49a 100644
--- a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
+++ b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java
@@ -158,7 +158,13 @@
new Listener() {
@Override
protected void onQueryComplete(int token, Object cookie, Cursor cursor) {
- if (cursor == null || cursor.getCount() != 1) {
+ /*
+ * In the frameworking blocking, numbers can be blocked in both e164 format
+ * and not, resulting in multiple rows being returned for this query. For
+ * example, both '16502530000' and '6502530000' can exist at the same time
+ * and will be returned by this query.
+ */
+ if (cursor == null || cursor.getCount() == 0) {
listener.onCheckComplete(null);
return;
}
diff --git a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java
index 28fdda0..625f3fd 100644
--- a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java
+++ b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java
@@ -47,6 +47,7 @@
private static final String NUMBER = "6502530000";
private static final String COUNTRY_ISO = "US";
private static final Integer ID = 1;
+ private static final Integer ID2 = 2;
private static final Uri BLOCKED_NUMBER_URI_N = CompatUtils.isNCompatible() ?
Uri.withAppendedPath(BlockedNumberContract.AUTHORITY_URI, "blocked") : null;
private static final Uri BLOCKED_NUMBER_URI_M =
@@ -177,6 +178,26 @@
mContentProvider.verify();
}
+ public void testIsBlockedNumber_MultipleResults() throws Throwable {
+ if (CompatUtils.isNCompatible()) {
+ newIsBlockedNumberExpectedQuery().returnRow(ID).returnRow(ID2);
+ } else {
+ newIsBlockedNumberExpectedQuery().returnRow(ID, FilteredNumberTypes.BLOCKED_NUMBER)
+ .returnRow(ID2, FilteredNumberTypes.BLOCKED_NUMBER);
+ }
+ final CheckBlockedListener listener = new CheckBlockedListener();
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ new FilteredNumberAsyncQueryHandler(mContentResolver)
+ .isBlockedNumber(listener, NUMBER, COUNTRY_ISO);
+ }
+ });
+ // When there are multiple matches, the first is returned
+ assertEquals(ID, listener.waitForCallback());
+ mContentProvider.verify();
+ }
+
public void testBlockNumber_Disabled() throws Throwable {
if (!CompatUtils.isNCompatible()) {
return;