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