diff --git a/api/current.txt b/api/current.txt index e7c25e469adfb..7b183a52478fb 100644 --- a/api/current.txt +++ b/api/current.txt @@ -29383,6 +29383,22 @@ package android.provider { field public static final java.lang.String _ID = "_id"; } + public class BlockedNumberContract { + 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; + } + + public static class BlockedNumberContract.BlockedNumbers { + 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; + } + public class Browser { ctor public Browser(); method public static final void sendString(android.content.Context, java.lang.String); diff --git a/api/system-current.txt b/api/system-current.txt index 8d4caefa3c742..4d1776d289954 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -31388,6 +31388,22 @@ package android.provider { field public static final java.lang.String _ID = "_id"; } + public class BlockedNumberContract { + 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; + } + + public static class BlockedNumberContract.BlockedNumbers { + 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; + } + public class Browser { ctor public Browser(); method public static final void sendString(android.content.Context, java.lang.String); diff --git a/api/test-current.txt b/api/test-current.txt index 5f1f63f37745c..c81bb08311018 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -29395,6 +29395,22 @@ package android.provider { field public static final java.lang.String _ID = "_id"; } + public class BlockedNumberContract { + 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; + } + + public static class BlockedNumberContract.BlockedNumbers { + 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; + } + public class Browser { ctor public Browser(); method public static final void sendString(android.content.Context, java.lang.String); diff --git a/core/java/android/provider/BlockedNumberContract.java b/core/java/android/provider/BlockedNumberContract.java new file mode 100644 index 0000000000000..03e0e11f4f746 --- /dev/null +++ b/core/java/android/provider/BlockedNumberContract.java @@ -0,0 +1,134 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +package android.provider; + +import android.content.Context; +import android.net.Uri; +import android.os.Bundle; + +/** + * Constants and methods to access blocked phone numbers for incoming calls and texts. + * + * TODO javadoc + * - Proper javadoc tagging. + * - Code sample? + * - Describe who can access it. + */ +public class BlockedNumberContract { + private BlockedNumberContract() { + } + + /** The authority for the contacts provider */ + public static final String AUTHORITY = "com.android.blockednumber"; + + /** A content:// style uri to the authority for the contacts provider */ + public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); + + /** + * TODO javadoc + * + * Constants to interact with the blocked phone number list. + */ + public static class BlockedNumbers { + private BlockedNumbers() { + } + + /** + * TODO javadoc + * + * Content URI for the blocked numbers. + * + * Supported operations + * blocked + * - query + * - delete + * - insert + * + * blocked/ID + * - query (selection is not supported) + * - delete (selection is not supported) + */ + public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, + "blocked"); + + /** + * The MIME type of {@link #CONTENT_URI} itself providing a directory of blocked phone + * numbers. + */ + public static final String CONTENT_TYPE = "vnd.android.cursor.dir/blocked_numbers"; + + /** + * The MIME type of a blocked phone number under {@link #CONTENT_URI}. + */ + public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/blocked_number"; + + /** + * Auto-generated ID field which monotonically increases. + *
TYPE: long
+ */ + public static final String COLUMN_ID = "_id"; + + /** + * Phone number to block. + *Must be specified in {@code insert}. + *
TYPE: String
+ */ + public static final String COLUMN_ORIGINAL_NUMBER = "original_number"; + + /** + * Phone number to block. The system generates it from {@link #COLUMN_ORIGINAL_NUMBER} + * by removing all formatting characters. + *Must NOT be specified in {@code insert}. + *
TYPE: String
+ */ + 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. + *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.) + *
TYPE: String
+ */ + public static final String COLUMN_E164_NUMBER = "e164_number"; + + /** @hide */ + public static final String COLUMN_INDEX_STRIPPED = "index_stripped"; + + /** @hide */ + public static final String COLUMN_INDEX_E164 = "index_e164"; + } + + /** @hide */ + public static final String METHOD_IS_BLOCKED = "is_blocked"; + + /** @hide */ + public static final String RES_NUMBER_IS_BLOCKED = "blocked"; + + /** + * 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) + */ + 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); + } +}