The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | */ |
| 16 | |
Debashish Chatterjee | 29c1575 | 2011-07-04 09:48:13 +0100 | [diff] [blame] | 17 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | package android.provider; |
| 19 | |
| 20 | import android.content.ContentResolver; |
| 21 | import android.content.ContentValues; |
| 22 | import android.content.Context; |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 23 | import android.database.Cursor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.net.Uri; |
Daisuke Miyakawa | e23362a | 2012-05-06 16:54:25 -0700 | [diff] [blame] | 25 | import android.provider.ContactsContract.CommonDataKinds.Callable; |
Daisuke Miyakawa | f468591 | 2011-06-25 12:31:13 -0700 | [diff] [blame] | 26 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 27 | import android.provider.ContactsContract.DataUsageFeedback; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.text.TextUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Chiao Cheng | 509e1f1 | 2012-08-01 15:40:55 -0700 | [diff] [blame] | 30 | import com.android.internal.telephony.CallerInfo; |
| 31 | import com.android.internal.telephony.PhoneConstants; |
| 32 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | /** |
| 34 | * The CallLog provider contains information about placed and received calls. |
| 35 | */ |
| 36 | public class CallLog { |
| 37 | public static final String AUTHORITY = "call_log"; |
| 38 | |
| 39 | /** |
| 40 | * The content:// style URL for this provider |
| 41 | */ |
| 42 | public static final Uri CONTENT_URI = |
| 43 | Uri.parse("content://" + AUTHORITY); |
| 44 | |
| 45 | /** |
| 46 | * Contains the recent calls. |
| 47 | */ |
| 48 | public static class Calls implements BaseColumns { |
| 49 | /** |
| 50 | * The content:// style URL for this table |
| 51 | */ |
| 52 | public static final Uri CONTENT_URI = |
| 53 | Uri.parse("content://call_log/calls"); |
| 54 | |
| 55 | /** |
| 56 | * The content:// style URL for filtering this table on phone numbers |
| 57 | */ |
| 58 | public static final Uri CONTENT_FILTER_URI = |
| 59 | Uri.parse("content://call_log/calls/filter"); |
| 60 | |
| 61 | /** |
Chiao Cheng | 509e1f1 | 2012-08-01 15:40:55 -0700 | [diff] [blame] | 62 | * Query parameter used to limit the number of call logs returned. |
| 63 | * <p> |
| 64 | * TYPE: integer |
| 65 | */ |
| 66 | public static final String LIMIT_PARAM_KEY = "limit"; |
| 67 | |
| 68 | /** |
| 69 | * Query parameter used to specify the starting record to return. |
| 70 | * <p> |
| 71 | * TYPE: integer |
| 72 | */ |
| 73 | public static final String OFFSET_PARAM_KEY = "offset"; |
| 74 | |
| 75 | /** |
Flavio Lerda | 9ef78f0 | 2011-06-29 10:51:59 +0100 | [diff] [blame] | 76 | * An optional URI parameter which instructs the provider to allow the operation to be |
| 77 | * applied to voicemail records as well. |
| 78 | * <p> |
| 79 | * TYPE: Boolean |
| 80 | * <p> |
| 81 | * Using this parameter with a value of {@code true} will result in a security error if the |
| 82 | * calling package does not have appropriate permissions to access voicemails. |
| 83 | * |
| 84 | * @hide |
| 85 | */ |
| 86 | public static final String ALLOW_VOICEMAILS_PARAM_KEY = "allow_voicemails"; |
| 87 | |
| 88 | /** |
Yorke Lee | 0a17393 | 2013-12-12 17:29:03 -0800 | [diff] [blame] | 89 | * Content uri used to access call log entries, including voicemail records. You must have |
| 90 | * the READ_CALL_LOG and WRITE_CALL_LOG permissions to read and write to the call log. |
Flavio Lerda | 9ef78f0 | 2011-06-29 10:51:59 +0100 | [diff] [blame] | 91 | */ |
| 92 | public static final Uri CONTENT_URI_WITH_VOICEMAIL = CONTENT_URI.buildUpon() |
| 93 | .appendQueryParameter(ALLOW_VOICEMAILS_PARAM_KEY, "true") |
| 94 | .build(); |
| 95 | |
| 96 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | * The default sort order for this table |
| 98 | */ |
| 99 | public static final String DEFAULT_SORT_ORDER = "date DESC"; |
| 100 | |
| 101 | /** |
| 102 | * The MIME type of {@link #CONTENT_URI} and {@link #CONTENT_FILTER_URI} |
| 103 | * providing a directory of calls. |
| 104 | */ |
| 105 | public static final String CONTENT_TYPE = "vnd.android.cursor.dir/calls"; |
| 106 | |
| 107 | /** |
| 108 | * The MIME type of a {@link #CONTENT_URI} sub-directory of a single |
| 109 | * call. |
| 110 | */ |
| 111 | public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/calls"; |
| 112 | |
| 113 | /** |
Yusuf T. Mobile | f6737d3 | 2009-05-15 10:56:36 -0700 | [diff] [blame] | 114 | * The type of the call (incoming, outgoing or missed). |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | * <P>Type: INTEGER (int)</P> |
| 116 | */ |
| 117 | public static final String TYPE = "type"; |
| 118 | |
Debashish Chatterjee | 412359f | 2011-06-06 17:35:59 +0100 | [diff] [blame] | 119 | /** Call log type for incoming calls. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | public static final int INCOMING_TYPE = 1; |
Debashish Chatterjee | 412359f | 2011-06-06 17:35:59 +0100 | [diff] [blame] | 121 | /** Call log type for outgoing calls. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | public static final int OUTGOING_TYPE = 2; |
Debashish Chatterjee | 412359f | 2011-06-06 17:35:59 +0100 | [diff] [blame] | 123 | /** Call log type for missed calls. */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 124 | public static final int MISSED_TYPE = 3; |
Yorke Lee | a5f6a93 | 2013-11-22 18:17:23 -0800 | [diff] [blame] | 125 | /** Call log type for voicemails. */ |
Debashish Chatterjee | 412359f | 2011-06-06 17:35:59 +0100 | [diff] [blame] | 126 | public static final int VOICEMAIL_TYPE = 4; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | |
| 128 | /** |
| 129 | * The phone number as the user entered it. |
| 130 | * <P>Type: TEXT</P> |
| 131 | */ |
| 132 | public static final String NUMBER = "number"; |
| 133 | |
| 134 | /** |
Yorke Lee | 49e1cf9 | 2013-09-10 14:39:24 -0700 | [diff] [blame] | 135 | * The number presenting rules set by the network. |
| 136 | * |
| 137 | * <p> |
| 138 | * Allowed values: |
| 139 | * <ul> |
| 140 | * <li>{@link #PRESENTATION_ALLOWED}</li> |
| 141 | * <li>{@link #PRESENTATION_RESTRICTED}</li> |
| 142 | * <li>{@link #PRESENTATION_UNKNOWN}</li> |
| 143 | * <li>{@link #PRESENTATION_PAYPHONE}</li> |
| 144 | * </ul> |
| 145 | * </p> |
| 146 | * |
Jay Shrauner | d88eb71 | 2013-06-10 10:10:11 -0700 | [diff] [blame] | 147 | * <P>Type: INTEGER</P> |
| 148 | */ |
| 149 | public static final String NUMBER_PRESENTATION = "presentation"; |
| 150 | |
| 151 | /** Number is allowed to display for caller id. */ |
| 152 | public static final int PRESENTATION_ALLOWED = 1; |
| 153 | /** Number is blocked by user. */ |
| 154 | public static final int PRESENTATION_RESTRICTED = 2; |
| 155 | /** Number is not specified or unknown by network. */ |
| 156 | public static final int PRESENTATION_UNKNOWN = 3; |
| 157 | /** Number is a pay phone. */ |
| 158 | public static final int PRESENTATION_PAYPHONE = 4; |
| 159 | |
| 160 | /** |
Bai Tao | 224744c | 2010-08-31 09:59:13 +0800 | [diff] [blame] | 161 | * The ISO 3166-1 two letters country code of the country where the |
| 162 | * user received or made the call. |
| 163 | * <P> |
| 164 | * Type: TEXT |
| 165 | * </P> |
Bai Tao | 224744c | 2010-08-31 09:59:13 +0800 | [diff] [blame] | 166 | */ |
| 167 | public static final String COUNTRY_ISO = "countryiso"; |
| 168 | |
| 169 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | * The date the call occured, in milliseconds since the epoch |
| 171 | * <P>Type: INTEGER (long)</P> |
| 172 | */ |
| 173 | public static final String DATE = "date"; |
| 174 | |
| 175 | /** |
| 176 | * The duration of the call in seconds |
| 177 | * <P>Type: INTEGER (long)</P> |
| 178 | */ |
| 179 | public static final String DURATION = "duration"; |
| 180 | |
| 181 | /** |
| 182 | * Whether or not the call has been acknowledged |
| 183 | * <P>Type: INTEGER (boolean)</P> |
| 184 | */ |
| 185 | public static final String NEW = "new"; |
| 186 | |
| 187 | /** |
| 188 | * The cached name associated with the phone number, if it exists. |
| 189 | * This value is not guaranteed to be current, if the contact information |
| 190 | * associated with this number has changed. |
| 191 | * <P>Type: TEXT</P> |
| 192 | */ |
| 193 | public static final String CACHED_NAME = "name"; |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 194 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | /** |
| 196 | * The cached number type (Home, Work, etc) associated with the |
| 197 | * phone number, if it exists. |
| 198 | * This value is not guaranteed to be current, if the contact information |
| 199 | * associated with this number has changed. |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 200 | * <P>Type: INTEGER</P> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | */ |
| 202 | public static final String CACHED_NUMBER_TYPE = "numbertype"; |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 203 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | /** |
| 205 | * The cached number label, for a custom number type, associated with the |
| 206 | * phone number, if it exists. |
| 207 | * This value is not guaranteed to be current, if the contact information |
| 208 | * associated with this number has changed. |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 209 | * <P>Type: TEXT</P> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | */ |
| 211 | public static final String CACHED_NUMBER_LABEL = "numberlabel"; |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | /** |
Debashish Chatterjee | 412359f | 2011-06-06 17:35:59 +0100 | [diff] [blame] | 214 | * URI of the voicemail entry. Populated only for {@link #VOICEMAIL_TYPE}. |
| 215 | * <P>Type: TEXT</P> |
Debashish Chatterjee | 412359f | 2011-06-06 17:35:59 +0100 | [diff] [blame] | 216 | */ |
| 217 | public static final String VOICEMAIL_URI = "voicemail_uri"; |
| 218 | |
| 219 | /** |
Flavio Lerda | 651212d | 2011-07-21 16:53:59 +0100 | [diff] [blame] | 220 | * Whether this item has been read or otherwise consumed by the user. |
| 221 | * <p> |
| 222 | * Unlike the {@link #NEW} field, which requires the user to have acknowledged the |
| 223 | * existence of the entry, this implies the user has interacted with the entry. |
| 224 | * <P>Type: INTEGER (boolean)</P> |
Flavio Lerda | 651212d | 2011-07-21 16:53:59 +0100 | [diff] [blame] | 225 | */ |
| 226 | public static final String IS_READ = "is_read"; |
| 227 | |
| 228 | /** |
Flavio Lerda | 270f930 | 2011-08-09 12:01:13 +0100 | [diff] [blame] | 229 | * A geocoded location for the number associated with this call. |
| 230 | * <p> |
| 231 | * The string represents a city, state, or country associated with the number. |
| 232 | * <P>Type: TEXT</P> |
Flavio Lerda | 270f930 | 2011-08-09 12:01:13 +0100 | [diff] [blame] | 233 | */ |
| 234 | public static final String GEOCODED_LOCATION = "geocoded_location"; |
| 235 | |
| 236 | /** |
Flavio Lerda | 2d538d4 | 2011-08-16 08:29:06 +0100 | [diff] [blame] | 237 | * The cached URI to look up the contact associated with the phone number, if it exists. |
Yorke Lee | a5f6a93 | 2013-11-22 18:17:23 -0800 | [diff] [blame] | 238 | * This value may not be current if the contact information associated with this number |
| 239 | * has changed. |
Flavio Lerda | 2d538d4 | 2011-08-16 08:29:06 +0100 | [diff] [blame] | 240 | * <P>Type: TEXT</P> |
Flavio Lerda | 2d538d4 | 2011-08-16 08:29:06 +0100 | [diff] [blame] | 241 | */ |
| 242 | public static final String CACHED_LOOKUP_URI = "lookup_uri"; |
| 243 | |
| 244 | /** |
| 245 | * The cached phone number of the contact which matches this entry, if it exists. |
Yorke Lee | a5f6a93 | 2013-11-22 18:17:23 -0800 | [diff] [blame] | 246 | * This value may not be current if the contact information associated with this number |
| 247 | * has changed. |
Flavio Lerda | 2d538d4 | 2011-08-16 08:29:06 +0100 | [diff] [blame] | 248 | * <P>Type: TEXT</P> |
Flavio Lerda | 2d538d4 | 2011-08-16 08:29:06 +0100 | [diff] [blame] | 249 | */ |
| 250 | public static final String CACHED_MATCHED_NUMBER = "matched_number"; |
| 251 | |
| 252 | /** |
Yorke Lee | a5f6a93 | 2013-11-22 18:17:23 -0800 | [diff] [blame] | 253 | * The cached normalized(E164) version of the phone number, if it exists. |
| 254 | * This value may not be current if the contact information associated with this number |
| 255 | * has changed. |
Flavio Lerda | 2d538d4 | 2011-08-16 08:29:06 +0100 | [diff] [blame] | 256 | * <P>Type: TEXT</P> |
Flavio Lerda | 2d538d4 | 2011-08-16 08:29:06 +0100 | [diff] [blame] | 257 | */ |
| 258 | public static final String CACHED_NORMALIZED_NUMBER = "normalized_number"; |
| 259 | |
| 260 | /** |
| 261 | * The cached photo id of the picture associated with the phone number, if it exists. |
Yorke Lee | a5f6a93 | 2013-11-22 18:17:23 -0800 | [diff] [blame] | 262 | * This value may not be current if the contact information associated with this number |
| 263 | * has changed. |
Flavio Lerda | 2d538d4 | 2011-08-16 08:29:06 +0100 | [diff] [blame] | 264 | * <P>Type: INTEGER (long)</P> |
Flavio Lerda | 2d538d4 | 2011-08-16 08:29:06 +0100 | [diff] [blame] | 265 | */ |
| 266 | public static final String CACHED_PHOTO_ID = "photo_id"; |
| 267 | |
| 268 | /** |
Yorke Lee | a5f6a93 | 2013-11-22 18:17:23 -0800 | [diff] [blame] | 269 | * The cached phone number, formatted with formatting rules based on the country the |
| 270 | * user was in when the call was made or received. |
| 271 | * This value is not guaranteed to be present, and may not be current if the contact |
| 272 | * information associated with this number |
| 273 | * has changed. |
Flavio Lerda | 0fce15b | 2011-10-01 18:55:33 +0100 | [diff] [blame] | 274 | * <P>Type: TEXT</P> |
Flavio Lerda | 0fce15b | 2011-10-01 18:55:33 +0100 | [diff] [blame] | 275 | */ |
| 276 | public static final String CACHED_FORMATTED_NUMBER = "formatted_number"; |
| 277 | |
| 278 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | * Adds a call to the call log. |
| 280 | * |
| 281 | * @param ci the CallerInfo object to get the target contact from. Can be null |
| 282 | * if the contact is unknown. |
| 283 | * @param context the context used to get the ContentResolver |
| 284 | * @param number the phone number to be added to the calls db |
Jay Shrauner | d88eb71 | 2013-06-10 10:10:11 -0700 | [diff] [blame] | 285 | * @param presentation enum value from PhoneConstants.PRESENTATION_xxx, which |
| 286 | * is set by the network and denotes the number presenting rules for |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 287 | * "allowed", "payphone", "restricted" or "unknown" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 288 | * @param callType enumerated values for "incoming", "outgoing", or "missed" |
| 289 | * @param start time stamp for the call in milliseconds |
| 290 | * @param duration call duration in seconds |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 291 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | * {@hide} |
| 293 | */ |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 294 | public static Uri addCall(CallerInfo ci, Context context, String number, |
The Android Open Source Project | 1059253 | 2009-03-18 17:39:46 -0700 | [diff] [blame] | 295 | int presentation, int callType, long start, int duration) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | final ContentResolver resolver = context.getContentResolver(); |
Jay Shrauner | d88eb71 | 2013-06-10 10:10:11 -0700 | [diff] [blame] | 297 | int numberPresentation = PRESENTATION_ALLOWED; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 298 | |
Jay Shrauner | d88eb71 | 2013-06-10 10:10:11 -0700 | [diff] [blame] | 299 | // Remap network specified number presentation types |
| 300 | // PhoneConstants.PRESENTATION_xxx to calllog number presentation types |
| 301 | // Calls.PRESENTATION_xxx, in order to insulate the persistent calllog |
| 302 | // from any future radio changes. |
| 303 | // If the number field is empty set the presentation type to Unknown. |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 304 | if (presentation == PhoneConstants.PRESENTATION_RESTRICTED) { |
Jay Shrauner | d88eb71 | 2013-06-10 10:10:11 -0700 | [diff] [blame] | 305 | numberPresentation = PRESENTATION_RESTRICTED; |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 306 | } else if (presentation == PhoneConstants.PRESENTATION_PAYPHONE) { |
Jay Shrauner | d88eb71 | 2013-06-10 10:10:11 -0700 | [diff] [blame] | 307 | numberPresentation = PRESENTATION_PAYPHONE; |
Pauyl l Berman | e1dc2ba | 2009-07-10 18:27:36 -0400 | [diff] [blame] | 308 | } else if (TextUtils.isEmpty(number) |
Wink Saville | a639b31 | 2012-07-10 12:37:54 -0700 | [diff] [blame] | 309 | || presentation == PhoneConstants.PRESENTATION_UNKNOWN) { |
Jay Shrauner | d88eb71 | 2013-06-10 10:10:11 -0700 | [diff] [blame] | 310 | numberPresentation = PRESENTATION_UNKNOWN; |
| 311 | } |
| 312 | if (numberPresentation != PRESENTATION_ALLOWED) { |
| 313 | number = ""; |
| 314 | if (ci != null) { |
| 315 | ci.name = ""; |
| 316 | } |
Wink Saville | dda5391 | 2009-05-28 17:32:34 -0700 | [diff] [blame] | 317 | } |
Pauyl l Berman | e1dc2ba | 2009-07-10 18:27:36 -0400 | [diff] [blame] | 318 | |
Jay Shrauner | d88eb71 | 2013-06-10 10:10:11 -0700 | [diff] [blame] | 319 | ContentValues values = new ContentValues(6); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | |
| 321 | values.put(NUMBER, number); |
Jay Shrauner | d88eb71 | 2013-06-10 10:10:11 -0700 | [diff] [blame] | 322 | values.put(NUMBER_PRESENTATION, Integer.valueOf(numberPresentation)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | values.put(TYPE, Integer.valueOf(callType)); |
| 324 | values.put(DATE, Long.valueOf(start)); |
| 325 | values.put(DURATION, Long.valueOf(duration)); |
| 326 | values.put(NEW, Integer.valueOf(1)); |
Debashish Chatterjee | 4efaf4b | 2011-08-11 16:47:16 +0100 | [diff] [blame] | 327 | if (callType == MISSED_TYPE) { |
| 328 | values.put(IS_READ, Integer.valueOf(0)); |
| 329 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 330 | if (ci != null) { |
| 331 | values.put(CACHED_NAME, ci.name); |
| 332 | values.put(CACHED_NUMBER_TYPE, ci.numberType); |
| 333 | values.put(CACHED_NUMBER_LABEL, ci.numberLabel); |
| 334 | } |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 335 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | if ((ci != null) && (ci.person_id > 0)) { |
Daisuke Miyakawa | f468591 | 2011-06-25 12:31:13 -0700 | [diff] [blame] | 337 | // Update usage information for the number associated with the contact ID. |
| 338 | // We need to use both the number and the ID for obtaining a data ID since other |
| 339 | // contacts may have the same number. |
| 340 | |
| 341 | final Cursor cursor; |
| 342 | |
| 343 | // We should prefer normalized one (probably coming from |
| 344 | // Phone.NORMALIZED_NUMBER column) first. If it isn't available try others. |
| 345 | if (ci.normalizedNumber != null) { |
| 346 | final String normalizedPhoneNumber = ci.normalizedNumber; |
| 347 | cursor = resolver.query(Phone.CONTENT_URI, |
| 348 | new String[] { Phone._ID }, |
| 349 | Phone.CONTACT_ID + " =? AND " + Phone.NORMALIZED_NUMBER + " =?", |
| 350 | new String[] { String.valueOf(ci.person_id), normalizedPhoneNumber}, |
| 351 | null); |
| 352 | } else { |
| 353 | final String phoneNumber = ci.phoneNumber != null ? ci.phoneNumber : number; |
Daisuke Miyakawa | e23362a | 2012-05-06 16:54:25 -0700 | [diff] [blame] | 354 | cursor = resolver.query( |
| 355 | Uri.withAppendedPath(Callable.CONTENT_FILTER_URI, |
| 356 | Uri.encode(phoneNumber)), |
Daisuke Miyakawa | f468591 | 2011-06-25 12:31:13 -0700 | [diff] [blame] | 357 | new String[] { Phone._ID }, |
Daisuke Miyakawa | e23362a | 2012-05-06 16:54:25 -0700 | [diff] [blame] | 358 | Phone.CONTACT_ID + " =?", |
| 359 | new String[] { String.valueOf(ci.person_id) }, |
Daisuke Miyakawa | f468591 | 2011-06-25 12:31:13 -0700 | [diff] [blame] | 360 | null); |
| 361 | } |
| 362 | |
| 363 | if (cursor != null) { |
| 364 | try { |
| 365 | if (cursor.getCount() > 0 && cursor.moveToFirst()) { |
| 366 | final Uri feedbackUri = DataUsageFeedback.FEEDBACK_URI.buildUpon() |
| 367 | .appendPath(cursor.getString(0)) |
| 368 | .appendQueryParameter(DataUsageFeedback.USAGE_TYPE, |
| 369 | DataUsageFeedback.USAGE_TYPE_CALL) |
| 370 | .build(); |
| 371 | resolver.update(feedbackUri, new ContentValues(), null, null); |
| 372 | } |
| 373 | } finally { |
| 374 | cursor.close(); |
| 375 | } |
| 376 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 377 | } |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 378 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 379 | Uri result = resolver.insert(CONTENT_URI, values); |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | removeExpiredEntries(context); |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 382 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | return result; |
| 384 | } |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 385 | |
| 386 | /** |
| 387 | * Query the call log database for the last dialed number. |
| 388 | * @param context Used to get the content resolver. |
| 389 | * @return The last phone number dialed (outgoing) or an empty |
| 390 | * string if none exist yet. |
| 391 | */ |
| 392 | public static String getLastOutgoingCall(Context context) { |
| 393 | final ContentResolver resolver = context.getContentResolver(); |
| 394 | Cursor c = null; |
| 395 | try { |
| 396 | c = resolver.query( |
| 397 | CONTENT_URI, |
| 398 | new String[] {NUMBER}, |
| 399 | TYPE + " = " + OUTGOING_TYPE, |
| 400 | null, |
| 401 | DEFAULT_SORT_ORDER + " LIMIT 1"); |
| 402 | if (c == null || !c.moveToFirst()) { |
| 403 | return ""; |
| 404 | } |
| 405 | return c.getString(0); |
| 406 | } finally { |
| 407 | if (c != null) c.close(); |
| 408 | } |
| 409 | } |
| 410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | private static void removeExpiredEntries(Context context) { |
| 412 | final ContentResolver resolver = context.getContentResolver(); |
| 413 | resolver.delete(CONTENT_URI, "_id IN " + |
Nicolas Catania | b8a2aaf | 2010-01-14 10:44:02 -0800 | [diff] [blame] | 414 | "(SELECT _id FROM calls ORDER BY " + DEFAULT_SORT_ORDER |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | + " LIMIT -1 OFFSET 500)", null); |
| 416 | } |
| 417 | } |
| 418 | } |