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