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