CalendarContract.java revision e4ce502d77899d273fda6ab79568f112d7d66f0a
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 17package android.provider; 18 19 20import android.annotation.SdkConstant; 21import android.annotation.SdkConstant.SdkConstantType; 22import android.app.Activity; 23import android.app.AlarmManager; 24import android.app.PendingIntent; 25import android.content.ContentProviderClient; 26import android.content.ContentResolver; 27import android.content.ContentUris; 28import android.content.ContentValues; 29import android.content.Context; 30import android.content.CursorEntityIterator; 31import android.content.Entity; 32import android.content.EntityIterator; 33import android.content.Intent; 34import android.database.Cursor; 35import android.database.DatabaseUtils; 36import android.net.Uri; 37import android.os.RemoteException; 38import android.text.format.DateUtils; 39import android.text.format.Time; 40import android.util.Log; 41 42/** 43 * <p> 44 * The contract between the calendar provider and applications. Contains 45 * definitions for the supported URIs and data columns. 46 * </p> 47 * <h3>Overview</h3> 48 * <p> 49 * CalendarContract defines the data model of calendar and event related 50 * information. This data is stored in a number of tables: 51 * </p> 52 * <ul> 53 * <li>The {@link Calendars} table holds the calendar specific information. Each 54 * row in this table contains the details for a single calendar, such as the 55 * name, color, sync info, etc.</li> 56 * <li>The {@link Events} table holds the event specific information. Each row 57 * in this table has the info for a single event. It contains information such 58 * as event title, location, start time, end time, etc. The event can occur 59 * one-time or can recur multiple times. Attendees, reminders, and extended 60 * properties are stored on separate tables and reference the {@link Events#_ID} 61 * to link them with the event.</li> 62 * <li>The {@link Instances} table holds the start and end time for occurrences 63 * of an event. Each row in this table represents a single occurrence. For 64 * one-time events there will be a 1:1 mapping of instances to events. For 65 * recurring events, multiple rows will automatically be generated which 66 * correspond to multiple occurrences of that event.</li> 67 * <li>The {@link Attendees} table holds the event attendee or guest 68 * information. Each row represents a single guest of an event. It specifies the 69 * type of guest they are and their attendance response for the event.</li> 70 * <li>The {@link Reminders} table holds the alert/notification data. Each row 71 * represents a single alert for an event. An event can have multiple reminders. 72 * The number of reminders per event is specified in 73 * {@link Calendars#MAX_REMINDERS} which is set by the Sync Adapter that owns 74 * the given calendar. Reminders are specified in minutes before the event and 75 * have a type.</li> 76 * <li>The {@link ExtendedProperties} table holds opaque data fields used by the 77 * sync adapter. The provider takes no action with items in this table except to 78 * delete them when their related events are deleted.</li> 79 * </ul> 80 * <p> 81 * Other tables include: 82 * </p> 83 * <ul> 84 * <li> 85 * {@link SyncState}, which contains free-form data maintained by the sync 86 * adapters</li> 87 * </ul> 88 * 89 */ 90public final class CalendarContract { 91 private static final String TAG = "Calendar"; 92 93 /** 94 * Broadcast Action: This is the intent that gets fired when an alarm 95 * notification needs to be posted for a reminder. 96 * 97 */ 98 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 99 public static final String ACTION_EVENT_REMINDER = "android.intent.action.EVENT_REMINDER"; 100 101 /** 102 * Activity Action: Display the event to the user in the custom app as 103 * specified in {@link EventsColumns#CUSTOM_APP_PACKAGE}. The custom app 104 * will be started via {@link Activity#startActivityForResult(Intent, int)} 105 * and it should call {@link Activity#setResult(int)} with 106 * {@link Activity#RESULT_OK} or {@link Activity#RESULT_CANCELED} to 107 * acknowledge whether the action was handled or not. 108 * 109 * The custom app should have an intent filter like the following: 110 * <pre> 111 * <intent-filter> 112 * <action android:name="android.provider.calendar.action.HANDLE_CUSTOM_EVENT" /> 113 * <category android:name="android.intent.category.DEFAULT" /> 114 * <data android:mimeType="vnd.android.cursor.item/event" /> 115 * </intent-filter></pre> 116 * <p> 117 * Input: {@link Intent#getData} has the event URI. The extra 118 * {@link #EXTRA_EVENT_BEGIN_TIME} has the start time of the instance. The 119 * extra {@link #EXTRA_CUSTOM_APP_URI} will have the 120 * {@link EventsColumns#CUSTOM_APP_URI}. 121 * <p> 122 * Output: {@link Activity#RESULT_OK} if this was handled; otherwise 123 * {@link Activity#RESULT_CANCELED}. 124 */ 125 @SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION) 126 public static final String ACTION_HANDLE_CUSTOM_EVENT = 127 "android.provider.calendar.action.HANDLE_CUSTOM_EVENT"; 128 129 /** 130 * Intent Extras key: {@link EventsColumns#CUSTOM_APP_URI} for the event in 131 * the {@link #ACTION_HANDLE_CUSTOM_EVENT} intent 132 */ 133 public static final String EXTRA_CUSTOM_APP_URI = "customAppUri"; 134 135 /** 136 * Intent Extras key: The start time of an event or an instance of a 137 * recurring event. (milliseconds since epoch) 138 */ 139 public static final String EXTRA_EVENT_BEGIN_TIME = "beginTime"; 140 141 /** 142 * Intent Extras key: The end time of an event or an instance of a recurring 143 * event. (milliseconds since epoch) 144 */ 145 public static final String EXTRA_EVENT_END_TIME = "endTime"; 146 147 /** 148 * Intent Extras key: When creating an event, set this to true to create an 149 * all-day event by default 150 */ 151 public static final String EXTRA_EVENT_ALL_DAY = "allDay"; 152 153 /** 154 * This authority is used for writing to or querying from the calendar 155 * provider. Note: This is set at first run and cannot be changed without 156 * breaking apps that access the provider. 157 */ 158 public static final String AUTHORITY = "com.android.calendar"; 159 160 /** 161 * The content:// style URL for the top-level calendar authority 162 */ 163 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY); 164 165 /** 166 * An optional insert, update or delete URI parameter that allows the caller 167 * to specify that it is a sync adapter. The default value is false. If set 168 * to true, the modified row is not marked as "dirty" (needs to be synced) 169 * and when the provider calls 170 * {@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)} 171 * , the third parameter "syncToNetwork" is set to false. Furthermore, if 172 * set to true, the caller must also include 173 * {@link Calendars#ACCOUNT_NAME} and {@link Calendars#ACCOUNT_TYPE} as 174 * query parameters. 175 * 176 * @see Uri.Builder#appendQueryParameter(java.lang.String, java.lang.String) 177 */ 178 public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter"; 179 180 /** 181 * A special account type for calendars not associated with any account. 182 * Normally calendars that do not match an account on the device will be 183 * removed. Setting the account_type on a calendar to this will prevent it 184 * from being wiped if it does not match an existing account. 185 * 186 * @see SyncColumns#ACCOUNT_TYPE 187 */ 188 public static final String ACCOUNT_TYPE_LOCAL = "LOCAL"; 189 190 /** 191 * This utility class cannot be instantiated 192 */ 193 private CalendarContract() {} 194 195 /** 196 * Generic columns for use by sync adapters. The specific functions of these 197 * columns are private to the sync adapter. Other clients of the API should 198 * not attempt to either read or write this column. These columns are 199 * editable as part of the Calendars Uri, but can only be read if accessed 200 * through any other Uri. 201 */ 202 protected interface CalendarSyncColumns { 203 204 205 /** 206 * Generic column for use by sync adapters. Column name. 207 * <P>Type: TEXT</P> 208 */ 209 public static final String CAL_SYNC1 = "cal_sync1"; 210 211 /** 212 * Generic column for use by sync adapters. Column name. 213 * <P>Type: TEXT</P> 214 */ 215 public static final String CAL_SYNC2 = "cal_sync2"; 216 217 /** 218 * Generic column for use by sync adapters. Column name. 219 * <P>Type: TEXT</P> 220 */ 221 public static final String CAL_SYNC3 = "cal_sync3"; 222 223 /** 224 * Generic column for use by sync adapters. Column name. 225 * <P>Type: TEXT</P> 226 */ 227 public static final String CAL_SYNC4 = "cal_sync4"; 228 229 /** 230 * Generic column for use by sync adapters. Column name. 231 * <P>Type: TEXT</P> 232 */ 233 public static final String CAL_SYNC5 = "cal_sync5"; 234 235 /** 236 * Generic column for use by sync adapters. Column name. 237 * <P>Type: TEXT</P> 238 */ 239 public static final String CAL_SYNC6 = "cal_sync6"; 240 241 /** 242 * Generic column for use by sync adapters. Column name. 243 * <P>Type: TEXT</P> 244 */ 245 public static final String CAL_SYNC7 = "cal_sync7"; 246 247 /** 248 * Generic column for use by sync adapters. Column name. 249 * <P>Type: TEXT</P> 250 */ 251 public static final String CAL_SYNC8 = "cal_sync8"; 252 253 /** 254 * Generic column for use by sync adapters. Column name. 255 * <P>Type: TEXT</P> 256 */ 257 public static final String CAL_SYNC9 = "cal_sync9"; 258 259 /** 260 * Generic column for use by sync adapters. Column name. 261 * <P>Type: TEXT</P> 262 */ 263 public static final String CAL_SYNC10 = "cal_sync10"; 264 } 265 266 /** 267 * Columns for Sync information used by Calendars and Events tables. These 268 * have specific uses which are expected to be consistent by the app and 269 * sync adapter. 270 * 271 */ 272 protected interface SyncColumns extends CalendarSyncColumns { 273 /** 274 * The account that was used to sync the entry to the device. If the 275 * account_type is not {@link #ACCOUNT_TYPE_LOCAL} then the name and 276 * type must match an account on the device or the calendar will be 277 * deleted. 278 * <P>Type: TEXT</P> 279 */ 280 public static final String ACCOUNT_NAME = "account_name"; 281 282 /** 283 * The type of the account that was used to sync the entry to the 284 * device. A type of {@link #ACCOUNT_TYPE_LOCAL} will keep this event 285 * form being deleted if there are no matching accounts on the device. 286 * <P>Type: TEXT</P> 287 */ 288 public static final String ACCOUNT_TYPE = "account_type"; 289 290 /** 291 * The unique ID for a row assigned by the sync source. NULL if the row 292 * has never been synced. This is used as a reference id for exceptions 293 * along with {@link BaseColumns#_ID}. 294 * <P>Type: TEXT</P> 295 */ 296 public static final String _SYNC_ID = "_sync_id"; 297 298 /** 299 * Used to indicate that local, unsynced, changes are present. 300 * <P>Type: INTEGER (long)</P> 301 */ 302 public static final String DIRTY = "dirty"; 303 304 /** 305 * Whether the row has been deleted but not synced to the server. A 306 * deleted row should be ignored. 307 * <P> 308 * Type: INTEGER (boolean) 309 * </P> 310 */ 311 public static final String DELETED = "deleted"; 312 313 /** 314 * If set to 1 this causes events on this calendar to be duplicated with 315 * {@link Events#LAST_SYNCED} set to 1 whenever the event 316 * transitions from non-dirty to dirty. The duplicated event will not be 317 * expanded in the instances table and will only show up in sync adapter 318 * queries of the events table. It will also be deleted when the 319 * originating event has its dirty flag cleared by the sync adapter. 320 * <P>Type: INTEGER (boolean)</P> 321 */ 322 public static final String CAN_PARTIALLY_UPDATE = "canPartiallyUpdate"; 323 } 324 325 /** 326 * Columns specific to the Calendars Uri that other Uris can query. 327 */ 328 protected interface CalendarColumns { 329 /** 330 * The color of the calendar. This should only be updated by the sync 331 * adapter, not other apps, as changing a calendar's color can adversely 332 * affect its display. 333 * <P>Type: INTEGER (color value)</P> 334 */ 335 public static final String CALENDAR_COLOR = "calendar_color"; 336 337 /** 338 * A key for looking up a color from the {@link Colors} table. NULL or 339 * an empty string are reserved for indicating that the calendar does 340 * not use a key for looking up the color. The provider will update 341 * {@link #CALENDAR_COLOR} automatically when a valid key is written to 342 * this column. The key must reference an existing row of the 343 * {@link Colors} table. @see Colors 344 * <P> 345 * Type: TEXT 346 * </P> 347 */ 348 public static final String CALENDAR_COLOR_KEY = "calendar_color_index"; 349 350 /** 351 * The display name of the calendar. Column name. 352 * <P> 353 * Type: TEXT 354 * </P> 355 */ 356 public static final String CALENDAR_DISPLAY_NAME = "calendar_displayName"; 357 358 /** 359 * The level of access that the user has for the calendar 360 * <P>Type: INTEGER (one of the values below)</P> 361 */ 362 public static final String CALENDAR_ACCESS_LEVEL = "calendar_access_level"; 363 364 /** Cannot access the calendar */ 365 public static final int CAL_ACCESS_NONE = 0; 366 /** Can only see free/busy information about the calendar */ 367 public static final int CAL_ACCESS_FREEBUSY = 100; 368 /** Can read all event details */ 369 public static final int CAL_ACCESS_READ = 200; 370 /** Can reply yes/no/maybe to an event */ 371 public static final int CAL_ACCESS_RESPOND = 300; 372 /** not used */ 373 public static final int CAL_ACCESS_OVERRIDE = 400; 374 /** Full access to modify the calendar, but not the access control 375 * settings 376 */ 377 public static final int CAL_ACCESS_CONTRIBUTOR = 500; 378 /** Full access to modify the calendar, but not the access control 379 * settings 380 */ 381 public static final int CAL_ACCESS_EDITOR = 600; 382 /** Full access to the calendar */ 383 public static final int CAL_ACCESS_OWNER = 700; 384 /** Domain admin */ 385 public static final int CAL_ACCESS_ROOT = 800; 386 387 /** 388 * Is the calendar selected to be displayed? 389 * 0 - do not show events associated with this calendar. 390 * 1 - show events associated with this calendar 391 * <P>Type: INTEGER (boolean)</P> 392 */ 393 public static final String VISIBLE = "visible"; 394 395 /** 396 * The time zone the calendar is associated with. 397 * <P>Type: TEXT</P> 398 */ 399 public static final String CALENDAR_TIME_ZONE = "calendar_timezone"; 400 401 /** 402 * Is this calendar synced and are its events stored on the device? 403 * 0 - Do not sync this calendar or store events for this calendar. 404 * 1 - Sync down events for this calendar. 405 * <p>Type: INTEGER (boolean)</p> 406 */ 407 public static final String SYNC_EVENTS = "sync_events"; 408 409 /** 410 * The owner account for this calendar, based on the calendar feed. 411 * This will be different from the _SYNC_ACCOUNT for delegated calendars. 412 * Column name. 413 * <P>Type: String</P> 414 */ 415 public static final String OWNER_ACCOUNT = "ownerAccount"; 416 417 /** 418 * Can the organizer respond to the event? If no, the status of the 419 * organizer should not be shown by the UI. Defaults to 1. Column name. 420 * <P>Type: INTEGER (boolean)</P> 421 */ 422 public static final String CAN_ORGANIZER_RESPOND = "canOrganizerRespond"; 423 424 /** 425 * Can the organizer modify the time zone of the event? Column name. 426 * <P>Type: INTEGER (boolean)</P> 427 */ 428 public static final String CAN_MODIFY_TIME_ZONE = "canModifyTimeZone"; 429 430 /** 431 * The maximum number of reminders allowed for an event. Column name. 432 * <P>Type: INTEGER</P> 433 */ 434 public static final String MAX_REMINDERS = "maxReminders"; 435 436 /** 437 * A comma separated list of reminder methods supported for this 438 * calendar in the format "#,#,#". Valid types are 439 * {@link Reminders#METHOD_DEFAULT}, {@link Reminders#METHOD_ALERT}, 440 * {@link Reminders#METHOD_EMAIL}, {@link Reminders#METHOD_SMS}, 441 * {@link Reminders#METHOD_ALARM}. Column name. 442 * <P>Type: TEXT</P> 443 */ 444 public static final String ALLOWED_REMINDERS = "allowedReminders"; 445 446 /** 447 * A comma separated list of availability types supported for this 448 * calendar in the format "#,#,#". Valid types are 449 * {@link Events#AVAILABILITY_BUSY}, {@link Events#AVAILABILITY_FREE}, 450 * {@link Events#AVAILABILITY_TENTATIVE}. Setting this field to only 451 * {@link Events#AVAILABILITY_BUSY} should be used to indicate that 452 * changing the availability is not supported. 453 * 454 */ 455 public static final String ALLOWED_AVAILABILITY = "allowedAvailability"; 456 457 /** 458 * A comma separated list of attendee types supported for this calendar 459 * in the format "#,#,#". Valid types are {@link Attendees#TYPE_NONE}, 460 * {@link Attendees#TYPE_OPTIONAL}, {@link Attendees#TYPE_REQUIRED}, 461 * {@link Attendees#TYPE_RESOURCE}. Setting this field to only 462 * {@link Attendees#TYPE_NONE} should be used to indicate that changing 463 * the attendee type is not supported. 464 * 465 */ 466 public static final String ALLOWED_ATTENDEE_TYPES = "allowedAttendeeTypes"; 467 468 /** 469 * Is this the primary calendar for this account. If this column is not explicitly set, the 470 * provider will return 1 if {@link Calendars#ACCOUNT_NAME} is equal to 471 * {@link Calendars#OWNER_ACCOUNT}. 472 */ 473 public static final String IS_PRIMARY = "isPrimary"; 474 } 475 476 /** 477 * Class that represents a Calendar Entity. There is one entry per calendar. 478 * This is a helper class to make batch operations easier. 479 */ 480 public static final class CalendarEntity implements BaseColumns, SyncColumns, CalendarColumns { 481 482 /** 483 * The default Uri used when creating a new calendar EntityIterator. 484 */ 485 @SuppressWarnings("hiding") 486 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + 487 "/calendar_entities"); 488 489 /** 490 * This utility class cannot be instantiated 491 */ 492 private CalendarEntity() {} 493 494 /** 495 * Creates an entity iterator for the given cursor. It assumes the 496 * cursor contains a calendars query. 497 * 498 * @param cursor query on {@link #CONTENT_URI} 499 * @return an EntityIterator of calendars 500 */ 501 public static EntityIterator newEntityIterator(Cursor cursor) { 502 return new EntityIteratorImpl(cursor); 503 } 504 505 private static class EntityIteratorImpl extends CursorEntityIterator { 506 507 public EntityIteratorImpl(Cursor cursor) { 508 super(cursor); 509 } 510 511 @Override 512 public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException { 513 // we expect the cursor is already at the row we need to read from 514 final long calendarId = cursor.getLong(cursor.getColumnIndexOrThrow(_ID)); 515 516 // Create the content value 517 ContentValues cv = new ContentValues(); 518 cv.put(_ID, calendarId); 519 520 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME); 521 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE); 522 523 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_ID); 524 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY); 525 526 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC1); 527 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC2); 528 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC3); 529 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC4); 530 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC5); 531 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC6); 532 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC7); 533 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC8); 534 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC9); 535 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC10); 536 537 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Calendars.NAME); 538 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 539 Calendars.CALENDAR_DISPLAY_NAME); 540 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, 541 Calendars.CALENDAR_COLOR); 542 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, CALENDAR_ACCESS_LEVEL); 543 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, VISIBLE); 544 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, SYNC_EVENTS); 545 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 546 Calendars.CALENDAR_LOCATION); 547 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CALENDAR_TIME_ZONE); 548 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 549 Calendars.OWNER_ACCOUNT); 550 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, 551 Calendars.CAN_ORGANIZER_RESPOND); 552 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, 553 Calendars.CAN_MODIFY_TIME_ZONE); 554 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, 555 Calendars.MAX_REMINDERS); 556 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, 557 Calendars.CAN_PARTIALLY_UPDATE); 558 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 559 Calendars.ALLOWED_REMINDERS); 560 561 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, DELETED); 562 563 // Create the Entity from the ContentValue 564 Entity entity = new Entity(cv); 565 566 // Set cursor to next row 567 cursor.moveToNext(); 568 569 // Return the created Entity 570 return entity; 571 } 572 } 573 } 574 575 /** 576 * Constants and helpers for the Calendars table, which contains details for 577 * individual calendars. <h3>Operations</h3> All operations can be done 578 * either as an app or as a sync adapter. To perform an operation as a sync 579 * adapter {@link #CALLER_IS_SYNCADAPTER} should be set to true and 580 * {@link #ACCOUNT_NAME} and {@link #ACCOUNT_TYPE} must be set in the Uri 581 * parameters. See 582 * {@link Uri.Builder#appendQueryParameter(java.lang.String, java.lang.String)} 583 * for details on adding parameters. Sync adapters have write access to more 584 * columns but are restricted to a single account at a time. Calendars are 585 * designed to be primarily managed by a sync adapter and inserting new 586 * calendars should be done as a sync adapter. For the most part, apps 587 * should only update calendars (such as changing the color or display 588 * name). If a local calendar is required an app can do so by inserting as a 589 * sync adapter and using an {@link #ACCOUNT_TYPE} of 590 * {@link #ACCOUNT_TYPE_LOCAL} . 591 * <dl> 592 * <dt><b>Insert</b></dt> 593 * <dd>When inserting a new calendar the following fields must be included: 594 * <ul> 595 * <li>{@link #ACCOUNT_NAME}</li> 596 * <li>{@link #ACCOUNT_TYPE}</li> 597 * <li>{@link #NAME}</li> 598 * <li>{@link #CALENDAR_DISPLAY_NAME}</li> 599 * <li>{@link #CALENDAR_COLOR}</li> 600 * <li>{@link #CALENDAR_ACCESS_LEVEL}</li> 601 * <li>{@link #OWNER_ACCOUNT}</li> 602 * </ul> 603 * The following fields are not required when inserting a Calendar but are 604 * generally a good idea to include: 605 * <ul> 606 * <li>{@link #SYNC_EVENTS} set to 1</li> 607 * <li>{@link #CALENDAR_TIME_ZONE}</li> 608 * <li>{@link #ALLOWED_REMINDERS}</li> 609 * <li>{@link #ALLOWED_AVAILABILITY}</li> 610 * <li>{@link #ALLOWED_ATTENDEE_TYPES}</li> 611 * </ul> 612 * <dt><b>Update</b></dt> 613 * <dd>To perform an update on a calendar the {@link #_ID} of the calendar 614 * should be provided either as an appended id to the Uri ( 615 * {@link ContentUris#withAppendedId}) or as the first selection item--the 616 * selection should start with "_id=?" and the first selectionArg should be 617 * the _id of the calendar. Calendars may also be updated using a selection 618 * without the id. In general, the {@link #ACCOUNT_NAME} and 619 * {@link #ACCOUNT_TYPE} should not be changed after a calendar is created 620 * as this can cause issues for sync adapters. 621 * <dt><b>Delete</b></dt> 622 * <dd>Calendars can be deleted either by the {@link #_ID} as an appended id 623 * on the Uri or using any standard selection. Deleting a calendar should 624 * generally be handled by a sync adapter as it will remove the calendar 625 * from the database and all associated data (aka events).</dd> 626 * <dt><b>Query</b></dt> 627 * <dd>Querying the Calendars table will get you all information about a set 628 * of calendars. There will be one row returned for each calendar that 629 * matches the query selection, or at most a single row if the {@link #_ID} 630 * is appended to the Uri.</dd> 631 * </dl> 632 * <h3>Calendar Columns</h3> The following Calendar columns are writable by 633 * both an app and a sync adapter. 634 * <ul> 635 * <li>{@link #NAME}</li> 636 * <li>{@link #CALENDAR_DISPLAY_NAME}</li> 637 * <li>{@link #VISIBLE}</li> 638 * <li>{@link #SYNC_EVENTS}</li> 639 * </ul> 640 * The following Calendars columns are writable only by a sync adapter 641 * <ul> 642 * <li>{@link #ACCOUNT_NAME}</li> 643 * <li>{@link #ACCOUNT_TYPE}</li> 644 * <li>{@link #CALENDAR_COLOR}</li> 645 * <li>{@link #_SYNC_ID}</li> 646 * <li>{@link #DIRTY}</li> 647 * <li>{@link #OWNER_ACCOUNT}</li> 648 * <li>{@link #MAX_REMINDERS}</li> 649 * <li>{@link #ALLOWED_REMINDERS}</li> 650 * <li>{@link #ALLOWED_AVAILABILITY}</li> 651 * <li>{@link #ALLOWED_ATTENDEE_TYPES}</li> 652 * <li>{@link #CAN_MODIFY_TIME_ZONE}</li> 653 * <li>{@link #CAN_ORGANIZER_RESPOND}</li> 654 * <li>{@link #CAN_PARTIALLY_UPDATE}</li> 655 * <li>{@link #CALENDAR_LOCATION}</li> 656 * <li>{@link #CALENDAR_TIME_ZONE}</li> 657 * <li>{@link #CALENDAR_ACCESS_LEVEL}</li> 658 * <li>{@link #DELETED}</li> 659 * <li>{@link #CAL_SYNC1}</li> 660 * <li>{@link #CAL_SYNC2}</li> 661 * <li>{@link #CAL_SYNC3}</li> 662 * <li>{@link #CAL_SYNC4}</li> 663 * <li>{@link #CAL_SYNC5}</li> 664 * <li>{@link #CAL_SYNC6}</li> 665 * <li>{@link #CAL_SYNC7}</li> 666 * <li>{@link #CAL_SYNC8}</li> 667 * <li>{@link #CAL_SYNC9}</li> 668 * <li>{@link #CAL_SYNC10}</li> 669 * </ul> 670 */ 671 public static final class Calendars implements BaseColumns, SyncColumns, CalendarColumns { 672 673 /** 674 * This utility class cannot be instantiated 675 */ 676 private Calendars() {} 677 678 /** 679 * The content:// style URL for accessing Calendars 680 */ 681 @SuppressWarnings("hiding") 682 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/calendars"); 683 684 /** 685 * The default sort order for this table 686 */ 687 public static final String DEFAULT_SORT_ORDER = CALENDAR_DISPLAY_NAME; 688 689 /** 690 * The name of the calendar. Column name. 691 * <P>Type: TEXT</P> 692 */ 693 public static final String NAME = "name"; 694 695 /** 696 * The default location for the calendar. Column name. 697 * <P>Type: TEXT</P> 698 */ 699 public static final String CALENDAR_LOCATION = "calendar_location"; 700 701 /** 702 * These fields are only writable by a sync adapter. To modify them the 703 * caller must include {@link #CALLER_IS_SYNCADAPTER}, 704 * {@link #ACCOUNT_NAME}, and {@link #ACCOUNT_TYPE} in the Uri's query 705 * parameters. TODO move to provider 706 * 707 * @hide 708 */ 709 public static final String[] SYNC_WRITABLE_COLUMNS = new String[] { 710 ACCOUNT_NAME, 711 ACCOUNT_TYPE, 712 _SYNC_ID, 713 DIRTY, 714 OWNER_ACCOUNT, 715 MAX_REMINDERS, 716 ALLOWED_REMINDERS, 717 CAN_MODIFY_TIME_ZONE, 718 CAN_ORGANIZER_RESPOND, 719 CAN_PARTIALLY_UPDATE, 720 CALENDAR_LOCATION, 721 CALENDAR_TIME_ZONE, 722 CALENDAR_ACCESS_LEVEL, 723 DELETED, 724 CAL_SYNC1, 725 CAL_SYNC2, 726 CAL_SYNC3, 727 CAL_SYNC4, 728 CAL_SYNC5, 729 CAL_SYNC6, 730 CAL_SYNC7, 731 CAL_SYNC8, 732 CAL_SYNC9, 733 CAL_SYNC10, 734 }; 735 } 736 737 /** 738 * Columns from the Attendees table that other tables join into themselves. 739 */ 740 protected interface AttendeesColumns { 741 742 /** 743 * The id of the event. Column name. 744 * <P>Type: INTEGER</P> 745 */ 746 public static final String EVENT_ID = "event_id"; 747 748 /** 749 * The name of the attendee. Column name. 750 * <P>Type: STRING</P> 751 */ 752 public static final String ATTENDEE_NAME = "attendeeName"; 753 754 /** 755 * The email address of the attendee. Column name. 756 * <P>Type: STRING</P> 757 */ 758 public static final String ATTENDEE_EMAIL = "attendeeEmail"; 759 760 /** 761 * The relationship of the attendee to the user. Column name. 762 * <P>Type: INTEGER (one of {@link #RELATIONSHIP_ATTENDEE}, ...}.</P> 763 */ 764 public static final String ATTENDEE_RELATIONSHIP = "attendeeRelationship"; 765 766 public static final int RELATIONSHIP_NONE = 0; 767 public static final int RELATIONSHIP_ATTENDEE = 1; 768 public static final int RELATIONSHIP_ORGANIZER = 2; 769 public static final int RELATIONSHIP_PERFORMER = 3; 770 public static final int RELATIONSHIP_SPEAKER = 4; 771 772 /** 773 * The type of attendee. Column name. 774 * <P> 775 * Type: Integer (one of {@link #TYPE_NONE}, {@link #TYPE_REQUIRED}, 776 * {@link #TYPE_OPTIONAL}, {@link #TYPE_RESOURCE}) 777 * </P> 778 */ 779 public static final String ATTENDEE_TYPE = "attendeeType"; 780 781 public static final int TYPE_NONE = 0; 782 public static final int TYPE_REQUIRED = 1; 783 public static final int TYPE_OPTIONAL = 2; 784 /** 785 * This specifies that an attendee is a resource, like a room, a 786 * cabbage, or something and not an actual person. 787 */ 788 public static final int TYPE_RESOURCE = 3; 789 790 /** 791 * The attendance status of the attendee. Column name. 792 * <P>Type: Integer (one of {@link #ATTENDEE_STATUS_ACCEPTED}, ...).</P> 793 */ 794 public static final String ATTENDEE_STATUS = "attendeeStatus"; 795 796 public static final int ATTENDEE_STATUS_NONE = 0; 797 public static final int ATTENDEE_STATUS_ACCEPTED = 1; 798 public static final int ATTENDEE_STATUS_DECLINED = 2; 799 public static final int ATTENDEE_STATUS_INVITED = 3; 800 public static final int ATTENDEE_STATUS_TENTATIVE = 4; 801 802 /** 803 * The identity of the attendee as referenced in 804 * {@link ContactsContract.CommonDataKinds.Identity#IDENTITY}. 805 * This is required only if {@link #ATTENDEE_ID_NAMESPACE} is present. Column name. 806 * <P>Type: STRING</P> 807 */ 808 public static final String ATTENDEE_IDENTITY = "attendeeIdentity"; 809 810 /** 811 * The identity name space of the attendee as referenced in 812 * {@link ContactsContract.CommonDataKinds.Identity#NAMESPACE}. 813 * This is required only if {@link #ATTENDEE_IDENTITY} is present. Column name. 814 * <P>Type: STRING</P> 815 */ 816 public static final String ATTENDEE_ID_NAMESPACE = "attendeeIdNamespace"; 817 } 818 819 /** 820 * Fields and helpers for interacting with Attendees. Each row of this table 821 * represents a single attendee or guest of an event. Calling 822 * {@link #query(ContentResolver, long, String[])} will return a list of attendees for 823 * the event with the given eventId. Both apps and sync adapters may write 824 * to this table. There are six writable fields and all of them except 825 * {@link #ATTENDEE_NAME} must be included when inserting a new attendee. 826 * They are: 827 * <ul> 828 * <li>{@link #EVENT_ID}</li> 829 * <li>{@link #ATTENDEE_NAME}</li> 830 * <li>{@link #ATTENDEE_EMAIL}</li> 831 * <li>{@link #ATTENDEE_RELATIONSHIP}</li> 832 * <li>{@link #ATTENDEE_TYPE}</li> 833 * <li>{@link #ATTENDEE_STATUS}</li> 834 * <li>{@link #ATTENDEE_IDENTITY}</li> 835 * <li>{@link #ATTENDEE_ID_NAMESPACE}</li> 836 * </ul> 837 */ 838 public static final class Attendees implements BaseColumns, AttendeesColumns, EventsColumns { 839 840 /** 841 * The content:// style URL for accessing Attendees data 842 */ 843 @SuppressWarnings("hiding") 844 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/attendees"); 845 private static final String ATTENDEES_WHERE = Attendees.EVENT_ID + "=?"; 846 847 /** 848 * This utility class cannot be instantiated 849 */ 850 private Attendees() {} 851 852 /** 853 * Queries all attendees associated with the given event. This is a 854 * blocking call and should not be done on the UI thread. 855 * 856 * @param cr The content resolver to use for the query 857 * @param eventId The id of the event to retrieve attendees for 858 * @param projection the columns to return in the cursor 859 * @return A Cursor containing all attendees for the event 860 */ 861 public static final Cursor query(ContentResolver cr, long eventId, String[] projection) { 862 String[] attArgs = {Long.toString(eventId)}; 863 return cr.query(CONTENT_URI, projection, ATTENDEES_WHERE, attArgs /* selection args */, 864 null /* sort order */); 865 } 866 } 867 868 /** 869 * Columns from the Events table that other tables join into themselves. 870 */ 871 protected interface EventsColumns { 872 873 /** 874 * The {@link Calendars#_ID} of the calendar the event belongs to. 875 * Column name. 876 * <P>Type: INTEGER</P> 877 */ 878 public static final String CALENDAR_ID = "calendar_id"; 879 880 /** 881 * The title of the event. Column name. 882 * <P>Type: TEXT</P> 883 */ 884 public static final String TITLE = "title"; 885 886 /** 887 * The description of the event. Column name. 888 * <P>Type: TEXT</P> 889 */ 890 public static final String DESCRIPTION = "description"; 891 892 /** 893 * Where the event takes place. Column name. 894 * <P>Type: TEXT</P> 895 */ 896 public static final String EVENT_LOCATION = "eventLocation"; 897 898 /** 899 * A secondary color for the individual event. This should only be 900 * updated by the sync adapter for a given account. 901 * <P>Type: INTEGER</P> 902 */ 903 public static final String EVENT_COLOR = "eventColor"; 904 905 /** 906 * A secondary color key for the individual event. NULL or an empty 907 * string are reserved for indicating that the event does not use a key 908 * for looking up the color. The provider will update 909 * {@link #EVENT_COLOR} automatically when a valid key is written to 910 * this column. The key must reference an existing row of the 911 * {@link Colors} table. @see Colors 912 * <P> 913 * Type: TEXT 914 * </P> 915 */ 916 public static final String EVENT_COLOR_KEY = "eventColor_index"; 917 918 /** 919 * This will be {@link #EVENT_COLOR} if it is not null; otherwise, this will be 920 * {@link Calendars#CALENDAR_COLOR}. 921 * Read-only value. To modify, write to {@link #EVENT_COLOR} or 922 * {@link Calendars#CALENDAR_COLOR} directly. 923 *<P> 924 * Type: INTEGER 925 *</P> 926 */ 927 public static final String DISPLAY_COLOR = "displayColor"; 928 929 /** 930 * The event status. Column name. 931 * <P>Type: INTEGER (one of {@link #STATUS_TENTATIVE}...)</P> 932 */ 933 public static final String STATUS = "eventStatus"; 934 935 public static final int STATUS_TENTATIVE = 0; 936 public static final int STATUS_CONFIRMED = 1; 937 public static final int STATUS_CANCELED = 2; 938 939 /** 940 * This is a copy of the attendee status for the owner of this event. 941 * This field is copied here so that we can efficiently filter out 942 * events that are declined without having to look in the Attendees 943 * table. Column name. 944 * 945 * <P>Type: INTEGER (int)</P> 946 */ 947 public static final String SELF_ATTENDEE_STATUS = "selfAttendeeStatus"; 948 949 /** 950 * This column is available for use by sync adapters. Column name. 951 * <P>Type: TEXT</P> 952 */ 953 public static final String SYNC_DATA1 = "sync_data1"; 954 955 /** 956 * This column is available for use by sync adapters. Column name. 957 * <P>Type: TEXT</P> 958 */ 959 public static final String SYNC_DATA2 = "sync_data2"; 960 961 /** 962 * This column is available for use by sync adapters. Column name. 963 * <P>Type: TEXT</P> 964 */ 965 public static final String SYNC_DATA3 = "sync_data3"; 966 967 /** 968 * This column is available for use by sync adapters. Column name. 969 * <P>Type: TEXT</P> 970 */ 971 public static final String SYNC_DATA4 = "sync_data4"; 972 973 /** 974 * This column is available for use by sync adapters. Column name. 975 * <P>Type: TEXT</P> 976 */ 977 public static final String SYNC_DATA5 = "sync_data5"; 978 979 /** 980 * This column is available for use by sync adapters. Column name. 981 * <P>Type: TEXT</P> 982 */ 983 public static final String SYNC_DATA6 = "sync_data6"; 984 985 /** 986 * This column is available for use by sync adapters. Column name. 987 * <P>Type: TEXT</P> 988 */ 989 public static final String SYNC_DATA7 = "sync_data7"; 990 991 /** 992 * This column is available for use by sync adapters. Column name. 993 * <P>Type: TEXT</P> 994 */ 995 public static final String SYNC_DATA8 = "sync_data8"; 996 997 /** 998 * This column is available for use by sync adapters. Column name. 999 * <P>Type: TEXT</P> 1000 */ 1001 public static final String SYNC_DATA9 = "sync_data9"; 1002 1003 /** 1004 * This column is available for use by sync adapters. Column name. 1005 * <P>Type: TEXT</P> 1006 */ 1007 public static final String SYNC_DATA10 = "sync_data10"; 1008 1009 /** 1010 * Used to indicate that a row is not a real event but an original copy of a locally 1011 * modified event. A copy is made when an event changes from non-dirty to dirty and the 1012 * event is on a calendar with {@link Calendars#CAN_PARTIALLY_UPDATE} set to 1. This copy 1013 * does not get expanded in the instances table and is only visible in queries made by a 1014 * sync adapter. The copy gets removed when the event is changed back to non-dirty by a 1015 * sync adapter. 1016 * <P>Type: INTEGER (boolean)</P> 1017 */ 1018 public static final String LAST_SYNCED = "lastSynced"; 1019 1020 /** 1021 * The time the event starts in UTC millis since epoch. Column name. 1022 * <P>Type: INTEGER (long; millis since epoch)</P> 1023 */ 1024 public static final String DTSTART = "dtstart"; 1025 1026 /** 1027 * The time the event ends in UTC millis since epoch. Column name. 1028 * <P>Type: INTEGER (long; millis since epoch)</P> 1029 */ 1030 public static final String DTEND = "dtend"; 1031 1032 /** 1033 * The duration of the event in RFC2445 format. Column name. 1034 * <P>Type: TEXT (duration in RFC2445 format)</P> 1035 */ 1036 public static final String DURATION = "duration"; 1037 1038 /** 1039 * The timezone for the event. Column name. 1040 * <P>Type: TEXT</P> 1041 */ 1042 public static final String EVENT_TIMEZONE = "eventTimezone"; 1043 1044 /** 1045 * The timezone for the end time of the event. Column name. 1046 * <P>Type: TEXT</P> 1047 */ 1048 public static final String EVENT_END_TIMEZONE = "eventEndTimezone"; 1049 1050 /** 1051 * Is the event all day (time zone independent). Column name. 1052 * <P>Type: INTEGER (boolean)</P> 1053 */ 1054 public static final String ALL_DAY = "allDay"; 1055 1056 /** 1057 * Defines how the event shows up for others when the calendar is 1058 * shared. Column name. 1059 * <P>Type: INTEGER (One of {@link #ACCESS_DEFAULT}, ...)</P> 1060 */ 1061 public static final String ACCESS_LEVEL = "accessLevel"; 1062 1063 /** 1064 * Default access is controlled by the server and will be treated as 1065 * public on the device. 1066 */ 1067 public static final int ACCESS_DEFAULT = 0; 1068 /** 1069 * Confidential is not used by the app. 1070 */ 1071 public static final int ACCESS_CONFIDENTIAL = 1; 1072 /** 1073 * Private shares the event as a free/busy slot with no details. 1074 */ 1075 public static final int ACCESS_PRIVATE = 2; 1076 /** 1077 * Public makes the contents visible to anyone with access to the 1078 * calendar. 1079 */ 1080 public static final int ACCESS_PUBLIC = 3; 1081 1082 /** 1083 * If this event counts as busy time or is still free time that can be 1084 * scheduled over. Column name. 1085 * <P> 1086 * Type: INTEGER (One of {@link #AVAILABILITY_BUSY}, 1087 * {@link #AVAILABILITY_FREE}, {@link #AVAILABILITY_TENTATIVE}) 1088 * </P> 1089 */ 1090 public static final String AVAILABILITY = "availability"; 1091 1092 /** 1093 * Indicates that this event takes up time and will conflict with other 1094 * events. 1095 */ 1096 public static final int AVAILABILITY_BUSY = 0; 1097 /** 1098 * Indicates that this event is free time and will not conflict with 1099 * other events. 1100 */ 1101 public static final int AVAILABILITY_FREE = 1; 1102 /** 1103 * Indicates that the owner's availability may change, but should be 1104 * considered busy time that will conflict. 1105 */ 1106 public static final int AVAILABILITY_TENTATIVE = 2; 1107 1108 /** 1109 * Whether the event has an alarm or not. Column name. 1110 * <P>Type: INTEGER (boolean)</P> 1111 */ 1112 public static final String HAS_ALARM = "hasAlarm"; 1113 1114 /** 1115 * Whether the event has extended properties or not. Column name. 1116 * <P>Type: INTEGER (boolean)</P> 1117 */ 1118 public static final String HAS_EXTENDED_PROPERTIES = "hasExtendedProperties"; 1119 1120 /** 1121 * The recurrence rule for the event. Column name. 1122 * <P>Type: TEXT</P> 1123 */ 1124 public static final String RRULE = "rrule"; 1125 1126 /** 1127 * The recurrence dates for the event. Column name. 1128 * <P>Type: TEXT</P> 1129 */ 1130 public static final String RDATE = "rdate"; 1131 1132 /** 1133 * The recurrence exception rule for the event. Column name. 1134 * <P>Type: TEXT</P> 1135 */ 1136 public static final String EXRULE = "exrule"; 1137 1138 /** 1139 * The recurrence exception dates for the event. Column name. 1140 * <P>Type: TEXT</P> 1141 */ 1142 public static final String EXDATE = "exdate"; 1143 1144 /** 1145 * The {@link Events#_ID} of the original recurring event for which this 1146 * event is an exception. Column name. 1147 * <P>Type: TEXT</P> 1148 */ 1149 public static final String ORIGINAL_ID = "original_id"; 1150 1151 /** 1152 * The _sync_id of the original recurring event for which this event is 1153 * an exception. The provider should keep the original_id in sync when 1154 * this is updated. Column name. 1155 * <P>Type: TEXT</P> 1156 */ 1157 public static final String ORIGINAL_SYNC_ID = "original_sync_id"; 1158 1159 /** 1160 * The original instance time of the recurring event for which this 1161 * event is an exception. Column name. 1162 * <P>Type: INTEGER (long; millis since epoch)</P> 1163 */ 1164 public static final String ORIGINAL_INSTANCE_TIME = "originalInstanceTime"; 1165 1166 /** 1167 * The allDay status (true or false) of the original recurring event 1168 * for which this event is an exception. Column name. 1169 * <P>Type: INTEGER (boolean)</P> 1170 */ 1171 public static final String ORIGINAL_ALL_DAY = "originalAllDay"; 1172 1173 /** 1174 * The last date this event repeats on, or NULL if it never ends. Column 1175 * name. 1176 * <P>Type: INTEGER (long; millis since epoch)</P> 1177 */ 1178 public static final String LAST_DATE = "lastDate"; 1179 1180 /** 1181 * Whether the event has attendee information. True if the event 1182 * has full attendee data, false if the event has information about 1183 * self only. Column name. 1184 * <P>Type: INTEGER (boolean)</P> 1185 */ 1186 public static final String HAS_ATTENDEE_DATA = "hasAttendeeData"; 1187 1188 /** 1189 * Whether guests can modify the event. Column name. 1190 * <P>Type: INTEGER (boolean)</P> 1191 */ 1192 public static final String GUESTS_CAN_MODIFY = "guestsCanModify"; 1193 1194 /** 1195 * Whether guests can invite other guests. Column name. 1196 * <P>Type: INTEGER (boolean)</P> 1197 */ 1198 public static final String GUESTS_CAN_INVITE_OTHERS = "guestsCanInviteOthers"; 1199 1200 /** 1201 * Whether guests can see the list of attendees. Column name. 1202 * <P>Type: INTEGER (boolean)</P> 1203 */ 1204 public static final String GUESTS_CAN_SEE_GUESTS = "guestsCanSeeGuests"; 1205 1206 /** 1207 * Email of the organizer (owner) of the event. Column name. 1208 * <P>Type: STRING</P> 1209 */ 1210 public static final String ORGANIZER = "organizer"; 1211 1212 /** 1213 * Are we the organizer of this event. If this column is not explicitly set, the provider 1214 * will return 1 if {@link #ORGANIZER} is equal to {@link Calendars#OWNER_ACCOUNT}. 1215 * Column name. 1216 * <P>Type: STRING</P> 1217 */ 1218 public static final String IS_ORGANIZER = "isOrganizer"; 1219 1220 /** 1221 * Whether the user can invite others to the event. The 1222 * GUESTS_CAN_INVITE_OTHERS is a setting that applies to an arbitrary 1223 * guest, while CAN_INVITE_OTHERS indicates if the user can invite 1224 * others (either through GUESTS_CAN_INVITE_OTHERS or because the user 1225 * has modify access to the event). Column name. 1226 * <P>Type: INTEGER (boolean, readonly)</P> 1227 */ 1228 public static final String CAN_INVITE_OTHERS = "canInviteOthers"; 1229 1230 /** 1231 * The package name of the custom app that can provide a richer 1232 * experience for the event. See the ACTION TYPE 1233 * {@link CalendarContract#ACTION_HANDLE_CUSTOM_EVENT} for details. 1234 * Column name. 1235 * <P> Type: TEXT </P> 1236 */ 1237 public static final String CUSTOM_APP_PACKAGE = "customAppPackage"; 1238 1239 /** 1240 * The URI used by the custom app for the event. Column name. 1241 * <P>Type: TEXT</P> 1242 */ 1243 public static final String CUSTOM_APP_URI = "customAppUri"; 1244 1245 /** 1246 * The UID for events added from the RFC 2445 iCalendar format. 1247 * Column name. 1248 * <P>Type: TEXT</P> 1249 */ 1250 public static final String UID_2445 = "uid2445"; 1251 } 1252 1253 /** 1254 * Class that represents an Event Entity. There is one entry per event. 1255 * Recurring events show up as a single entry. This is a helper class to 1256 * make batch operations easier. A {@link ContentResolver} or 1257 * {@link ContentProviderClient} is required as the helper does additional 1258 * queries to add reminders and attendees to each entry. 1259 */ 1260 public static final class EventsEntity implements BaseColumns, SyncColumns, EventsColumns { 1261 /** 1262 * The content:// style URL for this table 1263 */ 1264 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + 1265 "/event_entities"); 1266 1267 /** 1268 * This utility class cannot be instantiated 1269 */ 1270 private EventsEntity() {} 1271 1272 /** 1273 * Creates a new iterator for events 1274 * 1275 * @param cursor An event query 1276 * @param resolver For performing additional queries 1277 * @return an EntityIterator containing one entity per event in the 1278 * cursor 1279 */ 1280 public static EntityIterator newEntityIterator(Cursor cursor, ContentResolver resolver) { 1281 return new EntityIteratorImpl(cursor, resolver); 1282 } 1283 1284 /** 1285 * Creates a new iterator for events 1286 * 1287 * @param cursor An event query 1288 * @param provider For performing additional queries 1289 * @return an EntityIterator containing one entity per event in the 1290 * cursor 1291 */ 1292 public static EntityIterator newEntityIterator(Cursor cursor, 1293 ContentProviderClient provider) { 1294 return new EntityIteratorImpl(cursor, provider); 1295 } 1296 1297 private static class EntityIteratorImpl extends CursorEntityIterator { 1298 private final ContentResolver mResolver; 1299 private final ContentProviderClient mProvider; 1300 1301 private static final String[] REMINDERS_PROJECTION = new String[] { 1302 Reminders.MINUTES, 1303 Reminders.METHOD, 1304 }; 1305 private static final int COLUMN_MINUTES = 0; 1306 private static final int COLUMN_METHOD = 1; 1307 1308 private static final String[] ATTENDEES_PROJECTION = new String[] { 1309 Attendees.ATTENDEE_NAME, 1310 Attendees.ATTENDEE_EMAIL, 1311 Attendees.ATTENDEE_RELATIONSHIP, 1312 Attendees.ATTENDEE_TYPE, 1313 Attendees.ATTENDEE_STATUS, 1314 Attendees.ATTENDEE_IDENTITY, 1315 Attendees.ATTENDEE_ID_NAMESPACE 1316 }; 1317 private static final int COLUMN_ATTENDEE_NAME = 0; 1318 private static final int COLUMN_ATTENDEE_EMAIL = 1; 1319 private static final int COLUMN_ATTENDEE_RELATIONSHIP = 2; 1320 private static final int COLUMN_ATTENDEE_TYPE = 3; 1321 private static final int COLUMN_ATTENDEE_STATUS = 4; 1322 private static final int COLUMN_ATTENDEE_IDENTITY = 5; 1323 private static final int COLUMN_ATTENDEE_ID_NAMESPACE = 6; 1324 1325 private static final String[] EXTENDED_PROJECTION = new String[] { 1326 ExtendedProperties._ID, 1327 ExtendedProperties.NAME, 1328 ExtendedProperties.VALUE 1329 }; 1330 private static final int COLUMN_ID = 0; 1331 private static final int COLUMN_NAME = 1; 1332 private static final int COLUMN_VALUE = 2; 1333 1334 private static final String WHERE_EVENT_ID = "event_id=?"; 1335 1336 public EntityIteratorImpl(Cursor cursor, ContentResolver resolver) { 1337 super(cursor); 1338 mResolver = resolver; 1339 mProvider = null; 1340 } 1341 1342 public EntityIteratorImpl(Cursor cursor, ContentProviderClient provider) { 1343 super(cursor); 1344 mResolver = null; 1345 mProvider = provider; 1346 } 1347 1348 @Override 1349 public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException { 1350 // we expect the cursor is already at the row we need to read from 1351 final long eventId = cursor.getLong(cursor.getColumnIndexOrThrow(Events._ID)); 1352 ContentValues cv = new ContentValues(); 1353 cv.put(Events._ID, eventId); 1354 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, CALENDAR_ID); 1355 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, TITLE); 1356 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DESCRIPTION); 1357 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_LOCATION); 1358 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, STATUS); 1359 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, SELF_ATTENDEE_STATUS); 1360 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DTSTART); 1361 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DTEND); 1362 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DURATION); 1363 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_TIMEZONE); 1364 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EVENT_END_TIMEZONE); 1365 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ALL_DAY); 1366 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, ACCESS_LEVEL); 1367 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, AVAILABILITY); 1368 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, HAS_ALARM); 1369 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, 1370 HAS_EXTENDED_PROPERTIES); 1371 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, RRULE); 1372 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, RDATE); 1373 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EXRULE); 1374 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, EXDATE); 1375 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORIGINAL_SYNC_ID); 1376 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORIGINAL_ID); 1377 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, 1378 ORIGINAL_INSTANCE_TIME); 1379 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, ORIGINAL_ALL_DAY); 1380 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, LAST_DATE); 1381 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, HAS_ATTENDEE_DATA); 1382 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, 1383 GUESTS_CAN_INVITE_OTHERS); 1384 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, GUESTS_CAN_MODIFY); 1385 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, GUESTS_CAN_SEE_GUESTS); 1386 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CUSTOM_APP_PACKAGE); 1387 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CUSTOM_APP_URI); 1388 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, UID_2445); 1389 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ORGANIZER); 1390 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, IS_ORGANIZER); 1391 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, _SYNC_ID); 1392 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY); 1393 DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, LAST_SYNCED); 1394 DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, DELETED); 1395 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA1); 1396 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA2); 1397 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA3); 1398 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA4); 1399 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA5); 1400 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA6); 1401 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA7); 1402 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA8); 1403 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA9); 1404 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC_DATA10); 1405 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC1); 1406 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC2); 1407 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC3); 1408 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC4); 1409 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC5); 1410 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC6); 1411 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC7); 1412 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC8); 1413 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC9); 1414 DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, CAL_SYNC10); 1415 1416 Entity entity = new Entity(cv); 1417 Cursor subCursor; 1418 if (mResolver != null) { 1419 subCursor = mResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION, 1420 WHERE_EVENT_ID, 1421 new String[] { Long.toString(eventId) } /* selectionArgs */, 1422 null /* sortOrder */); 1423 } else { 1424 subCursor = mProvider.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION, 1425 WHERE_EVENT_ID, 1426 new String[] { Long.toString(eventId) } /* selectionArgs */, 1427 null /* sortOrder */); 1428 } 1429 try { 1430 while (subCursor.moveToNext()) { 1431 ContentValues reminderValues = new ContentValues(); 1432 reminderValues.put(Reminders.MINUTES, subCursor.getInt(COLUMN_MINUTES)); 1433 reminderValues.put(Reminders.METHOD, subCursor.getInt(COLUMN_METHOD)); 1434 entity.addSubValue(Reminders.CONTENT_URI, reminderValues); 1435 } 1436 } finally { 1437 subCursor.close(); 1438 } 1439 1440 if (mResolver != null) { 1441 subCursor = mResolver.query(Attendees.CONTENT_URI, ATTENDEES_PROJECTION, 1442 WHERE_EVENT_ID, 1443 new String[] { Long.toString(eventId) } /* selectionArgs */, 1444 null /* sortOrder */); 1445 } else { 1446 subCursor = mProvider.query(Attendees.CONTENT_URI, ATTENDEES_PROJECTION, 1447 WHERE_EVENT_ID, 1448 new String[] { Long.toString(eventId) } /* selectionArgs */, 1449 null /* sortOrder */); 1450 } 1451 try { 1452 while (subCursor.moveToNext()) { 1453 ContentValues attendeeValues = new ContentValues(); 1454 attendeeValues.put(Attendees.ATTENDEE_NAME, 1455 subCursor.getString(COLUMN_ATTENDEE_NAME)); 1456 attendeeValues.put(Attendees.ATTENDEE_EMAIL, 1457 subCursor.getString(COLUMN_ATTENDEE_EMAIL)); 1458 attendeeValues.put(Attendees.ATTENDEE_RELATIONSHIP, 1459 subCursor.getInt(COLUMN_ATTENDEE_RELATIONSHIP)); 1460 attendeeValues.put(Attendees.ATTENDEE_TYPE, 1461 subCursor.getInt(COLUMN_ATTENDEE_TYPE)); 1462 attendeeValues.put(Attendees.ATTENDEE_STATUS, 1463 subCursor.getInt(COLUMN_ATTENDEE_STATUS)); 1464 attendeeValues.put(Attendees.ATTENDEE_IDENTITY, 1465 subCursor.getString(COLUMN_ATTENDEE_IDENTITY)); 1466 attendeeValues.put(Attendees.ATTENDEE_ID_NAMESPACE, 1467 subCursor.getString(COLUMN_ATTENDEE_ID_NAMESPACE)); 1468 entity.addSubValue(Attendees.CONTENT_URI, attendeeValues); 1469 } 1470 } finally { 1471 subCursor.close(); 1472 } 1473 1474 if (mResolver != null) { 1475 subCursor = mResolver.query(ExtendedProperties.CONTENT_URI, EXTENDED_PROJECTION, 1476 WHERE_EVENT_ID, 1477 new String[] { Long.toString(eventId) } /* selectionArgs */, 1478 null /* sortOrder */); 1479 } else { 1480 subCursor = mProvider.query(ExtendedProperties.CONTENT_URI, EXTENDED_PROJECTION, 1481 WHERE_EVENT_ID, 1482 new String[] { Long.toString(eventId) } /* selectionArgs */, 1483 null /* sortOrder */); 1484 } 1485 try { 1486 while (subCursor.moveToNext()) { 1487 ContentValues extendedValues = new ContentValues(); 1488 extendedValues.put(ExtendedProperties._ID, 1489 subCursor.getString(COLUMN_ID)); 1490 extendedValues.put(ExtendedProperties.NAME, 1491 subCursor.getString(COLUMN_NAME)); 1492 extendedValues.put(ExtendedProperties.VALUE, 1493 subCursor.getString(COLUMN_VALUE)); 1494 entity.addSubValue(ExtendedProperties.CONTENT_URI, extendedValues); 1495 } 1496 } finally { 1497 subCursor.close(); 1498 } 1499 1500 cursor.moveToNext(); 1501 return entity; 1502 } 1503 } 1504 } 1505 1506 /** 1507 * Constants and helpers for the Events table, which contains details for 1508 * individual events. <h3>Operations</h3> All operations can be done either 1509 * as an app or as a sync adapter. To perform an operation as a sync adapter 1510 * {@link #CALLER_IS_SYNCADAPTER} should be set to true and 1511 * {@link #ACCOUNT_NAME} and {@link #ACCOUNT_TYPE} must be set in the Uri 1512 * parameters. See 1513 * {@link Uri.Builder#appendQueryParameter(java.lang.String, java.lang.String)} 1514 * for details on adding parameters. Sync adapters have write access to more 1515 * columns but are restricted to a single account at a time. 1516 * <dl> 1517 * <dt><b>Insert</b></dt> 1518 * <dd>When inserting a new event the following fields must be included: 1519 * <ul> 1520 * <li>dtstart</li> 1521 * <li>dtend if the event is non-recurring</li> 1522 * <li>duration if the event is recurring</li> 1523 * <li>rrule or rdate if the event is recurring</li> 1524 * <li>eventTimezone</li> 1525 * <li>a calendar_id</li> 1526 * </ul> 1527 * There are also further requirements when inserting or updating an event. 1528 * See the section on Writing to Events.</dd> 1529 * <dt><b>Update</b></dt> 1530 * <dd>To perform an update of an Event the {@link Events#_ID} of the event 1531 * should be provided either as an appended id to the Uri ( 1532 * {@link ContentUris#withAppendedId}) or as the first selection item--the 1533 * selection should start with "_id=?" and the first selectionArg should be 1534 * the _id of the event. Updates may also be done using a selection and no 1535 * id. Updating an event must respect the same rules as inserting and is 1536 * further restricted in the fields that can be written. See the section on 1537 * Writing to Events.</dd> 1538 * <dt><b>Delete</b></dt> 1539 * <dd>Events can be deleted either by the {@link Events#_ID} as an appended 1540 * id on the Uri or using any standard selection. If an appended id is used 1541 * a selection is not allowed. There are two versions of delete: as an app 1542 * and as a sync adapter. An app delete will set the deleted column on an 1543 * event and remove all instances of that event. A sync adapter delete will 1544 * remove the event from the database and all associated data.</dd> 1545 * <dt><b>Query</b></dt> 1546 * <dd>Querying the Events table will get you all information about a set of 1547 * events except their reminders, attendees, and extended properties. There 1548 * will be one row returned for each event that matches the query selection, 1549 * or at most a single row if the {@link Events#_ID} is appended to the Uri. 1550 * Recurring events will only return a single row regardless of the number 1551 * of times that event repeats.</dd> 1552 * </dl> 1553 * <h3>Writing to Events</h3> There are further restrictions on all Updates 1554 * and Inserts in the Events table: 1555 * <ul> 1556 * <li>If allDay is set to 1 eventTimezone must be {@link Time#TIMEZONE_UTC} 1557 * and the time must correspond to a midnight boundary.</li> 1558 * <li>Exceptions are not allowed to recur. If rrule or rdate is not empty, 1559 * original_id and original_sync_id must be empty.</li> 1560 * <li>In general a calendar_id should not be modified after insertion. This 1561 * is not explicitly forbidden but many sync adapters will not behave in an 1562 * expected way if the calendar_id is modified.</li> 1563 * </ul> 1564 * The following Events columns are writable by both an app and a sync 1565 * adapter. 1566 * <ul> 1567 * <li>{@link #CALENDAR_ID}</li> 1568 * <li>{@link #ORGANIZER}</li> 1569 * <li>{@link #TITLE}</li> 1570 * <li>{@link #EVENT_LOCATION}</li> 1571 * <li>{@link #DESCRIPTION}</li> 1572 * <li>{@link #EVENT_COLOR}</li> 1573 * <li>{@link #DTSTART}</li> 1574 * <li>{@link #DTEND}</li> 1575 * <li>{@link #EVENT_TIMEZONE}</li> 1576 * <li>{@link #EVENT_END_TIMEZONE}</li> 1577 * <li>{@link #DURATION}</li> 1578 * <li>{@link #ALL_DAY}</li> 1579 * <li>{@link #RRULE}</li> 1580 * <li>{@link #RDATE}</li> 1581 * <li>{@link #EXRULE}</li> 1582 * <li>{@link #EXDATE}</li> 1583 * <li>{@link #ORIGINAL_ID}</li> 1584 * <li>{@link #ORIGINAL_SYNC_ID}</li> 1585 * <li>{@link #ORIGINAL_INSTANCE_TIME}</li> 1586 * <li>{@link #ORIGINAL_ALL_DAY}</li> 1587 * <li>{@link #ACCESS_LEVEL}</li> 1588 * <li>{@link #AVAILABILITY}</li> 1589 * <li>{@link #GUESTS_CAN_MODIFY}</li> 1590 * <li>{@link #GUESTS_CAN_INVITE_OTHERS}</li> 1591 * <li>{@link #GUESTS_CAN_SEE_GUESTS}</li> 1592 * <li>{@link #CUSTOM_APP_PACKAGE}</li> 1593 * <li>{@link #CUSTOM_APP_URI}</li> 1594 * <li>{@link #UID_2445}</li> 1595 * </ul> 1596 * The following Events columns are writable only by a sync adapter 1597 * <ul> 1598 * <li>{@link #DIRTY}</li> 1599 * <li>{@link #_SYNC_ID}</li> 1600 * <li>{@link #SYNC_DATA1}</li> 1601 * <li>{@link #SYNC_DATA2}</li> 1602 * <li>{@link #SYNC_DATA3}</li> 1603 * <li>{@link #SYNC_DATA4}</li> 1604 * <li>{@link #SYNC_DATA5}</li> 1605 * <li>{@link #SYNC_DATA6}</li> 1606 * <li>{@link #SYNC_DATA7}</li> 1607 * <li>{@link #SYNC_DATA8}</li> 1608 * <li>{@link #SYNC_DATA9}</li> 1609 * <li>{@link #SYNC_DATA10}</li> 1610 * </ul> 1611 * The remaining columns are either updated by the provider only or are 1612 * views into other tables and cannot be changed through the Events table. 1613 */ 1614 public static final class Events implements BaseColumns, SyncColumns, EventsColumns, 1615 CalendarColumns { 1616 1617 /** 1618 * The content:// style URL for interacting with events. Appending an 1619 * event id using {@link ContentUris#withAppendedId(Uri, long)} will 1620 * specify a single event. 1621 */ 1622 @SuppressWarnings("hiding") 1623 public static final Uri CONTENT_URI = 1624 Uri.parse("content://" + AUTHORITY + "/events"); 1625 1626 /** 1627 * The content:// style URI for recurring event exceptions. Insertions require an 1628 * appended event ID. Deletion of exceptions requires both the original event ID and 1629 * the exception event ID (see {@link Uri.Builder#appendPath}). 1630 */ 1631 public static final Uri CONTENT_EXCEPTION_URI = 1632 Uri.parse("content://" + AUTHORITY + "/exception"); 1633 1634 /** 1635 * This utility class cannot be instantiated 1636 */ 1637 private Events() {} 1638 1639 /** 1640 * The default sort order for this table 1641 */ 1642 private static final String DEFAULT_SORT_ORDER = ""; 1643 1644 /** 1645 * These are columns that should only ever be updated by the provider, 1646 * either because they are views mapped to another table or because they 1647 * are used for provider only functionality. TODO move to provider 1648 * 1649 * @hide 1650 */ 1651 public static String[] PROVIDER_WRITABLE_COLUMNS = new String[] { 1652 ACCOUNT_NAME, 1653 ACCOUNT_TYPE, 1654 CAL_SYNC1, 1655 CAL_SYNC2, 1656 CAL_SYNC3, 1657 CAL_SYNC4, 1658 CAL_SYNC5, 1659 CAL_SYNC6, 1660 CAL_SYNC7, 1661 CAL_SYNC8, 1662 CAL_SYNC9, 1663 CAL_SYNC10, 1664 ALLOWED_REMINDERS, 1665 ALLOWED_ATTENDEE_TYPES, 1666 ALLOWED_AVAILABILITY, 1667 CALENDAR_ACCESS_LEVEL, 1668 CALENDAR_COLOR, 1669 CALENDAR_TIME_ZONE, 1670 CAN_MODIFY_TIME_ZONE, 1671 CAN_ORGANIZER_RESPOND, 1672 CALENDAR_DISPLAY_NAME, 1673 CAN_PARTIALLY_UPDATE, 1674 SYNC_EVENTS, 1675 VISIBLE, 1676 }; 1677 1678 /** 1679 * These fields are only writable by a sync adapter. To modify them the 1680 * caller must include CALLER_IS_SYNCADAPTER, _SYNC_ACCOUNT, and 1681 * _SYNC_ACCOUNT_TYPE in the query parameters. TODO move to provider. 1682 * 1683 * @hide 1684 */ 1685 public static final String[] SYNC_WRITABLE_COLUMNS = new String[] { 1686 _SYNC_ID, 1687 DIRTY, 1688 SYNC_DATA1, 1689 SYNC_DATA2, 1690 SYNC_DATA3, 1691 SYNC_DATA4, 1692 SYNC_DATA5, 1693 SYNC_DATA6, 1694 SYNC_DATA7, 1695 SYNC_DATA8, 1696 SYNC_DATA9, 1697 SYNC_DATA10, 1698 }; 1699 } 1700 1701 /** 1702 * Fields and helpers for interacting with Instances. An instance is a 1703 * single occurrence of an event including time zone specific start and end 1704 * days and minutes. The instances table is not writable and only provides a 1705 * way to query event occurrences. 1706 */ 1707 public static final class Instances implements BaseColumns, EventsColumns, CalendarColumns { 1708 1709 private static final String WHERE_CALENDARS_SELECTED = Calendars.VISIBLE + "=?"; 1710 private static final String[] WHERE_CALENDARS_ARGS = { 1711 "1" 1712 }; 1713 1714 /** 1715 * This utility class cannot be instantiated 1716 */ 1717 private Instances() {} 1718 1719 /** 1720 * Performs a query to return all visible instances in the given range. 1721 * This is a blocking function and should not be done on the UI thread. 1722 * This will cause an expansion of recurring events to fill this time 1723 * range if they are not already expanded and will slow down for larger 1724 * time ranges with many recurring events. 1725 * 1726 * @param cr The ContentResolver to use for the query 1727 * @param projection The columns to return 1728 * @param begin The start of the time range to query in UTC millis since 1729 * epoch 1730 * @param end The end of the time range to query in UTC millis since 1731 * epoch 1732 * @return A Cursor containing all instances in the given range 1733 */ 1734 public static final Cursor query(ContentResolver cr, String[] projection, 1735 long begin, long end) { 1736 Uri.Builder builder = CONTENT_URI.buildUpon(); 1737 ContentUris.appendId(builder, begin); 1738 ContentUris.appendId(builder, end); 1739 return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED, 1740 WHERE_CALENDARS_ARGS, DEFAULT_SORT_ORDER); 1741 } 1742 1743 /** 1744 * Performs a query to return all visible instances in the given range 1745 * that match the given query. This is a blocking function and should 1746 * not be done on the UI thread. This will cause an expansion of 1747 * recurring events to fill this time range if they are not already 1748 * expanded and will slow down for larger time ranges with many 1749 * recurring events. 1750 * 1751 * @param cr The ContentResolver to use for the query 1752 * @param projection The columns to return 1753 * @param begin The start of the time range to query in UTC millis since 1754 * epoch 1755 * @param end The end of the time range to query in UTC millis since 1756 * epoch 1757 * @param searchQuery A string of space separated search terms. Segments 1758 * enclosed by double quotes will be treated as a single 1759 * term. 1760 * @return A Cursor of instances matching the search terms in the given 1761 * time range 1762 */ 1763 public static final Cursor query(ContentResolver cr, String[] projection, 1764 long begin, long end, String searchQuery) { 1765 Uri.Builder builder = CONTENT_SEARCH_URI.buildUpon(); 1766 ContentUris.appendId(builder, begin); 1767 ContentUris.appendId(builder, end); 1768 builder = builder.appendPath(searchQuery); 1769 return cr.query(builder.build(), projection, WHERE_CALENDARS_SELECTED, 1770 WHERE_CALENDARS_ARGS, DEFAULT_SORT_ORDER); 1771 } 1772 1773 /** 1774 * The content:// style URL for querying an instance range. The begin 1775 * and end of the range to query should be added as path segments if 1776 * this is used directly. 1777 */ 1778 @SuppressWarnings("hiding") 1779 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + 1780 "/instances/when"); 1781 /** 1782 * The content:// style URL for querying an instance range by Julian 1783 * Day. The start and end day should be added as path segments if this 1784 * is used directly. 1785 */ 1786 public static final Uri CONTENT_BY_DAY_URI = 1787 Uri.parse("content://" + AUTHORITY + "/instances/whenbyday"); 1788 /** 1789 * The content:// style URL for querying an instance range with a search 1790 * term. The begin, end, and search string should be appended as path 1791 * segments if this is used directly. 1792 */ 1793 public static final Uri CONTENT_SEARCH_URI = Uri.parse("content://" + AUTHORITY + 1794 "/instances/search"); 1795 /** 1796 * The content:// style URL for querying an instance range with a search 1797 * term. The start day, end day, and search string should be appended as 1798 * path segments if this is used directly. 1799 */ 1800 public static final Uri CONTENT_SEARCH_BY_DAY_URI = 1801 Uri.parse("content://" + AUTHORITY + "/instances/searchbyday"); 1802 1803 /** 1804 * The default sort order for this table. 1805 */ 1806 private static final String DEFAULT_SORT_ORDER = "begin ASC"; 1807 1808 /** 1809 * The beginning time of the instance, in UTC milliseconds. Column name. 1810 * <P>Type: INTEGER (long; millis since epoch)</P> 1811 */ 1812 public static final String BEGIN = "begin"; 1813 1814 /** 1815 * The ending time of the instance, in UTC milliseconds. Column name. 1816 * <P>Type: INTEGER (long; millis since epoch)</P> 1817 */ 1818 public static final String END = "end"; 1819 1820 /** 1821 * The _id of the event for this instance. Column name. 1822 * <P>Type: INTEGER (long, foreign key to the Events table)</P> 1823 */ 1824 public static final String EVENT_ID = "event_id"; 1825 1826 /** 1827 * The Julian start day of the instance, relative to the local time 1828 * zone. Column name. 1829 * <P>Type: INTEGER (int)</P> 1830 */ 1831 public static final String START_DAY = "startDay"; 1832 1833 /** 1834 * The Julian end day of the instance, relative to the local time 1835 * zone. Column name. 1836 * <P>Type: INTEGER (int)</P> 1837 */ 1838 public static final String END_DAY = "endDay"; 1839 1840 /** 1841 * The start minute of the instance measured from midnight in the 1842 * local time zone. Column name. 1843 * <P>Type: INTEGER (int)</P> 1844 */ 1845 public static final String START_MINUTE = "startMinute"; 1846 1847 /** 1848 * The end minute of the instance measured from midnight in the 1849 * local time zone. Column name. 1850 * <P>Type: INTEGER (int)</P> 1851 */ 1852 public static final String END_MINUTE = "endMinute"; 1853 } 1854 1855 protected interface CalendarCacheColumns { 1856 /** 1857 * The key for the setting. Keys are defined in {@link CalendarCache}. 1858 */ 1859 public static final String KEY = "key"; 1860 1861 /** 1862 * The value of the given setting. 1863 */ 1864 public static final String VALUE = "value"; 1865 } 1866 1867 /** 1868 * CalendarCache stores some settings for calendar including the current 1869 * time zone for the instances. These settings are stored using a key/value 1870 * scheme. A {@link #KEY} must be specified when updating these values. 1871 */ 1872 public static final class CalendarCache implements CalendarCacheColumns { 1873 /** 1874 * The URI to use for retrieving the properties from the Calendar db. 1875 */ 1876 public static final Uri URI = 1877 Uri.parse("content://" + AUTHORITY + "/properties"); 1878 1879 /** 1880 * This utility class cannot be instantiated 1881 */ 1882 private CalendarCache() {} 1883 1884 /** 1885 * They key for updating the use of auto/home time zones in Calendar. 1886 * Valid values are {@link #TIMEZONE_TYPE_AUTO} or 1887 * {@link #TIMEZONE_TYPE_HOME}. 1888 */ 1889 public static final String KEY_TIMEZONE_TYPE = "timezoneType"; 1890 1891 /** 1892 * The key for updating the time zone used by the provider when it 1893 * generates the instances table. This should only be written if the 1894 * type is set to {@link #TIMEZONE_TYPE_HOME}. A valid time zone id 1895 * should be written to this field. 1896 */ 1897 public static final String KEY_TIMEZONE_INSTANCES = "timezoneInstances"; 1898 1899 /** 1900 * The key for reading the last time zone set by the user. This should 1901 * only be read by apps and it will be automatically updated whenever 1902 * {@link #KEY_TIMEZONE_INSTANCES} is updated with 1903 * {@link #TIMEZONE_TYPE_HOME} set. 1904 */ 1905 public static final String KEY_TIMEZONE_INSTANCES_PREVIOUS = "timezoneInstancesPrevious"; 1906 1907 /** 1908 * The value to write to {@link #KEY_TIMEZONE_TYPE} if the provider 1909 * should stay in sync with the device's time zone. 1910 */ 1911 public static final String TIMEZONE_TYPE_AUTO = "auto"; 1912 1913 /** 1914 * The value to write to {@link #KEY_TIMEZONE_TYPE} if the provider 1915 * should use a fixed time zone set by the user. 1916 */ 1917 public static final String TIMEZONE_TYPE_HOME = "home"; 1918 } 1919 1920 /** 1921 * A few Calendar globals are needed in the CalendarProvider for expanding 1922 * the Instances table and these are all stored in the first (and only) row 1923 * of the CalendarMetaData table. 1924 * 1925 * @hide 1926 */ 1927 protected interface CalendarMetaDataColumns { 1928 /** 1929 * The local timezone that was used for precomputing the fields 1930 * in the Instances table. 1931 */ 1932 public static final String LOCAL_TIMEZONE = "localTimezone"; 1933 1934 /** 1935 * The minimum time used in expanding the Instances table, 1936 * in UTC milliseconds. 1937 * <P>Type: INTEGER</P> 1938 */ 1939 public static final String MIN_INSTANCE = "minInstance"; 1940 1941 /** 1942 * The maximum time used in expanding the Instances table, 1943 * in UTC milliseconds. 1944 * <P>Type: INTEGER</P> 1945 */ 1946 public static final String MAX_INSTANCE = "maxInstance"; 1947 1948 /** 1949 * The minimum Julian day in the EventDays table. 1950 * <P>Type: INTEGER</P> 1951 */ 1952 public static final String MIN_EVENTDAYS = "minEventDays"; 1953 1954 /** 1955 * The maximum Julian day in the EventDays table. 1956 * <P>Type: INTEGER</P> 1957 */ 1958 public static final String MAX_EVENTDAYS = "maxEventDays"; 1959 } 1960 1961 /** 1962 * @hide 1963 */ 1964 public static final class CalendarMetaData implements CalendarMetaDataColumns, BaseColumns { 1965 1966 /** 1967 * This utility class cannot be instantiated 1968 */ 1969 private CalendarMetaData() {} 1970 } 1971 1972 protected interface EventDaysColumns { 1973 /** 1974 * The Julian starting day number. Column name. 1975 * <P>Type: INTEGER (int)</P> 1976 */ 1977 public static final String STARTDAY = "startDay"; 1978 /** 1979 * The Julian ending day number. Column name. 1980 * <P>Type: INTEGER (int)</P> 1981 */ 1982 public static final String ENDDAY = "endDay"; 1983 1984 } 1985 1986 /** 1987 * Fields and helpers for querying for a list of days that contain events. 1988 */ 1989 public static final class EventDays implements EventDaysColumns { 1990 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY 1991 + "/instances/groupbyday"); 1992 private static final String SELECTION = "selected=1"; 1993 1994 /** 1995 * This utility class cannot be instantiated 1996 */ 1997 private EventDays() {} 1998 1999 /** 2000 * Retrieves the days with events for the Julian days starting at 2001 * "startDay" for "numDays". It returns a cursor containing startday and 2002 * endday representing the max range of days for all events beginning on 2003 * each startday.This is a blocking function and should not be done on 2004 * the UI thread. 2005 * 2006 * @param cr the ContentResolver 2007 * @param startDay the first Julian day in the range 2008 * @param numDays the number of days to load (must be at least 1) 2009 * @param projection the columns to return in the cursor 2010 * @return a database cursor containing a list of start and end days for 2011 * events 2012 */ 2013 public static final Cursor query(ContentResolver cr, int startDay, int numDays, 2014 String[] projection) { 2015 if (numDays < 1) { 2016 return null; 2017 } 2018 int endDay = startDay + numDays - 1; 2019 Uri.Builder builder = CONTENT_URI.buildUpon(); 2020 ContentUris.appendId(builder, startDay); 2021 ContentUris.appendId(builder, endDay); 2022 return cr.query(builder.build(), projection, SELECTION, 2023 null /* selection args */, STARTDAY); 2024 } 2025 } 2026 2027 protected interface RemindersColumns { 2028 /** 2029 * The event the reminder belongs to. Column name. 2030 * <P>Type: INTEGER (foreign key to the Events table)</P> 2031 */ 2032 public static final String EVENT_ID = "event_id"; 2033 2034 /** 2035 * The minutes prior to the event that the alarm should ring. -1 2036 * specifies that we should use the default value for the system. 2037 * Column name. 2038 * <P>Type: INTEGER</P> 2039 */ 2040 public static final String MINUTES = "minutes"; 2041 2042 /** 2043 * Passing this as a minutes value will use the default reminder 2044 * minutes. 2045 */ 2046 public static final int MINUTES_DEFAULT = -1; 2047 2048 /** 2049 * The alarm method, as set on the server. {@link #METHOD_DEFAULT}, 2050 * {@link #METHOD_ALERT}, {@link #METHOD_EMAIL}, {@link #METHOD_SMS} and 2051 * {@link #METHOD_ALARM} are possible values; the device will only 2052 * process {@link #METHOD_DEFAULT} and {@link #METHOD_ALERT} reminders 2053 * (the other types are simply stored so we can send the same reminder 2054 * info back to the server when we make changes). 2055 */ 2056 public static final String METHOD = "method"; 2057 2058 public static final int METHOD_DEFAULT = 0; 2059 public static final int METHOD_ALERT = 1; 2060 public static final int METHOD_EMAIL = 2; 2061 public static final int METHOD_SMS = 3; 2062 public static final int METHOD_ALARM = 4; 2063 } 2064 2065 /** 2066 * Fields and helpers for accessing reminders for an event. Each row of this 2067 * table represents a single reminder for an event. Calling 2068 * {@link #query(ContentResolver, long, String[])} will return a list of reminders for 2069 * the event with the given eventId. Both apps and sync adapters may write 2070 * to this table. There are three writable fields and all of them must be 2071 * included when inserting a new reminder. They are: 2072 * <ul> 2073 * <li>{@link #EVENT_ID}</li> 2074 * <li>{@link #MINUTES}</li> 2075 * <li>{@link #METHOD}</li> 2076 * </ul> 2077 */ 2078 public static final class Reminders implements BaseColumns, RemindersColumns, EventsColumns { 2079 private static final String REMINDERS_WHERE = CalendarContract.Reminders.EVENT_ID + "=?"; 2080 @SuppressWarnings("hiding") 2081 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/reminders"); 2082 2083 /** 2084 * This utility class cannot be instantiated 2085 */ 2086 private Reminders() {} 2087 2088 /** 2089 * Queries all reminders associated with the given event. This is a 2090 * blocking call and should not be done on the UI thread. 2091 * 2092 * @param cr The content resolver to use for the query 2093 * @param eventId The id of the event to retrieve reminders for 2094 * @param projection the columns to return in the cursor 2095 * @return A Cursor containing all reminders for the event 2096 */ 2097 public static final Cursor query(ContentResolver cr, long eventId, String[] projection) { 2098 String[] remArgs = {Long.toString(eventId)}; 2099 return cr.query(CONTENT_URI, projection, REMINDERS_WHERE, remArgs /*selection args*/, 2100 null /* sort order */); 2101 } 2102 } 2103 2104 protected interface CalendarAlertsColumns { 2105 /** 2106 * The event that the alert belongs to. Column name. 2107 * <P>Type: INTEGER (foreign key to the Events table)</P> 2108 */ 2109 public static final String EVENT_ID = "event_id"; 2110 2111 /** 2112 * The start time of the event, in UTC. Column name. 2113 * <P>Type: INTEGER (long; millis since epoch)</P> 2114 */ 2115 public static final String BEGIN = "begin"; 2116 2117 /** 2118 * The end time of the event, in UTC. Column name. 2119 * <P>Type: INTEGER (long; millis since epoch)</P> 2120 */ 2121 public static final String END = "end"; 2122 2123 /** 2124 * The alarm time of the event, in UTC. Column name. 2125 * <P>Type: INTEGER (long; millis since epoch)</P> 2126 */ 2127 public static final String ALARM_TIME = "alarmTime"; 2128 2129 /** 2130 * The creation time of this database entry, in UTC. 2131 * Useful for debugging missed reminders. Column name. 2132 * <P>Type: INTEGER (long; millis since epoch)</P> 2133 */ 2134 public static final String CREATION_TIME = "creationTime"; 2135 2136 /** 2137 * The time that the alarm broadcast was received by the Calendar app, 2138 * in UTC. Useful for debugging missed reminders. Column name. 2139 * <P>Type: INTEGER (long; millis since epoch)</P> 2140 */ 2141 public static final String RECEIVED_TIME = "receivedTime"; 2142 2143 /** 2144 * The time that the notification was created by the Calendar app, 2145 * in UTC. Useful for debugging missed reminders. Column name. 2146 * <P>Type: INTEGER (long; millis since epoch)</P> 2147 */ 2148 public static final String NOTIFY_TIME = "notifyTime"; 2149 2150 /** 2151 * The state of this alert. It starts out as {@link #STATE_SCHEDULED}, then 2152 * when the alarm goes off, it changes to {@link #STATE_FIRED}, and then when 2153 * the user dismisses the alarm it changes to {@link #STATE_DISMISSED}. Column 2154 * name. 2155 * <P>Type: INTEGER</P> 2156 */ 2157 public static final String STATE = "state"; 2158 2159 /** 2160 * An alert begins in this state when it is first created. 2161 */ 2162 public static final int STATE_SCHEDULED = 0; 2163 /** 2164 * After a notification for an alert has been created it should be 2165 * updated to fired. 2166 */ 2167 public static final int STATE_FIRED = 1; 2168 /** 2169 * Once the user has dismissed the notification the alert's state should 2170 * be set to dismissed so it is not fired again. 2171 */ 2172 public static final int STATE_DISMISSED = 2; 2173 2174 /** 2175 * The number of minutes that this alarm precedes the start time. Column 2176 * name. 2177 * <P>Type: INTEGER</P> 2178 */ 2179 public static final String MINUTES = "minutes"; 2180 2181 /** 2182 * The default sort order for this alerts queries 2183 */ 2184 public static final String DEFAULT_SORT_ORDER = "begin ASC,title ASC"; 2185 } 2186 2187 /** 2188 * Fields and helpers for accessing calendar alerts information. These 2189 * fields are for tracking which alerts have been fired. Scheduled alarms 2190 * will generate an intent using {@link #ACTION_EVENT_REMINDER}. Apps that 2191 * receive this action may update the {@link #STATE} for the reminder when 2192 * they have finished handling it. Apps that have their notifications 2193 * disabled should not modify the table to ensure that they do not conflict 2194 * with another app that is generating a notification. In general, apps 2195 * should not need to write to this table directly except to update the 2196 * state of a reminder. 2197 */ 2198 public static final class CalendarAlerts implements BaseColumns, 2199 CalendarAlertsColumns, EventsColumns, CalendarColumns { 2200 2201 /** 2202 * @hide 2203 */ 2204 public static final String TABLE_NAME = "CalendarAlerts"; 2205 /** 2206 * The Uri for querying calendar alert information 2207 */ 2208 @SuppressWarnings("hiding") 2209 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + 2210 "/calendar_alerts"); 2211 2212 /** 2213 * This utility class cannot be instantiated 2214 */ 2215 private CalendarAlerts() {} 2216 2217 private static final String WHERE_ALARM_EXISTS = EVENT_ID + "=?" 2218 + " AND " + BEGIN + "=?" 2219 + " AND " + ALARM_TIME + "=?"; 2220 2221 private static final String WHERE_FINDNEXTALARMTIME = ALARM_TIME + ">=?"; 2222 private static final String SORT_ORDER_ALARMTIME_ASC = ALARM_TIME + " ASC"; 2223 2224 private static final String WHERE_RESCHEDULE_MISSED_ALARMS = STATE + "=" + STATE_SCHEDULED 2225 + " AND " + ALARM_TIME + "<?" 2226 + " AND " + ALARM_TIME + ">?" 2227 + " AND " + END + ">=?"; 2228 2229 /** 2230 * This URI is for grouping the query results by event_id and begin 2231 * time. This will return one result per instance of an event. So 2232 * events with multiple alarms will appear just once, but multiple 2233 * instances of a repeating event will show up multiple times. 2234 */ 2235 public static final Uri CONTENT_URI_BY_INSTANCE = 2236 Uri.parse("content://" + AUTHORITY + "/calendar_alerts/by_instance"); 2237 2238 private static final boolean DEBUG = false; 2239 2240 /** 2241 * Helper for inserting an alarm time associated with an event TODO move 2242 * to Provider 2243 * 2244 * @hide 2245 */ 2246 public static final Uri insert(ContentResolver cr, long eventId, 2247 long begin, long end, long alarmTime, int minutes) { 2248 ContentValues values = new ContentValues(); 2249 values.put(CalendarAlerts.EVENT_ID, eventId); 2250 values.put(CalendarAlerts.BEGIN, begin); 2251 values.put(CalendarAlerts.END, end); 2252 values.put(CalendarAlerts.ALARM_TIME, alarmTime); 2253 long currentTime = System.currentTimeMillis(); 2254 values.put(CalendarAlerts.CREATION_TIME, currentTime); 2255 values.put(CalendarAlerts.RECEIVED_TIME, 0); 2256 values.put(CalendarAlerts.NOTIFY_TIME, 0); 2257 values.put(CalendarAlerts.STATE, STATE_SCHEDULED); 2258 values.put(CalendarAlerts.MINUTES, minutes); 2259 return cr.insert(CONTENT_URI, values); 2260 } 2261 2262 /** 2263 * Finds the next alarm after (or equal to) the given time and returns 2264 * the time of that alarm or -1 if no such alarm exists. This is a 2265 * blocking call and should not be done on the UI thread. TODO move to 2266 * provider 2267 * 2268 * @param cr the ContentResolver 2269 * @param millis the time in UTC milliseconds 2270 * @return the next alarm time greater than or equal to "millis", or -1 2271 * if no such alarm exists. 2272 * @hide 2273 */ 2274 public static final long findNextAlarmTime(ContentResolver cr, long millis) { 2275 String selection = ALARM_TIME + ">=" + millis; 2276 // TODO: construct an explicit SQL query so that we can add 2277 // "LIMIT 1" to the end and get just one result. 2278 String[] projection = new String[] { ALARM_TIME }; 2279 Cursor cursor = cr.query(CONTENT_URI, projection, WHERE_FINDNEXTALARMTIME, 2280 (new String[] { 2281 Long.toString(millis) 2282 }), SORT_ORDER_ALARMTIME_ASC); 2283 long alarmTime = -1; 2284 try { 2285 if (cursor != null && cursor.moveToFirst()) { 2286 alarmTime = cursor.getLong(0); 2287 } 2288 } finally { 2289 if (cursor != null) { 2290 cursor.close(); 2291 } 2292 } 2293 return alarmTime; 2294 } 2295 2296 /** 2297 * Searches the CalendarAlerts table for alarms that should have fired 2298 * but have not and then reschedules them. This method can be called at 2299 * boot time to restore alarms that may have been lost due to a phone 2300 * reboot. TODO move to provider 2301 * 2302 * @param cr the ContentResolver 2303 * @param context the Context 2304 * @param manager the AlarmManager 2305 * @hide 2306 */ 2307 public static final void rescheduleMissedAlarms(ContentResolver cr, 2308 Context context, AlarmManager manager) { 2309 // Get all the alerts that have been scheduled but have not fired 2310 // and should have fired by now and are not too old. 2311 long now = System.currentTimeMillis(); 2312 long ancient = now - DateUtils.DAY_IN_MILLIS; 2313 String[] projection = new String[] { 2314 ALARM_TIME, 2315 }; 2316 2317 // TODO: construct an explicit SQL query so that we can add 2318 // "GROUPBY" instead of doing a sort and de-dup 2319 Cursor cursor = cr.query(CalendarAlerts.CONTENT_URI, projection, 2320 WHERE_RESCHEDULE_MISSED_ALARMS, (new String[] { 2321 Long.toString(now), Long.toString(ancient), Long.toString(now) 2322 }), SORT_ORDER_ALARMTIME_ASC); 2323 if (cursor == null) { 2324 return; 2325 } 2326 2327 if (DEBUG) { 2328 Log.d(TAG, "missed alarms found: " + cursor.getCount()); 2329 } 2330 2331 try { 2332 long alarmTime = -1; 2333 2334 while (cursor.moveToNext()) { 2335 long newAlarmTime = cursor.getLong(0); 2336 if (alarmTime != newAlarmTime) { 2337 if (DEBUG) { 2338 Log.w(TAG, "rescheduling missed alarm. alarmTime: " + newAlarmTime); 2339 } 2340 scheduleAlarm(context, manager, newAlarmTime); 2341 alarmTime = newAlarmTime; 2342 } 2343 } 2344 } finally { 2345 cursor.close(); 2346 } 2347 } 2348 2349 /** 2350 * Schedules an alarm intent with the system AlarmManager that will 2351 * notify listeners when a reminder should be fired. The provider will 2352 * keep scheduled reminders up to date but apps may use this to 2353 * implement snooze functionality without modifying the reminders table. 2354 * Scheduled alarms will generate an intent using 2355 * {@link #ACTION_EVENT_REMINDER}. TODO Move to provider 2356 * 2357 * @param context A context for referencing system resources 2358 * @param manager The AlarmManager to use or null 2359 * @param alarmTime The time to fire the intent in UTC millis since 2360 * epoch 2361 * @hide 2362 */ 2363 public static void scheduleAlarm(Context context, AlarmManager manager, long alarmTime) { 2364 if (DEBUG) { 2365 Time time = new Time(); 2366 time.set(alarmTime); 2367 String schedTime = time.format(" %a, %b %d, %Y %I:%M%P"); 2368 Log.d(TAG, "Schedule alarm at " + alarmTime + " " + schedTime); 2369 } 2370 2371 if (manager == null) { 2372 manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 2373 } 2374 2375 Intent intent = new Intent(ACTION_EVENT_REMINDER); 2376 intent.setData(ContentUris.withAppendedId(CalendarContract.CONTENT_URI, alarmTime)); 2377 intent.putExtra(ALARM_TIME, alarmTime); 2378 PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0); 2379 manager.set(AlarmManager.RTC_WAKEUP, alarmTime, pi); 2380 } 2381 2382 /** 2383 * Searches for an entry in the CalendarAlerts table that matches the 2384 * given event id, begin time and alarm time. If one is found then this 2385 * alarm already exists and this method returns true. TODO Move to 2386 * provider 2387 * 2388 * @param cr the ContentResolver 2389 * @param eventId the event id to match 2390 * @param begin the start time of the event in UTC millis 2391 * @param alarmTime the alarm time of the event in UTC millis 2392 * @return true if there is already an alarm for the given event with 2393 * the same start time and alarm time. 2394 * @hide 2395 */ 2396 public static final boolean alarmExists(ContentResolver cr, long eventId, 2397 long begin, long alarmTime) { 2398 // TODO: construct an explicit SQL query so that we can add 2399 // "LIMIT 1" to the end and get just one result. 2400 String[] projection = new String[] { ALARM_TIME }; 2401 Cursor cursor = cr.query(CONTENT_URI, projection, WHERE_ALARM_EXISTS, 2402 (new String[] { 2403 Long.toString(eventId), Long.toString(begin), Long.toString(alarmTime) 2404 }), null); 2405 boolean found = false; 2406 try { 2407 if (cursor != null && cursor.getCount() > 0) { 2408 found = true; 2409 } 2410 } finally { 2411 if (cursor != null) { 2412 cursor.close(); 2413 } 2414 } 2415 return found; 2416 } 2417 } 2418 2419 protected interface ColorsColumns extends SyncStateContract.Columns { 2420 2421 /** 2422 * The type of color, which describes how it should be used. Valid types 2423 * are {@link #TYPE_CALENDAR} and {@link #TYPE_EVENT}. Column name. 2424 * <P> 2425 * Type: INTEGER (NOT NULL) 2426 * </P> 2427 */ 2428 public static final String COLOR_TYPE = "color_type"; 2429 2430 /** 2431 * This indicateds a color that can be used for calendars. 2432 */ 2433 public static final int TYPE_CALENDAR = 0; 2434 /** 2435 * This indicates a color that can be used for events. 2436 */ 2437 public static final int TYPE_EVENT = 1; 2438 2439 /** 2440 * The key used to reference this color. This can be any non-empty 2441 * string, but must be unique for a given {@link #ACCOUNT_TYPE} and 2442 * {@link #ACCOUNT_NAME}. Column name. 2443 * <P> 2444 * Type: TEXT 2445 * </P> 2446 */ 2447 public static final String COLOR_KEY = "color_index"; 2448 2449 /** 2450 * The color as an 8-bit ARGB integer value. Colors should specify alpha 2451 * as fully opaque (eg 0xFF993322) as the alpha may be ignored or 2452 * modified for display. It is reccomended that colors be usable with 2453 * light (near white) text. Apps should not depend on that assumption, 2454 * however. Column name. 2455 * <P> 2456 * Type: INTEGER (NOT NULL) 2457 * </P> 2458 */ 2459 public static final String COLOR = "color"; 2460 2461 } 2462 2463 /** 2464 * Fields for accessing colors available for a given account. Colors are 2465 * referenced by {@link #COLOR_KEY} which must be unique for a given 2466 * account name/type. These values can only be updated by the sync 2467 * adapter. Only {@link #COLOR} may be updated after the initial insert. In 2468 * addition, a row can only be deleted once all references to that color 2469 * have been removed from the {@link Calendars} or {@link Events} tables. 2470 */ 2471 public static final class Colors implements ColorsColumns { 2472 /** 2473 * @hide 2474 */ 2475 public static final String TABLE_NAME = "Colors"; 2476 /** 2477 * The Uri for querying color information 2478 */ 2479 @SuppressWarnings("hiding") 2480 public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/colors"); 2481 2482 /** 2483 * This utility class cannot be instantiated 2484 */ 2485 private Colors() { 2486 } 2487 } 2488 2489 protected interface ExtendedPropertiesColumns { 2490 /** 2491 * The event the extended property belongs to. Column name. 2492 * <P>Type: INTEGER (foreign key to the Events table)</P> 2493 */ 2494 public static final String EVENT_ID = "event_id"; 2495 2496 /** 2497 * The name of the extended property. This is a uri of the form 2498 * {scheme}#{local-name} convention. Column name. 2499 * <P>Type: TEXT</P> 2500 */ 2501 public static final String NAME = "name"; 2502 2503 /** 2504 * The value of the extended property. Column name. 2505 * <P>Type: TEXT</P> 2506 */ 2507 public static final String VALUE = "value"; 2508 } 2509 2510 /** 2511 * Fields for accessing the Extended Properties. This is a generic set of 2512 * name/value pairs for use by sync adapters to add extra 2513 * information to events. There are three writable columns and all three 2514 * must be present when inserting a new value. They are: 2515 * <ul> 2516 * <li>{@link #EVENT_ID}</li> 2517 * <li>{@link #NAME}</li> 2518 * <li>{@link #VALUE}</li> 2519 * </ul> 2520 */ 2521 public static final class ExtendedProperties implements BaseColumns, 2522 ExtendedPropertiesColumns, EventsColumns { 2523 public static final Uri CONTENT_URI = 2524 Uri.parse("content://" + AUTHORITY + "/extendedproperties"); 2525 2526 /** 2527 * This utility class cannot be instantiated 2528 */ 2529 private ExtendedProperties() {} 2530 2531 // TODO: fill out this class when we actually start utilizing extendedproperties 2532 // in the calendar application. 2533 } 2534 2535 /** 2536 * A table provided for sync adapters to use for storing private sync state data. 2537 * 2538 * @see SyncStateContract 2539 */ 2540 public static final class SyncState implements SyncStateContract.Columns { 2541 /** 2542 * This utility class cannot be instantiated 2543 */ 2544 private SyncState() {} 2545 2546 private static final String CONTENT_DIRECTORY = 2547 SyncStateContract.Constants.CONTENT_DIRECTORY; 2548 2549 /** 2550 * The content:// style URI for this table 2551 */ 2552 public static final Uri CONTENT_URI = 2553 Uri.withAppendedPath(CalendarContract.CONTENT_URI, CONTENT_DIRECTORY); 2554 } 2555 2556 /** 2557 * Columns from the EventsRawTimes table 2558 * 2559 * @hide 2560 */ 2561 protected interface EventsRawTimesColumns { 2562 /** 2563 * The corresponding event id. Column name. 2564 * <P>Type: INTEGER (long)</P> 2565 */ 2566 public static final String EVENT_ID = "event_id"; 2567 2568 /** 2569 * The RFC2445 compliant time the event starts. Column name. 2570 * <P>Type: TEXT</P> 2571 */ 2572 public static final String DTSTART_2445 = "dtstart2445"; 2573 2574 /** 2575 * The RFC2445 compliant time the event ends. Column name. 2576 * <P>Type: TEXT</P> 2577 */ 2578 public static final String DTEND_2445 = "dtend2445"; 2579 2580 /** 2581 * The RFC2445 compliant original instance time of the recurring event 2582 * for which this event is an exception. Column name. 2583 * <P>Type: TEXT</P> 2584 */ 2585 public static final String ORIGINAL_INSTANCE_TIME_2445 = "originalInstanceTime2445"; 2586 2587 /** 2588 * The RFC2445 compliant last date this event repeats on, or NULL if it 2589 * never ends. Column name. 2590 * <P>Type: TEXT</P> 2591 */ 2592 public static final String LAST_DATE_2445 = "lastDate2445"; 2593 } 2594 2595 /** 2596 * @hide 2597 */ 2598 public static final class EventsRawTimes implements BaseColumns, EventsRawTimesColumns { 2599 2600 /** 2601 * This utility class cannot be instantiated 2602 */ 2603 private EventsRawTimes() {} 2604 } 2605} 2606