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