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