ContactsContract.java revision a6baa7748279b6a6d3212c5d7069fc585cc288b8
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, specific to the user's profile.
4813         */
4814        public static final Uri PROFILE_CONTENT_URI =
4815                Uri.withAppendedPath(Profile.CONTENT_URI, "raw_contact_entities");
4816
4817        /**
4818         * The MIME type of {@link #CONTENT_URI} providing a directory of raw contact entities.
4819         */
4820        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact_entity";
4821
4822        /**
4823         * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward
4824         * Data.CONTENT_URI contains only exportable data.
4825         *
4826         * This flag is useful (currently) only for vCard exporter in Contacts app, which
4827         * needs to exclude "un-exportable" data from available data to export, while
4828         * Contacts app itself has priviledge to access all data including "un-expotable"
4829         * ones and providers return all of them regardless of the callers' intention.
4830         * <P>Type: INTEGER</p>
4831         *
4832         * @hide Maybe available only in Eclair and not really ready for public use.
4833         * TODO: remove, or implement this feature completely. As of now (Eclair),
4834         * we only use this flag in queryEntities(), not query().
4835         */
4836        public static final String FOR_EXPORT_ONLY = "for_export_only";
4837
4838        /**
4839         * The ID of the data column. The value will be null if this raw contact has no data rows.
4840         * <P>Type: INTEGER</P>
4841         */
4842        public static final String DATA_ID = "data_id";
4843    }
4844
4845    /**
4846     * @see PhoneLookup
4847     */
4848    protected interface PhoneLookupColumns {
4849        /**
4850         * The phone number as the user entered it.
4851         * <P>Type: TEXT</P>
4852         */
4853        public static final String NUMBER = "number";
4854
4855        /**
4856         * The type of phone number, for example Home or Work.
4857         * <P>Type: INTEGER</P>
4858         */
4859        public static final String TYPE = "type";
4860
4861        /**
4862         * The user defined label for the phone number.
4863         * <P>Type: TEXT</P>
4864         */
4865        public static final String LABEL = "label";
4866
4867        /**
4868         * The phone number's E164 representation.
4869         * <P>Type: TEXT</P>
4870         */
4871        public static final String NORMALIZED_NUMBER = "normalized_number";
4872    }
4873
4874    /**
4875     * A table that represents the result of looking up a phone number, for
4876     * example for caller ID. To perform a lookup you must append the number you
4877     * want to find to {@link #CONTENT_FILTER_URI}.  This query is highly
4878     * optimized.
4879     * <pre>
4880     * Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
4881     * resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...
4882     * </pre>
4883     *
4884     * <h3>Columns</h3>
4885     *
4886     * <table class="jd-sumtable">
4887     * <tr>
4888     * <th colspan='4'>PhoneLookup</th>
4889     * </tr>
4890     * <tr>
4891     * <td>String</td>
4892     * <td>{@link #NUMBER}</td>
4893     * <td>read-only</td>
4894     * <td>Phone number.</td>
4895     * </tr>
4896     * <tr>
4897     * <td>String</td>
4898     * <td>{@link #TYPE}</td>
4899     * <td>read-only</td>
4900     * <td>Phone number type. See {@link CommonDataKinds.Phone}.</td>
4901     * </tr>
4902     * <tr>
4903     * <td>String</td>
4904     * <td>{@link #LABEL}</td>
4905     * <td>read-only</td>
4906     * <td>Custom label for the phone number. See {@link CommonDataKinds.Phone}.</td>
4907     * </tr>
4908     * </table>
4909     * <p>
4910     * Columns from the Contacts table are also available through a join.
4911     * </p>
4912     * <table class="jd-sumtable">
4913     * <tr>
4914     * <th colspan='4'>Join with {@link Contacts}</th>
4915     * </tr>
4916     * <tr>
4917     * <td>long</td>
4918     * <td>{@link #_ID}</td>
4919     * <td>read-only</td>
4920     * <td>Contact ID.</td>
4921     * </tr>
4922     * <tr>
4923     * <td>String</td>
4924     * <td>{@link #LOOKUP_KEY}</td>
4925     * <td>read-only</td>
4926     * <td>See {@link ContactsContract.Contacts}</td>
4927     * </tr>
4928     * <tr>
4929     * <td>String</td>
4930     * <td>{@link #DISPLAY_NAME}</td>
4931     * <td>read-only</td>
4932     * <td>See {@link ContactsContract.Contacts}</td>
4933     * </tr>
4934     * <tr>
4935     * <td>long</td>
4936     * <td>{@link #PHOTO_ID}</td>
4937     * <td>read-only</td>
4938     * <td>See {@link ContactsContract.Contacts}.</td>
4939     * </tr>
4940     * <tr>
4941     * <td>int</td>
4942     * <td>{@link #IN_VISIBLE_GROUP}</td>
4943     * <td>read-only</td>
4944     * <td>See {@link ContactsContract.Contacts}.</td>
4945     * </tr>
4946     * <tr>
4947     * <td>int</td>
4948     * <td>{@link #HAS_PHONE_NUMBER}</td>
4949     * <td>read-only</td>
4950     * <td>See {@link ContactsContract.Contacts}.</td>
4951     * </tr>
4952     * <tr>
4953     * <td>int</td>
4954     * <td>{@link #TIMES_CONTACTED}</td>
4955     * <td>read-only</td>
4956     * <td>See {@link ContactsContract.Contacts}.</td>
4957     * </tr>
4958     * <tr>
4959     * <td>long</td>
4960     * <td>{@link #LAST_TIME_CONTACTED}</td>
4961     * <td>read-only</td>
4962     * <td>See {@link ContactsContract.Contacts}.</td>
4963     * </tr>
4964     * <tr>
4965     * <td>int</td>
4966     * <td>{@link #STARRED}</td>
4967     * <td>read-only</td>
4968     * <td>See {@link ContactsContract.Contacts}.</td>
4969     * </tr>
4970     * <tr>
4971     * <td>String</td>
4972     * <td>{@link #CUSTOM_RINGTONE}</td>
4973     * <td>read-only</td>
4974     * <td>See {@link ContactsContract.Contacts}.</td>
4975     * </tr>
4976     * <tr>
4977     * <td>int</td>
4978     * <td>{@link #SEND_TO_VOICEMAIL}</td>
4979     * <td>read-only</td>
4980     * <td>See {@link ContactsContract.Contacts}.</td>
4981     * </tr>
4982     * </table>
4983     */
4984    public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns,
4985            ContactsColumns, ContactOptionsColumns {
4986        /**
4987         * This utility class cannot be instantiated
4988         */
4989        private PhoneLookup() {}
4990
4991        /**
4992         * The content:// style URI for this table. Append the phone number you want to lookup
4993         * to this URI and query it to perform a lookup. For example:
4994         * <pre>
4995         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
4996         *         Uri.encode(phoneNumber));
4997         * </pre>
4998         */
4999        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
5000                "phone_lookup");
5001
5002        /**
5003         * <p>URI used for the "enterprise caller-id".</p>
5004         *
5005         * <p>
5006         * It supports the same semantics as {@link #CONTENT_FILTER_URI} and returns the same
5007         * columns.  If the device has no corp profile that is linked to the current profile, it
5008         * behaves in the exact same way as {@link #CONTENT_FILTER_URI}.  If there is a corp profile
5009         * linked to the current profile, it first queries against the personal contact database,
5010         * and if no matching contacts are found there, then queries against the
5011         * corp contacts database.
5012         * </p>
5013         * <p>
5014         * If a result is from the corp profile, it makes the following changes to the data:
5015         * <ul>
5016         *     <li>
5017         *     {@link #PHOTO_THUMBNAIL_URI} and {@link #PHOTO_URI} will be rewritten to special
5018         *     URIs.  Use {@link ContentResolver#openAssetFileDescriptor} or its siblings to
5019         *     load pictures from them.
5020         *     {@link #PHOTO_ID} and {@link #PHOTO_FILE_ID} will be set to null.  Do not use them.
5021         *     </li>
5022         *     <li>
5023         *     Corp contacts will get artificial {@link #_ID}s.  In order to tell whether a contact
5024         *     is from the corp profile, use
5025         *     {@link ContactsContract.Contacts#isEnterpriseContactId(long)}.
5026         *     </li>
5027         * </ul>
5028         * <p>
5029         * This URI does NOT support selection nor order-by.
5030         *
5031         * <pre>
5032         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
5033         *         Uri.encode(phoneNumber));
5034         * </pre>
5035         */
5036        public static final Uri ENTERPRISE_CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
5037                "phone_lookup_enterprise");
5038
5039        /**
5040         * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows.
5041         *
5042         * @hide
5043         */
5044        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup";
5045
5046        /**
5047         * If this boolean parameter is set to true, then the appended query is treated as a
5048         * SIP address and the lookup will be performed against SIP addresses in the user's
5049         * contacts.
5050         */
5051        public static final String QUERY_PARAMETER_SIP_ADDRESS = "sip";
5052    }
5053
5054    /**
5055     * Additional data mixed in with {@link StatusColumns} to link
5056     * back to specific {@link ContactsContract.Data#_ID} entries.
5057     *
5058     * @see StatusUpdates
5059     */
5060    protected interface PresenceColumns {
5061
5062        /**
5063         * Reference to the {@link Data#_ID} entry that owns this presence.
5064         * <P>Type: INTEGER</P>
5065         */
5066        public static final String DATA_ID = "presence_data_id";
5067
5068        /**
5069         * See {@link CommonDataKinds.Im} for a list of defined protocol constants.
5070         * <p>Type: NUMBER</p>
5071         */
5072        public static final String PROTOCOL = "protocol";
5073
5074        /**
5075         * Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
5076         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
5077         * omitted if {@link #PROTOCOL} value is not
5078         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.
5079         *
5080         * <p>Type: NUMBER</p>
5081         */
5082        public static final String CUSTOM_PROTOCOL = "custom_protocol";
5083
5084        /**
5085         * The IM handle the presence item is for. The handle is scoped to
5086         * {@link #PROTOCOL}.
5087         * <P>Type: TEXT</P>
5088         */
5089        public static final String IM_HANDLE = "im_handle";
5090
5091        /**
5092         * The IM account for the local user that the presence data came from.
5093         * <P>Type: TEXT</P>
5094         */
5095        public static final String IM_ACCOUNT = "im_account";
5096    }
5097
5098    /**
5099     * <p>
5100     * A status update is linked to a {@link ContactsContract.Data} row and captures
5101     * the user's latest status update via the corresponding source, e.g.
5102     * "Having lunch" via "Google Talk".
5103     * </p>
5104     * <p>
5105     * There are two ways a status update can be inserted: by explicitly linking
5106     * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row
5107     * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
5108     * {@link #IM_HANDLE}.  There is no difference between insert and update, you can use
5109     * either.
5110     * </p>
5111     * <p>
5112     * Inserting or updating a status update for the user's profile requires either using
5113     * the {@link #DATA_ID} to identify the data row to attach the update to, or
5114     * {@link StatusUpdates#PROFILE_CONTENT_URI} to ensure that the change is scoped to the
5115     * profile.
5116     * </p>
5117     * <p>
5118     * You cannot use {@link ContentResolver#update} to change a status, but
5119     * {@link ContentResolver#insert} will replace the latests status if it already
5120     * exists.
5121     * </p>
5122     * <p>
5123     * Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses
5124     * for multiple contacts at once.
5125     * </p>
5126     *
5127     * <h3>Columns</h3>
5128     * <table class="jd-sumtable">
5129     * <tr>
5130     * <th colspan='4'>StatusUpdates</th>
5131     * </tr>
5132     * <tr>
5133     * <td>long</td>
5134     * <td>{@link #DATA_ID}</td>
5135     * <td>read/write</td>
5136     * <td>Reference to the {@link Data#_ID} entry that owns this presence. If this
5137     * field is <i>not</i> specified, the provider will attempt to find a data row
5138     * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
5139     * {@link #IM_HANDLE} columns.
5140     * </td>
5141     * </tr>
5142     * <tr>
5143     * <td>long</td>
5144     * <td>{@link #PROTOCOL}</td>
5145     * <td>read/write</td>
5146     * <td>See {@link CommonDataKinds.Im} for a list of defined protocol constants.</td>
5147     * </tr>
5148     * <tr>
5149     * <td>String</td>
5150     * <td>{@link #CUSTOM_PROTOCOL}</td>
5151     * <td>read/write</td>
5152     * <td>Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
5153     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
5154     * omitted if {@link #PROTOCOL} value is not
5155     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.</td>
5156     * </tr>
5157     * <tr>
5158     * <td>String</td>
5159     * <td>{@link #IM_HANDLE}</td>
5160     * <td>read/write</td>
5161     * <td> The IM handle the presence item is for. The handle is scoped to
5162     * {@link #PROTOCOL}.</td>
5163     * </tr>
5164     * <tr>
5165     * <td>String</td>
5166     * <td>{@link #IM_ACCOUNT}</td>
5167     * <td>read/write</td>
5168     * <td>The IM account for the local user that the presence data came from.</td>
5169     * </tr>
5170     * <tr>
5171     * <td>int</td>
5172     * <td>{@link #PRESENCE}</td>
5173     * <td>read/write</td>
5174     * <td>Contact IM presence status. The allowed values are:
5175     * <p>
5176     * <ul>
5177     * <li>{@link #OFFLINE}</li>
5178     * <li>{@link #INVISIBLE}</li>
5179     * <li>{@link #AWAY}</li>
5180     * <li>{@link #IDLE}</li>
5181     * <li>{@link #DO_NOT_DISTURB}</li>
5182     * <li>{@link #AVAILABLE}</li>
5183     * </ul>
5184     * </p>
5185     * <p>
5186     * Since presence status is inherently volatile, the content provider
5187     * may choose not to store this field in long-term storage.
5188     * </p>
5189     * </td>
5190     * </tr>
5191     * <tr>
5192     * <td>int</td>
5193     * <td>{@link #CHAT_CAPABILITY}</td>
5194     * <td>read/write</td>
5195     * <td>Contact IM chat compatibility value. The allowed values combinations of the following
5196     * flags. If None of these flags is set, the device can only do text messaging.
5197     * <p>
5198     * <ul>
5199     * <li>{@link #CAPABILITY_HAS_VIDEO}</li>
5200     * <li>{@link #CAPABILITY_HAS_VOICE}</li>
5201     * <li>{@link #CAPABILITY_HAS_CAMERA}</li>
5202     * </ul>
5203     * </p>
5204     * <p>
5205     * Since chat compatibility is inherently volatile as the contact's availability moves from
5206     * one device to another, the content provider may choose not to store this field in long-term
5207     * storage.
5208     * </p>
5209     * </td>
5210     * </tr>
5211     * <tr>
5212     * <td>String</td>
5213     * <td>{@link #STATUS}</td>
5214     * <td>read/write</td>
5215     * <td>Contact's latest status update, e.g. "having toast for breakfast"</td>
5216     * </tr>
5217     * <tr>
5218     * <td>long</td>
5219     * <td>{@link #STATUS_TIMESTAMP}</td>
5220     * <td>read/write</td>
5221     * <td>The absolute time in milliseconds when the status was
5222     * entered by the user. If this value is not provided, the provider will follow
5223     * this logic: if there was no prior status update, the value will be left as null.
5224     * If there was a prior status update, the provider will default this field
5225     * to the current time.</td>
5226     * </tr>
5227     * <tr>
5228     * <td>String</td>
5229     * <td>{@link #STATUS_RES_PACKAGE}</td>
5230     * <td>read/write</td>
5231     * <td> The package containing resources for this status: label and icon.</td>
5232     * </tr>
5233     * <tr>
5234     * <td>long</td>
5235     * <td>{@link #STATUS_LABEL}</td>
5236     * <td>read/write</td>
5237     * <td>The resource ID of the label describing the source of contact status,
5238     * e.g. "Google Talk". This resource is scoped by the
5239     * {@link #STATUS_RES_PACKAGE}.</td>
5240     * </tr>
5241     * <tr>
5242     * <td>long</td>
5243     * <td>{@link #STATUS_ICON}</td>
5244     * <td>read/write</td>
5245     * <td>The resource ID of the icon for the source of contact status. This
5246     * resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
5247     * </tr>
5248     * </table>
5249     */
5250    public static class StatusUpdates implements StatusColumns, PresenceColumns {
5251
5252        /**
5253         * This utility class cannot be instantiated
5254         */
5255        private StatusUpdates() {}
5256
5257        /**
5258         * The content:// style URI for this table
5259         */
5260        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates");
5261
5262        /**
5263         * The content:// style URI for this table, specific to the user's profile.
5264         */
5265        public static final Uri PROFILE_CONTENT_URI =
5266                Uri.withAppendedPath(Profile.CONTENT_URI, "status_updates");
5267
5268        /**
5269         * Gets the resource ID for the proper presence icon.
5270         *
5271         * @param status the status to get the icon for
5272         * @return the resource ID for the proper presence icon
5273         */
5274        public static final int getPresenceIconResourceId(int status) {
5275            switch (status) {
5276                case AVAILABLE:
5277                    return android.R.drawable.presence_online;
5278                case IDLE:
5279                case AWAY:
5280                    return android.R.drawable.presence_away;
5281                case DO_NOT_DISTURB:
5282                    return android.R.drawable.presence_busy;
5283                case INVISIBLE:
5284                    return android.R.drawable.presence_invisible;
5285                case OFFLINE:
5286                default:
5287                    return android.R.drawable.presence_offline;
5288            }
5289        }
5290
5291        /**
5292         * Returns the precedence of the status code the higher number being the higher precedence.
5293         *
5294         * @param status The status code.
5295         * @return An integer representing the precedence, 0 being the lowest.
5296         */
5297        public static final int getPresencePrecedence(int status) {
5298            // Keep this function here incase we want to enforce a different precedence than the
5299            // natural order of the status constants.
5300            return status;
5301        }
5302
5303        /**
5304         * The MIME type of {@link #CONTENT_URI} providing a directory of
5305         * status update details.
5306         */
5307        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/status-update";
5308
5309        /**
5310         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
5311         * status update detail.
5312         */
5313        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update";
5314    }
5315
5316    /**
5317     * @deprecated This old name was never meant to be made public. Do not use.
5318     */
5319    @Deprecated
5320    public static final class Presence extends StatusUpdates {
5321
5322    }
5323
5324    /**
5325     * Additional column returned by
5326     * {@link ContactsContract.Contacts#CONTENT_FILTER_URI Contacts.CONTENT_FILTER_URI} explaining
5327     * why the filter matched the contact. This column will contain extracts from the contact's
5328     * constituent {@link Data Data} items, formatted in a way that indicates the section of the
5329     * snippet that matched the filter.
5330     *
5331     * <p>
5332     * The following example searches for all contacts that match the query "presi" and requests
5333     * the snippet column as well.
5334     * <pre>
5335     * Builder builder = Contacts.CONTENT_FILTER_URI.buildUpon();
5336     * builder.appendPath("presi");
5337     * // Defer snippeting to the client side if possible, for performance reasons.
5338     * builder.appendQueryParameter(SearchSnippets.DEFERRED_SNIPPETING_KEY,"1");
5339     *
5340     * Cursor cursor = getContentResolver().query(builder.build());
5341     *
5342     * Bundle extras = cursor.getExtras();
5343     * if (extras.getBoolean(ContactsContract.DEFERRED_SNIPPETING)) {
5344     *     // Do our own snippet formatting.
5345     *     // For a contact with the email address (president@organization.com), the snippet
5346     *     // column will contain the string "president@organization.com".
5347     * } else {
5348     *     // The snippet has already been pre-formatted, we can display it as is.
5349     *     // For a contact with the email address (president@organization.com), the snippet
5350     *     // column will contain the string "[presi]dent@organization.com".
5351     * }
5352     * </pre>
5353     * </p>
5354     */
5355    public static class SearchSnippets {
5356
5357        /**
5358         * The search snippet constructed by SQLite snippeting functionality.
5359         * <p>
5360         * The snippet may contain (parts of) several data elements belonging to the contact,
5361         * with the matching parts optionally surrounded by special characters that indicate the
5362         * start and end of matching text.
5363         *
5364         * For example, if a contact has an address "123 Main Street", using a filter "mai" would
5365         * return the formatted snippet "123 [Mai]n street".
5366         *
5367         * @see <a href="http://www.sqlite.org/fts3.html#snippet">
5368         *         http://www.sqlite.org/fts3.html#snippet</a>
5369         */
5370        public static final String SNIPPET = "snippet";
5371
5372        /**
5373         * Comma-separated parameters for the generation of the snippet:
5374         * <ul>
5375         * <li>The "start match" text. Default is '['</li>
5376         * <li>The "end match" text. Default is ']'</li>
5377         * <li>The "ellipsis" text. Default is "..."</li>
5378         * <li>Maximum number of tokens to include in the snippet. Can be either
5379         * a positive or a negative number: A positive number indicates how many
5380         * tokens can be returned in total. A negative number indicates how many
5381         * tokens can be returned per occurrence of the search terms.</li>
5382         * </ul>
5383         *
5384         * @hide
5385         */
5386        public static final String SNIPPET_ARGS_PARAM_KEY = "snippet_args";
5387
5388        /**
5389         * The key to ask the provider to defer the formatting of the snippet to the client if
5390         * possible, for performance reasons.
5391         * A value of 1 indicates true, 0 indicates false. False is the default.
5392         * When a cursor is returned to the client, it should check for an extra with the name
5393         * {@link ContactsContract#DEFERRED_SNIPPETING} in the cursor. If it exists, the client
5394         * should do its own formatting of the snippet. If it doesn't exist, the snippet column
5395         * in the cursor should already contain a formatted snippet.
5396         */
5397        public static final String DEFERRED_SNIPPETING_KEY = "deferred_snippeting";
5398    }
5399
5400    /**
5401     * Container for definitions of common data types stored in the {@link ContactsContract.Data}
5402     * table.
5403     */
5404    public static final class CommonDataKinds {
5405        /**
5406         * This utility class cannot be instantiated
5407         */
5408        private CommonDataKinds() {}
5409
5410        /**
5411         * The {@link Data#RES_PACKAGE} value for common data that should be
5412         * shown using a default style.
5413         *
5414         * @hide RES_PACKAGE is hidden
5415         */
5416        public static final String PACKAGE_COMMON = "common";
5417
5418        /**
5419         * The base types that all "Typed" data kinds support.
5420         */
5421        public interface BaseTypes {
5422            /**
5423             * A custom type. The custom label should be supplied by user.
5424             */
5425            public static int TYPE_CUSTOM = 0;
5426        }
5427
5428        /**
5429         * Columns common across the specific types.
5430         */
5431        protected interface CommonColumns extends BaseTypes {
5432            /**
5433             * The data for the contact method.
5434             * <P>Type: TEXT</P>
5435             */
5436            public static final String DATA = DataColumns.DATA1;
5437
5438            /**
5439             * The type of data, for example Home or Work.
5440             * <P>Type: INTEGER</P>
5441             */
5442            public static final String TYPE = DataColumns.DATA2;
5443
5444            /**
5445             * The user defined label for the the contact method.
5446             * <P>Type: TEXT</P>
5447             */
5448            public static final String LABEL = DataColumns.DATA3;
5449        }
5450
5451        /**
5452         * A data kind representing the contact's proper name. You can use all
5453         * columns defined for {@link ContactsContract.Data} as well as the following aliases.
5454         *
5455         * <h2>Column aliases</h2>
5456         * <table class="jd-sumtable">
5457         * <tr>
5458         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
5459         * </tr>
5460         * <tr>
5461         * <td>String</td>
5462         * <td>{@link #DISPLAY_NAME}</td>
5463         * <td>{@link #DATA1}</td>
5464         * <td></td>
5465         * </tr>
5466         * <tr>
5467         * <td>String</td>
5468         * <td>{@link #GIVEN_NAME}</td>
5469         * <td>{@link #DATA2}</td>
5470         * <td></td>
5471         * </tr>
5472         * <tr>
5473         * <td>String</td>
5474         * <td>{@link #FAMILY_NAME}</td>
5475         * <td>{@link #DATA3}</td>
5476         * <td></td>
5477         * </tr>
5478         * <tr>
5479         * <td>String</td>
5480         * <td>{@link #PREFIX}</td>
5481         * <td>{@link #DATA4}</td>
5482         * <td>Common prefixes in English names are "Mr", "Ms", "Dr" etc.</td>
5483         * </tr>
5484         * <tr>
5485         * <td>String</td>
5486         * <td>{@link #MIDDLE_NAME}</td>
5487         * <td>{@link #DATA5}</td>
5488         * <td></td>
5489         * </tr>
5490         * <tr>
5491         * <td>String</td>
5492         * <td>{@link #SUFFIX}</td>
5493         * <td>{@link #DATA6}</td>
5494         * <td>Common suffixes in English names are "Sr", "Jr", "III" etc.</td>
5495         * </tr>
5496         * <tr>
5497         * <td>String</td>
5498         * <td>{@link #PHONETIC_GIVEN_NAME}</td>
5499         * <td>{@link #DATA7}</td>
5500         * <td>Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana</td>
5501         * </tr>
5502         * <tr>
5503         * <td>String</td>
5504         * <td>{@link #PHONETIC_MIDDLE_NAME}</td>
5505         * <td>{@link #DATA8}</td>
5506         * <td></td>
5507         * </tr>
5508         * <tr>
5509         * <td>String</td>
5510         * <td>{@link #PHONETIC_FAMILY_NAME}</td>
5511         * <td>{@link #DATA9}</td>
5512         * <td></td>
5513         * </tr>
5514         * </table>
5515         */
5516        public static final class StructuredName implements DataColumnsWithJoins, ContactCounts {
5517            /**
5518             * This utility class cannot be instantiated
5519             */
5520            private StructuredName() {}
5521
5522            /** MIME type used when storing this in data table. */
5523            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
5524
5525            /**
5526             * The name that should be used to display the contact.
5527             * <i>Unstructured component of the name should be consistent with
5528             * its structured representation.</i>
5529             * <p>
5530             * Type: TEXT
5531             */
5532            public static final String DISPLAY_NAME = DATA1;
5533
5534            /**
5535             * The given name for the contact.
5536             * <P>Type: TEXT</P>
5537             */
5538            public static final String GIVEN_NAME = DATA2;
5539
5540            /**
5541             * The family name for the contact.
5542             * <P>Type: TEXT</P>
5543             */
5544            public static final String FAMILY_NAME = DATA3;
5545
5546            /**
5547             * The contact's honorific prefix, e.g. "Sir"
5548             * <P>Type: TEXT</P>
5549             */
5550            public static final String PREFIX = DATA4;
5551
5552            /**
5553             * The contact's middle name
5554             * <P>Type: TEXT</P>
5555             */
5556            public static final String MIDDLE_NAME = DATA5;
5557
5558            /**
5559             * The contact's honorific suffix, e.g. "Jr"
5560             */
5561            public static final String SUFFIX = DATA6;
5562
5563            /**
5564             * The phonetic version of the given name for the contact.
5565             * <P>Type: TEXT</P>
5566             */
5567            public static final String PHONETIC_GIVEN_NAME = DATA7;
5568
5569            /**
5570             * The phonetic version of the additional name for the contact.
5571             * <P>Type: TEXT</P>
5572             */
5573            public static final String PHONETIC_MIDDLE_NAME = DATA8;
5574
5575            /**
5576             * The phonetic version of the family name for the contact.
5577             * <P>Type: TEXT</P>
5578             */
5579            public static final String PHONETIC_FAMILY_NAME = DATA9;
5580
5581            /**
5582             * The style used for combining given/middle/family name into a full name.
5583             * See {@link ContactsContract.FullNameStyle}.
5584             */
5585            public static final String FULL_NAME_STYLE = DATA10;
5586
5587            /**
5588             * The alphabet used for capturing the phonetic name.
5589             * See ContactsContract.PhoneticNameStyle.
5590             * @hide
5591             */
5592            public static final String PHONETIC_NAME_STYLE = DATA11;
5593        }
5594
5595        /**
5596         * <p>A data kind representing the contact's nickname. For example, for
5597         * Bob Parr ("Mr. Incredible"):
5598         * <pre>
5599         * ArrayList&lt;ContentProviderOperation&gt; ops =
5600         *          new ArrayList&lt;ContentProviderOperation&gt;();
5601         *
5602         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
5603         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
5604         *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
5605         *          .withValue(StructuredName.DISPLAY_NAME, &quot;Bob Parr&quot;)
5606         *          .build());
5607         *
5608         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
5609         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
5610         *          .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
5611         *          .withValue(Nickname.NAME, "Mr. Incredible")
5612         *          .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM)
5613         *          .withValue(Nickname.LABEL, "Superhero")
5614         *          .build());
5615         *
5616         * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
5617         * </pre>
5618         * </p>
5619         * <p>
5620         * You can use all columns defined for {@link ContactsContract.Data} as well as the
5621         * following aliases.
5622         * </p>
5623         *
5624         * <h2>Column aliases</h2>
5625         * <table class="jd-sumtable">
5626         * <tr>
5627         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
5628         * </tr>
5629         * <tr>
5630         * <td>String</td>
5631         * <td>{@link #NAME}</td>
5632         * <td>{@link #DATA1}</td>
5633         * <td></td>
5634         * </tr>
5635         * <tr>
5636         * <td>int</td>
5637         * <td>{@link #TYPE}</td>
5638         * <td>{@link #DATA2}</td>
5639         * <td>
5640         * Allowed values are:
5641         * <p>
5642         * <ul>
5643         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5644         * <li>{@link #TYPE_DEFAULT}</li>
5645         * <li>{@link #TYPE_OTHER_NAME}</li>
5646         * <li>{@link #TYPE_MAIDEN_NAME}</li>
5647         * <li>{@link #TYPE_SHORT_NAME}</li>
5648         * <li>{@link #TYPE_INITIALS}</li>
5649         * </ul>
5650         * </p>
5651         * </td>
5652         * </tr>
5653         * <tr>
5654         * <td>String</td>
5655         * <td>{@link #LABEL}</td>
5656         * <td>{@link #DATA3}</td>
5657         * <td></td>
5658         * </tr>
5659         * </table>
5660         */
5661        public static final class Nickname implements DataColumnsWithJoins, CommonColumns,
5662                ContactCounts{
5663            /**
5664             * This utility class cannot be instantiated
5665             */
5666            private Nickname() {}
5667
5668            /** MIME type used when storing this in data table. */
5669            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
5670
5671            public static final int TYPE_DEFAULT = 1;
5672            public static final int TYPE_OTHER_NAME = 2;
5673            public static final int TYPE_MAIDEN_NAME = 3;
5674            /** @deprecated Use TYPE_MAIDEN_NAME instead. */
5675            @Deprecated
5676            public static final int TYPE_MAINDEN_NAME = 3;
5677            public static final int TYPE_SHORT_NAME = 4;
5678            public static final int TYPE_INITIALS = 5;
5679
5680            /**
5681             * The name itself
5682             */
5683            public static final String NAME = DATA;
5684        }
5685
5686        /**
5687         * <p>
5688         * A data kind representing a telephone number.
5689         * </p>
5690         * <p>
5691         * You can use all columns defined for {@link ContactsContract.Data} as
5692         * well as the following aliases.
5693         * </p>
5694         * <h2>Column aliases</h2>
5695         * <table class="jd-sumtable">
5696         * <tr>
5697         * <th>Type</th>
5698         * <th>Alias</th><th colspan='2'>Data column</th>
5699         * </tr>
5700         * <tr>
5701         * <td>String</td>
5702         * <td>{@link #NUMBER}</td>
5703         * <td>{@link #DATA1}</td>
5704         * <td></td>
5705         * </tr>
5706         * <tr>
5707         * <td>int</td>
5708         * <td>{@link #TYPE}</td>
5709         * <td>{@link #DATA2}</td>
5710         * <td>Allowed values are:
5711         * <p>
5712         * <ul>
5713         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5714         * <li>{@link #TYPE_HOME}</li>
5715         * <li>{@link #TYPE_MOBILE}</li>
5716         * <li>{@link #TYPE_WORK}</li>
5717         * <li>{@link #TYPE_FAX_WORK}</li>
5718         * <li>{@link #TYPE_FAX_HOME}</li>
5719         * <li>{@link #TYPE_PAGER}</li>
5720         * <li>{@link #TYPE_OTHER}</li>
5721         * <li>{@link #TYPE_CALLBACK}</li>
5722         * <li>{@link #TYPE_CAR}</li>
5723         * <li>{@link #TYPE_COMPANY_MAIN}</li>
5724         * <li>{@link #TYPE_ISDN}</li>
5725         * <li>{@link #TYPE_MAIN}</li>
5726         * <li>{@link #TYPE_OTHER_FAX}</li>
5727         * <li>{@link #TYPE_RADIO}</li>
5728         * <li>{@link #TYPE_TELEX}</li>
5729         * <li>{@link #TYPE_TTY_TDD}</li>
5730         * <li>{@link #TYPE_WORK_MOBILE}</li>
5731         * <li>{@link #TYPE_WORK_PAGER}</li>
5732         * <li>{@link #TYPE_ASSISTANT}</li>
5733         * <li>{@link #TYPE_MMS}</li>
5734         * </ul>
5735         * </p>
5736         * </td>
5737         * </tr>
5738         * <tr>
5739         * <td>String</td>
5740         * <td>{@link #LABEL}</td>
5741         * <td>{@link #DATA3}</td>
5742         * <td></td>
5743         * </tr>
5744         * </table>
5745         */
5746        public static final class Phone implements DataColumnsWithJoins, CommonColumns,
5747                ContactCounts {
5748            /**
5749             * This utility class cannot be instantiated
5750             */
5751            private Phone() {}
5752
5753            /** MIME type used when storing this in data table. */
5754            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2";
5755
5756            /**
5757             * The MIME type of {@link #CONTENT_URI} providing a directory of
5758             * phones.
5759             */
5760            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2";
5761
5762            /**
5763             * The content:// style URI for all data records of the
5764             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
5765             * associated raw contact and aggregate contact data.
5766             */
5767            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
5768                    "phones");
5769
5770            /**
5771            * URI used for getting all contacts from primary and managed profile.
5772            *
5773            * It supports the same semantics as {@link #CONTENT_URI} and returns the same
5774            * columns.  If the device has no corp profile that is linked to the current profile, it
5775            * behaves in the exact same way as {@link #CONTENT_URI}.  If there is a corp profile
5776            * linked to the current profile, it will merge corp profile and current profile's
5777            * results and return
5778            *
5779            * @hide
5780            */
5781            public static final Uri ENTERPRISE_CONTENT_URI =
5782                    Uri.withAppendedPath(Data.ENTERPRISE_CONTENT_URI, "phones");
5783
5784            /**
5785             * The content:// style URL for phone lookup using a filter. The filter returns
5786             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
5787             * to display names as well as phone numbers. The filter argument should be passed
5788             * as an additional path segment after this URI.
5789             */
5790            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
5791                    "filter");
5792
5793            /**
5794             * A boolean query parameter that can be used with {@link #CONTENT_FILTER_URI}.
5795             * If "1" or "true", display names are searched.  If "0" or "false", display names
5796             * are not searched.  Default is "1".
5797             */
5798            public static final String SEARCH_DISPLAY_NAME_KEY = "search_display_name";
5799
5800            /**
5801             * A boolean query parameter that can be used with {@link #CONTENT_FILTER_URI}.
5802             * If "1" or "true", phone numbers are searched.  If "0" or "false", phone numbers
5803             * are not searched.  Default is "1".
5804             */
5805            public static final String SEARCH_PHONE_NUMBER_KEY = "search_phone_number";
5806
5807            public static final int TYPE_HOME = 1;
5808            public static final int TYPE_MOBILE = 2;
5809            public static final int TYPE_WORK = 3;
5810            public static final int TYPE_FAX_WORK = 4;
5811            public static final int TYPE_FAX_HOME = 5;
5812            public static final int TYPE_PAGER = 6;
5813            public static final int TYPE_OTHER = 7;
5814            public static final int TYPE_CALLBACK = 8;
5815            public static final int TYPE_CAR = 9;
5816            public static final int TYPE_COMPANY_MAIN = 10;
5817            public static final int TYPE_ISDN = 11;
5818            public static final int TYPE_MAIN = 12;
5819            public static final int TYPE_OTHER_FAX = 13;
5820            public static final int TYPE_RADIO = 14;
5821            public static final int TYPE_TELEX = 15;
5822            public static final int TYPE_TTY_TDD = 16;
5823            public static final int TYPE_WORK_MOBILE = 17;
5824            public static final int TYPE_WORK_PAGER = 18;
5825            public static final int TYPE_ASSISTANT = 19;
5826            public static final int TYPE_MMS = 20;
5827
5828            /**
5829             * The phone number as the user entered it.
5830             * <P>Type: TEXT</P>
5831             */
5832            public static final String NUMBER = DATA;
5833
5834            /**
5835             * The phone number's E164 representation. This value can be omitted in which
5836             * case the provider will try to automatically infer it.  (It'll be left null if the
5837             * provider fails to infer.)
5838             * If present, {@link #NUMBER} has to be set as well (it will be ignored otherwise).
5839             * <P>Type: TEXT</P>
5840             */
5841            public static final String NORMALIZED_NUMBER = DATA4;
5842
5843            /**
5844             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
5845             * @hide
5846             */
5847            @Deprecated
5848            public static final CharSequence getDisplayLabel(Context context, int type,
5849                    CharSequence label, CharSequence[] labelArray) {
5850                return getTypeLabel(context.getResources(), type, label);
5851            }
5852
5853            /**
5854             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
5855             * @hide
5856             */
5857            @Deprecated
5858            public static final CharSequence getDisplayLabel(Context context, int type,
5859                    CharSequence label) {
5860                return getTypeLabel(context.getResources(), type, label);
5861            }
5862
5863            /**
5864             * Return the string resource that best describes the given
5865             * {@link #TYPE}. Will always return a valid resource.
5866             */
5867            public static final int getTypeLabelResource(int type) {
5868                switch (type) {
5869                    case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome;
5870                    case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile;
5871                    case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork;
5872                    case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork;
5873                    case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome;
5874                    case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager;
5875                    case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther;
5876                    case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback;
5877                    case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar;
5878                    case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain;
5879                    case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn;
5880                    case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain;
5881                    case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax;
5882                    case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio;
5883                    case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex;
5884                    case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd;
5885                    case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile;
5886                    case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager;
5887                    case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant;
5888                    case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms;
5889                    default: return com.android.internal.R.string.phoneTypeCustom;
5890                }
5891            }
5892
5893            /**
5894             * Return a {@link CharSequence} that best describes the given type,
5895             * possibly substituting the given {@link #LABEL} value
5896             * for {@link #TYPE_CUSTOM}.
5897             */
5898            public static final CharSequence getTypeLabel(Resources res, int type,
5899                    CharSequence label) {
5900                if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) {
5901                    return label;
5902                } else {
5903                    final int labelRes = getTypeLabelResource(type);
5904                    return res.getText(labelRes);
5905                }
5906            }
5907        }
5908
5909        /**
5910         * <p>
5911         * A data kind representing an email address.
5912         * </p>
5913         * <p>
5914         * You can use all columns defined for {@link ContactsContract.Data} as
5915         * well as the following aliases.
5916         * </p>
5917         * <h2>Column aliases</h2>
5918         * <table class="jd-sumtable">
5919         * <tr>
5920         * <th>Type</th>
5921         * <th>Alias</th><th colspan='2'>Data column</th>
5922         * </tr>
5923         * <tr>
5924         * <td>String</td>
5925         * <td>{@link #ADDRESS}</td>
5926         * <td>{@link #DATA1}</td>
5927         * <td>Email address itself.</td>
5928         * </tr>
5929         * <tr>
5930         * <td>int</td>
5931         * <td>{@link #TYPE}</td>
5932         * <td>{@link #DATA2}</td>
5933         * <td>Allowed values are:
5934         * <p>
5935         * <ul>
5936         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5937         * <li>{@link #TYPE_HOME}</li>
5938         * <li>{@link #TYPE_WORK}</li>
5939         * <li>{@link #TYPE_OTHER}</li>
5940         * <li>{@link #TYPE_MOBILE}</li>
5941         * </ul>
5942         * </p>
5943         * </td>
5944         * </tr>
5945         * <tr>
5946         * <td>String</td>
5947         * <td>{@link #LABEL}</td>
5948         * <td>{@link #DATA3}</td>
5949         * <td></td>
5950         * </tr>
5951         * </table>
5952         */
5953        public static final class Email implements DataColumnsWithJoins, CommonColumns,
5954                ContactCounts {
5955            /**
5956             * This utility class cannot be instantiated
5957             */
5958            private Email() {}
5959
5960            /** MIME type used when storing this in data table. */
5961            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
5962
5963            /**
5964             * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses.
5965             */
5966            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";
5967
5968            /**
5969             * The content:// style URI for all data records of the
5970             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
5971             * associated raw contact and aggregate contact data.
5972             */
5973            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
5974                    "emails");
5975
5976            /**
5977             * <p>
5978             * The content:// style URL for looking up data rows by email address. The
5979             * lookup argument, an email address, should be passed as an additional path segment
5980             * after this URI.
5981             * </p>
5982             * <p>Example:
5983             * <pre>
5984             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email));
5985             * Cursor c = getContentResolver().query(uri,
5986             *          new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
5987             *          null, null, null);
5988             * </pre>
5989             * </p>
5990             */
5991            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
5992                    "lookup");
5993
5994            /**
5995            * <p>URI used for enterprise email lookup.</p>
5996            *
5997            * <p>
5998            * It supports the same semantics as {@link #CONTENT_LOOKUP_URI} and returns the same
5999            * columns.  If the device has no corp profile that is linked to the current profile, it
6000            * behaves in the exact same way as {@link #CONTENT_LOOKUP_URI}.  If there is a
6001            * corp profile linked to the current profile, it first queries against the personal contact database,
6002            * and if no matching contacts are found there, then queries against the
6003            * corp contacts database.
6004            * </p>
6005            * <p>
6006            * If a result is from the corp profile, it makes the following changes to the data:
6007            * <ul>
6008            *     <li>
6009            *     {@link #PHOTO_THUMBNAIL_URI} and {@link #PHOTO_URI} will be rewritten to special
6010            *     URIs.  Use {@link ContentResolver#openAssetFileDescriptor} or its siblings to
6011            *     load pictures from them.
6012            *     {@link #PHOTO_ID} and {@link #PHOTO_FILE_ID} will be set to null.  Do not
6013            *     use them.
6014            *     </li>
6015            *     <li>
6016            *     Corp contacts will get artificial {@link #CONTACT_ID}s.  In order to tell whether
6017            *     a contact
6018            *     is from the corp profile, use
6019            *     {@link ContactsContract.Contacts#isEnterpriseContactId(long)}.
6020            *     </li>
6021            * </ul>
6022            * <p>
6023            * This URI does NOT support selection nor order-by.
6024            *
6025            * <pre>
6026            * Uri lookupUri = Uri.withAppendedPath(Email.ENTERPRISE_CONTENT_LOOKUP_URI,
6027            *         Uri.encode(email));
6028            * </pre>
6029            */
6030            public static final Uri ENTERPRISE_CONTENT_LOOKUP_URI =
6031                    Uri.withAppendedPath(CONTENT_URI, "lookup_enterprise");
6032
6033            /**
6034             * <p>
6035             * The content:// style URL for email lookup using a filter. The filter returns
6036             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
6037             * to display names as well as email addresses. The filter argument should be passed
6038             * as an additional path segment after this URI.
6039             * </p>
6040             * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)"
6041             * as well as "Bob Parr (incredible@android.com)".
6042             * <pre>
6043             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
6044             * Cursor c = getContentResolver().query(uri,
6045             *          new String[]{Email.DISPLAY_NAME, Email.DATA},
6046             *          null, null, null);
6047             * </pre>
6048             * </p>
6049             */
6050            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
6051                    "filter");
6052
6053            /**
6054             * The email address.
6055             * <P>Type: TEXT</P>
6056             */
6057            public static final String ADDRESS = DATA1;
6058
6059            public static final int TYPE_HOME = 1;
6060            public static final int TYPE_WORK = 2;
6061            public static final int TYPE_OTHER = 3;
6062            public static final int TYPE_MOBILE = 4;
6063
6064            /**
6065             * The display name for the email address
6066             * <P>Type: TEXT</P>
6067             */
6068            public static final String DISPLAY_NAME = DATA4;
6069
6070            /**
6071             * Return the string resource that best describes the given
6072             * {@link #TYPE}. Will always return a valid resource.
6073             */
6074            public static final int getTypeLabelResource(int type) {
6075                switch (type) {
6076                    case TYPE_HOME: return com.android.internal.R.string.emailTypeHome;
6077                    case TYPE_WORK: return com.android.internal.R.string.emailTypeWork;
6078                    case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther;
6079                    case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile;
6080                    default: return com.android.internal.R.string.emailTypeCustom;
6081                }
6082            }
6083
6084            /**
6085             * Return a {@link CharSequence} that best describes the given type,
6086             * possibly substituting the given {@link #LABEL} value
6087             * for {@link #TYPE_CUSTOM}.
6088             */
6089            public static final CharSequence getTypeLabel(Resources res, int type,
6090                    CharSequence label) {
6091                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6092                    return label;
6093                } else {
6094                    final int labelRes = getTypeLabelResource(type);
6095                    return res.getText(labelRes);
6096                }
6097            }
6098        }
6099
6100        /**
6101         * <p>
6102         * A data kind representing a postal addresses.
6103         * </p>
6104         * <p>
6105         * You can use all columns defined for {@link ContactsContract.Data} as
6106         * well as the following aliases.
6107         * </p>
6108         * <h2>Column aliases</h2>
6109         * <table class="jd-sumtable">
6110         * <tr>
6111         * <th>Type</th>
6112         * <th>Alias</th><th colspan='2'>Data column</th>
6113         * </tr>
6114         * <tr>
6115         * <td>String</td>
6116         * <td>{@link #FORMATTED_ADDRESS}</td>
6117         * <td>{@link #DATA1}</td>
6118         * <td></td>
6119         * </tr>
6120         * <tr>
6121         * <td>int</td>
6122         * <td>{@link #TYPE}</td>
6123         * <td>{@link #DATA2}</td>
6124         * <td>Allowed values are:
6125         * <p>
6126         * <ul>
6127         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6128         * <li>{@link #TYPE_HOME}</li>
6129         * <li>{@link #TYPE_WORK}</li>
6130         * <li>{@link #TYPE_OTHER}</li>
6131         * </ul>
6132         * </p>
6133         * </td>
6134         * </tr>
6135         * <tr>
6136         * <td>String</td>
6137         * <td>{@link #LABEL}</td>
6138         * <td>{@link #DATA3}</td>
6139         * <td></td>
6140         * </tr>
6141         * <tr>
6142         * <td>String</td>
6143         * <td>{@link #STREET}</td>
6144         * <td>{@link #DATA4}</td>
6145         * <td></td>
6146         * </tr>
6147         * <tr>
6148         * <td>String</td>
6149         * <td>{@link #POBOX}</td>
6150         * <td>{@link #DATA5}</td>
6151         * <td>Post Office Box number</td>
6152         * </tr>
6153         * <tr>
6154         * <td>String</td>
6155         * <td>{@link #NEIGHBORHOOD}</td>
6156         * <td>{@link #DATA6}</td>
6157         * <td></td>
6158         * </tr>
6159         * <tr>
6160         * <td>String</td>
6161         * <td>{@link #CITY}</td>
6162         * <td>{@link #DATA7}</td>
6163         * <td></td>
6164         * </tr>
6165         * <tr>
6166         * <td>String</td>
6167         * <td>{@link #REGION}</td>
6168         * <td>{@link #DATA8}</td>
6169         * <td></td>
6170         * </tr>
6171         * <tr>
6172         * <td>String</td>
6173         * <td>{@link #POSTCODE}</td>
6174         * <td>{@link #DATA9}</td>
6175         * <td></td>
6176         * </tr>
6177         * <tr>
6178         * <td>String</td>
6179         * <td>{@link #COUNTRY}</td>
6180         * <td>{@link #DATA10}</td>
6181         * <td></td>
6182         * </tr>
6183         * </table>
6184         */
6185        public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns,
6186                ContactCounts {
6187            /**
6188             * This utility class cannot be instantiated
6189             */
6190            private StructuredPostal() {
6191            }
6192
6193            /** MIME type used when storing this in data table. */
6194            public static final String CONTENT_ITEM_TYPE =
6195                    "vnd.android.cursor.item/postal-address_v2";
6196
6197            /**
6198             * The MIME type of {@link #CONTENT_URI} providing a directory of
6199             * postal addresses.
6200             */
6201            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
6202
6203            /**
6204             * The content:// style URI for all data records of the
6205             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
6206             */
6207            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
6208                    "postals");
6209
6210            public static final int TYPE_HOME = 1;
6211            public static final int TYPE_WORK = 2;
6212            public static final int TYPE_OTHER = 3;
6213
6214            /**
6215             * The full, unstructured postal address. <i>This field must be
6216             * consistent with any structured data.</i>
6217             * <p>
6218             * Type: TEXT
6219             */
6220            public static final String FORMATTED_ADDRESS = DATA;
6221
6222            /**
6223             * Can be street, avenue, road, etc. This element also includes the
6224             * house number and room/apartment/flat/floor number.
6225             * <p>
6226             * Type: TEXT
6227             */
6228            public static final String STREET = DATA4;
6229
6230            /**
6231             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
6232             * usually but not always mutually exclusive with street.
6233             * <p>
6234             * Type: TEXT
6235             */
6236            public static final String POBOX = DATA5;
6237
6238            /**
6239             * This is used to disambiguate a street address when a city
6240             * contains more than one street with the same name, or to specify a
6241             * small place whose mail is routed through a larger postal town. In
6242             * China it could be a county or a minor city.
6243             * <p>
6244             * Type: TEXT
6245             */
6246            public static final String NEIGHBORHOOD = DATA6;
6247
6248            /**
6249             * Can be city, village, town, borough, etc. This is the postal town
6250             * and not necessarily the place of residence or place of business.
6251             * <p>
6252             * Type: TEXT
6253             */
6254            public static final String CITY = DATA7;
6255
6256            /**
6257             * A state, province, county (in Ireland), Land (in Germany),
6258             * departement (in France), etc.
6259             * <p>
6260             * Type: TEXT
6261             */
6262            public static final String REGION = DATA8;
6263
6264            /**
6265             * Postal code. Usually country-wide, but sometimes specific to the
6266             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
6267             * <p>
6268             * Type: TEXT
6269             */
6270            public static final String POSTCODE = DATA9;
6271
6272            /**
6273             * The name or code of the country.
6274             * <p>
6275             * Type: TEXT
6276             */
6277            public static final String COUNTRY = DATA10;
6278
6279            /**
6280             * Return the string resource that best describes the given
6281             * {@link #TYPE}. Will always return a valid resource.
6282             */
6283            public static final int getTypeLabelResource(int type) {
6284                switch (type) {
6285                    case TYPE_HOME: return com.android.internal.R.string.postalTypeHome;
6286                    case TYPE_WORK: return com.android.internal.R.string.postalTypeWork;
6287                    case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther;
6288                    default: return com.android.internal.R.string.postalTypeCustom;
6289                }
6290            }
6291
6292            /**
6293             * Return a {@link CharSequence} that best describes the given type,
6294             * possibly substituting the given {@link #LABEL} value
6295             * for {@link #TYPE_CUSTOM}.
6296             */
6297            public static final CharSequence getTypeLabel(Resources res, int type,
6298                    CharSequence label) {
6299                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6300                    return label;
6301                } else {
6302                    final int labelRes = getTypeLabelResource(type);
6303                    return res.getText(labelRes);
6304                }
6305            }
6306        }
6307
6308        /**
6309         * <p>
6310         * A data kind representing an IM address
6311         * </p>
6312         * <p>
6313         * You can use all columns defined for {@link ContactsContract.Data} as
6314         * well as the following aliases.
6315         * </p>
6316         * <h2>Column aliases</h2>
6317         * <table class="jd-sumtable">
6318         * <tr>
6319         * <th>Type</th>
6320         * <th>Alias</th><th colspan='2'>Data column</th>
6321         * </tr>
6322         * <tr>
6323         * <td>String</td>
6324         * <td>{@link #DATA}</td>
6325         * <td>{@link #DATA1}</td>
6326         * <td></td>
6327         * </tr>
6328         * <tr>
6329         * <td>int</td>
6330         * <td>{@link #TYPE}</td>
6331         * <td>{@link #DATA2}</td>
6332         * <td>Allowed values are:
6333         * <p>
6334         * <ul>
6335         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6336         * <li>{@link #TYPE_HOME}</li>
6337         * <li>{@link #TYPE_WORK}</li>
6338         * <li>{@link #TYPE_OTHER}</li>
6339         * </ul>
6340         * </p>
6341         * </td>
6342         * </tr>
6343         * <tr>
6344         * <td>String</td>
6345         * <td>{@link #LABEL}</td>
6346         * <td>{@link #DATA3}</td>
6347         * <td></td>
6348         * </tr>
6349         * <tr>
6350         * <td>String</td>
6351         * <td>{@link #PROTOCOL}</td>
6352         * <td>{@link #DATA5}</td>
6353         * <td>
6354         * <p>
6355         * Allowed values:
6356         * <ul>
6357         * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name
6358         * as {@link #CUSTOM_PROTOCOL}.</li>
6359         * <li>{@link #PROTOCOL_AIM}</li>
6360         * <li>{@link #PROTOCOL_MSN}</li>
6361         * <li>{@link #PROTOCOL_YAHOO}</li>
6362         * <li>{@link #PROTOCOL_SKYPE}</li>
6363         * <li>{@link #PROTOCOL_QQ}</li>
6364         * <li>{@link #PROTOCOL_GOOGLE_TALK}</li>
6365         * <li>{@link #PROTOCOL_ICQ}</li>
6366         * <li>{@link #PROTOCOL_JABBER}</li>
6367         * <li>{@link #PROTOCOL_NETMEETING}</li>
6368         * </ul>
6369         * </p>
6370         * </td>
6371         * </tr>
6372         * <tr>
6373         * <td>String</td>
6374         * <td>{@link #CUSTOM_PROTOCOL}</td>
6375         * <td>{@link #DATA6}</td>
6376         * <td></td>
6377         * </tr>
6378         * </table>
6379         */
6380        public static final class Im implements DataColumnsWithJoins, CommonColumns, ContactCounts {
6381            /**
6382             * This utility class cannot be instantiated
6383             */
6384            private Im() {}
6385
6386            /** MIME type used when storing this in data table. */
6387            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
6388
6389            public static final int TYPE_HOME = 1;
6390            public static final int TYPE_WORK = 2;
6391            public static final int TYPE_OTHER = 3;
6392
6393            /**
6394             * This column should be populated with one of the defined
6395             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
6396             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
6397             * should contain the name of the custom protocol.
6398             */
6399            public static final String PROTOCOL = DATA5;
6400
6401            public static final String CUSTOM_PROTOCOL = DATA6;
6402
6403            /*
6404             * The predefined IM protocol types.
6405             */
6406            public static final int PROTOCOL_CUSTOM = -1;
6407            public static final int PROTOCOL_AIM = 0;
6408            public static final int PROTOCOL_MSN = 1;
6409            public static final int PROTOCOL_YAHOO = 2;
6410            public static final int PROTOCOL_SKYPE = 3;
6411            public static final int PROTOCOL_QQ = 4;
6412            public static final int PROTOCOL_GOOGLE_TALK = 5;
6413            public static final int PROTOCOL_ICQ = 6;
6414            public static final int PROTOCOL_JABBER = 7;
6415            public static final int PROTOCOL_NETMEETING = 8;
6416
6417            /**
6418             * Return the string resource that best describes the given
6419             * {@link #TYPE}. Will always return a valid resource.
6420             */
6421            public static final int getTypeLabelResource(int type) {
6422                switch (type) {
6423                    case TYPE_HOME: return com.android.internal.R.string.imTypeHome;
6424                    case TYPE_WORK: return com.android.internal.R.string.imTypeWork;
6425                    case TYPE_OTHER: return com.android.internal.R.string.imTypeOther;
6426                    default: return com.android.internal.R.string.imTypeCustom;
6427                }
6428            }
6429
6430            /**
6431             * Return a {@link CharSequence} that best describes the given type,
6432             * possibly substituting the given {@link #LABEL} value
6433             * for {@link #TYPE_CUSTOM}.
6434             */
6435            public static final CharSequence getTypeLabel(Resources res, int type,
6436                    CharSequence label) {
6437                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6438                    return label;
6439                } else {
6440                    final int labelRes = getTypeLabelResource(type);
6441                    return res.getText(labelRes);
6442                }
6443            }
6444
6445            /**
6446             * Return the string resource that best describes the given
6447             * {@link #PROTOCOL}. Will always return a valid resource.
6448             */
6449            public static final int getProtocolLabelResource(int type) {
6450                switch (type) {
6451                    case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim;
6452                    case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn;
6453                    case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo;
6454                    case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype;
6455                    case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq;
6456                    case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk;
6457                    case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq;
6458                    case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber;
6459                    case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting;
6460                    default: return com.android.internal.R.string.imProtocolCustom;
6461                }
6462            }
6463
6464            /**
6465             * Return a {@link CharSequence} that best describes the given
6466             * protocol, possibly substituting the given
6467             * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}.
6468             */
6469            public static final CharSequence getProtocolLabel(Resources res, int type,
6470                    CharSequence label) {
6471                if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) {
6472                    return label;
6473                } else {
6474                    final int labelRes = getProtocolLabelResource(type);
6475                    return res.getText(labelRes);
6476                }
6477            }
6478        }
6479
6480        /**
6481         * <p>
6482         * A data kind representing an organization.
6483         * </p>
6484         * <p>
6485         * You can use all columns defined for {@link ContactsContract.Data} as
6486         * well as the following aliases.
6487         * </p>
6488         * <h2>Column aliases</h2>
6489         * <table class="jd-sumtable">
6490         * <tr>
6491         * <th>Type</th>
6492         * <th>Alias</th><th colspan='2'>Data column</th>
6493         * </tr>
6494         * <tr>
6495         * <td>String</td>
6496         * <td>{@link #COMPANY}</td>
6497         * <td>{@link #DATA1}</td>
6498         * <td></td>
6499         * </tr>
6500         * <tr>
6501         * <td>int</td>
6502         * <td>{@link #TYPE}</td>
6503         * <td>{@link #DATA2}</td>
6504         * <td>Allowed values are:
6505         * <p>
6506         * <ul>
6507         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6508         * <li>{@link #TYPE_WORK}</li>
6509         * <li>{@link #TYPE_OTHER}</li>
6510         * </ul>
6511         * </p>
6512         * </td>
6513         * </tr>
6514         * <tr>
6515         * <td>String</td>
6516         * <td>{@link #LABEL}</td>
6517         * <td>{@link #DATA3}</td>
6518         * <td></td>
6519         * </tr>
6520         * <tr>
6521         * <td>String</td>
6522         * <td>{@link #TITLE}</td>
6523         * <td>{@link #DATA4}</td>
6524         * <td></td>
6525         * </tr>
6526         * <tr>
6527         * <td>String</td>
6528         * <td>{@link #DEPARTMENT}</td>
6529         * <td>{@link #DATA5}</td>
6530         * <td></td>
6531         * </tr>
6532         * <tr>
6533         * <td>String</td>
6534         * <td>{@link #JOB_DESCRIPTION}</td>
6535         * <td>{@link #DATA6}</td>
6536         * <td></td>
6537         * </tr>
6538         * <tr>
6539         * <td>String</td>
6540         * <td>{@link #SYMBOL}</td>
6541         * <td>{@link #DATA7}</td>
6542         * <td></td>
6543         * </tr>
6544         * <tr>
6545         * <td>String</td>
6546         * <td>{@link #PHONETIC_NAME}</td>
6547         * <td>{@link #DATA8}</td>
6548         * <td></td>
6549         * </tr>
6550         * <tr>
6551         * <td>String</td>
6552         * <td>{@link #OFFICE_LOCATION}</td>
6553         * <td>{@link #DATA9}</td>
6554         * <td></td>
6555         * </tr>
6556         * <tr>
6557         * <td>String</td>
6558         * <td>PHONETIC_NAME_STYLE</td>
6559         * <td>{@link #DATA10}</td>
6560         * <td></td>
6561         * </tr>
6562         * </table>
6563         */
6564        public static final class Organization implements DataColumnsWithJoins, CommonColumns,
6565                ContactCounts {
6566            /**
6567             * This utility class cannot be instantiated
6568             */
6569            private Organization() {}
6570
6571            /** MIME type used when storing this in data table. */
6572            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
6573
6574            public static final int TYPE_WORK = 1;
6575            public static final int TYPE_OTHER = 2;
6576
6577            /**
6578             * The company as the user entered it.
6579             * <P>Type: TEXT</P>
6580             */
6581            public static final String COMPANY = DATA;
6582
6583            /**
6584             * The position title at this company as the user entered it.
6585             * <P>Type: TEXT</P>
6586             */
6587            public static final String TITLE = DATA4;
6588
6589            /**
6590             * The department at this company as the user entered it.
6591             * <P>Type: TEXT</P>
6592             */
6593            public static final String DEPARTMENT = DATA5;
6594
6595            /**
6596             * The job description at this company as the user entered it.
6597             * <P>Type: TEXT</P>
6598             */
6599            public static final String JOB_DESCRIPTION = DATA6;
6600
6601            /**
6602             * The symbol of this company as the user entered it.
6603             * <P>Type: TEXT</P>
6604             */
6605            public static final String SYMBOL = DATA7;
6606
6607            /**
6608             * The phonetic name of this company as the user entered it.
6609             * <P>Type: TEXT</P>
6610             */
6611            public static final String PHONETIC_NAME = DATA8;
6612
6613            /**
6614             * The office location of this organization.
6615             * <P>Type: TEXT</P>
6616             */
6617            public static final String OFFICE_LOCATION = DATA9;
6618
6619            /**
6620             * The alphabet used for capturing the phonetic name.
6621             * See {@link ContactsContract.PhoneticNameStyle}.
6622             * @hide
6623             */
6624            public static final String PHONETIC_NAME_STYLE = DATA10;
6625
6626            /**
6627             * Return the string resource that best describes the given
6628             * {@link #TYPE}. Will always return a valid resource.
6629             */
6630            public static final int getTypeLabelResource(int type) {
6631                switch (type) {
6632                    case TYPE_WORK: return com.android.internal.R.string.orgTypeWork;
6633                    case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther;
6634                    default: return com.android.internal.R.string.orgTypeCustom;
6635                }
6636            }
6637
6638            /**
6639             * Return a {@link CharSequence} that best describes the given type,
6640             * possibly substituting the given {@link #LABEL} value
6641             * for {@link #TYPE_CUSTOM}.
6642             */
6643            public static final CharSequence getTypeLabel(Resources res, int type,
6644                    CharSequence label) {
6645                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6646                    return label;
6647                } else {
6648                    final int labelRes = getTypeLabelResource(type);
6649                    return res.getText(labelRes);
6650                }
6651            }
6652        }
6653
6654        /**
6655         * <p>
6656         * A data kind representing a relation.
6657         * </p>
6658         * <p>
6659         * You can use all columns defined for {@link ContactsContract.Data} as
6660         * well as the following aliases.
6661         * </p>
6662         * <h2>Column aliases</h2>
6663         * <table class="jd-sumtable">
6664         * <tr>
6665         * <th>Type</th>
6666         * <th>Alias</th><th colspan='2'>Data column</th>
6667         * </tr>
6668         * <tr>
6669         * <td>String</td>
6670         * <td>{@link #NAME}</td>
6671         * <td>{@link #DATA1}</td>
6672         * <td></td>
6673         * </tr>
6674         * <tr>
6675         * <td>int</td>
6676         * <td>{@link #TYPE}</td>
6677         * <td>{@link #DATA2}</td>
6678         * <td>Allowed values are:
6679         * <p>
6680         * <ul>
6681         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6682         * <li>{@link #TYPE_ASSISTANT}</li>
6683         * <li>{@link #TYPE_BROTHER}</li>
6684         * <li>{@link #TYPE_CHILD}</li>
6685         * <li>{@link #TYPE_DOMESTIC_PARTNER}</li>
6686         * <li>{@link #TYPE_FATHER}</li>
6687         * <li>{@link #TYPE_FRIEND}</li>
6688         * <li>{@link #TYPE_MANAGER}</li>
6689         * <li>{@link #TYPE_MOTHER}</li>
6690         * <li>{@link #TYPE_PARENT}</li>
6691         * <li>{@link #TYPE_PARTNER}</li>
6692         * <li>{@link #TYPE_REFERRED_BY}</li>
6693         * <li>{@link #TYPE_RELATIVE}</li>
6694         * <li>{@link #TYPE_SISTER}</li>
6695         * <li>{@link #TYPE_SPOUSE}</li>
6696         * </ul>
6697         * </p>
6698         * </td>
6699         * </tr>
6700         * <tr>
6701         * <td>String</td>
6702         * <td>{@link #LABEL}</td>
6703         * <td>{@link #DATA3}</td>
6704         * <td></td>
6705         * </tr>
6706         * </table>
6707         */
6708        public static final class Relation implements DataColumnsWithJoins, CommonColumns,
6709                ContactCounts {
6710            /**
6711             * This utility class cannot be instantiated
6712             */
6713            private Relation() {}
6714
6715            /** MIME type used when storing this in data table. */
6716            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
6717
6718            public static final int TYPE_ASSISTANT = 1;
6719            public static final int TYPE_BROTHER = 2;
6720            public static final int TYPE_CHILD = 3;
6721            public static final int TYPE_DOMESTIC_PARTNER = 4;
6722            public static final int TYPE_FATHER = 5;
6723            public static final int TYPE_FRIEND = 6;
6724            public static final int TYPE_MANAGER = 7;
6725            public static final int TYPE_MOTHER = 8;
6726            public static final int TYPE_PARENT = 9;
6727            public static final int TYPE_PARTNER = 10;
6728            public static final int TYPE_REFERRED_BY = 11;
6729            public static final int TYPE_RELATIVE = 12;
6730            public static final int TYPE_SISTER = 13;
6731            public static final int TYPE_SPOUSE = 14;
6732
6733            /**
6734             * The name of the relative as the user entered it.
6735             * <P>Type: TEXT</P>
6736             */
6737            public static final String NAME = DATA;
6738
6739            /**
6740             * Return the string resource that best describes the given
6741             * {@link #TYPE}. Will always return a valid resource.
6742             */
6743            public static final int getTypeLabelResource(int type) {
6744                switch (type) {
6745                    case TYPE_ASSISTANT: return com.android.internal.R.string.relationTypeAssistant;
6746                    case TYPE_BROTHER: return com.android.internal.R.string.relationTypeBrother;
6747                    case TYPE_CHILD: return com.android.internal.R.string.relationTypeChild;
6748                    case TYPE_DOMESTIC_PARTNER:
6749                            return com.android.internal.R.string.relationTypeDomesticPartner;
6750                    case TYPE_FATHER: return com.android.internal.R.string.relationTypeFather;
6751                    case TYPE_FRIEND: return com.android.internal.R.string.relationTypeFriend;
6752                    case TYPE_MANAGER: return com.android.internal.R.string.relationTypeManager;
6753                    case TYPE_MOTHER: return com.android.internal.R.string.relationTypeMother;
6754                    case TYPE_PARENT: return com.android.internal.R.string.relationTypeParent;
6755                    case TYPE_PARTNER: return com.android.internal.R.string.relationTypePartner;
6756                    case TYPE_REFERRED_BY:
6757                            return com.android.internal.R.string.relationTypeReferredBy;
6758                    case TYPE_RELATIVE: return com.android.internal.R.string.relationTypeRelative;
6759                    case TYPE_SISTER: return com.android.internal.R.string.relationTypeSister;
6760                    case TYPE_SPOUSE: return com.android.internal.R.string.relationTypeSpouse;
6761                    default: return com.android.internal.R.string.orgTypeCustom;
6762                }
6763            }
6764
6765            /**
6766             * Return a {@link CharSequence} that best describes the given type,
6767             * possibly substituting the given {@link #LABEL} value
6768             * for {@link #TYPE_CUSTOM}.
6769             */
6770            public static final CharSequence getTypeLabel(Resources res, int type,
6771                    CharSequence label) {
6772                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6773                    return label;
6774                } else {
6775                    final int labelRes = getTypeLabelResource(type);
6776                    return res.getText(labelRes);
6777                }
6778            }
6779        }
6780
6781        /**
6782         * <p>
6783         * A data kind representing an event.
6784         * </p>
6785         * <p>
6786         * You can use all columns defined for {@link ContactsContract.Data} as
6787         * well as the following aliases.
6788         * </p>
6789         * <h2>Column aliases</h2>
6790         * <table class="jd-sumtable">
6791         * <tr>
6792         * <th>Type</th>
6793         * <th>Alias</th><th colspan='2'>Data column</th>
6794         * </tr>
6795         * <tr>
6796         * <td>String</td>
6797         * <td>{@link #START_DATE}</td>
6798         * <td>{@link #DATA1}</td>
6799         * <td></td>
6800         * </tr>
6801         * <tr>
6802         * <td>int</td>
6803         * <td>{@link #TYPE}</td>
6804         * <td>{@link #DATA2}</td>
6805         * <td>Allowed values are:
6806         * <p>
6807         * <ul>
6808         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6809         * <li>{@link #TYPE_ANNIVERSARY}</li>
6810         * <li>{@link #TYPE_OTHER}</li>
6811         * <li>{@link #TYPE_BIRTHDAY}</li>
6812         * </ul>
6813         * </p>
6814         * </td>
6815         * </tr>
6816         * <tr>
6817         * <td>String</td>
6818         * <td>{@link #LABEL}</td>
6819         * <td>{@link #DATA3}</td>
6820         * <td></td>
6821         * </tr>
6822         * </table>
6823         */
6824        public static final class Event implements DataColumnsWithJoins, CommonColumns,
6825                ContactCounts {
6826            /**
6827             * This utility class cannot be instantiated
6828             */
6829            private Event() {}
6830
6831            /** MIME type used when storing this in data table. */
6832            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event";
6833
6834            public static final int TYPE_ANNIVERSARY = 1;
6835            public static final int TYPE_OTHER = 2;
6836            public static final int TYPE_BIRTHDAY = 3;
6837
6838            /**
6839             * The event start date as the user entered it.
6840             * <P>Type: TEXT</P>
6841             */
6842            public static final String START_DATE = DATA;
6843
6844            /**
6845             * Return the string resource that best describes the given
6846             * {@link #TYPE}. Will always return a valid resource.
6847             */
6848            public static int getTypeResource(Integer type) {
6849                if (type == null) {
6850                    return com.android.internal.R.string.eventTypeOther;
6851                }
6852                switch (type) {
6853                    case TYPE_ANNIVERSARY:
6854                        return com.android.internal.R.string.eventTypeAnniversary;
6855                    case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday;
6856                    case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther;
6857                    default: return com.android.internal.R.string.eventTypeCustom;
6858                }
6859            }
6860
6861            /**
6862             * Return a {@link CharSequence} that best describes the given type,
6863             * possibly substituting the given {@link #LABEL} value
6864             * for {@link #TYPE_CUSTOM}.
6865             */
6866            public static final CharSequence getTypeLabel(Resources res, int type,
6867                    CharSequence label) {
6868                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6869                    return label;
6870                } else {
6871                    final int labelRes = getTypeResource(type);
6872                    return res.getText(labelRes);
6873                }
6874            }
6875        }
6876
6877        /**
6878         * <p>
6879         * A data kind representing a photo for the contact.
6880         * </p>
6881         * <p>
6882         * Some sync adapters will choose to download photos in a separate
6883         * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1}
6884         * through {@link ContactsContract.Data#SYNC4} to store temporary
6885         * data, e.g. the image URL or ID, state of download, server-side version
6886         * of the image.  It is allowed for the {@link #PHOTO} to be null.
6887         * </p>
6888         * <p>
6889         * You can use all columns defined for {@link ContactsContract.Data} as
6890         * well as the following aliases.
6891         * </p>
6892         * <h2>Column aliases</h2>
6893         * <table class="jd-sumtable">
6894         * <tr>
6895         * <th>Type</th>
6896         * <th>Alias</th><th colspan='2'>Data column</th>
6897         * </tr>
6898         * <tr>
6899         * <td>NUMBER</td>
6900         * <td>{@link #PHOTO_FILE_ID}</td>
6901         * <td>{@link #DATA14}</td>
6902         * <td>ID of the hi-res photo file.</td>
6903         * </tr>
6904         * <tr>
6905         * <td>BLOB</td>
6906         * <td>{@link #PHOTO}</td>
6907         * <td>{@link #DATA15}</td>
6908         * <td>By convention, binary data is stored in DATA15.  The thumbnail of the
6909         * photo is stored in this column.</td>
6910         * </tr>
6911         * </table>
6912         */
6913        public static final class Photo implements DataColumnsWithJoins, ContactCounts {
6914            /**
6915             * This utility class cannot be instantiated
6916             */
6917            private Photo() {}
6918
6919            /** MIME type used when storing this in data table. */
6920            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
6921
6922            /**
6923             * Photo file ID for the display photo of the raw contact.
6924             * See {@link ContactsContract.DisplayPhoto}.
6925             * <p>
6926             * Type: NUMBER
6927             */
6928            public static final String PHOTO_FILE_ID = DATA14;
6929
6930            /**
6931             * Thumbnail photo of the raw contact. This is the raw bytes of an image
6932             * that could be inflated using {@link android.graphics.BitmapFactory}.
6933             * <p>
6934             * Type: BLOB
6935             */
6936            public static final String PHOTO = DATA15;
6937        }
6938
6939        /**
6940         * <p>
6941         * Notes about the contact.
6942         * </p>
6943         * <p>
6944         * You can use all columns defined for {@link ContactsContract.Data} as
6945         * well as the following aliases.
6946         * </p>
6947         * <h2>Column aliases</h2>
6948         * <table class="jd-sumtable">
6949         * <tr>
6950         * <th>Type</th>
6951         * <th>Alias</th><th colspan='2'>Data column</th>
6952         * </tr>
6953         * <tr>
6954         * <td>String</td>
6955         * <td>{@link #NOTE}</td>
6956         * <td>{@link #DATA1}</td>
6957         * <td></td>
6958         * </tr>
6959         * </table>
6960         */
6961        public static final class Note implements DataColumnsWithJoins, ContactCounts {
6962            /**
6963             * This utility class cannot be instantiated
6964             */
6965            private Note() {}
6966
6967            /** MIME type used when storing this in data table. */
6968            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
6969
6970            /**
6971             * The note text.
6972             * <P>Type: TEXT</P>
6973             */
6974            public static final String NOTE = DATA1;
6975        }
6976
6977        /**
6978         * <p>
6979         * Group Membership.
6980         * </p>
6981         * <p>
6982         * You can use all columns defined for {@link ContactsContract.Data} as
6983         * well as the following aliases.
6984         * </p>
6985         * <h2>Column aliases</h2>
6986         * <table class="jd-sumtable">
6987         * <tr>
6988         * <th>Type</th>
6989         * <th>Alias</th><th colspan='2'>Data column</th>
6990         * </tr>
6991         * <tr>
6992         * <td>long</td>
6993         * <td>{@link #GROUP_ROW_ID}</td>
6994         * <td>{@link #DATA1}</td>
6995         * <td></td>
6996         * </tr>
6997         * <tr>
6998         * <td>String</td>
6999         * <td>{@link #GROUP_SOURCE_ID}</td>
7000         * <td>none</td>
7001         * <td>
7002         * <p>
7003         * The sourceid of the group that this group membership refers to.
7004         * Exactly one of this or {@link #GROUP_ROW_ID} must be set when
7005         * inserting a row.
7006         * </p>
7007         * <p>
7008         * If this field is specified, the provider will first try to
7009         * look up a group with this {@link Groups Groups.SOURCE_ID}.  If such a group
7010         * is found, it will use the corresponding row id.  If the group is not
7011         * found, it will create one.
7012         * </td>
7013         * </tr>
7014         * </table>
7015         */
7016        public static final class GroupMembership implements DataColumnsWithJoins, ContactCounts {
7017            /**
7018             * This utility class cannot be instantiated
7019             */
7020            private GroupMembership() {}
7021
7022            /** MIME type used when storing this in data table. */
7023            public static final String CONTENT_ITEM_TYPE =
7024                    "vnd.android.cursor.item/group_membership";
7025
7026            /**
7027             * The row id of the group that this group membership refers to. Exactly one of
7028             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
7029             * <P>Type: INTEGER</P>
7030             */
7031            public static final String GROUP_ROW_ID = DATA1;
7032
7033            /**
7034             * The sourceid of the group that this group membership refers to.  Exactly one of
7035             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
7036             * <P>Type: TEXT</P>
7037             */
7038            public static final String GROUP_SOURCE_ID = "group_sourceid";
7039        }
7040
7041        /**
7042         * <p>
7043         * A data kind representing a website related to the contact.
7044         * </p>
7045         * <p>
7046         * You can use all columns defined for {@link ContactsContract.Data} as
7047         * well as the following aliases.
7048         * </p>
7049         * <h2>Column aliases</h2>
7050         * <table class="jd-sumtable">
7051         * <tr>
7052         * <th>Type</th>
7053         * <th>Alias</th><th colspan='2'>Data column</th>
7054         * </tr>
7055         * <tr>
7056         * <td>String</td>
7057         * <td>{@link #URL}</td>
7058         * <td>{@link #DATA1}</td>
7059         * <td></td>
7060         * </tr>
7061         * <tr>
7062         * <td>int</td>
7063         * <td>{@link #TYPE}</td>
7064         * <td>{@link #DATA2}</td>
7065         * <td>Allowed values are:
7066         * <p>
7067         * <ul>
7068         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
7069         * <li>{@link #TYPE_HOMEPAGE}</li>
7070         * <li>{@link #TYPE_BLOG}</li>
7071         * <li>{@link #TYPE_PROFILE}</li>
7072         * <li>{@link #TYPE_HOME}</li>
7073         * <li>{@link #TYPE_WORK}</li>
7074         * <li>{@link #TYPE_FTP}</li>
7075         * <li>{@link #TYPE_OTHER}</li>
7076         * </ul>
7077         * </p>
7078         * </td>
7079         * </tr>
7080         * <tr>
7081         * <td>String</td>
7082         * <td>{@link #LABEL}</td>
7083         * <td>{@link #DATA3}</td>
7084         * <td></td>
7085         * </tr>
7086         * </table>
7087         */
7088        public static final class Website implements DataColumnsWithJoins, CommonColumns,
7089                ContactCounts {
7090            /**
7091             * This utility class cannot be instantiated
7092             */
7093            private Website() {}
7094
7095            /** MIME type used when storing this in data table. */
7096            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
7097
7098            public static final int TYPE_HOMEPAGE = 1;
7099            public static final int TYPE_BLOG = 2;
7100            public static final int TYPE_PROFILE = 3;
7101            public static final int TYPE_HOME = 4;
7102            public static final int TYPE_WORK = 5;
7103            public static final int TYPE_FTP = 6;
7104            public static final int TYPE_OTHER = 7;
7105
7106            /**
7107             * The website URL string.
7108             * <P>Type: TEXT</P>
7109             */
7110            public static final String URL = DATA;
7111        }
7112
7113        /**
7114         * <p>
7115         * A data kind representing a SIP address for the contact.
7116         * </p>
7117         * <p>
7118         * You can use all columns defined for {@link ContactsContract.Data} as
7119         * well as the following aliases.
7120         * </p>
7121         * <h2>Column aliases</h2>
7122         * <table class="jd-sumtable">
7123         * <tr>
7124         * <th>Type</th>
7125         * <th>Alias</th><th colspan='2'>Data column</th>
7126         * </tr>
7127         * <tr>
7128         * <td>String</td>
7129         * <td>{@link #SIP_ADDRESS}</td>
7130         * <td>{@link #DATA1}</td>
7131         * <td></td>
7132         * </tr>
7133         * <tr>
7134         * <td>int</td>
7135         * <td>{@link #TYPE}</td>
7136         * <td>{@link #DATA2}</td>
7137         * <td>Allowed values are:
7138         * <p>
7139         * <ul>
7140         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
7141         * <li>{@link #TYPE_HOME}</li>
7142         * <li>{@link #TYPE_WORK}</li>
7143         * <li>{@link #TYPE_OTHER}</li>
7144         * </ul>
7145         * </p>
7146         * </td>
7147         * </tr>
7148         * <tr>
7149         * <td>String</td>
7150         * <td>{@link #LABEL}</td>
7151         * <td>{@link #DATA3}</td>
7152         * <td></td>
7153         * </tr>
7154         * </table>
7155         */
7156        public static final class SipAddress implements DataColumnsWithJoins, CommonColumns,
7157                ContactCounts {
7158            /**
7159             * This utility class cannot be instantiated
7160             */
7161            private SipAddress() {}
7162
7163            /** MIME type used when storing this in data table. */
7164            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/sip_address";
7165
7166            public static final int TYPE_HOME = 1;
7167            public static final int TYPE_WORK = 2;
7168            public static final int TYPE_OTHER = 3;
7169
7170            /**
7171             * The SIP address.
7172             * <P>Type: TEXT</P>
7173             */
7174            public static final String SIP_ADDRESS = DATA1;
7175            // ...and TYPE and LABEL come from the CommonColumns interface.
7176
7177            /**
7178             * Return the string resource that best describes the given
7179             * {@link #TYPE}. Will always return a valid resource.
7180             */
7181            public static final int getTypeLabelResource(int type) {
7182                switch (type) {
7183                    case TYPE_HOME: return com.android.internal.R.string.sipAddressTypeHome;
7184                    case TYPE_WORK: return com.android.internal.R.string.sipAddressTypeWork;
7185                    case TYPE_OTHER: return com.android.internal.R.string.sipAddressTypeOther;
7186                    default: return com.android.internal.R.string.sipAddressTypeCustom;
7187                }
7188            }
7189
7190            /**
7191             * Return a {@link CharSequence} that best describes the given type,
7192             * possibly substituting the given {@link #LABEL} value
7193             * for {@link #TYPE_CUSTOM}.
7194             */
7195            public static final CharSequence getTypeLabel(Resources res, int type,
7196                    CharSequence label) {
7197                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
7198                    return label;
7199                } else {
7200                    final int labelRes = getTypeLabelResource(type);
7201                    return res.getText(labelRes);
7202                }
7203            }
7204        }
7205
7206        /**
7207         * A data kind representing an Identity related to the contact.
7208         * <p>
7209         * This can be used as a signal by the aggregator to combine raw contacts into
7210         * contacts, e.g. if two contacts have Identity rows with
7211         * the same NAMESPACE and IDENTITY values the aggregator can know that they refer
7212         * to the same person.
7213         * </p>
7214         */
7215        public static final class Identity implements DataColumnsWithJoins, ContactCounts {
7216            /**
7217             * This utility class cannot be instantiated
7218             */
7219            private Identity() {}
7220
7221            /** MIME type used when storing this in data table. */
7222            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/identity";
7223
7224            /**
7225             * The identity string.
7226             * <P>Type: TEXT</P>
7227             */
7228            public static final String IDENTITY = DataColumns.DATA1;
7229
7230            /**
7231             * The namespace of the identity string, e.g. "com.google"
7232             * <P>Type: TEXT</P>
7233             */
7234            public static final String NAMESPACE = DataColumns.DATA2;
7235        }
7236
7237        /**
7238         * <p>
7239         * Convenient functionalities for "callable" data. Note that, this is NOT a separate data
7240         * kind.
7241         * </p>
7242         * <p>
7243         * This URI allows the ContactsProvider to return a unified result for "callable" data
7244         * that users can use for calling purposes. {@link Phone} and {@link SipAddress} are the
7245         * current examples for "callable", but may be expanded to the other types.
7246         * </p>
7247         * <p>
7248         * Each returned row may have a different MIMETYPE and thus different interpretation for
7249         * each column. For example the meaning for {@link Phone}'s type is different than
7250         * {@link SipAddress}'s.
7251         * </p>
7252         */
7253        public static final class Callable implements DataColumnsWithJoins, CommonColumns,
7254                ContactCounts {
7255            /**
7256             * Similar to {@link Phone#CONTENT_URI}, but returns callable data instead of only
7257             * phone numbers.
7258             */
7259            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
7260                    "callables");
7261            /**
7262             * Similar to {@link Phone#CONTENT_FILTER_URI}, but allows users to filter callable
7263             * data.
7264             */
7265            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
7266                    "filter");
7267        }
7268
7269        /**
7270         * A special class of data items, used to refer to types of data that can be used to attempt
7271         * to start communicating with a person ({@link Phone} and {@link Email}). Note that this
7272         * is NOT a separate data kind.
7273         *
7274         * This URI allows the ContactsProvider to return a unified result for data items that users
7275         * can use to initiate communications with another contact. {@link Phone} and {@link Email}
7276         * are the current data types in this category.
7277         */
7278        public static final class Contactables implements DataColumnsWithJoins, CommonColumns,
7279                ContactCounts {
7280            /**
7281             * The content:// style URI for these data items, which requests a directory of data
7282             * rows matching the selection criteria.
7283             */
7284            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
7285                    "contactables");
7286
7287            /**
7288             * The content:// style URI for these data items, which allows for a query parameter to
7289             * be appended onto the end to filter for data items matching the query.
7290             */
7291            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(
7292                    Contactables.CONTENT_URI, "filter");
7293
7294            /**
7295             * A boolean parameter for {@link Data#CONTENT_URI}.
7296             * This specifies whether or not the returned data items should be filtered to show
7297             * data items belonging to visible contacts only.
7298             */
7299            public static final String VISIBLE_CONTACTS_ONLY = "visible_contacts_only";
7300        }
7301    }
7302
7303    /**
7304     * @see Groups
7305     */
7306    protected interface GroupsColumns {
7307        /**
7308         * The data set within the account that this group belongs to.  This allows
7309         * multiple sync adapters for the same account type to distinguish between
7310         * each others' group data.
7311         *
7312         * This is empty by default, and is completely optional.  It only needs to
7313         * be populated if multiple sync adapters are entering distinct group data
7314         * for the same account type and account name.
7315         * <P>Type: TEXT</P>
7316         */
7317        public static final String DATA_SET = "data_set";
7318
7319        /**
7320         * A concatenation of the account type and data set (delimited by a forward
7321         * slash) - if the data set is empty, this will be the same as the account
7322         * type.  For applications that need to be aware of the data set, this can
7323         * be used instead of account type to distinguish sets of data.  This is
7324         * never intended to be used for specifying accounts.
7325         * @hide
7326         */
7327        public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set";
7328
7329        /**
7330         * The display title of this group.
7331         * <p>
7332         * Type: TEXT
7333         */
7334        public static final String TITLE = "title";
7335
7336        /**
7337         * The package name to use when creating {@link Resources} objects for
7338         * this group. This value is only designed for use when building user
7339         * interfaces, and should not be used to infer the owner.
7340         */
7341        public static final String RES_PACKAGE = "res_package";
7342
7343        /**
7344         * The display title of this group to load as a resource from
7345         * {@link #RES_PACKAGE}, which may be localized.
7346         * <P>Type: TEXT</P>
7347         */
7348        public static final String TITLE_RES = "title_res";
7349
7350        /**
7351         * Notes about the group.
7352         * <p>
7353         * Type: TEXT
7354         */
7355        public static final String NOTES = "notes";
7356
7357        /**
7358         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
7359         * to the sync adapter, null otherwise.
7360         * <P>Type: TEXT</P>
7361         */
7362        public static final String SYSTEM_ID = "system_id";
7363
7364        /**
7365         * The total number of {@link Contacts} that have
7366         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
7367         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
7368         * <p>
7369         * Type: INTEGER
7370         */
7371        public static final String SUMMARY_COUNT = "summ_count";
7372
7373        /**
7374         * A boolean query parameter that can be used with {@link Groups#CONTENT_SUMMARY_URI}.
7375         * It will additionally return {@link #SUMMARY_GROUP_COUNT_PER_ACCOUNT}.
7376         *
7377         * @hide
7378         */
7379        public static final String PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT =
7380                "return_group_count_per_account";
7381
7382        /**
7383         * The total number of groups of the account that a group belongs to.
7384         * This column is available only when the parameter
7385         * {@link #PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT} is specified in
7386         * {@link Groups#CONTENT_SUMMARY_URI}.
7387         *
7388         * For example, when the account "A" has two groups "group1" and "group2", and the account
7389         * "B" has a group "group3", the rows for "group1" and "group2" return "2" and the row for
7390         * "group3" returns "1" for this column.
7391         *
7392         * Note: This counts only non-favorites, non-auto-add, and not deleted groups.
7393         *
7394         * Type: INTEGER
7395         * @hide
7396         */
7397        public static final String SUMMARY_GROUP_COUNT_PER_ACCOUNT = "group_count_per_account";
7398
7399        /**
7400         * The total number of {@link Contacts} that have both
7401         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
7402         * Read-only value that is only present when querying
7403         * {@link Groups#CONTENT_SUMMARY_URI}.
7404         * <p>
7405         * Type: INTEGER
7406         */
7407        public static final String SUMMARY_WITH_PHONES = "summ_phones";
7408
7409        /**
7410         * Flag indicating if the contacts belonging to this group should be
7411         * visible in any user interface.
7412         * <p>
7413         * Type: INTEGER (boolean)
7414         */
7415        public static final String GROUP_VISIBLE = "group_visible";
7416
7417        /**
7418         * The "deleted" flag: "0" by default, "1" if the row has been marked
7419         * for deletion. When {@link android.content.ContentResolver#delete} is
7420         * called on a group, it is marked for deletion. The sync adaptor
7421         * deletes the group on the server and then calls ContactResolver.delete
7422         * once more, this time setting the the
7423         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to
7424         * finalize the data removal.
7425         * <P>Type: INTEGER</P>
7426         */
7427        public static final String DELETED = "deleted";
7428
7429        /**
7430         * Whether this group should be synced if the SYNC_EVERYTHING settings
7431         * is false for this group's account.
7432         * <p>
7433         * Type: INTEGER (boolean)
7434         */
7435        public static final String SHOULD_SYNC = "should_sync";
7436
7437        /**
7438         * Any newly created contacts will automatically be added to groups that have this
7439         * flag set to true.
7440         * <p>
7441         * Type: INTEGER (boolean)
7442         */
7443        public static final String AUTO_ADD = "auto_add";
7444
7445        /**
7446         * When a contacts is marked as a favorites it will be automatically added
7447         * to the groups that have this flag set, and when it is removed from favorites
7448         * it will be removed from these groups.
7449         * <p>
7450         * Type: INTEGER (boolean)
7451         */
7452        public static final String FAVORITES = "favorites";
7453
7454        /**
7455         * The "read-only" flag: "0" by default, "1" if the row cannot be modified or
7456         * deleted except by a sync adapter.  See {@link ContactsContract#CALLER_IS_SYNCADAPTER}.
7457         * <P>Type: INTEGER</P>
7458         */
7459        public static final String GROUP_IS_READ_ONLY = "group_is_read_only";
7460    }
7461
7462    /**
7463     * Constants for the groups table. Only per-account groups are supported.
7464     * <h2>Columns</h2>
7465     * <table class="jd-sumtable">
7466     * <tr>
7467     * <th colspan='4'>Groups</th>
7468     * </tr>
7469     * <tr>
7470     * <td>long</td>
7471     * <td>{@link #_ID}</td>
7472     * <td>read-only</td>
7473     * <td>Row ID. Sync adapter should try to preserve row IDs during updates.
7474     * In other words, it would be a really bad idea to delete and reinsert a
7475     * group. A sync adapter should always do an update instead.</td>
7476     * </tr>
7477     # <tr>
7478     * <td>String</td>
7479     * <td>{@link #DATA_SET}</td>
7480     * <td>read/write-once</td>
7481     * <td>
7482     * <p>
7483     * The data set within the account that this group belongs to.  This allows
7484     * multiple sync adapters for the same account type to distinguish between
7485     * each others' group data.  The combination of {@link #ACCOUNT_TYPE},
7486     * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data
7487     * that is associated with a single sync adapter.
7488     * </p>
7489     * <p>
7490     * This is empty by default, and is completely optional.  It only needs to
7491     * be populated if multiple sync adapters are entering distinct data for
7492     * the same account type and account name.
7493     * </p>
7494     * <p>
7495     * It should be set at the time the group is inserted and never changed
7496     * afterwards.
7497     * </p>
7498     * </td>
7499     * </tr>
7500     * <tr>
7501     * <td>String</td>
7502     * <td>{@link #TITLE}</td>
7503     * <td>read/write</td>
7504     * <td>The display title of this group.</td>
7505     * </tr>
7506     * <tr>
7507     * <td>String</td>
7508     * <td>{@link #NOTES}</td>
7509     * <td>read/write</td>
7510     * <td>Notes about the group.</td>
7511     * </tr>
7512     * <tr>
7513     * <td>String</td>
7514     * <td>{@link #SYSTEM_ID}</td>
7515     * <td>read/write</td>
7516     * <td>The ID of this group if it is a System Group, i.e. a group that has a
7517     * special meaning to the sync adapter, null otherwise.</td>
7518     * </tr>
7519     * <tr>
7520     * <td>int</td>
7521     * <td>{@link #SUMMARY_COUNT}</td>
7522     * <td>read-only</td>
7523     * <td>The total number of {@link Contacts} that have
7524     * {@link CommonDataKinds.GroupMembership} in this group. Read-only value
7525     * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td>
7526     * </tr>
7527     * <tr>
7528     * <td>int</td>
7529     * <td>{@link #SUMMARY_WITH_PHONES}</td>
7530     * <td>read-only</td>
7531     * <td>The total number of {@link Contacts} that have both
7532     * {@link CommonDataKinds.GroupMembership} in this group, and also have
7533     * phone numbers. Read-only value that is only present when querying
7534     * {@link Groups#CONTENT_SUMMARY_URI}.</td>
7535     * </tr>
7536     * <tr>
7537     * <td>int</td>
7538     * <td>{@link #GROUP_VISIBLE}</td>
7539     * <td>read-only</td>
7540     * <td>Flag indicating if the contacts belonging to this group should be
7541     * visible in any user interface. Allowed values: 0 and 1.</td>
7542     * </tr>
7543     * <tr>
7544     * <td>int</td>
7545     * <td>{@link #DELETED}</td>
7546     * <td>read/write</td>
7547     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
7548     * for deletion. When {@link android.content.ContentResolver#delete} is
7549     * called on a group, it is marked for deletion. The sync adaptor deletes
7550     * the group on the server and then calls ContactResolver.delete once more,
7551     * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER}
7552     * query parameter to finalize the data removal.</td>
7553     * </tr>
7554     * <tr>
7555     * <td>int</td>
7556     * <td>{@link #SHOULD_SYNC}</td>
7557     * <td>read/write</td>
7558     * <td>Whether this group should be synced if the SYNC_EVERYTHING settings
7559     * is false for this group's account.</td>
7560     * </tr>
7561     * </table>
7562     */
7563    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
7564        /**
7565         * This utility class cannot be instantiated
7566         */
7567        private Groups() {
7568        }
7569
7570        /**
7571         * The content:// style URI for this table
7572         */
7573        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
7574
7575        /**
7576         * The content:// style URI for this table joined with details data from
7577         * {@link ContactsContract.Data}.
7578         */
7579        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
7580                "groups_summary");
7581
7582        /**
7583         * The MIME type of a directory of groups.
7584         */
7585        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
7586
7587        /**
7588         * The MIME type of a single group.
7589         */
7590        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
7591
7592        public static EntityIterator newEntityIterator(Cursor cursor) {
7593            return new EntityIteratorImpl(cursor);
7594        }
7595
7596        private static class EntityIteratorImpl extends CursorEntityIterator {
7597            public EntityIteratorImpl(Cursor cursor) {
7598                super(cursor);
7599            }
7600
7601            @Override
7602            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
7603                // we expect the cursor is already at the row we need to read from
7604                final ContentValues values = new ContentValues();
7605                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID);
7606                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME);
7607                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE);
7608                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY);
7609                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION);
7610                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID);
7611                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE);
7612                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE);
7613                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES);
7614                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE);
7615                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1);
7616                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2);
7617                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3);
7618                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4);
7619                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID);
7620                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED);
7621                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES);
7622                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC);
7623                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, FAVORITES);
7624                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, AUTO_ADD);
7625                cursor.moveToNext();
7626                return new Entity(values);
7627            }
7628        }
7629    }
7630
7631    /**
7632     * <p>
7633     * Constants for the contact aggregation exceptions table, which contains
7634     * aggregation rules overriding those used by automatic aggregation. This
7635     * type only supports query and update. Neither insert nor delete are
7636     * supported.
7637     * </p>
7638     * <h2>Columns</h2>
7639     * <table class="jd-sumtable">
7640     * <tr>
7641     * <th colspan='4'>AggregationExceptions</th>
7642     * </tr>
7643     * <tr>
7644     * <td>int</td>
7645     * <td>{@link #TYPE}</td>
7646     * <td>read/write</td>
7647     * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER},
7648     * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td>
7649     * </tr>
7650     * <tr>
7651     * <td>long</td>
7652     * <td>{@link #RAW_CONTACT_ID1}</td>
7653     * <td>read/write</td>
7654     * <td>A reference to the {@link RawContacts#_ID} of the raw contact that
7655     * the rule applies to.</td>
7656     * </tr>
7657     * <tr>
7658     * <td>long</td>
7659     * <td>{@link #RAW_CONTACT_ID2}</td>
7660     * <td>read/write</td>
7661     * <td>A reference to the other {@link RawContacts#_ID} of the raw contact
7662     * that the rule applies to.</td>
7663     * </tr>
7664     * </table>
7665     */
7666    public static final class AggregationExceptions implements BaseColumns {
7667        /**
7668         * This utility class cannot be instantiated
7669         */
7670        private AggregationExceptions() {}
7671
7672        /**
7673         * The content:// style URI for this table
7674         */
7675        public static final Uri CONTENT_URI =
7676                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
7677
7678        /**
7679         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
7680         */
7681        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
7682
7683        /**
7684         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
7685         */
7686        public static final String CONTENT_ITEM_TYPE =
7687                "vnd.android.cursor.item/aggregation_exception";
7688
7689        /**
7690         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
7691         * {@link #TYPE_AUTOMATIC}.
7692         *
7693         * <P>Type: INTEGER</P>
7694         */
7695        public static final String TYPE = "type";
7696
7697        /**
7698         * Allows the provider to automatically decide whether the specified raw contacts should
7699         * be included in the same aggregate contact or not.
7700         */
7701        public static final int TYPE_AUTOMATIC = 0;
7702
7703        /**
7704         * Makes sure that the specified raw contacts are included in the same
7705         * aggregate contact.
7706         */
7707        public static final int TYPE_KEEP_TOGETHER = 1;
7708
7709        /**
7710         * Makes sure that the specified raw contacts are NOT included in the same
7711         * aggregate contact.
7712         */
7713        public static final int TYPE_KEEP_SEPARATE = 2;
7714
7715        /**
7716         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
7717         */
7718        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
7719
7720        /**
7721         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
7722         * applies to.
7723         */
7724        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
7725    }
7726
7727    /**
7728     * @see Settings
7729     */
7730    protected interface SettingsColumns {
7731        /**
7732         * The name of the account instance to which this row belongs.
7733         * <P>Type: TEXT</P>
7734         */
7735        public static final String ACCOUNT_NAME = "account_name";
7736
7737        /**
7738         * The type of account to which this row belongs, which when paired with
7739         * {@link #ACCOUNT_NAME} identifies a specific account.
7740         * <P>Type: TEXT</P>
7741         */
7742        public static final String ACCOUNT_TYPE = "account_type";
7743
7744        /**
7745         * The data set within the account that this row belongs to.  This allows
7746         * multiple sync adapters for the same account type to distinguish between
7747         * each others' data.
7748         *
7749         * This is empty by default, and is completely optional.  It only needs to
7750         * be populated if multiple sync adapters are entering distinct data for
7751         * the same account type and account name.
7752         * <P>Type: TEXT</P>
7753         */
7754        public static final String DATA_SET = "data_set";
7755
7756        /**
7757         * Depending on the mode defined by the sync-adapter, this flag controls
7758         * the top-level sync behavior for this data source.
7759         * <p>
7760         * Type: INTEGER (boolean)
7761         */
7762        public static final String SHOULD_SYNC = "should_sync";
7763
7764        /**
7765         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
7766         * entries should be visible in any user interface.
7767         * <p>
7768         * Type: INTEGER (boolean)
7769         */
7770        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
7771
7772        /**
7773         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
7774         * {@link Groups#SHOULD_SYNC} under this account have been marked as
7775         * unsynced.
7776         */
7777        public static final String ANY_UNSYNCED = "any_unsynced";
7778
7779        /**
7780         * Read-only count of {@link Contacts} from a specific source that have
7781         * no {@link CommonDataKinds.GroupMembership} entries.
7782         * <p>
7783         * Type: INTEGER
7784         */
7785        public static final String UNGROUPED_COUNT = "summ_count";
7786
7787        /**
7788         * Read-only count of {@link Contacts} from a specific source that have
7789         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
7790         * <p>
7791         * Type: INTEGER
7792         */
7793        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
7794    }
7795
7796    /**
7797     * <p>
7798     * Contacts-specific settings for various {@link Account}'s.
7799     * </p>
7800     * <h2>Columns</h2>
7801     * <table class="jd-sumtable">
7802     * <tr>
7803     * <th colspan='4'>Settings</th>
7804     * </tr>
7805     * <tr>
7806     * <td>String</td>
7807     * <td>{@link #ACCOUNT_NAME}</td>
7808     * <td>read/write-once</td>
7809     * <td>The name of the account instance to which this row belongs.</td>
7810     * </tr>
7811     * <tr>
7812     * <td>String</td>
7813     * <td>{@link #ACCOUNT_TYPE}</td>
7814     * <td>read/write-once</td>
7815     * <td>The type of account to which this row belongs, which when paired with
7816     * {@link #ACCOUNT_NAME} identifies a specific account.</td>
7817     * </tr>
7818     * <tr>
7819     * <td>int</td>
7820     * <td>{@link #SHOULD_SYNC}</td>
7821     * <td>read/write</td>
7822     * <td>Depending on the mode defined by the sync-adapter, this flag controls
7823     * the top-level sync behavior for this data source.</td>
7824     * </tr>
7825     * <tr>
7826     * <td>int</td>
7827     * <td>{@link #UNGROUPED_VISIBLE}</td>
7828     * <td>read/write</td>
7829     * <td>Flag indicating if contacts without any
7830     * {@link CommonDataKinds.GroupMembership} entries should be visible in any
7831     * user interface.</td>
7832     * </tr>
7833     * <tr>
7834     * <td>int</td>
7835     * <td>{@link #ANY_UNSYNCED}</td>
7836     * <td>read-only</td>
7837     * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any
7838     * {@link Groups#SHOULD_SYNC} under this account have been marked as
7839     * unsynced.</td>
7840     * </tr>
7841     * <tr>
7842     * <td>int</td>
7843     * <td>{@link #UNGROUPED_COUNT}</td>
7844     * <td>read-only</td>
7845     * <td>Read-only count of {@link Contacts} from a specific source that have
7846     * no {@link CommonDataKinds.GroupMembership} entries.</td>
7847     * </tr>
7848     * <tr>
7849     * <td>int</td>
7850     * <td>{@link #UNGROUPED_WITH_PHONES}</td>
7851     * <td>read-only</td>
7852     * <td>Read-only count of {@link Contacts} from a specific source that have
7853     * no {@link CommonDataKinds.GroupMembership} entries, and also have phone
7854     * numbers.</td>
7855     * </tr>
7856     * </table>
7857     */
7858    public static final class Settings implements SettingsColumns {
7859        /**
7860         * This utility class cannot be instantiated
7861         */
7862        private Settings() {
7863        }
7864
7865        /**
7866         * The content:// style URI for this table
7867         */
7868        public static final Uri CONTENT_URI =
7869                Uri.withAppendedPath(AUTHORITY_URI, "settings");
7870
7871        /**
7872         * The MIME-type of {@link #CONTENT_URI} providing a directory of
7873         * settings.
7874         */
7875        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
7876
7877        /**
7878         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
7879         */
7880        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
7881    }
7882
7883    /**
7884     * API for inquiring about the general status of the provider.
7885     */
7886    public static final class ProviderStatus {
7887
7888        /**
7889         * Not instantiable.
7890         */
7891        private ProviderStatus() {
7892        }
7893
7894        /**
7895         * The content:// style URI for this table.  Requests to this URI can be
7896         * performed on the UI thread because they are always unblocking.
7897         */
7898        public static final Uri CONTENT_URI =
7899                Uri.withAppendedPath(AUTHORITY_URI, "provider_status");
7900
7901        /**
7902         * The MIME-type of {@link #CONTENT_URI} providing a directory of
7903         * settings.
7904         */
7905        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status";
7906
7907        /**
7908         * An integer representing the current status of the provider.
7909         */
7910        public static final String STATUS = "status";
7911
7912        /**
7913         * Default status of the provider.
7914         */
7915        public static final int STATUS_NORMAL = 0;
7916
7917        /**
7918         * The status used when the provider is in the process of upgrading.  Contacts
7919         * are temporarily unaccessible.
7920         */
7921        public static final int STATUS_UPGRADING = 1;
7922
7923        /**
7924         * The status used during a locale change.
7925         */
7926        public static final int STATUS_CHANGING_LOCALE = 3;
7927
7928        /**
7929         * The status that indicates that there are no accounts and no contacts
7930         * on the device.
7931         */
7932        public static final int STATUS_NO_ACCOUNTS_NO_CONTACTS = 4;
7933    }
7934
7935    /**
7936     * <p>
7937     * API allowing applications to send usage information for each {@link Data} row to the
7938     * Contacts Provider.  Applications can also clear all usage information.
7939     * </p>
7940     * <p>
7941     * With the feedback, Contacts Provider may return more contextually appropriate results for
7942     * Data listing, typically supplied with
7943     * {@link ContactsContract.Contacts#CONTENT_FILTER_URI},
7944     * {@link ContactsContract.CommonDataKinds.Email#CONTENT_FILTER_URI},
7945     * {@link ContactsContract.CommonDataKinds.Phone#CONTENT_FILTER_URI}, and users can benefit
7946     * from better ranked (sorted) lists in applications that show auto-complete list.
7947     * </p>
7948     * <p>
7949     * There is no guarantee for how this feedback is used, or even whether it is used at all.
7950     * The ranking algorithm will make best efforts to use the feedback data, but the exact
7951     * implementation, the storage data structures as well as the resulting sort order is device
7952     * and version specific and can change over time.
7953     * </p>
7954     * <p>
7955     * When updating usage information, users of this API need to use
7956     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} with a Uri constructed
7957     * from {@link DataUsageFeedback#FEEDBACK_URI}. The Uri must contain one or more data id(s) as
7958     * its last path. They also need to append a query parameter to the Uri, to specify the type of
7959     * the communication, which enables the Contacts Provider to differentiate between kinds of
7960     * interactions using the same contact data field (for example a phone number can be used to
7961     * make phone calls or send SMS).
7962     * </p>
7963     * <p>
7964     * Selection and selectionArgs are ignored and must be set to null. To get data ids,
7965     * you may need to call {@link ContentResolver#query(Uri, String[], String, String[], String)}
7966     * toward {@link Data#CONTENT_URI}.
7967     * </p>
7968     * <p>
7969     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} returns a positive
7970     * integer when successful, and returns 0 if no contact with that id was found.
7971     * </p>
7972     * <p>
7973     * Example:
7974     * <pre>
7975     * Uri uri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
7976     *         .appendPath(TextUtils.join(",", dataIds))
7977     *         .appendQueryParameter(DataUsageFeedback.USAGE_TYPE,
7978     *                 DataUsageFeedback.USAGE_TYPE_CALL)
7979     *         .build();
7980     * boolean successful = resolver.update(uri, new ContentValues(), null, null) > 0;
7981     * </pre>
7982     * </p>
7983     * <p>
7984     * Applications can also clear all usage information with:
7985     * <pre>
7986     * boolean successful = resolver.delete(DataUsageFeedback.DELETE_USAGE_URI, null, null) > 0;
7987     * </pre>
7988     * </p>
7989     */
7990    public static final class DataUsageFeedback {
7991
7992        /**
7993         * The content:// style URI for sending usage feedback.
7994         * Must be used with {@link ContentResolver#update(Uri, ContentValues, String, String[])}.
7995         */
7996        public static final Uri FEEDBACK_URI =
7997                Uri.withAppendedPath(Data.CONTENT_URI, "usagefeedback");
7998
7999        /**
8000         * The content:// style URI for deleting all usage information.
8001         * Must be used with {@link ContentResolver#delete(Uri, String, String[])}.
8002         * The {@code where} and {@code selectionArgs} parameters are ignored.
8003         */
8004        public static final Uri DELETE_USAGE_URI =
8005                Uri.withAppendedPath(Contacts.CONTENT_URI, "delete_usage");
8006
8007        /**
8008         * <p>
8009         * Name for query parameter specifying the type of data usage.
8010         * </p>
8011         */
8012        public static final String USAGE_TYPE = "type";
8013
8014        /**
8015         * <p>
8016         * Type of usage for voice interaction, which includes phone call, voice chat, and
8017         * video chat.
8018         * </p>
8019         */
8020        public static final String USAGE_TYPE_CALL = "call";
8021
8022        /**
8023         * <p>
8024         * Type of usage for text interaction involving longer messages, which includes email.
8025         * </p>
8026         */
8027        public static final String USAGE_TYPE_LONG_TEXT = "long_text";
8028
8029        /**
8030         * <p>
8031         * Type of usage for text interaction involving shorter messages, which includes SMS,
8032         * text chat with email addresses.
8033         * </p>
8034         */
8035        public static final String USAGE_TYPE_SHORT_TEXT = "short_text";
8036    }
8037
8038    /**
8039     * <p>
8040     * Contact-specific information about whether or not a contact has been pinned by the user
8041     * at a particular position within the system contact application's user interface.
8042     * </p>
8043     *
8044     * <p>
8045     * This pinning information can be used by individual applications to customize how
8046     * they order particular pinned contacts. For example, a Dialer application could
8047     * use pinned information to order user-pinned contacts in a top row of favorites.
8048     * </p>
8049     *
8050     * <p>
8051     * It is possible for two or more contacts to occupy the same pinned position (due
8052     * to aggregation and sync), so this pinning information should be used on a best-effort
8053     * basis to order contacts in-application rather than an absolute guide on where a contact
8054     * should be positioned. Contacts returned by the ContactsProvider will not be ordered based
8055     * on this information, so it is up to the client application to reorder these contacts within
8056     * their own UI adhering to (or ignoring as appropriate) information stored in the pinned
8057     * column.
8058     * </p>
8059     *
8060     * <p>
8061     * By default, unpinned contacts will have a pinned position of
8062     * {@link PinnedPositions#UNPINNED}. Client-provided pinned positions can be positive
8063     * integers that are greater than 1.
8064     * </p>
8065     */
8066    public static final class PinnedPositions {
8067        /**
8068         * The method to invoke in order to undemote a formerly demoted contact. The contact id of
8069         * the contact must be provided as an argument. If the contact was not previously demoted,
8070         * nothing will be done.
8071         * @hide
8072         */
8073        public static final String UNDEMOTE_METHOD = "undemote";
8074
8075        /**
8076         * Undemotes a formerly demoted contact. If the contact was not previously demoted, nothing
8077         * will be done.
8078         *
8079         * @param contentResolver to perform the undemote operation on.
8080         * @param contactId the id of the contact to undemote.
8081         */
8082        public static void undemote(ContentResolver contentResolver, long contactId) {
8083            contentResolver.call(ContactsContract.AUTHORITY_URI, PinnedPositions.UNDEMOTE_METHOD,
8084                    String.valueOf(contactId), null);
8085        }
8086
8087        /**
8088         * Pins a contact at a provided position, or unpins a contact.
8089         *
8090         * @param contentResolver to perform the pinning operation on.
8091         * @param pinnedPosition the position to pin the contact at. To unpin a contact, use
8092         *         {@link PinnedPositions#UNPINNED}.
8093         */
8094        public static void pin(
8095                ContentResolver contentResolver, long contactId, int pinnedPosition) {
8096            final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(contactId));
8097            final ContentValues values = new ContentValues();
8098            values.put(Contacts.PINNED, pinnedPosition);
8099            contentResolver.update(uri, values, null, null);
8100        }
8101
8102        /**
8103         * Default value for the pinned position of an unpinned contact.
8104         */
8105        public static final int UNPINNED = 0;
8106
8107        /**
8108         * Value of pinned position for a contact that a user has indicated should be considered
8109         * of the lowest priority. It is up to the client application to determine how to present
8110         * such a contact - for example all the way at the bottom of a contact list, or simply
8111         * just hidden from view.
8112         */
8113        public static final int DEMOTED = -1;
8114    }
8115
8116    /**
8117     * Helper methods to display QuickContact dialogs that display all the information belonging to
8118     * a specific {@link Contacts} entry.
8119     */
8120    public static final class QuickContact {
8121        /**
8122         * Action used to launch the system contacts application and bring up a QuickContact dialog
8123         * for the provided {@link Contacts} entry.
8124         */
8125        public static final String ACTION_QUICK_CONTACT =
8126                "android.provider.action.QUICK_CONTACT";
8127
8128        /**
8129         * Extra used to specify pivot dialog location in screen coordinates.
8130         * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead.
8131         * @hide
8132         */
8133        @Deprecated
8134        public static final String EXTRA_TARGET_RECT = "android.provider.extra.TARGET_RECT";
8135
8136        /**
8137         * Extra used to specify size of QuickContacts. Not all implementations of QuickContacts
8138         * will respect this extra's value.
8139         *
8140         * One of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
8141         */
8142        public static final String EXTRA_MODE = "android.provider.extra.MODE";
8143
8144        /**
8145         * Extra used to specify which mimetype should be prioritized in the QuickContacts UI.
8146         * For example, passing the value {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can
8147         * cause phone numbers to be displayed more prominently in QuickContacts.
8148         */
8149        public static final String EXTRA_PRIORITIZED_MIMETYPE
8150                = "android.provider.extra.PRIORITIZED_MIMETYPE";
8151
8152        /**
8153         * Extra used to indicate a list of specific MIME-types to exclude and not display in the
8154         * QuickContacts dialog. Stored as a {@link String} array.
8155         */
8156        public static final String EXTRA_EXCLUDE_MIMES = "android.provider.extra.EXCLUDE_MIMES";
8157
8158        /**
8159         * Small QuickContact mode, usually presented with minimal actions.
8160         */
8161        public static final int MODE_SMALL = 1;
8162
8163        /**
8164         * Medium QuickContact mode, includes actions and light summary describing
8165         * the {@link Contacts} entry being shown. This may include social
8166         * status and presence details.
8167         */
8168        public static final int MODE_MEDIUM = 2;
8169
8170        /**
8171         * Large QuickContact mode, includes actions and larger, card-like summary
8172         * of the {@link Contacts} entry being shown. This may include detailed
8173         * information, such as a photo.
8174         */
8175        public static final int MODE_LARGE = 3;
8176
8177        /**
8178         * Constructs the QuickContacts intent with a view's rect.
8179         * @hide
8180         */
8181        public static Intent composeQuickContactsIntent(Context context, View target, Uri lookupUri,
8182                int mode, String[] excludeMimes) {
8183            // Find location and bounds of target view, adjusting based on the
8184            // assumed local density.
8185            final float appScale = context.getResources().getCompatibilityInfo().applicationScale;
8186            final int[] pos = new int[2];
8187            target.getLocationOnScreen(pos);
8188
8189            final Rect rect = new Rect();
8190            rect.left = (int) (pos[0] * appScale + 0.5f);
8191            rect.top = (int) (pos[1] * appScale + 0.5f);
8192            rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f);
8193            rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f);
8194
8195            return composeQuickContactsIntent(context, rect, lookupUri, mode, excludeMimes);
8196        }
8197
8198        /**
8199         * Constructs the QuickContacts intent.
8200         * @hide
8201         */
8202        public static Intent composeQuickContactsIntent(Context context, Rect target,
8203                Uri lookupUri, int mode, String[] excludeMimes) {
8204            // When launching from an Activiy, we don't want to start a new task, but otherwise
8205            // we *must* start a new task.  (Otherwise startActivity() would crash.)
8206            Context actualContext = context;
8207            while ((actualContext instanceof ContextWrapper)
8208                    && !(actualContext instanceof Activity)) {
8209                actualContext = ((ContextWrapper) actualContext).getBaseContext();
8210            }
8211            final int intentFlags = ((actualContext instanceof Activity)
8212                    ? 0 : Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
8213                    // Workaround for b/16898764. Declaring singleTop in manifest doesn't work.
8214                    | Intent.FLAG_ACTIVITY_SINGLE_TOP;
8215
8216            // Launch pivot dialog through intent for now
8217            final Intent intent = new Intent(ACTION_QUICK_CONTACT).addFlags(intentFlags);
8218
8219            intent.setData(lookupUri);
8220            intent.setSourceBounds(target);
8221            intent.putExtra(EXTRA_MODE, mode);
8222            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);
8223            return intent;
8224        }
8225
8226        /**
8227         * Trigger a dialog that lists the various methods of interacting with
8228         * the requested {@link Contacts} entry. This may be based on available
8229         * {@link ContactsContract.Data} rows under that contact, and may also
8230         * include social status and presence details.
8231         *
8232         * @param context The parent {@link Context} that may be used as the
8233         *            parent for this dialog.
8234         * @param target Specific {@link View} from your layout that this dialog
8235         *            should be centered around. In particular, if the dialog
8236         *            has a "callout" arrow, it will be pointed and centered
8237         *            around this {@link View}.
8238         * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8239         *            {@link Uri} that describes a specific contact to feature
8240         *            in this dialog.
8241         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
8242         *            {@link #MODE_LARGE}, indicating the desired dialog size,
8243         *            when supported.
8244         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8245         *            to exclude when showing this dialog. For example, when
8246         *            already viewing the contact details card, this can be used
8247         *            to omit the details entry from the dialog.
8248         */
8249        public static void showQuickContact(Context context, View target, Uri lookupUri, int mode,
8250                String[] excludeMimes) {
8251            // Trigger with obtained rectangle
8252            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
8253                    excludeMimes);
8254            startActivityWithErrorToast(context, intent);
8255        }
8256
8257        /**
8258         * Trigger a dialog that lists the various methods of interacting with
8259         * the requested {@link Contacts} entry. This may be based on available
8260         * {@link ContactsContract.Data} rows under that contact, and may also
8261         * include social status and presence details.
8262         *
8263         * @param context The parent {@link Context} that may be used as the
8264         *            parent for this dialog.
8265         * @param target Specific {@link Rect} that this dialog should be
8266         *            centered around, in screen coordinates. In particular, if
8267         *            the dialog has a "callout" arrow, it will be pointed and
8268         *            centered around this {@link Rect}. If you are running at a
8269         *            non-native density, you need to manually adjust using
8270         *            {@link DisplayMetrics#density} before calling.
8271         * @param lookupUri A
8272         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8273         *            {@link Uri} that describes a specific contact to feature
8274         *            in this dialog.
8275         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
8276         *            {@link #MODE_LARGE}, indicating the desired dialog size,
8277         *            when supported.
8278         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8279         *            to exclude when showing this dialog. For example, when
8280         *            already viewing the contact details card, this can be used
8281         *            to omit the details entry from the dialog.
8282         */
8283        public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,
8284                String[] excludeMimes) {
8285            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
8286                    excludeMimes);
8287            startActivityWithErrorToast(context, intent);
8288        }
8289
8290        /**
8291         * Trigger a dialog that lists the various methods of interacting with
8292         * the requested {@link Contacts} entry. This may be based on available
8293         * {@link ContactsContract.Data} rows under that contact, and may also
8294         * include social status and presence details.
8295         *
8296         * @param context The parent {@link Context} that may be used as the
8297         *            parent for this dialog.
8298         * @param target Specific {@link View} from your layout that this dialog
8299         *            should be centered around. In particular, if the dialog
8300         *            has a "callout" arrow, it will be pointed and centered
8301         *            around this {@link View}.
8302         * @param lookupUri A
8303         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8304         *            {@link Uri} that describes a specific contact to feature
8305         *            in this dialog.
8306         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8307         *            to exclude when showing this dialog. For example, when
8308         *            already viewing the contact details card, this can be used
8309         *            to omit the details entry from the dialog.
8310         * @param prioritizedMimeType This mimetype should be prioritized in the QuickContacts UI.
8311         *             For example, passing the value
8312         *             {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can cause phone numbers to be
8313         *             displayed more prominently in QuickContacts.
8314         */
8315        public static void showQuickContact(Context context, View target, Uri lookupUri,
8316                String[] excludeMimes, String prioritizedMimeType) {
8317            // Use MODE_LARGE instead of accepting mode as a parameter. The different mode
8318            // values defined in ContactsContract only affect very old implementations
8319            // of QuickContacts.
8320            Intent intent = composeQuickContactsIntent(context, target, lookupUri, MODE_LARGE,
8321                    excludeMimes);
8322            intent.putExtra(EXTRA_PRIORITIZED_MIMETYPE, prioritizedMimeType);
8323            startActivityWithErrorToast(context, intent);
8324        }
8325
8326        /**
8327         * Trigger a dialog that lists the various methods of interacting with
8328         * the requested {@link Contacts} entry. This may be based on available
8329         * {@link ContactsContract.Data} rows under that contact, and may also
8330         * include social status and presence details.
8331         *
8332         * @param context The parent {@link Context} that may be used as the
8333         *            parent for this dialog.
8334         * @param target Specific {@link Rect} that this dialog should be
8335         *            centered around, in screen coordinates. In particular, if
8336         *            the dialog has a "callout" arrow, it will be pointed and
8337         *            centered around this {@link Rect}. If you are running at a
8338         *            non-native density, you need to manually adjust using
8339         *            {@link DisplayMetrics#density} before calling.
8340         * @param lookupUri A
8341         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8342         *            {@link Uri} that describes a specific contact to feature
8343         *            in this dialog.
8344         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8345         *            to exclude when showing this dialog. For example, when
8346         *            already viewing the contact details card, this can be used
8347         *            to omit the details entry from the dialog.
8348         * @param prioritizedMimeType This mimetype should be prioritized in the QuickContacts UI.
8349         *             For example, passing the value
8350         *             {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can cause phone numbers to be
8351         *             displayed more prominently in QuickContacts.
8352         */
8353        public static void showQuickContact(Context context, Rect target, Uri lookupUri,
8354                String[] excludeMimes, String prioritizedMimeType) {
8355            // Use MODE_LARGE instead of accepting mode as a parameter. The different mode
8356            // values defined in ContactsContract only affect very old implementations
8357            // of QuickContacts.
8358            Intent intent = composeQuickContactsIntent(context, target, lookupUri, MODE_LARGE,
8359                    excludeMimes);
8360            intent.putExtra(EXTRA_PRIORITIZED_MIMETYPE, prioritizedMimeType);
8361            startActivityWithErrorToast(context, intent);
8362        }
8363
8364        private static void startActivityWithErrorToast(Context context, Intent intent) {
8365            try {
8366              context.startActivity(intent);
8367            } catch (ActivityNotFoundException e) {
8368                Toast.makeText(context, com.android.internal.R.string.quick_contacts_not_available,
8369                                Toast.LENGTH_SHORT).show();
8370            }
8371        }
8372    }
8373
8374    /**
8375     * Helper class for accessing full-size photos by photo file ID.
8376     * <p>
8377     * Usage example:
8378     * <dl>
8379     * <dt>Retrieving a full-size photo by photo file ID (see
8380     * {@link ContactsContract.ContactsColumns#PHOTO_FILE_ID})
8381     * </dt>
8382     * <dd>
8383     * <pre>
8384     * public InputStream openDisplayPhoto(long photoFileId) {
8385     *     Uri displayPhotoUri = ContentUris.withAppendedId(DisplayPhoto.CONTENT_URI, photoKey);
8386     *     try {
8387     *         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(
8388     *             displayPhotoUri, "r");
8389     *         return fd.createInputStream();
8390     *     } catch (IOException e) {
8391     *         return null;
8392     *     }
8393     * }
8394     * </pre>
8395     * </dd>
8396     * </dl>
8397     * </p>
8398     */
8399    public static final class DisplayPhoto {
8400        /**
8401         * no public constructor since this is a utility class
8402         */
8403        private DisplayPhoto() {}
8404
8405        /**
8406         * The content:// style URI for this class, which allows access to full-size photos,
8407         * given a key.
8408         */
8409        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "display_photo");
8410
8411        /**
8412         * This URI allows the caller to query for the maximum dimensions of a display photo
8413         * or thumbnail.  Requests to this URI can be performed on the UI thread because
8414         * they are always unblocking.
8415         */
8416        public static final Uri CONTENT_MAX_DIMENSIONS_URI =
8417                Uri.withAppendedPath(AUTHORITY_URI, "photo_dimensions");
8418
8419        /**
8420         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8421         * contain this column, populated with the maximum height and width (in pixels)
8422         * that will be stored for a display photo.  Larger photos will be down-sized to
8423         * fit within a square of this many pixels.
8424         */
8425        public static final String DISPLAY_MAX_DIM = "display_max_dim";
8426
8427        /**
8428         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8429         * contain this column, populated with the height and width (in pixels) for photo
8430         * thumbnails.
8431         */
8432        public static final String THUMBNAIL_MAX_DIM = "thumbnail_max_dim";
8433    }
8434
8435    /**
8436     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
8437     * that involve contacts.
8438     */
8439    public static final class Intents {
8440        /**
8441         * This is the intent that is fired when a search suggestion is clicked on.
8442         */
8443        public static final String SEARCH_SUGGESTION_CLICKED =
8444                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
8445
8446        /**
8447         * This is the intent that is fired when a search suggestion for dialing a number
8448         * is clicked on.
8449         */
8450        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
8451                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
8452
8453        /**
8454         * This is the intent that is fired when a search suggestion for creating a contact
8455         * is clicked on.
8456         */
8457        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
8458                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
8459
8460        /**
8461         * This is the intent that is fired when the contacts database is created. <p> The
8462         * READ_CONTACT permission is required to receive these broadcasts.
8463         */
8464        public static final String CONTACTS_DATABASE_CREATED =
8465                "android.provider.Contacts.DATABASE_CREATED";
8466
8467        /**
8468         * Starts an Activity that lets the user pick a contact to attach an image to.
8469         * After picking the contact it launches the image cropper in face detection mode.
8470         */
8471        public static final String ATTACH_IMAGE =
8472                "com.android.contacts.action.ATTACH_IMAGE";
8473
8474        /**
8475         * This is the intent that is fired when the user clicks the "invite to the network" button
8476         * on a contact.  Only sent to an activity which is explicitly registered by a contact
8477         * provider which supports the "invite to the network" feature.
8478         * <p>
8479         * {@link Intent#getData()} contains the lookup URI for the contact.
8480         */
8481        public static final String INVITE_CONTACT =
8482                "com.android.contacts.action.INVITE_CONTACT";
8483
8484        /**
8485         * Takes as input a data URI with a mailto: or tel: scheme. If a single
8486         * contact exists with the given data it will be shown. If no contact
8487         * exists, a dialog will ask the user if they want to create a new
8488         * contact with the provided details filled in. If multiple contacts
8489         * share the data the user will be prompted to pick which contact they
8490         * want to view.
8491         * <p>
8492         * For <code>mailto:</code> URIs, the scheme specific portion must be a
8493         * raw email address, such as one built using
8494         * {@link Uri#fromParts(String, String, String)}.
8495         * <p>
8496         * For <code>tel:</code> URIs, the scheme specific portion is compared
8497         * to existing numbers using the standard caller ID lookup algorithm.
8498         * The number must be properly encoded, for example using
8499         * {@link Uri#fromParts(String, String, String)}.
8500         * <p>
8501         * Any extras from the {@link Insert} class will be passed along to the
8502         * create activity if there are no contacts to show.
8503         * <p>
8504         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
8505         * prompting the user when the contact doesn't exist.
8506         */
8507        public static final String SHOW_OR_CREATE_CONTACT =
8508                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
8509
8510        /**
8511         * Starts an Activity that lets the user select the multiple phones from a
8512         * list of phone numbers which come from the contacts or
8513         * {@link #EXTRA_PHONE_URIS}.
8514         * <p>
8515         * The phone numbers being passed in through {@link #EXTRA_PHONE_URIS}
8516         * could belong to the contacts or not, and will be selected by default.
8517         * <p>
8518         * The user's selection will be returned from
8519         * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
8520         * if the resultCode is
8521         * {@link android.app.Activity#RESULT_OK}, the array of picked phone
8522         * numbers are in the Intent's
8523         * {@link #EXTRA_PHONE_URIS}; otherwise, the
8524         * {@link android.app.Activity#RESULT_CANCELED} is returned if the user
8525         * left the Activity without changing the selection.
8526         *
8527         * @hide
8528         */
8529        public static final String ACTION_GET_MULTIPLE_PHONES =
8530                "com.android.contacts.action.GET_MULTIPLE_PHONES";
8531
8532        /**
8533         * A broadcast action which is sent when any change has been made to the profile, such
8534         * as the profile name or the picture.  A receiver must have
8535         * the android.permission.READ_PROFILE permission.
8536         *
8537         * @hide
8538         */
8539        public static final String ACTION_PROFILE_CHANGED =
8540                "android.provider.Contacts.PROFILE_CHANGED";
8541
8542        /**
8543         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
8544         * contact if no matching contact found. Otherwise, default behavior is
8545         * to prompt user with dialog before creating.
8546         * <p>
8547         * Type: BOOLEAN
8548         */
8549        public static final String EXTRA_FORCE_CREATE =
8550                "com.android.contacts.action.FORCE_CREATE";
8551
8552        /**
8553         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
8554         * description to be shown when prompting user about creating a new
8555         * contact.
8556         * <p>
8557         * Type: STRING
8558         */
8559        public static final String EXTRA_CREATE_DESCRIPTION =
8560            "com.android.contacts.action.CREATE_DESCRIPTION";
8561
8562        /**
8563         * Used with {@link #ACTION_GET_MULTIPLE_PHONES} as the input or output value.
8564         * <p>
8565         * The phone numbers want to be picked by default should be passed in as
8566         * input value. These phone numbers could belong to the contacts or not.
8567         * <p>
8568         * The phone numbers which were picked by the user are returned as output
8569         * value.
8570         * <p>
8571         * Type: array of URIs, the tel URI is used for the phone numbers which don't
8572         * belong to any contact, the content URI is used for phone id in contacts.
8573         *
8574         * @hide
8575         */
8576        public static final String EXTRA_PHONE_URIS =
8577            "com.android.contacts.extra.PHONE_URIS";
8578
8579        /**
8580         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8581         * dialog location using screen coordinates. When not specified, the
8582         * dialog will be centered.
8583         *
8584         * @hide
8585         */
8586        @Deprecated
8587        public static final String EXTRA_TARGET_RECT = "target_rect";
8588
8589        /**
8590         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8591         * desired dialog style, usually a variation on size. One of
8592         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
8593         *
8594         * @hide
8595         */
8596        @Deprecated
8597        public static final String EXTRA_MODE = "mode";
8598
8599        /**
8600         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
8601         *
8602         * @hide
8603         */
8604        @Deprecated
8605        public static final int MODE_SMALL = 1;
8606
8607        /**
8608         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
8609         *
8610         * @hide
8611         */
8612        @Deprecated
8613        public static final int MODE_MEDIUM = 2;
8614
8615        /**
8616         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
8617         *
8618         * @hide
8619         */
8620        @Deprecated
8621        public static final int MODE_LARGE = 3;
8622
8623        /**
8624         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
8625         * a list of specific MIME-types to exclude and not display. Stored as a
8626         * {@link String} array.
8627         *
8628         * @hide
8629         */
8630        @Deprecated
8631        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
8632
8633        /**
8634         * Convenience class that contains string constants used
8635         * to create contact {@link android.content.Intent Intents}.
8636         */
8637        public static final class Insert {
8638            /** The action code to use when adding a contact */
8639            public static final String ACTION = Intent.ACTION_INSERT;
8640
8641            /**
8642             * If present, forces a bypass of quick insert mode.
8643             */
8644            public static final String FULL_MODE = "full_mode";
8645
8646            /**
8647             * The extra field for the contact name.
8648             * <P>Type: String</P>
8649             */
8650            public static final String NAME = "name";
8651
8652            // TODO add structured name values here.
8653
8654            /**
8655             * The extra field for the contact phonetic name.
8656             * <P>Type: String</P>
8657             */
8658            public static final String PHONETIC_NAME = "phonetic_name";
8659
8660            /**
8661             * The extra field for the contact company.
8662             * <P>Type: String</P>
8663             */
8664            public static final String COMPANY = "company";
8665
8666            /**
8667             * The extra field for the contact job title.
8668             * <P>Type: String</P>
8669             */
8670            public static final String JOB_TITLE = "job_title";
8671
8672            /**
8673             * The extra field for the contact notes.
8674             * <P>Type: String</P>
8675             */
8676            public static final String NOTES = "notes";
8677
8678            /**
8679             * The extra field for the contact phone number.
8680             * <P>Type: String</P>
8681             */
8682            public static final String PHONE = "phone";
8683
8684            /**
8685             * The extra field for the contact phone number type.
8686             * <P>Type: Either an integer value from
8687             * {@link CommonDataKinds.Phone},
8688             *  or a string specifying a custom label.</P>
8689             */
8690            public static final String PHONE_TYPE = "phone_type";
8691
8692            /**
8693             * The extra field for the phone isprimary flag.
8694             * <P>Type: boolean</P>
8695             */
8696            public static final String PHONE_ISPRIMARY = "phone_isprimary";
8697
8698            /**
8699             * The extra field for an optional second contact phone number.
8700             * <P>Type: String</P>
8701             */
8702            public static final String SECONDARY_PHONE = "secondary_phone";
8703
8704            /**
8705             * The extra field for an optional second contact phone number type.
8706             * <P>Type: Either an integer value from
8707             * {@link CommonDataKinds.Phone},
8708             *  or a string specifying a custom label.</P>
8709             */
8710            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
8711
8712            /**
8713             * The extra field for an optional third contact phone number.
8714             * <P>Type: String</P>
8715             */
8716            public static final String TERTIARY_PHONE = "tertiary_phone";
8717
8718            /**
8719             * The extra field for an optional third contact phone number type.
8720             * <P>Type: Either an integer value from
8721             * {@link CommonDataKinds.Phone},
8722             *  or a string specifying a custom label.</P>
8723             */
8724            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
8725
8726            /**
8727             * The extra field for the contact email address.
8728             * <P>Type: String</P>
8729             */
8730            public static final String EMAIL = "email";
8731
8732            /**
8733             * The extra field for the contact email type.
8734             * <P>Type: Either an integer value from
8735             * {@link CommonDataKinds.Email}
8736             *  or a string specifying a custom label.</P>
8737             */
8738            public static final String EMAIL_TYPE = "email_type";
8739
8740            /**
8741             * The extra field for the email isprimary flag.
8742             * <P>Type: boolean</P>
8743             */
8744            public static final String EMAIL_ISPRIMARY = "email_isprimary";
8745
8746            /**
8747             * The extra field for an optional second contact email address.
8748             * <P>Type: String</P>
8749             */
8750            public static final String SECONDARY_EMAIL = "secondary_email";
8751
8752            /**
8753             * The extra field for an optional second contact email type.
8754             * <P>Type: Either an integer value from
8755             * {@link CommonDataKinds.Email}
8756             *  or a string specifying a custom label.</P>
8757             */
8758            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
8759
8760            /**
8761             * The extra field for an optional third contact email address.
8762             * <P>Type: String</P>
8763             */
8764            public static final String TERTIARY_EMAIL = "tertiary_email";
8765
8766            /**
8767             * The extra field for an optional third contact email type.
8768             * <P>Type: Either an integer value from
8769             * {@link CommonDataKinds.Email}
8770             *  or a string specifying a custom label.</P>
8771             */
8772            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
8773
8774            /**
8775             * The extra field for the contact postal address.
8776             * <P>Type: String</P>
8777             */
8778            public static final String POSTAL = "postal";
8779
8780            /**
8781             * The extra field for the contact postal address type.
8782             * <P>Type: Either an integer value from
8783             * {@link CommonDataKinds.StructuredPostal}
8784             *  or a string specifying a custom label.</P>
8785             */
8786            public static final String POSTAL_TYPE = "postal_type";
8787
8788            /**
8789             * The extra field for the postal isprimary flag.
8790             * <P>Type: boolean</P>
8791             */
8792            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
8793
8794            /**
8795             * The extra field for an IM handle.
8796             * <P>Type: String</P>
8797             */
8798            public static final String IM_HANDLE = "im_handle";
8799
8800            /**
8801             * The extra field for the IM protocol
8802             */
8803            public static final String IM_PROTOCOL = "im_protocol";
8804
8805            /**
8806             * The extra field for the IM isprimary flag.
8807             * <P>Type: boolean</P>
8808             */
8809            public static final String IM_ISPRIMARY = "im_isprimary";
8810
8811            /**
8812             * The extra field that allows the client to supply multiple rows of
8813             * arbitrary data for a single contact created using the {@link Intent#ACTION_INSERT}
8814             * or edited using {@link Intent#ACTION_EDIT}. It is an ArrayList of
8815             * {@link ContentValues}, one per data row. Supplying this extra is
8816             * similar to inserting multiple rows into the {@link Data} table,
8817             * except the user gets a chance to see and edit them before saving.
8818             * Each ContentValues object must have a value for {@link Data#MIMETYPE}.
8819             * If supplied values are not visible in the editor UI, they will be
8820             * dropped.  Duplicate data will dropped.  Some fields
8821             * like {@link CommonDataKinds.Email#TYPE Email.TYPE} may be automatically
8822             * adjusted to comply with the constraints of the specific account type.
8823             * For example, an Exchange contact can only have one phone numbers of type Home,
8824             * so the contact editor may choose a different type for this phone number to
8825             * avoid dropping the valueable part of the row, which is the phone number.
8826             * <p>
8827             * Example:
8828             * <pre>
8829             *  ArrayList&lt;ContentValues&gt; data = new ArrayList&lt;ContentValues&gt;();
8830             *
8831             *  ContentValues row1 = new ContentValues();
8832             *  row1.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
8833             *  row1.put(Organization.COMPANY, "Android");
8834             *  data.add(row1);
8835             *
8836             *  ContentValues row2 = new ContentValues();
8837             *  row2.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
8838             *  row2.put(Email.TYPE, Email.TYPE_CUSTOM);
8839             *  row2.put(Email.LABEL, "Green Bot");
8840             *  row2.put(Email.ADDRESS, "android@android.com");
8841             *  data.add(row2);
8842             *
8843             *  Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
8844             *  intent.putParcelableArrayListExtra(Insert.DATA, data);
8845             *
8846             *  startActivity(intent);
8847             * </pre>
8848             */
8849            public static final String DATA = "data";
8850
8851            /**
8852             * Used to specify the account in which to create the new contact.
8853             * <p>
8854             * If this value is not provided, the user is presented with a disambiguation
8855             * dialog to chose an account
8856             * <p>
8857             * Type: {@link Account}
8858             */
8859            public static final String EXTRA_ACCOUNT = "android.provider.extra.ACCOUNT";
8860
8861            /**
8862             * Used to specify the data set within the account in which to create the
8863             * new contact.
8864             * <p>
8865             * This value is optional - if it is not specified, the contact will be
8866             * created in the base account, with no data set.
8867             * <p>
8868             * Type: String
8869             */
8870            public static final String EXTRA_DATA_SET = "android.provider.extra.DATA_SET";
8871        }
8872    }
8873}
8874