diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-02-28 15:28:45 -0800 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2016-03-01 10:18:44 -0800 |
commit | f0e0ce60005a5732c65bddf290cd758c517d99db (patch) | |
tree | 6af138b0372d083aa17ed9f13b76104c1b3ba6a7 | |
parent | 60fb1dc7afe8fe6079785724a21bbffbdb4eac88 (diff) |
Using FilteredNumCompat for unblock
+ This CL updates the FilteredNumberAsyncQueryHandler#unblock methods
to use the FilteredNumberCompat class to properly choose between the
original Dialer blocking implementation and new blocking.
Bug=26664600
Change-Id: I528604eeafa4f7fa131cb1898d57a87708ba58b5
-rw-r--r-- | src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java | 23 | ||||
-rw-r--r-- | tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java | 80 |
2 files changed, 89 insertions, 14 deletions
diff --git a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java index 7279911ce..7af1a1339 100644 --- a/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java +++ b/src/com/android/dialer/database/FilteredNumberAsyncQueryHandler.java @@ -115,14 +115,6 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { } } - private static Uri getContentUri(Integer id) { - Uri uri = FilteredNumber.CONTENT_URI; - if (id != null) { - uri = ContentUris.withAppendedId(uri, id); - } - return uri; - } - public final void incrementFilteredCount(Integer id) { // No concept of counts with new filtering if (FilteredNumberCompat.useNewFiltering()) { @@ -228,22 +220,25 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { /** * Unblocks the number with the given id. * - * @param listener The {@link OnUnblockNumberListener} called after the number is unblocked. + * @param listener (optional) The {@link OnUnblockNumberListener} called after the number is + * unblocked. * @param id The id of the number to unblock. */ - public void unblock(final OnUnblockNumberListener listener, Integer id) { + public void unblock(@Nullable final OnUnblockNumberListener listener, Integer id) { if (id == null) { throw new IllegalArgumentException("Null id passed into unblock"); } - unblock(listener, getContentUri(id)); + unblock(listener, FilteredNumberCompat.getContentUri(id)); } /** * Removes row from database. + * @param listener (optional) The {@link OnUnblockNumberListener} called after the number is + * unblocked. * @param uri The uri of row to remove, from - * {@link FilteredNumberAsyncQueryHandler#blockNumber}. + * {@link FilteredNumberAsyncQueryHandler#blockNumber}. */ - public void unblock(final OnUnblockNumberListener listener, final Uri uri) { + public void unblock(@Nullable final OnUnblockNumberListener listener, final Uri uri) { startQuery(NO_TOKEN, new Listener() { @Override public void onQueryComplete(int token, Object cookie, Cursor cursor) { @@ -256,7 +251,7 @@ public class FilteredNumberAsyncQueryHandler extends AsyncQueryHandler { cursor.moveToFirst(); final ContentValues values = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, values); - values.remove(FilteredNumberColumns._ID); + values.remove(FilteredNumberCompat.getIdColumnName()); startDelete(NO_TOKEN, new Listener() { @Override diff --git a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java index 88f38fd62..28fdda0dc 100644 --- a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java +++ b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java @@ -16,6 +16,7 @@ package com.android.dialer.database; +import android.content.ContentUris; import android.content.ContentValues; import android.net.Uri; import android.provider.BlockedNumberContract; @@ -31,6 +32,7 @@ import com.android.dialer.compat.FilteredNumberCompat; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnBlockNumberListener; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener; +import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnUnblockNumberListener; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; import com.android.dialer.database.FilteredNumberContract.FilteredNumberSources; import com.android.dialer.database.FilteredNumberContract.FilteredNumberTypes; @@ -51,6 +53,8 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase Uri.withAppendedPath(FilteredNumberContract.AUTHORITY_URI, "filtered_numbers_table"); private static final Uri BLOCKED_NUMBER_URI = CompatUtils.isNCompatible() ? BLOCKED_NUMBER_URI_N : BLOCKED_NUMBER_URI_M; + private static final Uri BLOCKED_NUMBER_URI_WITH_ID = + ContentUris.withAppendedId(BLOCKED_NUMBER_URI, ID); private static final Uri EXPECTED_URI = Uri.fromParts("android", "google", "dialer"); private final MockContentResolver mContentResolver = new MockContentResolver(); @@ -226,6 +230,60 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase mContentProvider.verify(); } + public void testUnblockNumber_Disabled() throws Throwable { + if (!CompatUtils.isNCompatible()) { + return; + } + FilteredNumberCompat.setIsEnabledForTest(false); + final MockContentResolver resolver = new MockContentResolver(); + MockContentProvider disabledProvider = new MockContentProvider(); + resolver.addProvider(FilteredNumberContract.AUTHORITY, disabledProvider); + + Uri uriWithId = ContentUris.withAppendedId(BLOCKED_NUMBER_URI_M, ID); + disabledProvider.expectQuery(uriWithId) + .withProjection(null) + .withDefaultProjection(FilteredNumberCompat.getIdColumnName()) + .withSelection(null, null) + .withSortOrder(null) + .returnRow(ID); + disabledProvider.expectDelete(uriWithId).returnRowsAffected(1); + final UnblockNumberListener listener = new UnblockNumberListener(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + new FilteredNumberAsyncQueryHandler(resolver).unblock(listener, ID); + } + }); + assertNotNull(listener.waitForCallback()); + disabledProvider.verify(); + } + + public void testUnblockNumber_NullId() { + try { + new FilteredNumberAsyncQueryHandler(mContentResolver).unblock(null, (Integer) null); + fail(); + } catch (IllegalArgumentException e) {} + } + + public void testUnblockNumber() throws Throwable { + mContentProvider.expectQuery(BLOCKED_NUMBER_URI_WITH_ID) + .withProjection(null) + .withDefaultProjection(FilteredNumberCompat.getIdColumnName()) + .withSelection(null, null) + .withSortOrder(null) + .returnRow(ID); + mContentProvider.expectDelete(BLOCKED_NUMBER_URI_WITH_ID).returnRowsAffected(1); + final UnblockNumberListener listener = new UnblockNumberListener(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + new FilteredNumberAsyncQueryHandler(mContentResolver).unblock(listener, ID); + } + }); + assertNotNull(listener.waitForCallback()); + mContentProvider.verify(); + } + private Query newIsBlockedNumberExpectedQuery() { if (CompatUtils.isNCompatible()) { return newIsBlockedNumberExpectedQueryN(); @@ -353,4 +411,26 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase return uri; } } + + private class UnblockNumberListener implements OnUnblockNumberListener { + public final CountDownLatch onUnblockCompleteCalled; + public Integer result; + + public UnblockNumberListener() { + onUnblockCompleteCalled = new CountDownLatch(1); + } + + @Override + public void onUnblockComplete(int rows, ContentValues values) { + result = rows; + onUnblockCompleteCalled.countDown(); + } + + public Integer waitForCallback() throws InterruptedException { + if (!onUnblockCompleteCalled.await(5000, TimeUnit.MILLISECONDS)) { + throw new IllegalStateException("Waiting on callback timed out."); + } + return result; + } + } } |