From cdc2a4c7372d935f45d7a1de6fa199c34c3bdcf4 Mon Sep 17 00:00:00 2001 From: Abhijith Shastry Date: Wed, 23 Mar 2016 19:27:46 -0700 Subject: [PATCH] Add an unblock API to BlockedNumberContract. The delete API need not unblock a number if there are multiple copies of a single number. BUG: 27790536 Change-Id: I6391b0c095827afe85f2ee5d1756741e144c8c26 --- api/current.txt | 1 + api/system-current.txt | 1 + api/test-current.txt | 1 + .../provider/BlockedNumberContract.java | 47 ++++++++++++++++++- 4 files changed, 48 insertions(+), 2 deletions(-) diff --git a/api/current.txt b/api/current.txt index 3fc1673fc9599..86915bf6f1254 100644 --- a/api/current.txt +++ b/api/current.txt @@ -30396,6 +30396,7 @@ package android.provider { public class BlockedNumberContract { method public static boolean canCurrentUserBlockNumbers(android.content.Context); method public static boolean isBlocked(android.content.Context, java.lang.String); + method public static int unblock(android.content.Context, java.lang.String); field public static final java.lang.String AUTHORITY = "com.android.blockednumber"; field public static final android.net.Uri AUTHORITY_URI; } diff --git a/api/system-current.txt b/api/system-current.txt index 48e1bd06d6a7e..53567e1e81e11 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -32711,6 +32711,7 @@ package android.provider { public class BlockedNumberContract { method public static boolean canCurrentUserBlockNumbers(android.content.Context); method public static boolean isBlocked(android.content.Context, java.lang.String); + method public static int unblock(android.content.Context, java.lang.String); field public static final java.lang.String AUTHORITY = "com.android.blockednumber"; field public static final android.net.Uri AUTHORITY_URI; } diff --git a/api/test-current.txt b/api/test-current.txt index c1035afc9a641..4c5d62cb1b8dc 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -30465,6 +30465,7 @@ package android.provider { public class BlockedNumberContract { method public static boolean canCurrentUserBlockNumbers(android.content.Context); method public static boolean isBlocked(android.content.Context, java.lang.String); + method public static int unblock(android.content.Context, java.lang.String); field public static final java.lang.String AUTHORITY = "com.android.blockednumber"; field public static final android.net.Uri AUTHORITY_URI; } diff --git a/core/java/android/provider/BlockedNumberContract.java b/core/java/android/provider/BlockedNumberContract.java index 6fe01899f1440..e90dc9cf2e08d 100644 --- a/core/java/android/provider/BlockedNumberContract.java +++ b/core/java/android/provider/BlockedNumberContract.java @@ -15,6 +15,7 @@ */ package android.provider; +import android.annotation.WorkerThread; import android.content.Context; import android.net.Uri; import android.os.Bundle; @@ -109,6 +110,8 @@ import android.os.Bundle; * Uri uri = getContentResolver().insert(BlockedNumbers.CONTENT_URI, values); * getContentResolver().delete(uri, null, null); * + * To check if a particular number is blocked, use the method + * {@link #isBlocked(Context, String)}. *

* *
Query
@@ -120,8 +123,12 @@ import android.os.Bundle; * new String[]{BlockedNumbers.COLUMN_ID, BlockedNumbers.COLUMN_ORIGINAL_NUMBER, * BlockedNumbers.COLUMN_E164_NUMBER}, null, null, null); * - * To check if a particular number is blocked, use the method - * {@link #isBlocked(Context, String)}. + *

+ * + *
Unblock
+ *
+ *

+ * Use the method {@link #unblock(Context, String)} to unblock numbers. *

*
* @@ -205,9 +212,15 @@ public class BlockedNumberContract { /** @hide */ public static final String METHOD_IS_BLOCKED = "is_blocked"; + /** @hide */ + public static final String METHOD_UNBLOCK= "unblock"; + /** @hide */ public static final String RES_NUMBER_IS_BLOCKED = "blocked"; + /** @hide */ + public static final String RES_NUM_ROWS_DELETED = "num_deleted"; + /** @hide */ public static final String METHOD_CAN_CURRENT_USER_BLOCK_NUMBERS = "can_current_user_block_numbers"; @@ -217,15 +230,45 @@ public class BlockedNumberContract { /** * Returns whether a given number is in the blocked list. + * + *

This matches the {@code phoneNumber} against the + * {@link BlockedNumbers#COLUMN_ORIGINAL_NUMBER} column, and the E164 representation of the + * {@code phoneNumber} with the {@link BlockedNumbers#COLUMN_E164_NUMBER} column. + * *

Note that if the {@link #canCurrentUserBlockNumbers} is {@code false} for the user * context {@code context}, this method will throw an {@link UnsupportedOperationException}. */ + @WorkerThread public static boolean isBlocked(Context context, String phoneNumber) { final Bundle res = context.getContentResolver().call( AUTHORITY_URI, METHOD_IS_BLOCKED, phoneNumber, null); return res != null && res.getBoolean(RES_NUMBER_IS_BLOCKED, false); } + /** + * Unblocks the {@code phoneNumber} if it is blocked. + * + *

Returns the number of rows deleted in the blocked number provider as a result of unblock. + * + *

This deletes all rows where the {@code phoneNumber} matches the + * {@link BlockedNumbers#COLUMN_ORIGINAL_NUMBER} column or the E164 representation of the + * {@code phoneNumber} matches the {@link BlockedNumbers#COLUMN_E164_NUMBER} column. + * + *

To delete rows based on exact match with specific columns such as + * {@link BlockedNumbers#COLUMN_ID} use + * {@link android.content.ContentProvider#delete(Uri, String, String[])} with + * {@link BlockedNumbers#CONTENT_URI} URI. + * + *

Note that if the {@link #canCurrentUserBlockNumbers} is {@code false} for the user + * context {@code context}, this method will throw an {@link UnsupportedOperationException}. + */ + @WorkerThread + public static int unblock(Context context, String phoneNumber) { + final Bundle res = context.getContentResolver().call( + AUTHORITY_URI, METHOD_UNBLOCK, phoneNumber, null); + return res.getInt(RES_NUM_ROWS_DELETED, 0); + } + /** * Returns {@code true} if blocking numbers is supported for the current user. *

Typically, blocking numbers is only supported for one user at a time.