ContactsContract.java revision 7150e1a9e20e1c3b32b759aa13357487930ae9e2
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) {
5967                    return (label != null ? label : "");
5968                } else if (type == TYPE_ASSISTANT && !TextUtils.isEmpty(label)) {
5969                    return label;
5970                } else {
5971                    final int labelRes = getTypeLabelResource(type);
5972                    return res.getText(labelRes);
5973                }
5974            }
5975        }
5976
5977        /**
5978         * <p>
5979         * A data kind representing an email address.
5980         * </p>
5981         * <p>
5982         * You can use all columns defined for {@link ContactsContract.Data} as
5983         * well as the following aliases.
5984         * </p>
5985         * <h2>Column aliases</h2>
5986         * <table class="jd-sumtable">
5987         * <tr>
5988         * <th>Type</th>
5989         * <th>Alias</th><th colspan='2'>Data column</th>
5990         * </tr>
5991         * <tr>
5992         * <td>String</td>
5993         * <td>{@link #ADDRESS}</td>
5994         * <td>{@link #DATA1}</td>
5995         * <td>Email address itself.</td>
5996         * </tr>
5997         * <tr>
5998         * <td>int</td>
5999         * <td>{@link #TYPE}</td>
6000         * <td>{@link #DATA2}</td>
6001         * <td>Allowed values are:
6002         * <p>
6003         * <ul>
6004         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6005         * <li>{@link #TYPE_HOME}</li>
6006         * <li>{@link #TYPE_WORK}</li>
6007         * <li>{@link #TYPE_OTHER}</li>
6008         * <li>{@link #TYPE_MOBILE}</li>
6009         * </ul>
6010         * </p>
6011         * </td>
6012         * </tr>
6013         * <tr>
6014         * <td>String</td>
6015         * <td>{@link #LABEL}</td>
6016         * <td>{@link #DATA3}</td>
6017         * <td></td>
6018         * </tr>
6019         * </table>
6020         */
6021        public static final class Email implements DataColumnsWithJoins, CommonColumns,
6022                ContactCounts {
6023            /**
6024             * This utility class cannot be instantiated
6025             */
6026            private Email() {}
6027
6028            /** MIME type used when storing this in data table. */
6029            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
6030
6031            /**
6032             * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses.
6033             */
6034            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";
6035
6036            /**
6037             * The content:// style URI for all data records of the
6038             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
6039             * associated raw contact and aggregate contact data.
6040             */
6041            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
6042                    "emails");
6043
6044            /**
6045             * <p>
6046             * The content:// style URL for looking up data rows by email address. The
6047             * lookup argument, an email address, should be passed as an additional path segment
6048             * after this URI.
6049             * </p>
6050             * <p>Example:
6051             * <pre>
6052             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email));
6053             * Cursor c = getContentResolver().query(uri,
6054             *          new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
6055             *          null, null, null);
6056             * </pre>
6057             * </p>
6058             */
6059            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
6060                    "lookup");
6061
6062            /**
6063            * <p>URI used for enterprise email lookup.</p>
6064            *
6065            * <p>
6066            * It supports the same semantics as {@link #CONTENT_LOOKUP_URI} and returns the same
6067            * columns.  If the device has no corp profile that is linked to the current profile, it
6068            * behaves in the exact same way as {@link #CONTENT_LOOKUP_URI}.  If there is a
6069            * corp profile linked to the current profile, it first queries against the personal contact database,
6070            * and if no matching contacts are found there, then queries against the
6071            * corp contacts database.
6072            * </p>
6073            * <p>
6074            * If a result is from the corp profile, it makes the following changes to the data:
6075            * <ul>
6076            *     <li>
6077            *     {@link #PHOTO_THUMBNAIL_URI} and {@link #PHOTO_URI} will be rewritten to special
6078            *     URIs.  Use {@link ContentResolver#openAssetFileDescriptor} or its siblings to
6079            *     load pictures from them.
6080            *     {@link #PHOTO_ID} and {@link #PHOTO_FILE_ID} will be set to null.  Do not
6081            *     use them.
6082            *     </li>
6083            *     <li>
6084            *     Corp contacts will get artificial {@link #CONTACT_ID}s.  In order to tell whether
6085            *     a contact
6086            *     is from the corp profile, use
6087            *     {@link ContactsContract.Contacts#isEnterpriseContactId(long)}.
6088             *     </li>
6089             *     <li>
6090             *     Corp contacts will get artificial {@link #LOOKUP_KEY}s too.
6091             *     </li>
6092             * </ul>
6093             * <p>
6094             * A contact lookup URL built by
6095             * {@link ContactsContract.Contacts#getLookupUri(long, String)}
6096             * with an {@link #_ID} and a {@link #LOOKUP_KEY} returned by this API can be passed to
6097             * {@link ContactsContract.QuickContact#showQuickContact} even if a contact is from the
6098             * corp profile.
6099             * </p>
6100            *
6101            * <pre>
6102            * Uri lookupUri = Uri.withAppendedPath(Email.ENTERPRISE_CONTENT_LOOKUP_URI,
6103            *         Uri.encode(email));
6104            * </pre>
6105            */
6106            public static final Uri ENTERPRISE_CONTENT_LOOKUP_URI =
6107                    Uri.withAppendedPath(CONTENT_URI, "lookup_enterprise");
6108
6109            /**
6110             * <p>
6111             * The content:// style URL for email lookup using a filter. The filter returns
6112             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
6113             * to display names as well as email addresses. The filter argument should be passed
6114             * as an additional path segment after this URI.
6115             * </p>
6116             * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)"
6117             * as well as "Bob Parr (incredible@android.com)".
6118             * <pre>
6119             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
6120             * Cursor c = getContentResolver().query(uri,
6121             *          new String[]{Email.DISPLAY_NAME, Email.DATA},
6122             *          null, null, null);
6123             * </pre>
6124             * </p>
6125             */
6126            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
6127                    "filter");
6128
6129            /**
6130             * The email address.
6131             * <P>Type: TEXT</P>
6132             */
6133            public static final String ADDRESS = DATA1;
6134
6135            public static final int TYPE_HOME = 1;
6136            public static final int TYPE_WORK = 2;
6137            public static final int TYPE_OTHER = 3;
6138            public static final int TYPE_MOBILE = 4;
6139
6140            /**
6141             * The display name for the email address
6142             * <P>Type: TEXT</P>
6143             */
6144            public static final String DISPLAY_NAME = DATA4;
6145
6146            /**
6147             * Return the string resource that best describes the given
6148             * {@link #TYPE}. Will always return a valid resource.
6149             */
6150            public static final int getTypeLabelResource(int type) {
6151                switch (type) {
6152                    case TYPE_HOME: return com.android.internal.R.string.emailTypeHome;
6153                    case TYPE_WORK: return com.android.internal.R.string.emailTypeWork;
6154                    case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther;
6155                    case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile;
6156                    default: return com.android.internal.R.string.emailTypeCustom;
6157                }
6158            }
6159
6160            /**
6161             * Return a {@link CharSequence} that best describes the given type,
6162             * possibly substituting the given {@link #LABEL} value
6163             * for {@link #TYPE_CUSTOM}.
6164             */
6165            public static final CharSequence getTypeLabel(Resources res, int type,
6166                    CharSequence label) {
6167                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6168                    return label;
6169                } else {
6170                    final int labelRes = getTypeLabelResource(type);
6171                    return res.getText(labelRes);
6172                }
6173            }
6174        }
6175
6176        /**
6177         * <p>
6178         * A data kind representing a postal addresses.
6179         * </p>
6180         * <p>
6181         * You can use all columns defined for {@link ContactsContract.Data} as
6182         * well as the following aliases.
6183         * </p>
6184         * <h2>Column aliases</h2>
6185         * <table class="jd-sumtable">
6186         * <tr>
6187         * <th>Type</th>
6188         * <th>Alias</th><th colspan='2'>Data column</th>
6189         * </tr>
6190         * <tr>
6191         * <td>String</td>
6192         * <td>{@link #FORMATTED_ADDRESS}</td>
6193         * <td>{@link #DATA1}</td>
6194         * <td></td>
6195         * </tr>
6196         * <tr>
6197         * <td>int</td>
6198         * <td>{@link #TYPE}</td>
6199         * <td>{@link #DATA2}</td>
6200         * <td>Allowed values are:
6201         * <p>
6202         * <ul>
6203         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6204         * <li>{@link #TYPE_HOME}</li>
6205         * <li>{@link #TYPE_WORK}</li>
6206         * <li>{@link #TYPE_OTHER}</li>
6207         * </ul>
6208         * </p>
6209         * </td>
6210         * </tr>
6211         * <tr>
6212         * <td>String</td>
6213         * <td>{@link #LABEL}</td>
6214         * <td>{@link #DATA3}</td>
6215         * <td></td>
6216         * </tr>
6217         * <tr>
6218         * <td>String</td>
6219         * <td>{@link #STREET}</td>
6220         * <td>{@link #DATA4}</td>
6221         * <td></td>
6222         * </tr>
6223         * <tr>
6224         * <td>String</td>
6225         * <td>{@link #POBOX}</td>
6226         * <td>{@link #DATA5}</td>
6227         * <td>Post Office Box number</td>
6228         * </tr>
6229         * <tr>
6230         * <td>String</td>
6231         * <td>{@link #NEIGHBORHOOD}</td>
6232         * <td>{@link #DATA6}</td>
6233         * <td></td>
6234         * </tr>
6235         * <tr>
6236         * <td>String</td>
6237         * <td>{@link #CITY}</td>
6238         * <td>{@link #DATA7}</td>
6239         * <td></td>
6240         * </tr>
6241         * <tr>
6242         * <td>String</td>
6243         * <td>{@link #REGION}</td>
6244         * <td>{@link #DATA8}</td>
6245         * <td></td>
6246         * </tr>
6247         * <tr>
6248         * <td>String</td>
6249         * <td>{@link #POSTCODE}</td>
6250         * <td>{@link #DATA9}</td>
6251         * <td></td>
6252         * </tr>
6253         * <tr>
6254         * <td>String</td>
6255         * <td>{@link #COUNTRY}</td>
6256         * <td>{@link #DATA10}</td>
6257         * <td></td>
6258         * </tr>
6259         * </table>
6260         */
6261        public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns,
6262                ContactCounts {
6263            /**
6264             * This utility class cannot be instantiated
6265             */
6266            private StructuredPostal() {
6267            }
6268
6269            /** MIME type used when storing this in data table. */
6270            public static final String CONTENT_ITEM_TYPE =
6271                    "vnd.android.cursor.item/postal-address_v2";
6272
6273            /**
6274             * The MIME type of {@link #CONTENT_URI} providing a directory of
6275             * postal addresses.
6276             */
6277            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
6278
6279            /**
6280             * The content:// style URI for all data records of the
6281             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
6282             */
6283            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
6284                    "postals");
6285
6286            public static final int TYPE_HOME = 1;
6287            public static final int TYPE_WORK = 2;
6288            public static final int TYPE_OTHER = 3;
6289
6290            /**
6291             * The full, unstructured postal address. <i>This field must be
6292             * consistent with any structured data.</i>
6293             * <p>
6294             * Type: TEXT
6295             */
6296            public static final String FORMATTED_ADDRESS = DATA;
6297
6298            /**
6299             * Can be street, avenue, road, etc. This element also includes the
6300             * house number and room/apartment/flat/floor number.
6301             * <p>
6302             * Type: TEXT
6303             */
6304            public static final String STREET = DATA4;
6305
6306            /**
6307             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
6308             * usually but not always mutually exclusive with street.
6309             * <p>
6310             * Type: TEXT
6311             */
6312            public static final String POBOX = DATA5;
6313
6314            /**
6315             * This is used to disambiguate a street address when a city
6316             * contains more than one street with the same name, or to specify a
6317             * small place whose mail is routed through a larger postal town. In
6318             * China it could be a county or a minor city.
6319             * <p>
6320             * Type: TEXT
6321             */
6322            public static final String NEIGHBORHOOD = DATA6;
6323
6324            /**
6325             * Can be city, village, town, borough, etc. This is the postal town
6326             * and not necessarily the place of residence or place of business.
6327             * <p>
6328             * Type: TEXT
6329             */
6330            public static final String CITY = DATA7;
6331
6332            /**
6333             * A state, province, county (in Ireland), Land (in Germany),
6334             * departement (in France), etc.
6335             * <p>
6336             * Type: TEXT
6337             */
6338            public static final String REGION = DATA8;
6339
6340            /**
6341             * Postal code. Usually country-wide, but sometimes specific to the
6342             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
6343             * <p>
6344             * Type: TEXT
6345             */
6346            public static final String POSTCODE = DATA9;
6347
6348            /**
6349             * The name or code of the country.
6350             * <p>
6351             * Type: TEXT
6352             */
6353            public static final String COUNTRY = DATA10;
6354
6355            /**
6356             * Return the string resource that best describes the given
6357             * {@link #TYPE}. Will always return a valid resource.
6358             */
6359            public static final int getTypeLabelResource(int type) {
6360                switch (type) {
6361                    case TYPE_HOME: return com.android.internal.R.string.postalTypeHome;
6362                    case TYPE_WORK: return com.android.internal.R.string.postalTypeWork;
6363                    case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther;
6364                    default: return com.android.internal.R.string.postalTypeCustom;
6365                }
6366            }
6367
6368            /**
6369             * Return a {@link CharSequence} that best describes the given type,
6370             * possibly substituting the given {@link #LABEL} value
6371             * for {@link #TYPE_CUSTOM}.
6372             */
6373            public static final CharSequence getTypeLabel(Resources res, int type,
6374                    CharSequence label) {
6375                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6376                    return label;
6377                } else {
6378                    final int labelRes = getTypeLabelResource(type);
6379                    return res.getText(labelRes);
6380                }
6381            }
6382        }
6383
6384        /**
6385         * <p>
6386         * A data kind representing an IM address
6387         * </p>
6388         * <p>
6389         * You can use all columns defined for {@link ContactsContract.Data} as
6390         * well as the following aliases.
6391         * </p>
6392         * <h2>Column aliases</h2>
6393         * <table class="jd-sumtable">
6394         * <tr>
6395         * <th>Type</th>
6396         * <th>Alias</th><th colspan='2'>Data column</th>
6397         * </tr>
6398         * <tr>
6399         * <td>String</td>
6400         * <td>{@link #DATA}</td>
6401         * <td>{@link #DATA1}</td>
6402         * <td></td>
6403         * </tr>
6404         * <tr>
6405         * <td>int</td>
6406         * <td>{@link #TYPE}</td>
6407         * <td>{@link #DATA2}</td>
6408         * <td>Allowed values are:
6409         * <p>
6410         * <ul>
6411         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6412         * <li>{@link #TYPE_HOME}</li>
6413         * <li>{@link #TYPE_WORK}</li>
6414         * <li>{@link #TYPE_OTHER}</li>
6415         * </ul>
6416         * </p>
6417         * </td>
6418         * </tr>
6419         * <tr>
6420         * <td>String</td>
6421         * <td>{@link #LABEL}</td>
6422         * <td>{@link #DATA3}</td>
6423         * <td></td>
6424         * </tr>
6425         * <tr>
6426         * <td>String</td>
6427         * <td>{@link #PROTOCOL}</td>
6428         * <td>{@link #DATA5}</td>
6429         * <td>
6430         * <p>
6431         * Allowed values:
6432         * <ul>
6433         * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name
6434         * as {@link #CUSTOM_PROTOCOL}.</li>
6435         * <li>{@link #PROTOCOL_AIM}</li>
6436         * <li>{@link #PROTOCOL_MSN}</li>
6437         * <li>{@link #PROTOCOL_YAHOO}</li>
6438         * <li>{@link #PROTOCOL_SKYPE}</li>
6439         * <li>{@link #PROTOCOL_QQ}</li>
6440         * <li>{@link #PROTOCOL_GOOGLE_TALK}</li>
6441         * <li>{@link #PROTOCOL_ICQ}</li>
6442         * <li>{@link #PROTOCOL_JABBER}</li>
6443         * <li>{@link #PROTOCOL_NETMEETING}</li>
6444         * </ul>
6445         * </p>
6446         * </td>
6447         * </tr>
6448         * <tr>
6449         * <td>String</td>
6450         * <td>{@link #CUSTOM_PROTOCOL}</td>
6451         * <td>{@link #DATA6}</td>
6452         * <td></td>
6453         * </tr>
6454         * </table>
6455         */
6456        public static final class Im implements DataColumnsWithJoins, CommonColumns, ContactCounts {
6457            /**
6458             * This utility class cannot be instantiated
6459             */
6460            private Im() {}
6461
6462            /** MIME type used when storing this in data table. */
6463            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
6464
6465            public static final int TYPE_HOME = 1;
6466            public static final int TYPE_WORK = 2;
6467            public static final int TYPE_OTHER = 3;
6468
6469            /**
6470             * This column should be populated with one of the defined
6471             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
6472             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
6473             * should contain the name of the custom protocol.
6474             */
6475            public static final String PROTOCOL = DATA5;
6476
6477            public static final String CUSTOM_PROTOCOL = DATA6;
6478
6479            /*
6480             * The predefined IM protocol types.
6481             */
6482            public static final int PROTOCOL_CUSTOM = -1;
6483            public static final int PROTOCOL_AIM = 0;
6484            public static final int PROTOCOL_MSN = 1;
6485            public static final int PROTOCOL_YAHOO = 2;
6486            public static final int PROTOCOL_SKYPE = 3;
6487            public static final int PROTOCOL_QQ = 4;
6488            public static final int PROTOCOL_GOOGLE_TALK = 5;
6489            public static final int PROTOCOL_ICQ = 6;
6490            public static final int PROTOCOL_JABBER = 7;
6491            public static final int PROTOCOL_NETMEETING = 8;
6492
6493            /**
6494             * Return the string resource that best describes the given
6495             * {@link #TYPE}. Will always return a valid resource.
6496             */
6497            public static final int getTypeLabelResource(int type) {
6498                switch (type) {
6499                    case TYPE_HOME: return com.android.internal.R.string.imTypeHome;
6500                    case TYPE_WORK: return com.android.internal.R.string.imTypeWork;
6501                    case TYPE_OTHER: return com.android.internal.R.string.imTypeOther;
6502                    default: return com.android.internal.R.string.imTypeCustom;
6503                }
6504            }
6505
6506            /**
6507             * Return a {@link CharSequence} that best describes the given type,
6508             * possibly substituting the given {@link #LABEL} value
6509             * for {@link #TYPE_CUSTOM}.
6510             */
6511            public static final CharSequence getTypeLabel(Resources res, int type,
6512                    CharSequence label) {
6513                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6514                    return label;
6515                } else {
6516                    final int labelRes = getTypeLabelResource(type);
6517                    return res.getText(labelRes);
6518                }
6519            }
6520
6521            /**
6522             * Return the string resource that best describes the given
6523             * {@link #PROTOCOL}. Will always return a valid resource.
6524             */
6525            public static final int getProtocolLabelResource(int type) {
6526                switch (type) {
6527                    case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim;
6528                    case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn;
6529                    case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo;
6530                    case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype;
6531                    case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq;
6532                    case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk;
6533                    case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq;
6534                    case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber;
6535                    case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting;
6536                    default: return com.android.internal.R.string.imProtocolCustom;
6537                }
6538            }
6539
6540            /**
6541             * Return a {@link CharSequence} that best describes the given
6542             * protocol, possibly substituting the given
6543             * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}.
6544             */
6545            public static final CharSequence getProtocolLabel(Resources res, int type,
6546                    CharSequence label) {
6547                if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) {
6548                    return label;
6549                } else {
6550                    final int labelRes = getProtocolLabelResource(type);
6551                    return res.getText(labelRes);
6552                }
6553            }
6554        }
6555
6556        /**
6557         * <p>
6558         * A data kind representing an organization.
6559         * </p>
6560         * <p>
6561         * You can use all columns defined for {@link ContactsContract.Data} as
6562         * well as the following aliases.
6563         * </p>
6564         * <h2>Column aliases</h2>
6565         * <table class="jd-sumtable">
6566         * <tr>
6567         * <th>Type</th>
6568         * <th>Alias</th><th colspan='2'>Data column</th>
6569         * </tr>
6570         * <tr>
6571         * <td>String</td>
6572         * <td>{@link #COMPANY}</td>
6573         * <td>{@link #DATA1}</td>
6574         * <td></td>
6575         * </tr>
6576         * <tr>
6577         * <td>int</td>
6578         * <td>{@link #TYPE}</td>
6579         * <td>{@link #DATA2}</td>
6580         * <td>Allowed values are:
6581         * <p>
6582         * <ul>
6583         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6584         * <li>{@link #TYPE_WORK}</li>
6585         * <li>{@link #TYPE_OTHER}</li>
6586         * </ul>
6587         * </p>
6588         * </td>
6589         * </tr>
6590         * <tr>
6591         * <td>String</td>
6592         * <td>{@link #LABEL}</td>
6593         * <td>{@link #DATA3}</td>
6594         * <td></td>
6595         * </tr>
6596         * <tr>
6597         * <td>String</td>
6598         * <td>{@link #TITLE}</td>
6599         * <td>{@link #DATA4}</td>
6600         * <td></td>
6601         * </tr>
6602         * <tr>
6603         * <td>String</td>
6604         * <td>{@link #DEPARTMENT}</td>
6605         * <td>{@link #DATA5}</td>
6606         * <td></td>
6607         * </tr>
6608         * <tr>
6609         * <td>String</td>
6610         * <td>{@link #JOB_DESCRIPTION}</td>
6611         * <td>{@link #DATA6}</td>
6612         * <td></td>
6613         * </tr>
6614         * <tr>
6615         * <td>String</td>
6616         * <td>{@link #SYMBOL}</td>
6617         * <td>{@link #DATA7}</td>
6618         * <td></td>
6619         * </tr>
6620         * <tr>
6621         * <td>String</td>
6622         * <td>{@link #PHONETIC_NAME}</td>
6623         * <td>{@link #DATA8}</td>
6624         * <td></td>
6625         * </tr>
6626         * <tr>
6627         * <td>String</td>
6628         * <td>{@link #OFFICE_LOCATION}</td>
6629         * <td>{@link #DATA9}</td>
6630         * <td></td>
6631         * </tr>
6632         * <tr>
6633         * <td>String</td>
6634         * <td>PHONETIC_NAME_STYLE</td>
6635         * <td>{@link #DATA10}</td>
6636         * <td></td>
6637         * </tr>
6638         * </table>
6639         */
6640        public static final class Organization implements DataColumnsWithJoins, CommonColumns,
6641                ContactCounts {
6642            /**
6643             * This utility class cannot be instantiated
6644             */
6645            private Organization() {}
6646
6647            /** MIME type used when storing this in data table. */
6648            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
6649
6650            public static final int TYPE_WORK = 1;
6651            public static final int TYPE_OTHER = 2;
6652
6653            /**
6654             * The company as the user entered it.
6655             * <P>Type: TEXT</P>
6656             */
6657            public static final String COMPANY = DATA;
6658
6659            /**
6660             * The position title at this company as the user entered it.
6661             * <P>Type: TEXT</P>
6662             */
6663            public static final String TITLE = DATA4;
6664
6665            /**
6666             * The department at this company as the user entered it.
6667             * <P>Type: TEXT</P>
6668             */
6669            public static final String DEPARTMENT = DATA5;
6670
6671            /**
6672             * The job description at this company as the user entered it.
6673             * <P>Type: TEXT</P>
6674             */
6675            public static final String JOB_DESCRIPTION = DATA6;
6676
6677            /**
6678             * The symbol of this company as the user entered it.
6679             * <P>Type: TEXT</P>
6680             */
6681            public static final String SYMBOL = DATA7;
6682
6683            /**
6684             * The phonetic name of this company as the user entered it.
6685             * <P>Type: TEXT</P>
6686             */
6687            public static final String PHONETIC_NAME = DATA8;
6688
6689            /**
6690             * The office location of this organization.
6691             * <P>Type: TEXT</P>
6692             */
6693            public static final String OFFICE_LOCATION = DATA9;
6694
6695            /**
6696             * The alphabet used for capturing the phonetic name.
6697             * See {@link ContactsContract.PhoneticNameStyle}.
6698             * @hide
6699             */
6700            public static final String PHONETIC_NAME_STYLE = DATA10;
6701
6702            /**
6703             * Return the string resource that best describes the given
6704             * {@link #TYPE}. Will always return a valid resource.
6705             */
6706            public static final int getTypeLabelResource(int type) {
6707                switch (type) {
6708                    case TYPE_WORK: return com.android.internal.R.string.orgTypeWork;
6709                    case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther;
6710                    default: return com.android.internal.R.string.orgTypeCustom;
6711                }
6712            }
6713
6714            /**
6715             * Return a {@link CharSequence} that best describes the given type,
6716             * possibly substituting the given {@link #LABEL} value
6717             * for {@link #TYPE_CUSTOM}.
6718             */
6719            public static final CharSequence getTypeLabel(Resources res, int type,
6720                    CharSequence label) {
6721                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6722                    return label;
6723                } else {
6724                    final int labelRes = getTypeLabelResource(type);
6725                    return res.getText(labelRes);
6726                }
6727            }
6728        }
6729
6730        /**
6731         * <p>
6732         * A data kind representing a relation.
6733         * </p>
6734         * <p>
6735         * You can use all columns defined for {@link ContactsContract.Data} as
6736         * well as the following aliases.
6737         * </p>
6738         * <h2>Column aliases</h2>
6739         * <table class="jd-sumtable">
6740         * <tr>
6741         * <th>Type</th>
6742         * <th>Alias</th><th colspan='2'>Data column</th>
6743         * </tr>
6744         * <tr>
6745         * <td>String</td>
6746         * <td>{@link #NAME}</td>
6747         * <td>{@link #DATA1}</td>
6748         * <td></td>
6749         * </tr>
6750         * <tr>
6751         * <td>int</td>
6752         * <td>{@link #TYPE}</td>
6753         * <td>{@link #DATA2}</td>
6754         * <td>Allowed values are:
6755         * <p>
6756         * <ul>
6757         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6758         * <li>{@link #TYPE_ASSISTANT}</li>
6759         * <li>{@link #TYPE_BROTHER}</li>
6760         * <li>{@link #TYPE_CHILD}</li>
6761         * <li>{@link #TYPE_DOMESTIC_PARTNER}</li>
6762         * <li>{@link #TYPE_FATHER}</li>
6763         * <li>{@link #TYPE_FRIEND}</li>
6764         * <li>{@link #TYPE_MANAGER}</li>
6765         * <li>{@link #TYPE_MOTHER}</li>
6766         * <li>{@link #TYPE_PARENT}</li>
6767         * <li>{@link #TYPE_PARTNER}</li>
6768         * <li>{@link #TYPE_REFERRED_BY}</li>
6769         * <li>{@link #TYPE_RELATIVE}</li>
6770         * <li>{@link #TYPE_SISTER}</li>
6771         * <li>{@link #TYPE_SPOUSE}</li>
6772         * </ul>
6773         * </p>
6774         * </td>
6775         * </tr>
6776         * <tr>
6777         * <td>String</td>
6778         * <td>{@link #LABEL}</td>
6779         * <td>{@link #DATA3}</td>
6780         * <td></td>
6781         * </tr>
6782         * </table>
6783         */
6784        public static final class Relation implements DataColumnsWithJoins, CommonColumns,
6785                ContactCounts {
6786            /**
6787             * This utility class cannot be instantiated
6788             */
6789            private Relation() {}
6790
6791            /** MIME type used when storing this in data table. */
6792            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
6793
6794            public static final int TYPE_ASSISTANT = 1;
6795            public static final int TYPE_BROTHER = 2;
6796            public static final int TYPE_CHILD = 3;
6797            public static final int TYPE_DOMESTIC_PARTNER = 4;
6798            public static final int TYPE_FATHER = 5;
6799            public static final int TYPE_FRIEND = 6;
6800            public static final int TYPE_MANAGER = 7;
6801            public static final int TYPE_MOTHER = 8;
6802            public static final int TYPE_PARENT = 9;
6803            public static final int TYPE_PARTNER = 10;
6804            public static final int TYPE_REFERRED_BY = 11;
6805            public static final int TYPE_RELATIVE = 12;
6806            public static final int TYPE_SISTER = 13;
6807            public static final int TYPE_SPOUSE = 14;
6808
6809            /**
6810             * The name of the relative as the user entered it.
6811             * <P>Type: TEXT</P>
6812             */
6813            public static final String NAME = DATA;
6814
6815            /**
6816             * Return the string resource that best describes the given
6817             * {@link #TYPE}. Will always return a valid resource.
6818             */
6819            public static final int getTypeLabelResource(int type) {
6820                switch (type) {
6821                    case TYPE_ASSISTANT: return com.android.internal.R.string.relationTypeAssistant;
6822                    case TYPE_BROTHER: return com.android.internal.R.string.relationTypeBrother;
6823                    case TYPE_CHILD: return com.android.internal.R.string.relationTypeChild;
6824                    case TYPE_DOMESTIC_PARTNER:
6825                            return com.android.internal.R.string.relationTypeDomesticPartner;
6826                    case TYPE_FATHER: return com.android.internal.R.string.relationTypeFather;
6827                    case TYPE_FRIEND: return com.android.internal.R.string.relationTypeFriend;
6828                    case TYPE_MANAGER: return com.android.internal.R.string.relationTypeManager;
6829                    case TYPE_MOTHER: return com.android.internal.R.string.relationTypeMother;
6830                    case TYPE_PARENT: return com.android.internal.R.string.relationTypeParent;
6831                    case TYPE_PARTNER: return com.android.internal.R.string.relationTypePartner;
6832                    case TYPE_REFERRED_BY:
6833                            return com.android.internal.R.string.relationTypeReferredBy;
6834                    case TYPE_RELATIVE: return com.android.internal.R.string.relationTypeRelative;
6835                    case TYPE_SISTER: return com.android.internal.R.string.relationTypeSister;
6836                    case TYPE_SPOUSE: return com.android.internal.R.string.relationTypeSpouse;
6837                    default: return com.android.internal.R.string.orgTypeCustom;
6838                }
6839            }
6840
6841            /**
6842             * Return a {@link CharSequence} that best describes the given type,
6843             * possibly substituting the given {@link #LABEL} value
6844             * for {@link #TYPE_CUSTOM}.
6845             */
6846            public static final CharSequence getTypeLabel(Resources res, int type,
6847                    CharSequence label) {
6848                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6849                    return label;
6850                } else {
6851                    final int labelRes = getTypeLabelResource(type);
6852                    return res.getText(labelRes);
6853                }
6854            }
6855        }
6856
6857        /**
6858         * <p>
6859         * A data kind representing an event.
6860         * </p>
6861         * <p>
6862         * You can use all columns defined for {@link ContactsContract.Data} as
6863         * well as the following aliases.
6864         * </p>
6865         * <h2>Column aliases</h2>
6866         * <table class="jd-sumtable">
6867         * <tr>
6868         * <th>Type</th>
6869         * <th>Alias</th><th colspan='2'>Data column</th>
6870         * </tr>
6871         * <tr>
6872         * <td>String</td>
6873         * <td>{@link #START_DATE}</td>
6874         * <td>{@link #DATA1}</td>
6875         * <td></td>
6876         * </tr>
6877         * <tr>
6878         * <td>int</td>
6879         * <td>{@link #TYPE}</td>
6880         * <td>{@link #DATA2}</td>
6881         * <td>Allowed values are:
6882         * <p>
6883         * <ul>
6884         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6885         * <li>{@link #TYPE_ANNIVERSARY}</li>
6886         * <li>{@link #TYPE_OTHER}</li>
6887         * <li>{@link #TYPE_BIRTHDAY}</li>
6888         * </ul>
6889         * </p>
6890         * </td>
6891         * </tr>
6892         * <tr>
6893         * <td>String</td>
6894         * <td>{@link #LABEL}</td>
6895         * <td>{@link #DATA3}</td>
6896         * <td></td>
6897         * </tr>
6898         * </table>
6899         */
6900        public static final class Event implements DataColumnsWithJoins, CommonColumns,
6901                ContactCounts {
6902            /**
6903             * This utility class cannot be instantiated
6904             */
6905            private Event() {}
6906
6907            /** MIME type used when storing this in data table. */
6908            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event";
6909
6910            public static final int TYPE_ANNIVERSARY = 1;
6911            public static final int TYPE_OTHER = 2;
6912            public static final int TYPE_BIRTHDAY = 3;
6913
6914            /**
6915             * The event start date as the user entered it.
6916             * <P>Type: TEXT</P>
6917             */
6918            public static final String START_DATE = DATA;
6919
6920            /**
6921             * Return the string resource that best describes the given
6922             * {@link #TYPE}. Will always return a valid resource.
6923             */
6924            public static int getTypeResource(Integer type) {
6925                if (type == null) {
6926                    return com.android.internal.R.string.eventTypeOther;
6927                }
6928                switch (type) {
6929                    case TYPE_ANNIVERSARY:
6930                        return com.android.internal.R.string.eventTypeAnniversary;
6931                    case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday;
6932                    case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther;
6933                    default: return com.android.internal.R.string.eventTypeCustom;
6934                }
6935            }
6936
6937            /**
6938             * Return a {@link CharSequence} that best describes the given type,
6939             * possibly substituting the given {@link #LABEL} value
6940             * for {@link #TYPE_CUSTOM}.
6941             */
6942            public static final CharSequence getTypeLabel(Resources res, int type,
6943                    CharSequence label) {
6944                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6945                    return label;
6946                } else {
6947                    final int labelRes = getTypeResource(type);
6948                    return res.getText(labelRes);
6949                }
6950            }
6951        }
6952
6953        /**
6954         * <p>
6955         * A data kind representing a photo for the contact.
6956         * </p>
6957         * <p>
6958         * Some sync adapters will choose to download photos in a separate
6959         * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1}
6960         * through {@link ContactsContract.Data#SYNC4} to store temporary
6961         * data, e.g. the image URL or ID, state of download, server-side version
6962         * of the image.  It is allowed for the {@link #PHOTO} to be null.
6963         * </p>
6964         * <p>
6965         * You can use all columns defined for {@link ContactsContract.Data} as
6966         * well as the following aliases.
6967         * </p>
6968         * <h2>Column aliases</h2>
6969         * <table class="jd-sumtable">
6970         * <tr>
6971         * <th>Type</th>
6972         * <th>Alias</th><th colspan='2'>Data column</th>
6973         * </tr>
6974         * <tr>
6975         * <td>NUMBER</td>
6976         * <td>{@link #PHOTO_FILE_ID}</td>
6977         * <td>{@link #DATA14}</td>
6978         * <td>ID of the hi-res photo file.</td>
6979         * </tr>
6980         * <tr>
6981         * <td>BLOB</td>
6982         * <td>{@link #PHOTO}</td>
6983         * <td>{@link #DATA15}</td>
6984         * <td>By convention, binary data is stored in DATA15.  The thumbnail of the
6985         * photo is stored in this column.</td>
6986         * </tr>
6987         * </table>
6988         */
6989        public static final class Photo implements DataColumnsWithJoins, ContactCounts {
6990            /**
6991             * This utility class cannot be instantiated
6992             */
6993            private Photo() {}
6994
6995            /** MIME type used when storing this in data table. */
6996            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
6997
6998            /**
6999             * Photo file ID for the display photo of the raw contact.
7000             * See {@link ContactsContract.DisplayPhoto}.
7001             * <p>
7002             * Type: NUMBER
7003             */
7004            public static final String PHOTO_FILE_ID = DATA14;
7005
7006            /**
7007             * Thumbnail photo of the raw contact. This is the raw bytes of an image
7008             * that could be inflated using {@link android.graphics.BitmapFactory}.
7009             * <p>
7010             * Type: BLOB
7011             */
7012            public static final String PHOTO = DATA15;
7013        }
7014
7015        /**
7016         * <p>
7017         * Notes about the contact.
7018         * </p>
7019         * <p>
7020         * You can use all columns defined for {@link ContactsContract.Data} as
7021         * well as the following aliases.
7022         * </p>
7023         * <h2>Column aliases</h2>
7024         * <table class="jd-sumtable">
7025         * <tr>
7026         * <th>Type</th>
7027         * <th>Alias</th><th colspan='2'>Data column</th>
7028         * </tr>
7029         * <tr>
7030         * <td>String</td>
7031         * <td>{@link #NOTE}</td>
7032         * <td>{@link #DATA1}</td>
7033         * <td></td>
7034         * </tr>
7035         * </table>
7036         */
7037        public static final class Note implements DataColumnsWithJoins, ContactCounts {
7038            /**
7039             * This utility class cannot be instantiated
7040             */
7041            private Note() {}
7042
7043            /** MIME type used when storing this in data table. */
7044            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
7045
7046            /**
7047             * The note text.
7048             * <P>Type: TEXT</P>
7049             */
7050            public static final String NOTE = DATA1;
7051        }
7052
7053        /**
7054         * <p>
7055         * Group Membership.
7056         * </p>
7057         * <p>
7058         * You can use all columns defined for {@link ContactsContract.Data} as
7059         * well as the following aliases.
7060         * </p>
7061         * <h2>Column aliases</h2>
7062         * <table class="jd-sumtable">
7063         * <tr>
7064         * <th>Type</th>
7065         * <th>Alias</th><th colspan='2'>Data column</th>
7066         * </tr>
7067         * <tr>
7068         * <td>long</td>
7069         * <td>{@link #GROUP_ROW_ID}</td>
7070         * <td>{@link #DATA1}</td>
7071         * <td></td>
7072         * </tr>
7073         * <tr>
7074         * <td>String</td>
7075         * <td>{@link #GROUP_SOURCE_ID}</td>
7076         * <td>none</td>
7077         * <td>
7078         * <p>
7079         * The sourceid of the group that this group membership refers to.
7080         * Exactly one of this or {@link #GROUP_ROW_ID} must be set when
7081         * inserting a row.
7082         * </p>
7083         * <p>
7084         * If this field is specified, the provider will first try to
7085         * look up a group with this {@link Groups Groups.SOURCE_ID}.  If such a group
7086         * is found, it will use the corresponding row id.  If the group is not
7087         * found, it will create one.
7088         * </td>
7089         * </tr>
7090         * </table>
7091         */
7092        public static final class GroupMembership implements DataColumnsWithJoins, ContactCounts {
7093            /**
7094             * This utility class cannot be instantiated
7095             */
7096            private GroupMembership() {}
7097
7098            /** MIME type used when storing this in data table. */
7099            public static final String CONTENT_ITEM_TYPE =
7100                    "vnd.android.cursor.item/group_membership";
7101
7102            /**
7103             * The row id of the group that this group membership refers to. Exactly one of
7104             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
7105             * <P>Type: INTEGER</P>
7106             */
7107            public static final String GROUP_ROW_ID = DATA1;
7108
7109            /**
7110             * The sourceid of the group that this group membership refers to.  Exactly one of
7111             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
7112             * <P>Type: TEXT</P>
7113             */
7114            public static final String GROUP_SOURCE_ID = "group_sourceid";
7115        }
7116
7117        /**
7118         * <p>
7119         * A data kind representing a website related to the contact.
7120         * </p>
7121         * <p>
7122         * You can use all columns defined for {@link ContactsContract.Data} as
7123         * well as the following aliases.
7124         * </p>
7125         * <h2>Column aliases</h2>
7126         * <table class="jd-sumtable">
7127         * <tr>
7128         * <th>Type</th>
7129         * <th>Alias</th><th colspan='2'>Data column</th>
7130         * </tr>
7131         * <tr>
7132         * <td>String</td>
7133         * <td>{@link #URL}</td>
7134         * <td>{@link #DATA1}</td>
7135         * <td></td>
7136         * </tr>
7137         * <tr>
7138         * <td>int</td>
7139         * <td>{@link #TYPE}</td>
7140         * <td>{@link #DATA2}</td>
7141         * <td>Allowed values are:
7142         * <p>
7143         * <ul>
7144         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
7145         * <li>{@link #TYPE_HOMEPAGE}</li>
7146         * <li>{@link #TYPE_BLOG}</li>
7147         * <li>{@link #TYPE_PROFILE}</li>
7148         * <li>{@link #TYPE_HOME}</li>
7149         * <li>{@link #TYPE_WORK}</li>
7150         * <li>{@link #TYPE_FTP}</li>
7151         * <li>{@link #TYPE_OTHER}</li>
7152         * </ul>
7153         * </p>
7154         * </td>
7155         * </tr>
7156         * <tr>
7157         * <td>String</td>
7158         * <td>{@link #LABEL}</td>
7159         * <td>{@link #DATA3}</td>
7160         * <td></td>
7161         * </tr>
7162         * </table>
7163         */
7164        public static final class Website implements DataColumnsWithJoins, CommonColumns,
7165                ContactCounts {
7166            /**
7167             * This utility class cannot be instantiated
7168             */
7169            private Website() {}
7170
7171            /** MIME type used when storing this in data table. */
7172            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
7173
7174            public static final int TYPE_HOMEPAGE = 1;
7175            public static final int TYPE_BLOG = 2;
7176            public static final int TYPE_PROFILE = 3;
7177            public static final int TYPE_HOME = 4;
7178            public static final int TYPE_WORK = 5;
7179            public static final int TYPE_FTP = 6;
7180            public static final int TYPE_OTHER = 7;
7181
7182            /**
7183             * The website URL string.
7184             * <P>Type: TEXT</P>
7185             */
7186            public static final String URL = DATA;
7187        }
7188
7189        /**
7190         * <p>
7191         * A data kind representing a SIP address for the contact.
7192         * </p>
7193         * <p>
7194         * You can use all columns defined for {@link ContactsContract.Data} as
7195         * well as the following aliases.
7196         * </p>
7197         * <h2>Column aliases</h2>
7198         * <table class="jd-sumtable">
7199         * <tr>
7200         * <th>Type</th>
7201         * <th>Alias</th><th colspan='2'>Data column</th>
7202         * </tr>
7203         * <tr>
7204         * <td>String</td>
7205         * <td>{@link #SIP_ADDRESS}</td>
7206         * <td>{@link #DATA1}</td>
7207         * <td></td>
7208         * </tr>
7209         * <tr>
7210         * <td>int</td>
7211         * <td>{@link #TYPE}</td>
7212         * <td>{@link #DATA2}</td>
7213         * <td>Allowed values are:
7214         * <p>
7215         * <ul>
7216         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
7217         * <li>{@link #TYPE_HOME}</li>
7218         * <li>{@link #TYPE_WORK}</li>
7219         * <li>{@link #TYPE_OTHER}</li>
7220         * </ul>
7221         * </p>
7222         * </td>
7223         * </tr>
7224         * <tr>
7225         * <td>String</td>
7226         * <td>{@link #LABEL}</td>
7227         * <td>{@link #DATA3}</td>
7228         * <td></td>
7229         * </tr>
7230         * </table>
7231         */
7232        public static final class SipAddress implements DataColumnsWithJoins, CommonColumns,
7233                ContactCounts {
7234            /**
7235             * This utility class cannot be instantiated
7236             */
7237            private SipAddress() {}
7238
7239            /** MIME type used when storing this in data table. */
7240            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/sip_address";
7241
7242            public static final int TYPE_HOME = 1;
7243            public static final int TYPE_WORK = 2;
7244            public static final int TYPE_OTHER = 3;
7245
7246            /**
7247             * The SIP address.
7248             * <P>Type: TEXT</P>
7249             */
7250            public static final String SIP_ADDRESS = DATA1;
7251            // ...and TYPE and LABEL come from the CommonColumns interface.
7252
7253            /**
7254             * Return the string resource that best describes the given
7255             * {@link #TYPE}. Will always return a valid resource.
7256             */
7257            public static final int getTypeLabelResource(int type) {
7258                switch (type) {
7259                    case TYPE_HOME: return com.android.internal.R.string.sipAddressTypeHome;
7260                    case TYPE_WORK: return com.android.internal.R.string.sipAddressTypeWork;
7261                    case TYPE_OTHER: return com.android.internal.R.string.sipAddressTypeOther;
7262                    default: return com.android.internal.R.string.sipAddressTypeCustom;
7263                }
7264            }
7265
7266            /**
7267             * Return a {@link CharSequence} that best describes the given type,
7268             * possibly substituting the given {@link #LABEL} value
7269             * for {@link #TYPE_CUSTOM}.
7270             */
7271            public static final CharSequence getTypeLabel(Resources res, int type,
7272                    CharSequence label) {
7273                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
7274                    return label;
7275                } else {
7276                    final int labelRes = getTypeLabelResource(type);
7277                    return res.getText(labelRes);
7278                }
7279            }
7280        }
7281
7282        /**
7283         * A data kind representing an Identity related to the contact.
7284         * <p>
7285         * This can be used as a signal by the aggregator to combine raw contacts into
7286         * contacts, e.g. if two contacts have Identity rows with
7287         * the same NAMESPACE and IDENTITY values the aggregator can know that they refer
7288         * to the same person.
7289         * </p>
7290         */
7291        public static final class Identity implements DataColumnsWithJoins, ContactCounts {
7292            /**
7293             * This utility class cannot be instantiated
7294             */
7295            private Identity() {}
7296
7297            /** MIME type used when storing this in data table. */
7298            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/identity";
7299
7300            /**
7301             * The identity string.
7302             * <P>Type: TEXT</P>
7303             */
7304            public static final String IDENTITY = DataColumns.DATA1;
7305
7306            /**
7307             * The namespace of the identity string, e.g. "com.google"
7308             * <P>Type: TEXT</P>
7309             */
7310            public static final String NAMESPACE = DataColumns.DATA2;
7311        }
7312
7313        /**
7314         * <p>
7315         * Convenient functionalities for "callable" data. Note that, this is NOT a separate data
7316         * kind.
7317         * </p>
7318         * <p>
7319         * This URI allows the ContactsProvider to return a unified result for "callable" data
7320         * that users can use for calling purposes. {@link Phone} and {@link SipAddress} are the
7321         * current examples for "callable", but may be expanded to the other types.
7322         * </p>
7323         * <p>
7324         * Each returned row may have a different MIMETYPE and thus different interpretation for
7325         * each column. For example the meaning for {@link Phone}'s type is different than
7326         * {@link SipAddress}'s.
7327         * </p>
7328         */
7329        public static final class Callable implements DataColumnsWithJoins, CommonColumns,
7330                ContactCounts {
7331            /**
7332             * Similar to {@link Phone#CONTENT_URI}, but returns callable data instead of only
7333             * phone numbers.
7334             */
7335            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
7336                    "callables");
7337            /**
7338             * Similar to {@link Phone#CONTENT_FILTER_URI}, but allows users to filter callable
7339             * data.
7340             */
7341            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
7342                    "filter");
7343        }
7344
7345        /**
7346         * A special class of data items, used to refer to types of data that can be used to attempt
7347         * to start communicating with a person ({@link Phone} and {@link Email}). Note that this
7348         * is NOT a separate data kind.
7349         *
7350         * This URI allows the ContactsProvider to return a unified result for data items that users
7351         * can use to initiate communications with another contact. {@link Phone} and {@link Email}
7352         * are the current data types in this category.
7353         */
7354        public static final class Contactables implements DataColumnsWithJoins, CommonColumns,
7355                ContactCounts {
7356            /**
7357             * The content:// style URI for these data items, which requests a directory of data
7358             * rows matching the selection criteria.
7359             */
7360            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
7361                    "contactables");
7362
7363            /**
7364             * The content:// style URI for these data items, which allows for a query parameter to
7365             * be appended onto the end to filter for data items matching the query.
7366             */
7367            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(
7368                    Contactables.CONTENT_URI, "filter");
7369
7370            /**
7371             * A boolean parameter for {@link Data#CONTENT_URI}.
7372             * This specifies whether or not the returned data items should be filtered to show
7373             * data items belonging to visible contacts only.
7374             */
7375            public static final String VISIBLE_CONTACTS_ONLY = "visible_contacts_only";
7376        }
7377    }
7378
7379    /**
7380     * @see Groups
7381     */
7382    protected interface GroupsColumns {
7383        /**
7384         * The data set within the account that this group belongs to.  This allows
7385         * multiple sync adapters for the same account type to distinguish between
7386         * each others' group data.
7387         *
7388         * This is empty by default, and is completely optional.  It only needs to
7389         * be populated if multiple sync adapters are entering distinct group data
7390         * for the same account type and account name.
7391         * <P>Type: TEXT</P>
7392         */
7393        public static final String DATA_SET = "data_set";
7394
7395        /**
7396         * A concatenation of the account type and data set (delimited by a forward
7397         * slash) - if the data set is empty, this will be the same as the account
7398         * type.  For applications that need to be aware of the data set, this can
7399         * be used instead of account type to distinguish sets of data.  This is
7400         * never intended to be used for specifying accounts.
7401         * @hide
7402         */
7403        public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set";
7404
7405        /**
7406         * The display title of this group.
7407         * <p>
7408         * Type: TEXT
7409         */
7410        public static final String TITLE = "title";
7411
7412        /**
7413         * The package name to use when creating {@link Resources} objects for
7414         * this group. This value is only designed for use when building user
7415         * interfaces, and should not be used to infer the owner.
7416         */
7417        public static final String RES_PACKAGE = "res_package";
7418
7419        /**
7420         * The display title of this group to load as a resource from
7421         * {@link #RES_PACKAGE}, which may be localized.
7422         * <P>Type: TEXT</P>
7423         */
7424        public static final String TITLE_RES = "title_res";
7425
7426        /**
7427         * Notes about the group.
7428         * <p>
7429         * Type: TEXT
7430         */
7431        public static final String NOTES = "notes";
7432
7433        /**
7434         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
7435         * to the sync adapter, null otherwise.
7436         * <P>Type: TEXT</P>
7437         */
7438        public static final String SYSTEM_ID = "system_id";
7439
7440        /**
7441         * The total number of {@link Contacts} that have
7442         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
7443         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
7444         * <p>
7445         * Type: INTEGER
7446         */
7447        public static final String SUMMARY_COUNT = "summ_count";
7448
7449        /**
7450         * A boolean query parameter that can be used with {@link Groups#CONTENT_SUMMARY_URI}.
7451         * It will additionally return {@link #SUMMARY_GROUP_COUNT_PER_ACCOUNT}.
7452         *
7453         * @hide
7454         */
7455        public static final String PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT =
7456                "return_group_count_per_account";
7457
7458        /**
7459         * The total number of groups of the account that a group belongs to.
7460         * This column is available only when the parameter
7461         * {@link #PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT} is specified in
7462         * {@link Groups#CONTENT_SUMMARY_URI}.
7463         *
7464         * For example, when the account "A" has two groups "group1" and "group2", and the account
7465         * "B" has a group "group3", the rows for "group1" and "group2" return "2" and the row for
7466         * "group3" returns "1" for this column.
7467         *
7468         * Note: This counts only non-favorites, non-auto-add, and not deleted groups.
7469         *
7470         * Type: INTEGER
7471         * @hide
7472         */
7473        public static final String SUMMARY_GROUP_COUNT_PER_ACCOUNT = "group_count_per_account";
7474
7475        /**
7476         * The total number of {@link Contacts} that have both
7477         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
7478         * Read-only value that is only present when querying
7479         * {@link Groups#CONTENT_SUMMARY_URI}.
7480         * <p>
7481         * Type: INTEGER
7482         */
7483        public static final String SUMMARY_WITH_PHONES = "summ_phones";
7484
7485        /**
7486         * Flag indicating if the contacts belonging to this group should be
7487         * visible in any user interface.
7488         * <p>
7489         * Type: INTEGER (boolean)
7490         */
7491        public static final String GROUP_VISIBLE = "group_visible";
7492
7493        /**
7494         * The "deleted" flag: "0" by default, "1" if the row has been marked
7495         * for deletion. When {@link android.content.ContentResolver#delete} is
7496         * called on a group, it is marked for deletion. The sync adaptor
7497         * deletes the group on the server and then calls ContactResolver.delete
7498         * once more, this time setting the the
7499         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to
7500         * finalize the data removal.
7501         * <P>Type: INTEGER</P>
7502         */
7503        public static final String DELETED = "deleted";
7504
7505        /**
7506         * Whether this group should be synced if the SYNC_EVERYTHING settings
7507         * is false for this group's account.
7508         * <p>
7509         * Type: INTEGER (boolean)
7510         */
7511        public static final String SHOULD_SYNC = "should_sync";
7512
7513        /**
7514         * Any newly created contacts will automatically be added to groups that have this
7515         * flag set to true.
7516         * <p>
7517         * Type: INTEGER (boolean)
7518         */
7519        public static final String AUTO_ADD = "auto_add";
7520
7521        /**
7522         * When a contacts is marked as a favorites it will be automatically added
7523         * to the groups that have this flag set, and when it is removed from favorites
7524         * it will be removed from these groups.
7525         * <p>
7526         * Type: INTEGER (boolean)
7527         */
7528        public static final String FAVORITES = "favorites";
7529
7530        /**
7531         * The "read-only" flag: "0" by default, "1" if the row cannot be modified or
7532         * deleted except by a sync adapter.  See {@link ContactsContract#CALLER_IS_SYNCADAPTER}.
7533         * <P>Type: INTEGER</P>
7534         */
7535        public static final String GROUP_IS_READ_ONLY = "group_is_read_only";
7536    }
7537
7538    /**
7539     * Constants for the groups table. Only per-account groups are supported.
7540     * <h2>Columns</h2>
7541     * <table class="jd-sumtable">
7542     * <tr>
7543     * <th colspan='4'>Groups</th>
7544     * </tr>
7545     * <tr>
7546     * <td>long</td>
7547     * <td>{@link #_ID}</td>
7548     * <td>read-only</td>
7549     * <td>Row ID. Sync adapter should try to preserve row IDs during updates.
7550     * In other words, it would be a really bad idea to delete and reinsert a
7551     * group. A sync adapter should always do an update instead.</td>
7552     * </tr>
7553     # <tr>
7554     * <td>String</td>
7555     * <td>{@link #DATA_SET}</td>
7556     * <td>read/write-once</td>
7557     * <td>
7558     * <p>
7559     * The data set within the account that this group belongs to.  This allows
7560     * multiple sync adapters for the same account type to distinguish between
7561     * each others' group data.  The combination of {@link #ACCOUNT_TYPE},
7562     * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data
7563     * that is associated with a single sync adapter.
7564     * </p>
7565     * <p>
7566     * This is empty by default, and is completely optional.  It only needs to
7567     * be populated if multiple sync adapters are entering distinct data for
7568     * the same account type and account name.
7569     * </p>
7570     * <p>
7571     * It should be set at the time the group is inserted and never changed
7572     * afterwards.
7573     * </p>
7574     * </td>
7575     * </tr>
7576     * <tr>
7577     * <td>String</td>
7578     * <td>{@link #TITLE}</td>
7579     * <td>read/write</td>
7580     * <td>The display title of this group.</td>
7581     * </tr>
7582     * <tr>
7583     * <td>String</td>
7584     * <td>{@link #NOTES}</td>
7585     * <td>read/write</td>
7586     * <td>Notes about the group.</td>
7587     * </tr>
7588     * <tr>
7589     * <td>String</td>
7590     * <td>{@link #SYSTEM_ID}</td>
7591     * <td>read/write</td>
7592     * <td>The ID of this group if it is a System Group, i.e. a group that has a
7593     * special meaning to the sync adapter, null otherwise.</td>
7594     * </tr>
7595     * <tr>
7596     * <td>int</td>
7597     * <td>{@link #SUMMARY_COUNT}</td>
7598     * <td>read-only</td>
7599     * <td>The total number of {@link Contacts} that have
7600     * {@link CommonDataKinds.GroupMembership} in this group. Read-only value
7601     * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td>
7602     * </tr>
7603     * <tr>
7604     * <td>int</td>
7605     * <td>{@link #SUMMARY_WITH_PHONES}</td>
7606     * <td>read-only</td>
7607     * <td>The total number of {@link Contacts} that have both
7608     * {@link CommonDataKinds.GroupMembership} in this group, and also have
7609     * phone numbers. Read-only value that is only present when querying
7610     * {@link Groups#CONTENT_SUMMARY_URI}.</td>
7611     * </tr>
7612     * <tr>
7613     * <td>int</td>
7614     * <td>{@link #GROUP_VISIBLE}</td>
7615     * <td>read-only</td>
7616     * <td>Flag indicating if the contacts belonging to this group should be
7617     * visible in any user interface. Allowed values: 0 and 1.</td>
7618     * </tr>
7619     * <tr>
7620     * <td>int</td>
7621     * <td>{@link #DELETED}</td>
7622     * <td>read/write</td>
7623     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
7624     * for deletion. When {@link android.content.ContentResolver#delete} is
7625     * called on a group, it is marked for deletion. The sync adaptor deletes
7626     * the group on the server and then calls ContactResolver.delete once more,
7627     * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER}
7628     * query parameter to finalize the data removal.</td>
7629     * </tr>
7630     * <tr>
7631     * <td>int</td>
7632     * <td>{@link #SHOULD_SYNC}</td>
7633     * <td>read/write</td>
7634     * <td>Whether this group should be synced if the SYNC_EVERYTHING settings
7635     * is false for this group's account.</td>
7636     * </tr>
7637     * </table>
7638     */
7639    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
7640        /**
7641         * This utility class cannot be instantiated
7642         */
7643        private Groups() {
7644        }
7645
7646        /**
7647         * The content:// style URI for this table
7648         */
7649        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
7650
7651        /**
7652         * The content:// style URI for this table joined with details data from
7653         * {@link ContactsContract.Data}.
7654         */
7655        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
7656                "groups_summary");
7657
7658        /**
7659         * The MIME type of a directory of groups.
7660         */
7661        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
7662
7663        /**
7664         * The MIME type of a single group.
7665         */
7666        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
7667
7668        public static EntityIterator newEntityIterator(Cursor cursor) {
7669            return new EntityIteratorImpl(cursor);
7670        }
7671
7672        private static class EntityIteratorImpl extends CursorEntityIterator {
7673            public EntityIteratorImpl(Cursor cursor) {
7674                super(cursor);
7675            }
7676
7677            @Override
7678            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
7679                // we expect the cursor is already at the row we need to read from
7680                final ContentValues values = new ContentValues();
7681                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID);
7682                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME);
7683                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE);
7684                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY);
7685                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION);
7686                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID);
7687                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE);
7688                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE);
7689                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES);
7690                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE);
7691                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1);
7692                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2);
7693                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3);
7694                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4);
7695                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID);
7696                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED);
7697                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES);
7698                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC);
7699                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, FAVORITES);
7700                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, AUTO_ADD);
7701                cursor.moveToNext();
7702                return new Entity(values);
7703            }
7704        }
7705    }
7706
7707    /**
7708     * <p>
7709     * Constants for the contact aggregation exceptions table, which contains
7710     * aggregation rules overriding those used by automatic aggregation. This
7711     * type only supports query and update. Neither insert nor delete are
7712     * supported.
7713     * </p>
7714     * <h2>Columns</h2>
7715     * <table class="jd-sumtable">
7716     * <tr>
7717     * <th colspan='4'>AggregationExceptions</th>
7718     * </tr>
7719     * <tr>
7720     * <td>int</td>
7721     * <td>{@link #TYPE}</td>
7722     * <td>read/write</td>
7723     * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER},
7724     * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td>
7725     * </tr>
7726     * <tr>
7727     * <td>long</td>
7728     * <td>{@link #RAW_CONTACT_ID1}</td>
7729     * <td>read/write</td>
7730     * <td>A reference to the {@link RawContacts#_ID} of the raw contact that
7731     * the rule applies to.</td>
7732     * </tr>
7733     * <tr>
7734     * <td>long</td>
7735     * <td>{@link #RAW_CONTACT_ID2}</td>
7736     * <td>read/write</td>
7737     * <td>A reference to the other {@link RawContacts#_ID} of the raw contact
7738     * that the rule applies to.</td>
7739     * </tr>
7740     * </table>
7741     */
7742    public static final class AggregationExceptions implements BaseColumns {
7743        /**
7744         * This utility class cannot be instantiated
7745         */
7746        private AggregationExceptions() {}
7747
7748        /**
7749         * The content:// style URI for this table
7750         */
7751        public static final Uri CONTENT_URI =
7752                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
7753
7754        /**
7755         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
7756         */
7757        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
7758
7759        /**
7760         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
7761         */
7762        public static final String CONTENT_ITEM_TYPE =
7763                "vnd.android.cursor.item/aggregation_exception";
7764
7765        /**
7766         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
7767         * {@link #TYPE_AUTOMATIC}.
7768         *
7769         * <P>Type: INTEGER</P>
7770         */
7771        public static final String TYPE = "type";
7772
7773        /**
7774         * Allows the provider to automatically decide whether the specified raw contacts should
7775         * be included in the same aggregate contact or not.
7776         */
7777        public static final int TYPE_AUTOMATIC = 0;
7778
7779        /**
7780         * Makes sure that the specified raw contacts are included in the same
7781         * aggregate contact.
7782         */
7783        public static final int TYPE_KEEP_TOGETHER = 1;
7784
7785        /**
7786         * Makes sure that the specified raw contacts are NOT included in the same
7787         * aggregate contact.
7788         */
7789        public static final int TYPE_KEEP_SEPARATE = 2;
7790
7791        /**
7792         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
7793         */
7794        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
7795
7796        /**
7797         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
7798         * applies to.
7799         */
7800        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
7801    }
7802
7803    /**
7804     * @see Settings
7805     */
7806    protected interface SettingsColumns {
7807        /**
7808         * The name of the account instance to which this row belongs.
7809         * <P>Type: TEXT</P>
7810         */
7811        public static final String ACCOUNT_NAME = "account_name";
7812
7813        /**
7814         * The type of account to which this row belongs, which when paired with
7815         * {@link #ACCOUNT_NAME} identifies a specific account.
7816         * <P>Type: TEXT</P>
7817         */
7818        public static final String ACCOUNT_TYPE = "account_type";
7819
7820        /**
7821         * The data set within the account that this row belongs to.  This allows
7822         * multiple sync adapters for the same account type to distinguish between
7823         * each others' data.
7824         *
7825         * This is empty by default, and is completely optional.  It only needs to
7826         * be populated if multiple sync adapters are entering distinct data for
7827         * the same account type and account name.
7828         * <P>Type: TEXT</P>
7829         */
7830        public static final String DATA_SET = "data_set";
7831
7832        /**
7833         * Depending on the mode defined by the sync-adapter, this flag controls
7834         * the top-level sync behavior for this data source.
7835         * <p>
7836         * Type: INTEGER (boolean)
7837         */
7838        public static final String SHOULD_SYNC = "should_sync";
7839
7840        /**
7841         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
7842         * entries should be visible in any user interface.
7843         * <p>
7844         * Type: INTEGER (boolean)
7845         */
7846        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
7847
7848        /**
7849         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
7850         * {@link Groups#SHOULD_SYNC} under this account have been marked as
7851         * unsynced.
7852         */
7853        public static final String ANY_UNSYNCED = "any_unsynced";
7854
7855        /**
7856         * Read-only count of {@link Contacts} from a specific source that have
7857         * no {@link CommonDataKinds.GroupMembership} entries.
7858         * <p>
7859         * Type: INTEGER
7860         */
7861        public static final String UNGROUPED_COUNT = "summ_count";
7862
7863        /**
7864         * Read-only count of {@link Contacts} from a specific source that have
7865         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
7866         * <p>
7867         * Type: INTEGER
7868         */
7869        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
7870    }
7871
7872    /**
7873     * <p>
7874     * Contacts-specific settings for various {@link Account}'s.
7875     * </p>
7876     * <h2>Columns</h2>
7877     * <table class="jd-sumtable">
7878     * <tr>
7879     * <th colspan='4'>Settings</th>
7880     * </tr>
7881     * <tr>
7882     * <td>String</td>
7883     * <td>{@link #ACCOUNT_NAME}</td>
7884     * <td>read/write-once</td>
7885     * <td>The name of the account instance to which this row belongs.</td>
7886     * </tr>
7887     * <tr>
7888     * <td>String</td>
7889     * <td>{@link #ACCOUNT_TYPE}</td>
7890     * <td>read/write-once</td>
7891     * <td>The type of account to which this row belongs, which when paired with
7892     * {@link #ACCOUNT_NAME} identifies a specific account.</td>
7893     * </tr>
7894     * <tr>
7895     * <td>int</td>
7896     * <td>{@link #SHOULD_SYNC}</td>
7897     * <td>read/write</td>
7898     * <td>Depending on the mode defined by the sync-adapter, this flag controls
7899     * the top-level sync behavior for this data source.</td>
7900     * </tr>
7901     * <tr>
7902     * <td>int</td>
7903     * <td>{@link #UNGROUPED_VISIBLE}</td>
7904     * <td>read/write</td>
7905     * <td>Flag indicating if contacts without any
7906     * {@link CommonDataKinds.GroupMembership} entries should be visible in any
7907     * user interface.</td>
7908     * </tr>
7909     * <tr>
7910     * <td>int</td>
7911     * <td>{@link #ANY_UNSYNCED}</td>
7912     * <td>read-only</td>
7913     * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any
7914     * {@link Groups#SHOULD_SYNC} under this account have been marked as
7915     * unsynced.</td>
7916     * </tr>
7917     * <tr>
7918     * <td>int</td>
7919     * <td>{@link #UNGROUPED_COUNT}</td>
7920     * <td>read-only</td>
7921     * <td>Read-only count of {@link Contacts} from a specific source that have
7922     * no {@link CommonDataKinds.GroupMembership} entries.</td>
7923     * </tr>
7924     * <tr>
7925     * <td>int</td>
7926     * <td>{@link #UNGROUPED_WITH_PHONES}</td>
7927     * <td>read-only</td>
7928     * <td>Read-only count of {@link Contacts} from a specific source that have
7929     * no {@link CommonDataKinds.GroupMembership} entries, and also have phone
7930     * numbers.</td>
7931     * </tr>
7932     * </table>
7933     */
7934    public static final class Settings implements SettingsColumns {
7935        /**
7936         * This utility class cannot be instantiated
7937         */
7938        private Settings() {
7939        }
7940
7941        /**
7942         * The content:// style URI for this table
7943         */
7944        public static final Uri CONTENT_URI =
7945                Uri.withAppendedPath(AUTHORITY_URI, "settings");
7946
7947        /**
7948         * The MIME-type of {@link #CONTENT_URI} providing a directory of
7949         * settings.
7950         */
7951        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
7952
7953        /**
7954         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
7955         */
7956        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
7957    }
7958
7959    /**
7960     * API for inquiring about the general status of the provider.
7961     */
7962    public static final class ProviderStatus {
7963
7964        /**
7965         * Not instantiable.
7966         */
7967        private ProviderStatus() {
7968        }
7969
7970        /**
7971         * The content:// style URI for this table.  Requests to this URI can be
7972         * performed on the UI thread because they are always unblocking.
7973         */
7974        public static final Uri CONTENT_URI =
7975                Uri.withAppendedPath(AUTHORITY_URI, "provider_status");
7976
7977        /**
7978         * The MIME-type of {@link #CONTENT_URI} providing a directory of
7979         * settings.
7980         */
7981        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status";
7982
7983        /**
7984         * An integer representing the current status of the provider.
7985         */
7986        public static final String STATUS = "status";
7987
7988        /**
7989         * Default status of the provider.
7990         */
7991        public static final int STATUS_NORMAL = 0;
7992
7993        /**
7994         * The provider won't respond to queries. It is in the middle of a long running task, such
7995         * as a database upgrade or locale change.
7996         */
7997        public static final int STATUS_BUSY = 1;
7998
7999        /**
8000         * The status that indicates that there are no accounts and no contacts
8001         * on the device.
8002         */
8003        public static final int STATUS_EMPTY = 2;
8004    }
8005
8006    /**
8007     * <p>
8008     * API allowing applications to send usage information for each {@link Data} row to the
8009     * Contacts Provider.  Applications can also clear all usage information.
8010     * </p>
8011     * <p>
8012     * With the feedback, Contacts Provider may return more contextually appropriate results for
8013     * Data listing, typically supplied with
8014     * {@link ContactsContract.Contacts#CONTENT_FILTER_URI},
8015     * {@link ContactsContract.CommonDataKinds.Email#CONTENT_FILTER_URI},
8016     * {@link ContactsContract.CommonDataKinds.Phone#CONTENT_FILTER_URI}, and users can benefit
8017     * from better ranked (sorted) lists in applications that show auto-complete list.
8018     * </p>
8019     * <p>
8020     * There is no guarantee for how this feedback is used, or even whether it is used at all.
8021     * The ranking algorithm will make best efforts to use the feedback data, but the exact
8022     * implementation, the storage data structures as well as the resulting sort order is device
8023     * and version specific and can change over time.
8024     * </p>
8025     * <p>
8026     * When updating usage information, users of this API need to use
8027     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} with a Uri constructed
8028     * from {@link DataUsageFeedback#FEEDBACK_URI}. The Uri must contain one or more data id(s) as
8029     * its last path. They also need to append a query parameter to the Uri, to specify the type of
8030     * the communication, which enables the Contacts Provider to differentiate between kinds of
8031     * interactions using the same contact data field (for example a phone number can be used to
8032     * make phone calls or send SMS).
8033     * </p>
8034     * <p>
8035     * Selection and selectionArgs are ignored and must be set to null. To get data ids,
8036     * you may need to call {@link ContentResolver#query(Uri, String[], String, String[], String)}
8037     * toward {@link Data#CONTENT_URI}.
8038     * </p>
8039     * <p>
8040     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} returns a positive
8041     * integer when successful, and returns 0 if no contact with that id was found.
8042     * </p>
8043     * <p>
8044     * Example:
8045     * <pre>
8046     * Uri uri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
8047     *         .appendPath(TextUtils.join(",", dataIds))
8048     *         .appendQueryParameter(DataUsageFeedback.USAGE_TYPE,
8049     *                 DataUsageFeedback.USAGE_TYPE_CALL)
8050     *         .build();
8051     * boolean successful = resolver.update(uri, new ContentValues(), null, null) > 0;
8052     * </pre>
8053     * </p>
8054     * <p>
8055     * Applications can also clear all usage information with:
8056     * <pre>
8057     * boolean successful = resolver.delete(DataUsageFeedback.DELETE_USAGE_URI, null, null) > 0;
8058     * </pre>
8059     * </p>
8060     */
8061    public static final class DataUsageFeedback {
8062
8063        /**
8064         * The content:// style URI for sending usage feedback.
8065         * Must be used with {@link ContentResolver#update(Uri, ContentValues, String, String[])}.
8066         */
8067        public static final Uri FEEDBACK_URI =
8068                Uri.withAppendedPath(Data.CONTENT_URI, "usagefeedback");
8069
8070        /**
8071         * The content:// style URI for deleting all usage information.
8072         * Must be used with {@link ContentResolver#delete(Uri, String, String[])}.
8073         * The {@code where} and {@code selectionArgs} parameters are ignored.
8074         */
8075        public static final Uri DELETE_USAGE_URI =
8076                Uri.withAppendedPath(Contacts.CONTENT_URI, "delete_usage");
8077
8078        /**
8079         * <p>
8080         * Name for query parameter specifying the type of data usage.
8081         * </p>
8082         */
8083        public static final String USAGE_TYPE = "type";
8084
8085        /**
8086         * <p>
8087         * Type of usage for voice interaction, which includes phone call, voice chat, and
8088         * video chat.
8089         * </p>
8090         */
8091        public static final String USAGE_TYPE_CALL = "call";
8092
8093        /**
8094         * <p>
8095         * Type of usage for text interaction involving longer messages, which includes email.
8096         * </p>
8097         */
8098        public static final String USAGE_TYPE_LONG_TEXT = "long_text";
8099
8100        /**
8101         * <p>
8102         * Type of usage for text interaction involving shorter messages, which includes SMS,
8103         * text chat with email addresses.
8104         * </p>
8105         */
8106        public static final String USAGE_TYPE_SHORT_TEXT = "short_text";
8107    }
8108
8109    /**
8110     * <p>
8111     * Contact-specific information about whether or not a contact has been pinned by the user
8112     * at a particular position within the system contact application's user interface.
8113     * </p>
8114     *
8115     * <p>
8116     * This pinning information can be used by individual applications to customize how
8117     * they order particular pinned contacts. For example, a Dialer application could
8118     * use pinned information to order user-pinned contacts in a top row of favorites.
8119     * </p>
8120     *
8121     * <p>
8122     * It is possible for two or more contacts to occupy the same pinned position (due
8123     * to aggregation and sync), so this pinning information should be used on a best-effort
8124     * basis to order contacts in-application rather than an absolute guide on where a contact
8125     * should be positioned. Contacts returned by the ContactsProvider will not be ordered based
8126     * on this information, so it is up to the client application to reorder these contacts within
8127     * their own UI adhering to (or ignoring as appropriate) information stored in the pinned
8128     * column.
8129     * </p>
8130     *
8131     * <p>
8132     * By default, unpinned contacts will have a pinned position of
8133     * {@link PinnedPositions#UNPINNED}. Client-provided pinned positions can be positive
8134     * integers that are greater than 1.
8135     * </p>
8136     */
8137    public static final class PinnedPositions {
8138        /**
8139         * The method to invoke in order to undemote a formerly demoted contact. The contact id of
8140         * the contact must be provided as an argument. If the contact was not previously demoted,
8141         * nothing will be done.
8142         * @hide
8143         */
8144        public static final String UNDEMOTE_METHOD = "undemote";
8145
8146        /**
8147         * Undemotes a formerly demoted contact. If the contact was not previously demoted, nothing
8148         * will be done.
8149         *
8150         * @param contentResolver to perform the undemote operation on.
8151         * @param contactId the id of the contact to undemote.
8152         */
8153        public static void undemote(ContentResolver contentResolver, long contactId) {
8154            contentResolver.call(ContactsContract.AUTHORITY_URI, PinnedPositions.UNDEMOTE_METHOD,
8155                    String.valueOf(contactId), null);
8156        }
8157
8158        /**
8159         * Pins a contact at a provided position, or unpins a contact.
8160         *
8161         * @param contentResolver to perform the pinning operation on.
8162         * @param pinnedPosition the position to pin the contact at. To unpin a contact, use
8163         *         {@link PinnedPositions#UNPINNED}.
8164         */
8165        public static void pin(
8166                ContentResolver contentResolver, long contactId, int pinnedPosition) {
8167            final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(contactId));
8168            final ContentValues values = new ContentValues();
8169            values.put(Contacts.PINNED, pinnedPosition);
8170            contentResolver.update(uri, values, null, null);
8171        }
8172
8173        /**
8174         * Default value for the pinned position of an unpinned contact.
8175         */
8176        public static final int UNPINNED = 0;
8177
8178        /**
8179         * Value of pinned position for a contact that a user has indicated should be considered
8180         * of the lowest priority. It is up to the client application to determine how to present
8181         * such a contact - for example all the way at the bottom of a contact list, or simply
8182         * just hidden from view.
8183         */
8184        public static final int DEMOTED = -1;
8185    }
8186
8187    /**
8188     * Helper methods to display QuickContact dialogs that display all the information belonging to
8189     * a specific {@link Contacts} entry.
8190     */
8191    public static final class QuickContact {
8192        /**
8193         * Action used to launch the system contacts application and bring up a QuickContact dialog
8194         * for the provided {@link Contacts} entry.
8195         */
8196        public static final String ACTION_QUICK_CONTACT =
8197                "android.provider.action.QUICK_CONTACT";
8198
8199        /**
8200         * Extra used to specify pivot dialog location in screen coordinates.
8201         * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead.
8202         * @hide
8203         */
8204        @Deprecated
8205        public static final String EXTRA_TARGET_RECT = "android.provider.extra.TARGET_RECT";
8206
8207        /**
8208         * Extra used to specify size of QuickContacts. Not all implementations of QuickContacts
8209         * will respect this extra's value.
8210         *
8211         * One of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
8212         */
8213        public static final String EXTRA_MODE = "android.provider.extra.MODE";
8214
8215        /**
8216         * Extra used to specify which mimetype should be prioritized in the QuickContacts UI.
8217         * For example, passing the value {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can
8218         * cause phone numbers to be displayed more prominently in QuickContacts.
8219         */
8220        public static final String EXTRA_PRIORITIZED_MIMETYPE
8221                = "android.provider.extra.PRIORITIZED_MIMETYPE";
8222
8223        /**
8224         * Extra used to indicate a list of specific MIME-types to exclude and not display in the
8225         * QuickContacts dialog. Stored as a {@link String} array.
8226         */
8227        public static final String EXTRA_EXCLUDE_MIMES = "android.provider.extra.EXCLUDE_MIMES";
8228
8229        /**
8230         * Small QuickContact mode, usually presented with minimal actions.
8231         */
8232        public static final int MODE_SMALL = 1;
8233
8234        /**
8235         * Medium QuickContact mode, includes actions and light summary describing
8236         * the {@link Contacts} entry being shown. This may include social
8237         * status and presence details.
8238         */
8239        public static final int MODE_MEDIUM = 2;
8240
8241        /**
8242         * Large QuickContact mode, includes actions and larger, card-like summary
8243         * of the {@link Contacts} entry being shown. This may include detailed
8244         * information, such as a photo.
8245         */
8246        public static final int MODE_LARGE = 3;
8247
8248        /** @hide */
8249        public static final int MODE_DEFAULT = MODE_LARGE;
8250
8251        /**
8252         * Constructs the QuickContacts intent with a view's rect.
8253         * @hide
8254         */
8255        public static Intent composeQuickContactsIntent(Context context, View target, Uri lookupUri,
8256                int mode, String[] excludeMimes) {
8257            // Find location and bounds of target view, adjusting based on the
8258            // assumed local density.
8259            final float appScale = context.getResources().getCompatibilityInfo().applicationScale;
8260            final int[] pos = new int[2];
8261            target.getLocationOnScreen(pos);
8262
8263            final Rect rect = new Rect();
8264            rect.left = (int) (pos[0] * appScale + 0.5f);
8265            rect.top = (int) (pos[1] * appScale + 0.5f);
8266            rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f);
8267            rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f);
8268
8269            return composeQuickContactsIntent(context, rect, lookupUri, mode, excludeMimes);
8270        }
8271
8272        /**
8273         * Constructs the QuickContacts intent.
8274         * @hide
8275         */
8276        public static Intent composeQuickContactsIntent(Context context, Rect target,
8277                Uri lookupUri, int mode, String[] excludeMimes) {
8278            // When launching from an Activiy, we don't want to start a new task, but otherwise
8279            // we *must* start a new task.  (Otherwise startActivity() would crash.)
8280            Context actualContext = context;
8281            while ((actualContext instanceof ContextWrapper)
8282                    && !(actualContext instanceof Activity)) {
8283                actualContext = ((ContextWrapper) actualContext).getBaseContext();
8284            }
8285            final int intentFlags = ((actualContext instanceof Activity)
8286                    ? 0 : Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
8287                    // Workaround for b/16898764. Declaring singleTop in manifest doesn't work.
8288                    | Intent.FLAG_ACTIVITY_SINGLE_TOP;
8289
8290            // Launch pivot dialog through intent for now
8291            final Intent intent = new Intent(ACTION_QUICK_CONTACT).addFlags(intentFlags);
8292
8293            // NOTE: This logic and rebuildManagedQuickContactsIntent() must be in sync.
8294            intent.setData(lookupUri);
8295            intent.setSourceBounds(target);
8296            intent.putExtra(EXTRA_MODE, mode);
8297            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);
8298            return intent;
8299        }
8300
8301        /**
8302         * Constructs a QuickContacts intent based on an incoming intent for DevicePolicyManager
8303         * to strip off anything not necessary.
8304         *
8305         * @hide
8306         */
8307        public static Intent rebuildManagedQuickContactsIntent(String lookupKey, long contactId,
8308                Intent originalIntent) {
8309            final Intent intent = new Intent(ACTION_QUICK_CONTACT);
8310            // Rebuild the URI from a lookup key and a contact ID.
8311            intent.setData(Contacts.getLookupUri(contactId, lookupKey));
8312
8313            // Copy flags and always set NEW_TASK because it won't have a parent activity.
8314            intent.setFlags(originalIntent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
8315
8316            // Copy extras.
8317            intent.setSourceBounds(originalIntent.getSourceBounds());
8318            intent.putExtra(EXTRA_MODE, originalIntent.getIntExtra(EXTRA_MODE, MODE_DEFAULT));
8319            intent.putExtra(EXTRA_EXCLUDE_MIMES,
8320                    originalIntent.getStringArrayExtra(EXTRA_EXCLUDE_MIMES));
8321            return intent;
8322        }
8323
8324
8325        /**
8326         * Trigger a dialog that lists the various methods of interacting with
8327         * the requested {@link Contacts} entry. This may be based on available
8328         * {@link ContactsContract.Data} rows under that contact, and may also
8329         * include social status and presence details.
8330         *
8331         * @param context The parent {@link Context} that may be used as the
8332         *            parent for this dialog.
8333         * @param target Specific {@link View} from your layout that this dialog
8334         *            should be centered around. In particular, if the dialog
8335         *            has a "callout" arrow, it will be pointed and centered
8336         *            around this {@link View}.
8337         * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8338         *            {@link Uri} that describes a specific contact to feature
8339         *            in this dialog.
8340         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
8341         *            {@link #MODE_LARGE}, indicating the desired dialog size,
8342         *            when supported.
8343         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8344         *            to exclude when showing this dialog. For example, when
8345         *            already viewing the contact details card, this can be used
8346         *            to omit the details entry from the dialog.
8347         */
8348        public static void showQuickContact(Context context, View target, Uri lookupUri, int mode,
8349                String[] excludeMimes) {
8350            // Trigger with obtained rectangle
8351            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
8352                    excludeMimes);
8353            ContactsInternal.startQuickContactWithErrorToast(context, intent);
8354        }
8355
8356        /**
8357         * Trigger a dialog that lists the various methods of interacting with
8358         * the requested {@link Contacts} entry. This may be based on available
8359         * {@link ContactsContract.Data} rows under that contact, and may also
8360         * include social status and presence details.
8361         *
8362         * @param context The parent {@link Context} that may be used as the
8363         *            parent for this dialog.
8364         * @param target Specific {@link Rect} that this dialog should be
8365         *            centered around, in screen coordinates. In particular, if
8366         *            the dialog has a "callout" arrow, it will be pointed and
8367         *            centered around this {@link Rect}. If you are running at a
8368         *            non-native density, you need to manually adjust using
8369         *            {@link DisplayMetrics#density} before calling.
8370         * @param lookupUri A
8371         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8372         *            {@link Uri} that describes a specific contact to feature
8373         *            in this dialog.
8374         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
8375         *            {@link #MODE_LARGE}, indicating the desired dialog size,
8376         *            when supported.
8377         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8378         *            to exclude when showing this dialog. For example, when
8379         *            already viewing the contact details card, this can be used
8380         *            to omit the details entry from the dialog.
8381         */
8382        public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,
8383                String[] excludeMimes) {
8384            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
8385                    excludeMimes);
8386            ContactsInternal.startQuickContactWithErrorToast(context, intent);
8387        }
8388
8389        /**
8390         * Trigger a dialog that lists the various methods of interacting with
8391         * the requested {@link Contacts} entry. This may be based on available
8392         * {@link ContactsContract.Data} rows under that contact, and may also
8393         * include social status and presence details.
8394         *
8395         * @param context The parent {@link Context} that may be used as the
8396         *            parent for this dialog.
8397         * @param target Specific {@link View} from your layout that this dialog
8398         *            should be centered around. In particular, if the dialog
8399         *            has a "callout" arrow, it will be pointed and centered
8400         *            around this {@link View}.
8401         * @param lookupUri A
8402         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8403         *            {@link Uri} that describes a specific contact to feature
8404         *            in this dialog.
8405         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8406         *            to exclude when showing this dialog. For example, when
8407         *            already viewing the contact details card, this can be used
8408         *            to omit the details entry from the dialog.
8409         * @param prioritizedMimeType This mimetype should be prioritized in the QuickContacts UI.
8410         *             For example, passing the value
8411         *             {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can cause phone numbers to be
8412         *             displayed more prominently in QuickContacts.
8413         */
8414        public static void showQuickContact(Context context, View target, Uri lookupUri,
8415                String[] excludeMimes, String prioritizedMimeType) {
8416            // Use MODE_LARGE instead of accepting mode as a parameter. The different mode
8417            // values defined in ContactsContract only affect very old implementations
8418            // of QuickContacts.
8419            Intent intent = composeQuickContactsIntent(context, target, lookupUri, MODE_DEFAULT,
8420                    excludeMimes);
8421            intent.putExtra(EXTRA_PRIORITIZED_MIMETYPE, prioritizedMimeType);
8422            ContactsInternal.startQuickContactWithErrorToast(context, intent);
8423        }
8424
8425        /**
8426         * Trigger a dialog that lists the various methods of interacting with
8427         * the requested {@link Contacts} entry. This may be based on available
8428         * {@link ContactsContract.Data} rows under that contact, and may also
8429         * include social status and presence details.
8430         *
8431         * @param context The parent {@link Context} that may be used as the
8432         *            parent for this dialog.
8433         * @param target Specific {@link Rect} that this dialog should be
8434         *            centered around, in screen coordinates. In particular, if
8435         *            the dialog has a "callout" arrow, it will be pointed and
8436         *            centered around this {@link Rect}. If you are running at a
8437         *            non-native density, you need to manually adjust using
8438         *            {@link DisplayMetrics#density} before calling.
8439         * @param lookupUri A
8440         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8441         *            {@link Uri} that describes a specific contact to feature
8442         *            in this dialog.
8443         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8444         *            to exclude when showing this dialog. For example, when
8445         *            already viewing the contact details card, this can be used
8446         *            to omit the details entry from the dialog.
8447         * @param prioritizedMimeType This mimetype should be prioritized in the QuickContacts UI.
8448         *             For example, passing the value
8449         *             {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can cause phone numbers to be
8450         *             displayed more prominently in QuickContacts.
8451         */
8452        public static void showQuickContact(Context context, Rect target, Uri lookupUri,
8453                String[] excludeMimes, String prioritizedMimeType) {
8454            // Use MODE_LARGE instead of accepting mode as a parameter. The different mode
8455            // values defined in ContactsContract only affect very old implementations
8456            // of QuickContacts.
8457            Intent intent = composeQuickContactsIntent(context, target, lookupUri, MODE_DEFAULT,
8458                    excludeMimes);
8459            intent.putExtra(EXTRA_PRIORITIZED_MIMETYPE, prioritizedMimeType);
8460            ContactsInternal.startQuickContactWithErrorToast(context, intent);
8461        }
8462    }
8463
8464    /**
8465     * Helper class for accessing full-size photos by photo file ID.
8466     * <p>
8467     * Usage example:
8468     * <dl>
8469     * <dt>Retrieving a full-size photo by photo file ID (see
8470     * {@link ContactsContract.ContactsColumns#PHOTO_FILE_ID})
8471     * </dt>
8472     * <dd>
8473     * <pre>
8474     * public InputStream openDisplayPhoto(long photoFileId) {
8475     *     Uri displayPhotoUri = ContentUris.withAppendedId(DisplayPhoto.CONTENT_URI, photoKey);
8476     *     try {
8477     *         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(
8478     *             displayPhotoUri, "r");
8479     *         return fd.createInputStream();
8480     *     } catch (IOException e) {
8481     *         return null;
8482     *     }
8483     * }
8484     * </pre>
8485     * </dd>
8486     * </dl>
8487     * </p>
8488     */
8489    public static final class DisplayPhoto {
8490        /**
8491         * no public constructor since this is a utility class
8492         */
8493        private DisplayPhoto() {}
8494
8495        /**
8496         * The content:// style URI for this class, which allows access to full-size photos,
8497         * given a key.
8498         */
8499        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "display_photo");
8500
8501        /**
8502         * This URI allows the caller to query for the maximum dimensions of a display photo
8503         * or thumbnail.  Requests to this URI can be performed on the UI thread because
8504         * they are always unblocking.
8505         */
8506        public static final Uri CONTENT_MAX_DIMENSIONS_URI =
8507                Uri.withAppendedPath(AUTHORITY_URI, "photo_dimensions");
8508
8509        /**
8510         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8511         * contain this column, populated with the maximum height and width (in pixels)
8512         * that will be stored for a display photo.  Larger photos will be down-sized to
8513         * fit within a square of this many pixels.
8514         */
8515        public static final String DISPLAY_MAX_DIM = "display_max_dim";
8516
8517        /**
8518         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8519         * contain this column, populated with the height and width (in pixels) for photo
8520         * thumbnails.
8521         */
8522        public static final String THUMBNAIL_MAX_DIM = "thumbnail_max_dim";
8523    }
8524
8525    /**
8526     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
8527     * that involve contacts.
8528     */
8529    public static final class Intents {
8530        /**
8531         * This is the intent that is fired when a search suggestion is clicked on.
8532         */
8533        public static final String SEARCH_SUGGESTION_CLICKED =
8534                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
8535
8536        /**
8537         * This is the intent that is fired when a search suggestion for dialing a number
8538         * is clicked on.
8539         */
8540        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
8541                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
8542
8543        /**
8544         * This is the intent that is fired when a search suggestion for creating a contact
8545         * is clicked on.
8546         */
8547        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
8548                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
8549
8550        /**
8551         * This is the intent that is fired when the contacts database is created. <p> The
8552         * READ_CONTACT permission is required to receive these broadcasts.
8553         */
8554        public static final String CONTACTS_DATABASE_CREATED =
8555                "android.provider.Contacts.DATABASE_CREATED";
8556
8557        /**
8558         * Starts an Activity that lets the user pick a contact to attach an image to.
8559         * After picking the contact it launches the image cropper in face detection mode.
8560         */
8561        public static final String ATTACH_IMAGE =
8562                "com.android.contacts.action.ATTACH_IMAGE";
8563
8564        /**
8565         * This is the intent that is fired when the user clicks the "invite to the network" button
8566         * on a contact.  Only sent to an activity which is explicitly registered by a contact
8567         * provider which supports the "invite to the network" feature.
8568         * <p>
8569         * {@link Intent#getData()} contains the lookup URI for the contact.
8570         */
8571        public static final String INVITE_CONTACT =
8572                "com.android.contacts.action.INVITE_CONTACT";
8573
8574        /**
8575         * Takes as input a data URI with a mailto: or tel: scheme. If a single
8576         * contact exists with the given data it will be shown. If no contact
8577         * exists, a dialog will ask the user if they want to create a new
8578         * contact with the provided details filled in. If multiple contacts
8579         * share the data the user will be prompted to pick which contact they
8580         * want to view.
8581         * <p>
8582         * For <code>mailto:</code> URIs, the scheme specific portion must be a
8583         * raw email address, such as one built using
8584         * {@link Uri#fromParts(String, String, String)}.
8585         * <p>
8586         * For <code>tel:</code> URIs, the scheme specific portion is compared
8587         * to existing numbers using the standard caller ID lookup algorithm.
8588         * The number must be properly encoded, for example using
8589         * {@link Uri#fromParts(String, String, String)}.
8590         * <p>
8591         * Any extras from the {@link Insert} class will be passed along to the
8592         * create activity if there are no contacts to show.
8593         * <p>
8594         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
8595         * prompting the user when the contact doesn't exist.
8596         */
8597        public static final String SHOW_OR_CREATE_CONTACT =
8598                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
8599
8600        /**
8601         * Starts an Activity that lets the user select the multiple phones from a
8602         * list of phone numbers which come from the contacts or
8603         * {@link #EXTRA_PHONE_URIS}.
8604         * <p>
8605         * The phone numbers being passed in through {@link #EXTRA_PHONE_URIS}
8606         * could belong to the contacts or not, and will be selected by default.
8607         * <p>
8608         * The user's selection will be returned from
8609         * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
8610         * if the resultCode is
8611         * {@link android.app.Activity#RESULT_OK}, the array of picked phone
8612         * numbers are in the Intent's
8613         * {@link #EXTRA_PHONE_URIS}; otherwise, the
8614         * {@link android.app.Activity#RESULT_CANCELED} is returned if the user
8615         * left the Activity without changing the selection.
8616         *
8617         * @hide
8618         */
8619        public static final String ACTION_GET_MULTIPLE_PHONES =
8620                "com.android.contacts.action.GET_MULTIPLE_PHONES";
8621
8622        /**
8623         * A broadcast action which is sent when any change has been made to the profile, such
8624         * as the profile name or the picture.  A receiver must have
8625         * the android.permission.READ_PROFILE permission.
8626         *
8627         * @hide
8628         */
8629        public static final String ACTION_PROFILE_CHANGED =
8630                "android.provider.Contacts.PROFILE_CHANGED";
8631
8632        /**
8633         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
8634         * contact if no matching contact found. Otherwise, default behavior is
8635         * to prompt user with dialog before creating.
8636         * <p>
8637         * Type: BOOLEAN
8638         */
8639        public static final String EXTRA_FORCE_CREATE =
8640                "com.android.contacts.action.FORCE_CREATE";
8641
8642        /**
8643         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
8644         * description to be shown when prompting user about creating a new
8645         * contact.
8646         * <p>
8647         * Type: STRING
8648         */
8649        public static final String EXTRA_CREATE_DESCRIPTION =
8650            "com.android.contacts.action.CREATE_DESCRIPTION";
8651
8652        /**
8653         * Used with {@link #ACTION_GET_MULTIPLE_PHONES} as the input or output value.
8654         * <p>
8655         * The phone numbers want to be picked by default should be passed in as
8656         * input value. These phone numbers could belong to the contacts or not.
8657         * <p>
8658         * The phone numbers which were picked by the user are returned as output
8659         * value.
8660         * <p>
8661         * Type: array of URIs, the tel URI is used for the phone numbers which don't
8662         * belong to any contact, the content URI is used for phone id in contacts.
8663         *
8664         * @hide
8665         */
8666        public static final String EXTRA_PHONE_URIS =
8667            "com.android.contacts.extra.PHONE_URIS";
8668
8669        /**
8670         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8671         * dialog location using screen coordinates. When not specified, the
8672         * dialog will be centered.
8673         *
8674         * @hide
8675         */
8676        @Deprecated
8677        public static final String EXTRA_TARGET_RECT = "target_rect";
8678
8679        /**
8680         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8681         * desired dialog style, usually a variation on size. One of
8682         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
8683         *
8684         * @hide
8685         */
8686        @Deprecated
8687        public static final String EXTRA_MODE = "mode";
8688
8689        /**
8690         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
8691         *
8692         * @hide
8693         */
8694        @Deprecated
8695        public static final int MODE_SMALL = 1;
8696
8697        /**
8698         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
8699         *
8700         * @hide
8701         */
8702        @Deprecated
8703        public static final int MODE_MEDIUM = 2;
8704
8705        /**
8706         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
8707         *
8708         * @hide
8709         */
8710        @Deprecated
8711        public static final int MODE_LARGE = 3;
8712
8713        /**
8714         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
8715         * a list of specific MIME-types to exclude and not display. Stored as a
8716         * {@link String} array.
8717         *
8718         * @hide
8719         */
8720        @Deprecated
8721        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
8722
8723        /**
8724         * Convenience class that contains string constants used
8725         * to create contact {@link android.content.Intent Intents}.
8726         */
8727        public static final class Insert {
8728            /** The action code to use when adding a contact */
8729            public static final String ACTION = Intent.ACTION_INSERT;
8730
8731            /**
8732             * If present, forces a bypass of quick insert mode.
8733             */
8734            public static final String FULL_MODE = "full_mode";
8735
8736            /**
8737             * The extra field for the contact name.
8738             * <P>Type: String</P>
8739             */
8740            public static final String NAME = "name";
8741
8742            // TODO add structured name values here.
8743
8744            /**
8745             * The extra field for the contact phonetic name.
8746             * <P>Type: String</P>
8747             */
8748            public static final String PHONETIC_NAME = "phonetic_name";
8749
8750            /**
8751             * The extra field for the contact company.
8752             * <P>Type: String</P>
8753             */
8754            public static final String COMPANY = "company";
8755
8756            /**
8757             * The extra field for the contact job title.
8758             * <P>Type: String</P>
8759             */
8760            public static final String JOB_TITLE = "job_title";
8761
8762            /**
8763             * The extra field for the contact notes.
8764             * <P>Type: String</P>
8765             */
8766            public static final String NOTES = "notes";
8767
8768            /**
8769             * The extra field for the contact phone number.
8770             * <P>Type: String</P>
8771             */
8772            public static final String PHONE = "phone";
8773
8774            /**
8775             * The extra field for the contact phone number type.
8776             * <P>Type: Either an integer value from
8777             * {@link CommonDataKinds.Phone},
8778             *  or a string specifying a custom label.</P>
8779             */
8780            public static final String PHONE_TYPE = "phone_type";
8781
8782            /**
8783             * The extra field for the phone isprimary flag.
8784             * <P>Type: boolean</P>
8785             */
8786            public static final String PHONE_ISPRIMARY = "phone_isprimary";
8787
8788            /**
8789             * The extra field for an optional second contact phone number.
8790             * <P>Type: String</P>
8791             */
8792            public static final String SECONDARY_PHONE = "secondary_phone";
8793
8794            /**
8795             * The extra field for an optional second contact phone number type.
8796             * <P>Type: Either an integer value from
8797             * {@link CommonDataKinds.Phone},
8798             *  or a string specifying a custom label.</P>
8799             */
8800            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
8801
8802            /**
8803             * The extra field for an optional third contact phone number.
8804             * <P>Type: String</P>
8805             */
8806            public static final String TERTIARY_PHONE = "tertiary_phone";
8807
8808            /**
8809             * The extra field for an optional third contact phone number type.
8810             * <P>Type: Either an integer value from
8811             * {@link CommonDataKinds.Phone},
8812             *  or a string specifying a custom label.</P>
8813             */
8814            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
8815
8816            /**
8817             * The extra field for the contact email address.
8818             * <P>Type: String</P>
8819             */
8820            public static final String EMAIL = "email";
8821
8822            /**
8823             * The extra field for the contact email type.
8824             * <P>Type: Either an integer value from
8825             * {@link CommonDataKinds.Email}
8826             *  or a string specifying a custom label.</P>
8827             */
8828            public static final String EMAIL_TYPE = "email_type";
8829
8830            /**
8831             * The extra field for the email isprimary flag.
8832             * <P>Type: boolean</P>
8833             */
8834            public static final String EMAIL_ISPRIMARY = "email_isprimary";
8835
8836            /**
8837             * The extra field for an optional second contact email address.
8838             * <P>Type: String</P>
8839             */
8840            public static final String SECONDARY_EMAIL = "secondary_email";
8841
8842            /**
8843             * The extra field for an optional second contact email type.
8844             * <P>Type: Either an integer value from
8845             * {@link CommonDataKinds.Email}
8846             *  or a string specifying a custom label.</P>
8847             */
8848            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
8849
8850            /**
8851             * The extra field for an optional third contact email address.
8852             * <P>Type: String</P>
8853             */
8854            public static final String TERTIARY_EMAIL = "tertiary_email";
8855
8856            /**
8857             * The extra field for an optional third contact email type.
8858             * <P>Type: Either an integer value from
8859             * {@link CommonDataKinds.Email}
8860             *  or a string specifying a custom label.</P>
8861             */
8862            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
8863
8864            /**
8865             * The extra field for the contact postal address.
8866             * <P>Type: String</P>
8867             */
8868            public static final String POSTAL = "postal";
8869
8870            /**
8871             * The extra field for the contact postal address type.
8872             * <P>Type: Either an integer value from
8873             * {@link CommonDataKinds.StructuredPostal}
8874             *  or a string specifying a custom label.</P>
8875             */
8876            public static final String POSTAL_TYPE = "postal_type";
8877
8878            /**
8879             * The extra field for the postal isprimary flag.
8880             * <P>Type: boolean</P>
8881             */
8882            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
8883
8884            /**
8885             * The extra field for an IM handle.
8886             * <P>Type: String</P>
8887             */
8888            public static final String IM_HANDLE = "im_handle";
8889
8890            /**
8891             * The extra field for the IM protocol
8892             */
8893            public static final String IM_PROTOCOL = "im_protocol";
8894
8895            /**
8896             * The extra field for the IM isprimary flag.
8897             * <P>Type: boolean</P>
8898             */
8899            public static final String IM_ISPRIMARY = "im_isprimary";
8900
8901            /**
8902             * The extra field that allows the client to supply multiple rows of
8903             * arbitrary data for a single contact created using the {@link Intent#ACTION_INSERT}
8904             * or edited using {@link Intent#ACTION_EDIT}. It is an ArrayList of
8905             * {@link ContentValues}, one per data row. Supplying this extra is
8906             * similar to inserting multiple rows into the {@link Data} table,
8907             * except the user gets a chance to see and edit them before saving.
8908             * Each ContentValues object must have a value for {@link Data#MIMETYPE}.
8909             * If supplied values are not visible in the editor UI, they will be
8910             * dropped.  Duplicate data will dropped.  Some fields
8911             * like {@link CommonDataKinds.Email#TYPE Email.TYPE} may be automatically
8912             * adjusted to comply with the constraints of the specific account type.
8913             * For example, an Exchange contact can only have one phone numbers of type Home,
8914             * so the contact editor may choose a different type for this phone number to
8915             * avoid dropping the valueable part of the row, which is the phone number.
8916             * <p>
8917             * Example:
8918             * <pre>
8919             *  ArrayList&lt;ContentValues&gt; data = new ArrayList&lt;ContentValues&gt;();
8920             *
8921             *  ContentValues row1 = new ContentValues();
8922             *  row1.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
8923             *  row1.put(Organization.COMPANY, "Android");
8924             *  data.add(row1);
8925             *
8926             *  ContentValues row2 = new ContentValues();
8927             *  row2.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
8928             *  row2.put(Email.TYPE, Email.TYPE_CUSTOM);
8929             *  row2.put(Email.LABEL, "Green Bot");
8930             *  row2.put(Email.ADDRESS, "android@android.com");
8931             *  data.add(row2);
8932             *
8933             *  Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
8934             *  intent.putParcelableArrayListExtra(Insert.DATA, data);
8935             *
8936             *  startActivity(intent);
8937             * </pre>
8938             */
8939            public static final String DATA = "data";
8940
8941            /**
8942             * Used to specify the account in which to create the new contact.
8943             * <p>
8944             * If this value is not provided, the user is presented with a disambiguation
8945             * dialog to chose an account
8946             * <p>
8947             * Type: {@link Account}
8948             */
8949            public static final String EXTRA_ACCOUNT = "android.provider.extra.ACCOUNT";
8950
8951            /**
8952             * Used to specify the data set within the account in which to create the
8953             * new contact.
8954             * <p>
8955             * This value is optional - if it is not specified, the contact will be
8956             * created in the base account, with no data set.
8957             * <p>
8958             * Type: String
8959             */
8960            public static final String EXTRA_DATA_SET = "android.provider.extra.DATA_SET";
8961        }
8962    }
8963
8964    /**
8965     * @hide
8966     */
8967    @SystemApi
8968    protected interface MetadataSyncColumns {
8969
8970        /**
8971         * The raw contact backup id.
8972         * A reference to the {@link ContactsContract.RawContacts#BACKUP_ID} that save the
8973         * persistent unique id for each raw contact within its source system.
8974         */
8975        public static final String RAW_CONTACT_BACKUP_ID = "raw_contact_backup_id";
8976
8977        /**
8978         * The account type to which the raw_contact of this item is associated. See
8979         * {@link RawContacts#ACCOUNT_TYPE}
8980         */
8981        public static final String ACCOUNT_TYPE = "account_type";
8982
8983        /**
8984         * The account name to which the raw_contact of this item is associated. See
8985         * {@link RawContacts#ACCOUNT_NAME}
8986         */
8987        public static final String ACCOUNT_NAME = "account_name";
8988
8989        /**
8990         * The data set within the account that the raw_contact of this row belongs to. This allows
8991         * multiple sync adapters for the same account type to distinguish between
8992         * each others' data.
8993         * {@link RawContacts#DATA_SET}
8994         */
8995        public static final String DATA_SET = "data_set";
8996
8997        /**
8998         * A text column contains the Json string got from People API. The Json string contains
8999         * all the metadata related to the raw contact, i.e., all the data fields and
9000         * aggregation exceptions.
9001         *
9002         * Here is an example of the Json string got from the actual schema.
9003         * <pre>
9004         *     {
9005         *       "unique_contact_id": {
9006         *         "account_type": "CUSTOM_ACCOUNT",
9007         *         "custom_account_type": "facebook",
9008         *         "account_name": "android-test",
9009         *         "contact_id": "1111111",
9010         *         "data_set": "FOCUS"
9011         *       },
9012         *       "contact_prefs": {
9013         *         "send_to_voicemail": true,
9014         *         "starred": false,
9015         *         "pinned": 2
9016         *       },
9017         *       "aggregation_data": [
9018         *         {
9019         *           "type": "TOGETHER",
9020         *           "contact_ids": [
9021         *             {
9022         *               "account_type": "GOOGLE_ACCOUNT",
9023         *               "account_name": "android-test2",
9024         *               "contact_id": "2222222",
9025         *               "data_set": "GOOGLE_PLUS"
9026         *             },
9027         *             {
9028         *               "account_type": "GOOGLE_ACCOUNT",
9029         *               "account_name": "android-test3",
9030         *               "contact_id": "3333333",
9031         *               "data_set": "CUSTOM",
9032         *               "custom_data_set": "custom type"
9033         *             }
9034         *           ]
9035         *         }
9036         *       ],
9037         *       "field_data": [
9038         *         {
9039         *           "field_data_id": "1001",
9040         *           "field_data_prefs": {
9041         *             "is_primary": true,
9042         *             "is_super_primary": true
9043         *           },
9044         *           "usage_stats": [
9045         *             {
9046         *               "usage_type": "CALL",
9047         *               "last_time_used": 10000001,
9048         *               "usage_count": 10
9049         *             }
9050         *           ]
9051         *         }
9052         *       ]
9053         *     }
9054         * </pre>
9055         */
9056        public static final String DATA = "data";
9057
9058        /**
9059         * The "deleted" flag: "0" by default, "1" if the row has been marked
9060         * for deletion. When {@link android.content.ContentResolver#delete} is
9061         * called on a raw contact, updating MetadataSync table to set the flag of the raw contact
9062         * as "1", then metadata sync adapter deletes the raw contact metadata on the server.
9063         * <P>Type: INTEGER</P>
9064         */
9065        public static final String DELETED = "deleted";
9066    }
9067
9068    /**
9069     * Constants for the metadata sync table. This table is used to cache the metadata_sync data
9070     * from server before it is merged into other CP2 tables.
9071     *
9072     * @hide
9073     */
9074    @SystemApi
9075    public static final class MetadataSync implements BaseColumns, MetadataSyncColumns {
9076
9077        /** The authority for the contacts metadata */
9078        public static final String METADATA_AUTHORITY = "com.android.contacts.metadata";
9079
9080        /** A content:// style uri to the authority for the contacts metadata */
9081        public static final Uri METADATA_AUTHORITY_URI = Uri.parse(
9082                "content://" + METADATA_AUTHORITY);
9083
9084        /**
9085         * This utility class cannot be instantiated
9086         */
9087        private MetadataSync() {
9088        }
9089
9090        /**
9091         * The content:// style URI for this table.
9092         */
9093        public static final Uri CONTENT_URI = Uri.withAppendedPath(METADATA_AUTHORITY_URI,
9094                "metadata_sync");
9095
9096        /**
9097         * The MIME type of {@link #CONTENT_URI} providing a directory of contact metadata
9098         */
9099        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/contact_metadata";
9100
9101        /**
9102         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single contact metadata.
9103         */
9104        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_metadata";
9105    }
9106}
9107