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