BlockedNumberContract API changes:
1. Add a method isProviderSupportedForCurrentUser for multi-user scenarios.
2. Remove STRIPPED_NUMBER column.
BUG: 26232372
Change-Id: Ida703d7a873915a02cd7918ed297cf039a7956c9
diff --git a/api/current.txt b/api/current.txt
index 98f04e8..21e5392 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -30135,6 +30135,7 @@
}
public class BlockedNumberContract {
+ method public static boolean canCurrentUserBlockNumbers(android.content.Context);
method public static boolean isBlocked(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;
@@ -30144,7 +30145,6 @@
field public static final java.lang.String COLUMN_E164_NUMBER = "e164_number";
field public static final java.lang.String COLUMN_ID = "_id";
field public static final java.lang.String COLUMN_ORIGINAL_NUMBER = "original_number";
- field public static final java.lang.String COLUMN_STRIPPED_NUMBER = "stripped_number";
field public static final java.lang.String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/blocked_number";
field public static final java.lang.String CONTENT_TYPE = "vnd.android.cursor.dir/blocked_numbers";
field public static final android.net.Uri CONTENT_URI;
diff --git a/api/system-current.txt b/api/system-current.txt
index ad874ff..36d88ef 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -32182,6 +32182,7 @@
}
public class BlockedNumberContract {
+ method public static boolean canCurrentUserBlockNumbers(android.content.Context);
method public static boolean isBlocked(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;
@@ -32191,7 +32192,6 @@
field public static final java.lang.String COLUMN_E164_NUMBER = "e164_number";
field public static final java.lang.String COLUMN_ID = "_id";
field public static final java.lang.String COLUMN_ORIGINAL_NUMBER = "original_number";
- field public static final java.lang.String COLUMN_STRIPPED_NUMBER = "stripped_number";
field public static final java.lang.String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/blocked_number";
field public static final java.lang.String CONTENT_TYPE = "vnd.android.cursor.dir/blocked_numbers";
field public static final android.net.Uri CONTENT_URI;
diff --git a/api/test-current.txt b/api/test-current.txt
index 5e6ce39..f30108e 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -30148,6 +30148,7 @@
}
public class BlockedNumberContract {
+ method public static boolean canCurrentUserBlockNumbers(android.content.Context);
method public static boolean isBlocked(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;
@@ -30157,7 +30158,6 @@
field public static final java.lang.String COLUMN_E164_NUMBER = "e164_number";
field public static final java.lang.String COLUMN_ID = "_id";
field public static final java.lang.String COLUMN_ORIGINAL_NUMBER = "original_number";
- field public static final java.lang.String COLUMN_STRIPPED_NUMBER = "stripped_number";
field public static final java.lang.String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/blocked_number";
field public static final java.lang.String CONTENT_TYPE = "vnd.android.cursor.dir/blocked_numbers";
field public static final android.net.Uri CONTENT_URI;
diff --git a/core/java/android/provider/BlockedNumberContract.java b/core/java/android/provider/BlockedNumberContract.java
index 2a9d4ae..7a9d062 100644
--- a/core/java/android/provider/BlockedNumberContract.java
+++ b/core/java/android/provider/BlockedNumberContract.java
@@ -91,14 +91,6 @@
/**
* Phone number to block. The system generates it from {@link #COLUMN_ORIGINAL_NUMBER}
* by removing all formatting characters.
- * <p>Must NOT be specified in {@code insert}.
- * <p>TYPE: String</p>
- */
- public static final String COLUMN_STRIPPED_NUMBER = "stripped_number";
-
- /**
- * Phone number to block. The system generates it from {@link #COLUMN_ORIGINAL_NUMBER}
- * by removing all formatting characters.
* <p>Optional in {@code insert}. When not specified, the system tries to generate it
* assuming the current country. (Which will still be null if the number is not valid.)
* <p>TYPE: String</p>
@@ -112,17 +104,32 @@
/** @hide */
public static final String RES_NUMBER_IS_BLOCKED = "blocked";
+ /** @hide */
+ public static final String METHOD_CAN_CURRENT_USER_BLOCK_NUMBERS =
+ "can_current_user_block_numbers";
+
+ /** @hide */
+ public static final String RES_CAN_BLOCK_NUMBERS = "can_block";
+
/**
* Returns whether a given number is in the blocked list.
- *
- * TODO This should probably catch IllegalArgumentException to guard against the case where
- * the provider is encrypted or the user is not running.
- * (See addEntryAndRemoveExpiredEntries() in
- * http://ag/#/c/844426/3/core/java/android/provider/CallLog.java)
+ * <p> Note that if the {@link #canCurrentUserBlockNumbers} is {@code false} for the user
+ * context {@code context}, this method will throw an {@link UnsupportedOperationException}.
*/
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);
}
+
+ /**
+ * Returns {@code true} if blocking numbers is supported for the current user.
+ * <p> Typically, blocking numbers is only supported for the primary user.
+ */
+ public static boolean canCurrentUserBlockNumbers(Context context) {
+ final Bundle res = context.getContentResolver().call(
+ AUTHORITY_URI, METHOD_CAN_CURRENT_USER_BLOCK_NUMBERS, null, null);
+ return res != null && res.getBoolean(RES_CAN_BLOCK_NUMBERS, false);
+ }
+
}