ContactsContract.java revision 93637d3ee7b2346426b315627c8fcaf9b4782f93
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    /**
3307     * A table that represents the result of looking up a phone number, for
3308     * example for caller ID. To perform a lookup you must append the number you
3309     * want to find to {@link #CONTENT_FILTER_URI}.  This query is highly
3310     * optimized.
3311     * <pre>
3312     * Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
3313     * resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...
3314     * </pre>
3315     *
3316     * <h3>Columns</h3>
3317     *
3318     * <table class="jd-sumtable">
3319     * <tr>
3320     * <th colspan='4'>PhoneLookup</th>
3321     * </tr>
3322     * <tr>
3323     * <td>long</td>
3324     * <td>{@link #_ID}</td>
3325     * <td>read-only</td>
3326     * <td>Data row ID.</td>
3327     * </tr>
3328     * <tr>
3329     * <td>String</td>
3330     * <td>{@link #NUMBER}</td>
3331     * <td>read-only</td>
3332     * <td>Phone number.</td>
3333     * </tr>
3334     * <tr>
3335     * <td>String</td>
3336     * <td>{@link #TYPE}</td>
3337     * <td>read-only</td>
3338     * <td>Phone number type. See {@link CommonDataKinds.Phone}.</td>
3339     * </tr>
3340     * <tr>
3341     * <td>String</td>
3342     * <td>{@link #LABEL}</td>
3343     * <td>read-only</td>
3344     * <td>Custom label for the phone number. See {@link CommonDataKinds.Phone}.</td>
3345     * </tr>
3346     * </table>
3347     * <p>
3348     * Columns from the Contacts table are also available through a join.
3349     * </p>
3350     * <table class="jd-sumtable">
3351     * <tr>
3352     * <th colspan='4'>Join with {@link Contacts}</th>
3353     * </tr>
3354     * <tr>
3355     * <td>String</td>
3356     * <td>{@link #LOOKUP_KEY}</td>
3357     * <td>read-only</td>
3358     * <td>See {@link ContactsContract.Contacts}</td>
3359     * </tr>
3360     * <tr>
3361     * <td>String</td>
3362     * <td>{@link #DISPLAY_NAME}</td>
3363     * <td>read-only</td>
3364     * <td>See {@link ContactsContract.Contacts}</td>
3365     * </tr>
3366     * <tr>
3367     * <td>long</td>
3368     * <td>{@link #PHOTO_ID}</td>
3369     * <td>read-only</td>
3370     * <td>See {@link ContactsContract.Contacts}.</td>
3371     * </tr>
3372     * <tr>
3373     * <td>int</td>
3374     * <td>{@link #IN_VISIBLE_GROUP}</td>
3375     * <td>read-only</td>
3376     * <td>See {@link ContactsContract.Contacts}.</td>
3377     * </tr>
3378     * <tr>
3379     * <td>int</td>
3380     * <td>{@link #HAS_PHONE_NUMBER}</td>
3381     * <td>read-only</td>
3382     * <td>See {@link ContactsContract.Contacts}.</td>
3383     * </tr>
3384     * <tr>
3385     * <td>int</td>
3386     * <td>{@link #TIMES_CONTACTED}</td>
3387     * <td>read-only</td>
3388     * <td>See {@link ContactsContract.Contacts}.</td>
3389     * </tr>
3390     * <tr>
3391     * <td>long</td>
3392     * <td>{@link #LAST_TIME_CONTACTED}</td>
3393     * <td>read-only</td>
3394     * <td>See {@link ContactsContract.Contacts}.</td>
3395     * </tr>
3396     * <tr>
3397     * <td>int</td>
3398     * <td>{@link #STARRED}</td>
3399     * <td>read-only</td>
3400     * <td>See {@link ContactsContract.Contacts}.</td>
3401     * </tr>
3402     * <tr>
3403     * <td>String</td>
3404     * <td>{@link #CUSTOM_RINGTONE}</td>
3405     * <td>read-only</td>
3406     * <td>See {@link ContactsContract.Contacts}.</td>
3407     * </tr>
3408     * <tr>
3409     * <td>int</td>
3410     * <td>{@link #SEND_TO_VOICEMAIL}</td>
3411     * <td>read-only</td>
3412     * <td>See {@link ContactsContract.Contacts}.</td>
3413     * </tr>
3414     * </table>
3415     */
3416    public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns,
3417            ContactsColumns, ContactOptionsColumns {
3418        /**
3419         * This utility class cannot be instantiated
3420         */
3421        private PhoneLookup() {}
3422
3423        /**
3424         * The content:// style URI for this table. Append the phone number you want to lookup
3425         * to this URI and query it to perform a lookup. For example:
3426         * <pre>
3427         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_URI, Uri.encode(phoneNumber));
3428         * </pre>
3429         */
3430        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
3431                "phone_lookup");
3432
3433        /**
3434         * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows.
3435         *
3436         * @hide
3437         */
3438        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup";
3439    }
3440
3441    /**
3442     * Additional data mixed in with {@link StatusColumns} to link
3443     * back to specific {@link ContactsContract.Data#_ID} entries.
3444     *
3445     * @see StatusUpdates
3446     */
3447    protected interface PresenceColumns {
3448
3449        /**
3450         * Reference to the {@link Data#_ID} entry that owns this presence.
3451         * <P>Type: INTEGER</P>
3452         */
3453        public static final String DATA_ID = "presence_data_id";
3454
3455        /**
3456         * See {@link CommonDataKinds.Im} for a list of defined protocol constants.
3457         * <p>Type: NUMBER</p>
3458         */
3459        public static final String PROTOCOL = "protocol";
3460
3461        /**
3462         * Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
3463         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
3464         * omitted if {@link #PROTOCOL} value is not
3465         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.
3466         *
3467         * <p>Type: NUMBER</p>
3468         */
3469        public static final String CUSTOM_PROTOCOL = "custom_protocol";
3470
3471        /**
3472         * The IM handle the presence item is for. The handle is scoped to
3473         * {@link #PROTOCOL}.
3474         * <P>Type: TEXT</P>
3475         */
3476        public static final String IM_HANDLE = "im_handle";
3477
3478        /**
3479         * The IM account for the local user that the presence data came from.
3480         * <P>Type: TEXT</P>
3481         */
3482        public static final String IM_ACCOUNT = "im_account";
3483    }
3484
3485    /**
3486     * <p>
3487     * A status update is linked to a {@link ContactsContract.Data} row and captures
3488     * the user's latest status update via the corresponding source, e.g.
3489     * "Having lunch" via "Google Talk".
3490     * </p>
3491     * <p>
3492     * There are two ways a status update can be inserted: by explicitly linking
3493     * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row
3494     * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
3495     * {@link #IM_HANDLE}.  There is no difference between insert and update, you can use
3496     * either.
3497     * </p>
3498     * <p>
3499     * You cannot use {@link ContentResolver#update} to change a status, but
3500     * {@link ContentResolver#insert} will replace the latests status if it already
3501     * exists.
3502     * </p>
3503     * <p>
3504     * Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses
3505     * for multiple contacts at once.
3506     * </p>
3507     *
3508     * <h3>Columns</h3>
3509     * <table class="jd-sumtable">
3510     * <tr>
3511     * <th colspan='4'>StatusUpdates</th>
3512     * </tr>
3513     * <tr>
3514     * <td>long</td>
3515     * <td>{@link #DATA_ID}</td>
3516     * <td>read/write</td>
3517     * <td>Reference to the {@link Data#_ID} entry that owns this presence. If this
3518     * field is <i>not</i> specified, the provider will attempt to find a data row
3519     * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
3520     * {@link #IM_HANDLE} columns.
3521     * </td>
3522     * </tr>
3523     * <tr>
3524     * <td>long</td>
3525     * <td>{@link #PROTOCOL}</td>
3526     * <td>read/write</td>
3527     * <td>See {@link CommonDataKinds.Im} for a list of defined protocol constants.</td>
3528     * </tr>
3529     * <tr>
3530     * <td>String</td>
3531     * <td>{@link #CUSTOM_PROTOCOL}</td>
3532     * <td>read/write</td>
3533     * <td>Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
3534     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
3535     * omitted if {@link #PROTOCOL} value is not
3536     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.</td>
3537     * </tr>
3538     * <tr>
3539     * <td>String</td>
3540     * <td>{@link #IM_HANDLE}</td>
3541     * <td>read/write</td>
3542     * <td> The IM handle the presence item is for. The handle is scoped to
3543     * {@link #PROTOCOL}.</td>
3544     * </tr>
3545     * <tr>
3546     * <td>String</td>
3547     * <td>{@link #IM_ACCOUNT}</td>
3548     * <td>read/write</td>
3549     * <td>The IM account for the local user that the presence data came from.</td>
3550     * </tr>
3551     * <tr>
3552     * <td>int</td>
3553     * <td>{@link #PRESENCE}</td>
3554     * <td>read/write</td>
3555     * <td>Contact IM presence status. The allowed values are:
3556     * <p>
3557     * <ul>
3558     * <li>{@link #OFFLINE}</li>
3559     * <li>{@link #INVISIBLE}</li>
3560     * <li>{@link #AWAY}</li>
3561     * <li>{@link #IDLE}</li>
3562     * <li>{@link #DO_NOT_DISTURB}</li>
3563     * <li>{@link #AVAILABLE}</li>
3564     * </ul>
3565     * </p>
3566     * <p>
3567     * Since presence status is inherently volatile, the content provider
3568     * may choose not to store this field in long-term storage.
3569     * </p>
3570     * </td>
3571     * </tr>
3572     * <tr>
3573     * <td>int</td>
3574     * <td>{@link #CHAT_CAPABILITY}</td>
3575     * <td>read/write</td>
3576     * <td>Contact IM chat compatibility value. The allowed values combinations of the following
3577     * flags. If None of these flags is set, the device can only do text messaging.
3578     * <p>
3579     * <ul>
3580     * <li>{@link #CAPABILITY_HAS_VIDEO}</li>
3581     * <li>{@link #CAPABILITY_HAS_VOICE}</li>
3582     * <li>{@link #CAPABILITY_HAS_CAMERA}</li>
3583     * </ul>
3584     * </p>
3585     * <p>
3586     * Since chat compatibility is inherently volatile as the contact's availability moves from
3587     * one device to another, the content provider may choose not to store this field in long-term
3588     * storage.
3589     * </p>
3590     * </td>
3591     * </tr>
3592     * <tr>
3593     * <td>String</td>
3594     * <td>{@link #STATUS}</td>
3595     * <td>read/write</td>
3596     * <td>Contact's latest status update, e.g. "having toast for breakfast"</td>
3597     * </tr>
3598     * <tr>
3599     * <td>long</td>
3600     * <td>{@link #STATUS_TIMESTAMP}</td>
3601     * <td>read/write</td>
3602     * <td>The absolute time in milliseconds when the status was
3603     * entered by the user. If this value is not provided, the provider will follow
3604     * this logic: if there was no prior status update, the value will be left as null.
3605     * If there was a prior status update, the provider will default this field
3606     * to the current time.</td>
3607     * </tr>
3608     * <tr>
3609     * <td>String</td>
3610     * <td>{@link #STATUS_RES_PACKAGE}</td>
3611     * <td>read/write</td>
3612     * <td> The package containing resources for this status: label and icon.</td>
3613     * </tr>
3614     * <tr>
3615     * <td>long</td>
3616     * <td>{@link #STATUS_LABEL}</td>
3617     * <td>read/write</td>
3618     * <td>The resource ID of the label describing the source of contact status,
3619     * e.g. "Google Talk". This resource is scoped by the
3620     * {@link #STATUS_RES_PACKAGE}.</td>
3621     * </tr>
3622     * <tr>
3623     * <td>long</td>
3624     * <td>{@link #STATUS_ICON}</td>
3625     * <td>read/write</td>
3626     * <td>The resource ID of the icon for the source of contact status. This
3627     * resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
3628     * </tr>
3629     * </table>
3630     */
3631    public static class StatusUpdates implements StatusColumns, PresenceColumns {
3632
3633        /**
3634         * This utility class cannot be instantiated
3635         */
3636        private StatusUpdates() {}
3637
3638        /**
3639         * The content:// style URI for this table
3640         */
3641        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates");
3642
3643        /**
3644         * Gets the resource ID for the proper presence icon.
3645         *
3646         * @param status the status to get the icon for
3647         * @return the resource ID for the proper presence icon
3648         */
3649        public static final int getPresenceIconResourceId(int status) {
3650            switch (status) {
3651                case AVAILABLE:
3652                    return android.R.drawable.presence_online;
3653                case IDLE:
3654                case AWAY:
3655                    return android.R.drawable.presence_away;
3656                case DO_NOT_DISTURB:
3657                    return android.R.drawable.presence_busy;
3658                case INVISIBLE:
3659                    return android.R.drawable.presence_invisible;
3660                case OFFLINE:
3661                default:
3662                    return android.R.drawable.presence_offline;
3663            }
3664        }
3665
3666        /**
3667         * Returns the precedence of the status code the higher number being the higher precedence.
3668         *
3669         * @param status The status code.
3670         * @return An integer representing the precedence, 0 being the lowest.
3671         */
3672        public static final int getPresencePrecedence(int status) {
3673            // Keep this function here incase we want to enforce a different precedence than the
3674            // natural order of the status constants.
3675            return status;
3676        }
3677
3678        /**
3679         * The MIME type of {@link #CONTENT_URI} providing a directory of
3680         * status update details.
3681         */
3682        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/status-update";
3683
3684        /**
3685         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
3686         * status update detail.
3687         */
3688        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update";
3689    }
3690
3691    /**
3692     * @deprecated This old name was never meant to be made public. Do not use.
3693     */
3694    @Deprecated
3695    public static final class Presence extends StatusUpdates {
3696
3697    }
3698
3699    /**
3700     * Additional columns returned by the {@link Contacts#CONTENT_FILTER_URI} providing the
3701     * explanation of why the filter matched the contact.  Specifically, they contain the
3702     * data type and element that was used for matching.
3703     * <p>
3704     * This is temporary API, it will need to change when we move to FTS.
3705     *
3706     * @hide
3707     */
3708    public static class SearchSnippetColumns {
3709
3710        /**
3711         * The ID of the data row that was matched by the filter.
3712         *
3713         * @hide
3714         */
3715        public static final String SNIPPET_DATA_ID = "snippet_data_id";
3716
3717        /**
3718         * The type of data that was matched by the filter.
3719         *
3720         * @hide
3721         */
3722        public static final String SNIPPET_MIMETYPE = "snippet_mimetype";
3723
3724        /**
3725         * The {@link Data#DATA1} field of the data row that was matched by the filter.
3726         *
3727         * @hide
3728         */
3729        public static final String SNIPPET_DATA1 = "snippet_data1";
3730
3731        /**
3732         * The {@link Data#DATA2} field of the data row that was matched by the filter.
3733         *
3734         * @hide
3735         */
3736        public static final String SNIPPET_DATA2 = "snippet_data2";
3737
3738        /**
3739         * The {@link Data#DATA3} field of the data row that was matched by the filter.
3740         *
3741         * @hide
3742         */
3743        public static final String SNIPPET_DATA3 = "snippet_data3";
3744
3745        /**
3746         * The {@link Data#DATA4} field of the data row that was matched by the filter.
3747         *
3748         * @hide
3749         */
3750        public static final String SNIPPET_DATA4 = "snippet_data4";
3751
3752    }
3753
3754    /**
3755     * Container for definitions of common data types stored in the {@link ContactsContract.Data}
3756     * table.
3757     */
3758    public static final class CommonDataKinds {
3759        /**
3760         * This utility class cannot be instantiated
3761         */
3762        private CommonDataKinds() {}
3763
3764        /**
3765         * The {@link Data#RES_PACKAGE} value for common data that should be
3766         * shown using a default style.
3767         *
3768         * @hide RES_PACKAGE is hidden
3769         */
3770        public static final String PACKAGE_COMMON = "common";
3771
3772        /**
3773         * The base types that all "Typed" data kinds support.
3774         */
3775        public interface BaseTypes {
3776            /**
3777             * A custom type. The custom label should be supplied by user.
3778             */
3779            public static int TYPE_CUSTOM = 0;
3780        }
3781
3782        /**
3783         * Columns common across the specific types.
3784         */
3785        protected interface CommonColumns extends BaseTypes {
3786            /**
3787             * The data for the contact method.
3788             * <P>Type: TEXT</P>
3789             */
3790            public static final String DATA = DataColumns.DATA1;
3791
3792            /**
3793             * The type of data, for example Home or Work.
3794             * <P>Type: INTEGER</P>
3795             */
3796            public static final String TYPE = DataColumns.DATA2;
3797
3798            /**
3799             * The user defined label for the the contact method.
3800             * <P>Type: TEXT</P>
3801             */
3802            public static final String LABEL = DataColumns.DATA3;
3803        }
3804
3805        /**
3806         * A data kind representing the contact's proper name. You can use all
3807         * columns defined for {@link ContactsContract.Data} as well as the following aliases.
3808         *
3809         * <h2>Column aliases</h2>
3810         * <table class="jd-sumtable">
3811         * <tr>
3812         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
3813         * </tr>
3814         * <tr>
3815         * <td>String</td>
3816         * <td>{@link #DISPLAY_NAME}</td>
3817         * <td>{@link #DATA1}</td>
3818         * <td></td>
3819         * </tr>
3820         * <tr>
3821         * <td>String</td>
3822         * <td>{@link #GIVEN_NAME}</td>
3823         * <td>{@link #DATA2}</td>
3824         * <td></td>
3825         * </tr>
3826         * <tr>
3827         * <td>String</td>
3828         * <td>{@link #FAMILY_NAME}</td>
3829         * <td>{@link #DATA3}</td>
3830         * <td></td>
3831         * </tr>
3832         * <tr>
3833         * <td>String</td>
3834         * <td>{@link #PREFIX}</td>
3835         * <td>{@link #DATA4}</td>
3836         * <td>Common prefixes in English names are "Mr", "Ms", "Dr" etc.</td>
3837         * </tr>
3838         * <tr>
3839         * <td>String</td>
3840         * <td>{@link #MIDDLE_NAME}</td>
3841         * <td>{@link #DATA5}</td>
3842         * <td></td>
3843         * </tr>
3844         * <tr>
3845         * <td>String</td>
3846         * <td>{@link #SUFFIX}</td>
3847         * <td>{@link #DATA6}</td>
3848         * <td>Common suffixes in English names are "Sr", "Jr", "III" etc.</td>
3849         * </tr>
3850         * <tr>
3851         * <td>String</td>
3852         * <td>{@link #PHONETIC_GIVEN_NAME}</td>
3853         * <td>{@link #DATA7}</td>
3854         * <td>Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana</td>
3855         * </tr>
3856         * <tr>
3857         * <td>String</td>
3858         * <td>{@link #PHONETIC_MIDDLE_NAME}</td>
3859         * <td>{@link #DATA8}</td>
3860         * <td></td>
3861         * </tr>
3862         * <tr>
3863         * <td>String</td>
3864         * <td>{@link #PHONETIC_FAMILY_NAME}</td>
3865         * <td>{@link #DATA9}</td>
3866         * <td></td>
3867         * </tr>
3868         * </table>
3869         */
3870        public static final class StructuredName implements DataColumnsWithJoins {
3871            /**
3872             * This utility class cannot be instantiated
3873             */
3874            private StructuredName() {}
3875
3876            /** MIME type used when storing this in data table. */
3877            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
3878
3879            /**
3880             * The name that should be used to display the contact.
3881             * <i>Unstructured component of the name should be consistent with
3882             * its structured representation.</i>
3883             * <p>
3884             * Type: TEXT
3885             */
3886            public static final String DISPLAY_NAME = DATA1;
3887
3888            /**
3889             * The given name for the contact.
3890             * <P>Type: TEXT</P>
3891             */
3892            public static final String GIVEN_NAME = DATA2;
3893
3894            /**
3895             * The family name for the contact.
3896             * <P>Type: TEXT</P>
3897             */
3898            public static final String FAMILY_NAME = DATA3;
3899
3900            /**
3901             * The contact's honorific prefix, e.g. "Sir"
3902             * <P>Type: TEXT</P>
3903             */
3904            public static final String PREFIX = DATA4;
3905
3906            /**
3907             * The contact's middle name
3908             * <P>Type: TEXT</P>
3909             */
3910            public static final String MIDDLE_NAME = DATA5;
3911
3912            /**
3913             * The contact's honorific suffix, e.g. "Jr"
3914             */
3915            public static final String SUFFIX = DATA6;
3916
3917            /**
3918             * The phonetic version of the given name for the contact.
3919             * <P>Type: TEXT</P>
3920             */
3921            public static final String PHONETIC_GIVEN_NAME = DATA7;
3922
3923            /**
3924             * The phonetic version of the additional name for the contact.
3925             * <P>Type: TEXT</P>
3926             */
3927            public static final String PHONETIC_MIDDLE_NAME = DATA8;
3928
3929            /**
3930             * The phonetic version of the family name for the contact.
3931             * <P>Type: TEXT</P>
3932             */
3933            public static final String PHONETIC_FAMILY_NAME = DATA9;
3934
3935            /**
3936             * The style used for combining given/middle/family name into a full name.
3937             * See {@link ContactsContract.FullNameStyle}.
3938             *
3939             * @hide
3940             */
3941            public static final String FULL_NAME_STYLE = DATA10;
3942
3943            /**
3944             * The alphabet used for capturing the phonetic name.
3945             * See ContactsContract.PhoneticNameStyle.
3946             * @hide
3947             */
3948            public static final String PHONETIC_NAME_STYLE = DATA11;
3949        }
3950
3951        /**
3952         * <p>A data kind representing the contact's nickname. For example, for
3953         * Bob Parr ("Mr. Incredible"):
3954         * <pre>
3955         * ArrayList&lt;ContentProviderOperation&gt; ops = Lists.newArrayList();
3956         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
3957         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
3958         *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
3959         *          .withValue(StructuredName.DISPLAY_NAME, &quot;Bob Parr&quot;)
3960         *          .build());
3961         *
3962         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
3963         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
3964         *          .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
3965         *          .withValue(Nickname.NAME, "Mr. Incredible")
3966         *          .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM)
3967         *          .withValue(Nickname.LABEL, "Superhero")
3968         *          .build());
3969         *
3970         * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
3971         * </pre>
3972         * </p>
3973         * <p>
3974         * You can use all columns defined for {@link ContactsContract.Data} as well as the
3975         * following aliases.
3976         * </p>
3977         *
3978         * <h2>Column aliases</h2>
3979         * <table class="jd-sumtable">
3980         * <tr>
3981         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
3982         * </tr>
3983         * <tr>
3984         * <td>String</td>
3985         * <td>{@link #NAME}</td>
3986         * <td>{@link #DATA1}</td>
3987         * <td></td>
3988         * </tr>
3989         * <tr>
3990         * <td>int</td>
3991         * <td>{@link #TYPE}</td>
3992         * <td>{@link #DATA2}</td>
3993         * <td>
3994         * Allowed values are:
3995         * <p>
3996         * <ul>
3997         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
3998         * <li>{@link #TYPE_DEFAULT}</li>
3999         * <li>{@link #TYPE_OTHER_NAME}</li>
4000         * <li>{@link #TYPE_MAINDEN_NAME}</li>
4001         * <li>{@link #TYPE_SHORT_NAME}</li>
4002         * <li>{@link #TYPE_INITIALS}</li>
4003         * </ul>
4004         * </p>
4005         * </td>
4006         * </tr>
4007         * <tr>
4008         * <td>String</td>
4009         * <td>{@link #LABEL}</td>
4010         * <td>{@link #DATA3}</td>
4011         * <td></td>
4012         * </tr>
4013         * </table>
4014         */
4015        public static final class Nickname implements DataColumnsWithJoins, CommonColumns {
4016            /**
4017             * This utility class cannot be instantiated
4018             */
4019            private Nickname() {}
4020
4021            /** MIME type used when storing this in data table. */
4022            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
4023
4024            public static final int TYPE_DEFAULT = 1;
4025            public static final int TYPE_OTHER_NAME = 2;
4026            public static final int TYPE_MAINDEN_NAME = 3;
4027            public static final int TYPE_SHORT_NAME = 4;
4028            public static final int TYPE_INITIALS = 5;
4029
4030            /**
4031             * The name itself
4032             */
4033            public static final String NAME = DATA;
4034        }
4035
4036        /**
4037         * <p>
4038         * A data kind representing a telephone number.
4039         * </p>
4040         * <p>
4041         * You can use all columns defined for {@link ContactsContract.Data} as
4042         * well as the following aliases.
4043         * </p>
4044         * <h2>Column aliases</h2>
4045         * <table class="jd-sumtable">
4046         * <tr>
4047         * <th>Type</th>
4048         * <th>Alias</th><th colspan='2'>Data column</th>
4049         * </tr>
4050         * <tr>
4051         * <td>String</td>
4052         * <td>{@link #NUMBER}</td>
4053         * <td>{@link #DATA1}</td>
4054         * <td></td>
4055         * </tr>
4056         * <tr>
4057         * <td>int</td>
4058         * <td>{@link #TYPE}</td>
4059         * <td>{@link #DATA2}</td>
4060         * <td>Allowed values are:
4061         * <p>
4062         * <ul>
4063         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4064         * <li>{@link #TYPE_HOME}</li>
4065         * <li>{@link #TYPE_MOBILE}</li>
4066         * <li>{@link #TYPE_WORK}</li>
4067         * <li>{@link #TYPE_FAX_WORK}</li>
4068         * <li>{@link #TYPE_FAX_HOME}</li>
4069         * <li>{@link #TYPE_PAGER}</li>
4070         * <li>{@link #TYPE_OTHER}</li>
4071         * <li>{@link #TYPE_CALLBACK}</li>
4072         * <li>{@link #TYPE_CAR}</li>
4073         * <li>{@link #TYPE_COMPANY_MAIN}</li>
4074         * <li>{@link #TYPE_ISDN}</li>
4075         * <li>{@link #TYPE_MAIN}</li>
4076         * <li>{@link #TYPE_OTHER_FAX}</li>
4077         * <li>{@link #TYPE_RADIO}</li>
4078         * <li>{@link #TYPE_TELEX}</li>
4079         * <li>{@link #TYPE_TTY_TDD}</li>
4080         * <li>{@link #TYPE_WORK_MOBILE}</li>
4081         * <li>{@link #TYPE_WORK_PAGER}</li>
4082         * <li>{@link #TYPE_ASSISTANT}</li>
4083         * <li>{@link #TYPE_MMS}</li>
4084         * </ul>
4085         * </p>
4086         * </td>
4087         * </tr>
4088         * <tr>
4089         * <td>String</td>
4090         * <td>{@link #LABEL}</td>
4091         * <td>{@link #DATA3}</td>
4092         * <td></td>
4093         * </tr>
4094         * </table>
4095         */
4096        public static final class Phone implements DataColumnsWithJoins, CommonColumns {
4097            /**
4098             * This utility class cannot be instantiated
4099             */
4100            private Phone() {}
4101
4102            /** MIME type used when storing this in data table. */
4103            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2";
4104
4105            /**
4106             * The MIME type of {@link #CONTENT_URI} providing a directory of
4107             * phones.
4108             */
4109            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2";
4110
4111            /**
4112             * The content:// style URI for all data records of the
4113             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
4114             * associated raw contact and aggregate contact data.
4115             */
4116            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
4117                    "phones");
4118
4119            /**
4120             * The content:// style URL for phone lookup using a filter. The filter returns
4121             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
4122             * to display names as well as phone numbers. The filter argument should be passed
4123             * as an additional path segment after this URI.
4124             */
4125            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
4126                    "filter");
4127
4128            public static final int TYPE_HOME = 1;
4129            public static final int TYPE_MOBILE = 2;
4130            public static final int TYPE_WORK = 3;
4131            public static final int TYPE_FAX_WORK = 4;
4132            public static final int TYPE_FAX_HOME = 5;
4133            public static final int TYPE_PAGER = 6;
4134            public static final int TYPE_OTHER = 7;
4135            public static final int TYPE_CALLBACK = 8;
4136            public static final int TYPE_CAR = 9;
4137            public static final int TYPE_COMPANY_MAIN = 10;
4138            public static final int TYPE_ISDN = 11;
4139            public static final int TYPE_MAIN = 12;
4140            public static final int TYPE_OTHER_FAX = 13;
4141            public static final int TYPE_RADIO = 14;
4142            public static final int TYPE_TELEX = 15;
4143            public static final int TYPE_TTY_TDD = 16;
4144            public static final int TYPE_WORK_MOBILE = 17;
4145            public static final int TYPE_WORK_PAGER = 18;
4146            public static final int TYPE_ASSISTANT = 19;
4147            public static final int TYPE_MMS = 20;
4148
4149            /**
4150             * The phone number as the user entered it.
4151             * <P>Type: TEXT</P>
4152             */
4153            public static final String NUMBER = DATA;
4154
4155            /**
4156             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
4157             * @hide
4158             */
4159            @Deprecated
4160            public static final CharSequence getDisplayLabel(Context context, int type,
4161                    CharSequence label, CharSequence[] labelArray) {
4162                return getTypeLabel(context.getResources(), type, label);
4163            }
4164
4165            /**
4166             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
4167             * @hide
4168             */
4169            @Deprecated
4170            public static final CharSequence getDisplayLabel(Context context, int type,
4171                    CharSequence label) {
4172                return getTypeLabel(context.getResources(), type, label);
4173            }
4174
4175            /**
4176             * Return the string resource that best describes the given
4177             * {@link #TYPE}. Will always return a valid resource.
4178             */
4179            public static final int getTypeLabelResource(int type) {
4180                switch (type) {
4181                    case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome;
4182                    case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile;
4183                    case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork;
4184                    case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork;
4185                    case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome;
4186                    case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager;
4187                    case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther;
4188                    case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback;
4189                    case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar;
4190                    case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain;
4191                    case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn;
4192                    case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain;
4193                    case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax;
4194                    case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio;
4195                    case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex;
4196                    case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd;
4197                    case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile;
4198                    case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager;
4199                    case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant;
4200                    case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms;
4201                    default: return com.android.internal.R.string.phoneTypeCustom;
4202                }
4203            }
4204
4205            /**
4206             * Return a {@link CharSequence} that best describes the given type,
4207             * possibly substituting the given {@link #LABEL} value
4208             * for {@link #TYPE_CUSTOM}.
4209             */
4210            public static final CharSequence getTypeLabel(Resources res, int type,
4211                    CharSequence label) {
4212                if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) {
4213                    return label;
4214                } else {
4215                    final int labelRes = getTypeLabelResource(type);
4216                    return res.getText(labelRes);
4217                }
4218            }
4219        }
4220
4221        /**
4222         * <p>
4223         * A data kind representing an email address.
4224         * </p>
4225         * <p>
4226         * You can use all columns defined for {@link ContactsContract.Data} as
4227         * well as the following aliases.
4228         * </p>
4229         * <h2>Column aliases</h2>
4230         * <table class="jd-sumtable">
4231         * <tr>
4232         * <th>Type</th>
4233         * <th>Alias</th><th colspan='2'>Data column</th>
4234         * </tr>
4235         * <tr>
4236         * <td>String</td>
4237         * <td>{@link #DATA}</td>
4238         * <td>{@link #DATA1}</td>
4239         * <td>Email address itself.</td>
4240         * </tr>
4241         * <tr>
4242         * <td>int</td>
4243         * <td>{@link #TYPE}</td>
4244         * <td>{@link #DATA2}</td>
4245         * <td>Allowed values are:
4246         * <p>
4247         * <ul>
4248         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4249         * <li>{@link #TYPE_HOME}</li>
4250         * <li>{@link #TYPE_WORK}</li>
4251         * <li>{@link #TYPE_OTHER}</li>
4252         * <li>{@link #TYPE_MOBILE}</li>
4253         * </ul>
4254         * </p>
4255         * </td>
4256         * </tr>
4257         * <tr>
4258         * <td>String</td>
4259         * <td>{@link #LABEL}</td>
4260         * <td>{@link #DATA3}</td>
4261         * <td></td>
4262         * </tr>
4263         * </table>
4264         */
4265        public static final class Email implements DataColumnsWithJoins, CommonColumns {
4266            /**
4267             * This utility class cannot be instantiated
4268             */
4269            private Email() {}
4270
4271            /** MIME type used when storing this in data table. */
4272            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
4273
4274            /**
4275             * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses.
4276             */
4277            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";
4278
4279            /**
4280             * The content:// style URI for all data records of the
4281             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
4282             * associated raw contact and aggregate contact data.
4283             */
4284            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
4285                    "emails");
4286
4287            /**
4288             * <p>
4289             * The content:// style URL for looking up data rows by email address. The
4290             * lookup argument, an email address, should be passed as an additional path segment
4291             * after this URI.
4292             * </p>
4293             * <p>Example:
4294             * <pre>
4295             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email));
4296             * Cursor c = getContentResolver().query(uri,
4297             *          new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
4298             *          null, null, null);
4299             * </pre>
4300             * </p>
4301             */
4302            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
4303                    "lookup");
4304
4305            /**
4306             * <p>
4307             * The content:// style URL for email lookup using a filter. The filter returns
4308             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
4309             * to display names as well as email addresses. The filter argument should be passed
4310             * as an additional path segment after this URI.
4311             * </p>
4312             * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)"
4313             * as well as "Bob Parr (incredible@android.com)".
4314             * <pre>
4315             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
4316             * Cursor c = getContentResolver().query(uri,
4317             *          new String[]{Email.DISPLAY_NAME, Email.DATA},
4318             *          null, null, null);
4319             * </pre>
4320             * </p>
4321             */
4322            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
4323                    "filter");
4324
4325            /**
4326             * The email address.
4327             * <P>Type: TEXT</P>
4328             */
4329            public static final String ADDRESS = DATA1;
4330
4331            public static final int TYPE_HOME = 1;
4332            public static final int TYPE_WORK = 2;
4333            public static final int TYPE_OTHER = 3;
4334            public static final int TYPE_MOBILE = 4;
4335
4336            /**
4337             * The display name for the email address
4338             * <P>Type: TEXT</P>
4339             */
4340            public static final String DISPLAY_NAME = DATA4;
4341
4342            /**
4343             * Return the string resource that best describes the given
4344             * {@link #TYPE}. Will always return a valid resource.
4345             */
4346            public static final int getTypeLabelResource(int type) {
4347                switch (type) {
4348                    case TYPE_HOME: return com.android.internal.R.string.emailTypeHome;
4349                    case TYPE_WORK: return com.android.internal.R.string.emailTypeWork;
4350                    case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther;
4351                    case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile;
4352                    default: return com.android.internal.R.string.emailTypeCustom;
4353                }
4354            }
4355
4356            /**
4357             * Return a {@link CharSequence} that best describes the given type,
4358             * possibly substituting the given {@link #LABEL} value
4359             * for {@link #TYPE_CUSTOM}.
4360             */
4361            public static final CharSequence getTypeLabel(Resources res, int type,
4362                    CharSequence label) {
4363                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4364                    return label;
4365                } else {
4366                    final int labelRes = getTypeLabelResource(type);
4367                    return res.getText(labelRes);
4368                }
4369            }
4370        }
4371
4372        /**
4373         * <p>
4374         * A data kind representing a postal addresses.
4375         * </p>
4376         * <p>
4377         * You can use all columns defined for {@link ContactsContract.Data} as
4378         * well as the following aliases.
4379         * </p>
4380         * <h2>Column aliases</h2>
4381         * <table class="jd-sumtable">
4382         * <tr>
4383         * <th>Type</th>
4384         * <th>Alias</th><th colspan='2'>Data column</th>
4385         * </tr>
4386         * <tr>
4387         * <td>String</td>
4388         * <td>{@link #FORMATTED_ADDRESS}</td>
4389         * <td>{@link #DATA1}</td>
4390         * <td></td>
4391         * </tr>
4392         * <tr>
4393         * <td>int</td>
4394         * <td>{@link #TYPE}</td>
4395         * <td>{@link #DATA2}</td>
4396         * <td>Allowed values are:
4397         * <p>
4398         * <ul>
4399         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4400         * <li>{@link #TYPE_HOME}</li>
4401         * <li>{@link #TYPE_WORK}</li>
4402         * <li>{@link #TYPE_OTHER}</li>
4403         * </ul>
4404         * </p>
4405         * </td>
4406         * </tr>
4407         * <tr>
4408         * <td>String</td>
4409         * <td>{@link #LABEL}</td>
4410         * <td>{@link #DATA3}</td>
4411         * <td></td>
4412         * </tr>
4413         * <tr>
4414         * <td>String</td>
4415         * <td>{@link #STREET}</td>
4416         * <td>{@link #DATA4}</td>
4417         * <td></td>
4418         * </tr>
4419         * <tr>
4420         * <td>String</td>
4421         * <td>{@link #POBOX}</td>
4422         * <td>{@link #DATA5}</td>
4423         * <td>Post Office Box number</td>
4424         * </tr>
4425         * <tr>
4426         * <td>String</td>
4427         * <td>{@link #NEIGHBORHOOD}</td>
4428         * <td>{@link #DATA6}</td>
4429         * <td></td>
4430         * </tr>
4431         * <tr>
4432         * <td>String</td>
4433         * <td>{@link #CITY}</td>
4434         * <td>{@link #DATA7}</td>
4435         * <td></td>
4436         * </tr>
4437         * <tr>
4438         * <td>String</td>
4439         * <td>{@link #REGION}</td>
4440         * <td>{@link #DATA8}</td>
4441         * <td></td>
4442         * </tr>
4443         * <tr>
4444         * <td>String</td>
4445         * <td>{@link #POSTCODE}</td>
4446         * <td>{@link #DATA9}</td>
4447         * <td></td>
4448         * </tr>
4449         * <tr>
4450         * <td>String</td>
4451         * <td>{@link #COUNTRY}</td>
4452         * <td>{@link #DATA10}</td>
4453         * <td></td>
4454         * </tr>
4455         * </table>
4456         */
4457        public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns {
4458            /**
4459             * This utility class cannot be instantiated
4460             */
4461            private StructuredPostal() {
4462            }
4463
4464            /** MIME type used when storing this in data table. */
4465            public static final String CONTENT_ITEM_TYPE =
4466                    "vnd.android.cursor.item/postal-address_v2";
4467
4468            /**
4469             * The MIME type of {@link #CONTENT_URI} providing a directory of
4470             * postal addresses.
4471             */
4472            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
4473
4474            /**
4475             * The content:// style URI for all data records of the
4476             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
4477             */
4478            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
4479                    "postals");
4480
4481            public static final int TYPE_HOME = 1;
4482            public static final int TYPE_WORK = 2;
4483            public static final int TYPE_OTHER = 3;
4484
4485            /**
4486             * The full, unstructured postal address. <i>This field must be
4487             * consistent with any structured data.</i>
4488             * <p>
4489             * Type: TEXT
4490             */
4491            public static final String FORMATTED_ADDRESS = DATA;
4492
4493            /**
4494             * Can be street, avenue, road, etc. This element also includes the
4495             * house number and room/apartment/flat/floor number.
4496             * <p>
4497             * Type: TEXT
4498             */
4499            public static final String STREET = DATA4;
4500
4501            /**
4502             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
4503             * usually but not always mutually exclusive with street.
4504             * <p>
4505             * Type: TEXT
4506             */
4507            public static final String POBOX = DATA5;
4508
4509            /**
4510             * This is used to disambiguate a street address when a city
4511             * contains more than one street with the same name, or to specify a
4512             * small place whose mail is routed through a larger postal town. In
4513             * China it could be a county or a minor city.
4514             * <p>
4515             * Type: TEXT
4516             */
4517            public static final String NEIGHBORHOOD = DATA6;
4518
4519            /**
4520             * Can be city, village, town, borough, etc. This is the postal town
4521             * and not necessarily the place of residence or place of business.
4522             * <p>
4523             * Type: TEXT
4524             */
4525            public static final String CITY = DATA7;
4526
4527            /**
4528             * A state, province, county (in Ireland), Land (in Germany),
4529             * departement (in France), etc.
4530             * <p>
4531             * Type: TEXT
4532             */
4533            public static final String REGION = DATA8;
4534
4535            /**
4536             * Postal code. Usually country-wide, but sometimes specific to the
4537             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
4538             * <p>
4539             * Type: TEXT
4540             */
4541            public static final String POSTCODE = DATA9;
4542
4543            /**
4544             * The name or code of the country.
4545             * <p>
4546             * Type: TEXT
4547             */
4548            public static final String COUNTRY = DATA10;
4549
4550            /**
4551             * Return the string resource that best describes the given
4552             * {@link #TYPE}. Will always return a valid resource.
4553             */
4554            public static final int getTypeLabelResource(int type) {
4555                switch (type) {
4556                    case TYPE_HOME: return com.android.internal.R.string.postalTypeHome;
4557                    case TYPE_WORK: return com.android.internal.R.string.postalTypeWork;
4558                    case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther;
4559                    default: return com.android.internal.R.string.postalTypeCustom;
4560                }
4561            }
4562
4563            /**
4564             * Return a {@link CharSequence} that best describes the given type,
4565             * possibly substituting the given {@link #LABEL} value
4566             * for {@link #TYPE_CUSTOM}.
4567             */
4568            public static final CharSequence getTypeLabel(Resources res, int type,
4569                    CharSequence label) {
4570                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4571                    return label;
4572                } else {
4573                    final int labelRes = getTypeLabelResource(type);
4574                    return res.getText(labelRes);
4575                }
4576            }
4577        }
4578
4579        /**
4580         * <p>
4581         * A data kind representing an IM address
4582         * </p>
4583         * <p>
4584         * You can use all columns defined for {@link ContactsContract.Data} as
4585         * well as the following aliases.
4586         * </p>
4587         * <h2>Column aliases</h2>
4588         * <table class="jd-sumtable">
4589         * <tr>
4590         * <th>Type</th>
4591         * <th>Alias</th><th colspan='2'>Data column</th>
4592         * </tr>
4593         * <tr>
4594         * <td>String</td>
4595         * <td>{@link #DATA}</td>
4596         * <td>{@link #DATA1}</td>
4597         * <td></td>
4598         * </tr>
4599         * <tr>
4600         * <td>int</td>
4601         * <td>{@link #TYPE}</td>
4602         * <td>{@link #DATA2}</td>
4603         * <td>Allowed values are:
4604         * <p>
4605         * <ul>
4606         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4607         * <li>{@link #TYPE_HOME}</li>
4608         * <li>{@link #TYPE_WORK}</li>
4609         * <li>{@link #TYPE_OTHER}</li>
4610         * </ul>
4611         * </p>
4612         * </td>
4613         * </tr>
4614         * <tr>
4615         * <td>String</td>
4616         * <td>{@link #LABEL}</td>
4617         * <td>{@link #DATA3}</td>
4618         * <td></td>
4619         * </tr>
4620         * <tr>
4621         * <td>String</td>
4622         * <td>{@link #PROTOCOL}</td>
4623         * <td>{@link #DATA5}</td>
4624         * <td>
4625         * <p>
4626         * Allowed values:
4627         * <ul>
4628         * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name
4629         * as {@link #CUSTOM_PROTOCOL}.</li>
4630         * <li>{@link #PROTOCOL_AIM}</li>
4631         * <li>{@link #PROTOCOL_MSN}</li>
4632         * <li>{@link #PROTOCOL_YAHOO}</li>
4633         * <li>{@link #PROTOCOL_SKYPE}</li>
4634         * <li>{@link #PROTOCOL_QQ}</li>
4635         * <li>{@link #PROTOCOL_GOOGLE_TALK}</li>
4636         * <li>{@link #PROTOCOL_ICQ}</li>
4637         * <li>{@link #PROTOCOL_JABBER}</li>
4638         * <li>{@link #PROTOCOL_NETMEETING}</li>
4639         * </ul>
4640         * </p>
4641         * </td>
4642         * </tr>
4643         * <tr>
4644         * <td>String</td>
4645         * <td>{@link #CUSTOM_PROTOCOL}</td>
4646         * <td>{@link #DATA6}</td>
4647         * <td></td>
4648         * </tr>
4649         * </table>
4650         */
4651        public static final class Im implements DataColumnsWithJoins, CommonColumns {
4652            /**
4653             * This utility class cannot be instantiated
4654             */
4655            private Im() {}
4656
4657            /** MIME type used when storing this in data table. */
4658            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
4659
4660            public static final int TYPE_HOME = 1;
4661            public static final int TYPE_WORK = 2;
4662            public static final int TYPE_OTHER = 3;
4663
4664            /**
4665             * This column should be populated with one of the defined
4666             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
4667             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
4668             * should contain the name of the custom protocol.
4669             */
4670            public static final String PROTOCOL = DATA5;
4671
4672            public static final String CUSTOM_PROTOCOL = DATA6;
4673
4674            /*
4675             * The predefined IM protocol types.
4676             */
4677            public static final int PROTOCOL_CUSTOM = -1;
4678            public static final int PROTOCOL_AIM = 0;
4679            public static final int PROTOCOL_MSN = 1;
4680            public static final int PROTOCOL_YAHOO = 2;
4681            public static final int PROTOCOL_SKYPE = 3;
4682            public static final int PROTOCOL_QQ = 4;
4683            public static final int PROTOCOL_GOOGLE_TALK = 5;
4684            public static final int PROTOCOL_ICQ = 6;
4685            public static final int PROTOCOL_JABBER = 7;
4686            public static final int PROTOCOL_NETMEETING = 8;
4687
4688            /**
4689             * Return the string resource that best describes the given
4690             * {@link #TYPE}. Will always return a valid resource.
4691             */
4692            public static final int getTypeLabelResource(int type) {
4693                switch (type) {
4694                    case TYPE_HOME: return com.android.internal.R.string.imTypeHome;
4695                    case TYPE_WORK: return com.android.internal.R.string.imTypeWork;
4696                    case TYPE_OTHER: return com.android.internal.R.string.imTypeOther;
4697                    default: return com.android.internal.R.string.imTypeCustom;
4698                }
4699            }
4700
4701            /**
4702             * Return a {@link CharSequence} that best describes the given type,
4703             * possibly substituting the given {@link #LABEL} value
4704             * for {@link #TYPE_CUSTOM}.
4705             */
4706            public static final CharSequence getTypeLabel(Resources res, int type,
4707                    CharSequence label) {
4708                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4709                    return label;
4710                } else {
4711                    final int labelRes = getTypeLabelResource(type);
4712                    return res.getText(labelRes);
4713                }
4714            }
4715
4716            /**
4717             * Return the string resource that best describes the given
4718             * {@link #PROTOCOL}. Will always return a valid resource.
4719             */
4720            public static final int getProtocolLabelResource(int type) {
4721                switch (type) {
4722                    case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim;
4723                    case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn;
4724                    case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo;
4725                    case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype;
4726                    case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq;
4727                    case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk;
4728                    case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq;
4729                    case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber;
4730                    case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting;
4731                    default: return com.android.internal.R.string.imProtocolCustom;
4732                }
4733            }
4734
4735            /**
4736             * Return a {@link CharSequence} that best describes the given
4737             * protocol, possibly substituting the given
4738             * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}.
4739             */
4740            public static final CharSequence getProtocolLabel(Resources res, int type,
4741                    CharSequence label) {
4742                if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) {
4743                    return label;
4744                } else {
4745                    final int labelRes = getProtocolLabelResource(type);
4746                    return res.getText(labelRes);
4747                }
4748            }
4749        }
4750
4751        /**
4752         * <p>
4753         * A data kind representing an organization.
4754         * </p>
4755         * <p>
4756         * You can use all columns defined for {@link ContactsContract.Data} as
4757         * well as the following aliases.
4758         * </p>
4759         * <h2>Column aliases</h2>
4760         * <table class="jd-sumtable">
4761         * <tr>
4762         * <th>Type</th>
4763         * <th>Alias</th><th colspan='2'>Data column</th>
4764         * </tr>
4765         * <tr>
4766         * <td>String</td>
4767         * <td>{@link #COMPANY}</td>
4768         * <td>{@link #DATA1}</td>
4769         * <td></td>
4770         * </tr>
4771         * <tr>
4772         * <td>int</td>
4773         * <td>{@link #TYPE}</td>
4774         * <td>{@link #DATA2}</td>
4775         * <td>Allowed values are:
4776         * <p>
4777         * <ul>
4778         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4779         * <li>{@link #TYPE_WORK}</li>
4780         * <li>{@link #TYPE_OTHER}</li>
4781         * </ul>
4782         * </p>
4783         * </td>
4784         * </tr>
4785         * <tr>
4786         * <td>String</td>
4787         * <td>{@link #LABEL}</td>
4788         * <td>{@link #DATA3}</td>
4789         * <td></td>
4790         * </tr>
4791         * <tr>
4792         * <td>String</td>
4793         * <td>{@link #TITLE}</td>
4794         * <td>{@link #DATA4}</td>
4795         * <td></td>
4796         * </tr>
4797         * <tr>
4798         * <td>String</td>
4799         * <td>{@link #DEPARTMENT}</td>
4800         * <td>{@link #DATA5}</td>
4801         * <td></td>
4802         * </tr>
4803         * <tr>
4804         * <td>String</td>
4805         * <td>{@link #JOB_DESCRIPTION}</td>
4806         * <td>{@link #DATA6}</td>
4807         * <td></td>
4808         * </tr>
4809         * <tr>
4810         * <td>String</td>
4811         * <td>{@link #SYMBOL}</td>
4812         * <td>{@link #DATA7}</td>
4813         * <td></td>
4814         * </tr>
4815         * <tr>
4816         * <td>String</td>
4817         * <td>{@link #PHONETIC_NAME}</td>
4818         * <td>{@link #DATA8}</td>
4819         * <td></td>
4820         * </tr>
4821         * <tr>
4822         * <td>String</td>
4823         * <td>{@link #OFFICE_LOCATION}</td>
4824         * <td>{@link #DATA9}</td>
4825         * <td></td>
4826         * </tr>
4827         * <tr>
4828         * <td>String</td>
4829         * <td>PHONETIC_NAME_STYLE</td>
4830         * <td>{@link #DATA10}</td>
4831         * <td></td>
4832         * </tr>
4833         * </table>
4834         */
4835        public static final class Organization implements DataColumnsWithJoins, CommonColumns {
4836            /**
4837             * This utility class cannot be instantiated
4838             */
4839            private Organization() {}
4840
4841            /** MIME type used when storing this in data table. */
4842            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
4843
4844            public static final int TYPE_WORK = 1;
4845            public static final int TYPE_OTHER = 2;
4846
4847            /**
4848             * The company as the user entered it.
4849             * <P>Type: TEXT</P>
4850             */
4851            public static final String COMPANY = DATA;
4852
4853            /**
4854             * The position title at this company as the user entered it.
4855             * <P>Type: TEXT</P>
4856             */
4857            public static final String TITLE = DATA4;
4858
4859            /**
4860             * The department at this company as the user entered it.
4861             * <P>Type: TEXT</P>
4862             */
4863            public static final String DEPARTMENT = DATA5;
4864
4865            /**
4866             * The job description at this company as the user entered it.
4867             * <P>Type: TEXT</P>
4868             */
4869            public static final String JOB_DESCRIPTION = DATA6;
4870
4871            /**
4872             * The symbol of this company as the user entered it.
4873             * <P>Type: TEXT</P>
4874             */
4875            public static final String SYMBOL = DATA7;
4876
4877            /**
4878             * The phonetic name of this company as the user entered it.
4879             * <P>Type: TEXT</P>
4880             */
4881            public static final String PHONETIC_NAME = DATA8;
4882
4883            /**
4884             * The office location of this organization.
4885             * <P>Type: TEXT</P>
4886             */
4887            public static final String OFFICE_LOCATION = DATA9;
4888
4889            /**
4890             * The alphabet used for capturing the phonetic name.
4891             * See {@link ContactsContract.PhoneticNameStyle}.
4892             * @hide
4893             */
4894            public static final String PHONETIC_NAME_STYLE = DATA10;
4895
4896            /**
4897             * Return the string resource that best describes the given
4898             * {@link #TYPE}. Will always return a valid resource.
4899             */
4900            public static final int getTypeLabelResource(int type) {
4901                switch (type) {
4902                    case TYPE_WORK: return com.android.internal.R.string.orgTypeWork;
4903                    case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther;
4904                    default: return com.android.internal.R.string.orgTypeCustom;
4905                }
4906            }
4907
4908            /**
4909             * Return a {@link CharSequence} that best describes the given type,
4910             * possibly substituting the given {@link #LABEL} value
4911             * for {@link #TYPE_CUSTOM}.
4912             */
4913            public static final CharSequence getTypeLabel(Resources res, int type,
4914                    CharSequence label) {
4915                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
4916                    return label;
4917                } else {
4918                    final int labelRes = getTypeLabelResource(type);
4919                    return res.getText(labelRes);
4920                }
4921            }
4922        }
4923
4924        /**
4925         * <p>
4926         * A data kind representing a relation.
4927         * </p>
4928         * <p>
4929         * You can use all columns defined for {@link ContactsContract.Data} as
4930         * well as the following aliases.
4931         * </p>
4932         * <h2>Column aliases</h2>
4933         * <table class="jd-sumtable">
4934         * <tr>
4935         * <th>Type</th>
4936         * <th>Alias</th><th colspan='2'>Data column</th>
4937         * </tr>
4938         * <tr>
4939         * <td>String</td>
4940         * <td>{@link #NAME}</td>
4941         * <td>{@link #DATA1}</td>
4942         * <td></td>
4943         * </tr>
4944         * <tr>
4945         * <td>int</td>
4946         * <td>{@link #TYPE}</td>
4947         * <td>{@link #DATA2}</td>
4948         * <td>Allowed values are:
4949         * <p>
4950         * <ul>
4951         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
4952         * <li>{@link #TYPE_ASSISTANT}</li>
4953         * <li>{@link #TYPE_BROTHER}</li>
4954         * <li>{@link #TYPE_CHILD}</li>
4955         * <li>{@link #TYPE_DOMESTIC_PARTNER}</li>
4956         * <li>{@link #TYPE_FATHER}</li>
4957         * <li>{@link #TYPE_FRIEND}</li>
4958         * <li>{@link #TYPE_MANAGER}</li>
4959         * <li>{@link #TYPE_MOTHER}</li>
4960         * <li>{@link #TYPE_PARENT}</li>
4961         * <li>{@link #TYPE_PARTNER}</li>
4962         * <li>{@link #TYPE_REFERRED_BY}</li>
4963         * <li>{@link #TYPE_RELATIVE}</li>
4964         * <li>{@link #TYPE_SISTER}</li>
4965         * <li>{@link #TYPE_SPOUSE}</li>
4966         * </ul>
4967         * </p>
4968         * </td>
4969         * </tr>
4970         * <tr>
4971         * <td>String</td>
4972         * <td>{@link #LABEL}</td>
4973         * <td>{@link #DATA3}</td>
4974         * <td></td>
4975         * </tr>
4976         * </table>
4977         */
4978        public static final class Relation implements DataColumnsWithJoins, CommonColumns {
4979            /**
4980             * This utility class cannot be instantiated
4981             */
4982            private Relation() {}
4983
4984            /** MIME type used when storing this in data table. */
4985            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
4986
4987            public static final int TYPE_ASSISTANT = 1;
4988            public static final int TYPE_BROTHER = 2;
4989            public static final int TYPE_CHILD = 3;
4990            public static final int TYPE_DOMESTIC_PARTNER = 4;
4991            public static final int TYPE_FATHER = 5;
4992            public static final int TYPE_FRIEND = 6;
4993            public static final int TYPE_MANAGER = 7;
4994            public static final int TYPE_MOTHER = 8;
4995            public static final int TYPE_PARENT = 9;
4996            public static final int TYPE_PARTNER = 10;
4997            public static final int TYPE_REFERRED_BY = 11;
4998            public static final int TYPE_RELATIVE = 12;
4999            public static final int TYPE_SISTER = 13;
5000            public static final int TYPE_SPOUSE = 14;
5001
5002            /**
5003             * The name of the relative as the user entered it.
5004             * <P>Type: TEXT</P>
5005             */
5006            public static final String NAME = DATA;
5007        }
5008
5009        /**
5010         * <p>
5011         * A data kind representing an event.
5012         * </p>
5013         * <p>
5014         * You can use all columns defined for {@link ContactsContract.Data} as
5015         * well as the following aliases.
5016         * </p>
5017         * <h2>Column aliases</h2>
5018         * <table class="jd-sumtable">
5019         * <tr>
5020         * <th>Type</th>
5021         * <th>Alias</th><th colspan='2'>Data column</th>
5022         * </tr>
5023         * <tr>
5024         * <td>String</td>
5025         * <td>{@link #START_DATE}</td>
5026         * <td>{@link #DATA1}</td>
5027         * <td></td>
5028         * </tr>
5029         * <tr>
5030         * <td>int</td>
5031         * <td>{@link #TYPE}</td>
5032         * <td>{@link #DATA2}</td>
5033         * <td>Allowed values are:
5034         * <p>
5035         * <ul>
5036         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5037         * <li>{@link #TYPE_ANNIVERSARY}</li>
5038         * <li>{@link #TYPE_OTHER}</li>
5039         * <li>{@link #TYPE_BIRTHDAY}</li>
5040         * </ul>
5041         * </p>
5042         * </td>
5043         * </tr>
5044         * <tr>
5045         * <td>String</td>
5046         * <td>{@link #LABEL}</td>
5047         * <td>{@link #DATA3}</td>
5048         * <td></td>
5049         * </tr>
5050         * </table>
5051         */
5052        public static final class Event implements DataColumnsWithJoins, CommonColumns {
5053            /**
5054             * This utility class cannot be instantiated
5055             */
5056            private Event() {}
5057
5058            /** MIME type used when storing this in data table. */
5059            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event";
5060
5061            public static final int TYPE_ANNIVERSARY = 1;
5062            public static final int TYPE_OTHER = 2;
5063            public static final int TYPE_BIRTHDAY = 3;
5064
5065            /**
5066             * The event start date as the user entered it.
5067             * <P>Type: TEXT</P>
5068             */
5069            public static final String START_DATE = DATA;
5070
5071            /**
5072             * Return the string resource that best describes the given
5073             * {@link #TYPE}. Will always return a valid resource.
5074             */
5075            public static int getTypeResource(Integer type) {
5076                if (type == null) {
5077                    return com.android.internal.R.string.eventTypeOther;
5078                }
5079                switch (type) {
5080                    case TYPE_ANNIVERSARY:
5081                        return com.android.internal.R.string.eventTypeAnniversary;
5082                    case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday;
5083                    case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther;
5084                    default: return com.android.internal.R.string.eventTypeOther;
5085                }
5086            }
5087        }
5088
5089        /**
5090         * <p>
5091         * A data kind representing an photo for the contact.
5092         * </p>
5093         * <p>
5094         * Some sync adapters will choose to download photos in a separate
5095         * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1}
5096         * through {@link ContactsContract.Data#SYNC4} to store temporary
5097         * data, e.g. the image URL or ID, state of download, server-side version
5098         * of the image.  It is allowed for the {@link #PHOTO} to be null.
5099         * </p>
5100         * <p>
5101         * You can use all columns defined for {@link ContactsContract.Data} as
5102         * well as the following aliases.
5103         * </p>
5104         * <h2>Column aliases</h2>
5105         * <table class="jd-sumtable">
5106         * <tr>
5107         * <th>Type</th>
5108         * <th>Alias</th><th colspan='2'>Data column</th>
5109         * </tr>
5110         * <tr>
5111         * <td>BLOB</td>
5112         * <td>{@link #PHOTO}</td>
5113         * <td>{@link #DATA15}</td>
5114         * <td>By convention, binary data is stored in DATA15.</td>
5115         * </tr>
5116         * </table>
5117         */
5118        public static final class Photo implements DataColumnsWithJoins {
5119            /**
5120             * This utility class cannot be instantiated
5121             */
5122            private Photo() {}
5123
5124            /** MIME type used when storing this in data table. */
5125            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
5126
5127            /**
5128             * Thumbnail photo of the raw contact. This is the raw bytes of an image
5129             * that could be inflated using {@link android.graphics.BitmapFactory}.
5130             * <p>
5131             * Type: BLOB
5132             */
5133            public static final String PHOTO = DATA15;
5134        }
5135
5136        /**
5137         * <p>
5138         * Notes about the contact.
5139         * </p>
5140         * <p>
5141         * You can use all columns defined for {@link ContactsContract.Data} as
5142         * well as the following aliases.
5143         * </p>
5144         * <h2>Column aliases</h2>
5145         * <table class="jd-sumtable">
5146         * <tr>
5147         * <th>Type</th>
5148         * <th>Alias</th><th colspan='2'>Data column</th>
5149         * </tr>
5150         * <tr>
5151         * <td>String</td>
5152         * <td>{@link #NOTE}</td>
5153         * <td>{@link #DATA1}</td>
5154         * <td></td>
5155         * </tr>
5156         * </table>
5157         */
5158        public static final class Note implements DataColumnsWithJoins {
5159            /**
5160             * This utility class cannot be instantiated
5161             */
5162            private Note() {}
5163
5164            /** MIME type used when storing this in data table. */
5165            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
5166
5167            /**
5168             * The note text.
5169             * <P>Type: TEXT</P>
5170             */
5171            public static final String NOTE = DATA1;
5172        }
5173
5174        /**
5175         * <p>
5176         * Group Membership.
5177         * </p>
5178         * <p>
5179         * You can use all columns defined for {@link ContactsContract.Data} as
5180         * well as the following aliases.
5181         * </p>
5182         * <h2>Column aliases</h2>
5183         * <table class="jd-sumtable">
5184         * <tr>
5185         * <th>Type</th>
5186         * <th>Alias</th><th colspan='2'>Data column</th>
5187         * </tr>
5188         * <tr>
5189         * <td>long</td>
5190         * <td>{@link #GROUP_ROW_ID}</td>
5191         * <td>{@link #DATA1}</td>
5192         * <td></td>
5193         * </tr>
5194         * <tr>
5195         * <td>String</td>
5196         * <td>{@link #GROUP_SOURCE_ID}</td>
5197         * <td>none</td>
5198         * <td>
5199         * <p>
5200         * The sourceid of the group that this group membership refers to.
5201         * Exactly one of this or {@link #GROUP_ROW_ID} must be set when
5202         * inserting a row.
5203         * </p>
5204         * <p>
5205         * If this field is specified, the provider will first try to
5206         * look up a group with this {@link Groups Groups.SOURCE_ID}.  If such a group
5207         * is found, it will use the corresponding row id.  If the group is not
5208         * found, it will create one.
5209         * </td>
5210         * </tr>
5211         * </table>
5212         */
5213        public static final class GroupMembership implements DataColumnsWithJoins {
5214            /**
5215             * This utility class cannot be instantiated
5216             */
5217            private GroupMembership() {}
5218
5219            /** MIME type used when storing this in data table. */
5220            public static final String CONTENT_ITEM_TYPE =
5221                    "vnd.android.cursor.item/group_membership";
5222
5223            /**
5224             * The row id of the group that this group membership refers to. Exactly one of
5225             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
5226             * <P>Type: INTEGER</P>
5227             */
5228            public static final String GROUP_ROW_ID = DATA1;
5229
5230            /**
5231             * The sourceid of the group that this group membership refers to.  Exactly one of
5232             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
5233             * <P>Type: TEXT</P>
5234             */
5235            public static final String GROUP_SOURCE_ID = "group_sourceid";
5236        }
5237
5238        /**
5239         * <p>
5240         * A data kind representing a website related to the contact.
5241         * </p>
5242         * <p>
5243         * You can use all columns defined for {@link ContactsContract.Data} as
5244         * well as the following aliases.
5245         * </p>
5246         * <h2>Column aliases</h2>
5247         * <table class="jd-sumtable">
5248         * <tr>
5249         * <th>Type</th>
5250         * <th>Alias</th><th colspan='2'>Data column</th>
5251         * </tr>
5252         * <tr>
5253         * <td>String</td>
5254         * <td>{@link #URL}</td>
5255         * <td>{@link #DATA1}</td>
5256         * <td></td>
5257         * </tr>
5258         * <tr>
5259         * <td>int</td>
5260         * <td>{@link #TYPE}</td>
5261         * <td>{@link #DATA2}</td>
5262         * <td>Allowed values are:
5263         * <p>
5264         * <ul>
5265         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5266         * <li>{@link #TYPE_HOMEPAGE}</li>
5267         * <li>{@link #TYPE_BLOG}</li>
5268         * <li>{@link #TYPE_PROFILE}</li>
5269         * <li>{@link #TYPE_HOME}</li>
5270         * <li>{@link #TYPE_WORK}</li>
5271         * <li>{@link #TYPE_FTP}</li>
5272         * <li>{@link #TYPE_OTHER}</li>
5273         * </ul>
5274         * </p>
5275         * </td>
5276         * </tr>
5277         * <tr>
5278         * <td>String</td>
5279         * <td>{@link #LABEL}</td>
5280         * <td>{@link #DATA3}</td>
5281         * <td></td>
5282         * </tr>
5283         * </table>
5284         */
5285        public static final class Website implements DataColumnsWithJoins, CommonColumns {
5286            /**
5287             * This utility class cannot be instantiated
5288             */
5289            private Website() {}
5290
5291            /** MIME type used when storing this in data table. */
5292            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
5293
5294            public static final int TYPE_HOMEPAGE = 1;
5295            public static final int TYPE_BLOG = 2;
5296            public static final int TYPE_PROFILE = 3;
5297            public static final int TYPE_HOME = 4;
5298            public static final int TYPE_WORK = 5;
5299            public static final int TYPE_FTP = 6;
5300            public static final int TYPE_OTHER = 7;
5301
5302            /**
5303             * The website URL string.
5304             * <P>Type: TEXT</P>
5305             */
5306            public static final String URL = DATA;
5307        }
5308
5309        /**
5310         * <p>
5311         * A data kind representing a SIP address for the contact.
5312         * </p>
5313         * <p>
5314         * You can use all columns defined for {@link ContactsContract.Data} as
5315         * well as the following aliases.
5316         * </p>
5317         * <h2>Column aliases</h2>
5318         * <table class="jd-sumtable">
5319         * <tr>
5320         * <th>Type</th>
5321         * <th>Alias</th><th colspan='2'>Data column</th>
5322         * </tr>
5323         * <tr>
5324         * <td>String</td>
5325         * <td>{@link #SIP_ADDRESS}</td>
5326         * <td>{@link #DATA1}</td>
5327         * <td></td>
5328         * </tr>
5329         * </table>
5330         */
5331        public static final class SipAddress implements DataColumnsWithJoins {
5332            // TODO: Ultimately this class will probably implement
5333            // CommonColumns too (in addition to DataColumnsWithJoins)
5334            // since it may make sense to have multiple SIP addresses with
5335            // different types+labels, just like with phone numbers.
5336            //
5337            // But that can be extended in the future without breaking any
5338            // public API, so let's keep this class ultra-simple for now.
5339
5340            /**
5341             * This utility class cannot be instantiated
5342             */
5343            private SipAddress() {}
5344
5345            /** MIME type used when storing this in data table. */
5346            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/sip_address";
5347
5348            /**
5349             * The SIP address.
5350             * <P>Type: TEXT</P>
5351             */
5352            public static final String SIP_ADDRESS = DATA1;
5353        }
5354    }
5355
5356    /**
5357     * @see Groups
5358     */
5359    protected interface GroupsColumns {
5360        /**
5361         * The display title of this group.
5362         * <p>
5363         * Type: TEXT
5364         */
5365        public static final String TITLE = "title";
5366
5367        /**
5368         * The package name to use when creating {@link Resources} objects for
5369         * this group. This value is only designed for use when building user
5370         * interfaces, and should not be used to infer the owner.
5371         *
5372         * @hide
5373         */
5374        public static final String RES_PACKAGE = "res_package";
5375
5376        /**
5377         * The display title of this group to load as a resource from
5378         * {@link #RES_PACKAGE}, which may be localized.
5379         * <P>Type: TEXT</P>
5380         *
5381         * @hide
5382         */
5383        public static final String TITLE_RES = "title_res";
5384
5385        /**
5386         * Notes about the group.
5387         * <p>
5388         * Type: TEXT
5389         */
5390        public static final String NOTES = "notes";
5391
5392        /**
5393         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
5394         * to the sync adapter, null otherwise.
5395         * <P>Type: TEXT</P>
5396         */
5397        public static final String SYSTEM_ID = "system_id";
5398
5399        /**
5400         * The total number of {@link Contacts} that have
5401         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
5402         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
5403         * <p>
5404         * Type: INTEGER
5405         */
5406        public static final String SUMMARY_COUNT = "summ_count";
5407
5408        /**
5409         * The total number of {@link Contacts} that have both
5410         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
5411         * Read-only value that is only present when querying
5412         * {@link Groups#CONTENT_SUMMARY_URI}.
5413         * <p>
5414         * Type: INTEGER
5415         */
5416        public static final String SUMMARY_WITH_PHONES = "summ_phones";
5417
5418        /**
5419         * Flag indicating if the contacts belonging to this group should be
5420         * visible in any user interface.
5421         * <p>
5422         * Type: INTEGER (boolean)
5423         */
5424        public static final String GROUP_VISIBLE = "group_visible";
5425
5426        /**
5427         * The "deleted" flag: "0" by default, "1" if the row has been marked
5428         * for deletion. When {@link android.content.ContentResolver#delete} is
5429         * called on a group, it is marked for deletion. The sync adaptor
5430         * deletes the group on the server and then calls ContactResolver.delete
5431         * once more, this time setting the the
5432         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to
5433         * finalize the data removal.
5434         * <P>Type: INTEGER</P>
5435         */
5436        public static final String DELETED = "deleted";
5437
5438        /**
5439         * Whether this group should be synced if the SYNC_EVERYTHING settings
5440         * is false for this group's account.
5441         * <p>
5442         * Type: INTEGER (boolean)
5443         */
5444        public static final String SHOULD_SYNC = "should_sync";
5445
5446        /**
5447         * Any newly created contacts will automatically be added to groups that have this
5448         * flag set to true.
5449         * <p>
5450         * Type: INTEGER (boolean)
5451         */
5452        public static final String AUTO_ADD = "auto_add";
5453
5454        /**
5455         * When a contacts is marked as a favorites it will be automatically added
5456         * to the groups that have this flag set, and when it is removed from favorites
5457         * it will be removed from these groups.
5458         * <p>
5459         * Type: INTEGER (boolean)
5460         */
5461        public static final String FAVORITES = "favorites";
5462    }
5463
5464    /**
5465     * Constants for the groups table. Only per-account groups are supported.
5466     * <h2>Columns</h2>
5467     * <table class="jd-sumtable">
5468     * <tr>
5469     * <th colspan='4'>Groups</th>
5470     * </tr>
5471     * <tr>
5472     * <td>long</td>
5473     * <td>{@link #_ID}</td>
5474     * <td>read-only</td>
5475     * <td>Row ID. Sync adapter should try to preserve row IDs during updates.
5476     * In other words, it would be a really bad idea to delete and reinsert a
5477     * group. A sync adapter should always do an update instead.</td>
5478     * </tr>
5479     * <tr>
5480     * <td>String</td>
5481     * <td>{@link #TITLE}</td>
5482     * <td>read/write</td>
5483     * <td>The display title of this group.</td>
5484     * </tr>
5485     * <tr>
5486     * <td>String</td>
5487     * <td>{@link #NOTES}</td>
5488     * <td>read/write</td>
5489     * <td>Notes about the group.</td>
5490     * </tr>
5491     * <tr>
5492     * <td>String</td>
5493     * <td>{@link #SYSTEM_ID}</td>
5494     * <td>read/write</td>
5495     * <td>The ID of this group if it is a System Group, i.e. a group that has a
5496     * special meaning to the sync adapter, null otherwise.</td>
5497     * </tr>
5498     * <tr>
5499     * <td>int</td>
5500     * <td>{@link #SUMMARY_COUNT}</td>
5501     * <td>read-only</td>
5502     * <td>The total number of {@link Contacts} that have
5503     * {@link CommonDataKinds.GroupMembership} in this group. Read-only value
5504     * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td>
5505     * </tr>
5506     * <tr>
5507     * <td>int</td>
5508     * <td>{@link #SUMMARY_WITH_PHONES}</td>
5509     * <td>read-only</td>
5510     * <td>The total number of {@link Contacts} that have both
5511     * {@link CommonDataKinds.GroupMembership} in this group, and also have
5512     * phone numbers. Read-only value that is only present when querying
5513     * {@link Groups#CONTENT_SUMMARY_URI}.</td>
5514     * </tr>
5515     * <tr>
5516     * <td>int</td>
5517     * <td>{@link #GROUP_VISIBLE}</td>
5518     * <td>read-only</td>
5519     * <td>Flag indicating if the contacts belonging to this group should be
5520     * visible in any user interface. Allowed values: 0 and 1.</td>
5521     * </tr>
5522     * <tr>
5523     * <td>int</td>
5524     * <td>{@link #DELETED}</td>
5525     * <td>read/write</td>
5526     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
5527     * for deletion. When {@link android.content.ContentResolver#delete} is
5528     * called on a group, it is marked for deletion. The sync adaptor deletes
5529     * the group on the server and then calls ContactResolver.delete once more,
5530     * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER}
5531     * query parameter to finalize the data removal.</td>
5532     * </tr>
5533     * <tr>
5534     * <td>int</td>
5535     * <td>{@link #SHOULD_SYNC}</td>
5536     * <td>read/write</td>
5537     * <td>Whether this group should be synced if the SYNC_EVERYTHING settings
5538     * is false for this group's account.</td>
5539     * </tr>
5540     * </table>
5541     */
5542    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
5543        /**
5544         * This utility class cannot be instantiated
5545         */
5546        private Groups() {
5547        }
5548
5549        /**
5550         * The content:// style URI for this table
5551         */
5552        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
5553
5554        /**
5555         * The content:// style URI for this table joined with details data from
5556         * {@link ContactsContract.Data}.
5557         */
5558        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
5559                "groups_summary");
5560
5561        /**
5562         * The MIME type of a directory of groups.
5563         */
5564        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
5565
5566        /**
5567         * The MIME type of a single group.
5568         */
5569        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
5570
5571        public static EntityIterator newEntityIterator(Cursor cursor) {
5572            return new EntityIteratorImpl(cursor);
5573        }
5574
5575        private static class EntityIteratorImpl extends CursorEntityIterator {
5576            public EntityIteratorImpl(Cursor cursor) {
5577                super(cursor);
5578            }
5579
5580            @Override
5581            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
5582                // we expect the cursor is already at the row we need to read from
5583                final ContentValues values = new ContentValues();
5584                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID);
5585                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME);
5586                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE);
5587                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY);
5588                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION);
5589                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID);
5590                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE);
5591                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE);
5592                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES);
5593                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE);
5594                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1);
5595                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2);
5596                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3);
5597                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4);
5598                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID);
5599                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED);
5600                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES);
5601                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC);
5602                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, FAVORITES);
5603                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, AUTO_ADD);
5604                cursor.moveToNext();
5605                return new Entity(values);
5606            }
5607        }
5608    }
5609
5610    /**
5611     * <p>
5612     * Constants for the contact aggregation exceptions table, which contains
5613     * aggregation rules overriding those used by automatic aggregation. This
5614     * type only supports query and update. Neither insert nor delete are
5615     * supported.
5616     * </p>
5617     * <h2>Columns</h2>
5618     * <table class="jd-sumtable">
5619     * <tr>
5620     * <th colspan='4'>AggregationExceptions</th>
5621     * </tr>
5622     * <tr>
5623     * <td>int</td>
5624     * <td>{@link #TYPE}</td>
5625     * <td>read/write</td>
5626     * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER},
5627     * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td>
5628     * </tr>
5629     * <tr>
5630     * <td>long</td>
5631     * <td>{@link #RAW_CONTACT_ID1}</td>
5632     * <td>read/write</td>
5633     * <td>A reference to the {@link RawContacts#_ID} of the raw contact that
5634     * the rule applies to.</td>
5635     * </tr>
5636     * <tr>
5637     * <td>long</td>
5638     * <td>{@link #RAW_CONTACT_ID2}</td>
5639     * <td>read/write</td>
5640     * <td>A reference to the other {@link RawContacts#_ID} of the raw contact
5641     * that the rule applies to.</td>
5642     * </tr>
5643     * </table>
5644     */
5645    public static final class AggregationExceptions implements BaseColumns {
5646        /**
5647         * This utility class cannot be instantiated
5648         */
5649        private AggregationExceptions() {}
5650
5651        /**
5652         * The content:// style URI for this table
5653         */
5654        public static final Uri CONTENT_URI =
5655                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
5656
5657        /**
5658         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
5659         */
5660        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
5661
5662        /**
5663         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
5664         */
5665        public static final String CONTENT_ITEM_TYPE =
5666                "vnd.android.cursor.item/aggregation_exception";
5667
5668        /**
5669         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
5670         * {@link #TYPE_AUTOMATIC}.
5671         *
5672         * <P>Type: INTEGER</P>
5673         */
5674        public static final String TYPE = "type";
5675
5676        /**
5677         * Allows the provider to automatically decide whether the specified raw contacts should
5678         * be included in the same aggregate contact or not.
5679         */
5680        public static final int TYPE_AUTOMATIC = 0;
5681
5682        /**
5683         * Makes sure that the specified raw contacts are included in the same
5684         * aggregate contact.
5685         */
5686        public static final int TYPE_KEEP_TOGETHER = 1;
5687
5688        /**
5689         * Makes sure that the specified raw contacts are NOT included in the same
5690         * aggregate contact.
5691         */
5692        public static final int TYPE_KEEP_SEPARATE = 2;
5693
5694        /**
5695         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
5696         */
5697        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
5698
5699        /**
5700         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
5701         * applies to.
5702         */
5703        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
5704    }
5705
5706    /**
5707     * @see Settings
5708     */
5709    protected interface SettingsColumns {
5710        /**
5711         * The name of the account instance to which this row belongs.
5712         * <P>Type: TEXT</P>
5713         */
5714        public static final String ACCOUNT_NAME = "account_name";
5715
5716        /**
5717         * The type of account to which this row belongs, which when paired with
5718         * {@link #ACCOUNT_NAME} identifies a specific account.
5719         * <P>Type: TEXT</P>
5720         */
5721        public static final String ACCOUNT_TYPE = "account_type";
5722
5723        /**
5724         * Depending on the mode defined by the sync-adapter, this flag controls
5725         * the top-level sync behavior for this data source.
5726         * <p>
5727         * Type: INTEGER (boolean)
5728         */
5729        public static final String SHOULD_SYNC = "should_sync";
5730
5731        /**
5732         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
5733         * entries should be visible in any user interface.
5734         * <p>
5735         * Type: INTEGER (boolean)
5736         */
5737        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
5738
5739        /**
5740         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
5741         * {@link Groups#SHOULD_SYNC} under this account have been marked as
5742         * unsynced.
5743         */
5744        public static final String ANY_UNSYNCED = "any_unsynced";
5745
5746        /**
5747         * Read-only count of {@link Contacts} from a specific source that have
5748         * no {@link CommonDataKinds.GroupMembership} entries.
5749         * <p>
5750         * Type: INTEGER
5751         */
5752        public static final String UNGROUPED_COUNT = "summ_count";
5753
5754        /**
5755         * Read-only count of {@link Contacts} from a specific source that have
5756         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
5757         * <p>
5758         * Type: INTEGER
5759         */
5760        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
5761    }
5762
5763    /**
5764     * <p>
5765     * Contacts-specific settings for various {@link Account}'s.
5766     * </p>
5767     * <h2>Columns</h2>
5768     * <table class="jd-sumtable">
5769     * <tr>
5770     * <th colspan='4'>Settings</th>
5771     * </tr>
5772     * <tr>
5773     * <td>String</td>
5774     * <td>{@link #ACCOUNT_NAME}</td>
5775     * <td>read/write-once</td>
5776     * <td>The name of the account instance to which this row belongs.</td>
5777     * </tr>
5778     * <tr>
5779     * <td>String</td>
5780     * <td>{@link #ACCOUNT_TYPE}</td>
5781     * <td>read/write-once</td>
5782     * <td>The type of account to which this row belongs, which when paired with
5783     * {@link #ACCOUNT_NAME} identifies a specific account.</td>
5784     * </tr>
5785     * <tr>
5786     * <td>int</td>
5787     * <td>{@link #SHOULD_SYNC}</td>
5788     * <td>read/write</td>
5789     * <td>Depending on the mode defined by the sync-adapter, this flag controls
5790     * the top-level sync behavior for this data source.</td>
5791     * </tr>
5792     * <tr>
5793     * <td>int</td>
5794     * <td>{@link #UNGROUPED_VISIBLE}</td>
5795     * <td>read/write</td>
5796     * <td>Flag indicating if contacts without any
5797     * {@link CommonDataKinds.GroupMembership} entries should be visible in any
5798     * user interface.</td>
5799     * </tr>
5800     * <tr>
5801     * <td>int</td>
5802     * <td>{@link #ANY_UNSYNCED}</td>
5803     * <td>read-only</td>
5804     * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any
5805     * {@link Groups#SHOULD_SYNC} under this account have been marked as
5806     * unsynced.</td>
5807     * </tr>
5808     * <tr>
5809     * <td>int</td>
5810     * <td>{@link #UNGROUPED_COUNT}</td>
5811     * <td>read-only</td>
5812     * <td>Read-only count of {@link Contacts} from a specific source that have
5813     * no {@link CommonDataKinds.GroupMembership} entries.</td>
5814     * </tr>
5815     * <tr>
5816     * <td>int</td>
5817     * <td>{@link #UNGROUPED_WITH_PHONES}</td>
5818     * <td>read-only</td>
5819     * <td>Read-only count of {@link Contacts} from a specific source that have
5820     * no {@link CommonDataKinds.GroupMembership} entries, and also have phone
5821     * numbers.</td>
5822     * </tr>
5823     * </table>
5824     */
5825    public static final class Settings implements SettingsColumns {
5826        /**
5827         * This utility class cannot be instantiated
5828         */
5829        private Settings() {
5830        }
5831
5832        /**
5833         * The content:// style URI for this table
5834         */
5835        public static final Uri CONTENT_URI =
5836                Uri.withAppendedPath(AUTHORITY_URI, "settings");
5837
5838        /**
5839         * The MIME-type of {@link #CONTENT_URI} providing a directory of
5840         * settings.
5841         */
5842        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
5843
5844        /**
5845         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
5846         */
5847        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
5848    }
5849
5850    /**
5851     * Private API for inquiring about the general status of the provider.
5852     *
5853     * @hide
5854     */
5855    public static final class ProviderStatus {
5856
5857        /**
5858         * Not instantiable.
5859         */
5860        private ProviderStatus() {
5861        }
5862
5863        /**
5864         * The content:// style URI for this table.  Requests to this URI can be
5865         * performed on the UI thread because they are always unblocking.
5866         *
5867         * @hide
5868         */
5869        public static final Uri CONTENT_URI =
5870                Uri.withAppendedPath(AUTHORITY_URI, "provider_status");
5871
5872        /**
5873         * The MIME-type of {@link #CONTENT_URI} providing a directory of
5874         * settings.
5875         *
5876         * @hide
5877         */
5878        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status";
5879
5880        /**
5881         * An integer representing the current status of the provider.
5882         *
5883         * @hide
5884         */
5885        public static final String STATUS = "status";
5886
5887        /**
5888         * Default status of the provider.
5889         *
5890         * @hide
5891         */
5892        public static final int STATUS_NORMAL = 0;
5893
5894        /**
5895         * The status used when the provider is in the process of upgrading.  Contacts
5896         * are temporarily unaccessible.
5897         *
5898         * @hide
5899         */
5900        public static final int STATUS_UPGRADING = 1;
5901
5902        /**
5903         * The status used if the provider was in the process of upgrading but ran
5904         * out of storage. The DATA1 column will contain the estimated amount of
5905         * storage required (in bytes). Update status to STATUS_NORMAL to force
5906         * the provider to retry the upgrade.
5907         *
5908         * @hide
5909         */
5910        public static final int STATUS_UPGRADE_OUT_OF_MEMORY = 2;
5911
5912        /**
5913         * The status used during a locale change.
5914         *
5915         * @hide
5916         */
5917        public static final int STATUS_CHANGING_LOCALE = 3;
5918
5919        /**
5920         * Additional data associated with the status.
5921         *
5922         * @hide
5923         */
5924        public static final String DATA1 = "data1";
5925    }
5926
5927    /**
5928     * Helper methods to display QuickContact dialogs that allow users to pivot on
5929     * a specific {@link Contacts} entry.
5930     */
5931    public static final class QuickContact {
5932        /**
5933         * Action used to trigger person pivot dialog.
5934         * @hide
5935         */
5936        public static final String ACTION_QUICK_CONTACT =
5937                "com.android.contacts.action.QUICK_CONTACT";
5938
5939        /**
5940         * Extra used to specify pivot dialog location in screen coordinates.
5941         * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead.
5942         * @hide
5943         */
5944        @Deprecated
5945        public static final String EXTRA_TARGET_RECT = "target_rect";
5946
5947        /**
5948         * Extra used to specify size of pivot dialog.
5949         * @hide
5950         */
5951        public static final String EXTRA_MODE = "mode";
5952
5953        /**
5954         * Extra used to indicate a list of specific MIME-types to exclude and
5955         * not display. Stored as a {@link String} array.
5956         * @hide
5957         */
5958        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
5959
5960        /**
5961         * Small QuickContact mode, usually presented with minimal actions.
5962         */
5963        public static final int MODE_SMALL = 1;
5964
5965        /**
5966         * Medium QuickContact mode, includes actions and light summary describing
5967         * the {@link Contacts} entry being shown. This may include social
5968         * status and presence details.
5969         */
5970        public static final int MODE_MEDIUM = 2;
5971
5972        /**
5973         * Large QuickContact mode, includes actions and larger, card-like summary
5974         * of the {@link Contacts} entry being shown. This may include detailed
5975         * information, such as a photo.
5976         */
5977        public static final int MODE_LARGE = 3;
5978
5979        /**
5980         * Trigger a dialog that lists the various methods of interacting with
5981         * the requested {@link Contacts} entry. This may be based on available
5982         * {@link ContactsContract.Data} rows under that contact, and may also
5983         * include social status and presence details.
5984         *
5985         * @param context The parent {@link Context} that may be used as the
5986         *            parent for this dialog.
5987         * @param target Specific {@link View} from your layout that this dialog
5988         *            should be centered around. In particular, if the dialog
5989         *            has a "callout" arrow, it will be pointed and centered
5990         *            around this {@link View}.
5991         * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
5992         *            {@link Uri} that describes a specific contact to feature
5993         *            in this dialog.
5994         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
5995         *            {@link #MODE_LARGE}, indicating the desired dialog size,
5996         *            when supported.
5997         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
5998         *            to exclude when showing this dialog. For example, when
5999         *            already viewing the contact details card, this can be used
6000         *            to omit the details entry from the dialog.
6001         */
6002        public static void showQuickContact(Context context, View target, Uri lookupUri, int mode,
6003                String[] excludeMimes) {
6004            // Find location and bounds of target view, adjusting based on the
6005            // assumed local density.
6006            final float appScale = context.getResources().getCompatibilityInfo().applicationScale;
6007            final int[] pos = new int[2];
6008            target.getLocationOnScreen(pos);
6009
6010            final Rect rect = new Rect();
6011            rect.left = (int) (pos[0] * appScale + 0.5f);
6012            rect.top = (int) (pos[1] * appScale + 0.5f);
6013            rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f);
6014            rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f);
6015
6016            // Trigger with obtained rectangle
6017            showQuickContact(context, rect, lookupUri, mode, excludeMimes);
6018        }
6019
6020        /**
6021         * Trigger a dialog that lists the various methods of interacting with
6022         * the requested {@link Contacts} entry. This may be based on available
6023         * {@link ContactsContract.Data} rows under that contact, and may also
6024         * include social status and presence details.
6025         *
6026         * @param context The parent {@link Context} that may be used as the
6027         *            parent for this dialog.
6028         * @param target Specific {@link Rect} that this dialog should be
6029         *            centered around, in screen coordinates. In particular, if
6030         *            the dialog has a "callout" arrow, it will be pointed and
6031         *            centered around this {@link Rect}. If you are running at a
6032         *            non-native density, you need to manually adjust using
6033         *            {@link DisplayMetrics#density} before calling.
6034         * @param lookupUri A
6035         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
6036         *            {@link Uri} that describes a specific contact to feature
6037         *            in this dialog.
6038         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
6039         *            {@link #MODE_LARGE}, indicating the desired dialog size,
6040         *            when supported.
6041         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
6042         *            to exclude when showing this dialog. For example, when
6043         *            already viewing the contact details card, this can be used
6044         *            to omit the details entry from the dialog.
6045         */
6046        public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,
6047                String[] excludeMimes) {
6048            // Launch pivot dialog through intent for now
6049            final Intent intent = new Intent(ACTION_QUICK_CONTACT);
6050            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP
6051                    | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
6052
6053            intent.setData(lookupUri);
6054            intent.setSourceBounds(target);
6055            intent.putExtra(EXTRA_MODE, mode);
6056            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);
6057            context.startActivity(intent);
6058        }
6059    }
6060
6061    /**
6062     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
6063     * that involve contacts.
6064     */
6065    public static final class Intents {
6066        /**
6067         * This is the intent that is fired when a search suggestion is clicked on.
6068         */
6069        public static final String SEARCH_SUGGESTION_CLICKED =
6070                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
6071
6072        /**
6073         * This is the intent that is fired when a search suggestion for dialing a number
6074         * is clicked on.
6075         */
6076        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
6077                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
6078
6079        /**
6080         * This is the intent that is fired when a search suggestion for creating a contact
6081         * is clicked on.
6082         */
6083        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
6084                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
6085
6086        /**
6087         * Starts an Activity that lets the user pick a contact to attach an image to.
6088         * After picking the contact it launches the image cropper in face detection mode.
6089         */
6090        public static final String ATTACH_IMAGE =
6091                "com.android.contacts.action.ATTACH_IMAGE";
6092
6093        /**
6094         * Takes as input a data URI with a mailto: or tel: scheme. If a single
6095         * contact exists with the given data it will be shown. If no contact
6096         * exists, a dialog will ask the user if they want to create a new
6097         * contact with the provided details filled in. If multiple contacts
6098         * share the data the user will be prompted to pick which contact they
6099         * want to view.
6100         * <p>
6101         * For <code>mailto:</code> URIs, the scheme specific portion must be a
6102         * raw email address, such as one built using
6103         * {@link Uri#fromParts(String, String, String)}.
6104         * <p>
6105         * For <code>tel:</code> URIs, the scheme specific portion is compared
6106         * to existing numbers using the standard caller ID lookup algorithm.
6107         * The number must be properly encoded, for example using
6108         * {@link Uri#fromParts(String, String, String)}.
6109         * <p>
6110         * Any extras from the {@link Insert} class will be passed along to the
6111         * create activity if there are no contacts to show.
6112         * <p>
6113         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
6114         * prompting the user when the contact doesn't exist.
6115         */
6116        public static final String SHOW_OR_CREATE_CONTACT =
6117                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
6118
6119        /**
6120         * Starts an Activity that lets the user select the multiple phones from a
6121         * list of phone numbers which come from the contacts or
6122         * {@link #EXTRA_PHONE_URIS}.
6123         * <p>
6124         * The phone numbers being passed in through {@link #EXTRA_PHONE_URIS}
6125         * could belong to the contacts or not, and will be selected by default.
6126         * <p>
6127         * The user's selection will be returned from
6128         * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
6129         * if the resultCode is
6130         * {@link android.app.Activity#RESULT_OK}, the array of picked phone
6131         * numbers are in the Intent's
6132         * {@link #EXTRA_PHONE_URIS}; otherwise, the
6133         * {@link android.app.Activity#RESULT_CANCELED} is returned if the user
6134         * left the Activity without changing the selection.
6135         *
6136         * @hide
6137         */
6138        public static final String ACTION_GET_MULTIPLE_PHONES =
6139                "com.android.contacts.action.GET_MULTIPLE_PHONES";
6140
6141        /**
6142         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
6143         * contact if no matching contact found. Otherwise, default behavior is
6144         * to prompt user with dialog before creating.
6145         * <p>
6146         * Type: BOOLEAN
6147         */
6148        public static final String EXTRA_FORCE_CREATE =
6149                "com.android.contacts.action.FORCE_CREATE";
6150
6151        /**
6152         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
6153         * description to be shown when prompting user about creating a new
6154         * contact.
6155         * <p>
6156         * Type: STRING
6157         */
6158        public static final String EXTRA_CREATE_DESCRIPTION =
6159            "com.android.contacts.action.CREATE_DESCRIPTION";
6160
6161        /**
6162         * Used with {@link #ACTION_GET_MULTIPLE_PHONES} as the input or output value.
6163         * <p>
6164         * The phone numbers want to be picked by default should be passed in as
6165         * input value. These phone numbers could belong to the contacts or not.
6166         * <p>
6167         * The phone numbers which were picked by the user are returned as output
6168         * value.
6169         * <p>
6170         * Type: array of URIs, the tel URI is used for the phone numbers which don't
6171         * belong to any contact, the content URI is used for phone id in contacts.
6172         *
6173         * @hide
6174         */
6175        public static final String EXTRA_PHONE_URIS =
6176            "com.android.contacts.extra.PHONE_URIS";
6177
6178        /**
6179         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
6180         * dialog location using screen coordinates. When not specified, the
6181         * dialog will be centered.
6182         *
6183         * @hide
6184         */
6185        @Deprecated
6186        public static final String EXTRA_TARGET_RECT = "target_rect";
6187
6188        /**
6189         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
6190         * desired dialog style, usually a variation on size. One of
6191         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
6192         *
6193         * @hide
6194         */
6195        @Deprecated
6196        public static final String EXTRA_MODE = "mode";
6197
6198        /**
6199         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
6200         *
6201         * @hide
6202         */
6203        @Deprecated
6204        public static final int MODE_SMALL = 1;
6205
6206        /**
6207         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
6208         *
6209         * @hide
6210         */
6211        @Deprecated
6212        public static final int MODE_MEDIUM = 2;
6213
6214        /**
6215         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
6216         *
6217         * @hide
6218         */
6219        @Deprecated
6220        public static final int MODE_LARGE = 3;
6221
6222        /**
6223         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
6224         * a list of specific MIME-types to exclude and not display. Stored as a
6225         * {@link String} array.
6226         *
6227         * @hide
6228         */
6229        @Deprecated
6230        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
6231
6232        /**
6233         * Intents related to the Contacts app UI.
6234         *
6235         * @hide
6236         */
6237        public static final class UI {
6238            /**
6239             * The action for the default contacts list tab.
6240             */
6241            public static final String LIST_DEFAULT =
6242                    "com.android.contacts.action.LIST_DEFAULT";
6243
6244            /**
6245             * The action for the contacts list tab.
6246             */
6247            public static final String LIST_GROUP_ACTION =
6248                    "com.android.contacts.action.LIST_GROUP";
6249
6250            /**
6251             * When in LIST_GROUP_ACTION mode, this is the group to display.
6252             */
6253            public static final String GROUP_NAME_EXTRA_KEY = "com.android.contacts.extra.GROUP";
6254
6255            /**
6256             * The action for the all contacts list tab.
6257             */
6258            public static final String LIST_ALL_CONTACTS_ACTION =
6259                    "com.android.contacts.action.LIST_ALL_CONTACTS";
6260
6261            /**
6262             * The action for the contacts with phone numbers list tab.
6263             */
6264            public static final String LIST_CONTACTS_WITH_PHONES_ACTION =
6265                    "com.android.contacts.action.LIST_CONTACTS_WITH_PHONES";
6266
6267            /**
6268             * The action for the starred contacts list tab.
6269             */
6270            public static final String LIST_STARRED_ACTION =
6271                    "com.android.contacts.action.LIST_STARRED";
6272
6273            /**
6274             * The action for the frequent contacts list tab.
6275             */
6276            public static final String LIST_FREQUENT_ACTION =
6277                    "com.android.contacts.action.LIST_FREQUENT";
6278
6279            /**
6280             * The action for the "strequent" contacts list tab. It first lists the starred
6281             * contacts in alphabetical order and then the frequent contacts in descending
6282             * order of the number of times they have been contacted.
6283             */
6284            public static final String LIST_STREQUENT_ACTION =
6285                    "com.android.contacts.action.LIST_STREQUENT";
6286
6287            /**
6288             * A key for to be used as an intent extra to set the activity
6289             * title to a custom String value.
6290             */
6291            public static final String TITLE_EXTRA_KEY =
6292                    "com.android.contacts.extra.TITLE_EXTRA";
6293
6294            /**
6295             * Activity Action: Display a filtered list of contacts
6296             * <p>
6297             * Input: Extra field {@link #FILTER_TEXT_EXTRA_KEY} is the text to use for
6298             * filtering
6299             * <p>
6300             * Output: Nothing.
6301             */
6302            public static final String FILTER_CONTACTS_ACTION =
6303                    "com.android.contacts.action.FILTER_CONTACTS";
6304
6305            /**
6306             * Used as an int extra field in {@link #FILTER_CONTACTS_ACTION}
6307             * intents to supply the text on which to filter.
6308             */
6309            public static final String FILTER_TEXT_EXTRA_KEY =
6310                    "com.android.contacts.extra.FILTER_TEXT";
6311        }
6312
6313        /**
6314         * Convenience class that contains string constants used
6315         * to create contact {@link android.content.Intent Intents}.
6316         */
6317        public static final class Insert {
6318            /** The action code to use when adding a contact */
6319            public static final String ACTION = Intent.ACTION_INSERT;
6320
6321            /**
6322             * If present, forces a bypass of quick insert mode.
6323             */
6324            public static final String FULL_MODE = "full_mode";
6325
6326            /**
6327             * The extra field for the contact name.
6328             * <P>Type: String</P>
6329             */
6330            public static final String NAME = "name";
6331
6332            // TODO add structured name values here.
6333
6334            /**
6335             * The extra field for the contact phonetic name.
6336             * <P>Type: String</P>
6337             */
6338            public static final String PHONETIC_NAME = "phonetic_name";
6339
6340            /**
6341             * The extra field for the contact company.
6342             * <P>Type: String</P>
6343             */
6344            public static final String COMPANY = "company";
6345
6346            /**
6347             * The extra field for the contact job title.
6348             * <P>Type: String</P>
6349             */
6350            public static final String JOB_TITLE = "job_title";
6351
6352            /**
6353             * The extra field for the contact notes.
6354             * <P>Type: String</P>
6355             */
6356            public static final String NOTES = "notes";
6357
6358            /**
6359             * The extra field for the contact phone number.
6360             * <P>Type: String</P>
6361             */
6362            public static final String PHONE = "phone";
6363
6364            /**
6365             * The extra field for the contact phone number type.
6366             * <P>Type: Either an integer value from
6367             * {@link CommonDataKinds.Phone},
6368             *  or a string specifying a custom label.</P>
6369             */
6370            public static final String PHONE_TYPE = "phone_type";
6371
6372            /**
6373             * The extra field for the phone isprimary flag.
6374             * <P>Type: boolean</P>
6375             */
6376            public static final String PHONE_ISPRIMARY = "phone_isprimary";
6377
6378            /**
6379             * The extra field for an optional second contact phone number.
6380             * <P>Type: String</P>
6381             */
6382            public static final String SECONDARY_PHONE = "secondary_phone";
6383
6384            /**
6385             * The extra field for an optional second contact phone number type.
6386             * <P>Type: Either an integer value from
6387             * {@link CommonDataKinds.Phone},
6388             *  or a string specifying a custom label.</P>
6389             */
6390            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
6391
6392            /**
6393             * The extra field for an optional third contact phone number.
6394             * <P>Type: String</P>
6395             */
6396            public static final String TERTIARY_PHONE = "tertiary_phone";
6397
6398            /**
6399             * The extra field for an optional third contact phone number type.
6400             * <P>Type: Either an integer value from
6401             * {@link CommonDataKinds.Phone},
6402             *  or a string specifying a custom label.</P>
6403             */
6404            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
6405
6406            /**
6407             * The extra field for the contact email address.
6408             * <P>Type: String</P>
6409             */
6410            public static final String EMAIL = "email";
6411
6412            /**
6413             * The extra field for the contact email type.
6414             * <P>Type: Either an integer value from
6415             * {@link CommonDataKinds.Email}
6416             *  or a string specifying a custom label.</P>
6417             */
6418            public static final String EMAIL_TYPE = "email_type";
6419
6420            /**
6421             * The extra field for the email isprimary flag.
6422             * <P>Type: boolean</P>
6423             */
6424            public static final String EMAIL_ISPRIMARY = "email_isprimary";
6425
6426            /**
6427             * The extra field for an optional second contact email address.
6428             * <P>Type: String</P>
6429             */
6430            public static final String SECONDARY_EMAIL = "secondary_email";
6431
6432            /**
6433             * The extra field for an optional second contact email type.
6434             * <P>Type: Either an integer value from
6435             * {@link CommonDataKinds.Email}
6436             *  or a string specifying a custom label.</P>
6437             */
6438            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
6439
6440            /**
6441             * The extra field for an optional third contact email address.
6442             * <P>Type: String</P>
6443             */
6444            public static final String TERTIARY_EMAIL = "tertiary_email";
6445
6446            /**
6447             * The extra field for an optional third contact email type.
6448             * <P>Type: Either an integer value from
6449             * {@link CommonDataKinds.Email}
6450             *  or a string specifying a custom label.</P>
6451             */
6452            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
6453
6454            /**
6455             * The extra field for the contact postal address.
6456             * <P>Type: String</P>
6457             */
6458            public static final String POSTAL = "postal";
6459
6460            /**
6461             * The extra field for the contact postal address type.
6462             * <P>Type: Either an integer value from
6463             * {@link CommonDataKinds.StructuredPostal}
6464             *  or a string specifying a custom label.</P>
6465             */
6466            public static final String POSTAL_TYPE = "postal_type";
6467
6468            /**
6469             * The extra field for the postal isprimary flag.
6470             * <P>Type: boolean</P>
6471             */
6472            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
6473
6474            /**
6475             * The extra field for an IM handle.
6476             * <P>Type: String</P>
6477             */
6478            public static final String IM_HANDLE = "im_handle";
6479
6480            /**
6481             * The extra field for the IM protocol
6482             */
6483            public static final String IM_PROTOCOL = "im_protocol";
6484
6485            /**
6486             * The extra field for the IM isprimary flag.
6487             * <P>Type: boolean</P>
6488             */
6489            public static final String IM_ISPRIMARY = "im_isprimary";
6490        }
6491    }
6492}
6493