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