ContactsContract.java revision 97bdacc6d124f08a3f1c362fc35a5eed16af9880
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                InputStream inputStream;
2083                try {
2084                    AssetFileDescriptor fd = cr.openAssetFileDescriptor(displayPhotoUri, "r");
2085                    return fd.createInputStream();
2086                } catch (IOException e) {
2087                    // fallback to the thumbnail code
2088                }
2089           }
2090
2091            Uri photoUri = Uri.withAppendedPath(contactUri, Photo.CONTENT_DIRECTORY);
2092            if (photoUri == null) {
2093                return null;
2094            }
2095            Cursor cursor = cr.query(photoUri,
2096                    new String[] {
2097                        ContactsContract.CommonDataKinds.Photo.PHOTO
2098                    }, null, null, null);
2099            try {
2100                if (cursor == null || !cursor.moveToNext()) {
2101                    return null;
2102                }
2103                byte[] data = cursor.getBlob(0);
2104                if (data == null) {
2105                    return null;
2106                }
2107                return new ByteArrayInputStream(data);
2108            } finally {
2109                if (cursor != null) {
2110                    cursor.close();
2111                }
2112            }
2113        }
2114
2115        /**
2116         * Opens an InputStream for the contacts's thumbnail photo and returns the
2117         * photo as a byte stream.
2118         * @param cr The content resolver to use for querying
2119         * @param contactUri the contact whose photo should be used. This can be used with
2120         * either a {@link #CONTENT_URI} or a {@link #CONTENT_LOOKUP_URI} URI.
2121         * @return an InputStream of the photo, or null if no photo is present
2122         * @see #openContactPhotoInputStream(ContentResolver, Uri, boolean), if instead
2123         * of the thumbnail the high-res picture is preferred
2124         */
2125        public static InputStream openContactPhotoInputStream(ContentResolver cr, Uri contactUri) {
2126            return openContactPhotoInputStream(cr, contactUri, false);
2127        }
2128    }
2129
2130    /**
2131     * <p>
2132     * Constants for the user's profile data, which is represented as a single contact on
2133     * the device that represents the user.  The profile contact is not aggregated
2134     * together automatically in the same way that normal contacts are; instead, each
2135     * account (including data set, if applicable) on the device may contribute a single
2136     * raw contact representing the user's personal profile data from that source.
2137     * </p>
2138     * <p>
2139     * Access to the profile entry through these URIs (or incidental access to parts of
2140     * the profile if retrieved directly via ID) requires additional permissions beyond
2141     * the read/write contact permissions required by the provider.  Querying for profile
2142     * data requires android.permission.READ_PROFILE permission, and inserting or
2143     * updating profile data requires android.permission.WRITE_PROFILE permission.
2144     * </p>
2145     * <h3>Operations</h3>
2146     * <dl>
2147     * <dt><b>Insert</b></dt>
2148     * <dd>The user's profile entry cannot be created explicitly (attempting to do so
2149     * will throw an exception). When a raw contact is inserted into the profile, the
2150     * provider will check for the existence of a profile on the device.  If one is
2151     * found, the raw contact's {@link RawContacts#CONTACT_ID} column gets the _ID of
2152     * the profile Contact. If no match is found, the profile Contact is created and
2153     * its _ID is put into the {@link RawContacts#CONTACT_ID} column of the newly
2154     * inserted raw contact.</dd>
2155     * <dt><b>Update</b></dt>
2156     * <dd>The profile Contact has the same update restrictions as Contacts in general,
2157     * but requires the android.permission.WRITE_PROFILE permission.</dd>
2158     * <dt><b>Delete</b></dt>
2159     * <dd>The profile Contact cannot be explicitly deleted.  It will be removed
2160     * automatically if all of its constituent raw contact entries are deleted.</dd>
2161     * <dt><b>Query</b></dt>
2162     * <dd>
2163     * <ul>
2164     * <li>The {@link #CONTENT_URI} for profiles behaves in much the same way as
2165     * retrieving a contact by ID, except that it will only ever return the user's
2166     * profile contact.
2167     * </li>
2168     * <li>
2169     * The profile contact supports all of the same sub-paths as an individual contact
2170     * does - the content of the profile contact can be retrieved as entities or
2171     * data rows.  Similarly, specific raw contact entries can be retrieved by appending
2172     * the desired raw contact ID within the profile.
2173     * </li>
2174     * </ul>
2175     * </dd>
2176     * </dl>
2177     */
2178    public static final class Profile implements BaseColumns, ContactsColumns,
2179            ContactOptionsColumns, ContactNameColumns, ContactStatusColumns {
2180        /**
2181         * This utility class cannot be instantiated
2182         */
2183        private Profile() {
2184        }
2185
2186        /**
2187         * The content:// style URI for this table, which requests the contact entry
2188         * representing the user's personal profile data.
2189         */
2190        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "profile");
2191
2192        /**
2193         * {@link Uri} for referencing the user's profile {@link Contacts} entry,
2194         * Provides {@link OpenableColumns} columns when queried, or returns the
2195         * user's profile contact formatted as a vCard when opened through
2196         * {@link ContentResolver#openAssetFileDescriptor(Uri, String)}.
2197         */
2198        public static final Uri CONTENT_VCARD_URI = Uri.withAppendedPath(CONTENT_URI,
2199                "as_vcard");
2200
2201        /**
2202         * {@link Uri} for referencing the raw contacts that make up the user's profile
2203         * {@link Contacts} entry.  An individual raw contact entry within the profile
2204         * can be addressed by appending the raw contact ID.  The entities or data within
2205         * that specific raw contact can be requested by appending the entity or data
2206         * path as well.
2207         */
2208        public static final Uri CONTENT_RAW_CONTACTS_URI = Uri.withAppendedPath(CONTENT_URI,
2209                "raw_contacts");
2210
2211        /**
2212         * The minimum ID for any entity that belongs to the profile.  This essentially
2213         * defines an ID-space in which profile data is stored, and is used by the provider
2214         * to determine whether a request via a non-profile-specific URI should be directed
2215         * to the profile data rather than general contacts data, along with all the special
2216         * permission checks that entails.
2217         *
2218         * Callers may use {@link #isProfileId} to check whether a specific ID falls into
2219         * the set of data intended for the profile.
2220         */
2221        public static final long MIN_ID = Long.MAX_VALUE - (long) Integer.MAX_VALUE;
2222    }
2223
2224    /**
2225     * This method can be used to identify whether the given ID is associated with profile
2226     * data.  It does not necessarily indicate that the ID is tied to valid data, merely
2227     * that accessing data using this ID will result in profile access checks and will only
2228     * return data from the profile.
2229     *
2230     * @param id The ID to check.
2231     * @return Whether the ID is associated with profile data.
2232     */
2233    public static boolean isProfileId(long id) {
2234        return id >= Profile.MIN_ID;
2235    }
2236
2237    protected interface DeletedContactsColumns {
2238
2239        /**
2240         * A reference to the {@link ContactsContract.Contacts#_ID} that was deleted.
2241         * <P>Type: INTEGER</P>
2242         */
2243        public static final String CONTACT_ID = "contact_id";
2244
2245        /**
2246         * Time (milliseconds since epoch) that the contact was deleted.
2247         */
2248        public static final String CONTACT_DELETED_TIMESTAMP = "contact_deleted_timestamp";
2249    }
2250
2251    /**
2252     * Constants for the deleted contact table.  This table holds a log of deleted contacts.
2253     * <p>
2254     * Log older than {@link #DAYS_KEPT_MILLISECONDS} may be deleted.
2255     */
2256    public static final class DeletedContacts implements DeletedContactsColumns {
2257
2258        /**
2259         * This utility class cannot be instantiated
2260         */
2261        private DeletedContacts() {
2262        }
2263
2264        /**
2265         * The content:// style URI for this table, which requests a directory of raw contact rows
2266         * matching the selection criteria.
2267         */
2268        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI,
2269                "deleted_contacts");
2270
2271        /**
2272         * Number of days that the delete log will be kept.  After this time, delete records may be
2273         * deleted.
2274         *
2275         * @hide
2276         */
2277        private static final int DAYS_KEPT = 30;
2278
2279        /**
2280         * Milliseconds that the delete log will be kept.  After this time, delete records may be
2281         * deleted.
2282         */
2283        public static final long DAYS_KEPT_MILLISECONDS = 1000L * 60L * 60L * 24L * (long)DAYS_KEPT;
2284    }
2285
2286    protected interface RawContactsColumns {
2287        /**
2288         * A reference to the {@link ContactsContract.Contacts#_ID} that this
2289         * data belongs to.
2290         * <P>Type: INTEGER</P>
2291         */
2292        public static final String CONTACT_ID = "contact_id";
2293
2294        /**
2295         * Persistent unique id for each raw_contact within its account.
2296         * This id is provided by its own data source, and can be used to backup metadata
2297         * to the server.
2298         * This should be unique within each set of account_name/account_type/data_set
2299         */
2300        public static final String BACKUP_ID = "backup_id";
2301
2302        /**
2303         * The data set within the account that this row belongs to.  This allows
2304         * multiple sync adapters for the same account type to distinguish between
2305         * each others' data.
2306         *
2307         * This is empty by default, and is completely optional.  It only needs to
2308         * be populated if multiple sync adapters are entering distinct data for
2309         * the same account type and account name.
2310         * <P>Type: TEXT</P>
2311         */
2312        public static final String DATA_SET = "data_set";
2313
2314        /**
2315         * A concatenation of the account type and data set (delimited by a forward
2316         * slash) - if the data set is empty, this will be the same as the account
2317         * type.  For applications that need to be aware of the data set, this can
2318         * be used instead of account type to distinguish sets of data.  This is
2319         * never intended to be used for specifying accounts.
2320         * <p>
2321         * This column does *not* escape forward slashes in the account type or the data set.
2322         * If this is an issue, consider using
2323         * {@link ContactsContract.RawContacts#ACCOUNT_TYPE} and
2324         * {@link ContactsContract.RawContacts#DATA_SET} directly.
2325         */
2326        public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set";
2327
2328        /**
2329         * The aggregation mode for this contact.
2330         * <P>Type: INTEGER</P>
2331         */
2332        public static final String AGGREGATION_MODE = "aggregation_mode";
2333
2334        /**
2335         * The "deleted" flag: "0" by default, "1" if the row has been marked
2336         * for deletion. When {@link android.content.ContentResolver#delete} is
2337         * called on a raw contact, it is marked for deletion and removed from its
2338         * aggregate contact. The sync adaptor deletes the raw contact on the server and
2339         * then calls ContactResolver.delete once more, this time passing the
2340         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
2341         * the data removal.
2342         * <P>Type: INTEGER</P>
2343         */
2344        public static final String DELETED = "deleted";
2345
2346        /**
2347         * The "read-only" flag: "0" by default, "1" if the row cannot be modified or
2348         * deleted except by a sync adapter.  See {@link ContactsContract#CALLER_IS_SYNCADAPTER}.
2349         * <P>Type: INTEGER</P>
2350         */
2351        public static final String RAW_CONTACT_IS_READ_ONLY = "raw_contact_is_read_only";
2352
2353        /**
2354         * Flag that reflects whether this raw contact belongs to the user's
2355         * personal profile entry.
2356         */
2357        public static final String RAW_CONTACT_IS_USER_PROFILE = "raw_contact_is_user_profile";
2358
2359        /**
2360         * Flag indicating that a raw contact's metadata has changed, and its metadata
2361         * needs to be synchronized by the server.
2362         * <P>Type: INTEGER (boolean)</P>
2363         */
2364        public static final String METADATA_DIRTY = "metadata_dirty";
2365    }
2366
2367    /**
2368     * Constants for the raw contacts table, which contains one row of contact
2369     * information for each person in each synced account. Sync adapters and
2370     * contact management apps
2371     * are the primary consumers of this API.
2372     *
2373     * <h3>Aggregation</h3>
2374     * <p>
2375     * As soon as a raw contact is inserted or whenever its constituent data
2376     * changes, the provider will check if the raw contact matches other
2377     * existing raw contacts and if so will aggregate it with those. The
2378     * aggregation is reflected in the {@link RawContacts} table by the change of the
2379     * {@link #CONTACT_ID} field, which is the reference to the aggregate contact.
2380     * </p>
2381     * <p>
2382     * Changes to the structured name, organization, phone number, email address,
2383     * or nickname trigger a re-aggregation.
2384     * </p>
2385     * <p>
2386     * See also {@link AggregationExceptions} for a mechanism to control
2387     * aggregation programmatically.
2388     * </p>
2389     *
2390     * <h3>Operations</h3>
2391     * <dl>
2392     * <dt><b>Insert</b></dt>
2393     * <dd>
2394     * <p>
2395     * Raw contacts can be inserted incrementally or in a batch.
2396     * The incremental method is more traditional but less efficient.
2397     * It should be used
2398     * only if no {@link Data} values are available at the time the raw contact is created:
2399     * <pre>
2400     * ContentValues values = new ContentValues();
2401     * values.put(RawContacts.ACCOUNT_TYPE, accountType);
2402     * values.put(RawContacts.ACCOUNT_NAME, accountName);
2403     * Uri rawContactUri = getContentResolver().insert(RawContacts.CONTENT_URI, values);
2404     * long rawContactId = ContentUris.parseId(rawContactUri);
2405     * </pre>
2406     * </p>
2407     * <p>
2408     * Once {@link Data} values become available, insert those.
2409     * For example, here's how you would insert a name:
2410     *
2411     * <pre>
2412     * values.clear();
2413     * values.put(Data.RAW_CONTACT_ID, rawContactId);
2414     * values.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
2415     * values.put(StructuredName.DISPLAY_NAME, &quot;Mike Sullivan&quot;);
2416     * getContentResolver().insert(Data.CONTENT_URI, values);
2417     * </pre>
2418     * </p>
2419     * <p>
2420     * The batch method is by far preferred.  It inserts the raw contact and its
2421     * constituent data rows in a single database transaction
2422     * and causes at most one aggregation pass.
2423     * <pre>
2424     * ArrayList&lt;ContentProviderOperation&gt; ops =
2425     *          new ArrayList&lt;ContentProviderOperation&gt;();
2426     * ...
2427     * int rawContactInsertIndex = ops.size();
2428     * ops.add(ContentProviderOperation.newInsert(RawContacts.CONTENT_URI)
2429     *          .withValue(RawContacts.ACCOUNT_TYPE, accountType)
2430     *          .withValue(RawContacts.ACCOUNT_NAME, accountName)
2431     *          .build());
2432     *
2433     * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
2434     *          .withValueBackReference(Data.RAW_CONTACT_ID, rawContactInsertIndex)
2435     *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
2436     *          .withValue(StructuredName.DISPLAY_NAME, &quot;Mike Sullivan&quot;)
2437     *          .build());
2438     *
2439     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
2440     * </pre>
2441     * </p>
2442     * <p>
2443     * Note the use of {@link ContentProviderOperation.Builder#withValueBackReference(String, int)}
2444     * to refer to the as-yet-unknown index value of the raw contact inserted in the
2445     * first operation.
2446     * </p>
2447     *
2448     * <dt><b>Update</b></dt>
2449     * <dd><p>
2450     * Raw contacts can be updated incrementally or in a batch.
2451     * Batch mode should be used whenever possible.
2452     * The procedures and considerations are analogous to those documented above for inserts.
2453     * </p></dd>
2454     * <dt><b>Delete</b></dt>
2455     * <dd><p>When a raw contact is deleted, all of its Data rows as well as StatusUpdates,
2456     * AggregationExceptions, PhoneLookup rows are deleted automatically. When all raw
2457     * contacts associated with a {@link Contacts} row are deleted, the {@link Contacts} row
2458     * itself is also deleted automatically.
2459     * </p>
2460     * <p>
2461     * The invocation of {@code resolver.delete(...)}, does not immediately delete
2462     * a raw contacts row.
2463     * Instead, it sets the {@link #DELETED} flag on the raw contact and
2464     * removes the raw contact from its aggregate contact.
2465     * The sync adapter then deletes the raw contact from the server and
2466     * finalizes phone-side deletion by calling {@code resolver.delete(...)}
2467     * again and passing the {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter.<p>
2468     * <p>Some sync adapters are read-only, meaning that they only sync server-side
2469     * changes to the phone, but not the reverse.  If one of those raw contacts
2470     * is marked for deletion, it will remain on the phone.  However it will be
2471     * effectively invisible, because it will not be part of any aggregate contact.
2472     * </dd>
2473     *
2474     * <dt><b>Query</b></dt>
2475     * <dd>
2476     * <p>
2477     * It is easy to find all raw contacts in a Contact:
2478     * <pre>
2479     * Cursor c = getContentResolver().query(RawContacts.CONTENT_URI,
2480     *          new String[]{RawContacts._ID},
2481     *          RawContacts.CONTACT_ID + "=?",
2482     *          new String[]{String.valueOf(contactId)}, null);
2483     * </pre>
2484     * </p>
2485     * <p>
2486     * To find raw contacts within a specific account,
2487     * you can either put the account name and type in the selection or pass them as query
2488     * parameters.  The latter approach is preferable, especially when you can reuse the
2489     * URI:
2490     * <pre>
2491     * Uri rawContactUri = RawContacts.CONTENT_URI.buildUpon()
2492     *          .appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName)
2493     *          .appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType)
2494     *          .build();
2495     * Cursor c1 = getContentResolver().query(rawContactUri,
2496     *          RawContacts.STARRED + "&lt;&gt;0", null, null, null);
2497     * ...
2498     * Cursor c2 = getContentResolver().query(rawContactUri,
2499     *          RawContacts.DELETED + "&lt;&gt;0", null, null, null);
2500     * </pre>
2501     * </p>
2502     * <p>The best way to read a raw contact along with all the data associated with it is
2503     * by using the {@link Entity} directory. If the raw contact has data rows,
2504     * the Entity cursor will contain a row for each data row.  If the raw contact has no
2505     * data rows, the cursor will still contain one row with the raw contact-level information.
2506     * <pre>
2507     * Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
2508     * Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
2509     * Cursor c = getContentResolver().query(entityUri,
2510     *          new String[]{RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1},
2511     *          null, null, null);
2512     * try {
2513     *     while (c.moveToNext()) {
2514     *         String sourceId = c.getString(0);
2515     *         if (!c.isNull(1)) {
2516     *             String mimeType = c.getString(2);
2517     *             String data = c.getString(3);
2518     *             ...
2519     *         }
2520     *     }
2521     * } finally {
2522     *     c.close();
2523     * }
2524     * </pre>
2525     * </p>
2526     * </dd>
2527     * </dl>
2528     * <h2>Columns</h2>
2529     *
2530     * <table class="jd-sumtable">
2531     * <tr>
2532     * <th colspan='4'>RawContacts</th>
2533     * </tr>
2534     * <tr>
2535     * <td>long</td>
2536     * <td>{@link #_ID}</td>
2537     * <td>read-only</td>
2538     * <td>Row ID. Sync adapters should try to preserve row IDs during updates. In other words,
2539     * it is much better for a sync adapter to update a raw contact rather than to delete and
2540     * re-insert it.</td>
2541     * </tr>
2542     * <tr>
2543     * <td>long</td>
2544     * <td>{@link #CONTACT_ID}</td>
2545     * <td>read-only</td>
2546     * <td>The ID of the row in the {@link ContactsContract.Contacts} table
2547     * that this raw contact belongs
2548     * to. Raw contacts are linked to contacts by the aggregation process, which can be controlled
2549     * by the {@link #AGGREGATION_MODE} field and {@link AggregationExceptions}.</td>
2550     * </tr>
2551     * <tr>
2552     * <td>int</td>
2553     * <td>{@link #AGGREGATION_MODE}</td>
2554     * <td>read/write</td>
2555     * <td>A mechanism that allows programmatic control of the aggregation process. The allowed
2556     * values are {@link #AGGREGATION_MODE_DEFAULT}, {@link #AGGREGATION_MODE_DISABLED}
2557     * and {@link #AGGREGATION_MODE_SUSPENDED}. See also {@link AggregationExceptions}.</td>
2558     * </tr>
2559     * <tr>
2560     * <td>int</td>
2561     * <td>{@link #DELETED}</td>
2562     * <td>read/write</td>
2563     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
2564     * for deletion. When {@link android.content.ContentResolver#delete} is
2565     * called on a raw contact, it is marked for deletion and removed from its
2566     * aggregate contact. The sync adaptor deletes the raw contact on the server and
2567     * then calls ContactResolver.delete once more, this time passing the
2568     * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to finalize
2569     * the data removal.</td>
2570     * </tr>
2571     * <tr>
2572     * <td>int</td>
2573     * <td>{@link #TIMES_CONTACTED}</td>
2574     * <td>read/write</td>
2575     * <td>The number of times the contact has been contacted. To have an effect
2576     * on the corresponding value of the aggregate contact, this field
2577     * should be set at the time the raw contact is inserted.
2578     * After that, this value is typically updated via
2579     * {@link ContactsContract.Contacts#markAsContacted}.</td>
2580     * </tr>
2581     * <tr>
2582     * <td>long</td>
2583     * <td>{@link #LAST_TIME_CONTACTED}</td>
2584     * <td>read/write</td>
2585     * <td>The timestamp of the last time the contact was contacted. To have an effect
2586     * on the corresponding value of the aggregate contact, this field
2587     * should be set at the time the raw contact is inserted.
2588     * After that, this value is typically updated via
2589     * {@link ContactsContract.Contacts#markAsContacted}.
2590     * </td>
2591     * </tr>
2592     * <tr>
2593     * <td>int</td>
2594     * <td>{@link #STARRED}</td>
2595     * <td>read/write</td>
2596     * <td>An indicator for favorite contacts: '1' if favorite, '0' otherwise.
2597     * Changing this field immediately affects the corresponding aggregate contact:
2598     * if any raw contacts in that aggregate contact are starred, then the contact
2599     * itself is marked as starred.</td>
2600     * </tr>
2601     * <tr>
2602     * <td>String</td>
2603     * <td>{@link #CUSTOM_RINGTONE}</td>
2604     * <td>read/write</td>
2605     * <td>A custom ringtone associated with a raw contact. Typically this is the
2606     * URI returned by an activity launched with the
2607     * {@link android.media.RingtoneManager#ACTION_RINGTONE_PICKER} intent.
2608     * To have an effect on the corresponding value of the aggregate contact, this field
2609     * should be set at the time the raw contact is inserted. To set a custom
2610     * ringtone on a contact, use the field {@link ContactsContract.Contacts#CUSTOM_RINGTONE
2611     * Contacts.CUSTOM_RINGTONE}
2612     * instead.</td>
2613     * </tr>
2614     * <tr>
2615     * <td>int</td>
2616     * <td>{@link #SEND_TO_VOICEMAIL}</td>
2617     * <td>read/write</td>
2618     * <td>An indicator of whether calls from this raw contact should be forwarded
2619     * directly to voice mail ('1') or not ('0'). To have an effect
2620     * on the corresponding value of the aggregate contact, this field
2621     * should be set at the time the raw contact is inserted.</td>
2622     * </tr>
2623     * <tr>
2624     * <td>String</td>
2625     * <td>{@link #ACCOUNT_NAME}</td>
2626     * <td>read/write-once</td>
2627     * <td>The name of the account instance to which this row belongs, which when paired with
2628     * {@link #ACCOUNT_TYPE} identifies a specific account.
2629     * For example, this will be the Gmail address if it is a Google account.
2630     * It should be set at the time the raw contact is inserted and never
2631     * changed afterwards.</td>
2632     * </tr>
2633     * <tr>
2634     * <td>String</td>
2635     * <td>{@link #ACCOUNT_TYPE}</td>
2636     * <td>read/write-once</td>
2637     * <td>
2638     * <p>
2639     * The type of account to which this row belongs, which when paired with
2640     * {@link #ACCOUNT_NAME} identifies a specific account.
2641     * It should be set at the time the raw contact is inserted and never
2642     * changed afterwards.
2643     * </p>
2644     * <p>
2645     * To ensure uniqueness, new account types should be chosen according to the
2646     * Java package naming convention.  Thus a Google account is of type "com.google".
2647     * </p>
2648     * </td>
2649     * </tr>
2650     * <tr>
2651     * <td>String</td>
2652     * <td>{@link #DATA_SET}</td>
2653     * <td>read/write-once</td>
2654     * <td>
2655     * <p>
2656     * The data set within the account that this row belongs to.  This allows
2657     * multiple sync adapters for the same account type to distinguish between
2658     * each others' data.  The combination of {@link #ACCOUNT_TYPE},
2659     * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data
2660     * that is associated with a single sync adapter.
2661     * </p>
2662     * <p>
2663     * This is empty by default, and is completely optional.  It only needs to
2664     * be populated if multiple sync adapters are entering distinct data for
2665     * the same account type and account name.
2666     * </p>
2667     * <p>
2668     * It should be set at the time the raw contact is inserted and never
2669     * changed afterwards.
2670     * </p>
2671     * </td>
2672     * </tr>
2673     * <tr>
2674     * <td>String</td>
2675     * <td>{@link #SOURCE_ID}</td>
2676     * <td>read/write</td>
2677     * <td>String that uniquely identifies this row to its source account.
2678     * Typically it is set at the time the raw contact is inserted and never
2679     * changed afterwards. The one notable exception is a new raw contact: it
2680     * will have an account name and type (and possibly a data set), but no
2681     * source id. This indicates to the sync adapter that a new contact needs
2682     * to be created server-side and its ID stored in the corresponding
2683     * SOURCE_ID field on the phone.
2684     * </td>
2685     * </tr>
2686     * <tr>
2687     * <td>int</td>
2688     * <td>{@link #VERSION}</td>
2689     * <td>read-only</td>
2690     * <td>Version number that is updated whenever this row or its related data
2691     * changes. This field can be used for optimistic locking of a raw contact.
2692     * </td>
2693     * </tr>
2694     * <tr>
2695     * <td>int</td>
2696     * <td>{@link #DIRTY}</td>
2697     * <td>read/write</td>
2698     * <td>Flag indicating that {@link #VERSION} has changed, and this row needs
2699     * to be synchronized by its owning account.  The value is set to "1" automatically
2700     * whenever the raw contact changes, unless the URI has the
2701     * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter specified.
2702     * The sync adapter should always supply this query parameter to prevent
2703     * unnecessary synchronization: user changes some data on the server,
2704     * the sync adapter updates the contact on the phone (without the
2705     * CALLER_IS_SYNCADAPTER flag) flag, which sets the DIRTY flag,
2706     * which triggers a sync to bring the changes to the server.
2707     * </td>
2708     * </tr>
2709     * <tr>
2710     * <td>String</td>
2711     * <td>{@link #SYNC1}</td>
2712     * <td>read/write</td>
2713     * <td>Generic column provided for arbitrary use by sync adapters.
2714     * The content provider
2715     * stores this information on behalf of the sync adapter but does not
2716     * interpret it in any way.
2717     * </td>
2718     * </tr>
2719     * <tr>
2720     * <td>String</td>
2721     * <td>{@link #SYNC2}</td>
2722     * <td>read/write</td>
2723     * <td>Generic column for use by sync adapters.
2724     * </td>
2725     * </tr>
2726     * <tr>
2727     * <td>String</td>
2728     * <td>{@link #SYNC3}</td>
2729     * <td>read/write</td>
2730     * <td>Generic column for use by sync adapters.
2731     * </td>
2732     * </tr>
2733     * <tr>
2734     * <td>String</td>
2735     * <td>{@link #SYNC4}</td>
2736     * <td>read/write</td>
2737     * <td>Generic column for use by sync adapters.
2738     * </td>
2739     * </tr>
2740     * </table>
2741     */
2742    public static final class RawContacts implements BaseColumns, RawContactsColumns,
2743            ContactOptionsColumns, ContactNameColumns, SyncColumns  {
2744        /**
2745         * This utility class cannot be instantiated
2746         */
2747        private RawContacts() {
2748        }
2749
2750        /**
2751         * The content:// style URI for this table, which requests a directory of
2752         * raw contact rows matching the selection criteria.
2753         */
2754        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "raw_contacts");
2755
2756        /**
2757         * The MIME type of the results from {@link #CONTENT_URI} when a specific
2758         * ID value is not provided, and multiple raw contacts may be returned.
2759         */
2760        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact";
2761
2762        /**
2763         * The MIME type of the results when a raw contact ID is appended to {@link #CONTENT_URI},
2764         * yielding a subdirectory of a single person.
2765         */
2766        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/raw_contact";
2767
2768        /**
2769         * Aggregation mode: aggregate immediately after insert or update operation(s) are complete.
2770         */
2771        public static final int AGGREGATION_MODE_DEFAULT = 0;
2772
2773        /**
2774         * Aggregation mode: aggregate at the time the raw contact is inserted/updated.
2775         * @deprecated Aggregation is synchronous, this historic value is a no-op
2776         */
2777        @Deprecated
2778        public static final int AGGREGATION_MODE_IMMEDIATE = 1;
2779
2780        /**
2781         * <p>
2782         * Aggregation mode: aggregation suspended temporarily, and is likely to be resumed later.
2783         * Changes to the raw contact will update the associated aggregate contact but will not
2784         * result in any change in how the contact is aggregated. Similar to
2785         * {@link #AGGREGATION_MODE_DISABLED}, but maintains a link to the corresponding
2786         * {@link Contacts} aggregate.
2787         * </p>
2788         * <p>
2789         * This can be used to postpone aggregation until after a series of updates, for better
2790         * performance and/or user experience.
2791         * </p>
2792         * <p>
2793         * Note that changing
2794         * {@link #AGGREGATION_MODE} from {@link #AGGREGATION_MODE_SUSPENDED} to
2795         * {@link #AGGREGATION_MODE_DEFAULT} does not trigger an aggregation pass, but any
2796         * subsequent
2797         * change to the raw contact's data will.
2798         * </p>
2799         */
2800        public static final int AGGREGATION_MODE_SUSPENDED = 2;
2801
2802        /**
2803         * <p>
2804         * Aggregation mode: never aggregate this raw contact.  The raw contact will not
2805         * have a corresponding {@link Contacts} aggregate and therefore will not be included in
2806         * {@link Contacts} query results.
2807         * </p>
2808         * <p>
2809         * For example, this mode can be used for a raw contact that is marked for deletion while
2810         * waiting for the deletion to occur on the server side.
2811         * </p>
2812         *
2813         * @see #AGGREGATION_MODE_SUSPENDED
2814         */
2815        public static final int AGGREGATION_MODE_DISABLED = 3;
2816
2817        /**
2818         * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
2819         * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts}
2820         * entry of the given {@link RawContacts} entry.
2821         */
2822        public static Uri getContactLookupUri(ContentResolver resolver, Uri rawContactUri) {
2823            // TODO: use a lighter query by joining rawcontacts with contacts in provider
2824            final Uri dataUri = Uri.withAppendedPath(rawContactUri, Data.CONTENT_DIRECTORY);
2825            final Cursor cursor = resolver.query(dataUri, new String[] {
2826                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
2827            }, null, null, null);
2828
2829            Uri lookupUri = null;
2830            try {
2831                if (cursor != null && cursor.moveToFirst()) {
2832                    final long contactId = cursor.getLong(0);
2833                    final String lookupKey = cursor.getString(1);
2834                    return Contacts.getLookupUri(contactId, lookupKey);
2835                }
2836            } finally {
2837                if (cursor != null) cursor.close();
2838            }
2839            return lookupUri;
2840        }
2841
2842        /**
2843         * A sub-directory of a single raw contact that contains all of its
2844         * {@link ContactsContract.Data} rows. To access this directory
2845         * append {@link Data#CONTENT_DIRECTORY} to the raw contact URI.
2846         */
2847        public static final class Data implements BaseColumns, DataColumns {
2848            /**
2849             * no public constructor since this is a utility class
2850             */
2851            private Data() {
2852            }
2853
2854            /**
2855             * The directory twig for this sub-table
2856             */
2857            public static final String CONTENT_DIRECTORY = "data";
2858        }
2859
2860        /**
2861         * <p>
2862         * A sub-directory of a single raw contact that contains all of its
2863         * {@link ContactsContract.Data} rows. To access this directory append
2864         * {@link RawContacts.Entity#CONTENT_DIRECTORY} to the raw contact URI. See
2865         * {@link RawContactsEntity} for a stand-alone table containing the same
2866         * data.
2867         * </p>
2868         * <p>
2869         * Entity has two ID fields: {@link #_ID} for the raw contact
2870         * and {@link #DATA_ID} for the data rows.
2871         * Entity always contains at least one row, even if there are no
2872         * actual data rows. In this case the {@link #DATA_ID} field will be
2873         * null.
2874         * </p>
2875         * <p>
2876         * Using Entity should be preferred to using two separate queries:
2877         * RawContacts followed by Data. The reason is that Entity reads all
2878         * data for a raw contact in one transaction, so there is no possibility
2879         * of the data changing between the two queries.
2880         */
2881        public static final class Entity implements BaseColumns, DataColumns {
2882            /**
2883             * no public constructor since this is a utility class
2884             */
2885            private Entity() {
2886            }
2887
2888            /**
2889             * The directory twig for this sub-table
2890             */
2891            public static final String CONTENT_DIRECTORY = "entity";
2892
2893            /**
2894             * The ID of the data row. The value will be null if this raw contact has no
2895             * data rows.
2896             * <P>Type: INTEGER</P>
2897             */
2898            public static final String DATA_ID = "data_id";
2899        }
2900
2901        /**
2902         * <p>
2903         * A sub-directory of a single raw contact that contains all of its
2904         * {@link ContactsContract.StreamItems} rows. To access this directory append
2905         * {@link RawContacts.StreamItems#CONTENT_DIRECTORY} to the raw contact URI. See
2906         * {@link ContactsContract.StreamItems} for a stand-alone table containing the
2907         * same data.
2908         * </p>
2909         * <p>
2910         * Access to the social stream through this sub-directory requires additional permissions
2911         * beyond the read/write contact permissions required by the provider.  Querying for
2912         * social stream data requires android.permission.READ_SOCIAL_STREAM permission, and
2913         * inserting or updating social stream items requires android.permission.WRITE_SOCIAL_STREAM
2914         * permission.
2915         * </p>
2916         *
2917         * @deprecated - Do not use. This will not be supported in the future. In the future,
2918         * cursors returned from related queries will be empty.
2919         *
2920         * @hide
2921         * @removed
2922         */
2923        @Deprecated
2924        public static final class StreamItems implements BaseColumns, StreamItemsColumns {
2925            /**
2926             * No public constructor since this is a utility class
2927             *
2928             * @deprecated - Do not use. This will not be supported in the future. In the future,
2929             * cursors returned from related queries will be empty.
2930             */
2931            @Deprecated
2932            private StreamItems() {
2933            }
2934
2935            /**
2936             * The directory twig for this sub-table
2937             *
2938             * @deprecated - Do not use. This will not be supported in the future. In the future,
2939             * cursors returned from related queries will be empty.
2940             */
2941            @Deprecated
2942            public static final String CONTENT_DIRECTORY = "stream_items";
2943        }
2944
2945        /**
2946         * <p>
2947         * A sub-directory of a single raw contact that represents its primary
2948         * display photo.  To access this directory append
2949         * {@link RawContacts.DisplayPhoto#CONTENT_DIRECTORY} to the raw contact URI.
2950         * The resulting URI represents an image file, and should be interacted with
2951         * using ContentResolver.openAssetFileDescriptor.
2952         * <p>
2953         * <p>
2954         * Note that this sub-directory also supports opening the photo as an asset file
2955         * in write mode.  Callers can create or replace the primary photo associated
2956         * with this raw contact by opening the asset file and writing the full-size
2957         * photo contents into it.  When the file is closed, the image will be parsed,
2958         * sized down if necessary for the full-size display photo and thumbnail
2959         * dimensions, and stored.
2960         * </p>
2961         * <p>
2962         * Usage example:
2963         * <pre>
2964         * public void writeDisplayPhoto(long rawContactId, byte[] photo) {
2965         *     Uri rawContactPhotoUri = Uri.withAppendedPath(
2966         *             ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
2967         *             RawContacts.DisplayPhoto.CONTENT_DIRECTORY);
2968         *     try {
2969         *         AssetFileDescriptor fd =
2970         *             getContentResolver().openAssetFileDescriptor(rawContactPhotoUri, "rw");
2971         *         OutputStream os = fd.createOutputStream();
2972         *         os.write(photo);
2973         *         os.close();
2974         *         fd.close();
2975         *     } catch (IOException e) {
2976         *         // Handle error cases.
2977         *     }
2978         * }
2979         * </pre>
2980         * </p>
2981         */
2982        public static final class DisplayPhoto {
2983            /**
2984             * No public constructor since this is a utility class
2985             */
2986            private DisplayPhoto() {
2987            }
2988
2989            /**
2990             * The directory twig for this sub-table
2991             */
2992            public static final String CONTENT_DIRECTORY = "display_photo";
2993        }
2994
2995        /**
2996         * TODO: javadoc
2997         * @param cursor
2998         * @return
2999         */
3000        public static EntityIterator newEntityIterator(Cursor cursor) {
3001            return new EntityIteratorImpl(cursor);
3002        }
3003
3004        private static class EntityIteratorImpl extends CursorEntityIterator {
3005            private static final String[] DATA_KEYS = new String[]{
3006                    Data.DATA1,
3007                    Data.DATA2,
3008                    Data.DATA3,
3009                    Data.DATA4,
3010                    Data.DATA5,
3011                    Data.DATA6,
3012                    Data.DATA7,
3013                    Data.DATA8,
3014                    Data.DATA9,
3015                    Data.DATA10,
3016                    Data.DATA11,
3017                    Data.DATA12,
3018                    Data.DATA13,
3019                    Data.DATA14,
3020                    Data.DATA15,
3021                    Data.SYNC1,
3022                    Data.SYNC2,
3023                    Data.SYNC3,
3024                    Data.SYNC4};
3025
3026            public EntityIteratorImpl(Cursor cursor) {
3027                super(cursor);
3028            }
3029
3030            @Override
3031            public android.content.Entity getEntityAndIncrementCursor(Cursor cursor)
3032                    throws RemoteException {
3033                final int columnRawContactId = cursor.getColumnIndexOrThrow(RawContacts._ID);
3034                final long rawContactId = cursor.getLong(columnRawContactId);
3035
3036                // we expect the cursor is already at the row we need to read from
3037                ContentValues cv = new ContentValues();
3038                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_NAME);
3039                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, ACCOUNT_TYPE);
3040                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, DATA_SET);
3041                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, _ID);
3042                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DIRTY);
3043                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, VERSION);
3044                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SOURCE_ID);
3045                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC1);
3046                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC2);
3047                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC3);
3048                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, SYNC4);
3049                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, DELETED);
3050                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, CONTACT_ID);
3051                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, STARRED);
3052                android.content.Entity contact = new android.content.Entity(cv);
3053
3054                // read data rows until the contact id changes
3055                do {
3056                    if (rawContactId != cursor.getLong(columnRawContactId)) {
3057                        break;
3058                    }
3059                    // add the data to to the contact
3060                    cv = new ContentValues();
3061                    cv.put(Data._ID, cursor.getLong(cursor.getColumnIndexOrThrow(Entity.DATA_ID)));
3062                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
3063                            Data.RES_PACKAGE);
3064                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv, Data.MIMETYPE);
3065                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.IS_PRIMARY);
3066                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv,
3067                            Data.IS_SUPER_PRIMARY);
3068                    DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, cv, Data.DATA_VERSION);
3069                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
3070                            CommonDataKinds.GroupMembership.GROUP_SOURCE_ID);
3071                    DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, cv,
3072                            Data.DATA_VERSION);
3073                    for (String key : DATA_KEYS) {
3074                        final int columnIndex = cursor.getColumnIndexOrThrow(key);
3075                        switch (cursor.getType(columnIndex)) {
3076                            case Cursor.FIELD_TYPE_NULL:
3077                                // don't put anything
3078                                break;
3079                            case Cursor.FIELD_TYPE_INTEGER:
3080                            case Cursor.FIELD_TYPE_FLOAT:
3081                            case Cursor.FIELD_TYPE_STRING:
3082                                cv.put(key, cursor.getString(columnIndex));
3083                                break;
3084                            case Cursor.FIELD_TYPE_BLOB:
3085                                cv.put(key, cursor.getBlob(columnIndex));
3086                                break;
3087                            default:
3088                                throw new IllegalStateException("Invalid or unhandled data type");
3089                        }
3090                    }
3091                    contact.addSubValue(ContactsContract.Data.CONTENT_URI, cv);
3092                } while (cursor.moveToNext());
3093
3094                return contact;
3095            }
3096
3097        }
3098    }
3099
3100    /**
3101     * Social status update columns.
3102     *
3103     * @see StatusUpdates
3104     * @see ContactsContract.Data
3105     */
3106    protected interface StatusColumns {
3107        /**
3108         * Contact's latest presence level.
3109         * <P>Type: INTEGER (one of the values below)</P>
3110         */
3111        public static final String PRESENCE = "mode";
3112
3113        /**
3114         * @deprecated use {@link #PRESENCE}
3115         */
3116        @Deprecated
3117        public static final String PRESENCE_STATUS = PRESENCE;
3118
3119        /**
3120         * An allowed value of {@link #PRESENCE}.
3121         */
3122        int OFFLINE = 0;
3123
3124        /**
3125         * An allowed value of {@link #PRESENCE}.
3126         */
3127        int INVISIBLE = 1;
3128
3129        /**
3130         * An allowed value of {@link #PRESENCE}.
3131         */
3132        int AWAY = 2;
3133
3134        /**
3135         * An allowed value of {@link #PRESENCE}.
3136         */
3137        int IDLE = 3;
3138
3139        /**
3140         * An allowed value of {@link #PRESENCE}.
3141         */
3142        int DO_NOT_DISTURB = 4;
3143
3144        /**
3145         * An allowed value of {@link #PRESENCE}.
3146         */
3147        int AVAILABLE = 5;
3148
3149        /**
3150         * Contact latest status update.
3151         * <p>Type: TEXT</p>
3152         */
3153        public static final String STATUS = "status";
3154
3155        /**
3156         * @deprecated use {@link #STATUS}
3157         */
3158        @Deprecated
3159        public static final String PRESENCE_CUSTOM_STATUS = STATUS;
3160
3161        /**
3162         * The absolute time in milliseconds when the latest status was inserted/updated.
3163         * <p>Type: NUMBER</p>
3164         */
3165        public static final String STATUS_TIMESTAMP = "status_ts";
3166
3167        /**
3168         * The package containing resources for this status: label and icon.
3169         * <p>Type: TEXT</p>
3170         */
3171        public static final String STATUS_RES_PACKAGE = "status_res_package";
3172
3173        /**
3174         * The resource ID of the label describing the source of the status update, e.g. "Google
3175         * Talk".  This resource should be scoped by the {@link #STATUS_RES_PACKAGE}.
3176         * <p>Type: NUMBER</p>
3177         */
3178        public static final String STATUS_LABEL = "status_label";
3179
3180        /**
3181         * The resource ID of the icon for the source of the status update.
3182         * This resource should be scoped by the {@link #STATUS_RES_PACKAGE}.
3183         * <p>Type: NUMBER</p>
3184         */
3185        public static final String STATUS_ICON = "status_icon";
3186
3187        /**
3188         * Contact's audio/video chat capability level.
3189         * <P>Type: INTEGER (one of the values below)</P>
3190         */
3191        public static final String CHAT_CAPABILITY = "chat_capability";
3192
3193        /**
3194         * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates audio-chat capability (microphone
3195         * and speaker)
3196         */
3197        public static final int CAPABILITY_HAS_VOICE = 1;
3198
3199        /**
3200         * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates that the contact's device can
3201         * display a video feed.
3202         */
3203        public static final int CAPABILITY_HAS_VIDEO = 2;
3204
3205        /**
3206         * An allowed flag of {@link #CHAT_CAPABILITY}. Indicates that the contact's device has a
3207         * camera that can be used for video chat (e.g. a front-facing camera on a phone).
3208         */
3209        public static final int CAPABILITY_HAS_CAMERA = 4;
3210    }
3211
3212    /**
3213     * <p>
3214     * Constants for the stream_items table, which contains social stream updates from
3215     * the user's contact list.
3216     * </p>
3217     * <p>
3218     * Only a certain number of stream items will ever be stored under a given raw contact.
3219     * Users of this API can query {@link ContactsContract.StreamItems#CONTENT_LIMIT_URI} to
3220     * determine this limit, and should restrict the number of items inserted in any given
3221     * transaction correspondingly.  Insertion of more items beyond the limit will
3222     * automatically lead to deletion of the oldest items, by {@link StreamItems#TIMESTAMP}.
3223     * </p>
3224     * <p>
3225     * Access to the social stream through these URIs requires additional permissions beyond the
3226     * read/write contact permissions required by the provider.  Querying for social stream data
3227     * requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating social
3228     * stream items requires android.permission.WRITE_SOCIAL_STREAM permission.
3229     * </p>
3230     * <h3>Account check</h3>
3231     * <p>
3232     * The content URIs to the insert, update and delete operations are required to have the account
3233     * information matching that of the owning raw contact as query parameters, namely
3234     * {@link RawContacts#ACCOUNT_TYPE} and {@link RawContacts#ACCOUNT_NAME}.
3235     * {@link RawContacts#DATA_SET} isn't required.
3236     * </p>
3237     * <h3>Operations</h3>
3238     * <dl>
3239     * <dt><b>Insert</b></dt>
3240     * <dd>
3241     * <p>Social stream updates are always associated with a raw contact.  There are a couple
3242     * of ways to insert these entries.
3243     * <dl>
3244     * <dt>Via the {@link RawContacts.StreamItems#CONTENT_DIRECTORY} sub-path of a raw contact:</dt>
3245     * <dd>
3246     * <pre>
3247     * ContentValues values = new ContentValues();
3248     * values.put(StreamItems.TEXT, "Breakfasted at Tiffanys");
3249     * values.put(StreamItems.TIMESTAMP, timestamp);
3250     * values.put(StreamItems.COMMENTS, "3 people reshared this");
3251     * Uri.Builder builder = RawContacts.CONTENT_URI.buildUpon();
3252     * ContentUris.appendId(builder, rawContactId);
3253     * builder.appendEncodedPath(RawContacts.StreamItems.CONTENT_DIRECTORY);
3254     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3255     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3256     * Uri streamItemUri = getContentResolver().insert(builder.build(), values);
3257     * long streamItemId = ContentUris.parseId(streamItemUri);
3258     * </pre>
3259     * </dd>
3260     * <dt>Via {@link StreamItems#CONTENT_URI}:</dt>
3261     * <dd>
3262     *<pre>
3263     * ContentValues values = new ContentValues();
3264     * values.put(StreamItems.RAW_CONTACT_ID, rawContactId);
3265     * values.put(StreamItems.TEXT, "Breakfasted at Tiffanys");
3266     * values.put(StreamItems.TIMESTAMP, timestamp);
3267     * values.put(StreamItems.COMMENTS, "3 people reshared this");
3268     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3269     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3270     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3271     * Uri streamItemUri = getContentResolver().insert(builder.build(), values);
3272     * long streamItemId = ContentUris.parseId(streamItemUri);
3273     *</pre>
3274     * </dd>
3275     * </dl>
3276     * </dd>
3277     * </p>
3278     * <p>
3279     * Once a {@link StreamItems} entry has been inserted, photos associated with that
3280     * social update can be inserted.  For example, after one of the insertions above,
3281     * photos could be added to the stream item in one of the following ways:
3282     * <dl>
3283     * <dt>Via a URI including the stream item ID:</dt>
3284     * <dd>
3285     * <pre>
3286     * values.clear();
3287     * values.put(StreamItemPhotos.SORT_INDEX, 1);
3288     * values.put(StreamItemPhotos.PHOTO, photoData);
3289     * getContentResolver().insert(Uri.withAppendedPath(
3290     *     ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId),
3291     *     StreamItems.StreamItemPhotos.CONTENT_DIRECTORY), values);
3292     * </pre>
3293     * </dd>
3294     * <dt>Via {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI}:</dt>
3295     * <dd>
3296     * <pre>
3297     * values.clear();
3298     * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
3299     * values.put(StreamItemPhotos.SORT_INDEX, 1);
3300     * values.put(StreamItemPhotos.PHOTO, photoData);
3301     * getContentResolver().insert(StreamItems.CONTENT_PHOTO_URI, values);
3302     * </pre>
3303     * <p>Note that this latter form allows the insertion of a stream item and its
3304     * photos in a single transaction, by using {@link ContentProviderOperation} with
3305     * back references to populate the stream item ID in the {@link ContentValues}.
3306     * </dd>
3307     * </dl>
3308     * </p>
3309     * </dd>
3310     * <dt><b>Update</b></dt>
3311     * <dd>Updates can be performed by appending the stream item ID to the
3312     * {@link StreamItems#CONTENT_URI} URI.  Only social stream entries that were
3313     * created by the calling package can be updated.</dd>
3314     * <dt><b>Delete</b></dt>
3315     * <dd>Deletes can be performed by appending the stream item ID to the
3316     * {@link StreamItems#CONTENT_URI} URI.  Only social stream entries that were
3317     * created by the calling package can be deleted.</dd>
3318     * <dt><b>Query</b></dt>
3319     * <dl>
3320     * <dt>Finding all social stream updates for a given contact</dt>
3321     * <dd>By Contact ID:
3322     * <pre>
3323     * Cursor c = getContentResolver().query(Uri.withAppendedPath(
3324     *          ContentUris.withAppendedId(Contacts.CONTENT_URI, contactId),
3325     *          Contacts.StreamItems.CONTENT_DIRECTORY),
3326     *          null, null, null, null);
3327     * </pre>
3328     * </dd>
3329     * <dd>By lookup key:
3330     * <pre>
3331     * Cursor c = getContentResolver().query(Contacts.CONTENT_URI.buildUpon()
3332     *          .appendPath(lookupKey)
3333     *          .appendPath(Contacts.StreamItems.CONTENT_DIRECTORY).build(),
3334     *          null, null, null, null);
3335     * </pre>
3336     * </dd>
3337     * <dt>Finding all social stream updates for a given raw contact</dt>
3338     * <dd>
3339     * <pre>
3340     * Cursor c = getContentResolver().query(Uri.withAppendedPath(
3341     *          ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId),
3342     *          RawContacts.StreamItems.CONTENT_DIRECTORY)),
3343     *          null, null, null, null);
3344     * </pre>
3345     * </dd>
3346     * <dt>Querying for a specific stream item by ID</dt>
3347     * <dd>
3348     * <pre>
3349     * Cursor c = getContentResolver().query(ContentUris.withAppendedId(
3350     *          StreamItems.CONTENT_URI, streamItemId),
3351     *          null, null, null, null);
3352     * </pre>
3353     * </dd>
3354     * </dl>
3355     *
3356     * @deprecated - Do not use. This will not be supported in the future. In the future,
3357     * cursors returned from related queries will be empty.
3358     *
3359     * @hide
3360     * @removed
3361     */
3362    @Deprecated
3363    public static final class StreamItems implements BaseColumns, StreamItemsColumns {
3364        /**
3365         * This utility class cannot be instantiated
3366         *
3367         * @deprecated - Do not use. This will not be supported in the future. In the future,
3368         * cursors returned from related queries will be empty.
3369         */
3370        @Deprecated
3371        private StreamItems() {
3372        }
3373
3374        /**
3375         * The content:// style URI for this table, which handles social network stream
3376         * updates for the user's contacts.
3377         *
3378         * @deprecated - Do not use. This will not be supported in the future. In the future,
3379         * cursors returned from related queries will be empty.
3380         */
3381        @Deprecated
3382        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "stream_items");
3383
3384        /**
3385         * <p>
3386         * A content:// style URI for the photos stored in a sub-table underneath
3387         * stream items.  This is only used for inserts, and updates - queries and deletes
3388         * for photos should be performed by appending
3389         * {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} path to URIs for a
3390         * specific stream item.
3391         * </p>
3392         * <p>
3393         * When using this URI, the stream item ID for the photo(s) must be identified
3394         * in the {@link ContentValues} passed in.
3395         * </p>
3396         *
3397         * @deprecated - Do not use. This will not be supported in the future. In the future,
3398         * cursors returned from related queries will be empty.
3399         */
3400        @Deprecated
3401        public static final Uri CONTENT_PHOTO_URI = Uri.withAppendedPath(CONTENT_URI, "photo");
3402
3403        /**
3404         * This URI allows the caller to query for the maximum number of stream items
3405         * that will be stored under any single raw contact.
3406         *
3407         * @deprecated - Do not use. This will not be supported in the future. In the future,
3408         * cursors returned from related queries will be empty.
3409         */
3410        @Deprecated
3411        public static final Uri CONTENT_LIMIT_URI =
3412                Uri.withAppendedPath(AUTHORITY_URI, "stream_items_limit");
3413
3414        /**
3415         * The MIME type of a directory of stream items.
3416         *
3417         * @deprecated - Do not use. This will not be supported in the future. In the future,
3418         * cursors returned from related queries will be empty.
3419         */
3420        @Deprecated
3421        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/stream_item";
3422
3423        /**
3424         * The MIME type of a single stream item.
3425         *
3426         * @deprecated - Do not use. This will not be supported in the future. In the future,
3427         * cursors returned from related queries will be empty.
3428         */
3429        @Deprecated
3430        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/stream_item";
3431
3432        /**
3433         * Queries to {@link ContactsContract.StreamItems#CONTENT_LIMIT_URI} will
3434         * contain this column, with the value indicating the maximum number of
3435         * stream items that will be stored under any single raw contact.
3436         *
3437         * @deprecated - Do not use. This will not be supported in the future. In the future,
3438         * cursors returned from related queries will be empty.
3439         */
3440        @Deprecated
3441        public static final String MAX_ITEMS = "max_items";
3442
3443        /**
3444         * <p>
3445         * A sub-directory of a single stream item entry that contains all of its
3446         * photo rows. To access this
3447         * directory append {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} to
3448         * an individual stream item URI.
3449         * </p>
3450         * <p>
3451         * Access to social stream photos requires additional permissions beyond the read/write
3452         * contact permissions required by the provider.  Querying for social stream photos
3453         * requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating
3454         * social stream photos requires android.permission.WRITE_SOCIAL_STREAM permission.
3455         * </p>
3456         *
3457         * @deprecated - Do not use. This will not be supported in the future. In the future,
3458         * cursors returned from related queries will be empty.
3459         *
3460         * @hide
3461         * @removed
3462         */
3463        @Deprecated
3464        public static final class StreamItemPhotos
3465                implements BaseColumns, StreamItemPhotosColumns {
3466            /**
3467             * No public constructor since this is a utility class
3468             *
3469             * @deprecated - Do not use. This will not be supported in the future. In the future,
3470             * cursors returned from related queries will be empty.
3471             */
3472            @Deprecated
3473            private StreamItemPhotos() {
3474            }
3475
3476            /**
3477             * The directory twig for this sub-table
3478             *
3479             * @deprecated - Do not use. This will not be supported in the future. In the future,
3480             * cursors returned from related queries will be empty.
3481             */
3482            @Deprecated
3483            public static final String CONTENT_DIRECTORY = "photo";
3484
3485            /**
3486             * The MIME type of a directory of stream item photos.
3487             *
3488             * @deprecated - Do not use. This will not be supported in the future. In the future,
3489             * cursors returned from related queries will be empty.
3490             */
3491            @Deprecated
3492            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/stream_item_photo";
3493
3494            /**
3495             * The MIME type of a single stream item photo.
3496             *
3497             * @deprecated - Do not use. This will not be supported in the future. In the future,
3498             * cursors returned from related queries will be empty.
3499             */
3500            @Deprecated
3501            public static final String CONTENT_ITEM_TYPE
3502                    = "vnd.android.cursor.item/stream_item_photo";
3503        }
3504    }
3505
3506    /**
3507     * Columns in the StreamItems table.
3508     *
3509     * @see ContactsContract.StreamItems
3510     * @deprecated - Do not use. This will not be supported in the future. In the future,
3511     * cursors returned from related queries will be empty.
3512     *
3513     * @hide
3514     * @removed
3515     */
3516    @Deprecated
3517    protected interface StreamItemsColumns {
3518        /**
3519         * A reference to the {@link android.provider.ContactsContract.Contacts#_ID}
3520         * that this stream item belongs to.
3521         *
3522         * <p>Type: INTEGER</p>
3523         * <p>read-only</p>
3524         *
3525         * @deprecated - Do not use. This will not be supported in the future. In the future,
3526         * cursors returned from related queries will be empty.
3527         */
3528        @Deprecated
3529        public static final String CONTACT_ID = "contact_id";
3530
3531        /**
3532         * A reference to the {@link android.provider.ContactsContract.Contacts#LOOKUP_KEY}
3533         * that this stream item belongs to.
3534         *
3535         * <p>Type: TEXT</p>
3536         * <p>read-only</p>
3537         *
3538         * @deprecated - Do not use. This will not be supported in the future. In the future,
3539         * cursors returned from related queries will be empty.
3540         */
3541        @Deprecated
3542        public static final String CONTACT_LOOKUP_KEY = "contact_lookup";
3543
3544        /**
3545         * A reference to the {@link RawContacts#_ID}
3546         * that this stream item belongs to.
3547         * <p>Type: INTEGER</p>
3548         *
3549         * @deprecated - Do not use. This will not be supported in the future. In the future,
3550         * cursors returned from related queries will be empty.
3551         */
3552        @Deprecated
3553        public static final String RAW_CONTACT_ID = "raw_contact_id";
3554
3555        /**
3556         * The package name to use when creating {@link Resources} objects for
3557         * this stream item. This value is only designed for use when building
3558         * user interfaces, and should not be used to infer the owner.
3559         * <P>Type: TEXT</P>
3560         *
3561         * @deprecated - Do not use. This will not be supported in the future. In the future,
3562         * cursors returned from related queries will be empty.
3563         */
3564        @Deprecated
3565        public static final String RES_PACKAGE = "res_package";
3566
3567        /**
3568         * The account type to which the raw_contact of this item is associated. See
3569         * {@link RawContacts#ACCOUNT_TYPE}
3570         *
3571         * <p>Type: TEXT</p>
3572         * <p>read-only</p>
3573         *
3574         * @deprecated - Do not use. This will not be supported in the future. In the future,
3575         * cursors returned from related queries will be empty.
3576         */
3577        @Deprecated
3578        public static final String ACCOUNT_TYPE = "account_type";
3579
3580        /**
3581         * The account name to which the raw_contact of this item is associated. See
3582         * {@link RawContacts#ACCOUNT_NAME}
3583         *
3584         * <p>Type: TEXT</p>
3585         * <p>read-only</p>
3586         *
3587         * @deprecated - Do not use. This will not be supported in the future. In the future,
3588         * cursors returned from related queries will be empty.
3589         */
3590        @Deprecated
3591        public static final String ACCOUNT_NAME = "account_name";
3592
3593        /**
3594         * The data set within the account that the raw_contact of this row belongs to. This allows
3595         * multiple sync adapters for the same account type to distinguish between
3596         * each others' data.
3597         * {@link RawContacts#DATA_SET}
3598         *
3599         * <P>Type: TEXT</P>
3600         * <p>read-only</p>
3601         *
3602         * @deprecated - Do not use. This will not be supported in the future. In the future,
3603         * cursors returned from related queries will be empty.
3604         */
3605        @Deprecated
3606        public static final String DATA_SET = "data_set";
3607
3608        /**
3609         * The source_id of the raw_contact that this row belongs to.
3610         * {@link RawContacts#SOURCE_ID}
3611         *
3612         * <P>Type: TEXT</P>
3613         * <p>read-only</p>
3614         *
3615         * @deprecated - Do not use. This will not be supported in the future. In the future,
3616         * cursors returned from related queries will be empty.
3617         */
3618        @Deprecated
3619        public static final String RAW_CONTACT_SOURCE_ID = "raw_contact_source_id";
3620
3621        /**
3622         * The resource name of the icon for the source of the stream item.
3623         * This resource should be scoped by the {@link #RES_PACKAGE}. As this can only reference
3624         * drawables, the "@drawable/" prefix must be omitted.
3625         * <P>Type: TEXT</P>
3626         *
3627         * @deprecated - Do not use. This will not be supported in the future. In the future,
3628         * cursors returned from related queries will be empty.
3629         */
3630        @Deprecated
3631        public static final String RES_ICON = "icon";
3632
3633        /**
3634         * The resource name of the label describing the source of the status update, e.g. "Google
3635         * Talk". This resource should be scoped by the {@link #RES_PACKAGE}. As this can only
3636         * reference strings, the "@string/" prefix must be omitted.
3637         * <p>Type: TEXT</p>
3638         *
3639         * @deprecated - Do not use. This will not be supported in the future. In the future,
3640         * cursors returned from related queries will be empty.
3641         */
3642        @Deprecated
3643        public static final String RES_LABEL = "label";
3644
3645        /**
3646         * <P>
3647         * The main textual contents of the item. Typically this is content
3648         * that was posted by the source of this stream item, but it can also
3649         * be a textual representation of an action (e.g. ”Checked in at Joe's”).
3650         * This text is displayed to the user and allows formatting and embedded
3651         * resource images via HTML (as parseable via
3652         * {@link android.text.Html#fromHtml}).
3653         * </P>
3654         * <P>
3655         * Long content may be truncated and/or ellipsized - the exact behavior
3656         * is unspecified, but it should not break tags.
3657         * </P>
3658         * <P>Type: TEXT</P>
3659         *
3660         * @deprecated - Do not use. This will not be supported in the future. In the future,
3661         * cursors returned from related queries will be empty.
3662         */
3663        @Deprecated
3664        public static final String TEXT = "text";
3665
3666        /**
3667         * The absolute time (milliseconds since epoch) when this stream item was
3668         * inserted/updated.
3669         * <P>Type: NUMBER</P>
3670         *
3671         * @deprecated - Do not use. This will not be supported in the future. In the future,
3672         * cursors returned from related queries will be empty.
3673         */
3674        @Deprecated
3675        public static final String TIMESTAMP = "timestamp";
3676
3677        /**
3678         * <P>
3679         * Summary information about the stream item, for example to indicate how
3680         * many people have reshared it, how many have liked it, how many thumbs
3681         * up and/or thumbs down it has, what the original source was, etc.
3682         * </P>
3683         * <P>
3684         * This text is displayed to the user and allows simple formatting via
3685         * HTML, in the same manner as {@link #TEXT} allows.
3686         * </P>
3687         * <P>
3688         * Long content may be truncated and/or ellipsized - the exact behavior
3689         * is unspecified, but it should not break tags.
3690         * </P>
3691         * <P>Type: TEXT</P>
3692         *
3693         * @deprecated - Do not use. This will not be supported in the future. In the future,
3694         * cursors returned from related queries will be empty.
3695         */
3696        @Deprecated
3697        public static final String COMMENTS = "comments";
3698
3699        /**
3700         * Generic column for use by sync adapters.
3701         *
3702         * @deprecated - Do not use. This will not be supported in the future. In the future,
3703         * cursors returned from related queries will be empty.
3704         */
3705        @Deprecated
3706        public static final String SYNC1 = "stream_item_sync1";
3707        /**
3708         * Generic column for use by sync adapters.
3709         *
3710         * @deprecated - Do not use. This will not be supported in the future. In the future,
3711         * cursors returned from related queries will be empty.
3712         */
3713        @Deprecated
3714        public static final String SYNC2 = "stream_item_sync2";
3715        /**
3716         * Generic column for use by sync adapters.
3717         *
3718         * @deprecated - Do not use. This will not be supported in the future. In the future,
3719         * cursors returned from related queries will be empty.
3720         */
3721        @Deprecated
3722        public static final String SYNC3 = "stream_item_sync3";
3723        /**
3724         * Generic column for use by sync adapters.
3725         *
3726         * @deprecated - Do not use. This will not be supported in the future. In the future,
3727         * cursors returned from related queries will be empty.
3728         */
3729        @Deprecated
3730        public static final String SYNC4 = "stream_item_sync4";
3731    }
3732
3733    /**
3734     * <p>
3735     * Constants for the stream_item_photos table, which contains photos associated with
3736     * social stream updates.
3737     * </p>
3738     * <p>
3739     * Access to social stream photos requires additional permissions beyond the read/write
3740     * contact permissions required by the provider.  Querying for social stream photos
3741     * requires android.permission.READ_SOCIAL_STREAM permission, and inserting or updating
3742     * social stream photos requires android.permission.WRITE_SOCIAL_STREAM permission.
3743     * </p>
3744     * <h3>Account check</h3>
3745     * <p>
3746     * The content URIs to the insert, update and delete operations are required to have the account
3747     * information matching that of the owning raw contact as query parameters, namely
3748     * {@link RawContacts#ACCOUNT_TYPE} and {@link RawContacts#ACCOUNT_NAME}.
3749     * {@link RawContacts#DATA_SET} isn't required.
3750     * </p>
3751     * <h3>Operations</h3>
3752     * <dl>
3753     * <dt><b>Insert</b></dt>
3754     * <dd>
3755     * <p>Social stream photo entries are associated with a social stream item.  Photos
3756     * can be inserted into a social stream item in a couple of ways:
3757     * <dl>
3758     * <dt>
3759     * Via the {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a
3760     * stream item:
3761     * </dt>
3762     * <dd>
3763     * <pre>
3764     * ContentValues values = new ContentValues();
3765     * values.put(StreamItemPhotos.SORT_INDEX, 1);
3766     * values.put(StreamItemPhotos.PHOTO, photoData);
3767     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3768     * ContentUris.appendId(builder, streamItemId);
3769     * builder.appendEncodedPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY);
3770     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3771     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3772     * Uri photoUri = getContentResolver().insert(builder.build(), values);
3773     * long photoId = ContentUris.parseId(photoUri);
3774     * </pre>
3775     * </dd>
3776     * <dt>Via the {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI} URI:</dt>
3777     * <dd>
3778     * <pre>
3779     * ContentValues values = new ContentValues();
3780     * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
3781     * values.put(StreamItemPhotos.SORT_INDEX, 1);
3782     * values.put(StreamItemPhotos.PHOTO, photoData);
3783     * Uri.Builder builder = StreamItems.CONTENT_PHOTO_URI.buildUpon();
3784     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3785     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3786     * Uri photoUri = getContentResolver().insert(builder.build(), values);
3787     * long photoId = ContentUris.parseId(photoUri);
3788     * </pre>
3789     * </dd>
3790     * </dl>
3791     * </p>
3792     * </dd>
3793     * <dt><b>Update</b></dt>
3794     * <dd>
3795     * <p>Updates can only be made against a specific {@link StreamItemPhotos} entry,
3796     * identified by both the stream item ID it belongs to and the stream item photo ID.
3797     * This can be specified in two ways.
3798     * <dl>
3799     * <dt>Via the {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a
3800     * stream item:
3801     * </dt>
3802     * <dd>
3803     * <pre>
3804     * ContentValues values = new ContentValues();
3805     * values.put(StreamItemPhotos.PHOTO, newPhotoData);
3806     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3807     * ContentUris.appendId(builder, streamItemId);
3808     * builder.appendEncodedPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY);
3809     * ContentUris.appendId(builder, streamItemPhotoId);
3810     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3811     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3812     * getContentResolver().update(builder.build(), values, null, null);
3813     * </pre>
3814     * </dd>
3815     * <dt>Via the {@link ContactsContract.StreamItems#CONTENT_PHOTO_URI} URI:</dt>
3816     * <dd>
3817     * <pre>
3818     * ContentValues values = new ContentValues();
3819     * values.put(StreamItemPhotos.STREAM_ITEM_ID, streamItemId);
3820     * values.put(StreamItemPhotos.PHOTO, newPhotoData);
3821     * Uri.Builder builder = StreamItems.CONTENT_PHOTO_URI.buildUpon();
3822     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3823     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3824     * getContentResolver().update(builder.build(), values);
3825     * </pre>
3826     * </dd>
3827     * </dl>
3828     * </p>
3829     * </dd>
3830     * <dt><b>Delete</b></dt>
3831     * <dd>Deletes can be made against either a specific photo item in a stream item, or
3832     * against all or a selected subset of photo items under a stream item.
3833     * For example:
3834     * <dl>
3835     * <dt>Deleting a single photo via the
3836     * {@link StreamItems.StreamItemPhotos#CONTENT_DIRECTORY} sub-path of a stream item:
3837     * </dt>
3838     * <dd>
3839     * <pre>
3840     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3841     * ContentUris.appendId(builder, streamItemId);
3842     * builder.appendEncodedPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY);
3843     * ContentUris.appendId(builder, streamItemPhotoId);
3844     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3845     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3846     * getContentResolver().delete(builder.build(), null, null);
3847     * </pre>
3848     * </dd>
3849     * <dt>Deleting all photos under a stream item</dt>
3850     * <dd>
3851     * <pre>
3852     * Uri.Builder builder = StreamItems.CONTENT_URI.buildUpon();
3853     * ContentUris.appendId(builder, streamItemId);
3854     * builder.appendEncodedPath(StreamItems.StreamItemPhotos.CONTENT_DIRECTORY);
3855     * builder.appendQueryParameter(RawContacts.ACCOUNT_NAME, accountName);
3856     * builder.appendQueryParameter(RawContacts.ACCOUNT_TYPE, accountType);
3857     * getContentResolver().delete(builder.build(), null, null);
3858     * </pre>
3859     * </dd>
3860     * </dl>
3861     * </dd>
3862     * <dt><b>Query</b></dt>
3863     * <dl>
3864     * <dt>Querying for a specific photo in a stream item</dt>
3865     * <dd>
3866     * <pre>
3867     * Cursor c = getContentResolver().query(
3868     *     ContentUris.withAppendedId(
3869     *         Uri.withAppendedPath(
3870     *             ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
3871     *             StreamItems.StreamItemPhotos#CONTENT_DIRECTORY),
3872     *         streamItemPhotoId), null, null, null, null);
3873     * </pre>
3874     * </dd>
3875     * <dt>Querying for all photos in a stream item</dt>
3876     * <dd>
3877     * <pre>
3878     * Cursor c = getContentResolver().query(
3879     *     Uri.withAppendedPath(
3880     *         ContentUris.withAppendedId(StreamItems.CONTENT_URI, streamItemId)
3881     *         StreamItems.StreamItemPhotos#CONTENT_DIRECTORY),
3882     *     null, null, null, StreamItemPhotos.SORT_INDEX);
3883     * </pre>
3884     * </dl>
3885     * The record will contain both a {@link StreamItemPhotos#PHOTO_FILE_ID} and a
3886     * {@link StreamItemPhotos#PHOTO_URI}.  The {@link StreamItemPhotos#PHOTO_FILE_ID}
3887     * can be used in conjunction with the {@link ContactsContract.DisplayPhoto} API to
3888     * retrieve photo content, or you can open the {@link StreamItemPhotos#PHOTO_URI} as
3889     * an asset file, as follows:
3890     * <pre>
3891     * public InputStream openDisplayPhoto(String photoUri) {
3892     *     try {
3893     *         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(photoUri, "r");
3894     *         return fd.createInputStream();
3895     *     } catch (IOException e) {
3896     *         return null;
3897     *     }
3898     * }
3899     * <pre>
3900     * </dd>
3901     * </dl>
3902     *
3903     * @deprecated - Do not use. This will not be supported in the future. In the future,
3904     * cursors returned from related queries will be empty.
3905     *
3906     * @hide
3907     * @removed
3908     */
3909    @Deprecated
3910    public static final class StreamItemPhotos implements BaseColumns, StreamItemPhotosColumns {
3911        /**
3912         * No public constructor since this is a utility class
3913         *
3914         * @deprecated - Do not use. This will not be supported in the future. In the future,
3915         * cursors returned from related queries will be empty.
3916         */
3917        @Deprecated
3918        private StreamItemPhotos() {
3919        }
3920
3921        /**
3922         * <p>
3923         * The binary representation of the photo.  Any size photo can be inserted;
3924         * the provider will resize it appropriately for storage and display.
3925         * </p>
3926         * <p>
3927         * This is only intended for use when inserting or updating a stream item photo.
3928         * To retrieve the photo that was stored, open {@link StreamItemPhotos#PHOTO_URI}
3929         * as an asset file.
3930         * </p>
3931         * <P>Type: BLOB</P>
3932         *
3933         * @deprecated - Do not use. This will not be supported in the future. In the future,
3934         * cursors returned from related queries will be empty.
3935         */
3936        @Deprecated
3937        public static final String PHOTO = "photo";
3938    }
3939
3940    /**
3941     * Columns in the StreamItemPhotos table.
3942     *
3943     * @see ContactsContract.StreamItemPhotos
3944     * @deprecated - Do not use. This will not be supported in the future. In the future,
3945     * cursors returned from related queries will be empty.
3946     *
3947     * @hide
3948     * @removed
3949     */
3950    @Deprecated
3951    protected interface StreamItemPhotosColumns {
3952        /**
3953         * A reference to the {@link StreamItems#_ID} this photo is associated with.
3954         * <P>Type: NUMBER</P>
3955         *
3956         * @deprecated - Do not use. This will not be supported in the future. In the future,
3957         * cursors returned from related queries will be empty.
3958         */
3959        @Deprecated
3960        public static final String STREAM_ITEM_ID = "stream_item_id";
3961
3962        /**
3963         * An integer to use for sort order for photos in the stream item.  If not
3964         * specified, the {@link StreamItemPhotos#_ID} will be used for sorting.
3965         * <P>Type: NUMBER</P>
3966         *
3967         * @deprecated - Do not use. This will not be supported in the future. In the future,
3968         * cursors returned from related queries will be empty.
3969         */
3970        @Deprecated
3971        public static final String SORT_INDEX = "sort_index";
3972
3973        /**
3974         * Photo file ID for the photo.
3975         * See {@link ContactsContract.DisplayPhoto}.
3976         * <P>Type: NUMBER</P>
3977         *
3978         * @deprecated - Do not use. This will not be supported in the future. In the future,
3979         * cursors returned from related queries will be empty.
3980         */
3981        @Deprecated
3982        public static final String PHOTO_FILE_ID = "photo_file_id";
3983
3984        /**
3985         * URI for retrieving the photo content, automatically populated.  Callers
3986         * may retrieve the photo content by opening this URI as an asset file.
3987         * <P>Type: TEXT</P>
3988         *
3989         * @deprecated - Do not use. This will not be supported in the future. In the future,
3990         * cursors returned from related queries will be empty.
3991         */
3992        @Deprecated
3993        public static final String PHOTO_URI = "photo_uri";
3994
3995        /**
3996         * Generic column for use by sync adapters.
3997         *
3998         * @deprecated - Do not use. This will not be supported in the future. In the future,
3999         * cursors returned from related queries will be empty.
4000         */
4001        @Deprecated
4002        public static final String SYNC1 = "stream_item_photo_sync1";
4003        /**
4004         * Generic column for use by sync adapters.
4005         *
4006         * @deprecated - Do not use. This will not be supported in the future. In the future,
4007         * cursors returned from related queries will be empty.
4008         */
4009        @Deprecated
4010        public static final String SYNC2 = "stream_item_photo_sync2";
4011        /**
4012         * Generic column for use by sync adapters.
4013         *
4014         * @deprecated - Do not use. This will not be supported in the future. In the future,
4015         * cursors returned from related queries will be empty.
4016         */
4017        @Deprecated
4018        public static final String SYNC3 = "stream_item_photo_sync3";
4019        /**
4020         * Generic column for use by sync adapters.
4021         *
4022         * @deprecated - Do not use. This will not be supported in the future. In the future,
4023         * cursors returned from related queries will be empty.
4024         */
4025        @Deprecated
4026        public static final String SYNC4 = "stream_item_photo_sync4";
4027    }
4028
4029    /**
4030     * <p>
4031     * Constants for the photo files table, which tracks metadata for hi-res photos
4032     * stored in the file system.
4033     * </p>
4034     *
4035     * @hide
4036     */
4037    public static final class PhotoFiles implements BaseColumns, PhotoFilesColumns {
4038        /**
4039         * No public constructor since this is a utility class
4040         */
4041        private PhotoFiles() {
4042        }
4043    }
4044
4045    /**
4046     * Columns in the PhotoFiles table.
4047     *
4048     * @see ContactsContract.PhotoFiles
4049     *
4050     * @hide
4051     */
4052    protected interface PhotoFilesColumns {
4053
4054        /**
4055         * The height, in pixels, of the photo this entry is associated with.
4056         * <P>Type: NUMBER</P>
4057         */
4058        public static final String HEIGHT = "height";
4059
4060        /**
4061         * The width, in pixels, of the photo this entry is associated with.
4062         * <P>Type: NUMBER</P>
4063         */
4064        public static final String WIDTH = "width";
4065
4066        /**
4067         * The size, in bytes, of the photo stored on disk.
4068         * <P>Type: NUMBER</P>
4069         */
4070        public static final String FILESIZE = "filesize";
4071    }
4072
4073    /**
4074     * Columns in the Data table.
4075     *
4076     * @see ContactsContract.Data
4077     */
4078    protected interface DataColumns {
4079        /**
4080         * The package name to use when creating {@link Resources} objects for
4081         * this data row. This value is only designed for use when building user
4082         * interfaces, and should not be used to infer the owner.
4083         */
4084        public static final String RES_PACKAGE = "res_package";
4085
4086        /**
4087         * The MIME type of the item represented by this row.
4088         */
4089        public static final String MIMETYPE = "mimetype";
4090
4091        /**
4092         * Hash id on the data fields, used for backup and restore.
4093         *
4094         * @hide
4095         */
4096        public static final String HASH_ID = "hash_id";
4097
4098        /**
4099         * A reference to the {@link RawContacts#_ID}
4100         * that this data belongs to.
4101         */
4102        public static final String RAW_CONTACT_ID = "raw_contact_id";
4103
4104        /**
4105         * Whether this is the primary entry of its kind for the raw contact it belongs to.
4106         * <P>Type: INTEGER (if set, non-0 means true)</P>
4107         */
4108        public static final String IS_PRIMARY = "is_primary";
4109
4110        /**
4111         * Whether this is the primary entry of its kind for the aggregate
4112         * contact it belongs to. Any data record that is "super primary" must
4113         * also be "primary".
4114         * <P>Type: INTEGER (if set, non-0 means true)</P>
4115         */
4116        public static final String IS_SUPER_PRIMARY = "is_super_primary";
4117
4118        /**
4119         * The "read-only" flag: "0" by default, "1" if the row cannot be modified or
4120         * deleted except by a sync adapter.  See {@link ContactsContract#CALLER_IS_SYNCADAPTER}.
4121         * <P>Type: INTEGER</P>
4122         */
4123        public static final String IS_READ_ONLY = "is_read_only";
4124
4125        /**
4126         * The version of this data record. This is a read-only value. The data column is
4127         * guaranteed to not change without the version going up. This value is monotonically
4128         * increasing.
4129         * <P>Type: INTEGER</P>
4130         */
4131        public static final String DATA_VERSION = "data_version";
4132
4133        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4134        public static final String DATA1 = "data1";
4135        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4136        public static final String DATA2 = "data2";
4137        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4138        public static final String DATA3 = "data3";
4139        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4140        public static final String DATA4 = "data4";
4141        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4142        public static final String DATA5 = "data5";
4143        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4144        public static final String DATA6 = "data6";
4145        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4146        public static final String DATA7 = "data7";
4147        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4148        public static final String DATA8 = "data8";
4149        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4150        public static final String DATA9 = "data9";
4151        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4152        public static final String DATA10 = "data10";
4153        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4154        public static final String DATA11 = "data11";
4155        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4156        public static final String DATA12 = "data12";
4157        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4158        public static final String DATA13 = "data13";
4159        /** Generic data column, the meaning is {@link #MIMETYPE} specific */
4160        public static final String DATA14 = "data14";
4161        /**
4162         * Generic data column, the meaning is {@link #MIMETYPE} specific. By convention,
4163         * this field is used to store BLOBs (binary data).
4164         */
4165        public static final String DATA15 = "data15";
4166
4167        /** Generic column for use by sync adapters. */
4168        public static final String SYNC1 = "data_sync1";
4169        /** Generic column for use by sync adapters. */
4170        public static final String SYNC2 = "data_sync2";
4171        /** Generic column for use by sync adapters. */
4172        public static final String SYNC3 = "data_sync3";
4173        /** Generic column for use by sync adapters. */
4174        public static final String SYNC4 = "data_sync4";
4175
4176        /**
4177         * Carrier presence information.
4178         * <P>
4179         * Type: INTEGER (A bitmask of CARRIER_PRESENCE_* fields)
4180         * </P>
4181         */
4182        public static final String CARRIER_PRESENCE = "carrier_presence";
4183
4184        /**
4185         * Indicates that the entry is Video Telephony (VT) capable on the
4186         * current carrier. An allowed bitmask of {@link #CARRIER_PRESENCE}.
4187         */
4188        public static final int CARRIER_PRESENCE_VT_CAPABLE = 0x01;
4189    }
4190
4191    /**
4192     * Columns in the Data_Usage_Stat table
4193     */
4194    protected interface DataUsageStatColumns {
4195        /** The last time (in milliseconds) this {@link Data} was used. */
4196        public static final String LAST_TIME_USED = "last_time_used";
4197
4198        /** The number of times the referenced {@link Data} has been used. */
4199        public static final String TIMES_USED = "times_used";
4200    }
4201
4202    /**
4203     * Combines all columns returned by {@link ContactsContract.Data} table queries.
4204     *
4205     * @see ContactsContract.Data
4206     */
4207    protected interface DataColumnsWithJoins extends BaseColumns, DataColumns, StatusColumns,
4208            RawContactsColumns, ContactsColumns, ContactNameColumns, ContactOptionsColumns,
4209            ContactStatusColumns, DataUsageStatColumns {
4210    }
4211
4212    /**
4213     * <p>
4214     * Constants for the data table, which contains data points tied to a raw
4215     * contact.  Each row of the data table is typically used to store a single
4216     * piece of contact
4217     * information (such as a phone number) and its
4218     * associated metadata (such as whether it is a work or home number).
4219     * </p>
4220     * <h3>Data kinds</h3>
4221     * <p>
4222     * Data is a generic table that can hold any kind of contact data.
4223     * The kind of data stored in a given row is specified by the row's
4224     * {@link #MIMETYPE} value, which determines the meaning of the
4225     * generic columns {@link #DATA1} through
4226     * {@link #DATA15}.
4227     * For example, if the data kind is
4228     * {@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}, then the column
4229     * {@link #DATA1} stores the
4230     * phone number, but if the data kind is
4231     * {@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}, then {@link #DATA1}
4232     * stores the email address.
4233     * Sync adapters and applications can introduce their own data kinds.
4234     * </p>
4235     * <p>
4236     * ContactsContract defines a small number of pre-defined data kinds, e.g.
4237     * {@link CommonDataKinds.Phone}, {@link CommonDataKinds.Email} etc. As a
4238     * convenience, these classes define data kind specific aliases for DATA1 etc.
4239     * For example, {@link CommonDataKinds.Phone Phone.NUMBER} is the same as
4240     * {@link ContactsContract.Data Data.DATA1}.
4241     * </p>
4242     * <p>
4243     * {@link #DATA1} is an indexed column and should be used for the data element that is
4244     * expected to be most frequently used in query selections. For example, in the
4245     * case of a row representing email addresses {@link #DATA1} should probably
4246     * be used for the email address itself, while {@link #DATA2} etc can be
4247     * used for auxiliary information like type of email address.
4248     * <p>
4249     * <p>
4250     * By convention, {@link #DATA15} is used for storing BLOBs (binary data).
4251     * </p>
4252     * <p>
4253     * The sync adapter for a given account type must correctly handle every data type
4254     * used in the corresponding raw contacts.  Otherwise it could result in lost or
4255     * corrupted data.
4256     * </p>
4257     * <p>
4258     * Similarly, you should refrain from introducing new kinds of data for an other
4259     * party's account types. For example, if you add a data row for
4260     * "favorite song" to a raw contact owned by a Google account, it will not
4261     * get synced to the server, because the Google sync adapter does not know
4262     * how to handle this data kind. Thus new data kinds are typically
4263     * introduced along with new account types, i.e. new sync adapters.
4264     * </p>
4265     * <h3>Batch operations</h3>
4266     * <p>
4267     * Data rows can be inserted/updated/deleted using the traditional
4268     * {@link ContentResolver#insert}, {@link ContentResolver#update} and
4269     * {@link ContentResolver#delete} methods, however the newer mechanism based
4270     * on a batch of {@link ContentProviderOperation} will prove to be a better
4271     * choice in almost all cases. All operations in a batch are executed in a
4272     * single transaction, which ensures that the phone-side and server-side
4273     * state of a raw contact are always consistent. Also, the batch-based
4274     * approach is far more efficient: not only are the database operations
4275     * faster when executed in a single transaction, but also sending a batch of
4276     * commands to the content provider saves a lot of time on context switching
4277     * between your process and the process in which the content provider runs.
4278     * </p>
4279     * <p>
4280     * The flip side of using batched operations is that a large batch may lock
4281     * up the database for a long time preventing other applications from
4282     * accessing data and potentially causing ANRs ("Application Not Responding"
4283     * dialogs.)
4284     * </p>
4285     * <p>
4286     * To avoid such lockups of the database, make sure to insert "yield points"
4287     * in the batch. A yield point indicates to the content provider that before
4288     * executing the next operation it can commit the changes that have already
4289     * been made, yield to other requests, open another transaction and continue
4290     * processing operations. A yield point will not automatically commit the
4291     * transaction, but only if there is another request waiting on the
4292     * database. Normally a sync adapter should insert a yield point at the
4293     * beginning of each raw contact operation sequence in the batch. See
4294     * {@link ContentProviderOperation.Builder#withYieldAllowed(boolean)}.
4295     * </p>
4296     * <h3>Operations</h3>
4297     * <dl>
4298     * <dt><b>Insert</b></dt>
4299     * <dd>
4300     * <p>
4301     * An individual data row can be inserted using the traditional
4302     * {@link ContentResolver#insert(Uri, ContentValues)} method. Multiple rows
4303     * should always be inserted as a batch.
4304     * </p>
4305     * <p>
4306     * An example of a traditional insert:
4307     * <pre>
4308     * ContentValues values = new ContentValues();
4309     * values.put(Data.RAW_CONTACT_ID, rawContactId);
4310     * values.put(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
4311     * values.put(Phone.NUMBER, "1-800-GOOG-411");
4312     * values.put(Phone.TYPE, Phone.TYPE_CUSTOM);
4313     * values.put(Phone.LABEL, "free directory assistance");
4314     * Uri dataUri = getContentResolver().insert(Data.CONTENT_URI, values);
4315     * </pre>
4316     * <p>
4317     * The same done using ContentProviderOperations:
4318     * <pre>
4319     * ArrayList&lt;ContentProviderOperation&gt; ops =
4320     *          new ArrayList&lt;ContentProviderOperation&gt;();
4321     *
4322     * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
4323     *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
4324     *          .withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
4325     *          .withValue(Phone.NUMBER, "1-800-GOOG-411")
4326     *          .withValue(Phone.TYPE, Phone.TYPE_CUSTOM)
4327     *          .withValue(Phone.LABEL, "free directory assistance")
4328     *          .build());
4329     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
4330     * </pre>
4331     * </p>
4332     * <dt><b>Update</b></dt>
4333     * <dd>
4334     * <p>
4335     * Just as with insert, update can be done incrementally or as a batch,
4336     * the batch mode being the preferred method:
4337     * <pre>
4338     * ArrayList&lt;ContentProviderOperation&gt; ops =
4339     *          new ArrayList&lt;ContentProviderOperation&gt;();
4340     *
4341     * ops.add(ContentProviderOperation.newUpdate(Data.CONTENT_URI)
4342     *          .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
4343     *          .withValue(Email.DATA, "somebody@android.com")
4344     *          .build());
4345     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
4346     * </pre>
4347     * </p>
4348     * </dd>
4349     * <dt><b>Delete</b></dt>
4350     * <dd>
4351     * <p>
4352     * Just as with insert and update, deletion can be done either using the
4353     * {@link ContentResolver#delete} method or using a ContentProviderOperation:
4354     * <pre>
4355     * ArrayList&lt;ContentProviderOperation&gt; ops =
4356     *          new ArrayList&lt;ContentProviderOperation&gt;();
4357     *
4358     * ops.add(ContentProviderOperation.newDelete(Data.CONTENT_URI)
4359     *          .withSelection(Data._ID + "=?", new String[]{String.valueOf(dataId)})
4360     *          .build());
4361     * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
4362     * </pre>
4363     * </p>
4364     * </dd>
4365     * <dt><b>Query</b></dt>
4366     * <dd>
4367     * <p>
4368     * <dl>
4369     * <dt>Finding all Data of a given type for a given contact</dt>
4370     * <dd>
4371     * <pre>
4372     * Cursor c = getContentResolver().query(Data.CONTENT_URI,
4373     *          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
4374     *          Data.CONTACT_ID + &quot;=?&quot; + " AND "
4375     *                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
4376     *          new String[] {String.valueOf(contactId)}, null);
4377     * </pre>
4378     * </p>
4379     * <p>
4380     * </dd>
4381     * <dt>Finding all Data of a given type for a given raw contact</dt>
4382     * <dd>
4383     * <pre>
4384     * Cursor c = getContentResolver().query(Data.CONTENT_URI,
4385     *          new String[] {Data._ID, Phone.NUMBER, Phone.TYPE, Phone.LABEL},
4386     *          Data.RAW_CONTACT_ID + &quot;=?&quot; + " AND "
4387     *                  + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
4388     *          new String[] {String.valueOf(rawContactId)}, null);
4389     * </pre>
4390     * </dd>
4391     * <dt>Finding all Data for a given raw contact</dt>
4392     * <dd>
4393     * Most sync adapters will want to read all data rows for a raw contact
4394     * along with the raw contact itself.  For that you should use the
4395     * {@link RawContactsEntity}. See also {@link RawContacts}.
4396     * </dd>
4397     * </dl>
4398     * </p>
4399     * </dd>
4400     * </dl>
4401     * <h2>Columns</h2>
4402     * <p>
4403     * Many columns are available via a {@link Data#CONTENT_URI} query.  For best performance you
4404     * should explicitly specify a projection to only those columns that you need.
4405     * </p>
4406     * <table class="jd-sumtable">
4407     * <tr>
4408     * <th colspan='4'>Data</th>
4409     * </tr>
4410     * <tr>
4411     * <td style="width: 7em;">long</td>
4412     * <td style="width: 20em;">{@link #_ID}</td>
4413     * <td style="width: 5em;">read-only</td>
4414     * <td>Row ID. Sync adapter should try to preserve row IDs during updates. In other words,
4415     * it would be a bad idea to delete and reinsert a data row. A sync adapter should
4416     * always do an update instead.</td>
4417     * </tr>
4418     * <tr>
4419     * <td>String</td>
4420     * <td>{@link #MIMETYPE}</td>
4421     * <td>read/write-once</td>
4422     * <td>
4423     * <p>The MIME type of the item represented by this row. Examples of common
4424     * MIME types are:
4425     * <ul>
4426     * <li>{@link CommonDataKinds.StructuredName StructuredName.CONTENT_ITEM_TYPE}</li>
4427     * <li>{@link CommonDataKinds.Phone Phone.CONTENT_ITEM_TYPE}</li>
4428     * <li>{@link CommonDataKinds.Email Email.CONTENT_ITEM_TYPE}</li>
4429     * <li>{@link CommonDataKinds.Photo Photo.CONTENT_ITEM_TYPE}</li>
4430     * <li>{@link CommonDataKinds.Organization Organization.CONTENT_ITEM_TYPE}</li>
4431     * <li>{@link CommonDataKinds.Im Im.CONTENT_ITEM_TYPE}</li>
4432     * <li>{@link CommonDataKinds.Nickname Nickname.CONTENT_ITEM_TYPE}</li>
4433     * <li>{@link CommonDataKinds.Note Note.CONTENT_ITEM_TYPE}</li>
4434     * <li>{@link CommonDataKinds.StructuredPostal StructuredPostal.CONTENT_ITEM_TYPE}</li>
4435     * <li>{@link CommonDataKinds.GroupMembership GroupMembership.CONTENT_ITEM_TYPE}</li>
4436     * <li>{@link CommonDataKinds.Website Website.CONTENT_ITEM_TYPE}</li>
4437     * <li>{@link CommonDataKinds.Event Event.CONTENT_ITEM_TYPE}</li>
4438     * <li>{@link CommonDataKinds.Relation Relation.CONTENT_ITEM_TYPE}</li>
4439     * <li>{@link CommonDataKinds.SipAddress SipAddress.CONTENT_ITEM_TYPE}</li>
4440     * </ul>
4441     * </p>
4442     * </td>
4443     * </tr>
4444     * <tr>
4445     * <td>long</td>
4446     * <td>{@link #RAW_CONTACT_ID}</td>
4447     * <td>read/write-once</td>
4448     * <td>The id of the row in the {@link RawContacts} table that this data belongs to.</td>
4449     * </tr>
4450     * <tr>
4451     * <td>int</td>
4452     * <td>{@link #IS_PRIMARY}</td>
4453     * <td>read/write</td>
4454     * <td>Whether this is the primary entry of its kind for the raw contact it belongs to.
4455     * "1" if true, "0" if false.
4456     * </td>
4457     * </tr>
4458     * <tr>
4459     * <td>int</td>
4460     * <td>{@link #IS_SUPER_PRIMARY}</td>
4461     * <td>read/write</td>
4462     * <td>Whether this is the primary entry of its kind for the aggregate
4463     * contact it belongs to. Any data record that is "super primary" must
4464     * also be "primary".  For example, the super-primary entry may be
4465     * interpreted as the default contact value of its kind (for example,
4466     * the default phone number to use for the contact).</td>
4467     * </tr>
4468     * <tr>
4469     * <td>int</td>
4470     * <td>{@link #DATA_VERSION}</td>
4471     * <td>read-only</td>
4472     * <td>The version of this data record. Whenever the data row changes
4473     * the version goes up. This value is monotonically increasing.</td>
4474     * </tr>
4475     * <tr>
4476     * <td>Any type</td>
4477     * <td>
4478     * {@link #DATA1}<br>
4479     * {@link #DATA2}<br>
4480     * {@link #DATA3}<br>
4481     * {@link #DATA4}<br>
4482     * {@link #DATA5}<br>
4483     * {@link #DATA6}<br>
4484     * {@link #DATA7}<br>
4485     * {@link #DATA8}<br>
4486     * {@link #DATA9}<br>
4487     * {@link #DATA10}<br>
4488     * {@link #DATA11}<br>
4489     * {@link #DATA12}<br>
4490     * {@link #DATA13}<br>
4491     * {@link #DATA14}<br>
4492     * {@link #DATA15}
4493     * </td>
4494     * <td>read/write</td>
4495     * <td>
4496     * <p>
4497     * Generic data columns.  The meaning of each column is determined by the
4498     * {@link #MIMETYPE}.  By convention, {@link #DATA15} is used for storing
4499     * BLOBs (binary data).
4500     * </p>
4501     * <p>
4502     * Data columns whose meaning is not explicitly defined for a given MIMETYPE
4503     * should not be used.  There is no guarantee that any sync adapter will
4504     * preserve them.  Sync adapters themselves should not use such columns either,
4505     * but should instead use {@link #SYNC1}-{@link #SYNC4}.
4506     * </p>
4507     * </td>
4508     * </tr>
4509     * <tr>
4510     * <td>Any type</td>
4511     * <td>
4512     * {@link #SYNC1}<br>
4513     * {@link #SYNC2}<br>
4514     * {@link #SYNC3}<br>
4515     * {@link #SYNC4}
4516     * </td>
4517     * <td>read/write</td>
4518     * <td>Generic columns for use by sync adapters. For example, a Photo row
4519     * may store the image URL in SYNC1, a status (not loaded, loading, loaded, error)
4520     * in SYNC2, server-side version number in SYNC3 and error code in SYNC4.</td>
4521     * </tr>
4522     * </table>
4523     *
4524     * <p>
4525     * Some columns from the most recent associated status update are also available
4526     * through an implicit join.
4527     * </p>
4528     * <table class="jd-sumtable">
4529     * <tr>
4530     * <th colspan='4'>Join with {@link StatusUpdates}</th>
4531     * </tr>
4532     * <tr>
4533     * <td style="width: 7em;">int</td>
4534     * <td style="width: 20em;">{@link #PRESENCE}</td>
4535     * <td style="width: 5em;">read-only</td>
4536     * <td>IM presence status linked to this data row. Compare with
4537     * {@link #CONTACT_PRESENCE}, which contains the contact's presence across
4538     * all IM rows. See {@link StatusUpdates} for individual status definitions.
4539     * The provider may choose not to store this value
4540     * in persistent storage. The expectation is that presence status will be
4541     * updated on a regular basis.
4542     * </td>
4543     * </tr>
4544     * <tr>
4545     * <td>String</td>
4546     * <td>{@link #STATUS}</td>
4547     * <td>read-only</td>
4548     * <td>Latest status update linked with this data row.</td>
4549     * </tr>
4550     * <tr>
4551     * <td>long</td>
4552     * <td>{@link #STATUS_TIMESTAMP}</td>
4553     * <td>read-only</td>
4554     * <td>The absolute time in milliseconds when the latest status was
4555     * inserted/updated for this data row.</td>
4556     * </tr>
4557     * <tr>
4558     * <td>String</td>
4559     * <td>{@link #STATUS_RES_PACKAGE}</td>
4560     * <td>read-only</td>
4561     * <td>The package containing resources for this status: label and icon.</td>
4562     * </tr>
4563     * <tr>
4564     * <td>long</td>
4565     * <td>{@link #STATUS_LABEL}</td>
4566     * <td>read-only</td>
4567     * <td>The resource ID of the label describing the source of status update linked
4568     * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
4569     * </tr>
4570     * <tr>
4571     * <td>long</td>
4572     * <td>{@link #STATUS_ICON}</td>
4573     * <td>read-only</td>
4574     * <td>The resource ID of the icon for the source of the status update linked
4575     * to this data row. This resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
4576     * </tr>
4577     * </table>
4578     *
4579     * <p>
4580     * Some columns from the associated raw contact are also available through an
4581     * implicit join.  The other columns are excluded as uninteresting in this
4582     * context.
4583     * </p>
4584     *
4585     * <table class="jd-sumtable">
4586     * <tr>
4587     * <th colspan='4'>Join with {@link ContactsContract.RawContacts}</th>
4588     * </tr>
4589     * <tr>
4590     * <td style="width: 7em;">long</td>
4591     * <td style="width: 20em;">{@link #CONTACT_ID}</td>
4592     * <td style="width: 5em;">read-only</td>
4593     * <td>The id of the row in the {@link Contacts} table that this data belongs
4594     * to.</td>
4595     * </tr>
4596     * <tr>
4597     * <td>int</td>
4598     * <td>{@link #AGGREGATION_MODE}</td>
4599     * <td>read-only</td>
4600     * <td>See {@link RawContacts}.</td>
4601     * </tr>
4602     * <tr>
4603     * <td>int</td>
4604     * <td>{@link #DELETED}</td>
4605     * <td>read-only</td>
4606     * <td>See {@link RawContacts}.</td>
4607     * </tr>
4608     * </table>
4609     *
4610     * <p>
4611     * The ID column for the associated aggregated contact table
4612     * {@link ContactsContract.Contacts} is available
4613     * via the implicit join to the {@link RawContacts} table, see above.
4614     * The remaining columns from this table are also
4615     * available, through an implicit join.  This
4616     * facilitates lookup by
4617     * the value of a single data element, such as the email address.
4618     * </p>
4619     *
4620     * <table class="jd-sumtable">
4621     * <tr>
4622     * <th colspan='4'>Join with {@link ContactsContract.Contacts}</th>
4623     * </tr>
4624     * <tr>
4625     * <td style="width: 7em;">String</td>
4626     * <td style="width: 20em;">{@link #LOOKUP_KEY}</td>
4627     * <td style="width: 5em;">read-only</td>
4628     * <td>See {@link ContactsContract.Contacts}</td>
4629     * </tr>
4630     * <tr>
4631     * <td>String</td>
4632     * <td>{@link #DISPLAY_NAME}</td>
4633     * <td>read-only</td>
4634     * <td>See {@link ContactsContract.Contacts}</td>
4635     * </tr>
4636     * <tr>
4637     * <td>long</td>
4638     * <td>{@link #PHOTO_ID}</td>
4639     * <td>read-only</td>
4640     * <td>See {@link ContactsContract.Contacts}.</td>
4641     * </tr>
4642     * <tr>
4643     * <td>int</td>
4644     * <td>{@link #IN_VISIBLE_GROUP}</td>
4645     * <td>read-only</td>
4646     * <td>See {@link ContactsContract.Contacts}.</td>
4647     * </tr>
4648     * <tr>
4649     * <td>int</td>
4650     * <td>{@link #HAS_PHONE_NUMBER}</td>
4651     * <td>read-only</td>
4652     * <td>See {@link ContactsContract.Contacts}.</td>
4653     * </tr>
4654     * <tr>
4655     * <td>int</td>
4656     * <td>{@link #TIMES_CONTACTED}</td>
4657     * <td>read-only</td>
4658     * <td>See {@link ContactsContract.Contacts}.</td>
4659     * </tr>
4660     * <tr>
4661     * <td>long</td>
4662     * <td>{@link #LAST_TIME_CONTACTED}</td>
4663     * <td>read-only</td>
4664     * <td>See {@link ContactsContract.Contacts}.</td>
4665     * </tr>
4666     * <tr>
4667     * <td>int</td>
4668     * <td>{@link #STARRED}</td>
4669     * <td>read-only</td>
4670     * <td>See {@link ContactsContract.Contacts}.</td>
4671     * </tr>
4672     * <tr>
4673     * <td>String</td>
4674     * <td>{@link #CUSTOM_RINGTONE}</td>
4675     * <td>read-only</td>
4676     * <td>See {@link ContactsContract.Contacts}.</td>
4677     * </tr>
4678     * <tr>
4679     * <td>int</td>
4680     * <td>{@link #SEND_TO_VOICEMAIL}</td>
4681     * <td>read-only</td>
4682     * <td>See {@link ContactsContract.Contacts}.</td>
4683     * </tr>
4684     * <tr>
4685     * <td>int</td>
4686     * <td>{@link #CONTACT_PRESENCE}</td>
4687     * <td>read-only</td>
4688     * <td>See {@link ContactsContract.Contacts}.</td>
4689     * </tr>
4690     * <tr>
4691     * <td>String</td>
4692     * <td>{@link #CONTACT_STATUS}</td>
4693     * <td>read-only</td>
4694     * <td>See {@link ContactsContract.Contacts}.</td>
4695     * </tr>
4696     * <tr>
4697     * <td>long</td>
4698     * <td>{@link #CONTACT_STATUS_TIMESTAMP}</td>
4699     * <td>read-only</td>
4700     * <td>See {@link ContactsContract.Contacts}.</td>
4701     * </tr>
4702     * <tr>
4703     * <td>String</td>
4704     * <td>{@link #CONTACT_STATUS_RES_PACKAGE}</td>
4705     * <td>read-only</td>
4706     * <td>See {@link ContactsContract.Contacts}.</td>
4707     * </tr>
4708     * <tr>
4709     * <td>long</td>
4710     * <td>{@link #CONTACT_STATUS_LABEL}</td>
4711     * <td>read-only</td>
4712     * <td>See {@link ContactsContract.Contacts}.</td>
4713     * </tr>
4714     * <tr>
4715     * <td>long</td>
4716     * <td>{@link #CONTACT_STATUS_ICON}</td>
4717     * <td>read-only</td>
4718     * <td>See {@link ContactsContract.Contacts}.</td>
4719     * </tr>
4720     * </table>
4721     */
4722    public final static class Data implements DataColumnsWithJoins, ContactCounts {
4723        /**
4724         * This utility class cannot be instantiated
4725         */
4726        private Data() {}
4727
4728        /**
4729         * The content:// style URI for this table, which requests a directory
4730         * of data rows matching the selection criteria.
4731         */
4732        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "data");
4733
4734        /**
4735        * The content:// style URI for this table in managed profile, which requests a directory
4736        * of data rows matching the selection criteria.
4737        *
4738        * @hide
4739        */
4740        static final Uri ENTERPRISE_CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI,
4741                "data_enterprise");
4742
4743        /**
4744         * A boolean parameter for {@link Data#CONTENT_URI}.
4745         * This specifies whether or not the returned data items should be filtered to show
4746         * data items belonging to visible contacts only.
4747         */
4748        public static final String VISIBLE_CONTACTS_ONLY = "visible_contacts_only";
4749
4750        /**
4751         * The MIME type of the results from {@link #CONTENT_URI}.
4752         */
4753        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/data";
4754
4755        /**
4756         * <p>
4757         * Build a {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}
4758         * style {@link Uri} for the parent {@link android.provider.ContactsContract.Contacts}
4759         * entry of the given {@link ContactsContract.Data} entry.
4760         * </p>
4761         * <p>
4762         * Returns the Uri for the contact in the first entry returned by
4763         * {@link ContentResolver#query(Uri, String[], String, String[], String)}
4764         * for the provided {@code dataUri}.  If the query returns null or empty
4765         * results, silently returns null.
4766         * </p>
4767         */
4768        public static Uri getContactLookupUri(ContentResolver resolver, Uri dataUri) {
4769            final Cursor cursor = resolver.query(dataUri, new String[] {
4770                    RawContacts.CONTACT_ID, Contacts.LOOKUP_KEY
4771            }, null, null, null);
4772
4773            Uri lookupUri = null;
4774            try {
4775                if (cursor != null && cursor.moveToFirst()) {
4776                    final long contactId = cursor.getLong(0);
4777                    final String lookupKey = cursor.getString(1);
4778                    return Contacts.getLookupUri(contactId, lookupKey);
4779                }
4780            } finally {
4781                if (cursor != null) cursor.close();
4782            }
4783            return lookupUri;
4784        }
4785    }
4786
4787    /**
4788     * <p>
4789     * Constants for the raw contacts entities table, which can be thought of as
4790     * an outer join of the raw_contacts table with the data table.  It is a strictly
4791     * read-only table.
4792     * </p>
4793     * <p>
4794     * If a raw contact has data rows, the RawContactsEntity cursor will contain
4795     * a one row for each data row. If the raw contact has no data rows, the
4796     * cursor will still contain one row with the raw contact-level information
4797     * and nulls for data columns.
4798     *
4799     * <pre>
4800     * Uri entityUri = ContentUris.withAppendedId(RawContactsEntity.CONTENT_URI, rawContactId);
4801     * Cursor c = getContentResolver().query(entityUri,
4802     *          new String[]{
4803     *              RawContactsEntity.SOURCE_ID,
4804     *              RawContactsEntity.DATA_ID,
4805     *              RawContactsEntity.MIMETYPE,
4806     *              RawContactsEntity.DATA1
4807     *          }, null, null, null);
4808     * try {
4809     *     while (c.moveToNext()) {
4810     *         String sourceId = c.getString(0);
4811     *         if (!c.isNull(1)) {
4812     *             String mimeType = c.getString(2);
4813     *             String data = c.getString(3);
4814     *             ...
4815     *         }
4816     *     }
4817     * } finally {
4818     *     c.close();
4819     * }
4820     * </pre>
4821     *
4822     * <h3>Columns</h3>
4823     * RawContactsEntity has a combination of RawContact and Data columns.
4824     *
4825     * <table class="jd-sumtable">
4826     * <tr>
4827     * <th colspan='4'>RawContacts</th>
4828     * </tr>
4829     * <tr>
4830     * <td style="width: 7em;">long</td>
4831     * <td style="width: 20em;">{@link #_ID}</td>
4832     * <td style="width: 5em;">read-only</td>
4833     * <td>Raw contact row ID. See {@link RawContacts}.</td>
4834     * </tr>
4835     * <tr>
4836     * <td>long</td>
4837     * <td>{@link #CONTACT_ID}</td>
4838     * <td>read-only</td>
4839     * <td>See {@link RawContacts}.</td>
4840     * </tr>
4841     * <tr>
4842     * <td>int</td>
4843     * <td>{@link #AGGREGATION_MODE}</td>
4844     * <td>read-only</td>
4845     * <td>See {@link RawContacts}.</td>
4846     * </tr>
4847     * <tr>
4848     * <td>int</td>
4849     * <td>{@link #DELETED}</td>
4850     * <td>read-only</td>
4851     * <td>See {@link RawContacts}.</td>
4852     * </tr>
4853     * </table>
4854     *
4855     * <table class="jd-sumtable">
4856     * <tr>
4857     * <th colspan='4'>Data</th>
4858     * </tr>
4859     * <tr>
4860     * <td style="width: 7em;">long</td>
4861     * <td style="width: 20em;">{@link #DATA_ID}</td>
4862     * <td style="width: 5em;">read-only</td>
4863     * <td>Data row ID. It will be null if the raw contact has no data rows.</td>
4864     * </tr>
4865     * <tr>
4866     * <td>String</td>
4867     * <td>{@link #MIMETYPE}</td>
4868     * <td>read-only</td>
4869     * <td>See {@link ContactsContract.Data}.</td>
4870     * </tr>
4871     * <tr>
4872     * <td>int</td>
4873     * <td>{@link #IS_PRIMARY}</td>
4874     * <td>read-only</td>
4875     * <td>See {@link ContactsContract.Data}.</td>
4876     * </tr>
4877     * <tr>
4878     * <td>int</td>
4879     * <td>{@link #IS_SUPER_PRIMARY}</td>
4880     * <td>read-only</td>
4881     * <td>See {@link ContactsContract.Data}.</td>
4882     * </tr>
4883     * <tr>
4884     * <td>int</td>
4885     * <td>{@link #DATA_VERSION}</td>
4886     * <td>read-only</td>
4887     * <td>See {@link ContactsContract.Data}.</td>
4888     * </tr>
4889     * <tr>
4890     * <td>Any type</td>
4891     * <td>
4892     * {@link #DATA1}<br>
4893     * {@link #DATA2}<br>
4894     * {@link #DATA3}<br>
4895     * {@link #DATA4}<br>
4896     * {@link #DATA5}<br>
4897     * {@link #DATA6}<br>
4898     * {@link #DATA7}<br>
4899     * {@link #DATA8}<br>
4900     * {@link #DATA9}<br>
4901     * {@link #DATA10}<br>
4902     * {@link #DATA11}<br>
4903     * {@link #DATA12}<br>
4904     * {@link #DATA13}<br>
4905     * {@link #DATA14}<br>
4906     * {@link #DATA15}
4907     * </td>
4908     * <td>read-only</td>
4909     * <td>See {@link ContactsContract.Data}.</td>
4910     * </tr>
4911     * <tr>
4912     * <td>Any type</td>
4913     * <td>
4914     * {@link #SYNC1}<br>
4915     * {@link #SYNC2}<br>
4916     * {@link #SYNC3}<br>
4917     * {@link #SYNC4}
4918     * </td>
4919     * <td>read-only</td>
4920     * <td>See {@link ContactsContract.Data}.</td>
4921     * </tr>
4922     * </table>
4923     */
4924    public final static class RawContactsEntity
4925            implements BaseColumns, DataColumns, RawContactsColumns {
4926        /**
4927         * This utility class cannot be instantiated
4928         */
4929        private RawContactsEntity() {}
4930
4931        /**
4932         * The content:// style URI for this table
4933         */
4934        public static final Uri CONTENT_URI =
4935                Uri.withAppendedPath(AUTHORITY_URI, "raw_contact_entities");
4936
4937        /**
4938        * The content:// style URI for this table in corp profile
4939        *
4940        * @hide
4941        */
4942        public static final Uri CORP_CONTENT_URI =
4943                Uri.withAppendedPath(AUTHORITY_URI, "raw_contact_entities_corp");
4944
4945        /**
4946         * The content:// style URI for this table, specific to the user's profile.
4947         */
4948        public static final Uri PROFILE_CONTENT_URI =
4949                Uri.withAppendedPath(Profile.CONTENT_URI, "raw_contact_entities");
4950
4951        /**
4952         * The MIME type of {@link #CONTENT_URI} providing a directory of raw contact entities.
4953         */
4954        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/raw_contact_entity";
4955
4956        /**
4957         * If {@link #FOR_EXPORT_ONLY} is explicitly set to "1", returned Cursor toward
4958         * Data.CONTENT_URI contains only exportable data.
4959         *
4960         * This flag is useful (currently) only for vCard exporter in Contacts app, which
4961         * needs to exclude "un-exportable" data from available data to export, while
4962         * Contacts app itself has priviledge to access all data including "un-expotable"
4963         * ones and providers return all of them regardless of the callers' intention.
4964         * <P>Type: INTEGER</p>
4965         *
4966         * @hide Maybe available only in Eclair and not really ready for public use.
4967         * TODO: remove, or implement this feature completely. As of now (Eclair),
4968         * we only use this flag in queryEntities(), not query().
4969         */
4970        public static final String FOR_EXPORT_ONLY = "for_export_only";
4971
4972        /**
4973         * The ID of the data column. The value will be null if this raw contact has no data rows.
4974         * <P>Type: INTEGER</P>
4975         */
4976        public static final String DATA_ID = "data_id";
4977    }
4978
4979    /**
4980     * @see PhoneLookup
4981     */
4982    protected interface PhoneLookupColumns {
4983        /**
4984         * The phone number as the user entered it.
4985         * <P>Type: TEXT</P>
4986         */
4987        public static final String NUMBER = "number";
4988
4989        /**
4990         * The type of phone number, for example Home or Work.
4991         * <P>Type: INTEGER</P>
4992         */
4993        public static final String TYPE = "type";
4994
4995        /**
4996         * The user defined label for the phone number.
4997         * <P>Type: TEXT</P>
4998         */
4999        public static final String LABEL = "label";
5000
5001        /**
5002         * The phone number's E164 representation.
5003         * <P>Type: TEXT</P>
5004         */
5005        public static final String NORMALIZED_NUMBER = "normalized_number";
5006    }
5007
5008    /**
5009     * A table that represents the result of looking up a phone number, for
5010     * example for caller ID. To perform a lookup you must append the number you
5011     * want to find to {@link #CONTENT_FILTER_URI}.  This query is highly
5012     * optimized.
5013     * <pre>
5014     * Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
5015     * resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...
5016     * </pre>
5017     *
5018     * <h3>Columns</h3>
5019     *
5020     * <table class="jd-sumtable">
5021     * <tr>
5022     * <th colspan='4'>PhoneLookup</th>
5023     * </tr>
5024     * <tr>
5025     * <td>String</td>
5026     * <td>{@link #NUMBER}</td>
5027     * <td>read-only</td>
5028     * <td>Phone number.</td>
5029     * </tr>
5030     * <tr>
5031     * <td>String</td>
5032     * <td>{@link #TYPE}</td>
5033     * <td>read-only</td>
5034     * <td>Phone number type. See {@link CommonDataKinds.Phone}.</td>
5035     * </tr>
5036     * <tr>
5037     * <td>String</td>
5038     * <td>{@link #LABEL}</td>
5039     * <td>read-only</td>
5040     * <td>Custom label for the phone number. See {@link CommonDataKinds.Phone}.</td>
5041     * </tr>
5042     * </table>
5043     * <p>
5044     * Columns from the Contacts table are also available through a join.
5045     * </p>
5046     * <table class="jd-sumtable">
5047     * <tr>
5048     * <th colspan='4'>Join with {@link Contacts}</th>
5049     * </tr>
5050     * <tr>
5051     * <td>long</td>
5052     * <td>{@link #_ID}</td>
5053     * <td>read-only</td>
5054     * <td>Contact ID.</td>
5055     * </tr>
5056     * <tr>
5057     * <td>String</td>
5058     * <td>{@link #LOOKUP_KEY}</td>
5059     * <td>read-only</td>
5060     * <td>See {@link ContactsContract.Contacts}</td>
5061     * </tr>
5062     * <tr>
5063     * <td>String</td>
5064     * <td>{@link #DISPLAY_NAME}</td>
5065     * <td>read-only</td>
5066     * <td>See {@link ContactsContract.Contacts}</td>
5067     * </tr>
5068     * <tr>
5069     * <td>long</td>
5070     * <td>{@link #PHOTO_ID}</td>
5071     * <td>read-only</td>
5072     * <td>See {@link ContactsContract.Contacts}.</td>
5073     * </tr>
5074     * <tr>
5075     * <td>int</td>
5076     * <td>{@link #IN_VISIBLE_GROUP}</td>
5077     * <td>read-only</td>
5078     * <td>See {@link ContactsContract.Contacts}.</td>
5079     * </tr>
5080     * <tr>
5081     * <td>int</td>
5082     * <td>{@link #HAS_PHONE_NUMBER}</td>
5083     * <td>read-only</td>
5084     * <td>See {@link ContactsContract.Contacts}.</td>
5085     * </tr>
5086     * <tr>
5087     * <td>int</td>
5088     * <td>{@link #TIMES_CONTACTED}</td>
5089     * <td>read-only</td>
5090     * <td>See {@link ContactsContract.Contacts}.</td>
5091     * </tr>
5092     * <tr>
5093     * <td>long</td>
5094     * <td>{@link #LAST_TIME_CONTACTED}</td>
5095     * <td>read-only</td>
5096     * <td>See {@link ContactsContract.Contacts}.</td>
5097     * </tr>
5098     * <tr>
5099     * <td>int</td>
5100     * <td>{@link #STARRED}</td>
5101     * <td>read-only</td>
5102     * <td>See {@link ContactsContract.Contacts}.</td>
5103     * </tr>
5104     * <tr>
5105     * <td>String</td>
5106     * <td>{@link #CUSTOM_RINGTONE}</td>
5107     * <td>read-only</td>
5108     * <td>See {@link ContactsContract.Contacts}.</td>
5109     * </tr>
5110     * <tr>
5111     * <td>int</td>
5112     * <td>{@link #SEND_TO_VOICEMAIL}</td>
5113     * <td>read-only</td>
5114     * <td>See {@link ContactsContract.Contacts}.</td>
5115     * </tr>
5116     * </table>
5117     */
5118    public static final class PhoneLookup implements BaseColumns, PhoneLookupColumns,
5119            ContactsColumns, ContactOptionsColumns {
5120        /**
5121         * This utility class cannot be instantiated
5122         */
5123        private PhoneLookup() {}
5124
5125        /**
5126         * The content:// style URI for this table. Append the phone number you want to lookup
5127         * to this URI and query it to perform a lookup. For example:
5128         * <pre>
5129         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
5130         *         Uri.encode(phoneNumber));
5131         * </pre>
5132         */
5133        public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
5134                "phone_lookup");
5135
5136        /**
5137         * <p>URI used for the "enterprise caller-id".</p>
5138         *
5139         * <p>
5140         * It supports the same semantics as {@link #CONTENT_FILTER_URI} and returns the same
5141         * columns.  If the device has no corp profile that is linked to the current profile, it
5142         * behaves in the exact same way as {@link #CONTENT_FILTER_URI}.  If there is a corp profile
5143         * linked to the current profile, it first queries against the personal contact database,
5144         * and if no matching contacts are found there, then queries against the
5145         * corp contacts database.
5146         * </p>
5147         * <p>
5148         * If a result is from the corp profile, it makes the following changes to the data:
5149         * <ul>
5150         *     <li>
5151         *     {@link #PHOTO_THUMBNAIL_URI} and {@link #PHOTO_URI} will be rewritten to special
5152         *     URIs.  Use {@link ContentResolver#openAssetFileDescriptor} or its siblings to
5153         *     load pictures from them.
5154         *     {@link #PHOTO_ID} and {@link #PHOTO_FILE_ID} will be set to null.  Do not use them.
5155         *     </li>
5156         *     <li>
5157         *     Corp contacts will get artificial {@link #_ID}s.  In order to tell whether a contact
5158         *     is from the corp profile, use
5159         *     {@link ContactsContract.Contacts#isEnterpriseContactId(long)}.
5160         *     </li>
5161         *     <li>
5162         *     Corp contacts will get artificial {@link #LOOKUP_KEY}s too.
5163         *     </li>
5164         * </ul>
5165         * <p>
5166         * A contact lookup URL built by
5167         * {@link ContactsContract.Contacts#getLookupUri(long, String)}
5168         * with an {@link #_ID} and a {@link #LOOKUP_KEY} returned by this API can be passed to
5169         * {@link ContactsContract.QuickContact#showQuickContact} even if a contact is from the
5170         * corp profile.
5171         * </p>
5172         *
5173         * <pre>
5174         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
5175         *         Uri.encode(phoneNumber));
5176         * </pre>
5177         */
5178        public static final Uri ENTERPRISE_CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
5179                "phone_lookup_enterprise");
5180
5181        /**
5182         * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows.
5183         *
5184         * @hide
5185         */
5186        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup";
5187
5188        /**
5189         * If this boolean parameter is set to true, then the appended query is treated as a
5190         * SIP address and the lookup will be performed against SIP addresses in the user's
5191         * contacts.
5192         */
5193        public static final String QUERY_PARAMETER_SIP_ADDRESS = "sip";
5194    }
5195
5196    /**
5197     * Additional data mixed in with {@link StatusColumns} to link
5198     * back to specific {@link ContactsContract.Data#_ID} entries.
5199     *
5200     * @see StatusUpdates
5201     */
5202    protected interface PresenceColumns {
5203
5204        /**
5205         * Reference to the {@link Data#_ID} entry that owns this presence.
5206         * <P>Type: INTEGER</P>
5207         */
5208        public static final String DATA_ID = "presence_data_id";
5209
5210        /**
5211         * See {@link CommonDataKinds.Im} for a list of defined protocol constants.
5212         * <p>Type: NUMBER</p>
5213         */
5214        public static final String PROTOCOL = "protocol";
5215
5216        /**
5217         * Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
5218         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
5219         * omitted if {@link #PROTOCOL} value is not
5220         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.
5221         *
5222         * <p>Type: NUMBER</p>
5223         */
5224        public static final String CUSTOM_PROTOCOL = "custom_protocol";
5225
5226        /**
5227         * The IM handle the presence item is for. The handle is scoped to
5228         * {@link #PROTOCOL}.
5229         * <P>Type: TEXT</P>
5230         */
5231        public static final String IM_HANDLE = "im_handle";
5232
5233        /**
5234         * The IM account for the local user that the presence data came from.
5235         * <P>Type: TEXT</P>
5236         */
5237        public static final String IM_ACCOUNT = "im_account";
5238    }
5239
5240    /**
5241     * <p>
5242     * A status update is linked to a {@link ContactsContract.Data} row and captures
5243     * the user's latest status update via the corresponding source, e.g.
5244     * "Having lunch" via "Google Talk".
5245     * </p>
5246     * <p>
5247     * There are two ways a status update can be inserted: by explicitly linking
5248     * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row
5249     * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
5250     * {@link #IM_HANDLE}.  There is no difference between insert and update, you can use
5251     * either.
5252     * </p>
5253     * <p>
5254     * Inserting or updating a status update for the user's profile requires either using
5255     * the {@link #DATA_ID} to identify the data row to attach the update to, or
5256     * {@link StatusUpdates#PROFILE_CONTENT_URI} to ensure that the change is scoped to the
5257     * profile.
5258     * </p>
5259     * <p>
5260     * You cannot use {@link ContentResolver#update} to change a status, but
5261     * {@link ContentResolver#insert} will replace the latests status if it already
5262     * exists.
5263     * </p>
5264     * <p>
5265     * Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses
5266     * for multiple contacts at once.
5267     * </p>
5268     *
5269     * <h3>Columns</h3>
5270     * <table class="jd-sumtable">
5271     * <tr>
5272     * <th colspan='4'>StatusUpdates</th>
5273     * </tr>
5274     * <tr>
5275     * <td>long</td>
5276     * <td>{@link #DATA_ID}</td>
5277     * <td>read/write</td>
5278     * <td>Reference to the {@link Data#_ID} entry that owns this presence. If this
5279     * field is <i>not</i> specified, the provider will attempt to find a data row
5280     * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
5281     * {@link #IM_HANDLE} columns.
5282     * </td>
5283     * </tr>
5284     * <tr>
5285     * <td>long</td>
5286     * <td>{@link #PROTOCOL}</td>
5287     * <td>read/write</td>
5288     * <td>See {@link CommonDataKinds.Im} for a list of defined protocol constants.</td>
5289     * </tr>
5290     * <tr>
5291     * <td>String</td>
5292     * <td>{@link #CUSTOM_PROTOCOL}</td>
5293     * <td>read/write</td>
5294     * <td>Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
5295     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
5296     * omitted if {@link #PROTOCOL} value is not
5297     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.</td>
5298     * </tr>
5299     * <tr>
5300     * <td>String</td>
5301     * <td>{@link #IM_HANDLE}</td>
5302     * <td>read/write</td>
5303     * <td> The IM handle the presence item is for. The handle is scoped to
5304     * {@link #PROTOCOL}.</td>
5305     * </tr>
5306     * <tr>
5307     * <td>String</td>
5308     * <td>{@link #IM_ACCOUNT}</td>
5309     * <td>read/write</td>
5310     * <td>The IM account for the local user that the presence data came from.</td>
5311     * </tr>
5312     * <tr>
5313     * <td>int</td>
5314     * <td>{@link #PRESENCE}</td>
5315     * <td>read/write</td>
5316     * <td>Contact IM presence status. The allowed values are:
5317     * <p>
5318     * <ul>
5319     * <li>{@link #OFFLINE}</li>
5320     * <li>{@link #INVISIBLE}</li>
5321     * <li>{@link #AWAY}</li>
5322     * <li>{@link #IDLE}</li>
5323     * <li>{@link #DO_NOT_DISTURB}</li>
5324     * <li>{@link #AVAILABLE}</li>
5325     * </ul>
5326     * </p>
5327     * <p>
5328     * Since presence status is inherently volatile, the content provider
5329     * may choose not to store this field in long-term storage.
5330     * </p>
5331     * </td>
5332     * </tr>
5333     * <tr>
5334     * <td>int</td>
5335     * <td>{@link #CHAT_CAPABILITY}</td>
5336     * <td>read/write</td>
5337     * <td>Contact IM chat compatibility value. The allowed values combinations of the following
5338     * flags. If None of these flags is set, the device can only do text messaging.
5339     * <p>
5340     * <ul>
5341     * <li>{@link #CAPABILITY_HAS_VIDEO}</li>
5342     * <li>{@link #CAPABILITY_HAS_VOICE}</li>
5343     * <li>{@link #CAPABILITY_HAS_CAMERA}</li>
5344     * </ul>
5345     * </p>
5346     * <p>
5347     * Since chat compatibility is inherently volatile as the contact's availability moves from
5348     * one device to another, the content provider may choose not to store this field in long-term
5349     * storage.
5350     * </p>
5351     * </td>
5352     * </tr>
5353     * <tr>
5354     * <td>String</td>
5355     * <td>{@link #STATUS}</td>
5356     * <td>read/write</td>
5357     * <td>Contact's latest status update, e.g. "having toast for breakfast"</td>
5358     * </tr>
5359     * <tr>
5360     * <td>long</td>
5361     * <td>{@link #STATUS_TIMESTAMP}</td>
5362     * <td>read/write</td>
5363     * <td>The absolute time in milliseconds when the status was
5364     * entered by the user. If this value is not provided, the provider will follow
5365     * this logic: if there was no prior status update, the value will be left as null.
5366     * If there was a prior status update, the provider will default this field
5367     * to the current time.</td>
5368     * </tr>
5369     * <tr>
5370     * <td>String</td>
5371     * <td>{@link #STATUS_RES_PACKAGE}</td>
5372     * <td>read/write</td>
5373     * <td> The package containing resources for this status: label and icon.</td>
5374     * </tr>
5375     * <tr>
5376     * <td>long</td>
5377     * <td>{@link #STATUS_LABEL}</td>
5378     * <td>read/write</td>
5379     * <td>The resource ID of the label describing the source of contact status,
5380     * e.g. "Google Talk". This resource is scoped by the
5381     * {@link #STATUS_RES_PACKAGE}.</td>
5382     * </tr>
5383     * <tr>
5384     * <td>long</td>
5385     * <td>{@link #STATUS_ICON}</td>
5386     * <td>read/write</td>
5387     * <td>The resource ID of the icon for the source of contact status. This
5388     * resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
5389     * </tr>
5390     * </table>
5391     */
5392    public static class StatusUpdates implements StatusColumns, PresenceColumns {
5393
5394        /**
5395         * This utility class cannot be instantiated
5396         */
5397        private StatusUpdates() {}
5398
5399        /**
5400         * The content:// style URI for this table
5401         */
5402        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates");
5403
5404        /**
5405         * The content:// style URI for this table, specific to the user's profile.
5406         */
5407        public static final Uri PROFILE_CONTENT_URI =
5408                Uri.withAppendedPath(Profile.CONTENT_URI, "status_updates");
5409
5410        /**
5411         * Gets the resource ID for the proper presence icon.
5412         *
5413         * @param status the status to get the icon for
5414         * @return the resource ID for the proper presence icon
5415         */
5416        public static final int getPresenceIconResourceId(int status) {
5417            switch (status) {
5418                case AVAILABLE:
5419                    return android.R.drawable.presence_online;
5420                case IDLE:
5421                case AWAY:
5422                    return android.R.drawable.presence_away;
5423                case DO_NOT_DISTURB:
5424                    return android.R.drawable.presence_busy;
5425                case INVISIBLE:
5426                    return android.R.drawable.presence_invisible;
5427                case OFFLINE:
5428                default:
5429                    return android.R.drawable.presence_offline;
5430            }
5431        }
5432
5433        /**
5434         * Returns the precedence of the status code the higher number being the higher precedence.
5435         *
5436         * @param status The status code.
5437         * @return An integer representing the precedence, 0 being the lowest.
5438         */
5439        public static final int getPresencePrecedence(int status) {
5440            // Keep this function here incase we want to enforce a different precedence than the
5441            // natural order of the status constants.
5442            return status;
5443        }
5444
5445        /**
5446         * The MIME type of {@link #CONTENT_URI} providing a directory of
5447         * status update details.
5448         */
5449        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/status-update";
5450
5451        /**
5452         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
5453         * status update detail.
5454         */
5455        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update";
5456    }
5457
5458    /**
5459     * @deprecated This old name was never meant to be made public. Do not use.
5460     */
5461    @Deprecated
5462    public static final class Presence extends StatusUpdates {
5463
5464    }
5465
5466    /**
5467     * Additional column returned by
5468     * {@link ContactsContract.Contacts#CONTENT_FILTER_URI Contacts.CONTENT_FILTER_URI} explaining
5469     * why the filter matched the contact. This column will contain extracts from the contact's
5470     * constituent {@link Data Data} items, formatted in a way that indicates the section of the
5471     * snippet that matched the filter.
5472     *
5473     * <p>
5474     * The following example searches for all contacts that match the query "presi" and requests
5475     * the snippet column as well.
5476     * <pre>
5477     * Builder builder = Contacts.CONTENT_FILTER_URI.buildUpon();
5478     * builder.appendPath("presi");
5479     * // Defer snippeting to the client side if possible, for performance reasons.
5480     * builder.appendQueryParameter(SearchSnippets.DEFERRED_SNIPPETING_KEY,"1");
5481     *
5482     * Cursor cursor = getContentResolver().query(builder.build());
5483     *
5484     * Bundle extras = cursor.getExtras();
5485     * if (extras.getBoolean(ContactsContract.DEFERRED_SNIPPETING)) {
5486     *     // Do our own snippet formatting.
5487     *     // For a contact with the email address (president@organization.com), the snippet
5488     *     // column will contain the string "president@organization.com".
5489     * } else {
5490     *     // The snippet has already been pre-formatted, we can display it as is.
5491     *     // For a contact with the email address (president@organization.com), the snippet
5492     *     // column will contain the string "[presi]dent@organization.com".
5493     * }
5494     * </pre>
5495     * </p>
5496     */
5497    public static class SearchSnippets {
5498
5499        /**
5500         * The search snippet constructed by SQLite snippeting functionality.
5501         * <p>
5502         * The snippet may contain (parts of) several data elements belonging to the contact,
5503         * with the matching parts optionally surrounded by special characters that indicate the
5504         * start and end of matching text.
5505         *
5506         * For example, if a contact has an address "123 Main Street", using a filter "mai" would
5507         * return the formatted snippet "123 [Mai]n street".
5508         *
5509         * @see <a href="http://www.sqlite.org/fts3.html#snippet">
5510         *         http://www.sqlite.org/fts3.html#snippet</a>
5511         */
5512        public static final String SNIPPET = "snippet";
5513
5514        /**
5515         * Comma-separated parameters for the generation of the snippet:
5516         * <ul>
5517         * <li>The "start match" text. Default is '['</li>
5518         * <li>The "end match" text. Default is ']'</li>
5519         * <li>The "ellipsis" text. Default is "..."</li>
5520         * <li>Maximum number of tokens to include in the snippet. Can be either
5521         * a positive or a negative number: A positive number indicates how many
5522         * tokens can be returned in total. A negative number indicates how many
5523         * tokens can be returned per occurrence of the search terms.</li>
5524         * </ul>
5525         *
5526         * @hide
5527         */
5528        public static final String SNIPPET_ARGS_PARAM_KEY = "snippet_args";
5529
5530        /**
5531         * The key to ask the provider to defer the formatting of the snippet to the client if
5532         * possible, for performance reasons.
5533         * A value of 1 indicates true, 0 indicates false. False is the default.
5534         * When a cursor is returned to the client, it should check for an extra with the name
5535         * {@link ContactsContract#DEFERRED_SNIPPETING} in the cursor. If it exists, the client
5536         * should do its own formatting of the snippet. If it doesn't exist, the snippet column
5537         * in the cursor should already contain a formatted snippet.
5538         */
5539        public static final String DEFERRED_SNIPPETING_KEY = "deferred_snippeting";
5540    }
5541
5542    /**
5543     * Container for definitions of common data types stored in the {@link ContactsContract.Data}
5544     * table.
5545     */
5546    public static final class CommonDataKinds {
5547        /**
5548         * This utility class cannot be instantiated
5549         */
5550        private CommonDataKinds() {}
5551
5552        /**
5553         * The {@link Data#RES_PACKAGE} value for common data that should be
5554         * shown using a default style.
5555         *
5556         * @hide RES_PACKAGE is hidden
5557         */
5558        public static final String PACKAGE_COMMON = "common";
5559
5560        /**
5561         * The base types that all "Typed" data kinds support.
5562         */
5563        public interface BaseTypes {
5564            /**
5565             * A custom type. The custom label should be supplied by user.
5566             */
5567            public static int TYPE_CUSTOM = 0;
5568        }
5569
5570        /**
5571         * Columns common across the specific types.
5572         */
5573        protected interface CommonColumns extends BaseTypes {
5574            /**
5575             * The data for the contact method.
5576             * <P>Type: TEXT</P>
5577             */
5578            public static final String DATA = DataColumns.DATA1;
5579
5580            /**
5581             * The type of data, for example Home or Work.
5582             * <P>Type: INTEGER</P>
5583             */
5584            public static final String TYPE = DataColumns.DATA2;
5585
5586            /**
5587             * The user defined label for the the contact method.
5588             * <P>Type: TEXT</P>
5589             */
5590            public static final String LABEL = DataColumns.DATA3;
5591        }
5592
5593        /**
5594         * A data kind representing the contact's proper name. You can use all
5595         * columns defined for {@link ContactsContract.Data} as well as the following aliases.
5596         *
5597         * <h2>Column aliases</h2>
5598         * <table class="jd-sumtable">
5599         * <tr>
5600         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
5601         * </tr>
5602         * <tr>
5603         * <td>String</td>
5604         * <td>{@link #DISPLAY_NAME}</td>
5605         * <td>{@link #DATA1}</td>
5606         * <td></td>
5607         * </tr>
5608         * <tr>
5609         * <td>String</td>
5610         * <td>{@link #GIVEN_NAME}</td>
5611         * <td>{@link #DATA2}</td>
5612         * <td></td>
5613         * </tr>
5614         * <tr>
5615         * <td>String</td>
5616         * <td>{@link #FAMILY_NAME}</td>
5617         * <td>{@link #DATA3}</td>
5618         * <td></td>
5619         * </tr>
5620         * <tr>
5621         * <td>String</td>
5622         * <td>{@link #PREFIX}</td>
5623         * <td>{@link #DATA4}</td>
5624         * <td>Common prefixes in English names are "Mr", "Ms", "Dr" etc.</td>
5625         * </tr>
5626         * <tr>
5627         * <td>String</td>
5628         * <td>{@link #MIDDLE_NAME}</td>
5629         * <td>{@link #DATA5}</td>
5630         * <td></td>
5631         * </tr>
5632         * <tr>
5633         * <td>String</td>
5634         * <td>{@link #SUFFIX}</td>
5635         * <td>{@link #DATA6}</td>
5636         * <td>Common suffixes in English names are "Sr", "Jr", "III" etc.</td>
5637         * </tr>
5638         * <tr>
5639         * <td>String</td>
5640         * <td>{@link #PHONETIC_GIVEN_NAME}</td>
5641         * <td>{@link #DATA7}</td>
5642         * <td>Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana</td>
5643         * </tr>
5644         * <tr>
5645         * <td>String</td>
5646         * <td>{@link #PHONETIC_MIDDLE_NAME}</td>
5647         * <td>{@link #DATA8}</td>
5648         * <td></td>
5649         * </tr>
5650         * <tr>
5651         * <td>String</td>
5652         * <td>{@link #PHONETIC_FAMILY_NAME}</td>
5653         * <td>{@link #DATA9}</td>
5654         * <td></td>
5655         * </tr>
5656         * </table>
5657         */
5658        public static final class StructuredName implements DataColumnsWithJoins, ContactCounts {
5659            /**
5660             * This utility class cannot be instantiated
5661             */
5662            private StructuredName() {}
5663
5664            /** MIME type used when storing this in data table. */
5665            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
5666
5667            /**
5668             * The name that should be used to display the contact.
5669             * <i>Unstructured component of the name should be consistent with
5670             * its structured representation.</i>
5671             * <p>
5672             * Type: TEXT
5673             */
5674            public static final String DISPLAY_NAME = DATA1;
5675
5676            /**
5677             * The given name for the contact.
5678             * <P>Type: TEXT</P>
5679             */
5680            public static final String GIVEN_NAME = DATA2;
5681
5682            /**
5683             * The family name for the contact.
5684             * <P>Type: TEXT</P>
5685             */
5686            public static final String FAMILY_NAME = DATA3;
5687
5688            /**
5689             * The contact's honorific prefix, e.g. "Sir"
5690             * <P>Type: TEXT</P>
5691             */
5692            public static final String PREFIX = DATA4;
5693
5694            /**
5695             * The contact's middle name
5696             * <P>Type: TEXT</P>
5697             */
5698            public static final String MIDDLE_NAME = DATA5;
5699
5700            /**
5701             * The contact's honorific suffix, e.g. "Jr"
5702             */
5703            public static final String SUFFIX = DATA6;
5704
5705            /**
5706             * The phonetic version of the given name for the contact.
5707             * <P>Type: TEXT</P>
5708             */
5709            public static final String PHONETIC_GIVEN_NAME = DATA7;
5710
5711            /**
5712             * The phonetic version of the additional name for the contact.
5713             * <P>Type: TEXT</P>
5714             */
5715            public static final String PHONETIC_MIDDLE_NAME = DATA8;
5716
5717            /**
5718             * The phonetic version of the family name for the contact.
5719             * <P>Type: TEXT</P>
5720             */
5721            public static final String PHONETIC_FAMILY_NAME = DATA9;
5722
5723            /**
5724             * The style used for combining given/middle/family name into a full name.
5725             * See {@link ContactsContract.FullNameStyle}.
5726             */
5727            public static final String FULL_NAME_STYLE = DATA10;
5728
5729            /**
5730             * The alphabet used for capturing the phonetic name.
5731             * See ContactsContract.PhoneticNameStyle.
5732             */
5733            public static final String PHONETIC_NAME_STYLE = DATA11;
5734        }
5735
5736        /**
5737         * <p>A data kind representing the contact's nickname. For example, for
5738         * Bob Parr ("Mr. Incredible"):
5739         * <pre>
5740         * ArrayList&lt;ContentProviderOperation&gt; ops =
5741         *          new ArrayList&lt;ContentProviderOperation&gt;();
5742         *
5743         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
5744         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
5745         *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
5746         *          .withValue(StructuredName.DISPLAY_NAME, &quot;Bob Parr&quot;)
5747         *          .build());
5748         *
5749         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
5750         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
5751         *          .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
5752         *          .withValue(Nickname.NAME, "Mr. Incredible")
5753         *          .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM)
5754         *          .withValue(Nickname.LABEL, "Superhero")
5755         *          .build());
5756         *
5757         * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
5758         * </pre>
5759         * </p>
5760         * <p>
5761         * You can use all columns defined for {@link ContactsContract.Data} as well as the
5762         * following aliases.
5763         * </p>
5764         *
5765         * <h2>Column aliases</h2>
5766         * <table class="jd-sumtable">
5767         * <tr>
5768         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
5769         * </tr>
5770         * <tr>
5771         * <td>String</td>
5772         * <td>{@link #NAME}</td>
5773         * <td>{@link #DATA1}</td>
5774         * <td></td>
5775         * </tr>
5776         * <tr>
5777         * <td>int</td>
5778         * <td>{@link #TYPE}</td>
5779         * <td>{@link #DATA2}</td>
5780         * <td>
5781         * Allowed values are:
5782         * <p>
5783         * <ul>
5784         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5785         * <li>{@link #TYPE_DEFAULT}</li>
5786         * <li>{@link #TYPE_OTHER_NAME}</li>
5787         * <li>{@link #TYPE_MAIDEN_NAME}</li>
5788         * <li>{@link #TYPE_SHORT_NAME}</li>
5789         * <li>{@link #TYPE_INITIALS}</li>
5790         * </ul>
5791         * </p>
5792         * </td>
5793         * </tr>
5794         * <tr>
5795         * <td>String</td>
5796         * <td>{@link #LABEL}</td>
5797         * <td>{@link #DATA3}</td>
5798         * <td></td>
5799         * </tr>
5800         * </table>
5801         */
5802        public static final class Nickname implements DataColumnsWithJoins, CommonColumns,
5803                ContactCounts{
5804            /**
5805             * This utility class cannot be instantiated
5806             */
5807            private Nickname() {}
5808
5809            /** MIME type used when storing this in data table. */
5810            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
5811
5812            public static final int TYPE_DEFAULT = 1;
5813            public static final int TYPE_OTHER_NAME = 2;
5814            public static final int TYPE_MAIDEN_NAME = 3;
5815            /** @deprecated Use TYPE_MAIDEN_NAME instead. */
5816            @Deprecated
5817            public static final int TYPE_MAINDEN_NAME = 3;
5818            public static final int TYPE_SHORT_NAME = 4;
5819            public static final int TYPE_INITIALS = 5;
5820
5821            /**
5822             * The name itself
5823             */
5824            public static final String NAME = DATA;
5825        }
5826
5827        /**
5828         * <p>
5829         * A data kind representing a telephone number.
5830         * </p>
5831         * <p>
5832         * You can use all columns defined for {@link ContactsContract.Data} as
5833         * well as the following aliases.
5834         * </p>
5835         * <h2>Column aliases</h2>
5836         * <table class="jd-sumtable">
5837         * <tr>
5838         * <th>Type</th>
5839         * <th>Alias</th><th colspan='2'>Data column</th>
5840         * </tr>
5841         * <tr>
5842         * <td>String</td>
5843         * <td>{@link #NUMBER}</td>
5844         * <td>{@link #DATA1}</td>
5845         * <td></td>
5846         * </tr>
5847         * <tr>
5848         * <td>int</td>
5849         * <td>{@link #TYPE}</td>
5850         * <td>{@link #DATA2}</td>
5851         * <td>Allowed values are:
5852         * <p>
5853         * <ul>
5854         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5855         * <li>{@link #TYPE_HOME}</li>
5856         * <li>{@link #TYPE_MOBILE}</li>
5857         * <li>{@link #TYPE_WORK}</li>
5858         * <li>{@link #TYPE_FAX_WORK}</li>
5859         * <li>{@link #TYPE_FAX_HOME}</li>
5860         * <li>{@link #TYPE_PAGER}</li>
5861         * <li>{@link #TYPE_OTHER}</li>
5862         * <li>{@link #TYPE_CALLBACK}</li>
5863         * <li>{@link #TYPE_CAR}</li>
5864         * <li>{@link #TYPE_COMPANY_MAIN}</li>
5865         * <li>{@link #TYPE_ISDN}</li>
5866         * <li>{@link #TYPE_MAIN}</li>
5867         * <li>{@link #TYPE_OTHER_FAX}</li>
5868         * <li>{@link #TYPE_RADIO}</li>
5869         * <li>{@link #TYPE_TELEX}</li>
5870         * <li>{@link #TYPE_TTY_TDD}</li>
5871         * <li>{@link #TYPE_WORK_MOBILE}</li>
5872         * <li>{@link #TYPE_WORK_PAGER}</li>
5873         * <li>{@link #TYPE_ASSISTANT}</li>
5874         * <li>{@link #TYPE_MMS}</li>
5875         * </ul>
5876         * </p>
5877         * </td>
5878         * </tr>
5879         * <tr>
5880         * <td>String</td>
5881         * <td>{@link #LABEL}</td>
5882         * <td>{@link #DATA3}</td>
5883         * <td></td>
5884         * </tr>
5885         * </table>
5886         */
5887        public static final class Phone implements DataColumnsWithJoins, CommonColumns,
5888                ContactCounts {
5889            /**
5890             * This utility class cannot be instantiated
5891             */
5892            private Phone() {}
5893
5894            /** MIME type used when storing this in data table. */
5895            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2";
5896
5897            /**
5898             * The MIME type of {@link #CONTENT_URI} providing a directory of
5899             * phones.
5900             */
5901            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2";
5902
5903            /**
5904             * The content:// style URI for all data records of the
5905             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
5906             * associated raw contact and aggregate contact data.
5907             */
5908            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
5909                    "phones");
5910
5911            /**
5912            * URI used for getting all contacts from primary and managed profile.
5913            *
5914            * It supports the same semantics as {@link #CONTENT_URI} and returns the same
5915            * columns.  If the device has no corp profile that is linked to the current profile, it
5916            * behaves in the exact same way as {@link #CONTENT_URI}.  If there is a corp profile
5917            * linked to the current profile, it will merge corp profile and current profile's
5918            * results and return
5919            *
5920            * @hide
5921            */
5922            public static final Uri ENTERPRISE_CONTENT_URI =
5923                    Uri.withAppendedPath(Data.ENTERPRISE_CONTENT_URI, "phones");
5924
5925            /**
5926             * The content:// style URL for phone lookup using a filter. The filter returns
5927             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
5928             * to display names as well as phone numbers. The filter argument should be passed
5929             * as an additional path segment after this URI.
5930             */
5931            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
5932                    "filter");
5933
5934            /**
5935             * It supports the similar semantics as {@link #CONTENT_FILTER_URI} and returns the same
5936             * columns. This URI requires {@link ContactsContract#DIRECTORY_PARAM_KEY} in
5937             * parameters, otherwise it will throw UnsupportedOperationException.
5938             */
5939            public static final Uri ENTERPRISE_CONTENT_FILTER_URI = Uri.withAppendedPath(
5940                    CONTENT_URI, "filter_enterprise");
5941
5942            /**
5943             * A boolean query parameter that can be used with {@link #CONTENT_FILTER_URI}.
5944             * If "1" or "true", display names are searched.  If "0" or "false", display names
5945             * are not searched.  Default is "1".
5946             */
5947            public static final String SEARCH_DISPLAY_NAME_KEY = "search_display_name";
5948
5949            /**
5950             * A boolean query parameter that can be used with {@link #CONTENT_FILTER_URI}.
5951             * If "1" or "true", phone numbers are searched.  If "0" or "false", phone numbers
5952             * are not searched.  Default is "1".
5953             */
5954            public static final String SEARCH_PHONE_NUMBER_KEY = "search_phone_number";
5955
5956            public static final int TYPE_HOME = 1;
5957            public static final int TYPE_MOBILE = 2;
5958            public static final int TYPE_WORK = 3;
5959            public static final int TYPE_FAX_WORK = 4;
5960            public static final int TYPE_FAX_HOME = 5;
5961            public static final int TYPE_PAGER = 6;
5962            public static final int TYPE_OTHER = 7;
5963            public static final int TYPE_CALLBACK = 8;
5964            public static final int TYPE_CAR = 9;
5965            public static final int TYPE_COMPANY_MAIN = 10;
5966            public static final int TYPE_ISDN = 11;
5967            public static final int TYPE_MAIN = 12;
5968            public static final int TYPE_OTHER_FAX = 13;
5969            public static final int TYPE_RADIO = 14;
5970            public static final int TYPE_TELEX = 15;
5971            public static final int TYPE_TTY_TDD = 16;
5972            public static final int TYPE_WORK_MOBILE = 17;
5973            public static final int TYPE_WORK_PAGER = 18;
5974            public static final int TYPE_ASSISTANT = 19;
5975            public static final int TYPE_MMS = 20;
5976
5977            /**
5978             * The phone number as the user entered it.
5979             * <P>Type: TEXT</P>
5980             */
5981            public static final String NUMBER = DATA;
5982
5983            /**
5984             * The phone number's E164 representation. This value can be omitted in which
5985             * case the provider will try to automatically infer it.  (It'll be left null if the
5986             * provider fails to infer.)
5987             * If present, {@link #NUMBER} has to be set as well (it will be ignored otherwise).
5988             * <P>Type: TEXT</P>
5989             */
5990            public static final String NORMALIZED_NUMBER = DATA4;
5991
5992            /**
5993             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
5994             * @hide
5995             */
5996            @Deprecated
5997            public static final CharSequence getDisplayLabel(Context context, int type,
5998                    CharSequence label, CharSequence[] labelArray) {
5999                return getTypeLabel(context.getResources(), type, label);
6000            }
6001
6002            /**
6003             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
6004             * @hide
6005             */
6006            @Deprecated
6007            public static final CharSequence getDisplayLabel(Context context, int type,
6008                    CharSequence label) {
6009                return getTypeLabel(context.getResources(), type, label);
6010            }
6011
6012            /**
6013             * Return the string resource that best describes the given
6014             * {@link #TYPE}. Will always return a valid resource.
6015             */
6016            public static final int getTypeLabelResource(int type) {
6017                switch (type) {
6018                    case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome;
6019                    case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile;
6020                    case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork;
6021                    case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork;
6022                    case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome;
6023                    case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager;
6024                    case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther;
6025                    case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback;
6026                    case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar;
6027                    case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain;
6028                    case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn;
6029                    case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain;
6030                    case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax;
6031                    case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio;
6032                    case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex;
6033                    case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd;
6034                    case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile;
6035                    case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager;
6036                    case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant;
6037                    case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms;
6038                    default: return com.android.internal.R.string.phoneTypeCustom;
6039                }
6040            }
6041
6042            /**
6043             * Return a {@link CharSequence} that best describes the given type,
6044             * possibly substituting the given {@link #LABEL} value
6045             * for {@link #TYPE_CUSTOM}.
6046             */
6047            public static final CharSequence getTypeLabel(Resources res, int type,
6048                    CharSequence label) {
6049                if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) {
6050                    return label;
6051                } else {
6052                    final int labelRes = getTypeLabelResource(type);
6053                    return res.getText(labelRes);
6054                }
6055            }
6056        }
6057
6058        /**
6059         * <p>
6060         * A data kind representing an email address.
6061         * </p>
6062         * <p>
6063         * You can use all columns defined for {@link ContactsContract.Data} as
6064         * well as the following aliases.
6065         * </p>
6066         * <h2>Column aliases</h2>
6067         * <table class="jd-sumtable">
6068         * <tr>
6069         * <th>Type</th>
6070         * <th>Alias</th><th colspan='2'>Data column</th>
6071         * </tr>
6072         * <tr>
6073         * <td>String</td>
6074         * <td>{@link #ADDRESS}</td>
6075         * <td>{@link #DATA1}</td>
6076         * <td>Email address itself.</td>
6077         * </tr>
6078         * <tr>
6079         * <td>int</td>
6080         * <td>{@link #TYPE}</td>
6081         * <td>{@link #DATA2}</td>
6082         * <td>Allowed values are:
6083         * <p>
6084         * <ul>
6085         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6086         * <li>{@link #TYPE_HOME}</li>
6087         * <li>{@link #TYPE_WORK}</li>
6088         * <li>{@link #TYPE_OTHER}</li>
6089         * <li>{@link #TYPE_MOBILE}</li>
6090         * </ul>
6091         * </p>
6092         * </td>
6093         * </tr>
6094         * <tr>
6095         * <td>String</td>
6096         * <td>{@link #LABEL}</td>
6097         * <td>{@link #DATA3}</td>
6098         * <td></td>
6099         * </tr>
6100         * </table>
6101         */
6102        public static final class Email implements DataColumnsWithJoins, CommonColumns,
6103                ContactCounts {
6104            /**
6105             * This utility class cannot be instantiated
6106             */
6107            private Email() {}
6108
6109            /** MIME type used when storing this in data table. */
6110            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
6111
6112            /**
6113             * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses.
6114             */
6115            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";
6116
6117            /**
6118             * The content:// style URI for all data records of the
6119             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
6120             * associated raw contact and aggregate contact data.
6121             */
6122            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
6123                    "emails");
6124
6125            /**
6126             * <p>
6127             * The content:// style URL for looking up data rows by email address. The
6128             * lookup argument, an email address, should be passed as an additional path segment
6129             * after this URI.
6130             * </p>
6131             * <p>Example:
6132             * <pre>
6133             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email));
6134             * Cursor c = getContentResolver().query(uri,
6135             *          new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
6136             *          null, null, null);
6137             * </pre>
6138             * </p>
6139             */
6140            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
6141                    "lookup");
6142
6143            /**
6144            * <p>URI used for enterprise email lookup.</p>
6145            *
6146            * <p>
6147            * It supports the same semantics as {@link #CONTENT_LOOKUP_URI} and returns the same
6148            * columns.  If the device has no corp profile that is linked to the current profile, it
6149            * behaves in the exact same way as {@link #CONTENT_LOOKUP_URI}.  If there is a
6150            * corp profile linked to the current profile, it first queries against the personal contact database,
6151            * and if no matching contacts are found there, then queries against the
6152            * corp contacts database.
6153            * </p>
6154            * <p>
6155            * If a result is from the corp profile, it makes the following changes to the data:
6156            * <ul>
6157            *     <li>
6158            *     {@link #PHOTO_THUMBNAIL_URI} and {@link #PHOTO_URI} will be rewritten to special
6159            *     URIs.  Use {@link ContentResolver#openAssetFileDescriptor} or its siblings to
6160            *     load pictures from them.
6161            *     {@link #PHOTO_ID} and {@link #PHOTO_FILE_ID} will be set to null.  Do not
6162            *     use them.
6163            *     </li>
6164            *     <li>
6165            *     Corp contacts will get artificial {@link #CONTACT_ID}s.  In order to tell whether
6166            *     a contact
6167            *     is from the corp profile, use
6168            *     {@link ContactsContract.Contacts#isEnterpriseContactId(long)}.
6169             *     </li>
6170             *     <li>
6171             *     Corp contacts will get artificial {@link #LOOKUP_KEY}s too.
6172             *     </li>
6173             * </ul>
6174             * <p>
6175             * A contact lookup URL built by
6176             * {@link ContactsContract.Contacts#getLookupUri(long, String)}
6177             * with an {@link #_ID} and a {@link #LOOKUP_KEY} returned by this API can be passed to
6178             * {@link ContactsContract.QuickContact#showQuickContact} even if a contact is from the
6179             * corp profile.
6180             * </p>
6181            *
6182            * <pre>
6183            * Uri lookupUri = Uri.withAppendedPath(Email.ENTERPRISE_CONTENT_LOOKUP_URI,
6184            *         Uri.encode(email));
6185            * </pre>
6186            */
6187            public static final Uri ENTERPRISE_CONTENT_LOOKUP_URI =
6188                    Uri.withAppendedPath(CONTENT_URI, "lookup_enterprise");
6189
6190            /**
6191             * <p>
6192             * The content:// style URL for email lookup using a filter. The filter returns
6193             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
6194             * to display names as well as email addresses. The filter argument should be passed
6195             * as an additional path segment after this URI.
6196             * </p>
6197             * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)"
6198             * as well as "Bob Parr (incredible@android.com)".
6199             * <pre>
6200             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
6201             * Cursor c = getContentResolver().query(uri,
6202             *          new String[]{Email.DISPLAY_NAME, Email.DATA},
6203             *          null, null, null);
6204             * </pre>
6205             * </p>
6206             */
6207            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
6208                    "filter");
6209
6210            /**
6211             * It supports the similar semantics as {@link #CONTENT_FILTER_URI} and returns the same
6212             * columns. This URI requires {@link ContactsContract#DIRECTORY_PARAM_KEY} in
6213             * parameters, otherwise it will throw UnsupportedOperationException.
6214             */
6215            public static final Uri ENTERPRISE_CONTENT_FILTER_URI = Uri.withAppendedPath(
6216                    CONTENT_URI, "filter_enterprise");
6217
6218            /**
6219             * The email address.
6220             * <P>Type: TEXT</P>
6221             */
6222            public static final String ADDRESS = DATA1;
6223
6224            public static final int TYPE_HOME = 1;
6225            public static final int TYPE_WORK = 2;
6226            public static final int TYPE_OTHER = 3;
6227            public static final int TYPE_MOBILE = 4;
6228
6229            /**
6230             * The display name for the email address
6231             * <P>Type: TEXT</P>
6232             */
6233            public static final String DISPLAY_NAME = DATA4;
6234
6235            /**
6236             * Return the string resource that best describes the given
6237             * {@link #TYPE}. Will always return a valid resource.
6238             */
6239            public static final int getTypeLabelResource(int type) {
6240                switch (type) {
6241                    case TYPE_HOME: return com.android.internal.R.string.emailTypeHome;
6242                    case TYPE_WORK: return com.android.internal.R.string.emailTypeWork;
6243                    case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther;
6244                    case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile;
6245                    default: return com.android.internal.R.string.emailTypeCustom;
6246                }
6247            }
6248
6249            /**
6250             * Return a {@link CharSequence} that best describes the given type,
6251             * possibly substituting the given {@link #LABEL} value
6252             * for {@link #TYPE_CUSTOM}.
6253             */
6254            public static final CharSequence getTypeLabel(Resources res, int type,
6255                    CharSequence label) {
6256                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6257                    return label;
6258                } else {
6259                    final int labelRes = getTypeLabelResource(type);
6260                    return res.getText(labelRes);
6261                }
6262            }
6263        }
6264
6265        /**
6266         * <p>
6267         * A data kind representing a postal addresses.
6268         * </p>
6269         * <p>
6270         * You can use all columns defined for {@link ContactsContract.Data} as
6271         * well as the following aliases.
6272         * </p>
6273         * <h2>Column aliases</h2>
6274         * <table class="jd-sumtable">
6275         * <tr>
6276         * <th>Type</th>
6277         * <th>Alias</th><th colspan='2'>Data column</th>
6278         * </tr>
6279         * <tr>
6280         * <td>String</td>
6281         * <td>{@link #FORMATTED_ADDRESS}</td>
6282         * <td>{@link #DATA1}</td>
6283         * <td></td>
6284         * </tr>
6285         * <tr>
6286         * <td>int</td>
6287         * <td>{@link #TYPE}</td>
6288         * <td>{@link #DATA2}</td>
6289         * <td>Allowed values are:
6290         * <p>
6291         * <ul>
6292         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6293         * <li>{@link #TYPE_HOME}</li>
6294         * <li>{@link #TYPE_WORK}</li>
6295         * <li>{@link #TYPE_OTHER}</li>
6296         * </ul>
6297         * </p>
6298         * </td>
6299         * </tr>
6300         * <tr>
6301         * <td>String</td>
6302         * <td>{@link #LABEL}</td>
6303         * <td>{@link #DATA3}</td>
6304         * <td></td>
6305         * </tr>
6306         * <tr>
6307         * <td>String</td>
6308         * <td>{@link #STREET}</td>
6309         * <td>{@link #DATA4}</td>
6310         * <td></td>
6311         * </tr>
6312         * <tr>
6313         * <td>String</td>
6314         * <td>{@link #POBOX}</td>
6315         * <td>{@link #DATA5}</td>
6316         * <td>Post Office Box number</td>
6317         * </tr>
6318         * <tr>
6319         * <td>String</td>
6320         * <td>{@link #NEIGHBORHOOD}</td>
6321         * <td>{@link #DATA6}</td>
6322         * <td></td>
6323         * </tr>
6324         * <tr>
6325         * <td>String</td>
6326         * <td>{@link #CITY}</td>
6327         * <td>{@link #DATA7}</td>
6328         * <td></td>
6329         * </tr>
6330         * <tr>
6331         * <td>String</td>
6332         * <td>{@link #REGION}</td>
6333         * <td>{@link #DATA8}</td>
6334         * <td></td>
6335         * </tr>
6336         * <tr>
6337         * <td>String</td>
6338         * <td>{@link #POSTCODE}</td>
6339         * <td>{@link #DATA9}</td>
6340         * <td></td>
6341         * </tr>
6342         * <tr>
6343         * <td>String</td>
6344         * <td>{@link #COUNTRY}</td>
6345         * <td>{@link #DATA10}</td>
6346         * <td></td>
6347         * </tr>
6348         * </table>
6349         */
6350        public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns,
6351                ContactCounts {
6352            /**
6353             * This utility class cannot be instantiated
6354             */
6355            private StructuredPostal() {
6356            }
6357
6358            /** MIME type used when storing this in data table. */
6359            public static final String CONTENT_ITEM_TYPE =
6360                    "vnd.android.cursor.item/postal-address_v2";
6361
6362            /**
6363             * The MIME type of {@link #CONTENT_URI} providing a directory of
6364             * postal addresses.
6365             */
6366            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
6367
6368            /**
6369             * The content:// style URI for all data records of the
6370             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
6371             */
6372            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
6373                    "postals");
6374
6375            public static final int TYPE_HOME = 1;
6376            public static final int TYPE_WORK = 2;
6377            public static final int TYPE_OTHER = 3;
6378
6379            /**
6380             * The full, unstructured postal address. <i>This field must be
6381             * consistent with any structured data.</i>
6382             * <p>
6383             * Type: TEXT
6384             */
6385            public static final String FORMATTED_ADDRESS = DATA;
6386
6387            /**
6388             * Can be street, avenue, road, etc. This element also includes the
6389             * house number and room/apartment/flat/floor number.
6390             * <p>
6391             * Type: TEXT
6392             */
6393            public static final String STREET = DATA4;
6394
6395            /**
6396             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
6397             * usually but not always mutually exclusive with street.
6398             * <p>
6399             * Type: TEXT
6400             */
6401            public static final String POBOX = DATA5;
6402
6403            /**
6404             * This is used to disambiguate a street address when a city
6405             * contains more than one street with the same name, or to specify a
6406             * small place whose mail is routed through a larger postal town. In
6407             * China it could be a county or a minor city.
6408             * <p>
6409             * Type: TEXT
6410             */
6411            public static final String NEIGHBORHOOD = DATA6;
6412
6413            /**
6414             * Can be city, village, town, borough, etc. This is the postal town
6415             * and not necessarily the place of residence or place of business.
6416             * <p>
6417             * Type: TEXT
6418             */
6419            public static final String CITY = DATA7;
6420
6421            /**
6422             * A state, province, county (in Ireland), Land (in Germany),
6423             * departement (in France), etc.
6424             * <p>
6425             * Type: TEXT
6426             */
6427            public static final String REGION = DATA8;
6428
6429            /**
6430             * Postal code. Usually country-wide, but sometimes specific to the
6431             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
6432             * <p>
6433             * Type: TEXT
6434             */
6435            public static final String POSTCODE = DATA9;
6436
6437            /**
6438             * The name or code of the country.
6439             * <p>
6440             * Type: TEXT
6441             */
6442            public static final String COUNTRY = DATA10;
6443
6444            /**
6445             * Return the string resource that best describes the given
6446             * {@link #TYPE}. Will always return a valid resource.
6447             */
6448            public static final int getTypeLabelResource(int type) {
6449                switch (type) {
6450                    case TYPE_HOME: return com.android.internal.R.string.postalTypeHome;
6451                    case TYPE_WORK: return com.android.internal.R.string.postalTypeWork;
6452                    case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther;
6453                    default: return com.android.internal.R.string.postalTypeCustom;
6454                }
6455            }
6456
6457            /**
6458             * Return a {@link CharSequence} that best describes the given type,
6459             * possibly substituting the given {@link #LABEL} value
6460             * for {@link #TYPE_CUSTOM}.
6461             */
6462            public static final CharSequence getTypeLabel(Resources res, int type,
6463                    CharSequence label) {
6464                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6465                    return label;
6466                } else {
6467                    final int labelRes = getTypeLabelResource(type);
6468                    return res.getText(labelRes);
6469                }
6470            }
6471        }
6472
6473        /**
6474         * <p>
6475         * A data kind representing an IM address
6476         * </p>
6477         * <p>
6478         * You can use all columns defined for {@link ContactsContract.Data} as
6479         * well as the following aliases.
6480         * </p>
6481         * <h2>Column aliases</h2>
6482         * <table class="jd-sumtable">
6483         * <tr>
6484         * <th>Type</th>
6485         * <th>Alias</th><th colspan='2'>Data column</th>
6486         * </tr>
6487         * <tr>
6488         * <td>String</td>
6489         * <td>{@link #DATA}</td>
6490         * <td>{@link #DATA1}</td>
6491         * <td></td>
6492         * </tr>
6493         * <tr>
6494         * <td>int</td>
6495         * <td>{@link #TYPE}</td>
6496         * <td>{@link #DATA2}</td>
6497         * <td>Allowed values are:
6498         * <p>
6499         * <ul>
6500         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6501         * <li>{@link #TYPE_HOME}</li>
6502         * <li>{@link #TYPE_WORK}</li>
6503         * <li>{@link #TYPE_OTHER}</li>
6504         * </ul>
6505         * </p>
6506         * </td>
6507         * </tr>
6508         * <tr>
6509         * <td>String</td>
6510         * <td>{@link #LABEL}</td>
6511         * <td>{@link #DATA3}</td>
6512         * <td></td>
6513         * </tr>
6514         * <tr>
6515         * <td>String</td>
6516         * <td>{@link #PROTOCOL}</td>
6517         * <td>{@link #DATA5}</td>
6518         * <td>
6519         * <p>
6520         * Allowed values:
6521         * <ul>
6522         * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name
6523         * as {@link #CUSTOM_PROTOCOL}.</li>
6524         * <li>{@link #PROTOCOL_AIM}</li>
6525         * <li>{@link #PROTOCOL_MSN}</li>
6526         * <li>{@link #PROTOCOL_YAHOO}</li>
6527         * <li>{@link #PROTOCOL_SKYPE}</li>
6528         * <li>{@link #PROTOCOL_QQ}</li>
6529         * <li>{@link #PROTOCOL_GOOGLE_TALK}</li>
6530         * <li>{@link #PROTOCOL_ICQ}</li>
6531         * <li>{@link #PROTOCOL_JABBER}</li>
6532         * <li>{@link #PROTOCOL_NETMEETING}</li>
6533         * </ul>
6534         * </p>
6535         * </td>
6536         * </tr>
6537         * <tr>
6538         * <td>String</td>
6539         * <td>{@link #CUSTOM_PROTOCOL}</td>
6540         * <td>{@link #DATA6}</td>
6541         * <td></td>
6542         * </tr>
6543         * </table>
6544         */
6545        public static final class Im implements DataColumnsWithJoins, CommonColumns, ContactCounts {
6546            /**
6547             * This utility class cannot be instantiated
6548             */
6549            private Im() {}
6550
6551            /** MIME type used when storing this in data table. */
6552            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
6553
6554            public static final int TYPE_HOME = 1;
6555            public static final int TYPE_WORK = 2;
6556            public static final int TYPE_OTHER = 3;
6557
6558            /**
6559             * This column should be populated with one of the defined
6560             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
6561             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
6562             * should contain the name of the custom protocol.
6563             */
6564            public static final String PROTOCOL = DATA5;
6565
6566            public static final String CUSTOM_PROTOCOL = DATA6;
6567
6568            /*
6569             * The predefined IM protocol types.
6570             */
6571            public static final int PROTOCOL_CUSTOM = -1;
6572            public static final int PROTOCOL_AIM = 0;
6573            public static final int PROTOCOL_MSN = 1;
6574            public static final int PROTOCOL_YAHOO = 2;
6575            public static final int PROTOCOL_SKYPE = 3;
6576            public static final int PROTOCOL_QQ = 4;
6577            public static final int PROTOCOL_GOOGLE_TALK = 5;
6578            public static final int PROTOCOL_ICQ = 6;
6579            public static final int PROTOCOL_JABBER = 7;
6580            public static final int PROTOCOL_NETMEETING = 8;
6581
6582            /**
6583             * Return the string resource that best describes the given
6584             * {@link #TYPE}. Will always return a valid resource.
6585             */
6586            public static final int getTypeLabelResource(int type) {
6587                switch (type) {
6588                    case TYPE_HOME: return com.android.internal.R.string.imTypeHome;
6589                    case TYPE_WORK: return com.android.internal.R.string.imTypeWork;
6590                    case TYPE_OTHER: return com.android.internal.R.string.imTypeOther;
6591                    default: return com.android.internal.R.string.imTypeCustom;
6592                }
6593            }
6594
6595            /**
6596             * Return a {@link CharSequence} that best describes the given type,
6597             * possibly substituting the given {@link #LABEL} value
6598             * for {@link #TYPE_CUSTOM}.
6599             */
6600            public static final CharSequence getTypeLabel(Resources res, int type,
6601                    CharSequence label) {
6602                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6603                    return label;
6604                } else {
6605                    final int labelRes = getTypeLabelResource(type);
6606                    return res.getText(labelRes);
6607                }
6608            }
6609
6610            /**
6611             * Return the string resource that best describes the given
6612             * {@link #PROTOCOL}. Will always return a valid resource.
6613             */
6614            public static final int getProtocolLabelResource(int type) {
6615                switch (type) {
6616                    case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim;
6617                    case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn;
6618                    case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo;
6619                    case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype;
6620                    case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq;
6621                    case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk;
6622                    case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq;
6623                    case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber;
6624                    case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting;
6625                    default: return com.android.internal.R.string.imProtocolCustom;
6626                }
6627            }
6628
6629            /**
6630             * Return a {@link CharSequence} that best describes the given
6631             * protocol, possibly substituting the given
6632             * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}.
6633             */
6634            public static final CharSequence getProtocolLabel(Resources res, int type,
6635                    CharSequence label) {
6636                if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) {
6637                    return label;
6638                } else {
6639                    final int labelRes = getProtocolLabelResource(type);
6640                    return res.getText(labelRes);
6641                }
6642            }
6643        }
6644
6645        /**
6646         * <p>
6647         * A data kind representing an organization.
6648         * </p>
6649         * <p>
6650         * You can use all columns defined for {@link ContactsContract.Data} as
6651         * well as the following aliases.
6652         * </p>
6653         * <h2>Column aliases</h2>
6654         * <table class="jd-sumtable">
6655         * <tr>
6656         * <th>Type</th>
6657         * <th>Alias</th><th colspan='2'>Data column</th>
6658         * </tr>
6659         * <tr>
6660         * <td>String</td>
6661         * <td>{@link #COMPANY}</td>
6662         * <td>{@link #DATA1}</td>
6663         * <td></td>
6664         * </tr>
6665         * <tr>
6666         * <td>int</td>
6667         * <td>{@link #TYPE}</td>
6668         * <td>{@link #DATA2}</td>
6669         * <td>Allowed values are:
6670         * <p>
6671         * <ul>
6672         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6673         * <li>{@link #TYPE_WORK}</li>
6674         * <li>{@link #TYPE_OTHER}</li>
6675         * </ul>
6676         * </p>
6677         * </td>
6678         * </tr>
6679         * <tr>
6680         * <td>String</td>
6681         * <td>{@link #LABEL}</td>
6682         * <td>{@link #DATA3}</td>
6683         * <td></td>
6684         * </tr>
6685         * <tr>
6686         * <td>String</td>
6687         * <td>{@link #TITLE}</td>
6688         * <td>{@link #DATA4}</td>
6689         * <td></td>
6690         * </tr>
6691         * <tr>
6692         * <td>String</td>
6693         * <td>{@link #DEPARTMENT}</td>
6694         * <td>{@link #DATA5}</td>
6695         * <td></td>
6696         * </tr>
6697         * <tr>
6698         * <td>String</td>
6699         * <td>{@link #JOB_DESCRIPTION}</td>
6700         * <td>{@link #DATA6}</td>
6701         * <td></td>
6702         * </tr>
6703         * <tr>
6704         * <td>String</td>
6705         * <td>{@link #SYMBOL}</td>
6706         * <td>{@link #DATA7}</td>
6707         * <td></td>
6708         * </tr>
6709         * <tr>
6710         * <td>String</td>
6711         * <td>{@link #PHONETIC_NAME}</td>
6712         * <td>{@link #DATA8}</td>
6713         * <td></td>
6714         * </tr>
6715         * <tr>
6716         * <td>String</td>
6717         * <td>{@link #OFFICE_LOCATION}</td>
6718         * <td>{@link #DATA9}</td>
6719         * <td></td>
6720         * </tr>
6721         * <tr>
6722         * <td>String</td>
6723         * <td>PHONETIC_NAME_STYLE</td>
6724         * <td>{@link #DATA10}</td>
6725         * <td></td>
6726         * </tr>
6727         * </table>
6728         */
6729        public static final class Organization implements DataColumnsWithJoins, CommonColumns,
6730                ContactCounts {
6731            /**
6732             * This utility class cannot be instantiated
6733             */
6734            private Organization() {}
6735
6736            /** MIME type used when storing this in data table. */
6737            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
6738
6739            public static final int TYPE_WORK = 1;
6740            public static final int TYPE_OTHER = 2;
6741
6742            /**
6743             * The company as the user entered it.
6744             * <P>Type: TEXT</P>
6745             */
6746            public static final String COMPANY = DATA;
6747
6748            /**
6749             * The position title at this company as the user entered it.
6750             * <P>Type: TEXT</P>
6751             */
6752            public static final String TITLE = DATA4;
6753
6754            /**
6755             * The department at this company as the user entered it.
6756             * <P>Type: TEXT</P>
6757             */
6758            public static final String DEPARTMENT = DATA5;
6759
6760            /**
6761             * The job description at this company as the user entered it.
6762             * <P>Type: TEXT</P>
6763             */
6764            public static final String JOB_DESCRIPTION = DATA6;
6765
6766            /**
6767             * The symbol of this company as the user entered it.
6768             * <P>Type: TEXT</P>
6769             */
6770            public static final String SYMBOL = DATA7;
6771
6772            /**
6773             * The phonetic name of this company as the user entered it.
6774             * <P>Type: TEXT</P>
6775             */
6776            public static final String PHONETIC_NAME = DATA8;
6777
6778            /**
6779             * The office location of this organization.
6780             * <P>Type: TEXT</P>
6781             */
6782            public static final String OFFICE_LOCATION = DATA9;
6783
6784            /**
6785             * The alphabet used for capturing the phonetic name.
6786             * See {@link ContactsContract.PhoneticNameStyle}.
6787             */
6788            public static final String PHONETIC_NAME_STYLE = DATA10;
6789
6790            /**
6791             * Return the string resource that best describes the given
6792             * {@link #TYPE}. Will always return a valid resource.
6793             */
6794            public static final int getTypeLabelResource(int type) {
6795                switch (type) {
6796                    case TYPE_WORK: return com.android.internal.R.string.orgTypeWork;
6797                    case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther;
6798                    default: return com.android.internal.R.string.orgTypeCustom;
6799                }
6800            }
6801
6802            /**
6803             * Return a {@link CharSequence} that best describes the given type,
6804             * possibly substituting the given {@link #LABEL} value
6805             * for {@link #TYPE_CUSTOM}.
6806             */
6807            public static final CharSequence getTypeLabel(Resources res, int type,
6808                    CharSequence label) {
6809                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6810                    return label;
6811                } else {
6812                    final int labelRes = getTypeLabelResource(type);
6813                    return res.getText(labelRes);
6814                }
6815            }
6816        }
6817
6818        /**
6819         * <p>
6820         * A data kind representing a relation.
6821         * </p>
6822         * <p>
6823         * You can use all columns defined for {@link ContactsContract.Data} as
6824         * well as the following aliases.
6825         * </p>
6826         * <h2>Column aliases</h2>
6827         * <table class="jd-sumtable">
6828         * <tr>
6829         * <th>Type</th>
6830         * <th>Alias</th><th colspan='2'>Data column</th>
6831         * </tr>
6832         * <tr>
6833         * <td>String</td>
6834         * <td>{@link #NAME}</td>
6835         * <td>{@link #DATA1}</td>
6836         * <td></td>
6837         * </tr>
6838         * <tr>
6839         * <td>int</td>
6840         * <td>{@link #TYPE}</td>
6841         * <td>{@link #DATA2}</td>
6842         * <td>Allowed values are:
6843         * <p>
6844         * <ul>
6845         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6846         * <li>{@link #TYPE_ASSISTANT}</li>
6847         * <li>{@link #TYPE_BROTHER}</li>
6848         * <li>{@link #TYPE_CHILD}</li>
6849         * <li>{@link #TYPE_DOMESTIC_PARTNER}</li>
6850         * <li>{@link #TYPE_FATHER}</li>
6851         * <li>{@link #TYPE_FRIEND}</li>
6852         * <li>{@link #TYPE_MANAGER}</li>
6853         * <li>{@link #TYPE_MOTHER}</li>
6854         * <li>{@link #TYPE_PARENT}</li>
6855         * <li>{@link #TYPE_PARTNER}</li>
6856         * <li>{@link #TYPE_REFERRED_BY}</li>
6857         * <li>{@link #TYPE_RELATIVE}</li>
6858         * <li>{@link #TYPE_SISTER}</li>
6859         * <li>{@link #TYPE_SPOUSE}</li>
6860         * </ul>
6861         * </p>
6862         * </td>
6863         * </tr>
6864         * <tr>
6865         * <td>String</td>
6866         * <td>{@link #LABEL}</td>
6867         * <td>{@link #DATA3}</td>
6868         * <td></td>
6869         * </tr>
6870         * </table>
6871         */
6872        public static final class Relation implements DataColumnsWithJoins, CommonColumns,
6873                ContactCounts {
6874            /**
6875             * This utility class cannot be instantiated
6876             */
6877            private Relation() {}
6878
6879            /** MIME type used when storing this in data table. */
6880            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
6881
6882            public static final int TYPE_ASSISTANT = 1;
6883            public static final int TYPE_BROTHER = 2;
6884            public static final int TYPE_CHILD = 3;
6885            public static final int TYPE_DOMESTIC_PARTNER = 4;
6886            public static final int TYPE_FATHER = 5;
6887            public static final int TYPE_FRIEND = 6;
6888            public static final int TYPE_MANAGER = 7;
6889            public static final int TYPE_MOTHER = 8;
6890            public static final int TYPE_PARENT = 9;
6891            public static final int TYPE_PARTNER = 10;
6892            public static final int TYPE_REFERRED_BY = 11;
6893            public static final int TYPE_RELATIVE = 12;
6894            public static final int TYPE_SISTER = 13;
6895            public static final int TYPE_SPOUSE = 14;
6896
6897            /**
6898             * The name of the relative as the user entered it.
6899             * <P>Type: TEXT</P>
6900             */
6901            public static final String NAME = DATA;
6902
6903            /**
6904             * Return the string resource that best describes the given
6905             * {@link #TYPE}. Will always return a valid resource.
6906             */
6907            public static final int getTypeLabelResource(int type) {
6908                switch (type) {
6909                    case TYPE_ASSISTANT: return com.android.internal.R.string.relationTypeAssistant;
6910                    case TYPE_BROTHER: return com.android.internal.R.string.relationTypeBrother;
6911                    case TYPE_CHILD: return com.android.internal.R.string.relationTypeChild;
6912                    case TYPE_DOMESTIC_PARTNER:
6913                            return com.android.internal.R.string.relationTypeDomesticPartner;
6914                    case TYPE_FATHER: return com.android.internal.R.string.relationTypeFather;
6915                    case TYPE_FRIEND: return com.android.internal.R.string.relationTypeFriend;
6916                    case TYPE_MANAGER: return com.android.internal.R.string.relationTypeManager;
6917                    case TYPE_MOTHER: return com.android.internal.R.string.relationTypeMother;
6918                    case TYPE_PARENT: return com.android.internal.R.string.relationTypeParent;
6919                    case TYPE_PARTNER: return com.android.internal.R.string.relationTypePartner;
6920                    case TYPE_REFERRED_BY:
6921                            return com.android.internal.R.string.relationTypeReferredBy;
6922                    case TYPE_RELATIVE: return com.android.internal.R.string.relationTypeRelative;
6923                    case TYPE_SISTER: return com.android.internal.R.string.relationTypeSister;
6924                    case TYPE_SPOUSE: return com.android.internal.R.string.relationTypeSpouse;
6925                    default: return com.android.internal.R.string.orgTypeCustom;
6926                }
6927            }
6928
6929            /**
6930             * Return a {@link CharSequence} that best describes the given type,
6931             * possibly substituting the given {@link #LABEL} value
6932             * for {@link #TYPE_CUSTOM}.
6933             */
6934            public static final CharSequence getTypeLabel(Resources res, int type,
6935                    CharSequence label) {
6936                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6937                    return label;
6938                } else {
6939                    final int labelRes = getTypeLabelResource(type);
6940                    return res.getText(labelRes);
6941                }
6942            }
6943        }
6944
6945        /**
6946         * <p>
6947         * A data kind representing an event.
6948         * </p>
6949         * <p>
6950         * You can use all columns defined for {@link ContactsContract.Data} as
6951         * well as the following aliases.
6952         * </p>
6953         * <h2>Column aliases</h2>
6954         * <table class="jd-sumtable">
6955         * <tr>
6956         * <th>Type</th>
6957         * <th>Alias</th><th colspan='2'>Data column</th>
6958         * </tr>
6959         * <tr>
6960         * <td>String</td>
6961         * <td>{@link #START_DATE}</td>
6962         * <td>{@link #DATA1}</td>
6963         * <td></td>
6964         * </tr>
6965         * <tr>
6966         * <td>int</td>
6967         * <td>{@link #TYPE}</td>
6968         * <td>{@link #DATA2}</td>
6969         * <td>Allowed values are:
6970         * <p>
6971         * <ul>
6972         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6973         * <li>{@link #TYPE_ANNIVERSARY}</li>
6974         * <li>{@link #TYPE_OTHER}</li>
6975         * <li>{@link #TYPE_BIRTHDAY}</li>
6976         * </ul>
6977         * </p>
6978         * </td>
6979         * </tr>
6980         * <tr>
6981         * <td>String</td>
6982         * <td>{@link #LABEL}</td>
6983         * <td>{@link #DATA3}</td>
6984         * <td></td>
6985         * </tr>
6986         * </table>
6987         */
6988        public static final class Event implements DataColumnsWithJoins, CommonColumns,
6989                ContactCounts {
6990            /**
6991             * This utility class cannot be instantiated
6992             */
6993            private Event() {}
6994
6995            /** MIME type used when storing this in data table. */
6996            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event";
6997
6998            public static final int TYPE_ANNIVERSARY = 1;
6999            public static final int TYPE_OTHER = 2;
7000            public static final int TYPE_BIRTHDAY = 3;
7001
7002            /**
7003             * The event start date as the user entered it.
7004             * <P>Type: TEXT</P>
7005             */
7006            public static final String START_DATE = DATA;
7007
7008            /**
7009             * Return the string resource that best describes the given
7010             * {@link #TYPE}. Will always return a valid resource.
7011             */
7012            public static int getTypeResource(Integer type) {
7013                if (type == null) {
7014                    return com.android.internal.R.string.eventTypeOther;
7015                }
7016                switch (type) {
7017                    case TYPE_ANNIVERSARY:
7018                        return com.android.internal.R.string.eventTypeAnniversary;
7019                    case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday;
7020                    case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther;
7021                    default: return com.android.internal.R.string.eventTypeCustom;
7022                }
7023            }
7024
7025            /**
7026             * Return a {@link CharSequence} that best describes the given type,
7027             * possibly substituting the given {@link #LABEL} value
7028             * for {@link #TYPE_CUSTOM}.
7029             */
7030            public static final CharSequence getTypeLabel(Resources res, int type,
7031                    CharSequence label) {
7032                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
7033                    return label;
7034                } else {
7035                    final int labelRes = getTypeResource(type);
7036                    return res.getText(labelRes);
7037                }
7038            }
7039        }
7040
7041        /**
7042         * <p>
7043         * A data kind representing a photo for the contact.
7044         * </p>
7045         * <p>
7046         * Some sync adapters will choose to download photos in a separate
7047         * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1}
7048         * through {@link ContactsContract.Data#SYNC4} to store temporary
7049         * data, e.g. the image URL or ID, state of download, server-side version
7050         * of the image.  It is allowed for the {@link #PHOTO} to be null.
7051         * </p>
7052         * <p>
7053         * You can use all columns defined for {@link ContactsContract.Data} as
7054         * well as the following aliases.
7055         * </p>
7056         * <h2>Column aliases</h2>
7057         * <table class="jd-sumtable">
7058         * <tr>
7059         * <th>Type</th>
7060         * <th>Alias</th><th colspan='2'>Data column</th>
7061         * </tr>
7062         * <tr>
7063         * <td>NUMBER</td>
7064         * <td>{@link #PHOTO_FILE_ID}</td>
7065         * <td>{@link #DATA14}</td>
7066         * <td>ID of the hi-res photo file.</td>
7067         * </tr>
7068         * <tr>
7069         * <td>BLOB</td>
7070         * <td>{@link #PHOTO}</td>
7071         * <td>{@link #DATA15}</td>
7072         * <td>By convention, binary data is stored in DATA15.  The thumbnail of the
7073         * photo is stored in this column.</td>
7074         * </tr>
7075         * </table>
7076         */
7077        public static final class Photo implements DataColumnsWithJoins, ContactCounts {
7078            /**
7079             * This utility class cannot be instantiated
7080             */
7081            private Photo() {}
7082
7083            /** MIME type used when storing this in data table. */
7084            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
7085
7086            /**
7087             * Photo file ID for the display photo of the raw contact.
7088             * See {@link ContactsContract.DisplayPhoto}.
7089             * <p>
7090             * Type: NUMBER
7091             */
7092            public static final String PHOTO_FILE_ID = DATA14;
7093
7094            /**
7095             * Thumbnail photo of the raw contact. This is the raw bytes of an image
7096             * that could be inflated using {@link android.graphics.BitmapFactory}.
7097             * <p>
7098             * Type: BLOB
7099             */
7100            public static final String PHOTO = DATA15;
7101        }
7102
7103        /**
7104         * <p>
7105         * Notes about the contact.
7106         * </p>
7107         * <p>
7108         * You can use all columns defined for {@link ContactsContract.Data} as
7109         * well as the following aliases.
7110         * </p>
7111         * <h2>Column aliases</h2>
7112         * <table class="jd-sumtable">
7113         * <tr>
7114         * <th>Type</th>
7115         * <th>Alias</th><th colspan='2'>Data column</th>
7116         * </tr>
7117         * <tr>
7118         * <td>String</td>
7119         * <td>{@link #NOTE}</td>
7120         * <td>{@link #DATA1}</td>
7121         * <td></td>
7122         * </tr>
7123         * </table>
7124         */
7125        public static final class Note implements DataColumnsWithJoins, ContactCounts {
7126            /**
7127             * This utility class cannot be instantiated
7128             */
7129            private Note() {}
7130
7131            /** MIME type used when storing this in data table. */
7132            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
7133
7134            /**
7135             * The note text.
7136             * <P>Type: TEXT</P>
7137             */
7138            public static final String NOTE = DATA1;
7139        }
7140
7141        /**
7142         * <p>
7143         * Group Membership.
7144         * </p>
7145         * <p>
7146         * You can use all columns defined for {@link ContactsContract.Data} as
7147         * well as the following aliases.
7148         * </p>
7149         * <h2>Column aliases</h2>
7150         * <table class="jd-sumtable">
7151         * <tr>
7152         * <th>Type</th>
7153         * <th>Alias</th><th colspan='2'>Data column</th>
7154         * </tr>
7155         * <tr>
7156         * <td>long</td>
7157         * <td>{@link #GROUP_ROW_ID}</td>
7158         * <td>{@link #DATA1}</td>
7159         * <td></td>
7160         * </tr>
7161         * <tr>
7162         * <td>String</td>
7163         * <td>{@link #GROUP_SOURCE_ID}</td>
7164         * <td>none</td>
7165         * <td>
7166         * <p>
7167         * The sourceid of the group that this group membership refers to.
7168         * Exactly one of this or {@link #GROUP_ROW_ID} must be set when
7169         * inserting a row.
7170         * </p>
7171         * <p>
7172         * If this field is specified, the provider will first try to
7173         * look up a group with this {@link Groups Groups.SOURCE_ID}.  If such a group
7174         * is found, it will use the corresponding row id.  If the group is not
7175         * found, it will create one.
7176         * </td>
7177         * </tr>
7178         * </table>
7179         */
7180        public static final class GroupMembership implements DataColumnsWithJoins, ContactCounts {
7181            /**
7182             * This utility class cannot be instantiated
7183             */
7184            private GroupMembership() {}
7185
7186            /** MIME type used when storing this in data table. */
7187            public static final String CONTENT_ITEM_TYPE =
7188                    "vnd.android.cursor.item/group_membership";
7189
7190            /**
7191             * The row id of the group that this group membership refers to. Exactly one of
7192             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
7193             * <P>Type: INTEGER</P>
7194             */
7195            public static final String GROUP_ROW_ID = DATA1;
7196
7197            /**
7198             * The sourceid of the group that this group membership refers to.  Exactly one of
7199             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
7200             * <P>Type: TEXT</P>
7201             */
7202            public static final String GROUP_SOURCE_ID = "group_sourceid";
7203        }
7204
7205        /**
7206         * <p>
7207         * A data kind representing a website related to the contact.
7208         * </p>
7209         * <p>
7210         * You can use all columns defined for {@link ContactsContract.Data} as
7211         * well as the following aliases.
7212         * </p>
7213         * <h2>Column aliases</h2>
7214         * <table class="jd-sumtable">
7215         * <tr>
7216         * <th>Type</th>
7217         * <th>Alias</th><th colspan='2'>Data column</th>
7218         * </tr>
7219         * <tr>
7220         * <td>String</td>
7221         * <td>{@link #URL}</td>
7222         * <td>{@link #DATA1}</td>
7223         * <td></td>
7224         * </tr>
7225         * <tr>
7226         * <td>int</td>
7227         * <td>{@link #TYPE}</td>
7228         * <td>{@link #DATA2}</td>
7229         * <td>Allowed values are:
7230         * <p>
7231         * <ul>
7232         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
7233         * <li>{@link #TYPE_HOMEPAGE}</li>
7234         * <li>{@link #TYPE_BLOG}</li>
7235         * <li>{@link #TYPE_PROFILE}</li>
7236         * <li>{@link #TYPE_HOME}</li>
7237         * <li>{@link #TYPE_WORK}</li>
7238         * <li>{@link #TYPE_FTP}</li>
7239         * <li>{@link #TYPE_OTHER}</li>
7240         * </ul>
7241         * </p>
7242         * </td>
7243         * </tr>
7244         * <tr>
7245         * <td>String</td>
7246         * <td>{@link #LABEL}</td>
7247         * <td>{@link #DATA3}</td>
7248         * <td></td>
7249         * </tr>
7250         * </table>
7251         */
7252        public static final class Website implements DataColumnsWithJoins, CommonColumns,
7253                ContactCounts {
7254            /**
7255             * This utility class cannot be instantiated
7256             */
7257            private Website() {}
7258
7259            /** MIME type used when storing this in data table. */
7260            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
7261
7262            public static final int TYPE_HOMEPAGE = 1;
7263            public static final int TYPE_BLOG = 2;
7264            public static final int TYPE_PROFILE = 3;
7265            public static final int TYPE_HOME = 4;
7266            public static final int TYPE_WORK = 5;
7267            public static final int TYPE_FTP = 6;
7268            public static final int TYPE_OTHER = 7;
7269
7270            /**
7271             * The website URL string.
7272             * <P>Type: TEXT</P>
7273             */
7274            public static final String URL = DATA;
7275        }
7276
7277        /**
7278         * <p>
7279         * A data kind representing a SIP address for the contact.
7280         * </p>
7281         * <p>
7282         * You can use all columns defined for {@link ContactsContract.Data} as
7283         * well as the following aliases.
7284         * </p>
7285         * <h2>Column aliases</h2>
7286         * <table class="jd-sumtable">
7287         * <tr>
7288         * <th>Type</th>
7289         * <th>Alias</th><th colspan='2'>Data column</th>
7290         * </tr>
7291         * <tr>
7292         * <td>String</td>
7293         * <td>{@link #SIP_ADDRESS}</td>
7294         * <td>{@link #DATA1}</td>
7295         * <td></td>
7296         * </tr>
7297         * <tr>
7298         * <td>int</td>
7299         * <td>{@link #TYPE}</td>
7300         * <td>{@link #DATA2}</td>
7301         * <td>Allowed values are:
7302         * <p>
7303         * <ul>
7304         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
7305         * <li>{@link #TYPE_HOME}</li>
7306         * <li>{@link #TYPE_WORK}</li>
7307         * <li>{@link #TYPE_OTHER}</li>
7308         * </ul>
7309         * </p>
7310         * </td>
7311         * </tr>
7312         * <tr>
7313         * <td>String</td>
7314         * <td>{@link #LABEL}</td>
7315         * <td>{@link #DATA3}</td>
7316         * <td></td>
7317         * </tr>
7318         * </table>
7319         */
7320        public static final class SipAddress implements DataColumnsWithJoins, CommonColumns,
7321                ContactCounts {
7322            /**
7323             * This utility class cannot be instantiated
7324             */
7325            private SipAddress() {}
7326
7327            /** MIME type used when storing this in data table. */
7328            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/sip_address";
7329
7330            public static final int TYPE_HOME = 1;
7331            public static final int TYPE_WORK = 2;
7332            public static final int TYPE_OTHER = 3;
7333
7334            /**
7335             * The SIP address.
7336             * <P>Type: TEXT</P>
7337             */
7338            public static final String SIP_ADDRESS = DATA1;
7339            // ...and TYPE and LABEL come from the CommonColumns interface.
7340
7341            /**
7342             * Return the string resource that best describes the given
7343             * {@link #TYPE}. Will always return a valid resource.
7344             */
7345            public static final int getTypeLabelResource(int type) {
7346                switch (type) {
7347                    case TYPE_HOME: return com.android.internal.R.string.sipAddressTypeHome;
7348                    case TYPE_WORK: return com.android.internal.R.string.sipAddressTypeWork;
7349                    case TYPE_OTHER: return com.android.internal.R.string.sipAddressTypeOther;
7350                    default: return com.android.internal.R.string.sipAddressTypeCustom;
7351                }
7352            }
7353
7354            /**
7355             * Return a {@link CharSequence} that best describes the given type,
7356             * possibly substituting the given {@link #LABEL} value
7357             * for {@link #TYPE_CUSTOM}.
7358             */
7359            public static final CharSequence getTypeLabel(Resources res, int type,
7360                    CharSequence label) {
7361                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
7362                    return label;
7363                } else {
7364                    final int labelRes = getTypeLabelResource(type);
7365                    return res.getText(labelRes);
7366                }
7367            }
7368        }
7369
7370        /**
7371         * A data kind representing an Identity related to the contact.
7372         * <p>
7373         * This can be used as a signal by the aggregator to combine raw contacts into
7374         * contacts, e.g. if two contacts have Identity rows with
7375         * the same NAMESPACE and IDENTITY values the aggregator can know that they refer
7376         * to the same person.
7377         * </p>
7378         */
7379        public static final class Identity implements DataColumnsWithJoins, ContactCounts {
7380            /**
7381             * This utility class cannot be instantiated
7382             */
7383            private Identity() {}
7384
7385            /** MIME type used when storing this in data table. */
7386            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/identity";
7387
7388            /**
7389             * The identity string.
7390             * <P>Type: TEXT</P>
7391             */
7392            public static final String IDENTITY = DataColumns.DATA1;
7393
7394            /**
7395             * The namespace of the identity string, e.g. "com.google"
7396             * <P>Type: TEXT</P>
7397             */
7398            public static final String NAMESPACE = DataColumns.DATA2;
7399        }
7400
7401        /**
7402         * <p>
7403         * Convenient functionalities for "callable" data. Note that, this is NOT a separate data
7404         * kind.
7405         * </p>
7406         * <p>
7407         * This URI allows the ContactsProvider to return a unified result for "callable" data
7408         * that users can use for calling purposes. {@link Phone} and {@link SipAddress} are the
7409         * current examples for "callable", but may be expanded to the other types.
7410         * </p>
7411         * <p>
7412         * Each returned row may have a different MIMETYPE and thus different interpretation for
7413         * each column. For example the meaning for {@link Phone}'s type is different than
7414         * {@link SipAddress}'s.
7415         * </p>
7416         */
7417        public static final class Callable implements DataColumnsWithJoins, CommonColumns,
7418                ContactCounts {
7419            /**
7420             * Similar to {@link Phone#CONTENT_URI}, but returns callable data instead of only
7421             * phone numbers.
7422             */
7423            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
7424                    "callables");
7425            /**
7426             * Similar to {@link Phone#CONTENT_FILTER_URI}, but allows users to filter callable
7427             * data.
7428             */
7429            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
7430                    "filter");
7431
7432            /**
7433             * Similar to {@link Phone#ENTERPRISE_CONTENT_FILTER_URI}, but allows users to filter
7434             * callable data. This URI requires {@link ContactsContract#DIRECTORY_PARAM_KEY} in
7435             * parameters, otherwise it will throw UnsupportedOperationException.
7436             */
7437            public static final Uri ENTERPRISE_CONTENT_FILTER_URI = Uri.withAppendedPath(
7438                    CONTENT_URI, "filter_enterprise");
7439        }
7440
7441        /**
7442         * A special class of data items, used to refer to types of data that can be used to attempt
7443         * to start communicating with a person ({@link Phone} and {@link Email}). Note that this
7444         * is NOT a separate data kind.
7445         *
7446         * This URI allows the ContactsProvider to return a unified result for data items that users
7447         * can use to initiate communications with another contact. {@link Phone} and {@link Email}
7448         * are the current data types in this category.
7449         */
7450        public static final class Contactables implements DataColumnsWithJoins, CommonColumns,
7451                ContactCounts {
7452            /**
7453             * The content:// style URI for these data items, which requests a directory of data
7454             * rows matching the selection criteria.
7455             */
7456            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
7457                    "contactables");
7458
7459            /**
7460             * The content:// style URI for these data items, which allows for a query parameter to
7461             * be appended onto the end to filter for data items matching the query.
7462             */
7463            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(
7464                    Contactables.CONTENT_URI, "filter");
7465
7466            /**
7467             * A boolean parameter for {@link Data#CONTENT_URI}.
7468             * This specifies whether or not the returned data items should be filtered to show
7469             * data items belonging to visible contacts only.
7470             */
7471            public static final String VISIBLE_CONTACTS_ONLY = "visible_contacts_only";
7472        }
7473    }
7474
7475    /**
7476     * @see Groups
7477     */
7478    protected interface GroupsColumns {
7479        /**
7480         * The data set within the account that this group belongs to.  This allows
7481         * multiple sync adapters for the same account type to distinguish between
7482         * each others' group data.
7483         *
7484         * This is empty by default, and is completely optional.  It only needs to
7485         * be populated if multiple sync adapters are entering distinct group data
7486         * for the same account type and account name.
7487         * <P>Type: TEXT</P>
7488         */
7489        public static final String DATA_SET = "data_set";
7490
7491        /**
7492         * A concatenation of the account type and data set (delimited by a forward
7493         * slash) - if the data set is empty, this will be the same as the account
7494         * type.  For applications that need to be aware of the data set, this can
7495         * be used instead of account type to distinguish sets of data.  This is
7496         * never intended to be used for specifying accounts.
7497         * @hide
7498         */
7499        public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set";
7500
7501        /**
7502         * The display title of this group.
7503         * <p>
7504         * Type: TEXT
7505         */
7506        public static final String TITLE = "title";
7507
7508        /**
7509         * The package name to use when creating {@link Resources} objects for
7510         * this group. This value is only designed for use when building user
7511         * interfaces, and should not be used to infer the owner.
7512         */
7513        public static final String RES_PACKAGE = "res_package";
7514
7515        /**
7516         * The display title of this group to load as a resource from
7517         * {@link #RES_PACKAGE}, which may be localized.
7518         * <P>Type: TEXT</P>
7519         */
7520        public static final String TITLE_RES = "title_res";
7521
7522        /**
7523         * Notes about the group.
7524         * <p>
7525         * Type: TEXT
7526         */
7527        public static final String NOTES = "notes";
7528
7529        /**
7530         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
7531         * to the sync adapter, null otherwise.
7532         * <P>Type: TEXT</P>
7533         */
7534        public static final String SYSTEM_ID = "system_id";
7535
7536        /**
7537         * The total number of {@link Contacts} that have
7538         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
7539         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
7540         * <p>
7541         * Type: INTEGER
7542         */
7543        public static final String SUMMARY_COUNT = "summ_count";
7544
7545        /**
7546         * A boolean query parameter that can be used with {@link Groups#CONTENT_SUMMARY_URI}.
7547         * It will additionally return {@link #SUMMARY_GROUP_COUNT_PER_ACCOUNT}.
7548         *
7549         * @hide
7550         */
7551        public static final String PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT =
7552                "return_group_count_per_account";
7553
7554        /**
7555         * The total number of groups of the account that a group belongs to.
7556         * This column is available only when the parameter
7557         * {@link #PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT} is specified in
7558         * {@link Groups#CONTENT_SUMMARY_URI}.
7559         *
7560         * For example, when the account "A" has two groups "group1" and "group2", and the account
7561         * "B" has a group "group3", the rows for "group1" and "group2" return "2" and the row for
7562         * "group3" returns "1" for this column.
7563         *
7564         * Note: This counts only non-favorites, non-auto-add, and not deleted groups.
7565         *
7566         * Type: INTEGER
7567         * @hide
7568         */
7569        public static final String SUMMARY_GROUP_COUNT_PER_ACCOUNT = "group_count_per_account";
7570
7571        /**
7572         * The total number of {@link Contacts} that have both
7573         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
7574         * Read-only value that is only present when querying
7575         * {@link Groups#CONTENT_SUMMARY_URI}.
7576         * <p>
7577         * Type: INTEGER
7578         */
7579        public static final String SUMMARY_WITH_PHONES = "summ_phones";
7580
7581        /**
7582         * Flag indicating if the contacts belonging to this group should be
7583         * visible in any user interface.
7584         * <p>
7585         * Type: INTEGER (boolean)
7586         */
7587        public static final String GROUP_VISIBLE = "group_visible";
7588
7589        /**
7590         * The "deleted" flag: "0" by default, "1" if the row has been marked
7591         * for deletion. When {@link android.content.ContentResolver#delete} is
7592         * called on a group, it is marked for deletion. The sync adaptor
7593         * deletes the group on the server and then calls ContactResolver.delete
7594         * once more, this time setting the the
7595         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to
7596         * finalize the data removal.
7597         * <P>Type: INTEGER</P>
7598         */
7599        public static final String DELETED = "deleted";
7600
7601        /**
7602         * Whether this group should be synced if the SYNC_EVERYTHING settings
7603         * is false for this group's account.
7604         * <p>
7605         * Type: INTEGER (boolean)
7606         */
7607        public static final String SHOULD_SYNC = "should_sync";
7608
7609        /**
7610         * Any newly created contacts will automatically be added to groups that have this
7611         * flag set to true.
7612         * <p>
7613         * Type: INTEGER (boolean)
7614         */
7615        public static final String AUTO_ADD = "auto_add";
7616
7617        /**
7618         * When a contacts is marked as a favorites it will be automatically added
7619         * to the groups that have this flag set, and when it is removed from favorites
7620         * it will be removed from these groups.
7621         * <p>
7622         * Type: INTEGER (boolean)
7623         */
7624        public static final String FAVORITES = "favorites";
7625
7626        /**
7627         * The "read-only" flag: "0" by default, "1" if the row cannot be modified or
7628         * deleted except by a sync adapter.  See {@link ContactsContract#CALLER_IS_SYNCADAPTER}.
7629         * <P>Type: INTEGER</P>
7630         */
7631        public static final String GROUP_IS_READ_ONLY = "group_is_read_only";
7632    }
7633
7634    /**
7635     * Constants for the groups table. Only per-account groups are supported.
7636     * <h2>Columns</h2>
7637     * <table class="jd-sumtable">
7638     * <tr>
7639     * <th colspan='4'>Groups</th>
7640     * </tr>
7641     * <tr>
7642     * <td>long</td>
7643     * <td>{@link #_ID}</td>
7644     * <td>read-only</td>
7645     * <td>Row ID. Sync adapter should try to preserve row IDs during updates.
7646     * In other words, it would be a really bad idea to delete and reinsert a
7647     * group. A sync adapter should always do an update instead.</td>
7648     * </tr>
7649     # <tr>
7650     * <td>String</td>
7651     * <td>{@link #DATA_SET}</td>
7652     * <td>read/write-once</td>
7653     * <td>
7654     * <p>
7655     * The data set within the account that this group belongs to.  This allows
7656     * multiple sync adapters for the same account type to distinguish between
7657     * each others' group data.  The combination of {@link #ACCOUNT_TYPE},
7658     * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data
7659     * that is associated with a single sync adapter.
7660     * </p>
7661     * <p>
7662     * This is empty by default, and is completely optional.  It only needs to
7663     * be populated if multiple sync adapters are entering distinct data for
7664     * the same account type and account name.
7665     * </p>
7666     * <p>
7667     * It should be set at the time the group is inserted and never changed
7668     * afterwards.
7669     * </p>
7670     * </td>
7671     * </tr>
7672     * <tr>
7673     * <td>String</td>
7674     * <td>{@link #TITLE}</td>
7675     * <td>read/write</td>
7676     * <td>The display title of this group.</td>
7677     * </tr>
7678     * <tr>
7679     * <td>String</td>
7680     * <td>{@link #NOTES}</td>
7681     * <td>read/write</td>
7682     * <td>Notes about the group.</td>
7683     * </tr>
7684     * <tr>
7685     * <td>String</td>
7686     * <td>{@link #SYSTEM_ID}</td>
7687     * <td>read/write</td>
7688     * <td>The ID of this group if it is a System Group, i.e. a group that has a
7689     * special meaning to the sync adapter, null otherwise.</td>
7690     * </tr>
7691     * <tr>
7692     * <td>int</td>
7693     * <td>{@link #SUMMARY_COUNT}</td>
7694     * <td>read-only</td>
7695     * <td>The total number of {@link Contacts} that have
7696     * {@link CommonDataKinds.GroupMembership} in this group. Read-only value
7697     * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td>
7698     * </tr>
7699     * <tr>
7700     * <td>int</td>
7701     * <td>{@link #SUMMARY_WITH_PHONES}</td>
7702     * <td>read-only</td>
7703     * <td>The total number of {@link Contacts} that have both
7704     * {@link CommonDataKinds.GroupMembership} in this group, and also have
7705     * phone numbers. Read-only value that is only present when querying
7706     * {@link Groups#CONTENT_SUMMARY_URI}.</td>
7707     * </tr>
7708     * <tr>
7709     * <td>int</td>
7710     * <td>{@link #GROUP_VISIBLE}</td>
7711     * <td>read-only</td>
7712     * <td>Flag indicating if the contacts belonging to this group should be
7713     * visible in any user interface. Allowed values: 0 and 1.</td>
7714     * </tr>
7715     * <tr>
7716     * <td>int</td>
7717     * <td>{@link #DELETED}</td>
7718     * <td>read/write</td>
7719     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
7720     * for deletion. When {@link android.content.ContentResolver#delete} is
7721     * called on a group, it is marked for deletion. The sync adaptor deletes
7722     * the group on the server and then calls ContactResolver.delete once more,
7723     * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER}
7724     * query parameter to finalize the data removal.</td>
7725     * </tr>
7726     * <tr>
7727     * <td>int</td>
7728     * <td>{@link #SHOULD_SYNC}</td>
7729     * <td>read/write</td>
7730     * <td>Whether this group should be synced if the SYNC_EVERYTHING settings
7731     * is false for this group's account.</td>
7732     * </tr>
7733     * </table>
7734     */
7735    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
7736        /**
7737         * This utility class cannot be instantiated
7738         */
7739        private Groups() {
7740        }
7741
7742        /**
7743         * The content:// style URI for this table
7744         */
7745        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
7746
7747        /**
7748         * The content:// style URI for this table joined with details data from
7749         * {@link ContactsContract.Data}.
7750         */
7751        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
7752                "groups_summary");
7753
7754        /**
7755         * The MIME type of a directory of groups.
7756         */
7757        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
7758
7759        /**
7760         * The MIME type of a single group.
7761         */
7762        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
7763
7764        public static EntityIterator newEntityIterator(Cursor cursor) {
7765            return new EntityIteratorImpl(cursor);
7766        }
7767
7768        private static class EntityIteratorImpl extends CursorEntityIterator {
7769            public EntityIteratorImpl(Cursor cursor) {
7770                super(cursor);
7771            }
7772
7773            @Override
7774            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
7775                // we expect the cursor is already at the row we need to read from
7776                final ContentValues values = new ContentValues();
7777                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID);
7778                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME);
7779                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE);
7780                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY);
7781                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION);
7782                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID);
7783                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE);
7784                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE);
7785                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES);
7786                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE);
7787                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1);
7788                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2);
7789                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3);
7790                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4);
7791                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID);
7792                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED);
7793                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES);
7794                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC);
7795                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, FAVORITES);
7796                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, AUTO_ADD);
7797                cursor.moveToNext();
7798                return new Entity(values);
7799            }
7800        }
7801    }
7802
7803    /**
7804     * <p>
7805     * Constants for the contact aggregation exceptions table, which contains
7806     * aggregation rules overriding those used by automatic aggregation. This
7807     * type only supports query and update. Neither insert nor delete are
7808     * supported.
7809     * </p>
7810     * <h2>Columns</h2>
7811     * <table class="jd-sumtable">
7812     * <tr>
7813     * <th colspan='4'>AggregationExceptions</th>
7814     * </tr>
7815     * <tr>
7816     * <td>int</td>
7817     * <td>{@link #TYPE}</td>
7818     * <td>read/write</td>
7819     * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER},
7820     * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td>
7821     * </tr>
7822     * <tr>
7823     * <td>long</td>
7824     * <td>{@link #RAW_CONTACT_ID1}</td>
7825     * <td>read/write</td>
7826     * <td>A reference to the {@link RawContacts#_ID} of the raw contact that
7827     * the rule applies to.</td>
7828     * </tr>
7829     * <tr>
7830     * <td>long</td>
7831     * <td>{@link #RAW_CONTACT_ID2}</td>
7832     * <td>read/write</td>
7833     * <td>A reference to the other {@link RawContacts#_ID} of the raw contact
7834     * that the rule applies to.</td>
7835     * </tr>
7836     * </table>
7837     */
7838    public static final class AggregationExceptions implements BaseColumns {
7839        /**
7840         * This utility class cannot be instantiated
7841         */
7842        private AggregationExceptions() {}
7843
7844        /**
7845         * The content:// style URI for this table
7846         */
7847        public static final Uri CONTENT_URI =
7848                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
7849
7850        /**
7851         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
7852         */
7853        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
7854
7855        /**
7856         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
7857         */
7858        public static final String CONTENT_ITEM_TYPE =
7859                "vnd.android.cursor.item/aggregation_exception";
7860
7861        /**
7862         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
7863         * {@link #TYPE_AUTOMATIC}.
7864         *
7865         * <P>Type: INTEGER</P>
7866         */
7867        public static final String TYPE = "type";
7868
7869        /**
7870         * Allows the provider to automatically decide whether the specified raw contacts should
7871         * be included in the same aggregate contact or not.
7872         */
7873        public static final int TYPE_AUTOMATIC = 0;
7874
7875        /**
7876         * Makes sure that the specified raw contacts are included in the same
7877         * aggregate contact.
7878         */
7879        public static final int TYPE_KEEP_TOGETHER = 1;
7880
7881        /**
7882         * Makes sure that the specified raw contacts are NOT included in the same
7883         * aggregate contact.
7884         */
7885        public static final int TYPE_KEEP_SEPARATE = 2;
7886
7887        /**
7888         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
7889         */
7890        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
7891
7892        /**
7893         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
7894         * applies to.
7895         */
7896        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
7897    }
7898
7899    /**
7900     * @see Settings
7901     */
7902    protected interface SettingsColumns {
7903        /**
7904         * The name of the account instance to which this row belongs.
7905         * <P>Type: TEXT</P>
7906         */
7907        public static final String ACCOUNT_NAME = "account_name";
7908
7909        /**
7910         * The type of account to which this row belongs, which when paired with
7911         * {@link #ACCOUNT_NAME} identifies a specific account.
7912         * <P>Type: TEXT</P>
7913         */
7914        public static final String ACCOUNT_TYPE = "account_type";
7915
7916        /**
7917         * The data set within the account that this row belongs to.  This allows
7918         * multiple sync adapters for the same account type to distinguish between
7919         * each others' data.
7920         *
7921         * This is empty by default, and is completely optional.  It only needs to
7922         * be populated if multiple sync adapters are entering distinct data for
7923         * the same account type and account name.
7924         * <P>Type: TEXT</P>
7925         */
7926        public static final String DATA_SET = "data_set";
7927
7928        /**
7929         * Depending on the mode defined by the sync-adapter, this flag controls
7930         * the top-level sync behavior for this data source.
7931         * <p>
7932         * Type: INTEGER (boolean)
7933         */
7934        public static final String SHOULD_SYNC = "should_sync";
7935
7936        /**
7937         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
7938         * entries should be visible in any user interface.
7939         * <p>
7940         * Type: INTEGER (boolean)
7941         */
7942        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
7943
7944        /**
7945         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
7946         * {@link Groups#SHOULD_SYNC} under this account have been marked as
7947         * unsynced.
7948         */
7949        public static final String ANY_UNSYNCED = "any_unsynced";
7950
7951        /**
7952         * Read-only count of {@link Contacts} from a specific source that have
7953         * no {@link CommonDataKinds.GroupMembership} entries.
7954         * <p>
7955         * Type: INTEGER
7956         */
7957        public static final String UNGROUPED_COUNT = "summ_count";
7958
7959        /**
7960         * Read-only count of {@link Contacts} from a specific source that have
7961         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
7962         * <p>
7963         * Type: INTEGER
7964         */
7965        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
7966    }
7967
7968    /**
7969     * <p>
7970     * Contacts-specific settings for various {@link Account}'s.
7971     * </p>
7972     * <h2>Columns</h2>
7973     * <table class="jd-sumtable">
7974     * <tr>
7975     * <th colspan='4'>Settings</th>
7976     * </tr>
7977     * <tr>
7978     * <td>String</td>
7979     * <td>{@link #ACCOUNT_NAME}</td>
7980     * <td>read/write-once</td>
7981     * <td>The name of the account instance to which this row belongs.</td>
7982     * </tr>
7983     * <tr>
7984     * <td>String</td>
7985     * <td>{@link #ACCOUNT_TYPE}</td>
7986     * <td>read/write-once</td>
7987     * <td>The type of account to which this row belongs, which when paired with
7988     * {@link #ACCOUNT_NAME} identifies a specific account.</td>
7989     * </tr>
7990     * <tr>
7991     * <td>int</td>
7992     * <td>{@link #SHOULD_SYNC}</td>
7993     * <td>read/write</td>
7994     * <td>Depending on the mode defined by the sync-adapter, this flag controls
7995     * the top-level sync behavior for this data source.</td>
7996     * </tr>
7997     * <tr>
7998     * <td>int</td>
7999     * <td>{@link #UNGROUPED_VISIBLE}</td>
8000     * <td>read/write</td>
8001     * <td>Flag indicating if contacts without any
8002     * {@link CommonDataKinds.GroupMembership} entries should be visible in any
8003     * user interface.</td>
8004     * </tr>
8005     * <tr>
8006     * <td>int</td>
8007     * <td>{@link #ANY_UNSYNCED}</td>
8008     * <td>read-only</td>
8009     * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any
8010     * {@link Groups#SHOULD_SYNC} under this account have been marked as
8011     * unsynced.</td>
8012     * </tr>
8013     * <tr>
8014     * <td>int</td>
8015     * <td>{@link #UNGROUPED_COUNT}</td>
8016     * <td>read-only</td>
8017     * <td>Read-only count of {@link Contacts} from a specific source that have
8018     * no {@link CommonDataKinds.GroupMembership} entries.</td>
8019     * </tr>
8020     * <tr>
8021     * <td>int</td>
8022     * <td>{@link #UNGROUPED_WITH_PHONES}</td>
8023     * <td>read-only</td>
8024     * <td>Read-only count of {@link Contacts} from a specific source that have
8025     * no {@link CommonDataKinds.GroupMembership} entries, and also have phone
8026     * numbers.</td>
8027     * </tr>
8028     * </table>
8029     */
8030    public static final class Settings implements SettingsColumns {
8031        /**
8032         * This utility class cannot be instantiated
8033         */
8034        private Settings() {
8035        }
8036
8037        /**
8038         * The content:// style URI for this table
8039         */
8040        public static final Uri CONTENT_URI =
8041                Uri.withAppendedPath(AUTHORITY_URI, "settings");
8042
8043        /**
8044         * The MIME-type of {@link #CONTENT_URI} providing a directory of
8045         * settings.
8046         */
8047        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
8048
8049        /**
8050         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
8051         */
8052        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
8053    }
8054
8055    /**
8056     * API for inquiring about the general status of the provider.
8057     */
8058    public static final class ProviderStatus {
8059
8060        /**
8061         * Not instantiable.
8062         */
8063        private ProviderStatus() {
8064        }
8065
8066        /**
8067         * The content:// style URI for this table.  Requests to this URI can be
8068         * performed on the UI thread because they are always unblocking.
8069         */
8070        public static final Uri CONTENT_URI =
8071                Uri.withAppendedPath(AUTHORITY_URI, "provider_status");
8072
8073        /**
8074         * The MIME-type of {@link #CONTENT_URI} providing a directory of
8075         * settings.
8076         */
8077        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status";
8078
8079        /**
8080         * An integer representing the current status of the provider.
8081         */
8082        public static final String STATUS = "status";
8083
8084        /**
8085         * Default status of the provider.
8086         */
8087        public static final int STATUS_NORMAL = 0;
8088
8089        /**
8090         * The provider won't respond to queries. It is in the middle of a long running task, such
8091         * as a database upgrade or locale change.
8092         */
8093        public static final int STATUS_BUSY = 1;
8094
8095        /**
8096         * The status that indicates that there are no accounts and no contacts
8097         * on the device.
8098         */
8099        public static final int STATUS_EMPTY = 2;
8100    }
8101
8102    /**
8103     * <p>
8104     * API allowing applications to send usage information for each {@link Data} row to the
8105     * Contacts Provider.  Applications can also clear all usage information.
8106     * </p>
8107     * <p>
8108     * With the feedback, Contacts Provider may return more contextually appropriate results for
8109     * Data listing, typically supplied with
8110     * {@link ContactsContract.Contacts#CONTENT_FILTER_URI},
8111     * {@link ContactsContract.CommonDataKinds.Email#CONTENT_FILTER_URI},
8112     * {@link ContactsContract.CommonDataKinds.Phone#CONTENT_FILTER_URI}, and users can benefit
8113     * from better ranked (sorted) lists in applications that show auto-complete list.
8114     * </p>
8115     * <p>
8116     * There is no guarantee for how this feedback is used, or even whether it is used at all.
8117     * The ranking algorithm will make best efforts to use the feedback data, but the exact
8118     * implementation, the storage data structures as well as the resulting sort order is device
8119     * and version specific and can change over time.
8120     * </p>
8121     * <p>
8122     * When updating usage information, users of this API need to use
8123     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} with a Uri constructed
8124     * from {@link DataUsageFeedback#FEEDBACK_URI}. The Uri must contain one or more data id(s) as
8125     * its last path. They also need to append a query parameter to the Uri, to specify the type of
8126     * the communication, which enables the Contacts Provider to differentiate between kinds of
8127     * interactions using the same contact data field (for example a phone number can be used to
8128     * make phone calls or send SMS).
8129     * </p>
8130     * <p>
8131     * Selection and selectionArgs are ignored and must be set to null. To get data ids,
8132     * you may need to call {@link ContentResolver#query(Uri, String[], String, String[], String)}
8133     * toward {@link Data#CONTENT_URI}.
8134     * </p>
8135     * <p>
8136     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} returns a positive
8137     * integer when successful, and returns 0 if no contact with that id was found.
8138     * </p>
8139     * <p>
8140     * Example:
8141     * <pre>
8142     * Uri uri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
8143     *         .appendPath(TextUtils.join(",", dataIds))
8144     *         .appendQueryParameter(DataUsageFeedback.USAGE_TYPE,
8145     *                 DataUsageFeedback.USAGE_TYPE_CALL)
8146     *         .build();
8147     * boolean successful = resolver.update(uri, new ContentValues(), null, null) > 0;
8148     * </pre>
8149     * </p>
8150     * <p>
8151     * Applications can also clear all usage information with:
8152     * <pre>
8153     * boolean successful = resolver.delete(DataUsageFeedback.DELETE_USAGE_URI, null, null) > 0;
8154     * </pre>
8155     * </p>
8156     */
8157    public static final class DataUsageFeedback {
8158
8159        /**
8160         * The content:// style URI for sending usage feedback.
8161         * Must be used with {@link ContentResolver#update(Uri, ContentValues, String, String[])}.
8162         */
8163        public static final Uri FEEDBACK_URI =
8164                Uri.withAppendedPath(Data.CONTENT_URI, "usagefeedback");
8165
8166        /**
8167         * The content:// style URI for deleting all usage information.
8168         * Must be used with {@link ContentResolver#delete(Uri, String, String[])}.
8169         * The {@code where} and {@code selectionArgs} parameters are ignored.
8170         */
8171        public static final Uri DELETE_USAGE_URI =
8172                Uri.withAppendedPath(Contacts.CONTENT_URI, "delete_usage");
8173
8174        /**
8175         * <p>
8176         * Name for query parameter specifying the type of data usage.
8177         * </p>
8178         */
8179        public static final String USAGE_TYPE = "type";
8180
8181        /**
8182         * <p>
8183         * Type of usage for voice interaction, which includes phone call, voice chat, and
8184         * video chat.
8185         * </p>
8186         */
8187        public static final String USAGE_TYPE_CALL = "call";
8188
8189        /**
8190         * <p>
8191         * Type of usage for text interaction involving longer messages, which includes email.
8192         * </p>
8193         */
8194        public static final String USAGE_TYPE_LONG_TEXT = "long_text";
8195
8196        /**
8197         * <p>
8198         * Type of usage for text interaction involving shorter messages, which includes SMS,
8199         * text chat with email addresses.
8200         * </p>
8201         */
8202        public static final String USAGE_TYPE_SHORT_TEXT = "short_text";
8203    }
8204
8205    /**
8206     * <p>
8207     * Contact-specific information about whether or not a contact has been pinned by the user
8208     * at a particular position within the system contact application's user interface.
8209     * </p>
8210     *
8211     * <p>
8212     * This pinning information can be used by individual applications to customize how
8213     * they order particular pinned contacts. For example, a Dialer application could
8214     * use pinned information to order user-pinned contacts in a top row of favorites.
8215     * </p>
8216     *
8217     * <p>
8218     * It is possible for two or more contacts to occupy the same pinned position (due
8219     * to aggregation and sync), so this pinning information should be used on a best-effort
8220     * basis to order contacts in-application rather than an absolute guide on where a contact
8221     * should be positioned. Contacts returned by the ContactsProvider will not be ordered based
8222     * on this information, so it is up to the client application to reorder these contacts within
8223     * their own UI adhering to (or ignoring as appropriate) information stored in the pinned
8224     * column.
8225     * </p>
8226     *
8227     * <p>
8228     * By default, unpinned contacts will have a pinned position of
8229     * {@link PinnedPositions#UNPINNED}. Client-provided pinned positions can be positive
8230     * integers that are greater than 1.
8231     * </p>
8232     */
8233    public static final class PinnedPositions {
8234        /**
8235         * The method to invoke in order to undemote a formerly demoted contact. The contact id of
8236         * the contact must be provided as an argument. If the contact was not previously demoted,
8237         * nothing will be done.
8238         * @hide
8239         */
8240        public static final String UNDEMOTE_METHOD = "undemote";
8241
8242        /**
8243         * Undemotes a formerly demoted contact. If the contact was not previously demoted, nothing
8244         * will be done.
8245         *
8246         * @param contentResolver to perform the undemote operation on.
8247         * @param contactId the id of the contact to undemote.
8248         */
8249        public static void undemote(ContentResolver contentResolver, long contactId) {
8250            contentResolver.call(ContactsContract.AUTHORITY_URI, PinnedPositions.UNDEMOTE_METHOD,
8251                    String.valueOf(contactId), null);
8252        }
8253
8254        /**
8255         * Pins a contact at a provided position, or unpins a contact.
8256         *
8257         * @param contentResolver to perform the pinning operation on.
8258         * @param pinnedPosition the position to pin the contact at. To unpin a contact, use
8259         *         {@link PinnedPositions#UNPINNED}.
8260         */
8261        public static void pin(
8262                ContentResolver contentResolver, long contactId, int pinnedPosition) {
8263            final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(contactId));
8264            final ContentValues values = new ContentValues();
8265            values.put(Contacts.PINNED, pinnedPosition);
8266            contentResolver.update(uri, values, null, null);
8267        }
8268
8269        /**
8270         * Default value for the pinned position of an unpinned contact.
8271         */
8272        public static final int UNPINNED = 0;
8273
8274        /**
8275         * Value of pinned position for a contact that a user has indicated should be considered
8276         * of the lowest priority. It is up to the client application to determine how to present
8277         * such a contact - for example all the way at the bottom of a contact list, or simply
8278         * just hidden from view.
8279         */
8280        public static final int DEMOTED = -1;
8281    }
8282
8283    /**
8284     * Helper methods to display QuickContact dialogs that display all the information belonging to
8285     * a specific {@link Contacts} entry.
8286     */
8287    public static final class QuickContact {
8288        /**
8289         * Action used to launch the system contacts application and bring up a QuickContact dialog
8290         * for the provided {@link Contacts} entry.
8291         */
8292        public static final String ACTION_QUICK_CONTACT =
8293                "android.provider.action.QUICK_CONTACT";
8294
8295        /**
8296         * Extra used to specify pivot dialog location in screen coordinates.
8297         * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead.
8298         * @hide
8299         */
8300        @Deprecated
8301        public static final String EXTRA_TARGET_RECT = "android.provider.extra.TARGET_RECT";
8302
8303        /**
8304         * Extra used to specify size of QuickContacts. Not all implementations of QuickContacts
8305         * will respect this extra's value.
8306         *
8307         * One of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
8308         */
8309        public static final String EXTRA_MODE = "android.provider.extra.MODE";
8310
8311        /**
8312         * Extra used to specify which mimetype should be prioritized in the QuickContacts UI.
8313         * For example, passing the value {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can
8314         * cause phone numbers to be displayed more prominently in QuickContacts.
8315         */
8316        public static final String EXTRA_PRIORITIZED_MIMETYPE
8317                = "android.provider.extra.PRIORITIZED_MIMETYPE";
8318
8319        /**
8320         * Extra used to indicate a list of specific MIME-types to exclude and not display in the
8321         * QuickContacts dialog. Stored as a {@link String} array.
8322         */
8323        public static final String EXTRA_EXCLUDE_MIMES = "android.provider.extra.EXCLUDE_MIMES";
8324
8325        /**
8326         * Small QuickContact mode, usually presented with minimal actions.
8327         */
8328        public static final int MODE_SMALL = 1;
8329
8330        /**
8331         * Medium QuickContact mode, includes actions and light summary describing
8332         * the {@link Contacts} entry being shown. This may include social
8333         * status and presence details.
8334         */
8335        public static final int MODE_MEDIUM = 2;
8336
8337        /**
8338         * Large QuickContact mode, includes actions and larger, card-like summary
8339         * of the {@link Contacts} entry being shown. This may include detailed
8340         * information, such as a photo.
8341         */
8342        public static final int MODE_LARGE = 3;
8343
8344        /** @hide */
8345        public static final int MODE_DEFAULT = MODE_LARGE;
8346
8347        /**
8348         * Constructs the QuickContacts intent with a view's rect.
8349         * @hide
8350         */
8351        public static Intent composeQuickContactsIntent(Context context, View target, Uri lookupUri,
8352                int mode, String[] excludeMimes) {
8353            // Find location and bounds of target view, adjusting based on the
8354            // assumed local density.
8355            final float appScale = context.getResources().getCompatibilityInfo().applicationScale;
8356            final int[] pos = new int[2];
8357            target.getLocationOnScreen(pos);
8358
8359            final Rect rect = new Rect();
8360            rect.left = (int) (pos[0] * appScale + 0.5f);
8361            rect.top = (int) (pos[1] * appScale + 0.5f);
8362            rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f);
8363            rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f);
8364
8365            return composeQuickContactsIntent(context, rect, lookupUri, mode, excludeMimes);
8366        }
8367
8368        /**
8369         * Constructs the QuickContacts intent.
8370         * @hide
8371         */
8372        public static Intent composeQuickContactsIntent(Context context, Rect target,
8373                Uri lookupUri, int mode, String[] excludeMimes) {
8374            // When launching from an Activiy, we don't want to start a new task, but otherwise
8375            // we *must* start a new task.  (Otherwise startActivity() would crash.)
8376            Context actualContext = context;
8377            while ((actualContext instanceof ContextWrapper)
8378                    && !(actualContext instanceof Activity)) {
8379                actualContext = ((ContextWrapper) actualContext).getBaseContext();
8380            }
8381            final int intentFlags = ((actualContext instanceof Activity)
8382                    ? 0 : Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
8383                    // Workaround for b/16898764. Declaring singleTop in manifest doesn't work.
8384                    | Intent.FLAG_ACTIVITY_SINGLE_TOP;
8385
8386            // Launch pivot dialog through intent for now
8387            final Intent intent = new Intent(ACTION_QUICK_CONTACT).addFlags(intentFlags);
8388
8389            // NOTE: This logic and rebuildManagedQuickContactsIntent() must be in sync.
8390            intent.setData(lookupUri);
8391            intent.setSourceBounds(target);
8392            intent.putExtra(EXTRA_MODE, mode);
8393            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);
8394            return intent;
8395        }
8396
8397        /**
8398         * Constructs a QuickContacts intent based on an incoming intent for DevicePolicyManager
8399         * to strip off anything not necessary.
8400         *
8401         * @hide
8402         */
8403        public static Intent rebuildManagedQuickContactsIntent(String lookupKey, long contactId,
8404                boolean isContactIdIgnored, long directoryId, Intent originalIntent) {
8405            final Intent intent = new Intent(ACTION_QUICK_CONTACT);
8406            // Rebuild the URI from a lookup key and a contact ID.
8407            Uri uri = null;
8408            if (!TextUtils.isEmpty(lookupKey)) {
8409                uri = isContactIdIgnored
8410                        ? Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey)
8411                        : Contacts.getLookupUri(contactId, lookupKey);
8412            }
8413            if (uri != null && directoryId != Directory.DEFAULT) {
8414                uri = uri.buildUpon().appendQueryParameter(
8415                        ContactsContract.DIRECTORY_PARAM_KEY, String.valueOf(directoryId)).build();
8416            }
8417            intent.setData(uri);
8418
8419            // Copy flags and always set NEW_TASK because it won't have a parent activity.
8420            intent.setFlags(originalIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
8421
8422            // Copy extras.
8423            intent.setSourceBounds(originalIntent.getSourceBounds());
8424            intent.putExtra(EXTRA_MODE, originalIntent.getIntExtra(EXTRA_MODE, MODE_DEFAULT));
8425            intent.putExtra(EXTRA_EXCLUDE_MIMES,
8426                    originalIntent.getStringArrayExtra(EXTRA_EXCLUDE_MIMES));
8427            return intent;
8428        }
8429
8430
8431        /**
8432         * Trigger a dialog that lists the various methods of interacting with
8433         * the requested {@link Contacts} entry. This may be based on available
8434         * {@link ContactsContract.Data} rows under that contact, and may also
8435         * include social status and presence details.
8436         *
8437         * @param context The parent {@link Context} that may be used as the
8438         *            parent for this dialog.
8439         * @param target Specific {@link View} from your layout that this dialog
8440         *            should be centered around. In particular, if the dialog
8441         *            has a "callout" arrow, it will be pointed and centered
8442         *            around this {@link View}.
8443         * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8444         *            {@link Uri} that describes a specific contact to feature
8445         *            in this dialog.
8446         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
8447         *            {@link #MODE_LARGE}, indicating the desired dialog size,
8448         *            when supported.
8449         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8450         *            to exclude when showing this dialog. For example, when
8451         *            already viewing the contact details card, this can be used
8452         *            to omit the details entry from the dialog.
8453         */
8454        public static void showQuickContact(Context context, View target, Uri lookupUri, int mode,
8455                String[] excludeMimes) {
8456            // Trigger with obtained rectangle
8457            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
8458                    excludeMimes);
8459            ContactsInternal.startQuickContactWithErrorToast(context, intent);
8460        }
8461
8462        /**
8463         * Trigger a dialog that lists the various methods of interacting with
8464         * the requested {@link Contacts} entry. This may be based on available
8465         * {@link ContactsContract.Data} rows under that contact, and may also
8466         * include social status and presence details.
8467         *
8468         * @param context The parent {@link Context} that may be used as the
8469         *            parent for this dialog.
8470         * @param target Specific {@link Rect} that this dialog should be
8471         *            centered around, in screen coordinates. In particular, if
8472         *            the dialog has a "callout" arrow, it will be pointed and
8473         *            centered around this {@link Rect}. If you are running at a
8474         *            non-native density, you need to manually adjust using
8475         *            {@link DisplayMetrics#density} before calling.
8476         * @param lookupUri A
8477         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8478         *            {@link Uri} that describes a specific contact to feature
8479         *            in this dialog.
8480         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
8481         *            {@link #MODE_LARGE}, indicating the desired dialog size,
8482         *            when supported.
8483         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8484         *            to exclude when showing this dialog. For example, when
8485         *            already viewing the contact details card, this can be used
8486         *            to omit the details entry from the dialog.
8487         */
8488        public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,
8489                String[] excludeMimes) {
8490            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
8491                    excludeMimes);
8492            ContactsInternal.startQuickContactWithErrorToast(context, intent);
8493        }
8494
8495        /**
8496         * Trigger a dialog that lists the various methods of interacting with
8497         * the requested {@link Contacts} entry. This may be based on available
8498         * {@link ContactsContract.Data} rows under that contact, and may also
8499         * include social status and presence details.
8500         *
8501         * @param context The parent {@link Context} that may be used as the
8502         *            parent for this dialog.
8503         * @param target Specific {@link View} from your layout that this dialog
8504         *            should be centered around. In particular, if the dialog
8505         *            has a "callout" arrow, it will be pointed and centered
8506         *            around this {@link View}.
8507         * @param lookupUri A
8508         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8509         *            {@link Uri} that describes a specific contact to feature
8510         *            in this dialog.
8511         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8512         *            to exclude when showing this dialog. For example, when
8513         *            already viewing the contact details card, this can be used
8514         *            to omit the details entry from the dialog.
8515         * @param prioritizedMimeType This mimetype should be prioritized in the QuickContacts UI.
8516         *             For example, passing the value
8517         *             {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can cause phone numbers to be
8518         *             displayed more prominently in QuickContacts.
8519         */
8520        public static void showQuickContact(Context context, View target, Uri lookupUri,
8521                String[] excludeMimes, String prioritizedMimeType) {
8522            // Use MODE_LARGE instead of accepting mode as a parameter. The different mode
8523            // values defined in ContactsContract only affect very old implementations
8524            // of QuickContacts.
8525            Intent intent = composeQuickContactsIntent(context, target, lookupUri, MODE_DEFAULT,
8526                    excludeMimes);
8527            intent.putExtra(EXTRA_PRIORITIZED_MIMETYPE, prioritizedMimeType);
8528            ContactsInternal.startQuickContactWithErrorToast(context, intent);
8529        }
8530
8531        /**
8532         * Trigger a dialog that lists the various methods of interacting with
8533         * the requested {@link Contacts} entry. This may be based on available
8534         * {@link ContactsContract.Data} rows under that contact, and may also
8535         * include social status and presence details.
8536         *
8537         * @param context The parent {@link Context} that may be used as the
8538         *            parent for this dialog.
8539         * @param target Specific {@link Rect} that this dialog should be
8540         *            centered around, in screen coordinates. In particular, if
8541         *            the dialog has a "callout" arrow, it will be pointed and
8542         *            centered around this {@link Rect}. If you are running at a
8543         *            non-native density, you need to manually adjust using
8544         *            {@link DisplayMetrics#density} before calling.
8545         * @param lookupUri A
8546         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8547         *            {@link Uri} that describes a specific contact to feature
8548         *            in this dialog.
8549         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8550         *            to exclude when showing this dialog. For example, when
8551         *            already viewing the contact details card, this can be used
8552         *            to omit the details entry from the dialog.
8553         * @param prioritizedMimeType This mimetype should be prioritized in the QuickContacts UI.
8554         *             For example, passing the value
8555         *             {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can cause phone numbers to be
8556         *             displayed more prominently in QuickContacts.
8557         */
8558        public static void showQuickContact(Context context, Rect target, Uri lookupUri,
8559                String[] excludeMimes, String prioritizedMimeType) {
8560            // Use MODE_LARGE instead of accepting mode as a parameter. The different mode
8561            // values defined in ContactsContract only affect very old implementations
8562            // of QuickContacts.
8563            Intent intent = composeQuickContactsIntent(context, target, lookupUri, MODE_DEFAULT,
8564                    excludeMimes);
8565            intent.putExtra(EXTRA_PRIORITIZED_MIMETYPE, prioritizedMimeType);
8566            ContactsInternal.startQuickContactWithErrorToast(context, intent);
8567        }
8568    }
8569
8570    /**
8571     * Helper class for accessing full-size photos by photo file ID.
8572     * <p>
8573     * Usage example:
8574     * <dl>
8575     * <dt>Retrieving a full-size photo by photo file ID (see
8576     * {@link ContactsContract.ContactsColumns#PHOTO_FILE_ID})
8577     * </dt>
8578     * <dd>
8579     * <pre>
8580     * public InputStream openDisplayPhoto(long photoFileId) {
8581     *     Uri displayPhotoUri = ContentUris.withAppendedId(DisplayPhoto.CONTENT_URI, photoKey);
8582     *     try {
8583     *         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(
8584     *             displayPhotoUri, "r");
8585     *         return fd.createInputStream();
8586     *     } catch (IOException e) {
8587     *         return null;
8588     *     }
8589     * }
8590     * </pre>
8591     * </dd>
8592     * </dl>
8593     * </p>
8594     */
8595    public static final class DisplayPhoto {
8596        /**
8597         * no public constructor since this is a utility class
8598         */
8599        private DisplayPhoto() {}
8600
8601        /**
8602         * The content:// style URI for this class, which allows access to full-size photos,
8603         * given a key.
8604         */
8605        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "display_photo");
8606
8607        /**
8608         * This URI allows the caller to query for the maximum dimensions of a display photo
8609         * or thumbnail.  Requests to this URI can be performed on the UI thread because
8610         * they are always unblocking.
8611         */
8612        public static final Uri CONTENT_MAX_DIMENSIONS_URI =
8613                Uri.withAppendedPath(AUTHORITY_URI, "photo_dimensions");
8614
8615        /**
8616         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8617         * contain this column, populated with the maximum height and width (in pixels)
8618         * that will be stored for a display photo.  Larger photos will be down-sized to
8619         * fit within a square of this many pixels.
8620         */
8621        public static final String DISPLAY_MAX_DIM = "display_max_dim";
8622
8623        /**
8624         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8625         * contain this column, populated with the height and width (in pixels) for photo
8626         * thumbnails.
8627         */
8628        public static final String THUMBNAIL_MAX_DIM = "thumbnail_max_dim";
8629    }
8630
8631    /**
8632     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
8633     * that involve contacts.
8634     */
8635    public static final class Intents {
8636        /**
8637         * This is the intent that is fired when a search suggestion is clicked on.
8638         */
8639        public static final String SEARCH_SUGGESTION_CLICKED =
8640                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
8641
8642        /**
8643         * This is the intent that is fired when a search suggestion for dialing a number
8644         * is clicked on.
8645         */
8646        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
8647                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
8648
8649        /**
8650         * This is the intent that is fired when a search suggestion for creating a contact
8651         * is clicked on.
8652         */
8653        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
8654                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
8655
8656        /**
8657         * This is the intent that is fired when the contacts database is created. <p> The
8658         * READ_CONTACT permission is required to receive these broadcasts.
8659         */
8660        public static final String CONTACTS_DATABASE_CREATED =
8661                "android.provider.Contacts.DATABASE_CREATED";
8662
8663        /**
8664         * Starts an Activity that lets the user pick a contact to attach an image to.
8665         * After picking the contact it launches the image cropper in face detection mode.
8666         */
8667        public static final String ATTACH_IMAGE =
8668                "com.android.contacts.action.ATTACH_IMAGE";
8669
8670        /**
8671         * This is the intent that is fired when the user clicks the "invite to the network" button
8672         * on a contact.  Only sent to an activity which is explicitly registered by a contact
8673         * provider which supports the "invite to the network" feature.
8674         * <p>
8675         * {@link Intent#getData()} contains the lookup URI for the contact.
8676         */
8677        public static final String INVITE_CONTACT =
8678                "com.android.contacts.action.INVITE_CONTACT";
8679
8680        /**
8681         * Takes as input a data URI with a mailto: or tel: scheme. If a single
8682         * contact exists with the given data it will be shown. If no contact
8683         * exists, a dialog will ask the user if they want to create a new
8684         * contact with the provided details filled in. If multiple contacts
8685         * share the data the user will be prompted to pick which contact they
8686         * want to view.
8687         * <p>
8688         * For <code>mailto:</code> URIs, the scheme specific portion must be a
8689         * raw email address, such as one built using
8690         * {@link Uri#fromParts(String, String, String)}.
8691         * <p>
8692         * For <code>tel:</code> URIs, the scheme specific portion is compared
8693         * to existing numbers using the standard caller ID lookup algorithm.
8694         * The number must be properly encoded, for example using
8695         * {@link Uri#fromParts(String, String, String)}.
8696         * <p>
8697         * Any extras from the {@link Insert} class will be passed along to the
8698         * create activity if there are no contacts to show.
8699         * <p>
8700         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
8701         * prompting the user when the contact doesn't exist.
8702         */
8703        public static final String SHOW_OR_CREATE_CONTACT =
8704                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
8705
8706        /**
8707         * Starts an Activity that lets the user select the multiple phones from a
8708         * list of phone numbers which come from the contacts or
8709         * {@link #EXTRA_PHONE_URIS}.
8710         * <p>
8711         * The phone numbers being passed in through {@link #EXTRA_PHONE_URIS}
8712         * could belong to the contacts or not, and will be selected by default.
8713         * <p>
8714         * The user's selection will be returned from
8715         * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
8716         * if the resultCode is
8717         * {@link android.app.Activity#RESULT_OK}, the array of picked phone
8718         * numbers are in the Intent's
8719         * {@link #EXTRA_PHONE_URIS}; otherwise, the
8720         * {@link android.app.Activity#RESULT_CANCELED} is returned if the user
8721         * left the Activity without changing the selection.
8722         *
8723         * @hide
8724         */
8725        public static final String ACTION_GET_MULTIPLE_PHONES =
8726                "com.android.contacts.action.GET_MULTIPLE_PHONES";
8727
8728        /**
8729         * A broadcast action which is sent when any change has been made to the profile, such
8730         * as the profile name or the picture.  A receiver must have
8731         * the android.permission.READ_PROFILE permission.
8732         *
8733         * @hide
8734         */
8735        public static final String ACTION_PROFILE_CHANGED =
8736                "android.provider.Contacts.PROFILE_CHANGED";
8737
8738        /**
8739         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
8740         * contact if no matching contact found. Otherwise, default behavior is
8741         * to prompt user with dialog before creating.
8742         * <p>
8743         * Type: BOOLEAN
8744         */
8745        public static final String EXTRA_FORCE_CREATE =
8746                "com.android.contacts.action.FORCE_CREATE";
8747
8748        /**
8749         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
8750         * description to be shown when prompting user about creating a new
8751         * contact.
8752         * <p>
8753         * Type: STRING
8754         */
8755        public static final String EXTRA_CREATE_DESCRIPTION =
8756            "com.android.contacts.action.CREATE_DESCRIPTION";
8757
8758        /**
8759         * Used with {@link #ACTION_GET_MULTIPLE_PHONES} as the input or output value.
8760         * <p>
8761         * The phone numbers want to be picked by default should be passed in as
8762         * input value. These phone numbers could belong to the contacts or not.
8763         * <p>
8764         * The phone numbers which were picked by the user are returned as output
8765         * value.
8766         * <p>
8767         * Type: array of URIs, the tel URI is used for the phone numbers which don't
8768         * belong to any contact, the content URI is used for phone id in contacts.
8769         *
8770         * @hide
8771         */
8772        public static final String EXTRA_PHONE_URIS =
8773            "com.android.contacts.extra.PHONE_URIS";
8774
8775        /**
8776         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8777         * dialog location using screen coordinates. When not specified, the
8778         * dialog will be centered.
8779         *
8780         * @hide
8781         */
8782        @Deprecated
8783        public static final String EXTRA_TARGET_RECT = "target_rect";
8784
8785        /**
8786         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8787         * desired dialog style, usually a variation on size. One of
8788         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
8789         *
8790         * @hide
8791         */
8792        @Deprecated
8793        public static final String EXTRA_MODE = "mode";
8794
8795        /**
8796         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
8797         *
8798         * @hide
8799         */
8800        @Deprecated
8801        public static final int MODE_SMALL = 1;
8802
8803        /**
8804         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
8805         *
8806         * @hide
8807         */
8808        @Deprecated
8809        public static final int MODE_MEDIUM = 2;
8810
8811        /**
8812         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
8813         *
8814         * @hide
8815         */
8816        @Deprecated
8817        public static final int MODE_LARGE = 3;
8818
8819        /**
8820         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
8821         * a list of specific MIME-types to exclude and not display. Stored as a
8822         * {@link String} array.
8823         *
8824         * @hide
8825         */
8826        @Deprecated
8827        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
8828
8829        /**
8830         * Convenience class that contains string constants used
8831         * to create contact {@link android.content.Intent Intents}.
8832         */
8833        public static final class Insert {
8834            /** The action code to use when adding a contact */
8835            public static final String ACTION = Intent.ACTION_INSERT;
8836
8837            /**
8838             * If present, forces a bypass of quick insert mode.
8839             */
8840            public static final String FULL_MODE = "full_mode";
8841
8842            /**
8843             * The extra field for the contact name.
8844             * <P>Type: String</P>
8845             */
8846            public static final String NAME = "name";
8847
8848            // TODO add structured name values here.
8849
8850            /**
8851             * The extra field for the contact phonetic name.
8852             * <P>Type: String</P>
8853             */
8854            public static final String PHONETIC_NAME = "phonetic_name";
8855
8856            /**
8857             * The extra field for the contact company.
8858             * <P>Type: String</P>
8859             */
8860            public static final String COMPANY = "company";
8861
8862            /**
8863             * The extra field for the contact job title.
8864             * <P>Type: String</P>
8865             */
8866            public static final String JOB_TITLE = "job_title";
8867
8868            /**
8869             * The extra field for the contact notes.
8870             * <P>Type: String</P>
8871             */
8872            public static final String NOTES = "notes";
8873
8874            /**
8875             * The extra field for the contact phone number.
8876             * <P>Type: String</P>
8877             */
8878            public static final String PHONE = "phone";
8879
8880            /**
8881             * The extra field for the contact phone number type.
8882             * <P>Type: Either an integer value from
8883             * {@link CommonDataKinds.Phone},
8884             *  or a string specifying a custom label.</P>
8885             */
8886            public static final String PHONE_TYPE = "phone_type";
8887
8888            /**
8889             * The extra field for the phone isprimary flag.
8890             * <P>Type: boolean</P>
8891             */
8892            public static final String PHONE_ISPRIMARY = "phone_isprimary";
8893
8894            /**
8895             * The extra field for an optional second contact phone number.
8896             * <P>Type: String</P>
8897             */
8898            public static final String SECONDARY_PHONE = "secondary_phone";
8899
8900            /**
8901             * The extra field for an optional second contact phone number type.
8902             * <P>Type: Either an integer value from
8903             * {@link CommonDataKinds.Phone},
8904             *  or a string specifying a custom label.</P>
8905             */
8906            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
8907
8908            /**
8909             * The extra field for an optional third contact phone number.
8910             * <P>Type: String</P>
8911             */
8912            public static final String TERTIARY_PHONE = "tertiary_phone";
8913
8914            /**
8915             * The extra field for an optional third contact phone number type.
8916             * <P>Type: Either an integer value from
8917             * {@link CommonDataKinds.Phone},
8918             *  or a string specifying a custom label.</P>
8919             */
8920            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
8921
8922            /**
8923             * The extra field for the contact email address.
8924             * <P>Type: String</P>
8925             */
8926            public static final String EMAIL = "email";
8927
8928            /**
8929             * The extra field for the contact email type.
8930             * <P>Type: Either an integer value from
8931             * {@link CommonDataKinds.Email}
8932             *  or a string specifying a custom label.</P>
8933             */
8934            public static final String EMAIL_TYPE = "email_type";
8935
8936            /**
8937             * The extra field for the email isprimary flag.
8938             * <P>Type: boolean</P>
8939             */
8940            public static final String EMAIL_ISPRIMARY = "email_isprimary";
8941
8942            /**
8943             * The extra field for an optional second contact email address.
8944             * <P>Type: String</P>
8945             */
8946            public static final String SECONDARY_EMAIL = "secondary_email";
8947
8948            /**
8949             * The extra field for an optional second contact email type.
8950             * <P>Type: Either an integer value from
8951             * {@link CommonDataKinds.Email}
8952             *  or a string specifying a custom label.</P>
8953             */
8954            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
8955
8956            /**
8957             * The extra field for an optional third contact email address.
8958             * <P>Type: String</P>
8959             */
8960            public static final String TERTIARY_EMAIL = "tertiary_email";
8961
8962            /**
8963             * The extra field for an optional third contact email type.
8964             * <P>Type: Either an integer value from
8965             * {@link CommonDataKinds.Email}
8966             *  or a string specifying a custom label.</P>
8967             */
8968            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
8969
8970            /**
8971             * The extra field for the contact postal address.
8972             * <P>Type: String</P>
8973             */
8974            public static final String POSTAL = "postal";
8975
8976            /**
8977             * The extra field for the contact postal address type.
8978             * <P>Type: Either an integer value from
8979             * {@link CommonDataKinds.StructuredPostal}
8980             *  or a string specifying a custom label.</P>
8981             */
8982            public static final String POSTAL_TYPE = "postal_type";
8983
8984            /**
8985             * The extra field for the postal isprimary flag.
8986             * <P>Type: boolean</P>
8987             */
8988            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
8989
8990            /**
8991             * The extra field for an IM handle.
8992             * <P>Type: String</P>
8993             */
8994            public static final String IM_HANDLE = "im_handle";
8995
8996            /**
8997             * The extra field for the IM protocol
8998             */
8999            public static final String IM_PROTOCOL = "im_protocol";
9000
9001            /**
9002             * The extra field for the IM isprimary flag.
9003             * <P>Type: boolean</P>
9004             */
9005            public static final String IM_ISPRIMARY = "im_isprimary";
9006
9007            /**
9008             * The extra field that allows the client to supply multiple rows of
9009             * arbitrary data for a single contact created using the {@link Intent#ACTION_INSERT}
9010             * or edited using {@link Intent#ACTION_EDIT}. It is an ArrayList of
9011             * {@link ContentValues}, one per data row. Supplying this extra is
9012             * similar to inserting multiple rows into the {@link Data} table,
9013             * except the user gets a chance to see and edit them before saving.
9014             * Each ContentValues object must have a value for {@link Data#MIMETYPE}.
9015             * If supplied values are not visible in the editor UI, they will be
9016             * dropped.  Duplicate data will dropped.  Some fields
9017             * like {@link CommonDataKinds.Email#TYPE Email.TYPE} may be automatically
9018             * adjusted to comply with the constraints of the specific account type.
9019             * For example, an Exchange contact can only have one phone numbers of type Home,
9020             * so the contact editor may choose a different type for this phone number to
9021             * avoid dropping the valueable part of the row, which is the phone number.
9022             * <p>
9023             * Example:
9024             * <pre>
9025             *  ArrayList&lt;ContentValues&gt; data = new ArrayList&lt;ContentValues&gt;();
9026             *
9027             *  ContentValues row1 = new ContentValues();
9028             *  row1.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
9029             *  row1.put(Organization.COMPANY, "Android");
9030             *  data.add(row1);
9031             *
9032             *  ContentValues row2 = new ContentValues();
9033             *  row2.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
9034             *  row2.put(Email.TYPE, Email.TYPE_CUSTOM);
9035             *  row2.put(Email.LABEL, "Green Bot");
9036             *  row2.put(Email.ADDRESS, "android@android.com");
9037             *  data.add(row2);
9038             *
9039             *  Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
9040             *  intent.putParcelableArrayListExtra(Insert.DATA, data);
9041             *
9042             *  startActivity(intent);
9043             * </pre>
9044             */
9045            public static final String DATA = "data";
9046
9047            /**
9048             * Used to specify the account in which to create the new contact.
9049             * <p>
9050             * If this value is not provided, the user is presented with a disambiguation
9051             * dialog to chose an account
9052             * <p>
9053             * Type: {@link Account}
9054             */
9055            public static final String EXTRA_ACCOUNT = "android.provider.extra.ACCOUNT";
9056
9057            /**
9058             * Used to specify the data set within the account in which to create the
9059             * new contact.
9060             * <p>
9061             * This value is optional - if it is not specified, the contact will be
9062             * created in the base account, with no data set.
9063             * <p>
9064             * Type: String
9065             */
9066            public static final String EXTRA_DATA_SET = "android.provider.extra.DATA_SET";
9067        }
9068    }
9069
9070    /**
9071     * @hide
9072     */
9073    @SystemApi
9074    protected interface MetadataSyncColumns {
9075
9076        /**
9077         * The raw contact backup id.
9078         * A reference to the {@link ContactsContract.RawContacts#BACKUP_ID} that save the
9079         * persistent unique id for each raw contact within its source system.
9080         */
9081        public static final String RAW_CONTACT_BACKUP_ID = "raw_contact_backup_id";
9082
9083        /**
9084         * The account type to which the raw_contact of this item is associated. See
9085         * {@link RawContacts#ACCOUNT_TYPE}
9086         */
9087        public static final String ACCOUNT_TYPE = "account_type";
9088
9089        /**
9090         * The account name to which the raw_contact of this item is associated. See
9091         * {@link RawContacts#ACCOUNT_NAME}
9092         */
9093        public static final String ACCOUNT_NAME = "account_name";
9094
9095        /**
9096         * The data set within the account that the raw_contact of this row belongs to. This allows
9097         * multiple sync adapters for the same account type to distinguish between
9098         * each others' data.
9099         * {@link RawContacts#DATA_SET}
9100         */
9101        public static final String DATA_SET = "data_set";
9102
9103        /**
9104         * A text column contains the Json string got from People API. The Json string contains
9105         * all the metadata related to the raw contact, i.e., all the data fields and
9106         * aggregation exceptions.
9107         *
9108         * Here is an example of the Json string got from the actual schema.
9109         * <pre>
9110         *     {
9111         *       "unique_contact_id": {
9112         *         "account_type": "CUSTOM_ACCOUNT",
9113         *         "custom_account_type": "facebook",
9114         *         "account_name": "android-test",
9115         *         "contact_id": "1111111",
9116         *         "data_set": "FOCUS"
9117         *       },
9118         *       "contact_prefs": {
9119         *         "send_to_voicemail": true,
9120         *         "starred": false,
9121         *         "pinned": 2
9122         *       },
9123         *       "aggregation_data": [
9124         *         {
9125         *           "type": "TOGETHER",
9126         *           "contact_ids": [
9127         *             {
9128         *               "account_type": "GOOGLE_ACCOUNT",
9129         *               "account_name": "android-test2",
9130         *               "contact_id": "2222222",
9131         *               "data_set": "GOOGLE_PLUS"
9132         *             },
9133         *             {
9134         *               "account_type": "GOOGLE_ACCOUNT",
9135         *               "account_name": "android-test3",
9136         *               "contact_id": "3333333",
9137         *               "data_set": "CUSTOM",
9138         *               "custom_data_set": "custom type"
9139         *             }
9140         *           ]
9141         *         }
9142         *       ],
9143         *       "field_data": [
9144         *         {
9145         *           "field_data_id": "1001",
9146         *           "field_data_prefs": {
9147         *             "is_primary": true,
9148         *             "is_super_primary": true
9149         *           },
9150         *           "usage_stats": [
9151         *             {
9152         *               "usage_type": "CALL",
9153         *               "last_time_used": 10000001,
9154         *               "usage_count": 10
9155         *             }
9156         *           ]
9157         *         }
9158         *       ]
9159         *     }
9160         * </pre>
9161         */
9162        public static final String DATA = "data";
9163
9164        /**
9165         * The "deleted" flag: "0" by default, "1" if the row has been marked
9166         * for deletion. When {@link android.content.ContentResolver#delete} is
9167         * called on a raw contact, updating MetadataSync table to set the flag of the raw contact
9168         * as "1", then metadata sync adapter deletes the raw contact metadata on the server.
9169         * <P>Type: INTEGER</P>
9170         */
9171        public static final String DELETED = "deleted";
9172    }
9173
9174    /**
9175     * Constants for the metadata sync table. This table is used to cache the metadata_sync data
9176     * from server before it is merged into other CP2 tables.
9177     *
9178     * @hide
9179     */
9180    @SystemApi
9181    public static final class MetadataSync implements BaseColumns, MetadataSyncColumns {
9182
9183        /** The authority for the contacts metadata */
9184        public static final String METADATA_AUTHORITY = "com.android.contacts.metadata";
9185
9186        /** A content:// style uri to the authority for the contacts metadata */
9187        public static final Uri METADATA_AUTHORITY_URI = Uri.parse(
9188                "content://" + METADATA_AUTHORITY);
9189
9190        /**
9191         * This utility class cannot be instantiated
9192         */
9193        private MetadataSync() {
9194        }
9195
9196        /**
9197         * The content:// style URI for this table.
9198         */
9199        public static final Uri CONTENT_URI = Uri.withAppendedPath(METADATA_AUTHORITY_URI,
9200                "metadata_sync");
9201
9202        /**
9203         * The MIME type of {@link #CONTENT_URI} providing a directory of contact metadata
9204         */
9205        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact_metadata";
9206
9207        /**
9208         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single contact metadata.
9209         */
9210        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_metadata";
9211    }
9212
9213    /**
9214     * @hide
9215     */
9216    @SystemApi
9217    protected interface MetadataSyncStateColumns {
9218
9219        /**
9220         * A reference to the name of the account to which this state belongs
9221         * <P>Type: STRING</P>
9222         */
9223        public static final String ACCOUNT_TYPE = "account_type";
9224
9225        /**
9226         * A reference to the type of the account to which this state belongs
9227         * <P>Type: STRING</P>
9228         */
9229        public static final String ACCOUNT_NAME = "account_name";
9230
9231        /**
9232         * A reference to the data set within the account to which this state belongs
9233         * <P>Type: STRING</P>
9234         */
9235        public static final String DATA_SET = "data_set";
9236
9237        /**
9238         * The sync state associated with this account.
9239         * <P>Type: Blob</P>
9240         */
9241        public static final String STATE = "state";
9242    }
9243
9244    /**
9245     * Constants for the metadata_sync_state table. This table is used to store the metadata
9246     * sync state for a set of accounts.
9247     *
9248     * @hide
9249     */
9250    @SystemApi
9251    public static final class MetadataSyncState implements BaseColumns, MetadataSyncStateColumns {
9252
9253        /**
9254         * This utility class cannot be instantiated
9255         */
9256        private MetadataSyncState() {
9257        }
9258
9259        /**
9260         * The content:// style URI for this table.
9261         */
9262        public static final Uri CONTENT_URI =
9263                Uri.withAppendedPath(MetadataSync.METADATA_AUTHORITY_URI, "metadata_sync_state");
9264
9265        /**
9266         * The MIME type of {@link #CONTENT_URI} providing a directory of contact metadata sync
9267         * states.
9268         */
9269        public static final String CONTENT_TYPE =
9270                "vnd.android.cursor.dir/contact_metadata_sync_state";
9271
9272        /**
9273         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single contact metadata sync
9274         * state.
9275         */
9276        public static final String CONTENT_ITEM_TYPE =
9277                "vnd.android.cursor.item/contact_metadata_sync_state";
9278    }
9279}
9280