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