ContactsContract.java revision 747c61535281b4d2958e293e83245a19ba58f6a0
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package android.provider;
18
19import android.accounts.Account;
20import android.content.ContentProviderClient;
21import android.content.ContentProviderOperation;
22import android.content.ContentResolver;
23import android.content.ContentUris;
24import android.content.ContentValues;
25import android.content.Context;
26import android.content.CursorEntityIterator;
27import android.content.Entity;
28import android.content.EntityIterator;
29import android.content.Intent;
30import android.content.res.Resources;
31import android.database.Cursor;
32import android.database.DatabaseUtils;
33import android.database.sqlite.SQLiteException;
34import android.graphics.Rect;
35import android.net.Uri;
36import android.os.RemoteException;
37import android.text.TextUtils;
38import android.util.DisplayMetrics;
39import android.util.Pair;
40import android.view.View;
41
42import java.io.ByteArrayInputStream;
43import java.io.InputStream;
44
45/**
46 * <p>
47 * The contract between the contacts provider and applications. Contains
48 * definitions for the supported URIs and columns. These APIs supersede
49 * {@link Contacts}.
50 * </p>
51 * <h3>Overview</h3>
52 * <p>
53 * ContactsContract defines an extensible database of contact-related
54 * information. Contact information is stored in a three-tier data model:
55 * </p>
56 * <ul>
57 * <li>
58 * A row in the {@link Data} table can store any kind of personal data, such
59 * as a phone number or email addresses.  The set of data kinds that can be
60 * stored in this table is open-ended. There is a predefined set of common
61 * kinds, but any application can add its own data kinds.
62 * </li>
63 * <li>
64 * A row in the {@link RawContacts} table represents a set of data describing a
65 * person and associated with a single account (for example, one of the user's
66 * Gmail accounts).
67 * </li>
68 * <li>
69 * A row in the {@link Contacts} table represents an aggregate of one or more
70 * RawContacts presumably describing the same person.  When data in or associated with
71 * the RawContacts table is changed, the affected aggregate contacts are updated as
72 * necessary.
73 * </li>
74 * </ul>
75 * <p>
76 * Other tables include:
77 * </p>
78 * <ul>
79 * <li>
80 * {@link Groups}, which contains information about raw contact groups
81 * such as Gmail contact groups.  The
82 * current API does not support the notion of groups spanning multiple accounts.
83 * </li>
84 * <li>
85 * {@link StatusUpdates}, which contains social status updates including IM
86 * availability.
87 * </li>
88 * <li>
89 * {@link AggregationExceptions}, which is used for manual aggregation and
90 * disaggregation of raw contacts
91 * </li>
92 * <li>
93 * {@link Settings}, which contains visibility and sync settings for accounts
94 * and groups.
95 * </li>
96 * <li>
97 * {@link SyncState}, which contains free-form data maintained on behalf of sync
98 * adapters
99 * </li>
100 * <li>
101 * {@link PhoneLookup}, which is used for quick caller-ID lookup</li>
102 * </ul>
103 */
104@SuppressWarnings("unused")
105public final class ContactsContract {
106    /** The authority for the contacts provider */
107    public static final String AUTHORITY = "com.android.contacts";
108    /** A content:// style uri to the authority for the contacts provider */
109    public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
110
111    /**
112     * An optional URI parameter for insert, update, or delete queries
113     * that allows the caller
114     * to specify that it is a sync adapter. The default value is false. If true
115     * {@link RawContacts#DIRTY} is not automatically set and the
116     * "syncToNetwork" parameter is set to false when calling
117     * {@link
118     * ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)}.
119     * This prevents an unnecessary extra synchronization, see the discussion of
120     * the delete operation in {@link RawContacts}.
121     */
122    public static final String CALLER_IS_SYNCADAPTER = "caller_is_syncadapter";
123
124    /**
125     * A query parameter key used to specify the package that is requesting a query.
126     * This is used for restricting data based on package name.
127     *
128     * @hide
129     */
130    public static final String REQUESTING_PACKAGE_PARAM_KEY = "requesting_package";
131
132    /**
133     * @hide
134     */
135    public static final class Preferences {
136
137        /**
138         * A key in the {@link android.provider.Settings android.provider.Settings} provider
139         * that stores the preferred sorting order for contacts (by given name vs. by family name).
140         *
141         * @hide
142         */
143        public static final String SORT_ORDER = "android.contacts.SORT_ORDER";
144
145        /**
146         * The value for the SORT_ORDER key corresponding to sorting by given name first.
147         *
148         * @hide
149         */
150        public static final int SORT_ORDER_PRIMARY = 1;
151
152        /**
153         * The value for the SORT_ORDER key corresponding to sorting by family name first.
154         *
155         * @hide
156         */
157        public static final int SORT_ORDER_ALTERNATIVE = 2;
158
159        /**
160         * A key in the {@link android.provider.Settings android.provider.Settings} provider
161         * that stores the preferred display order for contacts (given name first vs. family
162         * name first).
163         *
164         * @hide
165         */
166        public static final String DISPLAY_ORDER = "android.contacts.DISPLAY_ORDER";
167
168        /**
169         * The value for the DISPLAY_ORDER key corresponding to showing the given name first.
170         *
171         * @hide
172         */
173        public static final int DISPLAY_ORDER_PRIMARY = 1;
174
175        /**
176         * The value for the DISPLAY_ORDER key corresponding to showing the family name first.
177         *
178         * @hide
179         */
180        public static final int DISPLAY_ORDER_ALTERNATIVE = 2;
181    }
182
183    /**
184     * @hide should be removed when users are updated to refer to SyncState
185     * @deprecated use SyncState instead
186     */
187    @Deprecated
188    public interface SyncStateColumns extends SyncStateContract.Columns {
189    }
190
191    /**
192     * A table provided for sync adapters to use for storing private sync state data.
193     *
194     * @see SyncStateContract
195     */
196    public static final class SyncState implements SyncStateContract.Columns {
197        /**
198         * This utility class cannot be instantiated
199         */
200        private SyncState() {}
201
202        public static final String CONTENT_DIRECTORY =
203                SyncStateContract.Constants.CONTENT_DIRECTORY;
204
205        /**
206         * The content:// style URI for this table
207         */
208        public static final Uri CONTENT_URI =
209                Uri.withAppendedPath(AUTHORITY_URI, CONTENT_DIRECTORY);
210
211        /**
212         * @see android.provider.SyncStateContract.Helpers#get
213         */
214        public static byte[] get(ContentProviderClient provider, Account account)
215                throws RemoteException {
216            return SyncStateContract.Helpers.get(provider, CONTENT_URI, account);
217        }
218
219        /**
220         * @see android.provider.SyncStateContract.Helpers#get
221         */
222        public static Pair<Uri, byte[]> getWithUri(ContentProviderClient provider, Account account)
223                throws RemoteException {
224            return SyncStateContract.Helpers.getWithUri(provider, CONTENT_URI, account);
225        }
226
227        /**
228         * @see android.provider.SyncStateContract.Helpers#set
229         */
230        public static void set(ContentProviderClient provider, Account account, byte[] data)
231                throws RemoteException {
232            SyncStateContract.Helpers.set(provider, CONTENT_URI, account, data);
233        }
234
235        /**
236         * @see android.provider.SyncStateContract.Helpers#newSetOperation
237         */
238        public static ContentProviderOperation newSetOperation(Account account, byte[] data) {
239            return SyncStateContract.Helpers.newSetOperation(CONTENT_URI, account, data);
240        }
241    }
242
243    /**
244     * Generic columns for use by sync adapters. The specific functions of
245     * these columns are private to the sync adapter. Other clients of the API
246     * should not attempt to either read or write this column.
247     *
248     * @see RawContacts
249     * @see Groups
250     */
251    protected interface BaseSyncColumns {
252
253        /** Generic column for use by sync adapters. */
254        public static final String SYNC1 = "sync1";
255        /** Generic column for use by sync adapters. */
256        public static final String SYNC2 = "sync2";
257        /** Generic column for use by sync adapters. */
258        public static final String SYNC3 = "sync3";
259        /** Generic column for use by sync adapters. */
260        public static final String SYNC4 = "sync4";
261    }
262
263    /**
264     * Columns that appear when each row of a table belongs to a specific
265     * account, including sync information that an account may need.
266     *
267     * @see RawContacts
268     * @see Groups
269     */
270    protected interface SyncColumns extends BaseSyncColumns {
271        /**
272         * The name of the account instance to which this row belongs, which when paired with
273         * {@link #ACCOUNT_TYPE} identifies a specific account.
274         * <P>Type: TEXT</P>
275         */
276        public static final String ACCOUNT_NAME = "account_name";
277
278        /**
279         * The type of account to which this row belongs, which when paired with
280         * {@link #ACCOUNT_NAME} identifies a specific account.
281         * <P>Type: TEXT</P>
282         */
283        public static final String ACCOUNT_TYPE = "account_type";
284
285        /**
286         * String that uniquely identifies this row to its source account.
287         * <P>Type: TEXT</P>
288         */
289        public static final String SOURCE_ID = "sourceid";
290
291        /**
292         * Version number that is updated whenever this row or its related data
293         * changes.
294         * <P>Type: INTEGER</P>
295         */
296        public static final String VERSION = "version";
297
298        /**
299         * Flag indicating that {@link #VERSION} has changed, and this row needs
300         * to be synchronized by its owning account.
301         * <P>Type: INTEGER (boolean)</P>
302         */
303        public static final String DIRTY = "dirty";
304    }
305
306    /**
307     * Columns of {@link ContactsContract.Contacts} that track the user's
308     * preferences for, or interactions with, the contact.
309     *
310     * @see Contacts
311     * @see RawContacts
312     * @see ContactsContract.Data
313     * @see PhoneLookup
314     * @see ContactsContract.Contacts.AggregationSuggestions
315     */
316    protected interface ContactOptionsColumns {
317        /**
318         * The number of times a contact has been contacted
319         * <P>Type: INTEGER</P>
320         */
321        public static final String TIMES_CONTACTED = "times_contacted";
322
323        /**
324         * The last time a contact was contacted.
325         * <P>Type: INTEGER</P>
326         */
327        public static final String LAST_TIME_CONTACTED = "last_time_contacted";
328
329        /**
330         * Is the contact starred?
331         * <P>Type: INTEGER (boolean)</P>
332         */
333        public static final String STARRED = "starred";
334
335        /**
336         * URI for a custom ringtone associated with the contact. If null or missing,
337         * the default ringtone is used.
338         * <P>Type: TEXT (URI to the ringtone)</P>
339         */
340        public static final String CUSTOM_RINGTONE = "custom_ringtone";
341
342        /**
343         * Whether the contact should always be sent to voicemail. If missing,
344         * defaults to false.
345         * <P>Type: INTEGER (0 for false, 1 for true)</P>
346         */
347        public static final String SEND_TO_VOICEMAIL = "send_to_voicemail";
348    }
349
350    /**
351     * Columns of {@link ContactsContract.Contacts} that refer to intrinsic
352     * properties of the contact, as opposed to the user-specified options
353     * found in {@link ContactOptionsColumns}.
354     *
355     * @see Contacts
356     * @see ContactsContract.Data
357     * @see PhoneLookup
358     * @see ContactsContract.Contacts.AggregationSuggestions
359     */
360    protected interface ContactsColumns {
361        /**
362         * The display name for the contact.
363         * <P>Type: TEXT</P>
364         */
365        public static final String DISPLAY_NAME = ContactNameColumns.DISPLAY_NAME_PRIMARY;
366
367        /**
368         * Reference to the row in the RawContacts table holding the contact name.
369         * <P>Type: INTEGER REFERENCES raw_contacts(_id)</P>
370         * @hide
371         */
372        public static final String NAME_RAW_CONTACT_ID = "name_raw_contact_id";
373
374        /**
375         * Reference to the row in the data table holding the photo.
376         * <P>Type: INTEGER REFERENCES data(_id)</P>
377         */
378        public static final String PHOTO_ID = "photo_id";
379
380        /**
381         * Lookup value that reflects the {@link Groups#GROUP_VISIBLE} state of
382         * any {@link CommonDataKinds.GroupMembership} for this contact.
383         */
384        public static final String IN_VISIBLE_GROUP = "in_visible_group";
385
386        /**
387         * An indicator of whether this contact has at least one phone number. "1" if there is
388         * at least one phone number, "0" otherwise.
389         * <P>Type: INTEGER</P>
390         */
391        public static final String HAS_PHONE_NUMBER = "has_phone_number";
392
393        /**
394         * An opaque value that contains hints on how to find the contact if
395         * its row id changed as a result of a sync or aggregation.
396         */
397        public static final String LOOKUP_KEY = "lookup";
398    }
399
400    /**
401     * @see Contacts
402     */
403    protected interface ContactStatusColumns {
404        /**
405         * Contact presence status. See {@link StatusUpdates} for individual status
406         * definitions.
407         * <p>Type: NUMBER</p>
408         */
409        public static final String CONTACT_PRESENCE = "contact_presence";
410
411        /**
412         * Contact Chat Capabilities. See {@link StatusUpdates} for individual
413         * definitions.
414         * <p>Type: NUMBER</p>
415         */
416        public static final String CONTACT_CHAT_CAPABILITY = "contact_chat_capability";
417
418        /**
419         * Contact's latest status update.
420         * <p>Type: TEXT</p>
421         */
422        public static final String CONTACT_STATUS = "contact_status";
423
424        /**
425         * The absolute time in milliseconds when the latest status was
426         * inserted/updated.
427         * <p>Type: NUMBER</p>
428         */
429        public static final String CONTACT_STATUS_TIMESTAMP = "contact_status_ts";
430
431        /**
432         * The package containing resources for this status: label and icon.
433         * <p>Type: TEXT</p>
434         */
435        public static final String CONTACT_STATUS_RES_PACKAGE = "contact_status_res_package";
436
437        /**
438         * The resource ID of the label describing the source of contact
439         * status, e.g. "Google Talk". This resource is scoped by the
440         * {@link #CONTACT_STATUS_RES_PACKAGE}.
441         * <p>Type: NUMBER</p>
442         */
443        public static final String CONTACT_STATUS_LABEL = "contact_status_label";
444
445        /**
446         * The resource ID of the icon for the source of contact status. This
447         * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}.
448         * <p>Type: NUMBER</p>
449         */
450        public static final String CONTACT_STATUS_ICON = "contact_status_icon";
451    }
452
453    /**
454     * Constants for various styles of combining given name, family name etc into
455     * a full name.  For example, the western tradition follows the pattern
456     * 'given name' 'middle name' 'family name' with the alternative pattern being
457     * 'family name', 'given name' 'middle name'.  The CJK tradition is
458     * 'family name' 'middle name' 'given name', with Japanese favoring a space between
459     * the names and Chinese omitting the space.
460     * @hide
461     */
462    public interface FullNameStyle {
463        public static final int UNDEFINED = 0;
464        public static final int WESTERN = 1;
465
466        /**
467         * Used if the name is written in Hanzi/Kanji/Hanja and we could not determine
468         * which specific language it belongs to: Chinese, Japanese or Korean.
469         */
470        public static final int CJK = 2;
471
472        public static final int CHINESE = 3;
473        public static final int JAPANESE = 4;
474        public static final int KOREAN = 5;
475    }
476
477    /**
478     * Constants for various styles of capturing the pronunciation of a person's name.
479     * @hide
480     */
481    public interface PhoneticNameStyle {
482        public static final int UNDEFINED = 0;
483
484        /**
485         * Pinyin is a phonetic method of entering Chinese characters. Typically not explicitly
486         * shown in UIs, but used for searches and sorting.
487         */
488        public static final int PINYIN = 3;
489
490        /**
491         * Hiragana and Katakana are two common styles of writing out the pronunciation
492         * of a Japanese names.
493         */
494        public static final int JAPANESE = 4;
495
496        /**
497         * Hangul is the Korean phonetic alphabet.
498         */
499        public static final int KOREAN = 5;
500    }
501
502    /**
503     * Types of data used to produce the display name for a contact. Listed in the order
504     * of increasing priority.
505     *
506     * @hide
507     */
508    public interface DisplayNameSources {
509        public static final int UNDEFINED = 0;
510        public static final int EMAIL = 10;
511        public static final int PHONE = 20;
512        public static final int ORGANIZATION = 30;
513        public static final int NICKNAME = 35;
514        public static final int STRUCTURED_NAME = 40;
515    }
516
517    /**
518     * Contact name and contact name metadata columns in the RawContacts table.
519     *
520     * @see Contacts
521     * @see RawContacts
522     * @hide
523     */
524    protected interface ContactNameColumns {
525
526        /**
527         * The kind of data that is used as the display name for the contact, such as
528         * structured name or email address.  See DisplayNameSources.
529         *
530         * TODO: convert DisplayNameSources to a link after it is un-hidden
531         */
532        public static final String DISPLAY_NAME_SOURCE = "display_name_source";
533
534        /**
535         * <p>
536         * The standard text shown as the contact's display name, based on the best
537         * available information for the contact (for example, it might be the email address
538         * if the name is not available).
539         * The information actually used to compute the name is stored in
540         * {@link #DISPLAY_NAME_SOURCE}.
541         * </p>
542         * <p>
543         * A contacts provider is free to choose whatever representation makes most
544         * sense for its target market.
545         * For example in the default Android Open Source Project implementation,
546         * if the display name is
547         * based on the structured name and the structured name follows
548         * the Western full-name style, then this field contains the "given name first"
549         * version of the full name.
550         * <p>
551         *
552         * @see ContactsContract.ContactNameColumns#DISPLAY_NAME_ALTERNATIVE
553         */
554        public static final String DISPLAY_NAME_PRIMARY = "display_name";
555
556        /**
557         * <p>
558         * An alternative representation of the display name, such as "family name first"
559         * instead of "given name first" for Western names.  If an alternative is not
560         * available, the values should be the same as {@link #DISPLAY_NAME_PRIMARY}.
561         * </p>
562         * <p>
563         * A contacts provider is free to provide alternatives as necessary for
564         * its target market.
565         * For example the default Android Open Source Project contacts provider
566         * currently provides an
567         * alternative in a single case:  if the display name is
568         * based on the structured name and the structured name follows
569         * the Western full name style, then the field contains the "family name first"
570         * version of the full name.
571         * Other cases may be added later.
572         * </p>
573         */
574        public static final String DISPLAY_NAME_ALTERNATIVE = "display_name_alt";
575
576        /**
577         * The phonetic alphabet used to represent the {@link #PHONETIC_NAME}.  See
578         * PhoneticNameStyle.
579         *
580         * TODO: convert PhoneticNameStyle to a link after it is un-hidden
581         */
582        public static final String PHONETIC_NAME_STYLE = "phonetic_name_style";
583
584        /**
585         * <p>
586         * Pronunciation of the full name in the phonetic alphabet specified by
587         * {@link #PHONETIC_NAME_STYLE}.
588         * </p>
589         * <p>
590         * The value may be set manually by the user.
591         * This capability is is of interest only in countries
592         * with commonly used phonetic
593         * alphabets, such as Japan and Korea.  See PhoneticNameStyle.
594         * </p>
595         *
596         * TODO: convert PhoneticNameStyle to a link after it is un-hidden
597         */
598        public static final String PHONETIC_NAME = "phonetic_name";
599
600        /**
601         * Sort key that takes into account locale-based traditions for sorting
602         * names in address books.  The default
603         * sort key is {@link #DISPLAY_NAME_PRIMARY}.  For Chinese names
604         * the sort key is the name's Pinyin spelling, and for Japanese names
605         * it is the Hiragana version of the phonetic name.
606         */
607        public static final String SORT_KEY_PRIMARY = "sort_key";
608
609        /**
610         * Sort key based on the alternative representation of the full name,
611         * {@link #DISPLAY_NAME_ALTERNATIVE}.  Thus for Western names,
612         * it is the one using the "family name first" format.
613         */
614        public static final String SORT_KEY_ALTERNATIVE = "sort_key_alt";
615    }
616
617    /**
618     * URI parameter and cursor extras that return counts of rows grouped by the
619     * address book index, which is usually the first letter of the sort key.
620     * When this parameter is supplied, the row counts are returned in the
621     * cursor extras bundle.
622     *
623     * @hide
624     */
625    public final static class ContactCounts {
626
627        /**
628         * Add this query parameter to a URI to get back row counts grouped by
629         * the address book index as cursor extras. For most languages it is the
630         * first letter of the sort key. This parameter does not affect the main
631         * content of the cursor.
632         *
633         * @hide
634         */
635        public static final String ADDRESS_BOOK_INDEX_EXTRAS = "address_book_index_extras";
636
637        /**
638         * The array of address book index titles, which are returned in the
639         * same order as the data in the cursor.
640         * <p>TYPE: String[]</p>
641         *
642         * @hide
643         */
644        public static final String EXTRA_ADDRESS_BOOK_INDEX_TITLES = "address_book_index_titles";
645
646        /**
647         * The array of group counts for the corresponding group.  Contains the same number
648         * of elements as the EXTRA_ADDRESS_BOOK_INDEX_TITLES array.
649         * <p>TYPE: int[]</p>
650         *
651         * @hide
652         */
653        public static final String EXTRA_ADDRESS_BOOK_INDEX_COUNTS = "address_book_index_counts";
654    }
655
656    /**
657     * Constants for the contacts table, which contains a record per aggregate
658     * of raw contacts representing the same person.
659     * <h3>Operations</h3>
660     * <dl>
661     * <dt><b>Insert</b></dt>
662     * <dd>A Contact cannot be created explicitly. When a raw contact is
663     * inserted, the provider will first try to find a Contact representing the
664     * same person. If one is found, the raw contact's
665     * {@link RawContacts#CONTACT_ID} column gets the _ID of the aggregate
666     * Contact. If no match is found, the provider automatically inserts a new
667     * Contact and puts its _ID into the {@link RawContacts#CONTACT_ID} column
668     * of the newly inserted raw contact.</dd>
669     * <dt><b>Update</b></dt>
670     * <dd>Only certain columns of Contact are modifiable:
671     * {@link #TIMES_CONTACTED}, {@link #LAST_TIME_CONTACTED}, {@link #STARRED},
672     * {@link #CUSTOM_RINGTONE}, {@link #SEND_TO_VOICEMAIL}. Changing any of
673     * these columns on the Contact also changes them on all constituent raw
674     * contacts.</dd>
675     * <dt><b>Delete</b></dt>
676     * <dd>Be careful with deleting Contacts! Deleting an aggregate contact
677     * deletes all constituent raw contacts. The corresponding sync adapters
678     * will notice the deletions of their respective raw contacts and remove
679     * them from their back end storage.</dd>
680     * <dt><b>Query</b></dt>
681     * <dd>
682     * <ul>
683     * <li>If you need to read an individual contact, consider using
684     * {@link #CONTENT_LOOKUP_URI} instead of {@link #CONTENT_URI}.</li>
685     * <li>If you need to look up a contact by the phone number, use
686     * {@link PhoneLookup#CONTENT_FILTER_URI PhoneLookup.CONTENT_FILTER_URI},
687     * which is optimized for this purpose.</li>
688     * <li>If you need to look up a contact by partial name, e.g. to produce
689     * filter-as-you-type suggestions, use the {@link #CONTENT_FILTER_URI} URI.
690     * <li>If you need to look up a contact by some data element like email
691     * address, nickname, etc, use a query against the {@link ContactsContract.Data} table.
692     * The result will contain contact ID, name etc.
693     * </ul>
694     * </dd>
695     * </dl>
696     * <h2>Columns</h2>
697     * <table class="jd-sumtable">
698     * <tr>
699     * <th colspan='4'>Contacts</th>
700     * </tr>
701     * <tr>
702     * <td>long</td>
703     * <td>{@link #_ID}</td>
704     * <td>read-only</td>
705     * <td>Row ID. Consider using {@link #LOOKUP_KEY} instead.</td>
706     * </tr>
707     * <tr>
708     * <td>String</td>
709     * <td>{@link #LOOKUP_KEY}</td>
710     * <td>read-only</td>
711     * <td>An opaque value that contains hints on how to find the contact if its
712     * row id changed as a result of a sync or aggregation.</td>
713     * </tr>
714     * <tr>
715     * <td>long</td>
716     * <td>NAME_RAW_CONTACT_ID</td>
717     * <td>read-only</td>
718     * <td>The ID of the raw contact that contributes the display name
719     * to the aggregate contact. During aggregation one of the constituent
720     * raw contacts is chosen using a heuristic: a longer name or a name
721     * with more diacritic marks or more upper case characters is chosen.</td>
722     * </tr>
723     * <tr>
724     * <td>String</td>
725     * <td>DISPLAY_NAME_PRIMARY</td>
726     * <td>read-only</td>
727     * <td>The display name for the contact. It is the display name
728     * contributed by the raw contact referred to by the NAME_RAW_CONTACT_ID
729     * column.</td>
730     * </tr>
731     * <tr>
732     * <td>long</td>
733     * <td>{@link #PHOTO_ID}</td>
734     * <td>read-only</td>
735     * <td>Reference to the row in the {@link ContactsContract.Data} table holding the photo.
736     * That row has the mime type
737     * {@link CommonDataKinds.Photo#CONTENT_ITEM_TYPE}. The value of this field
738     * is computed automatically based on the
739     * {@link CommonDataKinds.Photo#IS_SUPER_PRIMARY} field of the data rows of
740     * that mime type.</td>
741     * </tr>
742     * <tr>
743     * <td>int</td>
744     * <td>{@link #IN_VISIBLE_GROUP}</td>
745     * <td>read-only</td>
746     * <td>An indicator of whether this contact is supposed to be visible in the
747     * UI. "1" if the contact has at least one raw contact that belongs to a
748     * visible group; "0" otherwise.</td>
749     * </tr>
750     * <tr>
751     * <td>int</td>
752     * <td>{@link #HAS_PHONE_NUMBER}</td>
753     * <td>read-only</td>
754     * <td>An indicator of whether this contact has at least one phone number.
755     * "1" if there is at least one phone number, "0" otherwise.</td>
756     * </tr>
757     * <tr>
758     * <td>int</td>
759     * <td>{@link #TIMES_CONTACTED}</td>
760     * <td>read/write</td>
761     * <td>The number of times the contact has been contacted. See
762     * {@link #markAsContacted}. When raw contacts are aggregated, this field is
763     * computed automatically as the maximum number of times contacted among all
764     * constituent raw contacts. Setting this field automatically changes the
765     * corresponding field on all constituent raw contacts.</td>
766     * </tr>
767     * <tr>
768     * <td>long</td>
769     * <td>{@link #LAST_TIME_CONTACTED}</td>
770     * <td>read/write</td>
771     * <td>The timestamp of the last time the contact was contacted. See
772     * {@link #markAsContacted}. Setting this field also automatically
773     * increments {@link #TIMES_CONTACTED}. When raw contacts are aggregated,
774     * this field is computed automatically as the latest time contacted of all
775     * constituent raw contacts. Setting this field automatically changes the
776     * corresponding field on all constituent raw contacts.</td>
777     * </tr>
778     * <tr>
779     * <td>int</td>
780     * <td>{@link #STARRED}</td>
781     * <td>read/write</td>
782     * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise.
783     * When raw contacts are aggregated, this field is automatically computed:
784     * if any constituent raw contacts are starred, then this field is set to
785     * '1'. Setting this field automatically changes the corresponding field on
786     * all constituent raw contacts.</td>
787     * </tr>
788     * <tr>
789     * <td>String</td>
790     * <td>{@link #CUSTOM_RINGTONE}</td>
791     * <td>read/write</td>
792     * <td>A custom ringtone associated with a contact. Typically this is the
793     * URI returned by an activity launched with the
794     * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.</td>
795     * </tr>
796     * <tr>
797     * <td>int</td>
798     * <td>{@link #SEND_TO_VOICEMAIL}</td>
799     * <td>read/write</td>
800     * <td>An indicator of whether calls from this contact should be forwarded
801     * directly to voice mail ('1') or not ('0'). When raw contacts are
802     * aggregated, this field is automatically computed: if <i>all</i>
803     * constituent raw contacts have SEND_TO_VOICEMAIL=1, then this field is set
804     * to '1'. Setting this field automatically changes the corresponding field
805     * on all constituent raw contacts.</td>
806     * </tr>
807     * <tr>
808     * <td>int</td>
809     * <td>{@link #CONTACT_PRESENCE}</td>
810     * <td>read-only</td>
811     * <td>Contact IM presence status. See {@link StatusUpdates} for individual
812     * status definitions. Automatically computed as the highest presence of all
813     * constituent raw contacts. The provider may choose not to store this value
814     * in persistent storage. The expectation is that presence status will be
815     * updated on a regular basic.</td>
816     * </tr>
817     * <tr>
818     * <td>String</td>
819     * <td>{@link #CONTACT_STATUS}</td>
820     * <td>read-only</td>
821     * <td>Contact's latest status update. Automatically computed as the latest
822     * of all constituent raw contacts' status updates.</td>
823     * </tr>
824     * <tr>
825     * <td>long</td>
826     * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td>
827     * <td>read-only</td>
828     * <td>The absolute time in milliseconds when the latest status was
829     * inserted/updated.</td>
830     * </tr>
831     * <tr>
832     * <td>String</td>
833     * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td>
834     * <td>read-only</td>
835     * <td> The package containing resources for this status: label and icon.</td>
836     * </tr>
837     * <tr>
838     * <td>long</td>
839     * <td>{@link #CONTACT_STATUS_LABEL}</td>
840     * <td>read-only</td>
841     * <td>The resource ID of the label describing the source of contact status,
842     * e.g. "Google Talk". This resource is scoped by the
843     * {@link #CONTACT_STATUS_RES_PACKAGE}.</td>
844     * </tr>
845     * <tr>
846     * <td>long</td>
847     * <td>{@link #CONTACT_STATUS_ICON}</td>
848     * <td>read-only</td>
849     * <td>The resource ID of the icon for the source of contact status. This
850     * resource is scoped by the {@link #CONTACT_STATUS_RES_PACKAGE}.</td>
851     * </tr>
852     * </table>
853     */
854    public static class Contacts implements BaseColumns, ContactsColumns,
855            ContactOptionsColumns, ContactNameColumns, ContactStatusColumns {
856        /**
857         * This utility class cannot be instantiated
858         */
859        private Contacts()  {}
860
861        /**
862         * The content:// style URI for this table
863         */
864        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "contacts");
865
866        /**
867         * A content:// style URI for this table that should be used to create
868         * shortcuts or otherwise create long-term links to contacts. This URI
869         * should always be followed by a "/" and the contact's {@link #LOOKUP_KEY}.
870         * It can optionally also have a "/" and last known contact ID appended after
871         * that. This "complete" format is an important optimization and is highly recommended.
872         * <p>
873         * As long as the contact's row ID remains the same, this URI is
874         * equivalent to {@link #CONTENT_URI}. If the contact's row ID changes
875         * as a result of a sync or aggregation, this URI will look up the
876         * contact using indirect information (sync IDs or constituent raw
877         * contacts).
878         * <p>
879         * Lookup key should be appended unencoded - it is stored in the encoded
880         * form, ready for use in a URI.
881         */
882        public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
883                "lookup");
884
885        /**
886         * Base {@link Uri} for referencing a single {@link Contacts} entry,
887         * created by appending {@link #LOOKUP_KEY} using
888         * {@link Uri#withAppendedPath(Uri, String)}. Provides
889         * {@link OpenableColumns} columns when queried, or returns the
890         * referenced contact formatted as a vCard when opened through
891         * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}.
892         */
893        public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
894                "as_vcard");
895
896        /**
897         * Base {@link Uri} for referencing multiple {@link Contacts} entry,
898         * created by appending {@link #LOOKUP_KEY} using
899         * {@link Uri#withAppendedPath(Uri, String)}. The lookup keys have to be
900         * encoded and joined with the colon (":") seperator. The resulting string
901         * has to be encoded again. Provides
902         * {@link OpenableColumns} columns when queried, or returns the
903         * referenced contact formatted as a vCard when opened through
904         * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}.
905         *
906         * This is private API because we do not have a well-defined way to
907         * specify several entities yet. The format of this Uri might change in the future
908         * or the Uri might be completely removed.
909         *
910         * @hide
911         */
912        public static final Uri CONTENT_MULTI_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
913                "as_multi_vcard");
914
915        /**
916         * Builds a {@link #CONTENT_LOOKUP_URI} style {@link Uri} describing the
917         * requested {@link Contacts} entry.
918         *
919         * @param contactUri A {@link #CONTENT_URI} row, or an existing
920         *            {@link #CONTENT_LOOKUP_URI} to attempt refreshing.
921         */
922        public static Uri getLookupUri(ContentResolver resolver, Uri contactUri) {
923            final Cursor c = resolver.query(contactUri, new String[] {
924                    Contacts.LOOKUP_KEY, Contacts._ID
925            }, null, null, null);
926            if (c == null) {
927                return null;
928            }
929
930            try {
931                if (c.moveToFirst()) {
932                    final String lookupKey = c.getString(0);
933                    final long contactId = c.getLong(1);
934                    return getLookupUri(contactId, lookupKey);
935                }
936            } finally {
937                c.close();
938            }
939            return null;
940        }
941
942        /**
943         * Build a {@link #CONTENT_LOOKUP_URI} lookup {@link Uri} using the
944         * given {@link ContactsContract.Contacts#_ID} and {@link #LOOKUP_KEY}.
945         */
946        public static Uri getLookupUri(long contactId, String lookupKey) {
947            return ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI,
948                    lookupKey), contactId);
949        }
950
951        /**
952         * Computes a content URI (see {@link #CONTENT_URI}) given a lookup URI.
953         * <p>
954         * Returns null if the contact cannot be found.
955         */
956        public static Uri lookupContact(ContentResolver resolver, Uri lookupUri) {
957            if (lookupUri == null) {
958                return null;
959            }
960
961            Cursor c = resolver.query(lookupUri, new String[]{Contacts._ID}, null, null, null);
962            if (c == null) {
963                return null;
964            }
965
966            try {
967                if (c.moveToFirst()) {
968                    long contactId = c.getLong(0);
969                    return ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
970                }
971            } finally {
972                c.close();
973            }
974            return null;
975        }
976
977        /**
978         * Mark a contact as having been contacted.  This updates the
979         * {@link #TIMES_CONTACTED} and {@link #LAST_TIME_CONTACTED} for the
980         * contact, plus the corresponding values of any associated raw
981         * contacts.
982         *
983         * @param resolver the ContentResolver to use
984         * @param contactId the person who was contacted
985         */
986        public static void markAsContacted(ContentResolver resolver, long contactId) {
987            Uri uri = ContentUris.withAppendedId(CONTENT_URI, contactId);
988            ContentValues values = new ContentValues();
989            // TIMES_CONTACTED will be incremented when LAST_TIME_CONTACTED is modified.
990            values.put(LAST_TIME_CONTACTED, System.currentTimeMillis());
991            resolver.update(uri, values, null, null);
992        }
993
994        /**
995         * The content:// style URI used for "type-to-filter" functionality on the
996         * {@link #CONTENT_URI} URI. The filter string will be used to match
997         * various parts of the contact name. The filter argument should be passed
998         * as an additional path segment after this URI.
999         */
1000        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(
1001                CONTENT_URI, "filter");
1002
1003        /**
1004         * The content:// style URI for this table joined with useful data from
1005         * {@link ContactsContract.Data}, filtered to include only starred contacts
1006         * and the most frequently contacted contacts.
1007         */
1008        public static final Uri CONTENT_STREQUENT_URI = Uri.withAppendedPath(
1009                CONTENT_URI, "strequent");
1010
1011        /**
1012         * The content:// style URI used for "type-to-filter" functionality on the
1013         * {@link #CONTENT_STREQUENT_URI} URI. The filter string will be used to match
1014         * various parts of the contact name. The filter argument should be passed
1015         * as an additional path segment after this URI.
1016         */
1017        public static final Uri CONTENT_STREQUENT_FILTER_URI = Uri.withAppendedPath(
1018                CONTENT_STREQUENT_URI, "filter");
1019
1020        public static final Uri CONTENT_GROUP_URI = Uri.withAppendedPath(
1021                CONTENT_URI, "group");
1022
1023        /**
1024         * The MIME type of {@link #CONTENT_URI} providing a directory of
1025         * people.
1026         */
1027        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact";
1028
1029        /**
1030         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
1031         * person.
1032         */
1033        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact";
1034
1035        /**
1036         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
1037         * person.
1038         */
1039        public static final String CONTENT_VCARD_TYPE = "text/x-vcard";
1040
1041        /**
1042         * A sub-directory of a single contact that contains all of the constituent raw contact
1043         * {@link ContactsContract.Data} rows.
1044         */
1045        public static final class Data implements BaseColumns, DataColumns {
1046            /**
1047             * no public constructor since this is a utility class
1048             */
1049            private Data() {}
1050
1051            /**
1052             * The directory twig for this sub-table
1053             */
1054            public static final String CONTENT_DIRECTORY = "data";
1055        }
1056
1057        /**
1058         * <p>
1059         * A <i>read-only</i> sub-directory of a single contact aggregate that
1060         * contains all aggregation suggestions (other contacts). The
1061         * aggregation suggestions are computed based on approximate data
1062         * matches with this contact.
1063         * </p>
1064         * <p>
1065         * <i>Note: this query may be expensive! If you need to use it in bulk,
1066         * make sure the user experience is acceptable when the query runs for a
1067         * long time.</i>
1068         * <p>
1069         * Usage example:
1070         *
1071         * <pre>
1072         * Uri uri = Contacts.CONTENT_URI.buildUpon()
1073         *          .appendEncodedPath(String.valueOf(contactId))
1074         *          .appendPath(Contacts.AggregationSuggestions.CONTENT_DIRECTORY)
1075         *          .appendQueryParameter(&quot;limit&quot;, &quot;3&quot;)
1076         *          .build()
1077         * Cursor cursor = getContentResolver().query(suggestionsUri,
1078         *          new String[] {Contacts.DISPLAY_NAME, Contacts._ID, Contacts.LOOKUP_KEY},
1079         *          null, null, null);
1080         * </pre>
1081         *
1082         * </p>
1083         */
1084        // TODO: add ContactOptionsColumns, ContactStatusColumns
1085        public static final class AggregationSuggestions implements BaseColumns, ContactsColumns {
1086            /**
1087             * No public constructor since this is a utility class
1088             */
1089            private AggregationSuggestions() {}
1090
1091            /**
1092             * The directory twig for this sub-table. The URI can be followed by an optional
1093             * type-to-filter, similar to
1094             * {@link android.provider.ContactsContract.Contacts#CONTENT_FILTER_URI}.
1095             */
1096            public static final String CONTENT_DIRECTORY = "suggestions";
1097        }
1098
1099        /**
1100         * A <i>read-only</i> sub-directory of a single contact that contains
1101         * the contact's primary photo.
1102         * <p>
1103         * Usage example:
1104         *
1105         * <pre>
1106         * public InputStream openPhoto(long contactId) {
1107         *     Uri contactUri = ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId);
1108         *     Uri photoUri = Uri.withAppendedPath(contactUri, Contacts.Photo.CONTENT_DIRECTORY);
1109         *     Cursor cursor = getContentResolver().query(photoUri,
1110         *          new String[] {Contacts.Photo.PHOTO}, null, null, null);
1111         *     if (cursor == null) {
1112         *         return null;
1113         *     }
1114         *     try {
1115         *         if (cursor.moveToFirst()) {
1116         *             byte[] data = cursor.getBlob(0);
1117         *             if (data != null) {
1118         *                 return new ByteArrayInputStream(data);
1119         *             }
1120         *         }
1121         *     } finally {
1122         *         cursor.close();
1123         *     }
1124         *     return null;
1125         * }
1126         * </pre>
1127         *
1128         * </p>
1129         * <p>You should also consider using the convenience method
1130         * {@link ContactsContract.Contacts#openContactPhotoInputStream(ContentResolver, Uri)}
1131         * </p>
1132         */
1133        // TODO: change DataColumns to DataColumnsWithJoins
1134        public static final class Photo implements BaseColumns, DataColumns {
1135            /**
1136             * no public constructor since this is a utility class
1137             */
1138            private Photo() {}
1139
1140            /**
1141             * The directory twig for this sub-table
1142             */
1143            public static final String CONTENT_DIRECTORY = "photo";
1144
1145            /**
1146             * Thumbnail photo of the raw contact. This is the raw bytes of an image
1147             * that could be inflated using {@link android.graphics.BitmapFactory}.
1148             * <p>
1149             * Type: BLOB
1150             * @hide TODO: Unhide in a separate CL
1151             */
1152            public static final String PHOTO = DATA15;
1153        }
1154
1155        /**
1156         * Opens an InputStream for the contacts's default photo and returns the
1157         * photo as a byte stream. If there is not photo null will be returned.
1158         *
1159         * @param contactUri the contact whose photo should be used
1160         * @return an InputStream of the photo, or null if no photo is present
1161         */
1162        public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) {
1163            Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY);
1164            if (photoUri == null) {
1165                return null;
1166            }
1167            Cursor cursor = cr.query(photoUri,
1168                    new String[]{ContactsContract.CommonDataKinds.Photo.PHOTO}, null, null, null);
1169            try {
1170                if (cursor == null || !cursor.moveToNext()) {
1171                    return null;
1172                }
1173                byte[] data = cursor.getBlob(0);
1174                if (data == null) {
1175                    return null;
1176                }
1177                return new ByteArrayInputStream(data);
1178            } finally {
1179                if (cursor != null) {
1180                    cursor.close();
1181                }
1182            }
1183        }
1184    }
1185
1186    protected interface RawContactsColumns {
1187        /**
1188         * A reference to the {@link ContactsContract.Contacts#_ID} that this
1189         * data belongs to.
1190         * <P>Type: INTEGER</P>
1191         */
1192        public static final String CONTACT_ID = "contact_id";
1193
1194        /**
1195         * Flag indicating that this {@link RawContacts} entry and its children have
1196         * been restricted to specific platform apps.
1197         * <P>Type: INTEGER (boolean)</P>
1198         *
1199         * @hide until finalized in future platform release
1200         */
1201        public static final String IS_RESTRICTED = "is_restricted";
1202
1203        /**
1204         * The aggregation mode for this contact.
1205         * <P>Type: INTEGER</P>
1206         */
1207        public static final String AGGREGATION_MODE = "aggregation_mode";
1208
1209        /**
1210         * The "deleted" flag: "0" by default, "1" if the row has been marked
1211         * for deletion. When {@link android.content.ContentResolver#delete} is
1212         * called on a raw contact, it is marked for deletion and removed from its
1213         * aggregate contact. The sync adaptor deletes the raw contact on the server and
1214         * then calls ContactResolver.delete once more, this time passing the
1215         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
1216         * the data removal.
1217         * <P>Type: INTEGER</P>
1218         */
1219        public static final String DELETED = "deleted";
1220
1221        /**
1222         * The "name_verified" flag: "1" means that the name fields on this raw
1223         * contact can be trusted and therefore should be used for the entire
1224         * aggregated contact.
1225         * <p>
1226         * If an aggregated contact contains more than one raw contact with a
1227         * verified name, one of those verified names is chosen at random.
1228         * If an aggregated contact contains no verified names, the
1229         * name is chosen randomly from the constituent raw contacts.
1230         * </p>
1231         * <p>
1232         * Updating this flag from "0" to "1" automatically resets it to "0" on
1233         * all other raw contacts in the same aggregated contact.
1234         * </p>
1235         * <p>
1236         * Sync adapters should only specify a value for this column when
1237         * inserting a raw contact and leave it out when doing an update.
1238         * </p>
1239         * <p>
1240         * The default value is "0"
1241         * </p>
1242         * <p>Type: INTEGER</p>
1243         *
1244         * @hide
1245         */
1246        public static final String NAME_VERIFIED = "name_verified";
1247    }
1248
1249    /**
1250     * Constants for the raw contacts table, which contains one row of contact
1251     * information for each person in each synced account. Sync adapters and
1252     * contact management apps
1253     * are the primary consumers of this API.
1254     *
1255     * <h3>Aggregation</h3>
1256     * <p>
1257     * As soon as a raw contact is inserted or whenever its constituent data
1258     * changes, the provider will check if the raw contact matches other
1259     * existing raw contacts and if so will aggregate it with those. The
1260     * aggregation is reflected in the {@link RawContacts} table by the change of the
1261     * {@link #CONTACT_ID} field, which is the reference to the aggregate contact.
1262     * </p>
1263     * <p>
1264     * Changes to the structured name, organization, phone number, email address,
1265     * or nickname trigger a re-aggregation.
1266     * </p>
1267     * <p>
1268     * See also {@link AggregationExceptions} for a mechanism to control
1269     * aggregation programmatically.
1270     * </p>
1271     *
1272     * <h3>Operations</h3>
1273     * <dl>
1274     * <dt><b>Insert</b></dt>
1275     * <dd>
1276     * <p>
1277     * Raw contacts can be inserted incrementally or in a batch.
1278     * The incremental method is more traditional but less efficient.
1279     * It should be used
1280     * only if no {@link Data} values are available at the time the raw contact is created:
1281     * <pre>
1282     * ContentValues values = new ContentValues();
1283     * values.put(RawContacts.ACCOUNT_TYPE, accountType);
1284     * values.put(RawContacts.ACCOUNT_NAME, accountName);
1285     * Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
1286     * long rawContactId = ContentUris.parseId(rawContactUri);
1287     * </pre>
1288     * </p>
1289     * <p>
1290     * Once {@link Data} values become available, insert those.
1291     * For example, here's how you would insert a name:
1292     *
1293     * <pre>
1294     * values.clear();
1295     * values.put(Data.RAW_CONTACT_ID, rawContactId);
1296     * values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
1297     * values.put(StructuredName.DISPLAY_NAME, &quot;Mike Sullivan&quot;);
1298     * getContentResolver().insert(Data.CONTENT_URI, values);
1299     * </pre>
1300     * </p>
1301     * <p>
1302     * The batch method is by far preferred.  It inserts the raw contact and its
1303     * constituent data rows in a single database transaction
1304     * and causes at most one aggregation pass.
1305     * <pre>
1306     * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
1307     * ...
1308     * int rawContactInsertIndex = ops.size();
1309     * ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
1310     *          .withValue(RawContacts.ACCOUNT_TYPE, accountType)
1311     *          .withValue(RawContacts.ACCOUNT_NAME, accountName)
1312     *          .build());
1313     *
1314     * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
1315     *          .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
1316     *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
1317     *          .withValue(StructuredName.DISPLAY_NAME, &quot;Mike Sullivan&quot;)
1318     *          .build());
1319     *
1320     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
1321     * </pre>
1322     * </p>
1323     * <p>
1324     * Note the use of {@link ContentProviderOperation.Builder#withValueBackReference(String, int)}
1325     * to refer to the as-yet-unknown index value of the raw contact inserted in the
1326     * first operation.
1327     * </p>
1328     *
1329     * <dt><b>Update</b></dt>
1330     * <dd><p>
1331     * Raw contacts can be updated incrementally or in a batch.
1332     * Batch mode should be used whenever possible.
1333     * The procedures and considerations are analogous to those documented above for inserts.
1334     * </p></dd>
1335     * <dt><b>Delete</b></dt>
1336     * <dd><p>When a raw contact is deleted, all of its Data rows as well as StatusUpdates,
1337     * AggregationExceptions, PhoneLookup rows are deleted automatically. When all raw
1338     * contacts associated with a {@link Contacts} row are deleted, the {@link Contacts} row
1339     * itself is also deleted automatically.
1340     * </p>
1341     * <p>
1342     * The invocation of {@code resolver.delete(...)}, does not immediately delete
1343     * a raw contacts row.
1344     * Instead, it sets the {@link #DELETED} flag on the raw contact and
1345     * removes the raw contact from its aggregate contact.
1346     * The sync adapter then deletes the raw contact from the server and
1347     * finalizes phone-side deletion by calling {@code resolver.delete(...)}
1348     * again and passing the {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter.<p>
1349     * <p>Some sync adapters are read-only, meaning that they only sync server-side
1350     * changes to the phone, but not the reverse.  If one of those raw contacts
1351     * is marked for deletion, it will remain on the phone.  However it will be
1352     * effectively invisible, because it will not be part of any aggregate contact.
1353     * </dd>
1354     *
1355     * <dt><b>Query</b></dt>
1356     * <dd>
1357     * <p>
1358     * It is easy to find all raw contacts in a Contact:
1359     * <pre>
1360     * Cursor c = getContentResolver().query(RawContacts.CONTENT_URI,
1361     *          new String[]{RawContacts._ID},
1362     *          RawContacts.CONTACT_ID + "=?",
1363     *          new String[]{String.valueOf(contactId)}, null);
1364     * </pre>
1365     * </p>
1366     * <p>
1367     * To find raw contacts within a specific account,
1368     * you can either put the account name and type in the selection or pass them as query
1369     * parameters.  The latter approach is preferable, especially when you can reuse the
1370     * URI:
1371     * <pre>
1372     * Uri rawContactUri = RawContacts.URI.buildUpon()
1373     *          .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName)
1374     *          .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType)
1375     *          .build();
1376     * Cursor c1 = getContentResolver().query(rawContactUri,
1377     *          RawContacts.STARRED + "&lt;&gt;0", null, null, null);
1378     * ...
1379     * Cursor c2 = getContentResolver().query(rawContactUri,
1380     *          RawContacts.DELETED + "&lt;&gt;0", null, null, null);
1381     * </pre>
1382     * </p>
1383     * <p>The best way to read a raw contact along with all the data associated with it is
1384     * by using the {@link Entity} directory. If the raw contact has data rows,
1385     * the Entity cursor will contain a row for each data row.  If the raw contact has no
1386     * data rows, the cursor will still contain one row with the raw contact-level information.
1387     * <pre>
1388     * Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
1389     * Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
1390     * Cursor c = getContentResolver().query(entityUri,
1391     *          new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1},
1392     *          null, null, null);
1393     * try {
1394     *     while (c.moveToNext()) {
1395     *         String sourceId = c.getString(0);
1396     *         if (!c.isNull(1)) {
1397     *             String mimeType = c.getString(2);
1398     *             String data = c.getString(3);
1399     *             ...
1400     *         }
1401     *     }
1402     * } finally {
1403     *     c.close();
1404     * }
1405     * </pre>
1406     * </p>
1407     * </dd>
1408     * </dl>
1409     * <h2>Columns</h2>
1410     *
1411     * <table class="jd-sumtable">
1412     * <tr>
1413     * <th colspan='4'>RawContacts</th>
1414     * </tr>
1415     * <tr>
1416     * <td>long</td>
1417     * <td>{@link #_ID}</td>
1418     * <td>read-only</td>
1419     * <td>Row ID. Sync adapters should try to preserve row IDs during updates. In other words,
1420     * it is much better for a sync adapter to update a raw contact rather than to delete and
1421     * re-insert it.</td>
1422     * </tr>
1423     * <tr>
1424     * <td>long</td>
1425     * <td>{@link #CONTACT_ID}</td>
1426     * <td>read-only</td>
1427     * <td>The ID of the row in the {@link ContactsContract.Contacts} table
1428     * that this raw contact belongs
1429     * to. Raw contacts are linked to contacts by the aggregation process, which can be controlled
1430     * by the {@link #AGGREGATION_MODE} field and {@link AggregationExceptions}.</td>
1431     * </tr>
1432     * <tr>
1433     * <td>int</td>
1434     * <td>{@link #AGGREGATION_MODE}</td>
1435     * <td>read/write</td>
1436     * <td>A mechanism that allows programmatic control of the aggregation process. The allowed
1437     * values are {@link #AGGREGATION_MODE_DEFAULT}, {@link #AGGREGATION_MODE_DISABLED}
1438     * and {@link #AGGREGATION_MODE_SUSPENDED}. See also {@link AggregationExceptions}.</td>
1439     * </tr>
1440     * <tr>
1441     * <td>int</td>
1442     * <td>{@link #DELETED}</td>
1443     * <td>read/write</td>
1444     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
1445     * for deletion. When {@link android.content.ContentResolver#delete} is
1446     * called on a raw contact, it is marked for deletion and removed from its
1447     * aggregate contact. The sync adaptor deletes the raw contact on the server and
1448     * then calls ContactResolver.delete once more, this time passing the
1449     * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
1450     * the data removal.</td>
1451     * </tr>
1452     * <tr>
1453     * <td>int</td>
1454     * <td>{@link #TIMES_CONTACTED}</td>
1455     * <td>read/write</td>
1456     * <td>The number of times the contact has been contacted. To have an effect
1457     * on the corresponding value of the aggregate contact, this field
1458     * should be set at the time the raw contact is inserted.
1459     * After that, this value is typically updated via
1460     * {@link ContactsContract.Contacts#markAsContacted}.</td>
1461     * </tr>
1462     * <tr>
1463     * <td>long</td>
1464     * <td>{@link #LAST_TIME_CONTACTED}</td>
1465     * <td>read/write</td>
1466     * <td>The timestamp of the last time the contact was contacted. To have an effect
1467     * on the corresponding value of the aggregate contact, this field
1468     * should be set at the time the raw contact is inserted.
1469     * After that, this value is typically updated via
1470     * {@link ContactsContract.Contacts#markAsContacted}.
1471     * </td>
1472     * </tr>
1473     * <tr>
1474     * <td>int</td>
1475     * <td>{@link #STARRED}</td>
1476     * <td>read/write</td>
1477     * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise.
1478     * Changing this field immediately affects the corresponding aggregate contact:
1479     * if any raw contacts in that aggregate contact are starred, then the contact
1480     * itself is marked as starred.</td>
1481     * </tr>
1482     * <tr>
1483     * <td>String</td>
1484     * <td>{@link #CUSTOM_RINGTONE}</td>
1485     * <td>read/write</td>
1486     * <td>A custom ringtone associated with a raw contact. Typically this is the
1487     * URI returned by an activity launched with the
1488     * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.
1489     * To have an effect on the corresponding value of the aggregate contact, this field
1490     * should be set at the time the raw contact is inserted. To set a custom
1491     * ringtone on a contact, use the field {@link ContactsContract.Contacts#CUSTOM_RINGTONE
1492     * Contacts.CUSTOM_RINGTONE}
1493     * instead.</td>
1494     * </tr>
1495     * <tr>
1496     * <td>int</td>
1497     * <td>{@link #SEND_TO_VOICEMAIL}</td>
1498     * <td>read/write</td>
1499     * <td>An indicator of whether calls from this raw contact should be forwarded
1500     * directly to voice mail ('1') or not ('0'). To have an effect
1501     * on the corresponding value of the aggregate contact, this field
1502     * should be set at the time the raw contact is inserted.</td>
1503     * </tr>
1504     * <tr>
1505     * <td>String</td>
1506     * <td>{@link #ACCOUNT_NAME}</td>
1507     * <td>read/write-once</td>
1508     * <td>The name of the account instance to which this row belongs, which when paired with
1509     * {@link #ACCOUNT_TYPE} identifies a specific account.
1510     * For example, this will be the Gmail address if it is a Google account.
1511     * It should be set at the time
1512     * the raw contact is inserted and never changed afterwards.</td>
1513     * </tr>
1514     * <tr>
1515     * <td>String</td>
1516     * <td>{@link #ACCOUNT_TYPE}</td>
1517     * <td>read/write-once</td>
1518     * <td>
1519     * <p>
1520     * The type of account to which this row belongs, which when paired with
1521     * {@link #ACCOUNT_NAME} identifies a specific account.
1522     * It should be set at the time
1523     * the raw contact is inserted and never changed afterwards.
1524     * </p>
1525     * <p>
1526     * To ensure uniqueness, new account types should be chosen according to the
1527     * Java package naming convention.  Thus a Google account is of type "com.google".
1528     * </p>
1529     * </td>
1530     * </tr>
1531     * <tr>
1532     * <td>String</td>
1533     * <td>{@link #SOURCE_ID}</td>
1534     * <td>read/write</td>
1535     * <td>String that uniquely identifies this row to its source account.
1536     * Typically it is set at the time the raw contact is inserted and never
1537     * changed afterwards. The one notable exception is a new raw contact: it
1538     * will have an account name and type, but no source id. This
1539     * indicates to the sync adapter that a new contact needs to be created
1540     * server-side and its ID stored in the corresponding SOURCE_ID field on
1541     * the phone.
1542     * </td>
1543     * </tr>
1544     * <tr>
1545     * <td>int</td>
1546     * <td>{@link #VERSION}</td>
1547     * <td>read-only</td>
1548     * <td>Version number that is updated whenever this row or its related data
1549     * changes. This field can be used for optimistic locking of a raw contact.
1550     * </td>
1551     * </tr>
1552     * <tr>
1553     * <td>int</td>
1554     * <td>{@link #DIRTY}</td>
1555     * <td>read/write</td>
1556     * <td>Flag indicating that {@link #VERSION} has changed, and this row needs
1557     * to be synchronized by its owning account.  The value is set to "1" automatically
1558     * whenever the raw contact changes, unless the URI has the
1559     * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter specified.
1560     * The sync adapter should always supply this query parameter to prevent
1561     * unnecessary synchronization: user changes some data on the server,
1562     * the sync adapter updates the contact on the phone (without the
1563     * CALLER_IS_SYNCADAPTER flag) flag, which sets the DIRTY flag,
1564     * which triggers a sync to bring the changes to the server.
1565     * </td>
1566     * </tr>
1567     * <tr>
1568     * <td>String</td>
1569     * <td>{@link #SYNC1}</td>
1570     * <td>read/write</td>
1571     * <td>Generic column provided for arbitrary use by sync adapters.
1572     * The content provider
1573     * stores this information on behalf of the sync adapter but does not
1574     * interpret it in any way.
1575     * </td>
1576     * </tr>
1577     * <tr>
1578     * <td>String</td>
1579     * <td>{@link #SYNC2}</td>
1580     * <td>read/write</td>
1581     * <td>Generic column for use by sync adapters.
1582     * </td>
1583     * </tr>
1584     * <tr>
1585     * <td>String</td>
1586     * <td>{@link #SYNC3}</td>
1587     * <td>read/write</td>
1588     * <td>Generic column for use by sync adapters.
1589     * </td>
1590     * </tr>
1591     * <tr>
1592     * <td>String</td>
1593     * <td>{@link #SYNC4}</td>
1594     * <td>read/write</td>
1595     * <td>Generic column for use by sync adapters.
1596     * </td>
1597     * </tr>
1598     * </table>
1599     */
1600    public static final class RawContacts implements BaseColumns, RawContactsColumns,
1601            ContactOptionsColumns, ContactNameColumns, SyncColumns  {
1602        /**
1603         * This utility class cannot be instantiated
1604         */
1605        private RawContacts() {
1606        }
1607
1608        /**
1609         * The content:// style URI for this table, which requests a directory of
1610         * raw contact rows matching the selection criteria.
1611         */
1612        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "raw_contacts");
1613
1614        /**
1615         * The MIME type of the results from {@link #CONTENT_URI} when a specific
1616         * ID value is not provided, and multiple raw contacts may be returned.
1617         */
1618        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact";
1619
1620        /**
1621         * The MIME type of the results when a raw contact ID is appended to {@link #CONTENT_URI},
1622         * yielding a subdirectory of a single person.
1623         */
1624        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/raw_contact";
1625
1626        /**
1627         * Aggregation mode: aggregate immediately after insert or update operation(s) are complete.
1628         */
1629        public static final int AGGREGATION_MODE_DEFAULT = 0;
1630
1631        /**
1632         * Do not use.
1633         *
1634         * TODO: deprecate in favor of {@link #AGGREGATION_MODE_DEFAULT}
1635         */
1636        public static final int AGGREGATION_MODE_IMMEDIATE = 1;
1637
1638        /**
1639         * <p>
1640         * Aggregation mode: aggregation suspended temporarily, and is likely to be resumed later.
1641         * Changes to the raw contact will update the associated aggregate contact but will not
1642         * result in any change in how the contact is aggregated. Similar to
1643         * {@link #AGGREGATION_MODE_DISABLED}, but maintains a link to the corresponding
1644         * {@link Contacts} aggregate.
1645         * </p>
1646         * <p>
1647         * This can be used to postpone aggregation until after a series of updates, for better
1648         * performance and/or user experience.
1649         * </p>
1650         * <p>
1651         * Note that changing
1652         * {@link #AGGREGATION_MODE} from {@link #AGGREGATION_MODE_SUSPENDED} to
1653         * {@link #AGGREGATION_MODE_DEFAULT} does not trigger an aggregation pass, but any
1654         * subsequent
1655         * change to the raw contact's data will.
1656         * </p>
1657         */
1658        public static final int AGGREGATION_MODE_SUSPENDED = 2;
1659
1660        /**
1661         * <p>
1662         * Aggregation mode: never aggregate this raw contact.  The raw contact will not
1663         * have a corresponding {@link Contacts} aggregate and therefore will not be included in
1664         * {@link Contacts} query results.
1665         * </p>
1666         * <p>
1667         * For example, this mode can be used for a raw contact that is marked for deletion while
1668         * waiting for the deletion to occur on the server side.
1669         * </p>
1670         *
1671         * @see #AGGREGATION_MODE_SUSPENDED
1672         */
1673        public static final int AGGREGATION_MODE_DISABLED = 3;
1674
1675        /**
1676         * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
1677         * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts}
1678         * entry of the given {@link RawContacts} entry.
1679         */
1680        public static Uri getContactLookupUri(ContentResolver resolver, Uri rawContactUri) {
1681            // TODO: use a lighter query by joining rawcontacts with contacts in provider
1682            final Uri dataUri = Uri.withAppendedPath(rawContactUri, Data.CONTENT_DIRECTORY);
1683            final Cursor cursor = resolver.query(dataUri, new String[] {
1684                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
1685            }, null, null, null);
1686
1687            Uri lookupUri = null;
1688            try {
1689                if (cursor != null && cursor.moveToFirst()) {
1690                    final long contactId = cursor.getLong(0);
1691                    final String lookupKey = cursor.getString(1);
1692                    return Contacts.getLookupUri(contactId, lookupKey);
1693                }
1694            } finally {
1695                if (cursor != null) cursor.close();
1696            }
1697            return lookupUri;
1698        }
1699
1700        /**
1701         * A sub-directory of a single raw contact that contains all of its
1702         * {@link ContactsContract.Data} rows. To access this directory
1703         * append {@link Data#CONTENT_DIRECTORY} to the contact URI.
1704         *
1705         * TODO: deprecate in favor of {@link RawContacts.Entity}.
1706         */
1707        public static final class Data implements BaseColumns, DataColumns {
1708            /**
1709             * no public constructor since this is a utility class
1710             */
1711            private Data() {
1712            }
1713
1714            /**
1715             * The directory twig for this sub-table
1716             */
1717            public static final String CONTENT_DIRECTORY = "data";
1718        }
1719
1720        /**
1721         * <p>
1722         * A sub-directory of a single raw contact that contains all of its
1723         * {@link ContactsContract.Data} rows. To access this directory append
1724         * {@link #CONTENT_DIRECTORY} to the contact URI. See
1725         * {@link RawContactsEntity} for a stand-alone table containing the same
1726         * data.
1727         * </p>
1728         * <p>
1729         * Entity has two ID fields: {@link #_ID} for the raw contact
1730         * and {@link #DATA_ID} for the data rows.
1731         * Entity always contains at least one row, even if there are no
1732         * actual data rows. In this case the {@link #DATA_ID} field will be
1733         * null.
1734         * </p>
1735         * <p>
1736         * Entity reads all
1737         * data for a raw contact in one transaction, to guarantee
1738         * consistency.
1739         * </p>
1740         */
1741        public static final class Entity implements BaseColumns, DataColumns {
1742            /**
1743             * no public constructor since this is a utility class
1744             */
1745            private Entity() {
1746            }
1747
1748            /**
1749             * The directory twig for this sub-table
1750             */
1751            public static final String CONTENT_DIRECTORY = "entity";
1752
1753            /**
1754             * The ID of the data column. The value will be null if this raw contact has no
1755             * data rows.
1756             * <P>Type: INTEGER</P>
1757             */
1758            public static final String DATA_ID = "data_id";
1759        }
1760
1761        /**
1762         * TODO: javadoc
1763         * @param cursor
1764         * @return
1765         */
1766        public static EntityIterator newEntityIterator(Cursor cursor) {
1767            return new EntityIteratorImpl(cursor);
1768        }
1769
1770        private static class EntityIteratorImpl extends CursorEntityIterator {
1771            private static final String[] DATA_KEYS = new String[]{
1772                    Data.DATA1,
1773                    Data.DATA2,
1774                    Data.DATA3,
1775                    Data.DATA4,
1776                    Data.DATA5,
1777                    Data.DATA6,
1778                    Data.DATA7,
1779                    Data.DATA8,
1780                    Data.DATA9,
1781                    Data.DATA10,
1782                    Data.DATA11,
1783                    Data.DATA12,
1784                    Data.DATA13,
1785                    Data.DATA14,
1786                    Data.DATA15,
1787                    Data.SYNC1,
1788                    Data.SYNC2,
1789                    Data.SYNC3,
1790                    Data.SYNC4};
1791
1792            public EntityIteratorImpl(Cursor cursor) {
1793                super(cursor);
1794            }
1795
1796            @Override
1797            public android.content.Entity getEntityAndIncrementCursor(Cursor cursor)
1798                    throws RemoteException {
1799                final int columnRawContactId = cursor.getColumnIndexOrThrow(RawContacts._ID);
1800                final long rawContactId = cursor.getLong(columnRawContactId);
1801
1802                // we expect the cursor is already at the row we need to read from
1803                ContentValues cv = new ContentValues();
1804                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME);
1805                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE);
1806                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, _ID);
1807                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
1808                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, VERSION);
1809                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SOURCE_ID);
1810                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC1);
1811                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC2);
1812                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC3);
1813                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC4);
1814                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED);
1815                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID);
1816                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED);
1817                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, IS_RESTRICTED);
1818                DatabaseUtils.cursorIntToContentValuesIfPresent(cursor, cv, NAME_VERIFIED);
1819                android.content.Entity contact = new android.content.Entity(cv);
1820
1821                // read data rows until the contact id changes
1822                do {
1823                    if (rawContactId != cursor.getLong(columnRawContactId)) {
1824                        break;
1825                    }
1826                    // add the data to to the contact
1827                    cv = new ContentValues();
1828                    cv.put(Data._ID, cursor.getLong(cursor.getColumnIndexOrThrow(Entity.DATA_ID)));
1829                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
1830                            Data.RES_PACKAGE);
1831                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.MIMETYPE);
1832                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.IS_PRIMARY);
1833                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv,
1834                            Data.IS_SUPER_PRIMARY);
1835                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.DATA_VERSION);
1836                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
1837                            CommonDataKinds.GroupMembership.GROUP_SOURCE_ID);
1838                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
1839                            Data.DATA_VERSION);
1840                    for (String key : DATA_KEYS) {
1841                        final int columnIndex = cursor.getColumnIndexOrThrow(key);
1842                        if (cursor.isNull(columnIndex)) {
1843                            // don't put anything
1844                        } else {
1845                            try {
1846                                cv.put(key, cursor.getString(columnIndex));
1847                            } catch (SQLiteException e) {
1848                                cv.put(key, cursor.getBlob(columnIndex));
1849                            }
1850                        }
1851                        // TODO: go back to this version of the code when bug
1852                        // http://b/issue?id=2306370 is fixed.
1853//                        if (cursor.isNull(columnIndex)) {
1854//                            // don't put anything
1855//                        } else if (cursor.isLong(columnIndex)) {
1856//                            values.put(key, cursor.getLong(columnIndex));
1857//                        } else if (cursor.isFloat(columnIndex)) {
1858//                            values.put(key, cursor.getFloat(columnIndex));
1859//                        } else if (cursor.isString(columnIndex)) {
1860//                            values.put(key, cursor.getString(columnIndex));
1861//                        } else if (cursor.isBlob(columnIndex)) {
1862//                            values.put(key, cursor.getBlob(columnIndex));
1863//                        }
1864                    }
1865                    contact.addSubValue(ContactsContract.Data.CONTENT_URI, cv);
1866                } while (cursor.moveToNext());
1867
1868                return contact;
1869            }
1870
1871        }
1872    }
1873
1874    /**
1875     * Social status update columns.
1876     *
1877     * @see StatusUpdates
1878     * @see ContactsContract.Data
1879     */
1880    protected interface StatusColumns {
1881        /**
1882         * Contact's latest presence level.
1883         * <P>Type: INTEGER (one of the values below)</P>
1884         */
1885        public static final String PRESENCE = "mode";
1886
1887        /**
1888         * @deprecated use {@link #PRESENCE}
1889         */
1890        @Deprecated
1891        public static final String PRESENCE_STATUS = PRESENCE;
1892
1893        /**
1894         * An allowed value of {@link #PRESENCE}.
1895         */
1896        int OFFLINE = 0;
1897
1898        /**
1899         * An allowed value of {@link #PRESENCE}.
1900         */
1901        int INVISIBLE = 1;
1902
1903        /**
1904         * An allowed value of {@link #PRESENCE}.
1905         */
1906        int AWAY = 2;
1907
1908        /**
1909         * An allowed value of {@link #PRESENCE}.
1910         */
1911        int IDLE = 3;
1912
1913        /**
1914         * An allowed value of {@link #PRESENCE}.
1915         */
1916        int DO_NOT_DISTURB = 4;
1917
1918        /**
1919         * An allowed value of {@link #PRESENCE}.
1920         */
1921        int AVAILABLE = 5;
1922
1923        /**
1924         * Contact latest status update.
1925         * <p>Type: TEXT</p>
1926         */
1927        public static final String STATUS = "status";
1928
1929        /**
1930         * @deprecated use {@link #STATUS}
1931         */
1932        @Deprecated
1933        public static final String PRESENCE_CUSTOM_STATUS = STATUS;
1934
1935        /**
1936         * The absolute time in milliseconds when the latest status was inserted/updated.
1937         * <p>Type: NUMBER</p>
1938         */
1939        public static final String STATUS_TIMESTAMP = "status_ts";
1940
1941        /**
1942         * The package containing resources for this status: label and icon.
1943         * <p>Type: NUMBER</p>
1944         */
1945        public static final String STATUS_RES_PACKAGE = "status_res_package";
1946
1947        /**
1948         * The resource ID of the label describing the source of the status update, e.g. "Google
1949         * Talk".  This resource should be scoped by the {@link #STATUS_RES_PACKAGE}.
1950         * <p>Type: NUMBER</p>
1951         */
1952        public static final String STATUS_LABEL = "status_label";
1953
1954        /**
1955         * The resource ID of the icon for the source of the status update.
1956         * This resource should be scoped by the {@link #STATUS_RES_PACKAGE}.
1957         * <p>Type: NUMBER</p>
1958         */
1959        public static final String STATUS_ICON = "status_icon";
1960
1961        /**
1962         * Contact's audio/video chat capability level.
1963         * <P>Type: INTEGER (one of the values below)</P>
1964         */
1965        public static final String CHAT_CAPABILITY = "chat_capability";
1966
1967        /**
1968         * An allowed value of {@link #CHAT_CAPABILITY}. Indicates that the contact's device can
1969         * display a video feed.
1970         */
1971        public static final int CAPABILITY_HAS_VIDEO_PLAYBACK_ONLY = 1;
1972
1973        /**
1974         * An allowed value of {@link #CHAT_CAPABILITY}. Indicates audio-chat capability.
1975         */
1976        public static final int CAPABILITY_HAS_VOICE = 2;
1977
1978        /**
1979         * An allowed value of {@link #CHAT_CAPABILITY}. Indicates that the contact's device has a
1980         * camera that can be used for video chat (e.g. a front-facing camera on a phone).
1981         */
1982        public static final int CAPABILITY_HAS_CAMERA = 4;
1983    }
1984
1985    /**
1986     * Columns in the Data table.
1987     *
1988     * @see ContactsContract.Data
1989     */
1990    protected interface DataColumns {
1991        /**
1992         * The package name to use when creating {@link Resources} objects for
1993         * this data row. This value is only designed for use when building user
1994         * interfaces, and should not be used to infer the owner.
1995         *
1996         * @hide
1997         */
1998        public static final String RES_PACKAGE = "res_package";
1999
2000        /**
2001         * The MIME type of the item represented by this row.
2002         */
2003        public static final String MIMETYPE = "mimetype";
2004
2005        /**
2006         * A reference to the {@link RawContacts#_ID}
2007         * that this data belongs to.
2008         */
2009        public static final String RAW_CONTACT_ID = "raw_contact_id";
2010
2011        /**
2012         * Whether this is the primary entry of its kind for the raw contact it belongs to.
2013         * <P>Type: INTEGER (if set, non-0 means true)</P>
2014         */
2015        public static final String IS_PRIMARY = "is_primary";
2016
2017        /**
2018         * Whether this is the primary entry of its kind for the aggregate
2019         * contact it belongs to. Any data record that is "super primary" must
2020         * also be "primary".
2021         * <P>Type: INTEGER (if set, non-0 means true)</P>
2022         */
2023        public static final String IS_SUPER_PRIMARY = "is_super_primary";
2024
2025        /**
2026         * The version of this data record. This is a read-only value. The data column is
2027         * guaranteed to not change without the version going up. This value is monotonically
2028         * increasing.
2029         * <P>Type: INTEGER</P>
2030         */
2031        public static final String DATA_VERSION = "data_version";
2032
2033        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2034        public static final String DATA1 = "data1";
2035        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2036        public static final String DATA2 = "data2";
2037        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2038        public static final String DATA3 = "data3";
2039        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2040        public static final String DATA4 = "data4";
2041        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2042        public static final String DATA5 = "data5";
2043        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2044        public static final String DATA6 = "data6";
2045        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2046        public static final String DATA7 = "data7";
2047        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2048        public static final String DATA8 = "data8";
2049        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2050        public static final String DATA9 = "data9";
2051        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2052        public static final String DATA10 = "data10";
2053        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2054        public static final String DATA11 = "data11";
2055        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2056        public static final String DATA12 = "data12";
2057        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2058        public static final String DATA13 = "data13";
2059        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
2060        public static final String DATA14 = "data14";
2061        /**
2062         * Generic data column, the meaning is {@link #MIMETYPE} specific. By convention,
2063         * this field is used to store BLOBs (binary data).
2064         */
2065        public static final String DATA15 = "data15";
2066
2067        /** Generic column for use by sync adapters. */
2068        public static final String SYNC1 = "data_sync1";
2069        /** Generic column for use by sync adapters. */
2070        public static final String SYNC2 = "data_sync2";
2071        /** Generic column for use by sync adapters. */
2072        public static final String SYNC3 = "data_sync3";
2073        /** Generic column for use by sync adapters. */
2074        public static final String SYNC4 = "data_sync4";
2075    }
2076
2077    /**
2078     * Combines all columns returned by {@link ContactsContract.Data} table queries.
2079     *
2080     * @see ContactsContract.Data
2081     */
2082    protected interface DataColumnsWithJoins extends BaseColumns, DataColumns, StatusColumns,
2083            RawContactsColumns, ContactsColumns, ContactNameColumns, ContactOptionsColumns,
2084            ContactStatusColumns {
2085    }
2086
2087    /**
2088     * <p>
2089     * Constants for the data table, which contains data points tied to a raw
2090     * contact.  Each row of the data table is typically used to store a single
2091     * piece of contact
2092     * information (such as a phone number) and its
2093     * associated metadata (such as whether it is a work or home number).
2094     * </p>
2095     * <h3>Data kinds</h3>
2096     * <p>
2097     * Data is a generic table that can hold any kind of contact data.
2098     * The kind of data stored in a given row is specified by the row's
2099     * {@link #MIMETYPE} value, which determines the meaning of the
2100     * generic columns {@link #DATA1} through
2101     * {@link #DATA15}.
2102     * For example, if the data kind is
2103     * {@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}, then the column
2104     * {@link #DATA1} stores the
2105     * phone number, but if the data kind is
2106     * {@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}, then {@link #DATA1}
2107     * stores the email address.
2108     * Sync adapters and applications can introduce their own data kinds.
2109     * </p>
2110     * <p>
2111     * ContactsContract defines a small number of pre-defined data kinds, e.g.
2112     * {@link CommonDataKinds.Phone}, {@link CommonDataKinds.Email} etc. As a
2113     * convenience, these classes define data kind specific aliases for DATA1 etc.
2114     * For example, {@link CommonDataKinds.Phone Phone.NUMBER} is the same as
2115     * {@link ContactsContract.Data Data.DATA1}.
2116     * </p>
2117     * <p>
2118     * {@link #DATA1} is an indexed column and should be used for the data element that is
2119     * expected to be most frequently used in query selections. For example, in the
2120     * case of a row representing email addresses {@link #DATA1} should probably
2121     * be used for the email address itself, while {@link #DATA2} etc can be
2122     * used for auxiliary information like type of email address.
2123     * <p>
2124     * <p>
2125     * By convention, {@link #DATA15} is used for storing BLOBs (binary data).
2126     * </p>
2127     * <p>
2128     * The sync adapter for a given account type must correctly handle every data type
2129     * used in the corresponding raw contacts.  Otherwise it could result in lost or
2130     * corrupted data.
2131     * </p>
2132     * <p>
2133     * Similarly, you should refrain from introducing new kinds of data for an other
2134     * party's account types. For example, if you add a data row for
2135     * "favorite song" to a raw contact owned by a Google account, it will not
2136     * get synced to the server, because the Google sync adapter does not know
2137     * how to handle this data kind. Thus new data kinds are typically
2138     * introduced along with new account types, i.e. new sync adapters.
2139     * </p>
2140     * <h3>Batch operations</h3>
2141     * <p>
2142     * Data rows can be inserted/updated/deleted using the traditional
2143     * {@link ContentResolver#insert}, {@link ContentResolver#update} and
2144     * {@link ContentResolver#delete} methods, however the newer mechanism based
2145     * on a batch of {@link ContentProviderOperation} will prove to be a better
2146     * choice in almost all cases. All operations in a batch are executed in a
2147     * single transaction, which ensures that the phone-side and server-side
2148     * state of a raw contact are always consistent. Also, the batch-based
2149     * approach is far more efficient: not only are the database operations
2150     * faster when executed in a single transaction, but also sending a batch of
2151     * commands to the content provider saves a lot of time on context switching
2152     * between your process and the process in which the content provider runs.
2153     * </p>
2154     * <p>
2155     * The flip side of using batched operations is that a large batch may lock
2156     * up the database for a long time preventing other applications from
2157     * accessing data and potentially causing ANRs ("Application Not Responding"
2158     * dialogs.)
2159     * </p>
2160     * <p>
2161     * To avoid such lockups of the database, make sure to insert "yield points"
2162     * in the batch. A yield point indicates to the content provider that before
2163     * executing the next operation it can commit the changes that have already
2164     * been made, yield to other requests, open another transaction and continue
2165     * processing operations. A yield point will not automatically commit the
2166     * transaction, but only if there is another request waiting on the
2167     * database. Normally a sync adapter should insert a yield point at the
2168     * beginning of each raw contact operation sequence in the batch. See
2169     * {@link ContentProviderOperation.Builder#withYieldAllowed(boolean)}.
2170     * </p>
2171     * <h3>Operations</h3>
2172     * <dl>
2173     * <dt><b>Insert</b></dt>
2174     * <dd>
2175     * <p>
2176     * An individual data row can be inserted using the traditional
2177     * {@link ContentResolver#insert(Uri, ContentValues)} method. Multiple rows
2178     * should always be inserted as a batch.
2179     * </p>
2180     * <p>
2181     * An example of a traditional insert:
2182     * <pre>
2183     * ContentValues values = new ContentValues();
2184     * values.put(Data.RAW_CONTACT_ID, rawContactId);
2185     * values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
2186     * values.put(Phone.NUMBER, "1-800-GOOG-411");
2187     * values.put(Phone.TYPE, Phone.TYPE_CUSTOM);
2188     * values.put(Phone.LABEL, "free directory assistance");
2189     * Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values);
2190     * </pre>
2191     * <p>
2192     * The same done using ContentProviderOperations:
2193     * <pre>
2194     * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
2195     * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
2196     *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
2197     *          .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
2198     *          .withValue(Phone.NUMBER, "1-800-GOOG-411")
2199     *          .withValue(Phone.TYPE, Phone.TYPE_CUSTOM)
2200     *          .withValue(Phone.LABEL, "free directory assistance")
2201     *          .build());
2202     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
2203     * </pre>
2204     * </p>
2205     * <dt><b>Update</b></dt>
2206     * <dd>
2207     * <p>
2208     * Just as with insert, update can be done incrementally or as a batch,
2209     * the batch mode being the preferred method:
2210     * <pre>
2211     * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
2212     * ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
2213     *          .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
2214     *          .withValue(Email.DATA, "somebody@android.com")
2215     *          .build());
2216     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
2217     * </pre>
2218     * </p>
2219     * </dd>
2220     * <dt><b>Delete</b></dt>
2221     * <dd>
2222     * <p>
2223     * Just as with insert and update, deletion can be done either using the
2224     * {@link ContentResolver#delete} method or using a ContentProviderOperation:
2225     * <pre>
2226     * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
2227     * ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI)
2228     *          .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
2229     *          .build());
2230     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
2231     * </pre>
2232     * </p>
2233     * </dd>
2234     * <dt><b>Query</b></dt>
2235     * <dd>
2236     * <p>
2237     * <dl>
2238     * <dt>Finding all Data of a given type for a given contact</dt>
2239     * <dd>
2240     * <pre>
2241     * Cursor c = getContentResolver().query(Data.CONTENT_URI,
2242     *          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
2243     *          Data.CONTACT_ID + &quot;=?&quot; + " AND "
2244     *                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
2245     *          new String[] {String.valueOf(contactId)}, null);
2246     * </pre>
2247     * </p>
2248     * <p>
2249     * </dd>
2250     * <dt>Finding all Data of a given type for a given raw contact</dt>
2251     * <dd>
2252     * <pre>
2253     * Cursor c = getContentResolver().query(Data.CONTENT_URI,
2254     *          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
2255     *          Data.RAW_CONTACT_ID + &quot;=?&quot; + " AND "
2256     *                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
2257     *          new String[] {String.valueOf(rawContactId)}, null);
2258     * </pre>
2259     * </dd>
2260     * <dt>Finding all Data for a given raw contact</dt>
2261     * <dd>
2262     * Most sync adapters will want to read all data rows for a raw contact
2263     * along with the raw contact itself.  For that you should use the
2264     * {@link RawContactsEntity}. See also {@link RawContacts}.
2265     * </dd>
2266     * </dl>
2267     * </p>
2268     * </dd>
2269     * </dl>
2270     * <h2>Columns</h2>
2271     * <p>
2272     * Many columns are available via a {@link Data#CONTENT_URI} query.  For best performance you
2273     * should explicitly specify a projection to only those columns that you need.
2274     * </p>
2275     * <table class="jd-sumtable">
2276     * <tr>
2277     * <th colspan='4'>Data</th>
2278     * </tr>
2279     * <tr>
2280     * <td style="width: 7em;">long</td>
2281     * <td style="width: 20em;">{@link #_ID}</td>
2282     * <td style="width: 5em;">read-only</td>
2283     * <td>Row ID. Sync adapter should try to preserve row IDs during updates. In other words,
2284     * it would be a bad idea to delete and reinsert a data row. A sync adapter should
2285     * always do an update instead.</td>
2286     * </tr>
2287     * <tr>
2288     * <td>String</td>
2289     * <td>{@link #MIMETYPE}</td>
2290     * <td>read/write-once</td>
2291     * <td>
2292     * <p>The MIME type of the item represented by this row. Examples of common
2293     * MIME types are:
2294     * <ul>
2295     * <li>{@link CommonDataKinds.StructuredName StructuredName.CONTENT_ITEM_TYPE}</li>
2296     * <li>{@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}</li>
2297     * <li>{@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}</li>
2298     * <li>{@link CommonDataKinds.Photo Photo.CONTENT_ITEM_TYPE}</li>
2299     * <li>{@link CommonDataKinds.Organization Organization.CONTENT_ITEM_TYPE}</li>
2300     * <li>{@link CommonDataKinds.Im Im.CONTENT_ITEM_TYPE}</li>
2301     * <li>{@link CommonDataKinds.Nickname Nickname.CONTENT_ITEM_TYPE}</li>
2302     * <li>{@link CommonDataKinds.Note Note.CONTENT_ITEM_TYPE}</li>
2303     * <li>{@link CommonDataKinds.StructuredPostal StructuredPostal.CONTENT_ITEM_TYPE}</li>
2304     * <li>{@link CommonDataKinds.GroupMembership GroupMembership.CONTENT_ITEM_TYPE}</li>
2305     * <li>{@link CommonDataKinds.Website Website.CONTENT_ITEM_TYPE}</li>
2306     * <li>{@link CommonDataKinds.Event Event.CONTENT_ITEM_TYPE}</li>
2307     * <li>{@link CommonDataKinds.Relation Relation.CONTENT_ITEM_TYPE}</li>
2308     * <li>{@link CommonDataKinds.SipAddress SipAddress.CONTENT_ITEM_TYPE}</li>
2309     * </ul>
2310     * </p>
2311     * </td>
2312     * </tr>
2313     * <tr>
2314     * <td>long</td>
2315     * <td>{@link #RAW_CONTACT_ID}</td>
2316     * <td>read/write-once</td>
2317     * <td>The id of the row in the {@link RawContacts} table that this data belongs to.</td>
2318     * </tr>
2319     * <tr>
2320     * <td>int</td>
2321     * <td>{@link #IS_PRIMARY}</td>
2322     * <td>read/write</td>
2323     * <td>Whether this is the primary entry of its kind for the raw contact it belongs to.
2324     * "1" if true, "0" if false.
2325     * </td>
2326     * </tr>
2327     * <tr>
2328     * <td>int</td>
2329     * <td>{@link #IS_SUPER_PRIMARY}</td>
2330     * <td>read/write</td>
2331     * <td>Whether this is the primary entry of its kind for the aggregate
2332     * contact it belongs to. Any data record that is "super primary" must
2333     * also be "primary".  For example, the super-primary entry may be
2334     * interpreted as the default contact value of its kind (for example,
2335     * the default phone number to use for the contact).</td>
2336     * </tr>
2337     * <tr>
2338     * <td>int</td>
2339     * <td>{@link #DATA_VERSION}</td>
2340     * <td>read-only</td>
2341     * <td>The version of this data record. Whenever the data row changes
2342     * the version goes up. This value is monotonically increasing.</td>
2343     * </tr>
2344     * <tr>
2345     * <td>Any type</td>
2346     * <td>
2347     * {@link #DATA1}<br>
2348     * {@link #DATA2}<br>
2349     * {@link #DATA3}<br>
2350     * {@link #DATA4}<br>
2351     * {@link #DATA5}<br>
2352     * {@link #DATA6}<br>
2353     * {@link #DATA7}<br>
2354     * {@link #DATA8}<br>
2355     * {@link #DATA9}<br>
2356     * {@link #DATA10}<br>
2357     * {@link #DATA11}<br>
2358     * {@link #DATA12}<br>
2359     * {@link #DATA13}<br>
2360     * {@link #DATA14}<br>
2361     * {@link #DATA15}
2362     * </td>
2363     * <td>read/write</td>
2364     * <td>
2365     * <p>
2366     * Generic data columns.  The meaning of each column is determined by the
2367     * {@link #MIMETYPE}.  By convention, {@link #DATA15} is used for storing
2368     * BLOBs (binary data).
2369     * </p>
2370     * <p>
2371     * Data columns whose meaning is not explicitly defined for a given MIMETYPE
2372     * should not be used.  There is no guarantee that any sync adapter will
2373     * preserve them.  Sync adapters themselves should not use such columns either,
2374     * but should instead use {@link #SYNC1}-{@link #SYNC4}.
2375     * </p>
2376     * </td>
2377     * </tr>
2378     * <tr>
2379     * <td>Any type</td>
2380     * <td>
2381     * {@link #SYNC1}<br>
2382     * {@link #SYNC2}<br>
2383     * {@link #SYNC3}<br>
2384     * {@link #SYNC4}
2385     * </td>
2386     * <td>read/write</td>
2387     * <td>Generic columns for use by sync adapters. For example, a Photo row
2388     * may store the image URL in SYNC1, a status (not loaded, loading, loaded, error)
2389     * in SYNC2, server-side version number in SYNC3 and error code in SYNC4.</td>
2390     * </tr>
2391     * </table>
2392     *
2393     * <p>
2394     * Some columns from the most recent associated status update are also available
2395     * through an implicit join.
2396     * </p>
2397     * <table class="jd-sumtable">
2398     * <tr>
2399     * <th colspan='4'>Join with {@link StatusUpdates}</th>
2400     * </tr>
2401     * <tr>
2402     * <td style="width: 7em;">int</td>
2403     * <td style="width: 20em;">{@link #PRESENCE}</td>
2404     * <td style="width: 5em;">read-only</td>
2405     * <td>IM presence status linked to this data row. Compare with
2406     * {@link #CONTACT_PRESENCE}, which contains the contact's presence across
2407     * all IM rows. See {@link StatusUpdates} for individual status definitions.
2408     * The provider may choose not to store this value
2409     * in persistent storage. The expectation is that presence status will be
2410     * updated on a regular basic.
2411     * </td>
2412     * </tr>
2413     * <tr>
2414     * <td>String</td>
2415     * <td>{@link #STATUS}</td>
2416     * <td>read-only</td>
2417     * <td>Latest status update linked with this data row.</td>
2418     * </tr>
2419     * <tr>
2420     * <td>long</td>
2421     * <td>{@link #STATUS_TIMESTAMP}</td>
2422     * <td>read-only</td>
2423     * <td>The absolute time in milliseconds when the latest status was
2424     * inserted/updated for this data row.</td>
2425     * </tr>
2426     * <tr>
2427     * <td>String</td>
2428     * <td>{@link #STATUS_RES_PACKAGE}</td>
2429     * <td>read-only</td>
2430     * <td>The package containing resources for this status: label and icon.</td>
2431     * </tr>
2432     * <tr>
2433     * <td>long</td>
2434     * <td>{@link #STATUS_LABEL}</td>
2435     * <td>read-only</td>
2436     * <td>The resource ID of the label describing the source of status update linked
2437     * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
2438     * </tr>
2439     * <tr>
2440     * <td>long</td>
2441     * <td>{@link #STATUS_ICON}</td>
2442     * <td>read-only</td>
2443     * <td>The resource ID of the icon for the source of the status update linked
2444     * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
2445     * </tr>
2446     * </table>
2447     *
2448     * <p>
2449     * Some columns from the associated raw contact are also available through an
2450     * implicit join.  The other columns are excluded as uninteresting in this
2451     * context.
2452     * </p>
2453     *
2454     * <table class="jd-sumtable">
2455     * <tr>
2456     * <th colspan='4'>Join with {@link ContactsContract.RawContacts}</th>
2457     * </tr>
2458     * <tr>
2459     * <td style="width: 7em;">long</td>
2460     * <td style="width: 20em;">{@link #CONTACT_ID}</td>
2461     * <td style="width: 5em;">read-only</td>
2462     * <td>The id of the row in the {@link Contacts} table that this data belongs
2463     * to.</td>
2464     * </tr>
2465     * <tr>
2466     * <td>int</td>
2467     * <td>{@link #AGGREGATION_MODE}</td>
2468     * <td>read-only</td>
2469     * <td>See {@link RawContacts}.</td>
2470     * </tr>
2471     * <tr>
2472     * <td>int</td>
2473     * <td>{@link #DELETED}</td>
2474     * <td>read-only</td>
2475     * <td>See {@link RawContacts}.</td>
2476     * </tr>
2477     * </table>
2478     *
2479     * <p>
2480     * The ID column for the associated aggregated contact table
2481     * {@link ContactsContract.Contacts} is available
2482     * via the implicit join to the {@link RawContacts} table, see above.
2483     * The remaining columns from this table are also
2484     * available, through an implicit join.  This
2485     * facilitates lookup by
2486     * the value of a single data element, such as the email address.
2487     * </p>
2488     *
2489     * <table class="jd-sumtable">
2490     * <tr>
2491     * <th colspan='4'>Join with {@link ContactsContract.Contacts}</th>
2492     * </tr>
2493     * <tr>
2494     * <td style="width: 7em;">String</td>
2495     * <td style="width: 20em;">{@link #LOOKUP_KEY}</td>
2496     * <td style="width: 5em;">read-only</td>
2497     * <td>See {@link ContactsContract.Contacts}</td>
2498     * </tr>
2499     * <tr>
2500     * <td>String</td>
2501     * <td>{@link #DISPLAY_NAME}</td>
2502     * <td>read-only</td>
2503     * <td>See {@link ContactsContract.Contacts}</td>
2504     * </tr>
2505     * <tr>
2506     * <td>long</td>
2507     * <td>{@link #PHOTO_ID}</td>
2508     * <td>read-only</td>
2509     * <td>See {@link ContactsContract.Contacts}.</td>
2510     * </tr>
2511     * <tr>
2512     * <td>int</td>
2513     * <td>{@link #IN_VISIBLE_GROUP}</td>
2514     * <td>read-only</td>
2515     * <td>See {@link ContactsContract.Contacts}.</td>
2516     * </tr>
2517     * <tr>
2518     * <td>int</td>
2519     * <td>{@link #HAS_PHONE_NUMBER}</td>
2520     * <td>read-only</td>
2521     * <td>See {@link ContactsContract.Contacts}.</td>
2522     * </tr>
2523     * <tr>
2524     * <td>int</td>
2525     * <td>{@link #TIMES_CONTACTED}</td>
2526     * <td>read-only</td>
2527     * <td>See {@link ContactsContract.Contacts}.</td>
2528     * </tr>
2529     * <tr>
2530     * <td>long</td>
2531     * <td>{@link #LAST_TIME_CONTACTED}</td>
2532     * <td>read-only</td>
2533     * <td>See {@link ContactsContract.Contacts}.</td>
2534     * </tr>
2535     * <tr>
2536     * <td>int</td>
2537     * <td>{@link #STARRED}</td>
2538     * <td>read-only</td>
2539     * <td>See {@link ContactsContract.Contacts}.</td>
2540     * </tr>
2541     * <tr>
2542     * <td>String</td>
2543     * <td>{@link #CUSTOM_RINGTONE}</td>
2544     * <td>read-only</td>
2545     * <td>See {@link ContactsContract.Contacts}.</td>
2546     * </tr>
2547     * <tr>
2548     * <td>int</td>
2549     * <td>{@link #SEND_TO_VOICEMAIL}</td>
2550     * <td>read-only</td>
2551     * <td>See {@link ContactsContract.Contacts}.</td>
2552     * </tr>
2553     * <tr>
2554     * <td>int</td>
2555     * <td>{@link #CONTACT_PRESENCE}</td>
2556     * <td>read-only</td>
2557     * <td>See {@link ContactsContract.Contacts}.</td>
2558     * </tr>
2559     * <tr>
2560     * <td>String</td>
2561     * <td>{@link #CONTACT_STATUS}</td>
2562     * <td>read-only</td>
2563     * <td>See {@link ContactsContract.Contacts}.</td>
2564     * </tr>
2565     * <tr>
2566     * <td>long</td>
2567     * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td>
2568     * <td>read-only</td>
2569     * <td>See {@link ContactsContract.Contacts}.</td>
2570     * </tr>
2571     * <tr>
2572     * <td>String</td>
2573     * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td>
2574     * <td>read-only</td>
2575     * <td>See {@link ContactsContract.Contacts}.</td>
2576     * </tr>
2577     * <tr>
2578     * <td>long</td>
2579     * <td>{@link #CONTACT_STATUS_LABEL}</td>
2580     * <td>read-only</td>
2581     * <td>See {@link ContactsContract.Contacts}.</td>
2582     * </tr>
2583     * <tr>
2584     * <td>long</td>
2585     * <td>{@link #CONTACT_STATUS_ICON}</td>
2586     * <td>read-only</td>
2587     * <td>See {@link ContactsContract.Contacts}.</td>
2588     * </tr>
2589     * </table>
2590     */
2591    public final static class Data implements DataColumnsWithJoins {
2592        /**
2593         * This utility class cannot be instantiated
2594         */
2595        private Data() {}
2596
2597        /**
2598         * The content:// style URI for this table, which requests a directory
2599         * of data rows matching the selection criteria.
2600         */
2601        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data");
2602
2603        /**
2604         * The MIME type of the results from {@link #CONTENT_URI}.
2605         */
2606        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/data";
2607
2608        /**
2609         * <p>
2610         * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward
2611         * Data.CONTENT_URI contains only exportable data.
2612         * </p>
2613         * <p>
2614         * This flag is useful (currently) only for vCard exporter in Contacts app, which
2615         * needs to exclude "un-exportable" data from available data to export, while
2616         * Contacts app itself has priviledge to access all data including "un-exportable"
2617         * ones and providers return all of them regardless of the callers' intention.
2618         * </p>
2619         * <p>
2620         * Type: INTEGER
2621         * </p>
2622         *
2623         * @hide Maybe available only in Eclair and not really ready for public use.
2624         * TODO: remove, or implement this feature completely. As of now (Eclair),
2625         * we only use this flag in queryEntities(), not query().
2626         */
2627        public static final String FOR_EXPORT_ONLY = "for_export_only";
2628
2629        /**
2630         * <p>
2631         * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
2632         * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts}
2633         * entry of the given {@link ContactsContract.Data} entry.
2634         * </p>
2635         * <p>
2636         * Returns the Uri for the contact in the first entry returned by
2637         * {@link ContentResolver#query(Uri, String[], String, String[], String)}
2638         * for the provided {@code dataUri}.  If the query returns null or empty
2639         * results, silently returns null.
2640         * </p>
2641         */
2642        public static Uri getContactLookupUri(ContentResolver resolver, Uri dataUri) {
2643            final Cursor cursor = resolver.query(dataUri, new String[] {
2644                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
2645            }, null, null, null);
2646
2647            Uri lookupUri = null;
2648            try {
2649                if (cursor != null && cursor.moveToFirst()) {
2650                    final long contactId = cursor.getLong(0);
2651                    final String lookupKey = cursor.getString(1);
2652                    return Contacts.getLookupUri(contactId, lookupKey);
2653                }
2654            } finally {
2655                if (cursor != null) cursor.close();
2656            }
2657            return lookupUri;
2658        }
2659    }
2660
2661    /**
2662     * <p>
2663     * Constants for the raw contacts entities table, which can be thought of as
2664     * an outer join of the raw_contacts table with the data table.  It is a strictly
2665     * read-only table.
2666     * </p>
2667     * <p>
2668     * If a raw contact has data rows, the RawContactsEntity cursor will contain
2669     * a one row for each data row. If the raw contact has no data rows, the
2670     * cursor will still contain one row with the raw contact-level information
2671     * and nulls for data columns.
2672     *
2673     * <pre>
2674     * Uri entityUri = ContentUris.withAppendedId(RawContactsEntity.CONTENT_URI, rawContactId);
2675     * Cursor c = getContentResolver().query(entityUri,
2676     *          new String[]{
2677     *              RawContactsEntity.SOURCE_ID,
2678     *              RawContactsEntity.DATA_ID,
2679     *              RawContactsEntity.MIMETYPE,
2680     *              RawContactsEntity.DATA1
2681     *          }, null, null, null);
2682     * try {
2683     *     while (c.moveToNext()) {
2684     *         String sourceId = c.getString(0);
2685     *         if (!c.isNull(1)) {
2686     *             String mimeType = c.getString(2);
2687     *             String data = c.getString(3);
2688     *             ...
2689     *         }
2690     *     }
2691     * } finally {
2692     *     c.close();
2693     * }
2694     * </pre>
2695     *
2696     * <h3>Columns</h3>
2697     * RawContactsEntity has a combination of RawContact and Data columns.
2698     *
2699     * <table class="jd-sumtable">
2700     * <tr>
2701     * <th colspan='4'>RawContacts</th>
2702     * </tr>
2703     * <tr>
2704     * <td style="width: 7em;">long</td>
2705     * <td style="width: 20em;">{@link #_ID}</td>
2706     * <td style="width: 5em;">read-only</td>
2707     * <td>Raw contact row ID. See {@link RawContacts}.</td>
2708     * </tr>
2709     * <tr>
2710     * <td>long</td>
2711     * <td>{@link #CONTACT_ID}</td>
2712     * <td>read-only</td>
2713     * <td>See {@link RawContacts}.</td>
2714     * </tr>
2715     * <tr>
2716     * <td>int</td>
2717     * <td>{@link #AGGREGATION_MODE}</td>
2718     * <td>read-only</td>
2719     * <td>See {@link RawContacts}.</td>
2720     * </tr>
2721     * <tr>
2722     * <td>int</td>
2723     * <td>{@link #DELETED}</td>
2724     * <td>read-only</td>
2725     * <td>See {@link RawContacts}.</td>
2726     * </tr>
2727     * </table>
2728     *
2729     * <table class="jd-sumtable">
2730     * <tr>
2731     * <th colspan='4'>Data</th>
2732     * </tr>
2733     * <tr>
2734     * <td style="width: 7em;">long</td>
2735     * <td style="width: 20em;">{@link #DATA_ID}</td>
2736     * <td style="width: 5em;">read-only</td>
2737     * <td>Data row ID. It will be null if the raw contact has no data rows.</td>
2738     * </tr>
2739     * <tr>
2740     * <td>String</td>
2741     * <td>{@link #MIMETYPE}</td>
2742     * <td>read-only</td>
2743     * <td>See {@link ContactsContract.Data}.</td>
2744     * </tr>
2745     * <tr>
2746     * <td>int</td>
2747     * <td>{@link #IS_PRIMARY}</td>
2748     * <td>read-only</td>
2749     * <td>See {@link ContactsContract.Data}.</td>
2750     * </tr>
2751     * <tr>
2752     * <td>int</td>
2753     * <td>{@link #IS_SUPER_PRIMARY}</td>
2754     * <td>read-only</td>
2755     * <td>See {@link ContactsContract.Data}.</td>
2756     * </tr>
2757     * <tr>
2758     * <td>int</td>
2759     * <td>{@link #DATA_VERSION}</td>
2760     * <td>read-only</td>
2761     * <td>See {@link ContactsContract.Data}.</td>
2762     * </tr>
2763     * <tr>
2764     * <td>Any type</td>
2765     * <td>
2766     * {@link #DATA1}<br>
2767     * {@link #DATA2}<br>
2768     * {@link #DATA3}<br>
2769     * {@link #DATA4}<br>
2770     * {@link #DATA5}<br>
2771     * {@link #DATA6}<br>
2772     * {@link #DATA7}<br>
2773     * {@link #DATA8}<br>
2774     * {@link #DATA9}<br>
2775     * {@link #DATA10}<br>
2776     * {@link #DATA11}<br>
2777     * {@link #DATA12}<br>
2778     * {@link #DATA13}<br>
2779     * {@link #DATA14}<br>
2780     * {@link #DATA15}
2781     * </td>
2782     * <td>read-only</td>
2783     * <td>See {@link ContactsContract.Data}.</td>
2784     * </tr>
2785     * <tr>
2786     * <td>Any type</td>
2787     * <td>
2788     * {@link #SYNC1}<br>
2789     * {@link #SYNC2}<br>
2790     * {@link #SYNC3}<br>
2791     * {@link #SYNC4}
2792     * </td>
2793     * <td>read-only</td>
2794     * <td>See {@link ContactsContract.Data}.</td>
2795     * </tr>
2796     * </table>
2797     */
2798    public final static class RawContactsEntity
2799            implements BaseColumns, DataColumns, RawContactsColumns {
2800        /**
2801         * This utility class cannot be instantiated
2802         */
2803        private RawContactsEntity() {}
2804
2805        /**
2806         * The content:// style URI for this table
2807         */
2808        public static final Uri CONTENT_URI =
2809                Uri.withAppendedPath(AUTHORITY_URI, "raw_contact_entities");
2810
2811        /**
2812         * The MIME type of {@link #CONTENT_URI} providing a directory of raw contact entities.
2813         */
2814        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact_entity";
2815
2816        /**
2817         * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward
2818         * Data.CONTENT_URI contains only exportable data.
2819         *
2820         * This flag is useful (currently) only for vCard exporter in Contacts app, which
2821         * needs to exclude "un-exportable" data from available data to export, while
2822         * Contacts app itself has priviledge to access all data including "un-expotable"
2823         * ones and providers return all of them regardless of the callers' intention.
2824         * <P>Type: INTEGER</p>
2825         *
2826         * @hide Maybe available only in Eclair and not really ready for public use.
2827         * TODO: remove, or implement this feature completely. As of now (Eclair),
2828         * we only use this flag in queryEntities(), not query().
2829         */
2830        public static final String FOR_EXPORT_ONLY = "for_export_only";
2831
2832        /**
2833         * The ID of the data column. The value will be null if this raw contact has no data rows.
2834         * <P>Type: INTEGER</P>
2835         */
2836        public static final String DATA_ID = "data_id";
2837    }
2838
2839    /**
2840     * @see PhoneLookup
2841     */
2842    protected interface PhoneLookupColumns {
2843        /**
2844         * The phone number as the user entered it.
2845         * <P>Type: TEXT</P>
2846         */
2847        public static final String NUMBER = "number";
2848
2849        /**
2850         * The type of phone number, for example Home or Work.
2851         * <P>Type: INTEGER</P>
2852         */
2853        public static final String TYPE = "type";
2854
2855        /**
2856         * The user defined label for the phone number.
2857         * <P>Type: TEXT</P>
2858         */
2859        public static final String LABEL = "label";
2860    }
2861
2862    /**
2863     * A table that represents the result of looking up a phone number, for
2864     * example for caller ID. To perform a lookup you must append the number you
2865     * want to find to {@link #CONTENT_FILTER_URI}.  This query is highly
2866     * optimized.
2867     * <pre>
2868     * Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
2869     * resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...
2870     * </pre>
2871     *
2872     * <h3>Columns</h3>
2873     *
2874     * <table class="jd-sumtable">
2875     * <tr>
2876     * <th colspan='4'>PhoneLookup</th>
2877     * </tr>
2878     * <tr>
2879     * <td>long</td>
2880     * <td>{@link #_ID}</td>
2881     * <td>read-only</td>
2882     * <td>Data row ID.</td>
2883     * </tr>
2884     * <tr>
2885     * <td>String</td>
2886     * <td>{@link #NUMBER}</td>
2887     * <td>read-only</td>
2888     * <td>Phone number.</td>
2889     * </tr>
2890     * <tr>
2891     * <td>String</td>
2892     * <td>{@link #TYPE}</td>
2893     * <td>read-only</td>
2894     * <td>Phone number type. See {@link CommonDataKinds.Phone}.</td>
2895     * </tr>
2896     * <tr>
2897     * <td>String</td>
2898     * <td>{@link #LABEL}</td>
2899     * <td>read-only</td>
2900     * <td>Custom label for the phone number. See {@link CommonDataKinds.Phone}.</td>
2901     * </tr>
2902     * </table>
2903     * <p>
2904     * Columns from the Contacts table are also available through a join.
2905     * </p>
2906     * <table class="jd-sumtable">
2907     * <tr>
2908     * <th colspan='4'>Join with {@link Contacts}</th>
2909     * </tr>
2910     * <tr>
2911     * <td>String</td>
2912     * <td>{@link #LOOKUP_KEY}</td>
2913     * <td>read-only</td>
2914     * <td>See {@link ContactsContract.Contacts}</td>
2915     * </tr>
2916     * <tr>
2917     * <td>String</td>
2918     * <td>{@link #DISPLAY_NAME}</td>
2919     * <td>read-only</td>
2920     * <td>See {@link ContactsContract.Contacts}</td>
2921     * </tr>
2922     * <tr>
2923     * <td>long</td>
2924     * <td>{@link #PHOTO_ID}</td>
2925     * <td>read-only</td>
2926     * <td>See {@link ContactsContract.Contacts}.</td>
2927     * </tr>
2928     * <tr>
2929     * <td>int</td>
2930     * <td>{@link #IN_VISIBLE_GROUP}</td>
2931     * <td>read-only</td>
2932     * <td>See {@link ContactsContract.Contacts}.</td>
2933     * </tr>
2934     * <tr>
2935     * <td>int</td>
2936     * <td>{@link #HAS_PHONE_NUMBER}</td>
2937     * <td>read-only</td>
2938     * <td>See {@link ContactsContract.Contacts}.</td>
2939     * </tr>
2940     * <tr>
2941     * <td>int</td>
2942     * <td>{@link #TIMES_CONTACTED}</td>
2943     * <td>read-only</td>
2944     * <td>See {@link ContactsContract.Contacts}.</td>
2945     * </tr>
2946     * <tr>
2947     * <td>long</td>
2948     * <td>{@link #LAST_TIME_CONTACTED}</td>
2949     * <td>read-only</td>
2950     * <td>See {@link ContactsContract.Contacts}.</td>
2951     * </tr>
2952     * <tr>
2953     * <td>int</td>
2954     * <td>{@link #STARRED}</td>
2955     * <td>read-only</td>
2956     * <td>See {@link ContactsContract.Contacts}.</td>
2957     * </tr>
2958     * <tr>
2959     * <td>String</td>
2960     * <td>{@link #CUSTOM_RINGTONE}</td>
2961     * <td>read-only</td>
2962     * <td>See {@link ContactsContract.Contacts}.</td>
2963     * </tr>
2964     * <tr>
2965     * <td>int</td>
2966     * <td>{@link #SEND_TO_VOICEMAIL}</td>
2967     * <td>read-only</td>
2968     * <td>See {@link ContactsContract.Contacts}.</td>
2969     * </tr>
2970     * </table>
2971     */
2972    public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns,
2973            ContactsColumns, ContactOptionsColumns {
2974        /**
2975         * This utility class cannot be instantiated
2976         */
2977        private PhoneLookup() {}
2978
2979        /**
2980         * The content:// style URI for this table. Append the phone number you want to lookup
2981         * to this URI and query it to perform a lookup. For example:
2982         * <pre>
2983         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, Uri.encode(phoneNumber));
2984         * </pre>
2985         */
2986        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
2987                "phone_lookup");
2988
2989        /**
2990         * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows.
2991         *
2992         * @hide
2993         */
2994        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup";
2995    }
2996
2997    /**
2998     * Additional data mixed in with {@link StatusColumns} to link
2999     * back to specific {@link ContactsContract.Data#_ID} entries.
3000     *
3001     * @see StatusUpdates
3002     */
3003    protected interface PresenceColumns {
3004
3005        /**
3006         * Reference to the {@link Data#_ID} entry that owns this presence.
3007         * <P>Type: INTEGER</P>
3008         */
3009        public static final String DATA_ID = "presence_data_id";
3010
3011        /**
3012         * See {@link CommonDataKinds.Im} for a list of defined protocol constants.
3013         * <p>Type: NUMBER</p>
3014         */
3015        public static final String PROTOCOL = "protocol";
3016
3017        /**
3018         * Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
3019         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
3020         * omitted if {@link #PROTOCOL} value is not
3021         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.
3022         *
3023         * <p>Type: NUMBER</p>
3024         */
3025        public static final String CUSTOM_PROTOCOL = "custom_protocol";
3026
3027        /**
3028         * The IM handle the presence item is for. The handle is scoped to
3029         * {@link #PROTOCOL}.
3030         * <P>Type: TEXT</P>
3031         */
3032        public static final String IM_HANDLE = "im_handle";
3033
3034        /**
3035         * The IM account for the local user that the presence data came from.
3036         * <P>Type: TEXT</P>
3037         */
3038        public static final String IM_ACCOUNT = "im_account";
3039    }
3040
3041    /**
3042     * <p>
3043     * A status update is linked to a {@link ContactsContract.Data} row and captures
3044     * the user's latest status update via the corresponding source, e.g.
3045     * "Having lunch" via "Google Talk".
3046     * </p>
3047     * <p>
3048     * There are two ways a status update can be inserted: by explicitly linking
3049     * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row
3050     * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
3051     * {@link #IM_HANDLE}.  There is no difference between insert and update, you can use
3052     * either.
3053     * </p>
3054     * <p>
3055     * You cannot use {@link ContentResolver#update} to change a status, but
3056     * {@link ContentResolver#insert} will replace the latests status if it already
3057     * exists.
3058     * </p>
3059     * <p>
3060     * Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses
3061     * for multiple contacts at once.
3062     * </p>
3063     *
3064     * <h3>Columns</h3>
3065     * <table class="jd-sumtable">
3066     * <tr>
3067     * <th colspan='4'>StatusUpdates</th>
3068     * </tr>
3069     * <tr>
3070     * <td>long</td>
3071     * <td>{@link #DATA_ID}</td>
3072     * <td>read/write</td>
3073     * <td>Reference to the {@link Data#_ID} entry that owns this presence. If this
3074     * field is <i>not</i> specified, the provider will attempt to find a data row
3075     * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
3076     * {@link #IM_HANDLE} columns.
3077     * </td>
3078     * </tr>
3079     * <tr>
3080     * <td>long</td>
3081     * <td>{@link #PROTOCOL}</td>
3082     * <td>read/write</td>
3083     * <td>See {@link CommonDataKinds.Im} for a list of defined protocol constants.</td>
3084     * </tr>
3085     * <tr>
3086     * <td>String</td>
3087     * <td>{@link #CUSTOM_PROTOCOL}</td>
3088     * <td>read/write</td>
3089     * <td>Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
3090     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
3091     * omitted if {@link #PROTOCOL} value is not
3092     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.</td>
3093     * </tr>
3094     * <tr>
3095     * <td>String</td>
3096     * <td>{@link #IM_HANDLE}</td>
3097     * <td>read/write</td>
3098     * <td> The IM handle the presence item is for. The handle is scoped to
3099     * {@link #PROTOCOL}.</td>
3100     * </tr>
3101     * <tr>
3102     * <td>String</td>
3103     * <td>{@link #IM_ACCOUNT}</td>
3104     * <td>read/write</td>
3105     * <td>The IM account for the local user that the presence data came from.</td>
3106     * </tr>
3107     * <tr>
3108     * <td>int</td>
3109     * <td>{@link #PRESENCE}</td>
3110     * <td>read/write</td>
3111     * <td>Contact IM presence status. The allowed values are:
3112     * <p>
3113     * <ul>
3114     * <li>{@link #OFFLINE}</li>
3115     * <li>{@link #INVISIBLE}</li>
3116     * <li>{@link #AWAY}</li>
3117     * <li>{@link #IDLE}</li>
3118     * <li>{@link #DO_NOT_DISTURB}</li>
3119     * <li>{@link #AVAILABLE}</li>
3120     * </ul>
3121     * </p>
3122     * <p>
3123     * Since presence status is inherently volatile, the content provider
3124     * may choose not to store this field in long-term storage.
3125     * </p>
3126     * </td>
3127     * </tr>
3128     * <tr>
3129     * <td>int</td>
3130     * <td>{@link #CHAT_CAPABILITY}</td>
3131     * <td>read/write</td>
3132     * <td>Contact IM chat compatibility value. The allowed values are:
3133     * <p>
3134     * <ul>
3135     * <li>{@link #CAPABILITY_HAS_VIDEO_PLAYBACK_ONLY}</li>
3136     * <li>{@link #CAPABILITY_HAS_VOICE}</li>
3137     * <li>{@link #CAPABILITY_HAS_CAMERA}</li>
3138     * </ul>
3139     * </p>
3140     * <p>
3141     * Since chat compatibility is inherently volatile as the contact's availability moves from
3142     * one device to another, the content provider may choose not to store this field in long-term
3143     * storage.
3144     * </p>
3145     * </td>
3146     * </tr>
3147     * <tr>
3148     * <td>String</td>
3149     * <td>{@link #STATUS}</td>
3150     * <td>read/write</td>
3151     * <td>Contact's latest status update, e.g. "having toast for breakfast"</td>
3152     * </tr>
3153     * <tr>
3154     * <td>long</td>
3155     * <td>{@link #STATUS_TIMESTAMP}</td>
3156     * <td>read/write</td>
3157     * <td>The absolute time in milliseconds when the status was
3158     * entered by the user. If this value is not provided, the provider will follow
3159     * this logic: if there was no prior status update, the value will be left as null.
3160     * If there was a prior status update, the provider will default this field
3161     * to the current time.</td>
3162     * </tr>
3163     * <tr>
3164     * <td>String</td>
3165     * <td>{@link #STATUS_RES_PACKAGE}</td>
3166     * <td>read/write</td>
3167     * <td> The package containing resources for this status: label and icon.</td>
3168     * </tr>
3169     * <tr>
3170     * <td>long</td>
3171     * <td>{@link #STATUS_LABEL}</td>
3172     * <td>read/write</td>
3173     * <td>The resource ID of the label describing the source of contact status,
3174     * e.g. "Google Talk". This resource is scoped by the
3175     * {@link #STATUS_RES_PACKAGE}.</td>
3176     * </tr>
3177     * <tr>
3178     * <td>long</td>
3179     * <td>{@link #STATUS_ICON}</td>
3180     * <td>read/write</td>
3181     * <td>The resource ID of the icon for the source of contact status. This
3182     * resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
3183     * </tr>
3184     * </table>
3185     */
3186    public static class StatusUpdates implements StatusColumns, PresenceColumns {
3187
3188        /**
3189         * This utility class cannot be instantiated
3190         */
3191        private StatusUpdates() {}
3192
3193        /**
3194         * The content:// style URI for this table
3195         */
3196        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates");
3197
3198        /**
3199         * Gets the resource ID for the proper presence icon.
3200         *
3201         * @param status the status to get the icon for
3202         * @return the resource ID for the proper presence icon
3203         */
3204        public static final int getPresenceIconResourceId(int status) {
3205            switch (status) {
3206                case AVAILABLE:
3207                    return android.R.drawable.presence_online;
3208                case IDLE:
3209                case AWAY:
3210                    return android.R.drawable.presence_away;
3211                case DO_NOT_DISTURB:
3212                    return android.R.drawable.presence_busy;
3213                case INVISIBLE:
3214                    return android.R.drawable.presence_invisible;
3215                case OFFLINE:
3216                default:
3217                    return android.R.drawable.presence_offline;
3218            }
3219        }
3220
3221        /**
3222         * Returns the precedence of the status code the higher number being the higher precedence.
3223         *
3224         * @param status The status code.
3225         * @return An integer representing the precedence, 0 being the lowest.
3226         */
3227        public static final int getPresencePrecedence(int status) {
3228            // Keep this function here incase we want to enforce a different precedence than the
3229            // natural order of the status constants.
3230            return status;
3231        }
3232
3233        /**
3234         * The MIME type of {@link #CONTENT_URI} providing a directory of
3235         * status update details.
3236         */
3237        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/status-update";
3238
3239        /**
3240         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
3241         * status update detail.
3242         */
3243        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update";
3244    }
3245
3246    /**
3247     * @deprecated This old name was never meant to be made public. Do not use.
3248     */
3249    @Deprecated
3250    public static final class Presence extends StatusUpdates {
3251
3252    }
3253
3254    /**
3255     * Additional columns returned by the {@link Contacts#CONTENT_FILTER_URI} providing the
3256     * explanation of why the filter matched the contact.  Specifically, they contain the
3257     * data type and element that was used for matching.
3258     * <p>
3259     * This is temporary API, it will need to change when we move to FTS.
3260     *
3261     * @hide
3262     */
3263    public static class SearchSnippetColumns {
3264
3265        /**
3266         * The ID of the data row that was matched by the filter.
3267         *
3268         * @hide
3269         */
3270        public static final String SNIPPET_DATA_ID = "snippet_data_id";
3271
3272        /**
3273         * The type of data that was matched by the filter.
3274         *
3275         * @hide
3276         */
3277        public static final String SNIPPET_MIMETYPE = "snippet_mimetype";
3278
3279        /**
3280         * The {@link Data#DATA1} field of the data row that was matched by the filter.
3281         *
3282         * @hide
3283         */
3284        public static final String SNIPPET_DATA1 = "snippet_data1";
3285
3286        /**
3287         * The {@link Data#DATA2} field of the data row that was matched by the filter.
3288         *
3289         * @hide
3290         */
3291        public static final String SNIPPET_DATA2 = "snippet_data2";
3292
3293        /**
3294         * The {@link Data#DATA3} field of the data row that was matched by the filter.
3295         *
3296         * @hide
3297         */
3298        public static final String SNIPPET_DATA3 = "snippet_data3";
3299
3300        /**
3301         * The {@link Data#DATA4} field of the data row that was matched by the filter.
3302         *
3303         * @hide
3304         */
3305        public static final String SNIPPET_DATA4 = "snippet_data4";
3306
3307    }
3308
3309    /**
3310     * Container for definitions of common data types stored in the {@link ContactsContract.Data}
3311     * table.
3312     */
3313    public static final class CommonDataKinds {
3314        /**
3315         * This utility class cannot be instantiated
3316         */
3317        private CommonDataKinds() {}
3318
3319        /**
3320         * The {@link Data#RES_PACKAGE} value for common data that should be
3321         * shown using a default style.
3322         *
3323         * @hide RES_PACKAGE is hidden
3324         */
3325        public static final String PACKAGE_COMMON = "common";
3326
3327        /**
3328         * The base types that all "Typed" data kinds support.
3329         */
3330        public interface BaseTypes {
3331            /**
3332             * A custom type. The custom label should be supplied by user.
3333             */
3334            public static int TYPE_CUSTOM = 0;
3335        }
3336
3337        /**
3338         * Columns common across the specific types.
3339         */
3340        protected interface CommonColumns extends BaseTypes {
3341            /**
3342             * The data for the contact method.
3343             * <P>Type: TEXT</P>
3344             */
3345            public static final String DATA = DataColumns.DATA1;
3346
3347            /**
3348             * The type of data, for example Home or Work.
3349             * <P>Type: INTEGER</P>
3350             */
3351            public static final String TYPE = DataColumns.DATA2;
3352
3353            /**
3354             * The user defined label for the the contact method.
3355             * <P>Type: TEXT</P>
3356             */
3357            public static final String LABEL = DataColumns.DATA3;
3358        }
3359
3360        /**
3361         * A data kind representing the contact's proper name. You can use all
3362         * columns defined for {@link ContactsContract.Data} as well as the following aliases.
3363         *
3364         * <h2>Column aliases</h2>
3365         * <table class="jd-sumtable">
3366         * <tr>
3367         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
3368         * </tr>
3369         * <tr>
3370         * <td>String</td>
3371         * <td>{@link #DISPLAY_NAME}</td>
3372         * <td>{@link #DATA1}</td>
3373         * <td></td>
3374         * </tr>
3375         * <tr>
3376         * <td>String</td>
3377         * <td>{@link #GIVEN_NAME}</td>
3378         * <td>{@link #DATA2}</td>
3379         * <td></td>
3380         * </tr>
3381         * <tr>
3382         * <td>String</td>
3383         * <td>{@link #FAMILY_NAME}</td>
3384         * <td>{@link #DATA3}</td>
3385         * <td></td>
3386         * </tr>
3387         * <tr>
3388         * <td>String</td>
3389         * <td>{@link #PREFIX}</td>
3390         * <td>{@link #DATA4}</td>
3391         * <td>Common prefixes in English names are "Mr", "Ms", "Dr" etc.</td>
3392         * </tr>
3393         * <tr>
3394         * <td>String</td>
3395         * <td>{@link #MIDDLE_NAME}</td>
3396         * <td>{@link #DATA5}</td>
3397         * <td></td>
3398         * </tr>
3399         * <tr>
3400         * <td>String</td>
3401         * <td>{@link #SUFFIX}</td>
3402         * <td>{@link #DATA6}</td>
3403         * <td>Common suffixes in English names are "Sr", "Jr", "III" etc.</td>
3404         * </tr>
3405         * <tr>
3406         * <td>String</td>
3407         * <td>{@link #PHONETIC_GIVEN_NAME}</td>
3408         * <td>{@link #DATA7}</td>
3409         * <td>Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana</td>
3410         * </tr>
3411         * <tr>
3412         * <td>String</td>
3413         * <td>{@link #PHONETIC_MIDDLE_NAME}</td>
3414         * <td>{@link #DATA8}</td>
3415         * <td></td>
3416         * </tr>
3417         * <tr>
3418         * <td>String</td>
3419         * <td>{@link #PHONETIC_FAMILY_NAME}</td>
3420         * <td>{@link #DATA9}</td>
3421         * <td></td>
3422         * </tr>
3423         * </table>
3424         */
3425        public static final class StructuredName implements DataColumnsWithJoins {
3426            /**
3427             * This utility class cannot be instantiated
3428             */
3429            private StructuredName() {}
3430
3431            /** MIME type used when storing this in data table. */
3432            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
3433
3434            /**
3435             * The name that should be used to display the contact.
3436             * <i>Unstructured component of the name should be consistent with
3437             * its structured representation.</i>
3438             * <p>
3439             * Type: TEXT
3440             */
3441            public static final String DISPLAY_NAME = DATA1;
3442
3443            /**
3444             * The given name for the contact.
3445             * <P>Type: TEXT</P>
3446             */
3447            public static final String GIVEN_NAME = DATA2;
3448
3449            /**
3450             * The family name for the contact.
3451             * <P>Type: TEXT</P>
3452             */
3453            public static final String FAMILY_NAME = DATA3;
3454
3455            /**
3456             * The contact's honorific prefix, e.g. "Sir"
3457             * <P>Type: TEXT</P>
3458             */
3459            public static final String PREFIX = DATA4;
3460
3461            /**
3462             * The contact's middle name
3463             * <P>Type: TEXT</P>
3464             */
3465            public static final String MIDDLE_NAME = DATA5;
3466
3467            /**
3468             * The contact's honorific suffix, e.g. "Jr"
3469             */
3470            public static final String SUFFIX = DATA6;
3471
3472            /**
3473             * The phonetic version of the given name for the contact.
3474             * <P>Type: TEXT</P>
3475             */
3476            public static final String PHONETIC_GIVEN_NAME = DATA7;
3477
3478            /**
3479             * The phonetic version of the additional name for the contact.
3480             * <P>Type: TEXT</P>
3481             */
3482            public static final String PHONETIC_MIDDLE_NAME = DATA8;
3483
3484            /**
3485             * The phonetic version of the family name for the contact.
3486             * <P>Type: TEXT</P>
3487             */
3488            public static final String PHONETIC_FAMILY_NAME = DATA9;
3489
3490            /**
3491             * The style used for combining given/middle/family name into a full name.
3492             * See {@link ContactsContract.FullNameStyle}.
3493             *
3494             * @hide
3495             */
3496            public static final String FULL_NAME_STYLE = DATA10;
3497
3498            /**
3499             * The alphabet used for capturing the phonetic name.
3500             * See ContactsContract.PhoneticNameStyle.
3501             * @hide
3502             */
3503            public static final String PHONETIC_NAME_STYLE = DATA11;
3504        }
3505
3506        /**
3507         * <p>A data kind representing the contact's nickname. For example, for
3508         * Bob Parr ("Mr. Incredible"):
3509         * <pre>
3510         * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
3511         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
3512         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
3513         *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
3514         *          .withValue(StructuredName.DISPLAY_NAME, &quot;Bob Parr&quot;)
3515         *          .build());
3516         *
3517         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
3518         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
3519         *          .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
3520         *          .withValue(Nickname.NAME, "Mr. Incredible")
3521         *          .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM)
3522         *          .withValue(Nickname.LABEL, "Superhero")
3523         *          .build());
3524         *
3525         * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
3526         * </pre>
3527         * </p>
3528         * <p>
3529         * You can use all columns defined for {@link ContactsContract.Data} as well as the
3530         * following aliases.
3531         * </p>
3532         *
3533         * <h2>Column aliases</h2>
3534         * <table class="jd-sumtable">
3535         * <tr>
3536         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
3537         * </tr>
3538         * <tr>
3539         * <td>String</td>
3540         * <td>{@link #NAME}</td>
3541         * <td>{@link #DATA1}</td>
3542         * <td></td>
3543         * </tr>
3544         * <tr>
3545         * <td>int</td>
3546         * <td>{@link #TYPE}</td>
3547         * <td>{@link #DATA2}</td>
3548         * <td>
3549         * Allowed values are:
3550         * <p>
3551         * <ul>
3552         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
3553         * <li>{@link #TYPE_DEFAULT}</li>
3554         * <li>{@link #TYPE_OTHER_NAME}</li>
3555         * <li>{@link #TYPE_MAIDEN_NAME}</li>
3556         * <li>{@link #TYPE_SHORT_NAME}</li>
3557         * <li>{@link #TYPE_INITIALS}</li>
3558         * </ul>
3559         * </p>
3560         * </td>
3561         * </tr>
3562         * <tr>
3563         * <td>String</td>
3564         * <td>{@link #LABEL}</td>
3565         * <td>{@link #DATA3}</td>
3566         * <td></td>
3567         * </tr>
3568         * </table>
3569         */
3570        public static final class Nickname implements DataColumnsWithJoins, CommonColumns {
3571            /**
3572             * This utility class cannot be instantiated
3573             */
3574            private Nickname() {}
3575
3576            /** MIME type used when storing this in data table. */
3577            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
3578
3579            public static final int TYPE_DEFAULT = 1;
3580            public static final int TYPE_OTHER_NAME = 2;
3581            public static final int TYPE_MAIDEN_NAME = 3;
3582            /** @deprecated Use TYPE_MAIDEN_NAME instead. */
3583            @Deprecated
3584            public static final int TYPE_MAINDEN_NAME = 3;
3585            public static final int TYPE_SHORT_NAME = 4;
3586            public static final int TYPE_INITIALS = 5;
3587
3588            /**
3589             * The name itself
3590             */
3591            public static final String NAME = DATA;
3592        }
3593
3594        /**
3595         * <p>
3596         * A data kind representing a telephone number.
3597         * </p>
3598         * <p>
3599         * You can use all columns defined for {@link ContactsContract.Data} as
3600         * well as the following aliases.
3601         * </p>
3602         * <h2>Column aliases</h2>
3603         * <table class="jd-sumtable">
3604         * <tr>
3605         * <th>Type</th>
3606         * <th>Alias</th><th colspan='2'>Data column</th>
3607         * </tr>
3608         * <tr>
3609         * <td>String</td>
3610         * <td>{@link #NUMBER}</td>
3611         * <td>{@link #DATA1}</td>
3612         * <td></td>
3613         * </tr>
3614         * <tr>
3615         * <td>int</td>
3616         * <td>{@link #TYPE}</td>
3617         * <td>{@link #DATA2}</td>
3618         * <td>Allowed values are:
3619         * <p>
3620         * <ul>
3621         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
3622         * <li>{@link #TYPE_HOME}</li>
3623         * <li>{@link #TYPE_MOBILE}</li>
3624         * <li>{@link #TYPE_WORK}</li>
3625         * <li>{@link #TYPE_FAX_WORK}</li>
3626         * <li>{@link #TYPE_FAX_HOME}</li>
3627         * <li>{@link #TYPE_PAGER}</li>
3628         * <li>{@link #TYPE_OTHER}</li>
3629         * <li>{@link #TYPE_CALLBACK}</li>
3630         * <li>{@link #TYPE_CAR}</li>
3631         * <li>{@link #TYPE_COMPANY_MAIN}</li>
3632         * <li>{@link #TYPE_ISDN}</li>
3633         * <li>{@link #TYPE_MAIN}</li>
3634         * <li>{@link #TYPE_OTHER_FAX}</li>
3635         * <li>{@link #TYPE_RADIO}</li>
3636         * <li>{@link #TYPE_TELEX}</li>
3637         * <li>{@link #TYPE_TTY_TDD}</li>
3638         * <li>{@link #TYPE_WORK_MOBILE}</li>
3639         * <li>{@link #TYPE_WORK_PAGER}</li>
3640         * <li>{@link #TYPE_ASSISTANT}</li>
3641         * <li>{@link #TYPE_MMS}</li>
3642         * </ul>
3643         * </p>
3644         * </td>
3645         * </tr>
3646         * <tr>
3647         * <td>String</td>
3648         * <td>{@link #LABEL}</td>
3649         * <td>{@link #DATA3}</td>
3650         * <td></td>
3651         * </tr>
3652         * </table>
3653         */
3654        public static final class Phone implements DataColumnsWithJoins, CommonColumns {
3655            /**
3656             * This utility class cannot be instantiated
3657             */
3658            private Phone() {}
3659
3660            /** MIME type used when storing this in data table. */
3661            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2";
3662
3663            /**
3664             * The MIME type of {@link #CONTENT_URI} providing a directory of
3665             * phones.
3666             */
3667            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2";
3668
3669            /**
3670             * The content:// style URI for all data records of the
3671             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
3672             * associated raw contact and aggregate contact data.
3673             */
3674            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
3675                    "phones");
3676
3677            /**
3678             * The content:// style URL for phone lookup using a filter. The filter returns
3679             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
3680             * to display names as well as phone numbers. The filter argument should be passed
3681             * as an additional path segment after this URI.
3682             */
3683            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
3684                    "filter");
3685
3686            public static final int TYPE_HOME = 1;
3687            public static final int TYPE_MOBILE = 2;
3688            public static final int TYPE_WORK = 3;
3689            public static final int TYPE_FAX_WORK = 4;
3690            public static final int TYPE_FAX_HOME = 5;
3691            public static final int TYPE_PAGER = 6;
3692            public static final int TYPE_OTHER = 7;
3693            public static final int TYPE_CALLBACK = 8;
3694            public static final int TYPE_CAR = 9;
3695            public static final int TYPE_COMPANY_MAIN = 10;
3696            public static final int TYPE_ISDN = 11;
3697            public static final int TYPE_MAIN = 12;
3698            public static final int TYPE_OTHER_FAX = 13;
3699            public static final int TYPE_RADIO = 14;
3700            public static final int TYPE_TELEX = 15;
3701            public static final int TYPE_TTY_TDD = 16;
3702            public static final int TYPE_WORK_MOBILE = 17;
3703            public static final int TYPE_WORK_PAGER = 18;
3704            public static final int TYPE_ASSISTANT = 19;
3705            public static final int TYPE_MMS = 20;
3706
3707            /**
3708             * The phone number as the user entered it.
3709             * <P>Type: TEXT</P>
3710             */
3711            public static final String NUMBER = DATA;
3712
3713            /**
3714             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
3715             * @hide
3716             */
3717            @Deprecated
3718            public static final CharSequence getDisplayLabel(Context context, int type,
3719                    CharSequence label, CharSequence[] labelArray) {
3720                return getTypeLabel(context.getResources(), type, label);
3721            }
3722
3723            /**
3724             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
3725             * @hide
3726             */
3727            @Deprecated
3728            public static final CharSequence getDisplayLabel(Context context, int type,
3729                    CharSequence label) {
3730                return getTypeLabel(context.getResources(), type, label);
3731            }
3732
3733            /**
3734             * Return the string resource that best describes the given
3735             * {@link #TYPE}. Will always return a valid resource.
3736             */
3737            public static final int getTypeLabelResource(int type) {
3738                switch (type) {
3739                    case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome;
3740                    case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile;
3741                    case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork;
3742                    case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork;
3743                    case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome;
3744                    case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager;
3745                    case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther;
3746                    case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback;
3747                    case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar;
3748                    case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain;
3749                    case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn;
3750                    case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain;
3751                    case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax;
3752                    case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio;
3753                    case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex;
3754                    case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd;
3755                    case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile;
3756                    case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager;
3757                    case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant;
3758                    case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms;
3759                    default: return com.android.internal.R.string.phoneTypeCustom;
3760                }
3761            }
3762
3763            /**
3764             * Return a {@link CharSequence} that best describes the given type,
3765             * possibly substituting the given {@link #LABEL} value
3766             * for {@link #TYPE_CUSTOM}.
3767             */
3768            public static final CharSequence getTypeLabel(Resources res, int type,
3769                    CharSequence label) {
3770                if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) {
3771                    return label;
3772                } else {
3773                    final int labelRes = getTypeLabelResource(type);
3774                    return res.getText(labelRes);
3775                }
3776            }
3777        }
3778
3779        /**
3780         * <p>
3781         * A data kind representing an email address.
3782         * </p>
3783         * <p>
3784         * You can use all columns defined for {@link ContactsContract.Data} as
3785         * well as the following aliases.
3786         * </p>
3787         * <h2>Column aliases</h2>
3788         * <table class="jd-sumtable">
3789         * <tr>
3790         * <th>Type</th>
3791         * <th>Alias</th><th colspan='2'>Data column</th>
3792         * </tr>
3793         * <tr>
3794         * <td>String</td>
3795         * <td>{@link #DATA}</td>
3796         * <td>{@link #DATA1}</td>
3797         * <td>Email address itself.</td>
3798         * </tr>
3799         * <tr>
3800         * <td>int</td>
3801         * <td>{@link #TYPE}</td>
3802         * <td>{@link #DATA2}</td>
3803         * <td>Allowed values are:
3804         * <p>
3805         * <ul>
3806         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
3807         * <li>{@link #TYPE_HOME}</li>
3808         * <li>{@link #TYPE_WORK}</li>
3809         * <li>{@link #TYPE_OTHER}</li>
3810         * <li>{@link #TYPE_MOBILE}</li>
3811         * </ul>
3812         * </p>
3813         * </td>
3814         * </tr>
3815         * <tr>
3816         * <td>String</td>
3817         * <td>{@link #LABEL}</td>
3818         * <td>{@link #DATA3}</td>
3819         * <td></td>
3820         * </tr>
3821         * </table>
3822         */
3823        public static final class Email implements DataColumnsWithJoins, CommonColumns {
3824            /**
3825             * This utility class cannot be instantiated
3826             */
3827            private Email() {}
3828
3829            /** MIME type used when storing this in data table. */
3830            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
3831
3832            /**
3833             * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses.
3834             */
3835            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";
3836
3837            /**
3838             * The content:// style URI for all data records of the
3839             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
3840             * associated raw contact and aggregate contact data.
3841             */
3842            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
3843                    "emails");
3844
3845            /**
3846             * <p>
3847             * The content:// style URL for looking up data rows by email address. The
3848             * lookup argument, an email address, should be passed as an additional path segment
3849             * after this URI.
3850             * </p>
3851             * <p>Example:
3852             * <pre>
3853             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email));
3854             * Cursor c = getContentResolver().query(uri,
3855             *          new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
3856             *          null, null, null);
3857             * </pre>
3858             * </p>
3859             */
3860            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
3861                    "lookup");
3862
3863            /**
3864             * <p>
3865             * The content:// style URL for email lookup using a filter. The filter returns
3866             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
3867             * to display names as well as email addresses. The filter argument should be passed
3868             * as an additional path segment after this URI.
3869             * </p>
3870             * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)"
3871             * as well as "Bob Parr (incredible@android.com)".
3872             * <pre>
3873             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
3874             * Cursor c = getContentResolver().query(uri,
3875             *          new String[]{Email.DISPLAY_NAME, Email.DATA},
3876             *          null, null, null);
3877             * </pre>
3878             * </p>
3879             */
3880            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
3881                    "filter");
3882
3883            /**
3884             * The email address.
3885             * <P>Type: TEXT</P>
3886             * @hide TODO: Unhide in a separate CL
3887             */
3888            public static final String ADDRESS = DATA1;
3889
3890            public static final int TYPE_HOME = 1;
3891            public static final int TYPE_WORK = 2;
3892            public static final int TYPE_OTHER = 3;
3893            public static final int TYPE_MOBILE = 4;
3894
3895            /**
3896             * The display name for the email address
3897             * <P>Type: TEXT</P>
3898             */
3899            public static final String DISPLAY_NAME = DATA4;
3900
3901            /**
3902             * Return the string resource that best describes the given
3903             * {@link #TYPE}. Will always return a valid resource.
3904             */
3905            public static final int getTypeLabelResource(int type) {
3906                switch (type) {
3907                    case TYPE_HOME: return com.android.internal.R.string.emailTypeHome;
3908                    case TYPE_WORK: return com.android.internal.R.string.emailTypeWork;
3909                    case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther;
3910                    case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile;
3911                    default: return com.android.internal.R.string.emailTypeCustom;
3912                }
3913            }
3914
3915            /**
3916             * Return a {@link CharSequence} that best describes the given type,
3917             * possibly substituting the given {@link #LABEL} value
3918             * for {@link #TYPE_CUSTOM}.
3919             */
3920            public static final CharSequence getTypeLabel(Resources res, int type,
3921                    CharSequence label) {
3922                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
3923                    return label;
3924                } else {
3925                    final int labelRes = getTypeLabelResource(type);
3926                    return res.getText(labelRes);
3927                }
3928            }
3929        }
3930
3931        /**
3932         * <p>
3933         * A data kind representing a postal addresses.
3934         * </p>
3935         * <p>
3936         * You can use all columns defined for {@link ContactsContract.Data} as
3937         * well as the following aliases.
3938         * </p>
3939         * <h2>Column aliases</h2>
3940         * <table class="jd-sumtable">
3941         * <tr>
3942         * <th>Type</th>
3943         * <th>Alias</th><th colspan='2'>Data column</th>
3944         * </tr>
3945         * <tr>
3946         * <td>String</td>
3947         * <td>{@link #FORMATTED_ADDRESS}</td>
3948         * <td>{@link #DATA1}</td>
3949         * <td></td>
3950         * </tr>
3951         * <tr>
3952         * <td>int</td>
3953         * <td>{@link #TYPE}</td>
3954         * <td>{@link #DATA2}</td>
3955         * <td>Allowed values are:
3956         * <p>
3957         * <ul>
3958         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
3959         * <li>{@link #TYPE_HOME}</li>
3960         * <li>{@link #TYPE_WORK}</li>
3961         * <li>{@link #TYPE_OTHER}</li>
3962         * </ul>
3963         * </p>
3964         * </td>
3965         * </tr>
3966         * <tr>
3967         * <td>String</td>
3968         * <td>{@link #LABEL}</td>
3969         * <td>{@link #DATA3}</td>
3970         * <td></td>
3971         * </tr>
3972         * <tr>
3973         * <td>String</td>
3974         * <td>{@link #STREET}</td>
3975         * <td>{@link #DATA4}</td>
3976         * <td></td>
3977         * </tr>
3978         * <tr>
3979         * <td>String</td>
3980         * <td>{@link #POBOX}</td>
3981         * <td>{@link #DATA5}</td>
3982         * <td>Post Office Box number</td>
3983         * </tr>
3984         * <tr>
3985         * <td>String</td>
3986         * <td>{@link #NEIGHBORHOOD}</td>
3987         * <td>{@link #DATA6}</td>
3988         * <td></td>
3989         * </tr>
3990         * <tr>
3991         * <td>String</td>
3992         * <td>{@link #CITY}</td>
3993         * <td>{@link #DATA7}</td>
3994         * <td></td>
3995         * </tr>
3996         * <tr>
3997         * <td>String</td>
3998         * <td>{@link #REGION}</td>
3999         * <td>{@link #DATA8}</td>
4000         * <td></td>
4001         * </tr>
4002         * <tr>
4003         * <td>String</td>
4004         * <td>{@link #POSTCODE}</td>
4005         * <td>{@link #DATA9}</td>
4006         * <td></td>
4007         * </tr>
4008         * <tr>
4009         * <td>String</td>
4010         * <td>{@link #COUNTRY}</td>
4011         * <td>{@link #DATA10}</td>
4012         * <td></td>
4013         * </tr>
4014         * </table>
4015         */
4016        public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns {
4017            /**
4018             * This utility class cannot be instantiated
4019             */
4020            private StructuredPostal() {
4021            }
4022
4023            /** MIME type used when storing this in data table. */
4024            public static final String CONTENT_ITEM_TYPE =
4025                    "vnd.android.cursor.item/postal-address_v2";
4026
4027            /**
4028             * The MIME type of {@link #CONTENT_URI} providing a directory of
4029             * postal addresses.
4030             */
4031            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
4032
4033            /**
4034             * The content:// style URI for all data records of the
4035             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
4036             */
4037            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
4038                    "postals");
4039
4040            public static final int TYPE_HOME = 1;
4041            public static final int TYPE_WORK = 2;
4042            public static final int TYPE_OTHER = 3;
4043
4044            /**
4045             * The full, unstructured postal address. <i>This field must be
4046             * consistent with any structured data.</i>
4047             * <p>
4048             * Type: TEXT
4049             */
4050            public static final String FORMATTED_ADDRESS = DATA;
4051
4052            /**
4053             * Can be street, avenue, road, etc. This element also includes the
4054             * house number and room/apartment/flat/floor number.
4055             * <p>
4056             * Type: TEXT
4057             */
4058            public static final String STREET = DATA4;
4059
4060            /**
4061             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
4062             * usually but not always mutually exclusive with street.
4063             * <p>
4064             * Type: TEXT
4065             */
4066            public static final String POBOX = DATA5;
4067
4068            /**
4069             * This is used to disambiguate a street address when a city
4070             * contains more than one street with the same name, or to specify a
4071             * small place whose mail is routed through a larger postal town. In
4072             * China it could be a county or a minor city.
4073             * <p>
4074             * Type: TEXT
4075             */
4076            public static final String NEIGHBORHOOD = DATA6;
4077
4078            /**
4079             * Can be city, village, town, borough, etc. This is the postal town
4080             * and not necessarily the place of residence or place of business.
4081             * <p>
4082             * Type: TEXT
4083             */
4084            public static final String CITY = DATA7;
4085
4086            /**
4087             * A state, province, county (in Ireland), Land (in Germany),
4088             * departement (in France), etc.
4089             * <p>
4090             * Type: TEXT
4091             */
4092            public static final String REGION = DATA8;
4093
4094            /**
4095             * Postal code. Usually country-wide, but sometimes specific to the
4096             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
4097             * <p>
4098             * Type: TEXT
4099             */
4100            public static final String POSTCODE = DATA9;
4101
4102            /**
4103             * The name or code of the country.
4104             * <p>
4105             * Type: TEXT
4106             */
4107            public static final String COUNTRY = DATA10;
4108
4109            /**
4110             * Return the string resource that best describes the given
4111             * {@link #TYPE}. Will always return a valid resource.
4112             */
4113            public static final int getTypeLabelResource(int type) {
4114                switch (type) {
4115                    case TYPE_HOME: return com.android.internal.R.string.postalTypeHome;
4116                    case TYPE_WORK: return com.android.internal.R.string.postalTypeWork;
4117                    case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther;
4118                    default: return com.android.internal.R.string.postalTypeCustom;
4119                }
4120            }
4121
4122            /**
4123             * Return a {@link CharSequence} that best describes the given type,
4124             * possibly substituting the given {@link #LABEL} value
4125             * for {@link #TYPE_CUSTOM}.
4126             */
4127            public static final CharSequence getTypeLabel(Resources res, int type,
4128                    CharSequence label) {
4129                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4130                    return label;
4131                } else {
4132                    final int labelRes = getTypeLabelResource(type);
4133                    return res.getText(labelRes);
4134                }
4135            }
4136        }
4137
4138        /**
4139         * <p>
4140         * A data kind representing an IM address
4141         * </p>
4142         * <p>
4143         * You can use all columns defined for {@link ContactsContract.Data} as
4144         * well as the following aliases.
4145         * </p>
4146         * <h2>Column aliases</h2>
4147         * <table class="jd-sumtable">
4148         * <tr>
4149         * <th>Type</th>
4150         * <th>Alias</th><th colspan='2'>Data column</th>
4151         * </tr>
4152         * <tr>
4153         * <td>String</td>
4154         * <td>{@link #DATA}</td>
4155         * <td>{@link #DATA1}</td>
4156         * <td></td>
4157         * </tr>
4158         * <tr>
4159         * <td>int</td>
4160         * <td>{@link #TYPE}</td>
4161         * <td>{@link #DATA2}</td>
4162         * <td>Allowed values are:
4163         * <p>
4164         * <ul>
4165         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4166         * <li>{@link #TYPE_HOME}</li>
4167         * <li>{@link #TYPE_WORK}</li>
4168         * <li>{@link #TYPE_OTHER}</li>
4169         * </ul>
4170         * </p>
4171         * </td>
4172         * </tr>
4173         * <tr>
4174         * <td>String</td>
4175         * <td>{@link #LABEL}</td>
4176         * <td>{@link #DATA3}</td>
4177         * <td></td>
4178         * </tr>
4179         * <tr>
4180         * <td>String</td>
4181         * <td>{@link #PROTOCOL}</td>
4182         * <td>{@link #DATA5}</td>
4183         * <td>
4184         * <p>
4185         * Allowed values:
4186         * <ul>
4187         * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name
4188         * as {@link #CUSTOM_PROTOCOL}.</li>
4189         * <li>{@link #PROTOCOL_AIM}</li>
4190         * <li>{@link #PROTOCOL_MSN}</li>
4191         * <li>{@link #PROTOCOL_YAHOO}</li>
4192         * <li>{@link #PROTOCOL_SKYPE}</li>
4193         * <li>{@link #PROTOCOL_QQ}</li>
4194         * <li>{@link #PROTOCOL_GOOGLE_TALK}</li>
4195         * <li>{@link #PROTOCOL_ICQ}</li>
4196         * <li>{@link #PROTOCOL_JABBER}</li>
4197         * <li>{@link #PROTOCOL_NETMEETING}</li>
4198         * </ul>
4199         * </p>
4200         * </td>
4201         * </tr>
4202         * <tr>
4203         * <td>String</td>
4204         * <td>{@link #CUSTOM_PROTOCOL}</td>
4205         * <td>{@link #DATA6}</td>
4206         * <td></td>
4207         * </tr>
4208         * </table>
4209         */
4210        public static final class Im implements DataColumnsWithJoins, CommonColumns {
4211            /**
4212             * This utility class cannot be instantiated
4213             */
4214            private Im() {}
4215
4216            /** MIME type used when storing this in data table. */
4217            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
4218
4219            public static final int TYPE_HOME = 1;
4220            public static final int TYPE_WORK = 2;
4221            public static final int TYPE_OTHER = 3;
4222
4223            /**
4224             * This column should be populated with one of the defined
4225             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
4226             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
4227             * should contain the name of the custom protocol.
4228             */
4229            public static final String PROTOCOL = DATA5;
4230
4231            public static final String CUSTOM_PROTOCOL = DATA6;
4232
4233            /*
4234             * The predefined IM protocol types.
4235             */
4236            public static final int PROTOCOL_CUSTOM = -1;
4237            public static final int PROTOCOL_AIM = 0;
4238            public static final int PROTOCOL_MSN = 1;
4239            public static final int PROTOCOL_YAHOO = 2;
4240            public static final int PROTOCOL_SKYPE = 3;
4241            public static final int PROTOCOL_QQ = 4;
4242            public static final int PROTOCOL_GOOGLE_TALK = 5;
4243            public static final int PROTOCOL_ICQ = 6;
4244            public static final int PROTOCOL_JABBER = 7;
4245            public static final int PROTOCOL_NETMEETING = 8;
4246
4247            /**
4248             * Return the string resource that best describes the given
4249             * {@link #TYPE}. Will always return a valid resource.
4250             */
4251            public static final int getTypeLabelResource(int type) {
4252                switch (type) {
4253                    case TYPE_HOME: return com.android.internal.R.string.imTypeHome;
4254                    case TYPE_WORK: return com.android.internal.R.string.imTypeWork;
4255                    case TYPE_OTHER: return com.android.internal.R.string.imTypeOther;
4256                    default: return com.android.internal.R.string.imTypeCustom;
4257                }
4258            }
4259
4260            /**
4261             * Return a {@link CharSequence} that best describes the given type,
4262             * possibly substituting the given {@link #LABEL} value
4263             * for {@link #TYPE_CUSTOM}.
4264             */
4265            public static final CharSequence getTypeLabel(Resources res, int type,
4266                    CharSequence label) {
4267                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4268                    return label;
4269                } else {
4270                    final int labelRes = getTypeLabelResource(type);
4271                    return res.getText(labelRes);
4272                }
4273            }
4274
4275            /**
4276             * Return the string resource that best describes the given
4277             * {@link #PROTOCOL}. Will always return a valid resource.
4278             */
4279            public static final int getProtocolLabelResource(int type) {
4280                switch (type) {
4281                    case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim;
4282                    case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn;
4283                    case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo;
4284                    case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype;
4285                    case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq;
4286                    case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk;
4287                    case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq;
4288                    case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber;
4289                    case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting;
4290                    default: return com.android.internal.R.string.imProtocolCustom;
4291                }
4292            }
4293
4294            /**
4295             * Return a {@link CharSequence} that best describes the given
4296             * protocol, possibly substituting the given
4297             * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}.
4298             */
4299            public static final CharSequence getProtocolLabel(Resources res, int type,
4300                    CharSequence label) {
4301                if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) {
4302                    return label;
4303                } else {
4304                    final int labelRes = getProtocolLabelResource(type);
4305                    return res.getText(labelRes);
4306                }
4307            }
4308        }
4309
4310        /**
4311         * <p>
4312         * A data kind representing an organization.
4313         * </p>
4314         * <p>
4315         * You can use all columns defined for {@link ContactsContract.Data} as
4316         * well as the following aliases.
4317         * </p>
4318         * <h2>Column aliases</h2>
4319         * <table class="jd-sumtable">
4320         * <tr>
4321         * <th>Type</th>
4322         * <th>Alias</th><th colspan='2'>Data column</th>
4323         * </tr>
4324         * <tr>
4325         * <td>String</td>
4326         * <td>{@link #COMPANY}</td>
4327         * <td>{@link #DATA1}</td>
4328         * <td></td>
4329         * </tr>
4330         * <tr>
4331         * <td>int</td>
4332         * <td>{@link #TYPE}</td>
4333         * <td>{@link #DATA2}</td>
4334         * <td>Allowed values are:
4335         * <p>
4336         * <ul>
4337         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4338         * <li>{@link #TYPE_WORK}</li>
4339         * <li>{@link #TYPE_OTHER}</li>
4340         * </ul>
4341         * </p>
4342         * </td>
4343         * </tr>
4344         * <tr>
4345         * <td>String</td>
4346         * <td>{@link #LABEL}</td>
4347         * <td>{@link #DATA3}</td>
4348         * <td></td>
4349         * </tr>
4350         * <tr>
4351         * <td>String</td>
4352         * <td>{@link #TITLE}</td>
4353         * <td>{@link #DATA4}</td>
4354         * <td></td>
4355         * </tr>
4356         * <tr>
4357         * <td>String</td>
4358         * <td>{@link #DEPARTMENT}</td>
4359         * <td>{@link #DATA5}</td>
4360         * <td></td>
4361         * </tr>
4362         * <tr>
4363         * <td>String</td>
4364         * <td>{@link #JOB_DESCRIPTION}</td>
4365         * <td>{@link #DATA6}</td>
4366         * <td></td>
4367         * </tr>
4368         * <tr>
4369         * <td>String</td>
4370         * <td>{@link #SYMBOL}</td>
4371         * <td>{@link #DATA7}</td>
4372         * <td></td>
4373         * </tr>
4374         * <tr>
4375         * <td>String</td>
4376         * <td>{@link #PHONETIC_NAME}</td>
4377         * <td>{@link #DATA8}</td>
4378         * <td></td>
4379         * </tr>
4380         * <tr>
4381         * <td>String</td>
4382         * <td>{@link #OFFICE_LOCATION}</td>
4383         * <td>{@link #DATA9}</td>
4384         * <td></td>
4385         * </tr>
4386         * <tr>
4387         * <td>String</td>
4388         * <td>PHONETIC_NAME_STYLE</td>
4389         * <td>{@link #DATA10}</td>
4390         * <td></td>
4391         * </tr>
4392         * </table>
4393         */
4394        public static final class Organization implements DataColumnsWithJoins, CommonColumns {
4395            /**
4396             * This utility class cannot be instantiated
4397             */
4398            private Organization() {}
4399
4400            /** MIME type used when storing this in data table. */
4401            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
4402
4403            public static final int TYPE_WORK = 1;
4404            public static final int TYPE_OTHER = 2;
4405
4406            /**
4407             * The company as the user entered it.
4408             * <P>Type: TEXT</P>
4409             */
4410            public static final String COMPANY = DATA;
4411
4412            /**
4413             * The position title at this company as the user entered it.
4414             * <P>Type: TEXT</P>
4415             */
4416            public static final String TITLE = DATA4;
4417
4418            /**
4419             * The department at this company as the user entered it.
4420             * <P>Type: TEXT</P>
4421             */
4422            public static final String DEPARTMENT = DATA5;
4423
4424            /**
4425             * The job description at this company as the user entered it.
4426             * <P>Type: TEXT</P>
4427             */
4428            public static final String JOB_DESCRIPTION = DATA6;
4429
4430            /**
4431             * The symbol of this company as the user entered it.
4432             * <P>Type: TEXT</P>
4433             */
4434            public static final String SYMBOL = DATA7;
4435
4436            /**
4437             * The phonetic name of this company as the user entered it.
4438             * <P>Type: TEXT</P>
4439             */
4440            public static final String PHONETIC_NAME = DATA8;
4441
4442            /**
4443             * The office location of this organization.
4444             * <P>Type: TEXT</P>
4445             */
4446            public static final String OFFICE_LOCATION = DATA9;
4447
4448            /**
4449             * The alphabet used for capturing the phonetic name.
4450             * See {@link ContactsContract.PhoneticNameStyle}.
4451             * @hide
4452             */
4453            public static final String PHONETIC_NAME_STYLE = DATA10;
4454
4455            /**
4456             * Return the string resource that best describes the given
4457             * {@link #TYPE}. Will always return a valid resource.
4458             */
4459            public static final int getTypeLabelResource(int type) {
4460                switch (type) {
4461                    case TYPE_WORK: return com.android.internal.R.string.orgTypeWork;
4462                    case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther;
4463                    default: return com.android.internal.R.string.orgTypeCustom;
4464                }
4465            }
4466
4467            /**
4468             * Return a {@link CharSequence} that best describes the given type,
4469             * possibly substituting the given {@link #LABEL} value
4470             * for {@link #TYPE_CUSTOM}.
4471             */
4472            public static final CharSequence getTypeLabel(Resources res, int type,
4473                    CharSequence label) {
4474                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4475                    return label;
4476                } else {
4477                    final int labelRes = getTypeLabelResource(type);
4478                    return res.getText(labelRes);
4479                }
4480            }
4481        }
4482
4483        /**
4484         * <p>
4485         * A data kind representing a relation.
4486         * </p>
4487         * <p>
4488         * You can use all columns defined for {@link ContactsContract.Data} as
4489         * well as the following aliases.
4490         * </p>
4491         * <h2>Column aliases</h2>
4492         * <table class="jd-sumtable">
4493         * <tr>
4494         * <th>Type</th>
4495         * <th>Alias</th><th colspan='2'>Data column</th>
4496         * </tr>
4497         * <tr>
4498         * <td>String</td>
4499         * <td>{@link #NAME}</td>
4500         * <td>{@link #DATA1}</td>
4501         * <td></td>
4502         * </tr>
4503         * <tr>
4504         * <td>int</td>
4505         * <td>{@link #TYPE}</td>
4506         * <td>{@link #DATA2}</td>
4507         * <td>Allowed values are:
4508         * <p>
4509         * <ul>
4510         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4511         * <li>{@link #TYPE_ASSISTANT}</li>
4512         * <li>{@link #TYPE_BROTHER}</li>
4513         * <li>{@link #TYPE_CHILD}</li>
4514         * <li>{@link #TYPE_DOMESTIC_PARTNER}</li>
4515         * <li>{@link #TYPE_FATHER}</li>
4516         * <li>{@link #TYPE_FRIEND}</li>
4517         * <li>{@link #TYPE_MANAGER}</li>
4518         * <li>{@link #TYPE_MOTHER}</li>
4519         * <li>{@link #TYPE_PARENT}</li>
4520         * <li>{@link #TYPE_PARTNER}</li>
4521         * <li>{@link #TYPE_REFERRED_BY}</li>
4522         * <li>{@link #TYPE_RELATIVE}</li>
4523         * <li>{@link #TYPE_SISTER}</li>
4524         * <li>{@link #TYPE_SPOUSE}</li>
4525         * </ul>
4526         * </p>
4527         * </td>
4528         * </tr>
4529         * <tr>
4530         * <td>String</td>
4531         * <td>{@link #LABEL}</td>
4532         * <td>{@link #DATA3}</td>
4533         * <td></td>
4534         * </tr>
4535         * </table>
4536         */
4537        public static final class Relation implements DataColumnsWithJoins, CommonColumns {
4538            /**
4539             * This utility class cannot be instantiated
4540             */
4541            private Relation() {}
4542
4543            /** MIME type used when storing this in data table. */
4544            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
4545
4546            public static final int TYPE_ASSISTANT = 1;
4547            public static final int TYPE_BROTHER = 2;
4548            public static final int TYPE_CHILD = 3;
4549            public static final int TYPE_DOMESTIC_PARTNER = 4;
4550            public static final int TYPE_FATHER = 5;
4551            public static final int TYPE_FRIEND = 6;
4552            public static final int TYPE_MANAGER = 7;
4553            public static final int TYPE_MOTHER = 8;
4554            public static final int TYPE_PARENT = 9;
4555            public static final int TYPE_PARTNER = 10;
4556            public static final int TYPE_REFERRED_BY = 11;
4557            public static final int TYPE_RELATIVE = 12;
4558            public static final int TYPE_SISTER = 13;
4559            public static final int TYPE_SPOUSE = 14;
4560
4561            /**
4562             * The name of the relative as the user entered it.
4563             * <P>Type: TEXT</P>
4564             */
4565            public static final String NAME = DATA;
4566        }
4567
4568        /**
4569         * <p>
4570         * A data kind representing an event.
4571         * </p>
4572         * <p>
4573         * You can use all columns defined for {@link ContactsContract.Data} as
4574         * well as the following aliases.
4575         * </p>
4576         * <h2>Column aliases</h2>
4577         * <table class="jd-sumtable">
4578         * <tr>
4579         * <th>Type</th>
4580         * <th>Alias</th><th colspan='2'>Data column</th>
4581         * </tr>
4582         * <tr>
4583         * <td>String</td>
4584         * <td>{@link #START_DATE}</td>
4585         * <td>{@link #DATA1}</td>
4586         * <td></td>
4587         * </tr>
4588         * <tr>
4589         * <td>int</td>
4590         * <td>{@link #TYPE}</td>
4591         * <td>{@link #DATA2}</td>
4592         * <td>Allowed values are:
4593         * <p>
4594         * <ul>
4595         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4596         * <li>{@link #TYPE_ANNIVERSARY}</li>
4597         * <li>{@link #TYPE_OTHER}</li>
4598         * <li>{@link #TYPE_BIRTHDAY}</li>
4599         * </ul>
4600         * </p>
4601         * </td>
4602         * </tr>
4603         * <tr>
4604         * <td>String</td>
4605         * <td>{@link #LABEL}</td>
4606         * <td>{@link #DATA3}</td>
4607         * <td></td>
4608         * </tr>
4609         * </table>
4610         */
4611        public static final class Event implements DataColumnsWithJoins, CommonColumns {
4612            /**
4613             * This utility class cannot be instantiated
4614             */
4615            private Event() {}
4616
4617            /** MIME type used when storing this in data table. */
4618            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event";
4619
4620            public static final int TYPE_ANNIVERSARY = 1;
4621            public static final int TYPE_OTHER = 2;
4622            public static final int TYPE_BIRTHDAY = 3;
4623
4624            /**
4625             * The event start date as the user entered it.
4626             * <P>Type: TEXT</P>
4627             */
4628            public static final String START_DATE = DATA;
4629
4630            /**
4631             * Return the string resource that best describes the given
4632             * {@link #TYPE}. Will always return a valid resource.
4633             */
4634            public static int getTypeResource(Integer type) {
4635                if (type == null) {
4636                    return com.android.internal.R.string.eventTypeOther;
4637                }
4638                switch (type) {
4639                    case TYPE_ANNIVERSARY:
4640                        return com.android.internal.R.string.eventTypeAnniversary;
4641                    case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday;
4642                    case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther;
4643                    default: return com.android.internal.R.string.eventTypeOther;
4644                }
4645            }
4646        }
4647
4648        /**
4649         * <p>
4650         * A data kind representing an photo for the contact.
4651         * </p>
4652         * <p>
4653         * Some sync adapters will choose to download photos in a separate
4654         * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1}
4655         * through {@link ContactsContract.Data#SYNC4} to store temporary
4656         * data, e.g. the image URL or ID, state of download, server-side version
4657         * of the image.  It is allowed for the {@link #PHOTO} to be null.
4658         * </p>
4659         * <p>
4660         * You can use all columns defined for {@link ContactsContract.Data} as
4661         * well as the following aliases.
4662         * </p>
4663         * <h2>Column aliases</h2>
4664         * <table class="jd-sumtable">
4665         * <tr>
4666         * <th>Type</th>
4667         * <th>Alias</th><th colspan='2'>Data column</th>
4668         * </tr>
4669         * <tr>
4670         * <td>BLOB</td>
4671         * <td>{@link #PHOTO}</td>
4672         * <td>{@link #DATA15}</td>
4673         * <td>By convention, binary data is stored in DATA15.</td>
4674         * </tr>
4675         * </table>
4676         */
4677        public static final class Photo implements DataColumnsWithJoins {
4678            /**
4679             * This utility class cannot be instantiated
4680             */
4681            private Photo() {}
4682
4683            /** MIME type used when storing this in data table. */
4684            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
4685
4686            /**
4687             * Thumbnail photo of the raw contact. This is the raw bytes of an image
4688             * that could be inflated using {@link android.graphics.BitmapFactory}.
4689             * <p>
4690             * Type: BLOB
4691             */
4692            public static final String PHOTO = DATA15;
4693        }
4694
4695        /**
4696         * <p>
4697         * Notes about the contact.
4698         * </p>
4699         * <p>
4700         * You can use all columns defined for {@link ContactsContract.Data} as
4701         * well as the following aliases.
4702         * </p>
4703         * <h2>Column aliases</h2>
4704         * <table class="jd-sumtable">
4705         * <tr>
4706         * <th>Type</th>
4707         * <th>Alias</th><th colspan='2'>Data column</th>
4708         * </tr>
4709         * <tr>
4710         * <td>String</td>
4711         * <td>{@link #NOTE}</td>
4712         * <td>{@link #DATA1}</td>
4713         * <td></td>
4714         * </tr>
4715         * </table>
4716         */
4717        public static final class Note implements DataColumnsWithJoins {
4718            /**
4719             * This utility class cannot be instantiated
4720             */
4721            private Note() {}
4722
4723            /** MIME type used when storing this in data table. */
4724            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
4725
4726            /**
4727             * The note text.
4728             * <P>Type: TEXT</P>
4729             */
4730            public static final String NOTE = DATA1;
4731        }
4732
4733        /**
4734         * <p>
4735         * Group Membership.
4736         * </p>
4737         * <p>
4738         * You can use all columns defined for {@link ContactsContract.Data} as
4739         * well as the following aliases.
4740         * </p>
4741         * <h2>Column aliases</h2>
4742         * <table class="jd-sumtable">
4743         * <tr>
4744         * <th>Type</th>
4745         * <th>Alias</th><th colspan='2'>Data column</th>
4746         * </tr>
4747         * <tr>
4748         * <td>long</td>
4749         * <td>{@link #GROUP_ROW_ID}</td>
4750         * <td>{@link #DATA1}</td>
4751         * <td></td>
4752         * </tr>
4753         * <tr>
4754         * <td>String</td>
4755         * <td>{@link #GROUP_SOURCE_ID}</td>
4756         * <td>none</td>
4757         * <td>
4758         * <p>
4759         * The sourceid of the group that this group membership refers to.
4760         * Exactly one of this or {@link #GROUP_ROW_ID} must be set when
4761         * inserting a row.
4762         * </p>
4763         * <p>
4764         * If this field is specified, the provider will first try to
4765         * look up a group with this {@link Groups Groups.SOURCE_ID}.  If such a group
4766         * is found, it will use the corresponding row id.  If the group is not
4767         * found, it will create one.
4768         * </td>
4769         * </tr>
4770         * </table>
4771         */
4772        public static final class GroupMembership implements DataColumnsWithJoins {
4773            /**
4774             * This utility class cannot be instantiated
4775             */
4776            private GroupMembership() {}
4777
4778            /** MIME type used when storing this in data table. */
4779            public static final String CONTENT_ITEM_TYPE =
4780                    "vnd.android.cursor.item/group_membership";
4781
4782            /**
4783             * The row id of the group that this group membership refers to. Exactly one of
4784             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
4785             * <P>Type: INTEGER</P>
4786             */
4787            public static final String GROUP_ROW_ID = DATA1;
4788
4789            /**
4790             * The sourceid of the group that this group membership refers to.  Exactly one of
4791             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
4792             * <P>Type: TEXT</P>
4793             */
4794            public static final String GROUP_SOURCE_ID = "group_sourceid";
4795        }
4796
4797        /**
4798         * <p>
4799         * A data kind representing a website related to the contact.
4800         * </p>
4801         * <p>
4802         * You can use all columns defined for {@link ContactsContract.Data} as
4803         * well as the following aliases.
4804         * </p>
4805         * <h2>Column aliases</h2>
4806         * <table class="jd-sumtable">
4807         * <tr>
4808         * <th>Type</th>
4809         * <th>Alias</th><th colspan='2'>Data column</th>
4810         * </tr>
4811         * <tr>
4812         * <td>String</td>
4813         * <td>{@link #URL}</td>
4814         * <td>{@link #DATA1}</td>
4815         * <td></td>
4816         * </tr>
4817         * <tr>
4818         * <td>int</td>
4819         * <td>{@link #TYPE}</td>
4820         * <td>{@link #DATA2}</td>
4821         * <td>Allowed values are:
4822         * <p>
4823         * <ul>
4824         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4825         * <li>{@link #TYPE_HOMEPAGE}</li>
4826         * <li>{@link #TYPE_BLOG}</li>
4827         * <li>{@link #TYPE_PROFILE}</li>
4828         * <li>{@link #TYPE_HOME}</li>
4829         * <li>{@link #TYPE_WORK}</li>
4830         * <li>{@link #TYPE_FTP}</li>
4831         * <li>{@link #TYPE_OTHER}</li>
4832         * </ul>
4833         * </p>
4834         * </td>
4835         * </tr>
4836         * <tr>
4837         * <td>String</td>
4838         * <td>{@link #LABEL}</td>
4839         * <td>{@link #DATA3}</td>
4840         * <td></td>
4841         * </tr>
4842         * </table>
4843         */
4844        public static final class Website implements DataColumnsWithJoins, CommonColumns {
4845            /**
4846             * This utility class cannot be instantiated
4847             */
4848            private Website() {}
4849
4850            /** MIME type used when storing this in data table. */
4851            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
4852
4853            public static final int TYPE_HOMEPAGE = 1;
4854            public static final int TYPE_BLOG = 2;
4855            public static final int TYPE_PROFILE = 3;
4856            public static final int TYPE_HOME = 4;
4857            public static final int TYPE_WORK = 5;
4858            public static final int TYPE_FTP = 6;
4859            public static final int TYPE_OTHER = 7;
4860
4861            /**
4862             * The website URL string.
4863             * <P>Type: TEXT</P>
4864             */
4865            public static final String URL = DATA;
4866        }
4867
4868        /**
4869         * <p>
4870         * A data kind representing a SIP address for the contact.
4871         * </p>
4872         * <p>
4873         * You can use all columns defined for {@link ContactsContract.Data} as
4874         * well as the following aliases.
4875         * </p>
4876         * <h2>Column aliases</h2>
4877         * <table class="jd-sumtable">
4878         * <tr>
4879         * <th>Type</th>
4880         * <th>Alias</th><th colspan='2'>Data column</th>
4881         * </tr>
4882         * <tr>
4883         * <td>String</td>
4884         * <td>{@link #SIP_ADDRESS}</td>
4885         * <td>{@link #DATA1}</td>
4886         * <td></td>
4887         * </tr>
4888         * <tr>
4889         * <td>int</td>
4890         * <td>{@link #TYPE}</td>
4891         * <td>{@link #DATA2}</td>
4892         * <td>Allowed values are:
4893         * <p>
4894         * <ul>
4895         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4896         * <li>{@link #TYPE_HOME}</li>
4897         * <li>{@link #TYPE_WORK}</li>
4898         * <li>{@link #TYPE_OTHER}</li>
4899         * </ul>
4900         * </p>
4901         * </td>
4902         * </tr>
4903         * <tr>
4904         * <td>String</td>
4905         * <td>{@link #LABEL}</td>
4906         * <td>{@link #DATA3}</td>
4907         * <td></td>
4908         * </tr>
4909         * </table>
4910         */
4911        public static final class SipAddress implements DataColumnsWithJoins, CommonColumns {
4912            /**
4913             * This utility class cannot be instantiated
4914             */
4915            private SipAddress() {}
4916
4917            /** MIME type used when storing this in data table. */
4918            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/sip_address";
4919
4920            public static final int TYPE_HOME = 1;
4921            public static final int TYPE_WORK = 2;
4922            public static final int TYPE_OTHER = 3;
4923
4924            /**
4925             * The SIP address.
4926             * <P>Type: TEXT</P>
4927             */
4928            public static final String SIP_ADDRESS = DATA1;
4929            // ...and TYPE and LABEL come from the CommonColumns interface.
4930
4931            /**
4932             * Return the string resource that best describes the given
4933             * {@link #TYPE}. Will always return a valid resource.
4934             */
4935            public static final int getTypeLabelResource(int type) {
4936                switch (type) {
4937                    case TYPE_HOME: return com.android.internal.R.string.sipAddressTypeHome;
4938                    case TYPE_WORK: return com.android.internal.R.string.sipAddressTypeWork;
4939                    case TYPE_OTHER: return com.android.internal.R.string.sipAddressTypeOther;
4940                    default: return com.android.internal.R.string.sipAddressTypeCustom;
4941                }
4942            }
4943
4944            /**
4945             * Return a {@link CharSequence} that best describes the given type,
4946             * possibly substituting the given {@link #LABEL} value
4947             * for {@link #TYPE_CUSTOM}.
4948             */
4949            public static final CharSequence getTypeLabel(Resources res, int type,
4950                    CharSequence label) {
4951                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4952                    return label;
4953                } else {
4954                    final int labelRes = getTypeLabelResource(type);
4955                    return res.getText(labelRes);
4956                }
4957            }
4958        }
4959    }
4960
4961    /**
4962     * @see Groups
4963     */
4964    protected interface GroupsColumns {
4965        /**
4966         * The display title of this group.
4967         * <p>
4968         * Type: TEXT
4969         */
4970        public static final String TITLE = "title";
4971
4972        /**
4973         * The package name to use when creating {@link Resources} objects for
4974         * this group. This value is only designed for use when building user
4975         * interfaces, and should not be used to infer the owner.
4976         *
4977         * @hide
4978         */
4979        public static final String RES_PACKAGE = "res_package";
4980
4981        /**
4982         * The display title of this group to load as a resource from
4983         * {@link #RES_PACKAGE}, which may be localized.
4984         * <P>Type: TEXT</P>
4985         *
4986         * @hide
4987         */
4988        public static final String TITLE_RES = "title_res";
4989
4990        /**
4991         * Notes about the group.
4992         * <p>
4993         * Type: TEXT
4994         */
4995        public static final String NOTES = "notes";
4996
4997        /**
4998         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
4999         * to the sync adapter, null otherwise.
5000         * <P>Type: TEXT</P>
5001         */
5002        public static final String SYSTEM_ID = "system_id";
5003
5004        /**
5005         * The total number of {@link Contacts} that have
5006         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
5007         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
5008         * <p>
5009         * Type: INTEGER
5010         */
5011        public static final String SUMMARY_COUNT = "summ_count";
5012
5013        /**
5014         * The total number of {@link Contacts} that have both
5015         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
5016         * Read-only value that is only present when querying
5017         * {@link Groups#CONTENT_SUMMARY_URI}.
5018         * <p>
5019         * Type: INTEGER
5020         */
5021        public static final String SUMMARY_WITH_PHONES = "summ_phones";
5022
5023        /**
5024         * Flag indicating if the contacts belonging to this group should be
5025         * visible in any user interface.
5026         * <p>
5027         * Type: INTEGER (boolean)
5028         */
5029        public static final String GROUP_VISIBLE = "group_visible";
5030
5031        /**
5032         * The "deleted" flag: "0" by default, "1" if the row has been marked
5033         * for deletion. When {@link android.content.ContentResolver#delete} is
5034         * called on a group, it is marked for deletion. The sync adaptor
5035         * deletes the group on the server and then calls ContactResolver.delete
5036         * once more, this time setting the the
5037         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to
5038         * finalize the data removal.
5039         * <P>Type: INTEGER</P>
5040         */
5041        public static final String DELETED = "deleted";
5042
5043        /**
5044         * Whether this group should be synced if the SYNC_EVERYTHING settings
5045         * is false for this group's account.
5046         * <p>
5047         * Type: INTEGER (boolean)
5048         */
5049        public static final String SHOULD_SYNC = "should_sync";
5050    }
5051
5052    /**
5053     * Constants for the groups table. Only per-account groups are supported.
5054     * <h2>Columns</h2>
5055     * <table class="jd-sumtable">
5056     * <tr>
5057     * <th colspan='4'>Groups</th>
5058     * </tr>
5059     * <tr>
5060     * <td>long</td>
5061     * <td>{@link #_ID}</td>
5062     * <td>read-only</td>
5063     * <td>Row ID. Sync adapter should try to preserve row IDs during updates.
5064     * In other words, it would be a really bad idea to delete and reinsert a
5065     * group. A sync adapter should always do an update instead.</td>
5066     * </tr>
5067     * <tr>
5068     * <td>String</td>
5069     * <td>{@link #TITLE}</td>
5070     * <td>read/write</td>
5071     * <td>The display title of this group.</td>
5072     * </tr>
5073     * <tr>
5074     * <td>String</td>
5075     * <td>{@link #NOTES}</td>
5076     * <td>read/write</td>
5077     * <td>Notes about the group.</td>
5078     * </tr>
5079     * <tr>
5080     * <td>String</td>
5081     * <td>{@link #SYSTEM_ID}</td>
5082     * <td>read/write</td>
5083     * <td>The ID of this group if it is a System Group, i.e. a group that has a
5084     * special meaning to the sync adapter, null otherwise.</td>
5085     * </tr>
5086     * <tr>
5087     * <td>int</td>
5088     * <td>{@link #SUMMARY_COUNT}</td>
5089     * <td>read-only</td>
5090     * <td>The total number of {@link Contacts} that have
5091     * {@link CommonDataKinds.GroupMembership} in this group. Read-only value
5092     * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td>
5093     * </tr>
5094     * <tr>
5095     * <td>int</td>
5096     * <td>{@link #SUMMARY_WITH_PHONES}</td>
5097     * <td>read-only</td>
5098     * <td>The total number of {@link Contacts} that have both
5099     * {@link CommonDataKinds.GroupMembership} in this group, and also have
5100     * phone numbers. Read-only value that is only present when querying
5101     * {@link Groups#CONTENT_SUMMARY_URI}.</td>
5102     * </tr>
5103     * <tr>
5104     * <td>int</td>
5105     * <td>{@link #GROUP_VISIBLE}</td>
5106     * <td>read-only</td>
5107     * <td>Flag indicating if the contacts belonging to this group should be
5108     * visible in any user interface. Allowed values: 0 and 1.</td>
5109     * </tr>
5110     * <tr>
5111     * <td>int</td>
5112     * <td>{@link #DELETED}</td>
5113     * <td>read/write</td>
5114     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
5115     * for deletion. When {@link android.content.ContentResolver#delete} is
5116     * called on a group, it is marked for deletion. The sync adaptor deletes
5117     * the group on the server and then calls ContactResolver.delete once more,
5118     * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER}
5119     * query parameter to finalize the data removal.</td>
5120     * </tr>
5121     * <tr>
5122     * <td>int</td>
5123     * <td>{@link #SHOULD_SYNC}</td>
5124     * <td>read/write</td>
5125     * <td>Whether this group should be synced if the SYNC_EVERYTHING settings
5126     * is false for this group's account.</td>
5127     * </tr>
5128     * </table>
5129     */
5130    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
5131        /**
5132         * This utility class cannot be instantiated
5133         */
5134        private Groups() {
5135        }
5136
5137        /**
5138         * The content:// style URI for this table
5139         */
5140        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
5141
5142        /**
5143         * The content:// style URI for this table joined with details data from
5144         * {@link ContactsContract.Data}.
5145         */
5146        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
5147                "groups_summary");
5148
5149        /**
5150         * The MIME type of a directory of groups.
5151         */
5152        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
5153
5154        /**
5155         * The MIME type of a single group.
5156         */
5157        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
5158
5159        public static EntityIterator newEntityIterator(Cursor cursor) {
5160            return new EntityIteratorImpl(cursor);
5161        }
5162
5163        private static class EntityIteratorImpl extends CursorEntityIterator {
5164            public EntityIteratorImpl(Cursor cursor) {
5165                super(cursor);
5166            }
5167
5168            @Override
5169            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
5170                // we expect the cursor is already at the row we need to read from
5171                final ContentValues values = new ContentValues();
5172                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID);
5173                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME);
5174                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE);
5175                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY);
5176                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION);
5177                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID);
5178                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE);
5179                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE);
5180                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES);
5181                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE);
5182                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1);
5183                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2);
5184                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3);
5185                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4);
5186                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID);
5187                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED);
5188                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES);
5189                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC);
5190                cursor.moveToNext();
5191                return new Entity(values);
5192            }
5193        }
5194    }
5195
5196    /**
5197     * <p>
5198     * Constants for the contact aggregation exceptions table, which contains
5199     * aggregation rules overriding those used by automatic aggregation. This
5200     * type only supports query and update. Neither insert nor delete are
5201     * supported.
5202     * </p>
5203     * <h2>Columns</h2>
5204     * <table class="jd-sumtable">
5205     * <tr>
5206     * <th colspan='4'>AggregationExceptions</th>
5207     * </tr>
5208     * <tr>
5209     * <td>int</td>
5210     * <td>{@link #TYPE}</td>
5211     * <td>read/write</td>
5212     * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER},
5213     * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td>
5214     * </tr>
5215     * <tr>
5216     * <td>long</td>
5217     * <td>{@link #RAW_CONTACT_ID1}</td>
5218     * <td>read/write</td>
5219     * <td>A reference to the {@link RawContacts#_ID} of the raw contact that
5220     * the rule applies to.</td>
5221     * </tr>
5222     * <tr>
5223     * <td>long</td>
5224     * <td>{@link #RAW_CONTACT_ID2}</td>
5225     * <td>read/write</td>
5226     * <td>A reference to the other {@link RawContacts#_ID} of the raw contact
5227     * that the rule applies to.</td>
5228     * </tr>
5229     * </table>
5230     */
5231    public static final class AggregationExceptions implements BaseColumns {
5232        /**
5233         * This utility class cannot be instantiated
5234         */
5235        private AggregationExceptions() {}
5236
5237        /**
5238         * The content:// style URI for this table
5239         */
5240        public static final Uri CONTENT_URI =
5241                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
5242
5243        /**
5244         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
5245         */
5246        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
5247
5248        /**
5249         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
5250         */
5251        public static final String CONTENT_ITEM_TYPE =
5252                "vnd.android.cursor.item/aggregation_exception";
5253
5254        /**
5255         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
5256         * {@link #TYPE_AUTOMATIC}.
5257         *
5258         * <P>Type: INTEGER</P>
5259         */
5260        public static final String TYPE = "type";
5261
5262        /**
5263         * Allows the provider to automatically decide whether the specified raw contacts should
5264         * be included in the same aggregate contact or not.
5265         */
5266        public static final int TYPE_AUTOMATIC = 0;
5267
5268        /**
5269         * Makes sure that the specified raw contacts are included in the same
5270         * aggregate contact.
5271         */
5272        public static final int TYPE_KEEP_TOGETHER = 1;
5273
5274        /**
5275         * Makes sure that the specified raw contacts are NOT included in the same
5276         * aggregate contact.
5277         */
5278        public static final int TYPE_KEEP_SEPARATE = 2;
5279
5280        /**
5281         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
5282         */
5283        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
5284
5285        /**
5286         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
5287         * applies to.
5288         */
5289        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
5290    }
5291
5292    /**
5293     * @see Settings
5294     */
5295    protected interface SettingsColumns {
5296        /**
5297         * The name of the account instance to which this row belongs.
5298         * <P>Type: TEXT</P>
5299         */
5300        public static final String ACCOUNT_NAME = "account_name";
5301
5302        /**
5303         * The type of account to which this row belongs, which when paired with
5304         * {@link #ACCOUNT_NAME} identifies a specific account.
5305         * <P>Type: TEXT</P>
5306         */
5307        public static final String ACCOUNT_TYPE = "account_type";
5308
5309        /**
5310         * Depending on the mode defined by the sync-adapter, this flag controls
5311         * the top-level sync behavior for this data source.
5312         * <p>
5313         * Type: INTEGER (boolean)
5314         */
5315        public static final String SHOULD_SYNC = "should_sync";
5316
5317        /**
5318         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
5319         * entries should be visible in any user interface.
5320         * <p>
5321         * Type: INTEGER (boolean)
5322         */
5323        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
5324
5325        /**
5326         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
5327         * {@link Groups#SHOULD_SYNC} under this account have been marked as
5328         * unsynced.
5329         */
5330        public static final String ANY_UNSYNCED = "any_unsynced";
5331
5332        /**
5333         * Read-only count of {@link Contacts} from a specific source that have
5334         * no {@link CommonDataKinds.GroupMembership} entries.
5335         * <p>
5336         * Type: INTEGER
5337         */
5338        public static final String UNGROUPED_COUNT = "summ_count";
5339
5340        /**
5341         * Read-only count of {@link Contacts} from a specific source that have
5342         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
5343         * <p>
5344         * Type: INTEGER
5345         */
5346        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
5347    }
5348
5349    /**
5350     * <p>
5351     * Contacts-specific settings for various {@link Account}'s.
5352     * </p>
5353     * <h2>Columns</h2>
5354     * <table class="jd-sumtable">
5355     * <tr>
5356     * <th colspan='4'>Settings</th>
5357     * </tr>
5358     * <tr>
5359     * <td>String</td>
5360     * <td>{@link #ACCOUNT_NAME}</td>
5361     * <td>read/write-once</td>
5362     * <td>The name of the account instance to which this row belongs.</td>
5363     * </tr>
5364     * <tr>
5365     * <td>String</td>
5366     * <td>{@link #ACCOUNT_TYPE}</td>
5367     * <td>read/write-once</td>
5368     * <td>The type of account to which this row belongs, which when paired with
5369     * {@link #ACCOUNT_NAME} identifies a specific account.</td>
5370     * </tr>
5371     * <tr>
5372     * <td>int</td>
5373     * <td>{@link #SHOULD_SYNC}</td>
5374     * <td>read/write</td>
5375     * <td>Depending on the mode defined by the sync-adapter, this flag controls
5376     * the top-level sync behavior for this data source.</td>
5377     * </tr>
5378     * <tr>
5379     * <td>int</td>
5380     * <td>{@link #UNGROUPED_VISIBLE}</td>
5381     * <td>read/write</td>
5382     * <td>Flag indicating if contacts without any
5383     * {@link CommonDataKinds.GroupMembership} entries should be visible in any
5384     * user interface.</td>
5385     * </tr>
5386     * <tr>
5387     * <td>int</td>
5388     * <td>{@link #ANY_UNSYNCED}</td>
5389     * <td>read-only</td>
5390     * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any
5391     * {@link Groups#SHOULD_SYNC} under this account have been marked as
5392     * unsynced.</td>
5393     * </tr>
5394     * <tr>
5395     * <td>int</td>
5396     * <td>{@link #UNGROUPED_COUNT}</td>
5397     * <td>read-only</td>
5398     * <td>Read-only count of {@link Contacts} from a specific source that have
5399     * no {@link CommonDataKinds.GroupMembership} entries.</td>
5400     * </tr>
5401     * <tr>
5402     * <td>int</td>
5403     * <td>{@link #UNGROUPED_WITH_PHONES}</td>
5404     * <td>read-only</td>
5405     * <td>Read-only count of {@link Contacts} from a specific source that have
5406     * no {@link CommonDataKinds.GroupMembership} entries, and also have phone
5407     * numbers.</td>
5408     * </tr>
5409     * </table>
5410     */
5411    public static final class Settings implements SettingsColumns {
5412        /**
5413         * This utility class cannot be instantiated
5414         */
5415        private Settings() {
5416        }
5417
5418        /**
5419         * The content:// style URI for this table
5420         */
5421        public static final Uri CONTENT_URI =
5422                Uri.withAppendedPath(AUTHORITY_URI, "settings");
5423
5424        /**
5425         * The MIME-type of {@link #CONTENT_URI} providing a directory of
5426         * settings.
5427         */
5428        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
5429
5430        /**
5431         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
5432         */
5433        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
5434    }
5435
5436    /**
5437     * Private API for inquiring about the general status of the provider.
5438     *
5439     * @hide
5440     */
5441    public static final class ProviderStatus {
5442
5443        /**
5444         * Not instantiable.
5445         */
5446        private ProviderStatus() {
5447        }
5448
5449        /**
5450         * The content:// style URI for this table.  Requests to this URI can be
5451         * performed on the UI thread because they are always unblocking.
5452         *
5453         * @hide
5454         */
5455        public static final Uri CONTENT_URI =
5456                Uri.withAppendedPath(AUTHORITY_URI, "provider_status");
5457
5458        /**
5459         * The MIME-type of {@link #CONTENT_URI} providing a directory of
5460         * settings.
5461         *
5462         * @hide
5463         */
5464        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status";
5465
5466        /**
5467         * An integer representing the current status of the provider.
5468         *
5469         * @hide
5470         */
5471        public static final String STATUS = "status";
5472
5473        /**
5474         * Default status of the provider.
5475         *
5476         * @hide
5477         */
5478        public static final int STATUS_NORMAL = 0;
5479
5480        /**
5481         * The status used when the provider is in the process of upgrading.  Contacts
5482         * are temporarily unaccessible.
5483         *
5484         * @hide
5485         */
5486        public static final int STATUS_UPGRADING = 1;
5487
5488        /**
5489         * The status used if the provider was in the process of upgrading but ran
5490         * out of storage. The DATA1 column will contain the estimated amount of
5491         * storage required (in bytes). Update status to STATUS_NORMAL to force
5492         * the provider to retry the upgrade.
5493         *
5494         * @hide
5495         */
5496        public static final int STATUS_UPGRADE_OUT_OF_MEMORY = 2;
5497
5498        /**
5499         * The status used during a locale change.
5500         *
5501         * @hide
5502         */
5503        public static final int STATUS_CHANGING_LOCALE = 3;
5504
5505        /**
5506         * Additional data associated with the status.
5507         *
5508         * @hide
5509         */
5510        public static final String DATA1 = "data1";
5511    }
5512
5513    /**
5514     * Helper methods to display QuickContact dialogs that allow users to pivot on
5515     * a specific {@link Contacts} entry.
5516     */
5517    public static final class QuickContact {
5518        /**
5519         * Action used to trigger person pivot dialog.
5520         * @hide
5521         */
5522        public static final String ACTION_QUICK_CONTACT =
5523                "com.android.contacts.action.QUICK_CONTACT";
5524
5525        /**
5526         * Extra used to specify pivot dialog location in screen coordinates.
5527         * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead.
5528         * @hide
5529         */
5530        @Deprecated
5531        public static final String EXTRA_TARGET_RECT = "target_rect";
5532
5533        /**
5534         * Extra used to specify size of pivot dialog.
5535         * @hide
5536         */
5537        public static final String EXTRA_MODE = "mode";
5538
5539        /**
5540         * Extra used to indicate a list of specific MIME-types to exclude and
5541         * not display. Stored as a {@link String} array.
5542         * @hide
5543         */
5544        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
5545
5546        /**
5547         * Small QuickContact mode, usually presented with minimal actions.
5548         */
5549        public static final int MODE_SMALL = 1;
5550
5551        /**
5552         * Medium QuickContact mode, includes actions and light summary describing
5553         * the {@link Contacts} entry being shown. This may include social
5554         * status and presence details.
5555         */
5556        public static final int MODE_MEDIUM = 2;
5557
5558        /**
5559         * Large QuickContact mode, includes actions and larger, card-like summary
5560         * of the {@link Contacts} entry being shown. This may include detailed
5561         * information, such as a photo.
5562         */
5563        public static final int MODE_LARGE = 3;
5564
5565        /**
5566         * Trigger a dialog that lists the various methods of interacting with
5567         * the requested {@link Contacts} entry. This may be based on available
5568         * {@link ContactsContract.Data} rows under that contact, and may also
5569         * include social status and presence details.
5570         *
5571         * @param context The parent {@link Context} that may be used as the
5572         *            parent for this dialog.
5573         * @param target Specific {@link View} from your layout that this dialog
5574         *            should be centered around. In particular, if the dialog
5575         *            has a "callout" arrow, it will be pointed and centered
5576         *            around this {@link View}.
5577         * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
5578         *            {@link Uri} that describes a specific contact to feature
5579         *            in this dialog.
5580         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
5581         *            {@link #MODE_LARGE}, indicating the desired dialog size,
5582         *            when supported.
5583         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
5584         *            to exclude when showing this dialog. For example, when
5585         *            already viewing the contact details card, this can be used
5586         *            to omit the details entry from the dialog.
5587         */
5588        public static void showQuickContact(Context context, View target, Uri lookupUri, int mode,
5589                String[] excludeMimes) {
5590            // Find location and bounds of target view, adjusting based on the
5591            // assumed local density.
5592            final float appScale = context.getResources().getCompatibilityInfo().applicationScale;
5593            final int[] pos = new int[2];
5594            target.getLocationOnScreen(pos);
5595
5596            final Rect rect = new Rect();
5597            rect.left = (int) (pos[0] * appScale + 0.5f);
5598            rect.top = (int) (pos[1] * appScale + 0.5f);
5599            rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f);
5600            rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f);
5601
5602            // Trigger with obtained rectangle
5603            showQuickContact(context, rect, lookupUri, mode, excludeMimes);
5604        }
5605
5606        /**
5607         * Trigger a dialog that lists the various methods of interacting with
5608         * the requested {@link Contacts} entry. This may be based on available
5609         * {@link ContactsContract.Data} rows under that contact, and may also
5610         * include social status and presence details.
5611         *
5612         * @param context The parent {@link Context} that may be used as the
5613         *            parent for this dialog.
5614         * @param target Specific {@link Rect} that this dialog should be
5615         *            centered around, in screen coordinates. In particular, if
5616         *            the dialog has a "callout" arrow, it will be pointed and
5617         *            centered around this {@link Rect}. If you are running at a
5618         *            non-native density, you need to manually adjust using
5619         *            {@link DisplayMetrics#density} before calling.
5620         * @param lookupUri A
5621         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
5622         *            {@link Uri} that describes a specific contact to feature
5623         *            in this dialog.
5624         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
5625         *            {@link #MODE_LARGE}, indicating the desired dialog size,
5626         *            when supported.
5627         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
5628         *            to exclude when showing this dialog. For example, when
5629         *            already viewing the contact details card, this can be used
5630         *            to omit the details entry from the dialog.
5631         */
5632        public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,
5633                String[] excludeMimes) {
5634            // Launch pivot dialog through intent for now
5635            final Intent intent = new Intent(ACTION_QUICK_CONTACT);
5636            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
5637                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
5638
5639            intent.setData(lookupUri);
5640            intent.setSourceBounds(target);
5641            intent.putExtra(EXTRA_MODE, mode);
5642            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);
5643            context.startActivity(intent);
5644        }
5645    }
5646
5647    /**
5648     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
5649     * that involve contacts.
5650     */
5651    public static final class Intents {
5652        /**
5653         * This is the intent that is fired when a search suggestion is clicked on.
5654         */
5655        public static final String SEARCH_SUGGESTION_CLICKED =
5656                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
5657
5658        /**
5659         * This is the intent that is fired when a search suggestion for dialing a number
5660         * is clicked on.
5661         */
5662        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
5663                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
5664
5665        /**
5666         * This is the intent that is fired when a search suggestion for creating a contact
5667         * is clicked on.
5668         */
5669        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
5670                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
5671
5672        /**
5673         * Starts an Activity that lets the user pick a contact to attach an image to.
5674         * After picking the contact it launches the image cropper in face detection mode.
5675         */
5676        public static final String ATTACH_IMAGE =
5677                "com.android.contacts.action.ATTACH_IMAGE";
5678
5679        /**
5680         * Takes as input a data URI with a mailto: or tel: scheme. If a single
5681         * contact exists with the given data it will be shown. If no contact
5682         * exists, a dialog will ask the user if they want to create a new
5683         * contact with the provided details filled in. If multiple contacts
5684         * share the data the user will be prompted to pick which contact they
5685         * want to view.
5686         * <p>
5687         * For <code>mailto:</code> URIs, the scheme specific portion must be a
5688         * raw email address, such as one built using
5689         * {@link Uri#fromParts(String, String, String)}.
5690         * <p>
5691         * For <code>tel:</code> URIs, the scheme specific portion is compared
5692         * to existing numbers using the standard caller ID lookup algorithm.
5693         * The number must be properly encoded, for example using
5694         * {@link Uri#fromParts(String, String, String)}.
5695         * <p>
5696         * Any extras from the {@link Insert} class will be passed along to the
5697         * create activity if there are no contacts to show.
5698         * <p>
5699         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
5700         * prompting the user when the contact doesn't exist.
5701         */
5702        public static final String SHOW_OR_CREATE_CONTACT =
5703                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
5704
5705        /**
5706         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
5707         * contact if no matching contact found. Otherwise, default behavior is
5708         * to prompt user with dialog before creating.
5709         * <p>
5710         * Type: BOOLEAN
5711         */
5712        public static final String EXTRA_FORCE_CREATE =
5713                "com.android.contacts.action.FORCE_CREATE";
5714
5715        /**
5716         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
5717         * description to be shown when prompting user about creating a new
5718         * contact.
5719         * <p>
5720         * Type: STRING
5721         */
5722        public static final String EXTRA_CREATE_DESCRIPTION =
5723            "com.android.contacts.action.CREATE_DESCRIPTION";
5724
5725        /**
5726         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
5727         * dialog location using screen coordinates. When not specified, the
5728         * dialog will be centered.
5729         *
5730         * @hide
5731         */
5732        @Deprecated
5733        public static final String EXTRA_TARGET_RECT = "target_rect";
5734
5735        /**
5736         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
5737         * desired dialog style, usually a variation on size. One of
5738         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
5739         *
5740         * @hide
5741         */
5742        @Deprecated
5743        public static final String EXTRA_MODE = "mode";
5744
5745        /**
5746         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
5747         *
5748         * @hide
5749         */
5750        @Deprecated
5751        public static final int MODE_SMALL = 1;
5752
5753        /**
5754         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
5755         *
5756         * @hide
5757         */
5758        @Deprecated
5759        public static final int MODE_MEDIUM = 2;
5760
5761        /**
5762         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
5763         *
5764         * @hide
5765         */
5766        @Deprecated
5767        public static final int MODE_LARGE = 3;
5768
5769        /**
5770         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
5771         * a list of specific MIME-types to exclude and not display. Stored as a
5772         * {@link String} array.
5773         *
5774         * @hide
5775         */
5776        @Deprecated
5777        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
5778
5779        /**
5780         * Intents related to the Contacts app UI.
5781         *
5782         * @hide
5783         */
5784        public static final class UI {
5785            /**
5786             * The action for the default contacts list tab.
5787             */
5788            public static final String LIST_DEFAULT =
5789                    "com.android.contacts.action.LIST_DEFAULT";
5790
5791            /**
5792             * The action for the contacts list tab.
5793             */
5794            public static final String LIST_GROUP_ACTION =
5795                    "com.android.contacts.action.LIST_GROUP";
5796
5797            /**
5798             * When in LIST_GROUP_ACTION mode, this is the group to display.
5799             */
5800            public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
5801
5802            /**
5803             * The action for the all contacts list tab.
5804             */
5805            public static final String LIST_ALL_CONTACTS_ACTION =
5806                    "com.android.contacts.action.LIST_ALL_CONTACTS";
5807
5808            /**
5809             * The action for the contacts with phone numbers list tab.
5810             */
5811            public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
5812                    "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
5813
5814            /**
5815             * The action for the starred contacts list tab.
5816             */
5817            public static final String LIST_STARRED_ACTION =
5818                    "com.android.contacts.action.LIST_STARRED";
5819
5820            /**
5821             * The action for the frequent contacts list tab.
5822             */
5823            public static final String LIST_FREQUENT_ACTION =
5824                    "com.android.contacts.action.LIST_FREQUENT";
5825
5826            /**
5827             * The action for the "strequent" contacts list tab. It first lists the starred
5828             * contacts in alphabetical order and then the frequent contacts in descending
5829             * order of the number of times they have been contacted.
5830             */
5831            public static final String LIST_STREQUENT_ACTION =
5832                    "com.android.contacts.action.LIST_STREQUENT";
5833
5834            /**
5835             * A key for to be used as an intent extra to set the activity
5836             * title to a custom String value.
5837             */
5838            public static final String TITLE_EXTRA_KEY =
5839                    "com.android.contacts.extra.TITLE_EXTRA";
5840
5841            /**
5842             * Activity Action: Display a filtered list of contacts
5843             * <p>
5844             * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for
5845             * filtering
5846             * <p>
5847             * Output: Nothing.
5848             */
5849            public static final String FILTER_CONTACTS_ACTION =
5850                    "com.android.contacts.action.FILTER_CONTACTS";
5851
5852            /**
5853             * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
5854             * intents to supply the text on which to filter.
5855             */
5856            public static final String FILTER_TEXT_EXTRA_KEY =
5857                    "com.android.contacts.extra.FILTER_TEXT";
5858        }
5859
5860        /**
5861         * Convenience class that contains string constants used
5862         * to create contact {@link android.content.Intent Intents}.
5863         */
5864        public static final class Insert {
5865            /** The action code to use when adding a contact */
5866            public static final String ACTION = Intent.ACTION_INSERT;
5867
5868            /**
5869             * If present, forces a bypass of quick insert mode.
5870             */
5871            public static final String FULL_MODE = "full_mode";
5872
5873            /**
5874             * The extra field for the contact name.
5875             * <P>Type: String</P>
5876             */
5877            public static final String NAME = "name";
5878
5879            // TODO add structured name values here.
5880
5881            /**
5882             * The extra field for the contact phonetic name.
5883             * <P>Type: String</P>
5884             */
5885            public static final String PHONETIC_NAME = "phonetic_name";
5886
5887            /**
5888             * The extra field for the contact company.
5889             * <P>Type: String</P>
5890             */
5891            public static final String COMPANY = "company";
5892
5893            /**
5894             * The extra field for the contact job title.
5895             * <P>Type: String</P>
5896             */
5897            public static final String JOB_TITLE = "job_title";
5898
5899            /**
5900             * The extra field for the contact notes.
5901             * <P>Type: String</P>
5902             */
5903            public static final String NOTES = "notes";
5904
5905            /**
5906             * The extra field for the contact phone number.
5907             * <P>Type: String</P>
5908             */
5909            public static final String PHONE = "phone";
5910
5911            /**
5912             * The extra field for the contact phone number type.
5913             * <P>Type: Either an integer value from
5914             * {@link CommonDataKinds.Phone},
5915             *  or a string specifying a custom label.</P>
5916             */
5917            public static final String PHONE_TYPE = "phone_type";
5918
5919            /**
5920             * The extra field for the phone isprimary flag.
5921             * <P>Type: boolean</P>
5922             */
5923            public static final String PHONE_ISPRIMARY = "phone_isprimary";
5924
5925            /**
5926             * The extra field for an optional second contact phone number.
5927             * <P>Type: String</P>
5928             */
5929            public static final String SECONDARY_PHONE = "secondary_phone";
5930
5931            /**
5932             * The extra field for an optional second contact phone number type.
5933             * <P>Type: Either an integer value from
5934             * {@link CommonDataKinds.Phone},
5935             *  or a string specifying a custom label.</P>
5936             */
5937            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
5938
5939            /**
5940             * The extra field for an optional third contact phone number.
5941             * <P>Type: String</P>
5942             */
5943            public static final String TERTIARY_PHONE = "tertiary_phone";
5944
5945            /**
5946             * The extra field for an optional third contact phone number type.
5947             * <P>Type: Either an integer value from
5948             * {@link CommonDataKinds.Phone},
5949             *  or a string specifying a custom label.</P>
5950             */
5951            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
5952
5953            /**
5954             * The extra field for the contact email address.
5955             * <P>Type: String</P>
5956             */
5957            public static final String EMAIL = "email";
5958
5959            /**
5960             * The extra field for the contact email type.
5961             * <P>Type: Either an integer value from
5962             * {@link CommonDataKinds.Email}
5963             *  or a string specifying a custom label.</P>
5964             */
5965            public static final String EMAIL_TYPE = "email_type";
5966
5967            /**
5968             * The extra field for the email isprimary flag.
5969             * <P>Type: boolean</P>
5970             */
5971            public static final String EMAIL_ISPRIMARY = "email_isprimary";
5972
5973            /**
5974             * The extra field for an optional second contact email address.
5975             * <P>Type: String</P>
5976             */
5977            public static final String SECONDARY_EMAIL = "secondary_email";
5978
5979            /**
5980             * The extra field for an optional second contact email type.
5981             * <P>Type: Either an integer value from
5982             * {@link CommonDataKinds.Email}
5983             *  or a string specifying a custom label.</P>
5984             */
5985            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
5986
5987            /**
5988             * The extra field for an optional third contact email address.
5989             * <P>Type: String</P>
5990             */
5991            public static final String TERTIARY_EMAIL = "tertiary_email";
5992
5993            /**
5994             * The extra field for an optional third contact email type.
5995             * <P>Type: Either an integer value from
5996             * {@link CommonDataKinds.Email}
5997             *  or a string specifying a custom label.</P>
5998             */
5999            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
6000
6001            /**
6002             * The extra field for the contact postal address.
6003             * <P>Type: String</P>
6004             */
6005            public static final String POSTAL = "postal";
6006
6007            /**
6008             * The extra field for the contact postal address type.
6009             * <P>Type: Either an integer value from
6010             * {@link CommonDataKinds.StructuredPostal}
6011             *  or a string specifying a custom label.</P>
6012             */
6013            public static final String POSTAL_TYPE = "postal_type";
6014
6015            /**
6016             * The extra field for the postal isprimary flag.
6017             * <P>Type: boolean</P>
6018             */
6019            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
6020
6021            /**
6022             * The extra field for an IM handle.
6023             * <P>Type: String</P>
6024             */
6025            public static final String IM_HANDLE = "im_handle";
6026
6027            /**
6028             * The extra field for the IM protocol
6029             */
6030            public static final String IM_PROTOCOL = "im_protocol";
6031
6032            /**
6033             * The extra field for the IM isprimary flag.
6034             * <P>Type: boolean</P>
6035             */
6036            public static final String IM_ISPRIMARY = "im_isprimary";
6037        }
6038    }
6039}
6040