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