BlockedNumberContract.java revision d907c64ff9c2ab860a035f462a8f4d6e38dbf760
1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16package android.provider; 17 18import android.content.Context; 19import android.net.Uri; 20import android.os.Bundle; 21 22/** 23 * Constants and methods to access blocked phone numbers for incoming calls and texts. 24 * 25 * TODO javadoc 26 * - Proper javadoc tagging. 27 * - Code sample? 28 * - Describe who can access it. 29 */ 30public class BlockedNumberContract { 31 private BlockedNumberContract() { 32 } 33 34 /** The authority for the contacts provider */ 35 public static final String AUTHORITY = "com.android.blockednumber"; 36 37 /** A content:// style uri to the authority for the contacts provider */ 38 public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY); 39 40 /** 41 * TODO javadoc 42 * 43 * Constants to interact with the blocked phone number list. 44 */ 45 public static class BlockedNumbers { 46 private BlockedNumbers() { 47 } 48 49 /** 50 * TODO javadoc 51 * 52 * Content URI for the blocked numbers. 53 * 54 * Supported operations 55 * blocked 56 * - query 57 * - delete 58 * - insert 59 * 60 * blocked/ID 61 * - query (selection is not supported) 62 * - delete (selection is not supported) 63 */ 64 public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, 65 "blocked"); 66 67 /** 68 * The MIME type of {@link #CONTENT_URI} itself providing a directory of blocked phone 69 * numbers. 70 */ 71 public static final String CONTENT_TYPE = "vnd.android.cursor.dir/blocked_numbers"; 72 73 /** 74 * The MIME type of a blocked phone number under {@link #CONTENT_URI}. 75 */ 76 public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/blocked_number"; 77 78 /** 79 * Auto-generated ID field which monotonically increases. 80 * <p>TYPE: long</p> 81 */ 82 public static final String COLUMN_ID = "_id"; 83 84 /** 85 * Phone number to block. 86 * <p>Must be specified in {@code insert}. 87 * <p>TYPE: String</p> 88 */ 89 public static final String COLUMN_ORIGINAL_NUMBER = "original_number"; 90 91 /** 92 * Phone number to block. The system generates it from {@link #COLUMN_ORIGINAL_NUMBER} 93 * by removing all formatting characters. 94 * <p>Optional in {@code insert}. When not specified, the system tries to generate it 95 * assuming the current country. (Which will still be null if the number is not valid.) 96 * <p>TYPE: String</p> 97 */ 98 public static final String COLUMN_E164_NUMBER = "e164_number"; 99 } 100 101 /** @hide */ 102 public static final String METHOD_IS_BLOCKED = "is_blocked"; 103 104 /** @hide */ 105 public static final String RES_NUMBER_IS_BLOCKED = "blocked"; 106 107 /** @hide */ 108 public static final String METHOD_CAN_CURRENT_USER_BLOCK_NUMBERS = 109 "can_current_user_block_numbers"; 110 111 /** @hide */ 112 public static final String RES_CAN_BLOCK_NUMBERS = "can_block"; 113 114 /** 115 * Returns whether a given number is in the blocked list. 116 * <p> Note that if the {@link #canCurrentUserBlockNumbers} is {@code false} for the user 117 * context {@code context}, this method will throw an {@link UnsupportedOperationException}. 118 */ 119 public static boolean isBlocked(Context context, String phoneNumber) { 120 final Bundle res = context.getContentResolver().call(AUTHORITY_URI, 121 METHOD_IS_BLOCKED, phoneNumber, null); 122 return res != null && res.getBoolean(RES_NUMBER_IS_BLOCKED, false); 123 } 124 125 /** 126 * Returns {@code true} if blocking numbers is supported for the current user. 127 * <p> Typically, blocking numbers is only supported for the primary user. 128 */ 129 public static boolean canCurrentUserBlockNumbers(Context context) { 130 final Bundle res = context.getContentResolver().call( 131 AUTHORITY_URI, METHOD_CAN_CURRENT_USER_BLOCK_NUMBERS, null, null); 132 return res != null && res.getBoolean(RES_CAN_BLOCK_NUMBERS, false); 133 } 134 135} 136