diff options
| author | 2016-01-11 14:05:15 -0800 | |
|---|---|---|
| committer | 2016-01-13 12:41:54 -0800 | |
| commit | cbd0ed2944875660ffc9232b45f54f514b00d082 (patch) | |
| tree | f3af46d8efa458fcab33afac57325b0f8647cb90 | |
| parent | de41d3cd5a28cce3ba7f0fa23ba7c41ef93b223d (diff) | |
API for blocked number provider
Bug 26232372
Change-Id: I4d243c00ab9f02af527a96d7b549abfe7876f565
| -rw-r--r-- | api/current.txt | 16 | ||||
| -rw-r--r-- | api/system-current.txt | 16 | ||||
| -rw-r--r-- | api/test-current.txt | 16 | ||||
| -rw-r--r-- | core/java/android/provider/BlockedNumberContract.java | 134 |
4 files changed, 182 insertions, 0 deletions
diff --git a/api/current.txt b/api/current.txt index e7c25e469adf..7b183a52478f 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 8d4caefa3c74..4d1776d28995 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 5f1f63f37745..c81bb0831101 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 000000000000..03e0e11f4f74 --- /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. + * <p>TYPE: long</p> + */ + public static final String COLUMN_ID = "_id"; + + /** + * Phone number to block. + * <p>Must be specified in {@code insert}. + * <p>TYPE: String</p> + */ + 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. + * <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> + */ + 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); + } +} |