BlockedNumberContract.java revision cbd0ed2944875660ffc9232b45f54f514b00d082
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>Must NOT be specified in {@code insert}. 95 * <p>TYPE: String</p> 96 */ 97 public static final String COLUMN_STRIPPED_NUMBER = "stripped_number"; 98 99 /** 100 * Phone number to block. The system generates it from {@link #COLUMN_ORIGINAL_NUMBER} 101 * by removing all formatting characters. 102 * <p>Optional in {@code insert}. When not specified, the system tries to generate it 103 * assuming the current country. (Which will still be null if the number is not valid.) 104 * <p>TYPE: String</p> 105 */ 106 public static final String COLUMN_E164_NUMBER = "e164_number"; 107 108 /** @hide */ 109 public static final String COLUMN_INDEX_STRIPPED = "index_stripped"; 110 111 /** @hide */ 112 public static final String COLUMN_INDEX_E164 = "index_e164"; 113 } 114 115 /** @hide */ 116 public static final String METHOD_IS_BLOCKED = "is_blocked"; 117 118 /** @hide */ 119 public static final String RES_NUMBER_IS_BLOCKED = "blocked"; 120 121 /** 122 * Returns whether a given number is in the blocked list. 123 * 124 * TODO This should probably catch IllegalArgumentException to guard against the case where 125 * the provider is encrypted or the user is not running. 126 * (See addEntryAndRemoveExpiredEntries() in 127 * http://ag/#/c/844426/3/core/java/android/provider/CallLog.java) 128 */ 129 public static boolean isBlocked(Context context, String phoneNumber) { 130 final Bundle res = context.getContentResolver().call(AUTHORITY_URI, 131 METHOD_IS_BLOCKED, phoneNumber, null); 132 return res != null && res.getBoolean(RES_NUMBER_IS_BLOCKED, false); 133 } 134} 135