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