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