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