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