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