ContactsContract.java revision 73f43da5090b77467b4a7eed30225955f04ab9cc
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         * URI used for the "enterprise caller-id".
4998         *
4999         * It supports the same semantics as {@link #CONTENT_FILTER_URI} and returns the same
5000         * columns.  If the device has no corp profile that is linked to the current profile, it
5001         * behaves in the exact same way as {@link #CONTENT_FILTER_URI}.  If there is a corp profile
5002         * linked to the current profile, it first queries against the personal contact database,
5003         * and if no matching contacts are found there, then queries against the
5004         * corp contacts database.
5005         * <p>
5006         * If a result is from the corp profile, it makes the following changes to the data:
5007         * <ul>
5008         *     <li>
5009         *     {@link #PHOTO_THUMBNAIL_URI} and {@link #PHOTO_URI} will be rewritten to special
5010         *     URIs.  Use {@link ContentResolver#openAssetFileDescriptor} or its siblings to
5011         *     load pictures from them.
5012         *     {@link #PHOTO_ID} and {@link #PHOTO_FILE_ID} will be set to null.  Do not use them.
5013         *     </li>
5014         *     <li>
5015         *     Corp contacts will get artificial {@link #_ID}s.  In order to tell whether a contact
5016         *     is from the corp profile, use
5017         *     {@link ContactsContract.Contacts#isEnterpriseContactId(long)}.
5018         *     </li>
5019         * </ul>
5020         * <p>
5021         * This URI does NOT support selection nor order-by.
5022         *
5023         * <pre>
5024         * Uri lookupUri = Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
5025         *         Uri.encode(phoneNumber));
5026         * </pre>
5027         */
5028        public static final Uri ENTERPRISE_CONTENT_FILTER_URI = Uri.withAppendedPath(AUTHORITY_URI,
5029                "phone_lookup_enterprise");
5030
5031        /**
5032         * The MIME type of {@link #CONTENT_FILTER_URI} providing a directory of phone lookup rows.
5033         *
5034         * @hide
5035         */
5036        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_lookup";
5037
5038        /**
5039         * If this boolean parameter is set to true, then the appended query is treated as a
5040         * SIP address and the lookup will be performed against SIP addresses in the user's
5041         * contacts.
5042         */
5043        public static final String QUERY_PARAMETER_SIP_ADDRESS = "sip";
5044    }
5045
5046    /**
5047     * Additional data mixed in with {@link StatusColumns} to link
5048     * back to specific {@link ContactsContract.Data#_ID} entries.
5049     *
5050     * @see StatusUpdates
5051     */
5052    protected interface PresenceColumns {
5053
5054        /**
5055         * Reference to the {@link Data#_ID} entry that owns this presence.
5056         * <P>Type: INTEGER</P>
5057         */
5058        public static final String DATA_ID = "presence_data_id";
5059
5060        /**
5061         * See {@link CommonDataKinds.Im} for a list of defined protocol constants.
5062         * <p>Type: NUMBER</p>
5063         */
5064        public static final String PROTOCOL = "protocol";
5065
5066        /**
5067         * Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
5068         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
5069         * omitted if {@link #PROTOCOL} value is not
5070         * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.
5071         *
5072         * <p>Type: NUMBER</p>
5073         */
5074        public static final String CUSTOM_PROTOCOL = "custom_protocol";
5075
5076        /**
5077         * The IM handle the presence item is for. The handle is scoped to
5078         * {@link #PROTOCOL}.
5079         * <P>Type: TEXT</P>
5080         */
5081        public static final String IM_HANDLE = "im_handle";
5082
5083        /**
5084         * The IM account for the local user that the presence data came from.
5085         * <P>Type: TEXT</P>
5086         */
5087        public static final String IM_ACCOUNT = "im_account";
5088    }
5089
5090    /**
5091     * <p>
5092     * A status update is linked to a {@link ContactsContract.Data} row and captures
5093     * the user's latest status update via the corresponding source, e.g.
5094     * "Having lunch" via "Google Talk".
5095     * </p>
5096     * <p>
5097     * There are two ways a status update can be inserted: by explicitly linking
5098     * it to a Data row using {@link #DATA_ID} or indirectly linking it to a data row
5099     * using a combination of {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
5100     * {@link #IM_HANDLE}.  There is no difference between insert and update, you can use
5101     * either.
5102     * </p>
5103     * <p>
5104     * Inserting or updating a status update for the user's profile requires either using
5105     * the {@link #DATA_ID} to identify the data row to attach the update to, or
5106     * {@link StatusUpdates#PROFILE_CONTENT_URI} to ensure that the change is scoped to the
5107     * profile.
5108     * </p>
5109     * <p>
5110     * You cannot use {@link ContentResolver#update} to change a status, but
5111     * {@link ContentResolver#insert} will replace the latests status if it already
5112     * exists.
5113     * </p>
5114     * <p>
5115     * Use {@link ContentResolver#bulkInsert(Uri, ContentValues[])} to insert/update statuses
5116     * for multiple contacts at once.
5117     * </p>
5118     *
5119     * <h3>Columns</h3>
5120     * <table class="jd-sumtable">
5121     * <tr>
5122     * <th colspan='4'>StatusUpdates</th>
5123     * </tr>
5124     * <tr>
5125     * <td>long</td>
5126     * <td>{@link #DATA_ID}</td>
5127     * <td>read/write</td>
5128     * <td>Reference to the {@link Data#_ID} entry that owns this presence. If this
5129     * field is <i>not</i> specified, the provider will attempt to find a data row
5130     * that matches the {@link #PROTOCOL} (or {@link #CUSTOM_PROTOCOL}) and
5131     * {@link #IM_HANDLE} columns.
5132     * </td>
5133     * </tr>
5134     * <tr>
5135     * <td>long</td>
5136     * <td>{@link #PROTOCOL}</td>
5137     * <td>read/write</td>
5138     * <td>See {@link CommonDataKinds.Im} for a list of defined protocol constants.</td>
5139     * </tr>
5140     * <tr>
5141     * <td>String</td>
5142     * <td>{@link #CUSTOM_PROTOCOL}</td>
5143     * <td>read/write</td>
5144     * <td>Name of the custom protocol.  Should be supplied along with the {@link #PROTOCOL} value
5145     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.  Should be null or
5146     * omitted if {@link #PROTOCOL} value is not
5147     * {@link ContactsContract.CommonDataKinds.Im#PROTOCOL_CUSTOM}.</td>
5148     * </tr>
5149     * <tr>
5150     * <td>String</td>
5151     * <td>{@link #IM_HANDLE}</td>
5152     * <td>read/write</td>
5153     * <td> The IM handle the presence item is for. The handle is scoped to
5154     * {@link #PROTOCOL}.</td>
5155     * </tr>
5156     * <tr>
5157     * <td>String</td>
5158     * <td>{@link #IM_ACCOUNT}</td>
5159     * <td>read/write</td>
5160     * <td>The IM account for the local user that the presence data came from.</td>
5161     * </tr>
5162     * <tr>
5163     * <td>int</td>
5164     * <td>{@link #PRESENCE}</td>
5165     * <td>read/write</td>
5166     * <td>Contact IM presence status. The allowed values are:
5167     * <p>
5168     * <ul>
5169     * <li>{@link #OFFLINE}</li>
5170     * <li>{@link #INVISIBLE}</li>
5171     * <li>{@link #AWAY}</li>
5172     * <li>{@link #IDLE}</li>
5173     * <li>{@link #DO_NOT_DISTURB}</li>
5174     * <li>{@link #AVAILABLE}</li>
5175     * </ul>
5176     * </p>
5177     * <p>
5178     * Since presence status is inherently volatile, the content provider
5179     * may choose not to store this field in long-term storage.
5180     * </p>
5181     * </td>
5182     * </tr>
5183     * <tr>
5184     * <td>int</td>
5185     * <td>{@link #CHAT_CAPABILITY}</td>
5186     * <td>read/write</td>
5187     * <td>Contact IM chat compatibility value. The allowed values combinations of the following
5188     * flags. If None of these flags is set, the device can only do text messaging.
5189     * <p>
5190     * <ul>
5191     * <li>{@link #CAPABILITY_HAS_VIDEO}</li>
5192     * <li>{@link #CAPABILITY_HAS_VOICE}</li>
5193     * <li>{@link #CAPABILITY_HAS_CAMERA}</li>
5194     * </ul>
5195     * </p>
5196     * <p>
5197     * Since chat compatibility is inherently volatile as the contact's availability moves from
5198     * one device to another, the content provider may choose not to store this field in long-term
5199     * storage.
5200     * </p>
5201     * </td>
5202     * </tr>
5203     * <tr>
5204     * <td>String</td>
5205     * <td>{@link #STATUS}</td>
5206     * <td>read/write</td>
5207     * <td>Contact's latest status update, e.g. "having toast for breakfast"</td>
5208     * </tr>
5209     * <tr>
5210     * <td>long</td>
5211     * <td>{@link #STATUS_TIMESTAMP}</td>
5212     * <td>read/write</td>
5213     * <td>The absolute time in milliseconds when the status was
5214     * entered by the user. If this value is not provided, the provider will follow
5215     * this logic: if there was no prior status update, the value will be left as null.
5216     * If there was a prior status update, the provider will default this field
5217     * to the current time.</td>
5218     * </tr>
5219     * <tr>
5220     * <td>String</td>
5221     * <td>{@link #STATUS_RES_PACKAGE}</td>
5222     * <td>read/write</td>
5223     * <td> The package containing resources for this status: label and icon.</td>
5224     * </tr>
5225     * <tr>
5226     * <td>long</td>
5227     * <td>{@link #STATUS_LABEL}</td>
5228     * <td>read/write</td>
5229     * <td>The resource ID of the label describing the source of contact status,
5230     * e.g. "Google Talk". This resource is scoped by the
5231     * {@link #STATUS_RES_PACKAGE}.</td>
5232     * </tr>
5233     * <tr>
5234     * <td>long</td>
5235     * <td>{@link #STATUS_ICON}</td>
5236     * <td>read/write</td>
5237     * <td>The resource ID of the icon for the source of contact status. This
5238     * resource is scoped by the {@link #STATUS_RES_PACKAGE}.</td>
5239     * </tr>
5240     * </table>
5241     */
5242    public static class StatusUpdates implements StatusColumns, PresenceColumns {
5243
5244        /**
5245         * This utility class cannot be instantiated
5246         */
5247        private StatusUpdates() {}
5248
5249        /**
5250         * The content:// style URI for this table
5251         */
5252        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "status_updates");
5253
5254        /**
5255         * The content:// style URI for this table, specific to the user's profile.
5256         */
5257        public static final Uri PROFILE_CONTENT_URI =
5258                Uri.withAppendedPath(Profile.CONTENT_URI, "status_updates");
5259
5260        /**
5261         * Gets the resource ID for the proper presence icon.
5262         *
5263         * @param status the status to get the icon for
5264         * @return the resource ID for the proper presence icon
5265         */
5266        public static final int getPresenceIconResourceId(int status) {
5267            switch (status) {
5268                case AVAILABLE:
5269                    return android.R.drawable.presence_online;
5270                case IDLE:
5271                case AWAY:
5272                    return android.R.drawable.presence_away;
5273                case DO_NOT_DISTURB:
5274                    return android.R.drawable.presence_busy;
5275                case INVISIBLE:
5276                    return android.R.drawable.presence_invisible;
5277                case OFFLINE:
5278                default:
5279                    return android.R.drawable.presence_offline;
5280            }
5281        }
5282
5283        /**
5284         * Returns the precedence of the status code the higher number being the higher precedence.
5285         *
5286         * @param status The status code.
5287         * @return An integer representing the precedence, 0 being the lowest.
5288         */
5289        public static final int getPresencePrecedence(int status) {
5290            // Keep this function here incase we want to enforce a different precedence than the
5291            // natural order of the status constants.
5292            return status;
5293        }
5294
5295        /**
5296         * The MIME type of {@link #CONTENT_URI} providing a directory of
5297         * status update details.
5298         */
5299        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/status-update";
5300
5301        /**
5302         * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
5303         * status update detail.
5304         */
5305        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/status-update";
5306    }
5307
5308    /**
5309     * @deprecated This old name was never meant to be made public. Do not use.
5310     */
5311    @Deprecated
5312    public static final class Presence extends StatusUpdates {
5313
5314    }
5315
5316    /**
5317     * Additional column returned by
5318     * {@link ContactsContract.Contacts#CONTENT_FILTER_URI Contacts.CONTENT_FILTER_URI} explaining
5319     * why the filter matched the contact. This column will contain extracts from the contact's
5320     * constituent {@link Data Data} items, formatted in a way that indicates the section of the
5321     * snippet that matched the filter.
5322     *
5323     * <p>
5324     * The following example searches for all contacts that match the query "presi" and requests
5325     * the snippet column as well.
5326     * <pre>
5327     * Builder builder = Contacts.CONTENT_FILTER_URI.buildUpon();
5328     * builder.appendPath("presi");
5329     * // Defer snippeting to the client side if possible, for performance reasons.
5330     * builder.appendQueryParameter(SearchSnippets.DEFERRED_SNIPPETING_KEY,"1");
5331     *
5332     * Cursor cursor = getContentResolver().query(builder.build());
5333     *
5334     * Bundle extras = cursor.getExtras();
5335     * if (extras.getBoolean(ContactsContract.DEFERRED_SNIPPETING)) {
5336     *     // Do our own snippet formatting.
5337     *     // For a contact with the email address (president@organization.com), the snippet
5338     *     // column will contain the string "president@organization.com".
5339     * } else {
5340     *     // The snippet has already been pre-formatted, we can display it as is.
5341     *     // For a contact with the email address (president@organization.com), the snippet
5342     *     // column will contain the string "[presi]dent@organization.com".
5343     * }
5344     * </pre>
5345     * </p>
5346     */
5347    public static class SearchSnippets {
5348
5349        /**
5350         * The search snippet constructed by SQLite snippeting functionality.
5351         * <p>
5352         * The snippet may contain (parts of) several data elements belonging to the contact,
5353         * with the matching parts optionally surrounded by special characters that indicate the
5354         * start and end of matching text.
5355         *
5356         * For example, if a contact has an address "123 Main Street", using a filter "mai" would
5357         * return the formatted snippet "123 [Mai]n street".
5358         *
5359         * @see <a href="http://www.sqlite.org/fts3.html#snippet">
5360         *         http://www.sqlite.org/fts3.html#snippet</a>
5361         */
5362        public static final String SNIPPET = "snippet";
5363
5364        /**
5365         * Comma-separated parameters for the generation of the snippet:
5366         * <ul>
5367         * <li>The "start match" text. Default is '['</li>
5368         * <li>The "end match" text. Default is ']'</li>
5369         * <li>The "ellipsis" text. Default is "..."</li>
5370         * <li>Maximum number of tokens to include in the snippet. Can be either
5371         * a positive or a negative number: A positive number indicates how many
5372         * tokens can be returned in total. A negative number indicates how many
5373         * tokens can be returned per occurrence of the search terms.</li>
5374         * </ul>
5375         *
5376         * @hide
5377         */
5378        public static final String SNIPPET_ARGS_PARAM_KEY = "snippet_args";
5379
5380        /**
5381         * The key to ask the provider to defer the formatting of the snippet to the client if
5382         * possible, for performance reasons.
5383         * A value of 1 indicates true, 0 indicates false. False is the default.
5384         * When a cursor is returned to the client, it should check for an extra with the name
5385         * {@link ContactsContract#DEFERRED_SNIPPETING} in the cursor. If it exists, the client
5386         * should do its own formatting of the snippet. If it doesn't exist, the snippet column
5387         * in the cursor should already contain a formatted snippet.
5388         */
5389        public static final String DEFERRED_SNIPPETING_KEY = "deferred_snippeting";
5390    }
5391
5392    /**
5393     * Container for definitions of common data types stored in the {@link ContactsContract.Data}
5394     * table.
5395     */
5396    public static final class CommonDataKinds {
5397        /**
5398         * This utility class cannot be instantiated
5399         */
5400        private CommonDataKinds() {}
5401
5402        /**
5403         * The {@link Data#RES_PACKAGE} value for common data that should be
5404         * shown using a default style.
5405         *
5406         * @hide RES_PACKAGE is hidden
5407         */
5408        public static final String PACKAGE_COMMON = "common";
5409
5410        /**
5411         * The base types that all "Typed" data kinds support.
5412         */
5413        public interface BaseTypes {
5414            /**
5415             * A custom type. The custom label should be supplied by user.
5416             */
5417            public static int TYPE_CUSTOM = 0;
5418        }
5419
5420        /**
5421         * Columns common across the specific types.
5422         */
5423        protected interface CommonColumns extends BaseTypes {
5424            /**
5425             * The data for the contact method.
5426             * <P>Type: TEXT</P>
5427             */
5428            public static final String DATA = DataColumns.DATA1;
5429
5430            /**
5431             * The type of data, for example Home or Work.
5432             * <P>Type: INTEGER</P>
5433             */
5434            public static final String TYPE = DataColumns.DATA2;
5435
5436            /**
5437             * The user defined label for the the contact method.
5438             * <P>Type: TEXT</P>
5439             */
5440            public static final String LABEL = DataColumns.DATA3;
5441        }
5442
5443        /**
5444         * A data kind representing the contact's proper name. You can use all
5445         * columns defined for {@link ContactsContract.Data} as well as the following aliases.
5446         *
5447         * <h2>Column aliases</h2>
5448         * <table class="jd-sumtable">
5449         * <tr>
5450         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
5451         * </tr>
5452         * <tr>
5453         * <td>String</td>
5454         * <td>{@link #DISPLAY_NAME}</td>
5455         * <td>{@link #DATA1}</td>
5456         * <td></td>
5457         * </tr>
5458         * <tr>
5459         * <td>String</td>
5460         * <td>{@link #GIVEN_NAME}</td>
5461         * <td>{@link #DATA2}</td>
5462         * <td></td>
5463         * </tr>
5464         * <tr>
5465         * <td>String</td>
5466         * <td>{@link #FAMILY_NAME}</td>
5467         * <td>{@link #DATA3}</td>
5468         * <td></td>
5469         * </tr>
5470         * <tr>
5471         * <td>String</td>
5472         * <td>{@link #PREFIX}</td>
5473         * <td>{@link #DATA4}</td>
5474         * <td>Common prefixes in English names are "Mr", "Ms", "Dr" etc.</td>
5475         * </tr>
5476         * <tr>
5477         * <td>String</td>
5478         * <td>{@link #MIDDLE_NAME}</td>
5479         * <td>{@link #DATA5}</td>
5480         * <td></td>
5481         * </tr>
5482         * <tr>
5483         * <td>String</td>
5484         * <td>{@link #SUFFIX}</td>
5485         * <td>{@link #DATA6}</td>
5486         * <td>Common suffixes in English names are "Sr", "Jr", "III" etc.</td>
5487         * </tr>
5488         * <tr>
5489         * <td>String</td>
5490         * <td>{@link #PHONETIC_GIVEN_NAME}</td>
5491         * <td>{@link #DATA7}</td>
5492         * <td>Used for phonetic spelling of the name, e.g. Pinyin, Katakana, Hiragana</td>
5493         * </tr>
5494         * <tr>
5495         * <td>String</td>
5496         * <td>{@link #PHONETIC_MIDDLE_NAME}</td>
5497         * <td>{@link #DATA8}</td>
5498         * <td></td>
5499         * </tr>
5500         * <tr>
5501         * <td>String</td>
5502         * <td>{@link #PHONETIC_FAMILY_NAME}</td>
5503         * <td>{@link #DATA9}</td>
5504         * <td></td>
5505         * </tr>
5506         * </table>
5507         */
5508        public static final class StructuredName implements DataColumnsWithJoins, ContactCounts {
5509            /**
5510             * This utility class cannot be instantiated
5511             */
5512            private StructuredName() {}
5513
5514            /** MIME type used when storing this in data table. */
5515            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/name";
5516
5517            /**
5518             * The name that should be used to display the contact.
5519             * <i>Unstructured component of the name should be consistent with
5520             * its structured representation.</i>
5521             * <p>
5522             * Type: TEXT
5523             */
5524            public static final String DISPLAY_NAME = DATA1;
5525
5526            /**
5527             * The given name for the contact.
5528             * <P>Type: TEXT</P>
5529             */
5530            public static final String GIVEN_NAME = DATA2;
5531
5532            /**
5533             * The family name for the contact.
5534             * <P>Type: TEXT</P>
5535             */
5536            public static final String FAMILY_NAME = DATA3;
5537
5538            /**
5539             * The contact's honorific prefix, e.g. "Sir"
5540             * <P>Type: TEXT</P>
5541             */
5542            public static final String PREFIX = DATA4;
5543
5544            /**
5545             * The contact's middle name
5546             * <P>Type: TEXT</P>
5547             */
5548            public static final String MIDDLE_NAME = DATA5;
5549
5550            /**
5551             * The contact's honorific suffix, e.g. "Jr"
5552             */
5553            public static final String SUFFIX = DATA6;
5554
5555            /**
5556             * The phonetic version of the given name for the contact.
5557             * <P>Type: TEXT</P>
5558             */
5559            public static final String PHONETIC_GIVEN_NAME = DATA7;
5560
5561            /**
5562             * The phonetic version of the additional name for the contact.
5563             * <P>Type: TEXT</P>
5564             */
5565            public static final String PHONETIC_MIDDLE_NAME = DATA8;
5566
5567            /**
5568             * The phonetic version of the family name for the contact.
5569             * <P>Type: TEXT</P>
5570             */
5571            public static final String PHONETIC_FAMILY_NAME = DATA9;
5572
5573            /**
5574             * The style used for combining given/middle/family name into a full name.
5575             * See {@link ContactsContract.FullNameStyle}.
5576             */
5577            public static final String FULL_NAME_STYLE = DATA10;
5578
5579            /**
5580             * The alphabet used for capturing the phonetic name.
5581             * See ContactsContract.PhoneticNameStyle.
5582             * @hide
5583             */
5584            public static final String PHONETIC_NAME_STYLE = DATA11;
5585        }
5586
5587        /**
5588         * <p>A data kind representing the contact's nickname. For example, for
5589         * Bob Parr ("Mr. Incredible"):
5590         * <pre>
5591         * ArrayList&lt;ContentProviderOperation&gt; ops =
5592         *          new ArrayList&lt;ContentProviderOperation&gt;();
5593         *
5594         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
5595         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
5596         *          .withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
5597         *          .withValue(StructuredName.DISPLAY_NAME, &quot;Bob Parr&quot;)
5598         *          .build());
5599         *
5600         * ops.add(ContentProviderOperation.newInsert(Data.CONTENT_URI)
5601         *          .withValue(Data.RAW_CONTACT_ID, rawContactId)
5602         *          .withValue(Data.MIMETYPE, Nickname.CONTENT_ITEM_TYPE)
5603         *          .withValue(Nickname.NAME, "Mr. Incredible")
5604         *          .withValue(Nickname.TYPE, Nickname.TYPE_CUSTOM)
5605         *          .withValue(Nickname.LABEL, "Superhero")
5606         *          .build());
5607         *
5608         * getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
5609         * </pre>
5610         * </p>
5611         * <p>
5612         * You can use all columns defined for {@link ContactsContract.Data} as well as the
5613         * following aliases.
5614         * </p>
5615         *
5616         * <h2>Column aliases</h2>
5617         * <table class="jd-sumtable">
5618         * <tr>
5619         * <th>Type</th><th>Alias</th><th colspan='2'>Data column</th>
5620         * </tr>
5621         * <tr>
5622         * <td>String</td>
5623         * <td>{@link #NAME}</td>
5624         * <td>{@link #DATA1}</td>
5625         * <td></td>
5626         * </tr>
5627         * <tr>
5628         * <td>int</td>
5629         * <td>{@link #TYPE}</td>
5630         * <td>{@link #DATA2}</td>
5631         * <td>
5632         * Allowed values are:
5633         * <p>
5634         * <ul>
5635         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5636         * <li>{@link #TYPE_DEFAULT}</li>
5637         * <li>{@link #TYPE_OTHER_NAME}</li>
5638         * <li>{@link #TYPE_MAIDEN_NAME}</li>
5639         * <li>{@link #TYPE_SHORT_NAME}</li>
5640         * <li>{@link #TYPE_INITIALS}</li>
5641         * </ul>
5642         * </p>
5643         * </td>
5644         * </tr>
5645         * <tr>
5646         * <td>String</td>
5647         * <td>{@link #LABEL}</td>
5648         * <td>{@link #DATA3}</td>
5649         * <td></td>
5650         * </tr>
5651         * </table>
5652         */
5653        public static final class Nickname implements DataColumnsWithJoins, CommonColumns,
5654                ContactCounts{
5655            /**
5656             * This utility class cannot be instantiated
5657             */
5658            private Nickname() {}
5659
5660            /** MIME type used when storing this in data table. */
5661            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/nickname";
5662
5663            public static final int TYPE_DEFAULT = 1;
5664            public static final int TYPE_OTHER_NAME = 2;
5665            public static final int TYPE_MAIDEN_NAME = 3;
5666            /** @deprecated Use TYPE_MAIDEN_NAME instead. */
5667            @Deprecated
5668            public static final int TYPE_MAINDEN_NAME = 3;
5669            public static final int TYPE_SHORT_NAME = 4;
5670            public static final int TYPE_INITIALS = 5;
5671
5672            /**
5673             * The name itself
5674             */
5675            public static final String NAME = DATA;
5676        }
5677
5678        /**
5679         * <p>
5680         * A data kind representing a telephone number.
5681         * </p>
5682         * <p>
5683         * You can use all columns defined for {@link ContactsContract.Data} as
5684         * well as the following aliases.
5685         * </p>
5686         * <h2>Column aliases</h2>
5687         * <table class="jd-sumtable">
5688         * <tr>
5689         * <th>Type</th>
5690         * <th>Alias</th><th colspan='2'>Data column</th>
5691         * </tr>
5692         * <tr>
5693         * <td>String</td>
5694         * <td>{@link #NUMBER}</td>
5695         * <td>{@link #DATA1}</td>
5696         * <td></td>
5697         * </tr>
5698         * <tr>
5699         * <td>int</td>
5700         * <td>{@link #TYPE}</td>
5701         * <td>{@link #DATA2}</td>
5702         * <td>Allowed values are:
5703         * <p>
5704         * <ul>
5705         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5706         * <li>{@link #TYPE_HOME}</li>
5707         * <li>{@link #TYPE_MOBILE}</li>
5708         * <li>{@link #TYPE_WORK}</li>
5709         * <li>{@link #TYPE_FAX_WORK}</li>
5710         * <li>{@link #TYPE_FAX_HOME}</li>
5711         * <li>{@link #TYPE_PAGER}</li>
5712         * <li>{@link #TYPE_OTHER}</li>
5713         * <li>{@link #TYPE_CALLBACK}</li>
5714         * <li>{@link #TYPE_CAR}</li>
5715         * <li>{@link #TYPE_COMPANY_MAIN}</li>
5716         * <li>{@link #TYPE_ISDN}</li>
5717         * <li>{@link #TYPE_MAIN}</li>
5718         * <li>{@link #TYPE_OTHER_FAX}</li>
5719         * <li>{@link #TYPE_RADIO}</li>
5720         * <li>{@link #TYPE_TELEX}</li>
5721         * <li>{@link #TYPE_TTY_TDD}</li>
5722         * <li>{@link #TYPE_WORK_MOBILE}</li>
5723         * <li>{@link #TYPE_WORK_PAGER}</li>
5724         * <li>{@link #TYPE_ASSISTANT}</li>
5725         * <li>{@link #TYPE_MMS}</li>
5726         * </ul>
5727         * </p>
5728         * </td>
5729         * </tr>
5730         * <tr>
5731         * <td>String</td>
5732         * <td>{@link #LABEL}</td>
5733         * <td>{@link #DATA3}</td>
5734         * <td></td>
5735         * </tr>
5736         * </table>
5737         */
5738        public static final class Phone implements DataColumnsWithJoins, CommonColumns,
5739                ContactCounts {
5740            /**
5741             * This utility class cannot be instantiated
5742             */
5743            private Phone() {}
5744
5745            /** MIME type used when storing this in data table. */
5746            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/phone_v2";
5747
5748            /**
5749             * The MIME type of {@link #CONTENT_URI} providing a directory of
5750             * phones.
5751             */
5752            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/phone_v2";
5753
5754            /**
5755             * The content:// style URI for all data records of the
5756             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
5757             * associated raw contact and aggregate contact data.
5758             */
5759            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
5760                    "phones");
5761
5762            /**
5763            * URI used for getting all contacts from primary and managed profile.
5764            *
5765            * It supports the same semantics as {@link #CONTENT_URI} and returns the same
5766            * columns.  If the device has no corp profile that is linked to the current profile, it
5767            * behaves in the exact same way as {@link #CONTENT_URI}.  If there is a corp profile
5768            * linked to the current profile, it will merge corp profile and current profile's
5769            * results and return
5770            *
5771            * @hide
5772            */
5773            public static final Uri ENTERPRISE_CONTENT_URI =
5774                    Uri.withAppendedPath(Data.ENTERPRISE_CONTENT_URI, "phones");
5775
5776            /**
5777             * The content:// style URL for phone lookup using a filter. The filter returns
5778             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
5779             * to display names as well as phone numbers. The filter argument should be passed
5780             * as an additional path segment after this URI.
5781             */
5782            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
5783                    "filter");
5784
5785            /**
5786             * A boolean query parameter that can be used with {@link #CONTENT_FILTER_URI}.
5787             * If "1" or "true", display names are searched.  If "0" or "false", display names
5788             * are not searched.  Default is "1".
5789             */
5790            public static final String SEARCH_DISPLAY_NAME_KEY = "search_display_name";
5791
5792            /**
5793             * A boolean query parameter that can be used with {@link #CONTENT_FILTER_URI}.
5794             * If "1" or "true", phone numbers are searched.  If "0" or "false", phone numbers
5795             * are not searched.  Default is "1".
5796             */
5797            public static final String SEARCH_PHONE_NUMBER_KEY = "search_phone_number";
5798
5799            public static final int TYPE_HOME = 1;
5800            public static final int TYPE_MOBILE = 2;
5801            public static final int TYPE_WORK = 3;
5802            public static final int TYPE_FAX_WORK = 4;
5803            public static final int TYPE_FAX_HOME = 5;
5804            public static final int TYPE_PAGER = 6;
5805            public static final int TYPE_OTHER = 7;
5806            public static final int TYPE_CALLBACK = 8;
5807            public static final int TYPE_CAR = 9;
5808            public static final int TYPE_COMPANY_MAIN = 10;
5809            public static final int TYPE_ISDN = 11;
5810            public static final int TYPE_MAIN = 12;
5811            public static final int TYPE_OTHER_FAX = 13;
5812            public static final int TYPE_RADIO = 14;
5813            public static final int TYPE_TELEX = 15;
5814            public static final int TYPE_TTY_TDD = 16;
5815            public static final int TYPE_WORK_MOBILE = 17;
5816            public static final int TYPE_WORK_PAGER = 18;
5817            public static final int TYPE_ASSISTANT = 19;
5818            public static final int TYPE_MMS = 20;
5819
5820            /**
5821             * The phone number as the user entered it.
5822             * <P>Type: TEXT</P>
5823             */
5824            public static final String NUMBER = DATA;
5825
5826            /**
5827             * The phone number's E164 representation. This value can be omitted in which
5828             * case the provider will try to automatically infer it.  (It'll be left null if the
5829             * provider fails to infer.)
5830             * If present, {@link #NUMBER} has to be set as well (it will be ignored otherwise).
5831             * <P>Type: TEXT</P>
5832             */
5833            public static final String NORMALIZED_NUMBER = DATA4;
5834
5835            /**
5836             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
5837             * @hide
5838             */
5839            @Deprecated
5840            public static final CharSequence getDisplayLabel(Context context, int type,
5841                    CharSequence label, CharSequence[] labelArray) {
5842                return getTypeLabel(context.getResources(), type, label);
5843            }
5844
5845            /**
5846             * @deprecated use {@link #getTypeLabel(Resources, int, CharSequence)} instead.
5847             * @hide
5848             */
5849            @Deprecated
5850            public static final CharSequence getDisplayLabel(Context context, int type,
5851                    CharSequence label) {
5852                return getTypeLabel(context.getResources(), type, label);
5853            }
5854
5855            /**
5856             * Return the string resource that best describes the given
5857             * {@link #TYPE}. Will always return a valid resource.
5858             */
5859            public static final int getTypeLabelResource(int type) {
5860                switch (type) {
5861                    case TYPE_HOME: return com.android.internal.R.string.phoneTypeHome;
5862                    case TYPE_MOBILE: return com.android.internal.R.string.phoneTypeMobile;
5863                    case TYPE_WORK: return com.android.internal.R.string.phoneTypeWork;
5864                    case TYPE_FAX_WORK: return com.android.internal.R.string.phoneTypeFaxWork;
5865                    case TYPE_FAX_HOME: return com.android.internal.R.string.phoneTypeFaxHome;
5866                    case TYPE_PAGER: return com.android.internal.R.string.phoneTypePager;
5867                    case TYPE_OTHER: return com.android.internal.R.string.phoneTypeOther;
5868                    case TYPE_CALLBACK: return com.android.internal.R.string.phoneTypeCallback;
5869                    case TYPE_CAR: return com.android.internal.R.string.phoneTypeCar;
5870                    case TYPE_COMPANY_MAIN: return com.android.internal.R.string.phoneTypeCompanyMain;
5871                    case TYPE_ISDN: return com.android.internal.R.string.phoneTypeIsdn;
5872                    case TYPE_MAIN: return com.android.internal.R.string.phoneTypeMain;
5873                    case TYPE_OTHER_FAX: return com.android.internal.R.string.phoneTypeOtherFax;
5874                    case TYPE_RADIO: return com.android.internal.R.string.phoneTypeRadio;
5875                    case TYPE_TELEX: return com.android.internal.R.string.phoneTypeTelex;
5876                    case TYPE_TTY_TDD: return com.android.internal.R.string.phoneTypeTtyTdd;
5877                    case TYPE_WORK_MOBILE: return com.android.internal.R.string.phoneTypeWorkMobile;
5878                    case TYPE_WORK_PAGER: return com.android.internal.R.string.phoneTypeWorkPager;
5879                    case TYPE_ASSISTANT: return com.android.internal.R.string.phoneTypeAssistant;
5880                    case TYPE_MMS: return com.android.internal.R.string.phoneTypeMms;
5881                    default: return com.android.internal.R.string.phoneTypeCustom;
5882                }
5883            }
5884
5885            /**
5886             * Return a {@link CharSequence} that best describes the given type,
5887             * possibly substituting the given {@link #LABEL} value
5888             * for {@link #TYPE_CUSTOM}.
5889             */
5890            public static final CharSequence getTypeLabel(Resources res, int type,
5891                    CharSequence label) {
5892                if ((type == TYPE_CUSTOM || type == TYPE_ASSISTANT) && !TextUtils.isEmpty(label)) {
5893                    return label;
5894                } else {
5895                    final int labelRes = getTypeLabelResource(type);
5896                    return res.getText(labelRes);
5897                }
5898            }
5899        }
5900
5901        /**
5902         * <p>
5903         * A data kind representing an email address.
5904         * </p>
5905         * <p>
5906         * You can use all columns defined for {@link ContactsContract.Data} as
5907         * well as the following aliases.
5908         * </p>
5909         * <h2>Column aliases</h2>
5910         * <table class="jd-sumtable">
5911         * <tr>
5912         * <th>Type</th>
5913         * <th>Alias</th><th colspan='2'>Data column</th>
5914         * </tr>
5915         * <tr>
5916         * <td>String</td>
5917         * <td>{@link #ADDRESS}</td>
5918         * <td>{@link #DATA1}</td>
5919         * <td>Email address itself.</td>
5920         * </tr>
5921         * <tr>
5922         * <td>int</td>
5923         * <td>{@link #TYPE}</td>
5924         * <td>{@link #DATA2}</td>
5925         * <td>Allowed values are:
5926         * <p>
5927         * <ul>
5928         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
5929         * <li>{@link #TYPE_HOME}</li>
5930         * <li>{@link #TYPE_WORK}</li>
5931         * <li>{@link #TYPE_OTHER}</li>
5932         * <li>{@link #TYPE_MOBILE}</li>
5933         * </ul>
5934         * </p>
5935         * </td>
5936         * </tr>
5937         * <tr>
5938         * <td>String</td>
5939         * <td>{@link #LABEL}</td>
5940         * <td>{@link #DATA3}</td>
5941         * <td></td>
5942         * </tr>
5943         * </table>
5944         */
5945        public static final class Email implements DataColumnsWithJoins, CommonColumns,
5946                ContactCounts {
5947            /**
5948             * This utility class cannot be instantiated
5949             */
5950            private Email() {}
5951
5952            /** MIME type used when storing this in data table. */
5953            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/email_v2";
5954
5955            /**
5956             * The MIME type of {@link #CONTENT_URI} providing a directory of email addresses.
5957             */
5958            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/email_v2";
5959
5960            /**
5961             * The content:// style URI for all data records of the
5962             * {@link #CONTENT_ITEM_TYPE} MIME type, combined with the
5963             * associated raw contact and aggregate contact data.
5964             */
5965            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
5966                    "emails");
5967
5968            /**
5969             * <p>
5970             * The content:// style URL for looking up data rows by email address. The
5971             * lookup argument, an email address, should be passed as an additional path segment
5972             * after this URI.
5973             * </p>
5974             * <p>Example:
5975             * <pre>
5976             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode(email));
5977             * Cursor c = getContentResolver().query(uri,
5978             *          new String[]{Email.CONTACT_ID, Email.DISPLAY_NAME, Email.DATA},
5979             *          null, null, null);
5980             * </pre>
5981             * </p>
5982             */
5983            public static final Uri CONTENT_LOOKUP_URI = Uri.withAppendedPath(CONTENT_URI,
5984                    "lookup");
5985
5986            /**
5987             * <p>
5988             * The content:// style URL for email lookup using a filter. The filter returns
5989             * records of MIME type {@link #CONTENT_ITEM_TYPE}. The filter is applied
5990             * to display names as well as email addresses. The filter argument should be passed
5991             * as an additional path segment after this URI.
5992             * </p>
5993             * <p>The query in the following example will return "Robert Parr (bob@incredibles.com)"
5994             * as well as "Bob Parr (incredible@android.com)".
5995             * <pre>
5996             * Uri uri = Uri.withAppendedPath(Email.CONTENT_LOOKUP_URI, Uri.encode("bob"));
5997             * Cursor c = getContentResolver().query(uri,
5998             *          new String[]{Email.DISPLAY_NAME, Email.DATA},
5999             *          null, null, null);
6000             * </pre>
6001             * </p>
6002             */
6003            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
6004                    "filter");
6005
6006            /**
6007             * The email address.
6008             * <P>Type: TEXT</P>
6009             */
6010            public static final String ADDRESS = DATA1;
6011
6012            public static final int TYPE_HOME = 1;
6013            public static final int TYPE_WORK = 2;
6014            public static final int TYPE_OTHER = 3;
6015            public static final int TYPE_MOBILE = 4;
6016
6017            /**
6018             * The display name for the email address
6019             * <P>Type: TEXT</P>
6020             */
6021            public static final String DISPLAY_NAME = DATA4;
6022
6023            /**
6024             * Return the string resource that best describes the given
6025             * {@link #TYPE}. Will always return a valid resource.
6026             */
6027            public static final int getTypeLabelResource(int type) {
6028                switch (type) {
6029                    case TYPE_HOME: return com.android.internal.R.string.emailTypeHome;
6030                    case TYPE_WORK: return com.android.internal.R.string.emailTypeWork;
6031                    case TYPE_OTHER: return com.android.internal.R.string.emailTypeOther;
6032                    case TYPE_MOBILE: return com.android.internal.R.string.emailTypeMobile;
6033                    default: return com.android.internal.R.string.emailTypeCustom;
6034                }
6035            }
6036
6037            /**
6038             * Return a {@link CharSequence} that best describes the given type,
6039             * possibly substituting the given {@link #LABEL} value
6040             * for {@link #TYPE_CUSTOM}.
6041             */
6042            public static final CharSequence getTypeLabel(Resources res, int type,
6043                    CharSequence label) {
6044                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6045                    return label;
6046                } else {
6047                    final int labelRes = getTypeLabelResource(type);
6048                    return res.getText(labelRes);
6049                }
6050            }
6051        }
6052
6053        /**
6054         * <p>
6055         * A data kind representing a postal addresses.
6056         * </p>
6057         * <p>
6058         * You can use all columns defined for {@link ContactsContract.Data} as
6059         * well as the following aliases.
6060         * </p>
6061         * <h2>Column aliases</h2>
6062         * <table class="jd-sumtable">
6063         * <tr>
6064         * <th>Type</th>
6065         * <th>Alias</th><th colspan='2'>Data column</th>
6066         * </tr>
6067         * <tr>
6068         * <td>String</td>
6069         * <td>{@link #FORMATTED_ADDRESS}</td>
6070         * <td>{@link #DATA1}</td>
6071         * <td></td>
6072         * </tr>
6073         * <tr>
6074         * <td>int</td>
6075         * <td>{@link #TYPE}</td>
6076         * <td>{@link #DATA2}</td>
6077         * <td>Allowed values are:
6078         * <p>
6079         * <ul>
6080         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6081         * <li>{@link #TYPE_HOME}</li>
6082         * <li>{@link #TYPE_WORK}</li>
6083         * <li>{@link #TYPE_OTHER}</li>
6084         * </ul>
6085         * </p>
6086         * </td>
6087         * </tr>
6088         * <tr>
6089         * <td>String</td>
6090         * <td>{@link #LABEL}</td>
6091         * <td>{@link #DATA3}</td>
6092         * <td></td>
6093         * </tr>
6094         * <tr>
6095         * <td>String</td>
6096         * <td>{@link #STREET}</td>
6097         * <td>{@link #DATA4}</td>
6098         * <td></td>
6099         * </tr>
6100         * <tr>
6101         * <td>String</td>
6102         * <td>{@link #POBOX}</td>
6103         * <td>{@link #DATA5}</td>
6104         * <td>Post Office Box number</td>
6105         * </tr>
6106         * <tr>
6107         * <td>String</td>
6108         * <td>{@link #NEIGHBORHOOD}</td>
6109         * <td>{@link #DATA6}</td>
6110         * <td></td>
6111         * </tr>
6112         * <tr>
6113         * <td>String</td>
6114         * <td>{@link #CITY}</td>
6115         * <td>{@link #DATA7}</td>
6116         * <td></td>
6117         * </tr>
6118         * <tr>
6119         * <td>String</td>
6120         * <td>{@link #REGION}</td>
6121         * <td>{@link #DATA8}</td>
6122         * <td></td>
6123         * </tr>
6124         * <tr>
6125         * <td>String</td>
6126         * <td>{@link #POSTCODE}</td>
6127         * <td>{@link #DATA9}</td>
6128         * <td></td>
6129         * </tr>
6130         * <tr>
6131         * <td>String</td>
6132         * <td>{@link #COUNTRY}</td>
6133         * <td>{@link #DATA10}</td>
6134         * <td></td>
6135         * </tr>
6136         * </table>
6137         */
6138        public static final class StructuredPostal implements DataColumnsWithJoins, CommonColumns,
6139                ContactCounts {
6140            /**
6141             * This utility class cannot be instantiated
6142             */
6143            private StructuredPostal() {
6144            }
6145
6146            /** MIME type used when storing this in data table. */
6147            public static final String CONTENT_ITEM_TYPE =
6148                    "vnd.android.cursor.item/postal-address_v2";
6149
6150            /**
6151             * The MIME type of {@link #CONTENT_URI} providing a directory of
6152             * postal addresses.
6153             */
6154            public static final String CONTENT_TYPE = "vnd.android.cursor.dir/postal-address_v2";
6155
6156            /**
6157             * The content:// style URI for all data records of the
6158             * {@link StructuredPostal#CONTENT_ITEM_TYPE} MIME type.
6159             */
6160            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
6161                    "postals");
6162
6163            public static final int TYPE_HOME = 1;
6164            public static final int TYPE_WORK = 2;
6165            public static final int TYPE_OTHER = 3;
6166
6167            /**
6168             * The full, unstructured postal address. <i>This field must be
6169             * consistent with any structured data.</i>
6170             * <p>
6171             * Type: TEXT
6172             */
6173            public static final String FORMATTED_ADDRESS = DATA;
6174
6175            /**
6176             * Can be street, avenue, road, etc. This element also includes the
6177             * house number and room/apartment/flat/floor number.
6178             * <p>
6179             * Type: TEXT
6180             */
6181            public static final String STREET = DATA4;
6182
6183            /**
6184             * Covers actual P.O. boxes, drawers, locked bags, etc. This is
6185             * usually but not always mutually exclusive with street.
6186             * <p>
6187             * Type: TEXT
6188             */
6189            public static final String POBOX = DATA5;
6190
6191            /**
6192             * This is used to disambiguate a street address when a city
6193             * contains more than one street with the same name, or to specify a
6194             * small place whose mail is routed through a larger postal town. In
6195             * China it could be a county or a minor city.
6196             * <p>
6197             * Type: TEXT
6198             */
6199            public static final String NEIGHBORHOOD = DATA6;
6200
6201            /**
6202             * Can be city, village, town, borough, etc. This is the postal town
6203             * and not necessarily the place of residence or place of business.
6204             * <p>
6205             * Type: TEXT
6206             */
6207            public static final String CITY = DATA7;
6208
6209            /**
6210             * A state, province, county (in Ireland), Land (in Germany),
6211             * departement (in France), etc.
6212             * <p>
6213             * Type: TEXT
6214             */
6215            public static final String REGION = DATA8;
6216
6217            /**
6218             * Postal code. Usually country-wide, but sometimes specific to the
6219             * city (e.g. "2" in "Dublin 2, Ireland" addresses).
6220             * <p>
6221             * Type: TEXT
6222             */
6223            public static final String POSTCODE = DATA9;
6224
6225            /**
6226             * The name or code of the country.
6227             * <p>
6228             * Type: TEXT
6229             */
6230            public static final String COUNTRY = DATA10;
6231
6232            /**
6233             * Return the string resource that best describes the given
6234             * {@link #TYPE}. Will always return a valid resource.
6235             */
6236            public static final int getTypeLabelResource(int type) {
6237                switch (type) {
6238                    case TYPE_HOME: return com.android.internal.R.string.postalTypeHome;
6239                    case TYPE_WORK: return com.android.internal.R.string.postalTypeWork;
6240                    case TYPE_OTHER: return com.android.internal.R.string.postalTypeOther;
6241                    default: return com.android.internal.R.string.postalTypeCustom;
6242                }
6243            }
6244
6245            /**
6246             * Return a {@link CharSequence} that best describes the given type,
6247             * possibly substituting the given {@link #LABEL} value
6248             * for {@link #TYPE_CUSTOM}.
6249             */
6250            public static final CharSequence getTypeLabel(Resources res, int type,
6251                    CharSequence label) {
6252                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6253                    return label;
6254                } else {
6255                    final int labelRes = getTypeLabelResource(type);
6256                    return res.getText(labelRes);
6257                }
6258            }
6259        }
6260
6261        /**
6262         * <p>
6263         * A data kind representing an IM address
6264         * </p>
6265         * <p>
6266         * You can use all columns defined for {@link ContactsContract.Data} as
6267         * well as the following aliases.
6268         * </p>
6269         * <h2>Column aliases</h2>
6270         * <table class="jd-sumtable">
6271         * <tr>
6272         * <th>Type</th>
6273         * <th>Alias</th><th colspan='2'>Data column</th>
6274         * </tr>
6275         * <tr>
6276         * <td>String</td>
6277         * <td>{@link #DATA}</td>
6278         * <td>{@link #DATA1}</td>
6279         * <td></td>
6280         * </tr>
6281         * <tr>
6282         * <td>int</td>
6283         * <td>{@link #TYPE}</td>
6284         * <td>{@link #DATA2}</td>
6285         * <td>Allowed values are:
6286         * <p>
6287         * <ul>
6288         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6289         * <li>{@link #TYPE_HOME}</li>
6290         * <li>{@link #TYPE_WORK}</li>
6291         * <li>{@link #TYPE_OTHER}</li>
6292         * </ul>
6293         * </p>
6294         * </td>
6295         * </tr>
6296         * <tr>
6297         * <td>String</td>
6298         * <td>{@link #LABEL}</td>
6299         * <td>{@link #DATA3}</td>
6300         * <td></td>
6301         * </tr>
6302         * <tr>
6303         * <td>String</td>
6304         * <td>{@link #PROTOCOL}</td>
6305         * <td>{@link #DATA5}</td>
6306         * <td>
6307         * <p>
6308         * Allowed values:
6309         * <ul>
6310         * <li>{@link #PROTOCOL_CUSTOM}. Also provide the actual protocol name
6311         * as {@link #CUSTOM_PROTOCOL}.</li>
6312         * <li>{@link #PROTOCOL_AIM}</li>
6313         * <li>{@link #PROTOCOL_MSN}</li>
6314         * <li>{@link #PROTOCOL_YAHOO}</li>
6315         * <li>{@link #PROTOCOL_SKYPE}</li>
6316         * <li>{@link #PROTOCOL_QQ}</li>
6317         * <li>{@link #PROTOCOL_GOOGLE_TALK}</li>
6318         * <li>{@link #PROTOCOL_ICQ}</li>
6319         * <li>{@link #PROTOCOL_JABBER}</li>
6320         * <li>{@link #PROTOCOL_NETMEETING}</li>
6321         * </ul>
6322         * </p>
6323         * </td>
6324         * </tr>
6325         * <tr>
6326         * <td>String</td>
6327         * <td>{@link #CUSTOM_PROTOCOL}</td>
6328         * <td>{@link #DATA6}</td>
6329         * <td></td>
6330         * </tr>
6331         * </table>
6332         */
6333        public static final class Im implements DataColumnsWithJoins, CommonColumns, ContactCounts {
6334            /**
6335             * This utility class cannot be instantiated
6336             */
6337            private Im() {}
6338
6339            /** MIME type used when storing this in data table. */
6340            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/im";
6341
6342            public static final int TYPE_HOME = 1;
6343            public static final int TYPE_WORK = 2;
6344            public static final int TYPE_OTHER = 3;
6345
6346            /**
6347             * This column should be populated with one of the defined
6348             * constants, e.g. {@link #PROTOCOL_YAHOO}. If the value of this
6349             * column is {@link #PROTOCOL_CUSTOM}, the {@link #CUSTOM_PROTOCOL}
6350             * should contain the name of the custom protocol.
6351             */
6352            public static final String PROTOCOL = DATA5;
6353
6354            public static final String CUSTOM_PROTOCOL = DATA6;
6355
6356            /*
6357             * The predefined IM protocol types.
6358             */
6359            public static final int PROTOCOL_CUSTOM = -1;
6360            public static final int PROTOCOL_AIM = 0;
6361            public static final int PROTOCOL_MSN = 1;
6362            public static final int PROTOCOL_YAHOO = 2;
6363            public static final int PROTOCOL_SKYPE = 3;
6364            public static final int PROTOCOL_QQ = 4;
6365            public static final int PROTOCOL_GOOGLE_TALK = 5;
6366            public static final int PROTOCOL_ICQ = 6;
6367            public static final int PROTOCOL_JABBER = 7;
6368            public static final int PROTOCOL_NETMEETING = 8;
6369
6370            /**
6371             * Return the string resource that best describes the given
6372             * {@link #TYPE}. Will always return a valid resource.
6373             */
6374            public static final int getTypeLabelResource(int type) {
6375                switch (type) {
6376                    case TYPE_HOME: return com.android.internal.R.string.imTypeHome;
6377                    case TYPE_WORK: return com.android.internal.R.string.imTypeWork;
6378                    case TYPE_OTHER: return com.android.internal.R.string.imTypeOther;
6379                    default: return com.android.internal.R.string.imTypeCustom;
6380                }
6381            }
6382
6383            /**
6384             * Return a {@link CharSequence} that best describes the given type,
6385             * possibly substituting the given {@link #LABEL} value
6386             * for {@link #TYPE_CUSTOM}.
6387             */
6388            public static final CharSequence getTypeLabel(Resources res, int type,
6389                    CharSequence label) {
6390                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6391                    return label;
6392                } else {
6393                    final int labelRes = getTypeLabelResource(type);
6394                    return res.getText(labelRes);
6395                }
6396            }
6397
6398            /**
6399             * Return the string resource that best describes the given
6400             * {@link #PROTOCOL}. Will always return a valid resource.
6401             */
6402            public static final int getProtocolLabelResource(int type) {
6403                switch (type) {
6404                    case PROTOCOL_AIM: return com.android.internal.R.string.imProtocolAim;
6405                    case PROTOCOL_MSN: return com.android.internal.R.string.imProtocolMsn;
6406                    case PROTOCOL_YAHOO: return com.android.internal.R.string.imProtocolYahoo;
6407                    case PROTOCOL_SKYPE: return com.android.internal.R.string.imProtocolSkype;
6408                    case PROTOCOL_QQ: return com.android.internal.R.string.imProtocolQq;
6409                    case PROTOCOL_GOOGLE_TALK: return com.android.internal.R.string.imProtocolGoogleTalk;
6410                    case PROTOCOL_ICQ: return com.android.internal.R.string.imProtocolIcq;
6411                    case PROTOCOL_JABBER: return com.android.internal.R.string.imProtocolJabber;
6412                    case PROTOCOL_NETMEETING: return com.android.internal.R.string.imProtocolNetMeeting;
6413                    default: return com.android.internal.R.string.imProtocolCustom;
6414                }
6415            }
6416
6417            /**
6418             * Return a {@link CharSequence} that best describes the given
6419             * protocol, possibly substituting the given
6420             * {@link #CUSTOM_PROTOCOL} value for {@link #PROTOCOL_CUSTOM}.
6421             */
6422            public static final CharSequence getProtocolLabel(Resources res, int type,
6423                    CharSequence label) {
6424                if (type == PROTOCOL_CUSTOM && !TextUtils.isEmpty(label)) {
6425                    return label;
6426                } else {
6427                    final int labelRes = getProtocolLabelResource(type);
6428                    return res.getText(labelRes);
6429                }
6430            }
6431        }
6432
6433        /**
6434         * <p>
6435         * A data kind representing an organization.
6436         * </p>
6437         * <p>
6438         * You can use all columns defined for {@link ContactsContract.Data} as
6439         * well as the following aliases.
6440         * </p>
6441         * <h2>Column aliases</h2>
6442         * <table class="jd-sumtable">
6443         * <tr>
6444         * <th>Type</th>
6445         * <th>Alias</th><th colspan='2'>Data column</th>
6446         * </tr>
6447         * <tr>
6448         * <td>String</td>
6449         * <td>{@link #COMPANY}</td>
6450         * <td>{@link #DATA1}</td>
6451         * <td></td>
6452         * </tr>
6453         * <tr>
6454         * <td>int</td>
6455         * <td>{@link #TYPE}</td>
6456         * <td>{@link #DATA2}</td>
6457         * <td>Allowed values are:
6458         * <p>
6459         * <ul>
6460         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6461         * <li>{@link #TYPE_WORK}</li>
6462         * <li>{@link #TYPE_OTHER}</li>
6463         * </ul>
6464         * </p>
6465         * </td>
6466         * </tr>
6467         * <tr>
6468         * <td>String</td>
6469         * <td>{@link #LABEL}</td>
6470         * <td>{@link #DATA3}</td>
6471         * <td></td>
6472         * </tr>
6473         * <tr>
6474         * <td>String</td>
6475         * <td>{@link #TITLE}</td>
6476         * <td>{@link #DATA4}</td>
6477         * <td></td>
6478         * </tr>
6479         * <tr>
6480         * <td>String</td>
6481         * <td>{@link #DEPARTMENT}</td>
6482         * <td>{@link #DATA5}</td>
6483         * <td></td>
6484         * </tr>
6485         * <tr>
6486         * <td>String</td>
6487         * <td>{@link #JOB_DESCRIPTION}</td>
6488         * <td>{@link #DATA6}</td>
6489         * <td></td>
6490         * </tr>
6491         * <tr>
6492         * <td>String</td>
6493         * <td>{@link #SYMBOL}</td>
6494         * <td>{@link #DATA7}</td>
6495         * <td></td>
6496         * </tr>
6497         * <tr>
6498         * <td>String</td>
6499         * <td>{@link #PHONETIC_NAME}</td>
6500         * <td>{@link #DATA8}</td>
6501         * <td></td>
6502         * </tr>
6503         * <tr>
6504         * <td>String</td>
6505         * <td>{@link #OFFICE_LOCATION}</td>
6506         * <td>{@link #DATA9}</td>
6507         * <td></td>
6508         * </tr>
6509         * <tr>
6510         * <td>String</td>
6511         * <td>PHONETIC_NAME_STYLE</td>
6512         * <td>{@link #DATA10}</td>
6513         * <td></td>
6514         * </tr>
6515         * </table>
6516         */
6517        public static final class Organization implements DataColumnsWithJoins, CommonColumns,
6518                ContactCounts {
6519            /**
6520             * This utility class cannot be instantiated
6521             */
6522            private Organization() {}
6523
6524            /** MIME type used when storing this in data table. */
6525            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/organization";
6526
6527            public static final int TYPE_WORK = 1;
6528            public static final int TYPE_OTHER = 2;
6529
6530            /**
6531             * The company as the user entered it.
6532             * <P>Type: TEXT</P>
6533             */
6534            public static final String COMPANY = DATA;
6535
6536            /**
6537             * The position title at this company as the user entered it.
6538             * <P>Type: TEXT</P>
6539             */
6540            public static final String TITLE = DATA4;
6541
6542            /**
6543             * The department at this company as the user entered it.
6544             * <P>Type: TEXT</P>
6545             */
6546            public static final String DEPARTMENT = DATA5;
6547
6548            /**
6549             * The job description at this company as the user entered it.
6550             * <P>Type: TEXT</P>
6551             */
6552            public static final String JOB_DESCRIPTION = DATA6;
6553
6554            /**
6555             * The symbol of this company as the user entered it.
6556             * <P>Type: TEXT</P>
6557             */
6558            public static final String SYMBOL = DATA7;
6559
6560            /**
6561             * The phonetic name of this company as the user entered it.
6562             * <P>Type: TEXT</P>
6563             */
6564            public static final String PHONETIC_NAME = DATA8;
6565
6566            /**
6567             * The office location of this organization.
6568             * <P>Type: TEXT</P>
6569             */
6570            public static final String OFFICE_LOCATION = DATA9;
6571
6572            /**
6573             * The alphabet used for capturing the phonetic name.
6574             * See {@link ContactsContract.PhoneticNameStyle}.
6575             * @hide
6576             */
6577            public static final String PHONETIC_NAME_STYLE = DATA10;
6578
6579            /**
6580             * Return the string resource that best describes the given
6581             * {@link #TYPE}. Will always return a valid resource.
6582             */
6583            public static final int getTypeLabelResource(int type) {
6584                switch (type) {
6585                    case TYPE_WORK: return com.android.internal.R.string.orgTypeWork;
6586                    case TYPE_OTHER: return com.android.internal.R.string.orgTypeOther;
6587                    default: return com.android.internal.R.string.orgTypeCustom;
6588                }
6589            }
6590
6591            /**
6592             * Return a {@link CharSequence} that best describes the given type,
6593             * possibly substituting the given {@link #LABEL} value
6594             * for {@link #TYPE_CUSTOM}.
6595             */
6596            public static final CharSequence getTypeLabel(Resources res, int type,
6597                    CharSequence label) {
6598                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6599                    return label;
6600                } else {
6601                    final int labelRes = getTypeLabelResource(type);
6602                    return res.getText(labelRes);
6603                }
6604            }
6605        }
6606
6607        /**
6608         * <p>
6609         * A data kind representing a relation.
6610         * </p>
6611         * <p>
6612         * You can use all columns defined for {@link ContactsContract.Data} as
6613         * well as the following aliases.
6614         * </p>
6615         * <h2>Column aliases</h2>
6616         * <table class="jd-sumtable">
6617         * <tr>
6618         * <th>Type</th>
6619         * <th>Alias</th><th colspan='2'>Data column</th>
6620         * </tr>
6621         * <tr>
6622         * <td>String</td>
6623         * <td>{@link #NAME}</td>
6624         * <td>{@link #DATA1}</td>
6625         * <td></td>
6626         * </tr>
6627         * <tr>
6628         * <td>int</td>
6629         * <td>{@link #TYPE}</td>
6630         * <td>{@link #DATA2}</td>
6631         * <td>Allowed values are:
6632         * <p>
6633         * <ul>
6634         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6635         * <li>{@link #TYPE_ASSISTANT}</li>
6636         * <li>{@link #TYPE_BROTHER}</li>
6637         * <li>{@link #TYPE_CHILD}</li>
6638         * <li>{@link #TYPE_DOMESTIC_PARTNER}</li>
6639         * <li>{@link #TYPE_FATHER}</li>
6640         * <li>{@link #TYPE_FRIEND}</li>
6641         * <li>{@link #TYPE_MANAGER}</li>
6642         * <li>{@link #TYPE_MOTHER}</li>
6643         * <li>{@link #TYPE_PARENT}</li>
6644         * <li>{@link #TYPE_PARTNER}</li>
6645         * <li>{@link #TYPE_REFERRED_BY}</li>
6646         * <li>{@link #TYPE_RELATIVE}</li>
6647         * <li>{@link #TYPE_SISTER}</li>
6648         * <li>{@link #TYPE_SPOUSE}</li>
6649         * </ul>
6650         * </p>
6651         * </td>
6652         * </tr>
6653         * <tr>
6654         * <td>String</td>
6655         * <td>{@link #LABEL}</td>
6656         * <td>{@link #DATA3}</td>
6657         * <td></td>
6658         * </tr>
6659         * </table>
6660         */
6661        public static final class Relation implements DataColumnsWithJoins, CommonColumns,
6662                ContactCounts {
6663            /**
6664             * This utility class cannot be instantiated
6665             */
6666            private Relation() {}
6667
6668            /** MIME type used when storing this in data table. */
6669            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/relation";
6670
6671            public static final int TYPE_ASSISTANT = 1;
6672            public static final int TYPE_BROTHER = 2;
6673            public static final int TYPE_CHILD = 3;
6674            public static final int TYPE_DOMESTIC_PARTNER = 4;
6675            public static final int TYPE_FATHER = 5;
6676            public static final int TYPE_FRIEND = 6;
6677            public static final int TYPE_MANAGER = 7;
6678            public static final int TYPE_MOTHER = 8;
6679            public static final int TYPE_PARENT = 9;
6680            public static final int TYPE_PARTNER = 10;
6681            public static final int TYPE_REFERRED_BY = 11;
6682            public static final int TYPE_RELATIVE = 12;
6683            public static final int TYPE_SISTER = 13;
6684            public static final int TYPE_SPOUSE = 14;
6685
6686            /**
6687             * The name of the relative as the user entered it.
6688             * <P>Type: TEXT</P>
6689             */
6690            public static final String NAME = DATA;
6691
6692            /**
6693             * Return the string resource that best describes the given
6694             * {@link #TYPE}. Will always return a valid resource.
6695             */
6696            public static final int getTypeLabelResource(int type) {
6697                switch (type) {
6698                    case TYPE_ASSISTANT: return com.android.internal.R.string.relationTypeAssistant;
6699                    case TYPE_BROTHER: return com.android.internal.R.string.relationTypeBrother;
6700                    case TYPE_CHILD: return com.android.internal.R.string.relationTypeChild;
6701                    case TYPE_DOMESTIC_PARTNER:
6702                            return com.android.internal.R.string.relationTypeDomesticPartner;
6703                    case TYPE_FATHER: return com.android.internal.R.string.relationTypeFather;
6704                    case TYPE_FRIEND: return com.android.internal.R.string.relationTypeFriend;
6705                    case TYPE_MANAGER: return com.android.internal.R.string.relationTypeManager;
6706                    case TYPE_MOTHER: return com.android.internal.R.string.relationTypeMother;
6707                    case TYPE_PARENT: return com.android.internal.R.string.relationTypeParent;
6708                    case TYPE_PARTNER: return com.android.internal.R.string.relationTypePartner;
6709                    case TYPE_REFERRED_BY:
6710                            return com.android.internal.R.string.relationTypeReferredBy;
6711                    case TYPE_RELATIVE: return com.android.internal.R.string.relationTypeRelative;
6712                    case TYPE_SISTER: return com.android.internal.R.string.relationTypeSister;
6713                    case TYPE_SPOUSE: return com.android.internal.R.string.relationTypeSpouse;
6714                    default: return com.android.internal.R.string.orgTypeCustom;
6715                }
6716            }
6717
6718            /**
6719             * Return a {@link CharSequence} that best describes the given type,
6720             * possibly substituting the given {@link #LABEL} value
6721             * for {@link #TYPE_CUSTOM}.
6722             */
6723            public static final CharSequence getTypeLabel(Resources res, int type,
6724                    CharSequence label) {
6725                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6726                    return label;
6727                } else {
6728                    final int labelRes = getTypeLabelResource(type);
6729                    return res.getText(labelRes);
6730                }
6731            }
6732        }
6733
6734        /**
6735         * <p>
6736         * A data kind representing an event.
6737         * </p>
6738         * <p>
6739         * You can use all columns defined for {@link ContactsContract.Data} as
6740         * well as the following aliases.
6741         * </p>
6742         * <h2>Column aliases</h2>
6743         * <table class="jd-sumtable">
6744         * <tr>
6745         * <th>Type</th>
6746         * <th>Alias</th><th colspan='2'>Data column</th>
6747         * </tr>
6748         * <tr>
6749         * <td>String</td>
6750         * <td>{@link #START_DATE}</td>
6751         * <td>{@link #DATA1}</td>
6752         * <td></td>
6753         * </tr>
6754         * <tr>
6755         * <td>int</td>
6756         * <td>{@link #TYPE}</td>
6757         * <td>{@link #DATA2}</td>
6758         * <td>Allowed values are:
6759         * <p>
6760         * <ul>
6761         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
6762         * <li>{@link #TYPE_ANNIVERSARY}</li>
6763         * <li>{@link #TYPE_OTHER}</li>
6764         * <li>{@link #TYPE_BIRTHDAY}</li>
6765         * </ul>
6766         * </p>
6767         * </td>
6768         * </tr>
6769         * <tr>
6770         * <td>String</td>
6771         * <td>{@link #LABEL}</td>
6772         * <td>{@link #DATA3}</td>
6773         * <td></td>
6774         * </tr>
6775         * </table>
6776         */
6777        public static final class Event implements DataColumnsWithJoins, CommonColumns,
6778                ContactCounts {
6779            /**
6780             * This utility class cannot be instantiated
6781             */
6782            private Event() {}
6783
6784            /** MIME type used when storing this in data table. */
6785            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_event";
6786
6787            public static final int TYPE_ANNIVERSARY = 1;
6788            public static final int TYPE_OTHER = 2;
6789            public static final int TYPE_BIRTHDAY = 3;
6790
6791            /**
6792             * The event start date as the user entered it.
6793             * <P>Type: TEXT</P>
6794             */
6795            public static final String START_DATE = DATA;
6796
6797            /**
6798             * Return the string resource that best describes the given
6799             * {@link #TYPE}. Will always return a valid resource.
6800             */
6801            public static int getTypeResource(Integer type) {
6802                if (type == null) {
6803                    return com.android.internal.R.string.eventTypeOther;
6804                }
6805                switch (type) {
6806                    case TYPE_ANNIVERSARY:
6807                        return com.android.internal.R.string.eventTypeAnniversary;
6808                    case TYPE_BIRTHDAY: return com.android.internal.R.string.eventTypeBirthday;
6809                    case TYPE_OTHER: return com.android.internal.R.string.eventTypeOther;
6810                    default: return com.android.internal.R.string.eventTypeCustom;
6811                }
6812            }
6813
6814            /**
6815             * Return a {@link CharSequence} that best describes the given type,
6816             * possibly substituting the given {@link #LABEL} value
6817             * for {@link #TYPE_CUSTOM}.
6818             */
6819            public static final CharSequence getTypeLabel(Resources res, int type,
6820                    CharSequence label) {
6821                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
6822                    return label;
6823                } else {
6824                    final int labelRes = getTypeResource(type);
6825                    return res.getText(labelRes);
6826                }
6827            }
6828        }
6829
6830        /**
6831         * <p>
6832         * A data kind representing a photo for the contact.
6833         * </p>
6834         * <p>
6835         * Some sync adapters will choose to download photos in a separate
6836         * pass. A common pattern is to use columns {@link ContactsContract.Data#SYNC1}
6837         * through {@link ContactsContract.Data#SYNC4} to store temporary
6838         * data, e.g. the image URL or ID, state of download, server-side version
6839         * of the image.  It is allowed for the {@link #PHOTO} to be null.
6840         * </p>
6841         * <p>
6842         * You can use all columns defined for {@link ContactsContract.Data} as
6843         * well as the following aliases.
6844         * </p>
6845         * <h2>Column aliases</h2>
6846         * <table class="jd-sumtable">
6847         * <tr>
6848         * <th>Type</th>
6849         * <th>Alias</th><th colspan='2'>Data column</th>
6850         * </tr>
6851         * <tr>
6852         * <td>NUMBER</td>
6853         * <td>{@link #PHOTO_FILE_ID}</td>
6854         * <td>{@link #DATA14}</td>
6855         * <td>ID of the hi-res photo file.</td>
6856         * </tr>
6857         * <tr>
6858         * <td>BLOB</td>
6859         * <td>{@link #PHOTO}</td>
6860         * <td>{@link #DATA15}</td>
6861         * <td>By convention, binary data is stored in DATA15.  The thumbnail of the
6862         * photo is stored in this column.</td>
6863         * </tr>
6864         * </table>
6865         */
6866        public static final class Photo implements DataColumnsWithJoins, ContactCounts {
6867            /**
6868             * This utility class cannot be instantiated
6869             */
6870            private Photo() {}
6871
6872            /** MIME type used when storing this in data table. */
6873            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/photo";
6874
6875            /**
6876             * Photo file ID for the display photo of the raw contact.
6877             * See {@link ContactsContract.DisplayPhoto}.
6878             * <p>
6879             * Type: NUMBER
6880             */
6881            public static final String PHOTO_FILE_ID = DATA14;
6882
6883            /**
6884             * Thumbnail photo of the raw contact. This is the raw bytes of an image
6885             * that could be inflated using {@link android.graphics.BitmapFactory}.
6886             * <p>
6887             * Type: BLOB
6888             */
6889            public static final String PHOTO = DATA15;
6890        }
6891
6892        /**
6893         * <p>
6894         * Notes about the contact.
6895         * </p>
6896         * <p>
6897         * You can use all columns defined for {@link ContactsContract.Data} as
6898         * well as the following aliases.
6899         * </p>
6900         * <h2>Column aliases</h2>
6901         * <table class="jd-sumtable">
6902         * <tr>
6903         * <th>Type</th>
6904         * <th>Alias</th><th colspan='2'>Data column</th>
6905         * </tr>
6906         * <tr>
6907         * <td>String</td>
6908         * <td>{@link #NOTE}</td>
6909         * <td>{@link #DATA1}</td>
6910         * <td></td>
6911         * </tr>
6912         * </table>
6913         */
6914        public static final class Note implements DataColumnsWithJoins, ContactCounts {
6915            /**
6916             * This utility class cannot be instantiated
6917             */
6918            private Note() {}
6919
6920            /** MIME type used when storing this in data table. */
6921            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/note";
6922
6923            /**
6924             * The note text.
6925             * <P>Type: TEXT</P>
6926             */
6927            public static final String NOTE = DATA1;
6928        }
6929
6930        /**
6931         * <p>
6932         * Group Membership.
6933         * </p>
6934         * <p>
6935         * You can use all columns defined for {@link ContactsContract.Data} as
6936         * well as the following aliases.
6937         * </p>
6938         * <h2>Column aliases</h2>
6939         * <table class="jd-sumtable">
6940         * <tr>
6941         * <th>Type</th>
6942         * <th>Alias</th><th colspan='2'>Data column</th>
6943         * </tr>
6944         * <tr>
6945         * <td>long</td>
6946         * <td>{@link #GROUP_ROW_ID}</td>
6947         * <td>{@link #DATA1}</td>
6948         * <td></td>
6949         * </tr>
6950         * <tr>
6951         * <td>String</td>
6952         * <td>{@link #GROUP_SOURCE_ID}</td>
6953         * <td>none</td>
6954         * <td>
6955         * <p>
6956         * The sourceid of the group that this group membership refers to.
6957         * Exactly one of this or {@link #GROUP_ROW_ID} must be set when
6958         * inserting a row.
6959         * </p>
6960         * <p>
6961         * If this field is specified, the provider will first try to
6962         * look up a group with this {@link Groups Groups.SOURCE_ID}.  If such a group
6963         * is found, it will use the corresponding row id.  If the group is not
6964         * found, it will create one.
6965         * </td>
6966         * </tr>
6967         * </table>
6968         */
6969        public static final class GroupMembership implements DataColumnsWithJoins, ContactCounts {
6970            /**
6971             * This utility class cannot be instantiated
6972             */
6973            private GroupMembership() {}
6974
6975            /** MIME type used when storing this in data table. */
6976            public static final String CONTENT_ITEM_TYPE =
6977                    "vnd.android.cursor.item/group_membership";
6978
6979            /**
6980             * The row id of the group that this group membership refers to. Exactly one of
6981             * this or {@link #GROUP_SOURCE_ID} must be set when inserting a row.
6982             * <P>Type: INTEGER</P>
6983             */
6984            public static final String GROUP_ROW_ID = DATA1;
6985
6986            /**
6987             * The sourceid of the group that this group membership refers to.  Exactly one of
6988             * this or {@link #GROUP_ROW_ID} must be set when inserting a row.
6989             * <P>Type: TEXT</P>
6990             */
6991            public static final String GROUP_SOURCE_ID = "group_sourceid";
6992        }
6993
6994        /**
6995         * <p>
6996         * A data kind representing a website related to the contact.
6997         * </p>
6998         * <p>
6999         * You can use all columns defined for {@link ContactsContract.Data} as
7000         * well as the following aliases.
7001         * </p>
7002         * <h2>Column aliases</h2>
7003         * <table class="jd-sumtable">
7004         * <tr>
7005         * <th>Type</th>
7006         * <th>Alias</th><th colspan='2'>Data column</th>
7007         * </tr>
7008         * <tr>
7009         * <td>String</td>
7010         * <td>{@link #URL}</td>
7011         * <td>{@link #DATA1}</td>
7012         * <td></td>
7013         * </tr>
7014         * <tr>
7015         * <td>int</td>
7016         * <td>{@link #TYPE}</td>
7017         * <td>{@link #DATA2}</td>
7018         * <td>Allowed values are:
7019         * <p>
7020         * <ul>
7021         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
7022         * <li>{@link #TYPE_HOMEPAGE}</li>
7023         * <li>{@link #TYPE_BLOG}</li>
7024         * <li>{@link #TYPE_PROFILE}</li>
7025         * <li>{@link #TYPE_HOME}</li>
7026         * <li>{@link #TYPE_WORK}</li>
7027         * <li>{@link #TYPE_FTP}</li>
7028         * <li>{@link #TYPE_OTHER}</li>
7029         * </ul>
7030         * </p>
7031         * </td>
7032         * </tr>
7033         * <tr>
7034         * <td>String</td>
7035         * <td>{@link #LABEL}</td>
7036         * <td>{@link #DATA3}</td>
7037         * <td></td>
7038         * </tr>
7039         * </table>
7040         */
7041        public static final class Website implements DataColumnsWithJoins, CommonColumns,
7042                ContactCounts {
7043            /**
7044             * This utility class cannot be instantiated
7045             */
7046            private Website() {}
7047
7048            /** MIME type used when storing this in data table. */
7049            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/website";
7050
7051            public static final int TYPE_HOMEPAGE = 1;
7052            public static final int TYPE_BLOG = 2;
7053            public static final int TYPE_PROFILE = 3;
7054            public static final int TYPE_HOME = 4;
7055            public static final int TYPE_WORK = 5;
7056            public static final int TYPE_FTP = 6;
7057            public static final int TYPE_OTHER = 7;
7058
7059            /**
7060             * The website URL string.
7061             * <P>Type: TEXT</P>
7062             */
7063            public static final String URL = DATA;
7064        }
7065
7066        /**
7067         * <p>
7068         * A data kind representing a SIP address for the contact.
7069         * </p>
7070         * <p>
7071         * You can use all columns defined for {@link ContactsContract.Data} as
7072         * well as the following aliases.
7073         * </p>
7074         * <h2>Column aliases</h2>
7075         * <table class="jd-sumtable">
7076         * <tr>
7077         * <th>Type</th>
7078         * <th>Alias</th><th colspan='2'>Data column</th>
7079         * </tr>
7080         * <tr>
7081         * <td>String</td>
7082         * <td>{@link #SIP_ADDRESS}</td>
7083         * <td>{@link #DATA1}</td>
7084         * <td></td>
7085         * </tr>
7086         * <tr>
7087         * <td>int</td>
7088         * <td>{@link #TYPE}</td>
7089         * <td>{@link #DATA2}</td>
7090         * <td>Allowed values are:
7091         * <p>
7092         * <ul>
7093         * <li>{@link #TYPE_CUSTOM}. Put the actual type in {@link #LABEL}.</li>
7094         * <li>{@link #TYPE_HOME}</li>
7095         * <li>{@link #TYPE_WORK}</li>
7096         * <li>{@link #TYPE_OTHER}</li>
7097         * </ul>
7098         * </p>
7099         * </td>
7100         * </tr>
7101         * <tr>
7102         * <td>String</td>
7103         * <td>{@link #LABEL}</td>
7104         * <td>{@link #DATA3}</td>
7105         * <td></td>
7106         * </tr>
7107         * </table>
7108         */
7109        public static final class SipAddress implements DataColumnsWithJoins, CommonColumns,
7110                ContactCounts {
7111            /**
7112             * This utility class cannot be instantiated
7113             */
7114            private SipAddress() {}
7115
7116            /** MIME type used when storing this in data table. */
7117            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/sip_address";
7118
7119            public static final int TYPE_HOME = 1;
7120            public static final int TYPE_WORK = 2;
7121            public static final int TYPE_OTHER = 3;
7122
7123            /**
7124             * The SIP address.
7125             * <P>Type: TEXT</P>
7126             */
7127            public static final String SIP_ADDRESS = DATA1;
7128            // ...and TYPE and LABEL come from the CommonColumns interface.
7129
7130            /**
7131             * Return the string resource that best describes the given
7132             * {@link #TYPE}. Will always return a valid resource.
7133             */
7134            public static final int getTypeLabelResource(int type) {
7135                switch (type) {
7136                    case TYPE_HOME: return com.android.internal.R.string.sipAddressTypeHome;
7137                    case TYPE_WORK: return com.android.internal.R.string.sipAddressTypeWork;
7138                    case TYPE_OTHER: return com.android.internal.R.string.sipAddressTypeOther;
7139                    default: return com.android.internal.R.string.sipAddressTypeCustom;
7140                }
7141            }
7142
7143            /**
7144             * Return a {@link CharSequence} that best describes the given type,
7145             * possibly substituting the given {@link #LABEL} value
7146             * for {@link #TYPE_CUSTOM}.
7147             */
7148            public static final CharSequence getTypeLabel(Resources res, int type,
7149                    CharSequence label) {
7150                if (type == TYPE_CUSTOM && !TextUtils.isEmpty(label)) {
7151                    return label;
7152                } else {
7153                    final int labelRes = getTypeLabelResource(type);
7154                    return res.getText(labelRes);
7155                }
7156            }
7157        }
7158
7159        /**
7160         * A data kind representing an Identity related to the contact.
7161         * <p>
7162         * This can be used as a signal by the aggregator to combine raw contacts into
7163         * contacts, e.g. if two contacts have Identity rows with
7164         * the same NAMESPACE and IDENTITY values the aggregator can know that they refer
7165         * to the same person.
7166         * </p>
7167         */
7168        public static final class Identity implements DataColumnsWithJoins, ContactCounts {
7169            /**
7170             * This utility class cannot be instantiated
7171             */
7172            private Identity() {}
7173
7174            /** MIME type used when storing this in data table. */
7175            public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/identity";
7176
7177            /**
7178             * The identity string.
7179             * <P>Type: TEXT</P>
7180             */
7181            public static final String IDENTITY = DataColumns.DATA1;
7182
7183            /**
7184             * The namespace of the identity string, e.g. "com.google"
7185             * <P>Type: TEXT</P>
7186             */
7187            public static final String NAMESPACE = DataColumns.DATA2;
7188        }
7189
7190        /**
7191         * <p>
7192         * Convenient functionalities for "callable" data. Note that, this is NOT a separate data
7193         * kind.
7194         * </p>
7195         * <p>
7196         * This URI allows the ContactsProvider to return a unified result for "callable" data
7197         * that users can use for calling purposes. {@link Phone} and {@link SipAddress} are the
7198         * current examples for "callable", but may be expanded to the other types.
7199         * </p>
7200         * <p>
7201         * Each returned row may have a different MIMETYPE and thus different interpretation for
7202         * each column. For example the meaning for {@link Phone}'s type is different than
7203         * {@link SipAddress}'s.
7204         * </p>
7205         */
7206        public static final class Callable implements DataColumnsWithJoins, CommonColumns,
7207                ContactCounts {
7208            /**
7209             * Similar to {@link Phone#CONTENT_URI}, but returns callable data instead of only
7210             * phone numbers.
7211             */
7212            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
7213                    "callables");
7214            /**
7215             * Similar to {@link Phone#CONTENT_FILTER_URI}, but allows users to filter callable
7216             * data.
7217             */
7218            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(CONTENT_URI,
7219                    "filter");
7220        }
7221
7222        /**
7223         * A special class of data items, used to refer to types of data that can be used to attempt
7224         * to start communicating with a person ({@link Phone} and {@link Email}). Note that this
7225         * is NOT a separate data kind.
7226         *
7227         * This URI allows the ContactsProvider to return a unified result for data items that users
7228         * can use to initiate communications with another contact. {@link Phone} and {@link Email}
7229         * are the current data types in this category.
7230         */
7231        public static final class Contactables implements DataColumnsWithJoins, CommonColumns,
7232                ContactCounts {
7233            /**
7234             * The content:// style URI for these data items, which requests a directory of data
7235             * rows matching the selection criteria.
7236             */
7237            public static final Uri CONTENT_URI = Uri.withAppendedPath(Data.CONTENT_URI,
7238                    "contactables");
7239
7240            /**
7241             * The content:// style URI for these data items, which allows for a query parameter to
7242             * be appended onto the end to filter for data items matching the query.
7243             */
7244            public static final Uri CONTENT_FILTER_URI = Uri.withAppendedPath(
7245                    Contactables.CONTENT_URI, "filter");
7246
7247            /**
7248             * A boolean parameter for {@link Data#CONTENT_URI}.
7249             * This specifies whether or not the returned data items should be filtered to show
7250             * data items belonging to visible contacts only.
7251             */
7252            public static final String VISIBLE_CONTACTS_ONLY = "visible_contacts_only";
7253        }
7254    }
7255
7256    /**
7257     * @see Groups
7258     */
7259    protected interface GroupsColumns {
7260        /**
7261         * The data set within the account that this group belongs to.  This allows
7262         * multiple sync adapters for the same account type to distinguish between
7263         * each others' group data.
7264         *
7265         * This is empty by default, and is completely optional.  It only needs to
7266         * be populated if multiple sync adapters are entering distinct group data
7267         * for the same account type and account name.
7268         * <P>Type: TEXT</P>
7269         */
7270        public static final String DATA_SET = "data_set";
7271
7272        /**
7273         * A concatenation of the account type and data set (delimited by a forward
7274         * slash) - if the data set is empty, this will be the same as the account
7275         * type.  For applications that need to be aware of the data set, this can
7276         * be used instead of account type to distinguish sets of data.  This is
7277         * never intended to be used for specifying accounts.
7278         * @hide
7279         */
7280        public static final String ACCOUNT_TYPE_AND_DATA_SET = "account_type_and_data_set";
7281
7282        /**
7283         * The display title of this group.
7284         * <p>
7285         * Type: TEXT
7286         */
7287        public static final String TITLE = "title";
7288
7289        /**
7290         * The package name to use when creating {@link Resources} objects for
7291         * this group. This value is only designed for use when building user
7292         * interfaces, and should not be used to infer the owner.
7293         */
7294        public static final String RES_PACKAGE = "res_package";
7295
7296        /**
7297         * The display title of this group to load as a resource from
7298         * {@link #RES_PACKAGE}, which may be localized.
7299         * <P>Type: TEXT</P>
7300         */
7301        public static final String TITLE_RES = "title_res";
7302
7303        /**
7304         * Notes about the group.
7305         * <p>
7306         * Type: TEXT
7307         */
7308        public static final String NOTES = "notes";
7309
7310        /**
7311         * The ID of this group if it is a System Group, i.e. a group that has a special meaning
7312         * to the sync adapter, null otherwise.
7313         * <P>Type: TEXT</P>
7314         */
7315        public static final String SYSTEM_ID = "system_id";
7316
7317        /**
7318         * The total number of {@link Contacts} that have
7319         * {@link CommonDataKinds.GroupMembership} in this group. Read-only value that is only
7320         * present when querying {@link Groups#CONTENT_SUMMARY_URI}.
7321         * <p>
7322         * Type: INTEGER
7323         */
7324        public static final String SUMMARY_COUNT = "summ_count";
7325
7326        /**
7327         * A boolean query parameter that can be used with {@link Groups#CONTENT_SUMMARY_URI}.
7328         * It will additionally return {@link #SUMMARY_GROUP_COUNT_PER_ACCOUNT}.
7329         *
7330         * @hide
7331         */
7332        public static final String PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT =
7333                "return_group_count_per_account";
7334
7335        /**
7336         * The total number of groups of the account that a group belongs to.
7337         * This column is available only when the parameter
7338         * {@link #PARAM_RETURN_GROUP_COUNT_PER_ACCOUNT} is specified in
7339         * {@link Groups#CONTENT_SUMMARY_URI}.
7340         *
7341         * For example, when the account "A" has two groups "group1" and "group2", and the account
7342         * "B" has a group "group3", the rows for "group1" and "group2" return "2" and the row for
7343         * "group3" returns "1" for this column.
7344         *
7345         * Note: This counts only non-favorites, non-auto-add, and not deleted groups.
7346         *
7347         * Type: INTEGER
7348         * @hide
7349         */
7350        public static final String SUMMARY_GROUP_COUNT_PER_ACCOUNT = "group_count_per_account";
7351
7352        /**
7353         * The total number of {@link Contacts} that have both
7354         * {@link CommonDataKinds.GroupMembership} in this group, and also have phone numbers.
7355         * Read-only value that is only present when querying
7356         * {@link Groups#CONTENT_SUMMARY_URI}.
7357         * <p>
7358         * Type: INTEGER
7359         */
7360        public static final String SUMMARY_WITH_PHONES = "summ_phones";
7361
7362        /**
7363         * Flag indicating if the contacts belonging to this group should be
7364         * visible in any user interface.
7365         * <p>
7366         * Type: INTEGER (boolean)
7367         */
7368        public static final String GROUP_VISIBLE = "group_visible";
7369
7370        /**
7371         * The "deleted" flag: "0" by default, "1" if the row has been marked
7372         * for deletion. When {@link android.content.ContentResolver#delete} is
7373         * called on a group, it is marked for deletion. The sync adaptor
7374         * deletes the group on the server and then calls ContactResolver.delete
7375         * once more, this time setting the the
7376         * {@link ContactsContract#CALLER_IS_SYNCADAPTER} query parameter to
7377         * finalize the data removal.
7378         * <P>Type: INTEGER</P>
7379         */
7380        public static final String DELETED = "deleted";
7381
7382        /**
7383         * Whether this group should be synced if the SYNC_EVERYTHING settings
7384         * is false for this group's account.
7385         * <p>
7386         * Type: INTEGER (boolean)
7387         */
7388        public static final String SHOULD_SYNC = "should_sync";
7389
7390        /**
7391         * Any newly created contacts will automatically be added to groups that have this
7392         * flag set to true.
7393         * <p>
7394         * Type: INTEGER (boolean)
7395         */
7396        public static final String AUTO_ADD = "auto_add";
7397
7398        /**
7399         * When a contacts is marked as a favorites it will be automatically added
7400         * to the groups that have this flag set, and when it is removed from favorites
7401         * it will be removed from these groups.
7402         * <p>
7403         * Type: INTEGER (boolean)
7404         */
7405        public static final String FAVORITES = "favorites";
7406
7407        /**
7408         * The "read-only" flag: "0" by default, "1" if the row cannot be modified or
7409         * deleted except by a sync adapter.  See {@link ContactsContract#CALLER_IS_SYNCADAPTER}.
7410         * <P>Type: INTEGER</P>
7411         */
7412        public static final String GROUP_IS_READ_ONLY = "group_is_read_only";
7413    }
7414
7415    /**
7416     * Constants for the groups table. Only per-account groups are supported.
7417     * <h2>Columns</h2>
7418     * <table class="jd-sumtable">
7419     * <tr>
7420     * <th colspan='4'>Groups</th>
7421     * </tr>
7422     * <tr>
7423     * <td>long</td>
7424     * <td>{@link #_ID}</td>
7425     * <td>read-only</td>
7426     * <td>Row ID. Sync adapter should try to preserve row IDs during updates.
7427     * In other words, it would be a really bad idea to delete and reinsert a
7428     * group. A sync adapter should always do an update instead.</td>
7429     * </tr>
7430     # <tr>
7431     * <td>String</td>
7432     * <td>{@link #DATA_SET}</td>
7433     * <td>read/write-once</td>
7434     * <td>
7435     * <p>
7436     * The data set within the account that this group belongs to.  This allows
7437     * multiple sync adapters for the same account type to distinguish between
7438     * each others' group data.  The combination of {@link #ACCOUNT_TYPE},
7439     * {@link #ACCOUNT_NAME}, and {@link #DATA_SET} identifies a set of data
7440     * that is associated with a single sync adapter.
7441     * </p>
7442     * <p>
7443     * This is empty by default, and is completely optional.  It only needs to
7444     * be populated if multiple sync adapters are entering distinct data for
7445     * the same account type and account name.
7446     * </p>
7447     * <p>
7448     * It should be set at the time the group is inserted and never changed
7449     * afterwards.
7450     * </p>
7451     * </td>
7452     * </tr>
7453     * <tr>
7454     * <td>String</td>
7455     * <td>{@link #TITLE}</td>
7456     * <td>read/write</td>
7457     * <td>The display title of this group.</td>
7458     * </tr>
7459     * <tr>
7460     * <td>String</td>
7461     * <td>{@link #NOTES}</td>
7462     * <td>read/write</td>
7463     * <td>Notes about the group.</td>
7464     * </tr>
7465     * <tr>
7466     * <td>String</td>
7467     * <td>{@link #SYSTEM_ID}</td>
7468     * <td>read/write</td>
7469     * <td>The ID of this group if it is a System Group, i.e. a group that has a
7470     * special meaning to the sync adapter, null otherwise.</td>
7471     * </tr>
7472     * <tr>
7473     * <td>int</td>
7474     * <td>{@link #SUMMARY_COUNT}</td>
7475     * <td>read-only</td>
7476     * <td>The total number of {@link Contacts} that have
7477     * {@link CommonDataKinds.GroupMembership} in this group. Read-only value
7478     * that is only present when querying {@link Groups#CONTENT_SUMMARY_URI}.</td>
7479     * </tr>
7480     * <tr>
7481     * <td>int</td>
7482     * <td>{@link #SUMMARY_WITH_PHONES}</td>
7483     * <td>read-only</td>
7484     * <td>The total number of {@link Contacts} that have both
7485     * {@link CommonDataKinds.GroupMembership} in this group, and also have
7486     * phone numbers. Read-only value that is only present when querying
7487     * {@link Groups#CONTENT_SUMMARY_URI}.</td>
7488     * </tr>
7489     * <tr>
7490     * <td>int</td>
7491     * <td>{@link #GROUP_VISIBLE}</td>
7492     * <td>read-only</td>
7493     * <td>Flag indicating if the contacts belonging to this group should be
7494     * visible in any user interface. Allowed values: 0 and 1.</td>
7495     * </tr>
7496     * <tr>
7497     * <td>int</td>
7498     * <td>{@link #DELETED}</td>
7499     * <td>read/write</td>
7500     * <td>The "deleted" flag: "0" by default, "1" if the row has been marked
7501     * for deletion. When {@link android.content.ContentResolver#delete} is
7502     * called on a group, it is marked for deletion. The sync adaptor deletes
7503     * the group on the server and then calls ContactResolver.delete once more,
7504     * this time setting the the {@link ContactsContract#CALLER_IS_SYNCADAPTER}
7505     * query parameter to finalize the data removal.</td>
7506     * </tr>
7507     * <tr>
7508     * <td>int</td>
7509     * <td>{@link #SHOULD_SYNC}</td>
7510     * <td>read/write</td>
7511     * <td>Whether this group should be synced if the SYNC_EVERYTHING settings
7512     * is false for this group's account.</td>
7513     * </tr>
7514     * </table>
7515     */
7516    public static final class Groups implements BaseColumns, GroupsColumns, SyncColumns {
7517        /**
7518         * This utility class cannot be instantiated
7519         */
7520        private Groups() {
7521        }
7522
7523        /**
7524         * The content:// style URI for this table
7525         */
7526        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "groups");
7527
7528        /**
7529         * The content:// style URI for this table joined with details data from
7530         * {@link ContactsContract.Data}.
7531         */
7532        public static final Uri CONTENT_SUMMARY_URI = Uri.withAppendedPath(AUTHORITY_URI,
7533                "groups_summary");
7534
7535        /**
7536         * The MIME type of a directory of groups.
7537         */
7538        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/group";
7539
7540        /**
7541         * The MIME type of a single group.
7542         */
7543        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/group";
7544
7545        public static EntityIterator newEntityIterator(Cursor cursor) {
7546            return new EntityIteratorImpl(cursor);
7547        }
7548
7549        private static class EntityIteratorImpl extends CursorEntityIterator {
7550            public EntityIteratorImpl(Cursor cursor) {
7551                super(cursor);
7552            }
7553
7554            @Override
7555            public Entity getEntityAndIncrementCursor(Cursor cursor) throws RemoteException {
7556                // we expect the cursor is already at the row we need to read from
7557                final ContentValues values = new ContentValues();
7558                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, _ID);
7559                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_NAME);
7560                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, ACCOUNT_TYPE);
7561                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DIRTY);
7562                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, VERSION);
7563                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SOURCE_ID);
7564                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, RES_PACKAGE);
7565                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE);
7566                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, TITLE_RES);
7567                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, GROUP_VISIBLE);
7568                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC1);
7569                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC2);
7570                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC3);
7571                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYNC4);
7572                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SYSTEM_ID);
7573                DatabaseUtils.cursorLongToContentValuesIfPresent(cursor, values, DELETED);
7574                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, NOTES);
7575                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, SHOULD_SYNC);
7576                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, FAVORITES);
7577                DatabaseUtils.cursorStringToContentValuesIfPresent(cursor, values, AUTO_ADD);
7578                cursor.moveToNext();
7579                return new Entity(values);
7580            }
7581        }
7582    }
7583
7584    /**
7585     * <p>
7586     * Constants for the contact aggregation exceptions table, which contains
7587     * aggregation rules overriding those used by automatic aggregation. This
7588     * type only supports query and update. Neither insert nor delete are
7589     * supported.
7590     * </p>
7591     * <h2>Columns</h2>
7592     * <table class="jd-sumtable">
7593     * <tr>
7594     * <th colspan='4'>AggregationExceptions</th>
7595     * </tr>
7596     * <tr>
7597     * <td>int</td>
7598     * <td>{@link #TYPE}</td>
7599     * <td>read/write</td>
7600     * <td>The type of exception: {@link #TYPE_KEEP_TOGETHER},
7601     * {@link #TYPE_KEEP_SEPARATE} or {@link #TYPE_AUTOMATIC}.</td>
7602     * </tr>
7603     * <tr>
7604     * <td>long</td>
7605     * <td>{@link #RAW_CONTACT_ID1}</td>
7606     * <td>read/write</td>
7607     * <td>A reference to the {@link RawContacts#_ID} of the raw contact that
7608     * the rule applies to.</td>
7609     * </tr>
7610     * <tr>
7611     * <td>long</td>
7612     * <td>{@link #RAW_CONTACT_ID2}</td>
7613     * <td>read/write</td>
7614     * <td>A reference to the other {@link RawContacts#_ID} of the raw contact
7615     * that the rule applies to.</td>
7616     * </tr>
7617     * </table>
7618     */
7619    public static final class AggregationExceptions implements BaseColumns {
7620        /**
7621         * This utility class cannot be instantiated
7622         */
7623        private AggregationExceptions() {}
7624
7625        /**
7626         * The content:// style URI for this table
7627         */
7628        public static final Uri CONTENT_URI =
7629                Uri.withAppendedPath(AUTHORITY_URI, "aggregation_exceptions");
7630
7631        /**
7632         * The MIME type of {@link #CONTENT_URI} providing a directory of data.
7633         */
7634        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/aggregation_exception";
7635
7636        /**
7637         * The MIME type of a {@link #CONTENT_URI} subdirectory of an aggregation exception
7638         */
7639        public static final String CONTENT_ITEM_TYPE =
7640                "vnd.android.cursor.item/aggregation_exception";
7641
7642        /**
7643         * The type of exception: {@link #TYPE_KEEP_TOGETHER}, {@link #TYPE_KEEP_SEPARATE} or
7644         * {@link #TYPE_AUTOMATIC}.
7645         *
7646         * <P>Type: INTEGER</P>
7647         */
7648        public static final String TYPE = "type";
7649
7650        /**
7651         * Allows the provider to automatically decide whether the specified raw contacts should
7652         * be included in the same aggregate contact or not.
7653         */
7654        public static final int TYPE_AUTOMATIC = 0;
7655
7656        /**
7657         * Makes sure that the specified raw contacts are included in the same
7658         * aggregate contact.
7659         */
7660        public static final int TYPE_KEEP_TOGETHER = 1;
7661
7662        /**
7663         * Makes sure that the specified raw contacts are NOT included in the same
7664         * aggregate contact.
7665         */
7666        public static final int TYPE_KEEP_SEPARATE = 2;
7667
7668        /**
7669         * A reference to the {@link RawContacts#_ID} of the raw contact that the rule applies to.
7670         */
7671        public static final String RAW_CONTACT_ID1 = "raw_contact_id1";
7672
7673        /**
7674         * A reference to the other {@link RawContacts#_ID} of the raw contact that the rule
7675         * applies to.
7676         */
7677        public static final String RAW_CONTACT_ID2 = "raw_contact_id2";
7678    }
7679
7680    /**
7681     * @see Settings
7682     */
7683    protected interface SettingsColumns {
7684        /**
7685         * The name of the account instance to which this row belongs.
7686         * <P>Type: TEXT</P>
7687         */
7688        public static final String ACCOUNT_NAME = "account_name";
7689
7690        /**
7691         * The type of account to which this row belongs, which when paired with
7692         * {@link #ACCOUNT_NAME} identifies a specific account.
7693         * <P>Type: TEXT</P>
7694         */
7695        public static final String ACCOUNT_TYPE = "account_type";
7696
7697        /**
7698         * The data set within the account that this row belongs to.  This allows
7699         * multiple sync adapters for the same account type to distinguish between
7700         * each others' data.
7701         *
7702         * This is empty by default, and is completely optional.  It only needs to
7703         * be populated if multiple sync adapters are entering distinct data for
7704         * the same account type and account name.
7705         * <P>Type: TEXT</P>
7706         */
7707        public static final String DATA_SET = "data_set";
7708
7709        /**
7710         * Depending on the mode defined by the sync-adapter, this flag controls
7711         * the top-level sync behavior for this data source.
7712         * <p>
7713         * Type: INTEGER (boolean)
7714         */
7715        public static final String SHOULD_SYNC = "should_sync";
7716
7717        /**
7718         * Flag indicating if contacts without any {@link CommonDataKinds.GroupMembership}
7719         * entries should be visible in any user interface.
7720         * <p>
7721         * Type: INTEGER (boolean)
7722         */
7723        public static final String UNGROUPED_VISIBLE = "ungrouped_visible";
7724
7725        /**
7726         * Read-only flag indicating if this {@link #SHOULD_SYNC} or any
7727         * {@link Groups#SHOULD_SYNC} under this account have been marked as
7728         * unsynced.
7729         */
7730        public static final String ANY_UNSYNCED = "any_unsynced";
7731
7732        /**
7733         * Read-only count of {@link Contacts} from a specific source that have
7734         * no {@link CommonDataKinds.GroupMembership} entries.
7735         * <p>
7736         * Type: INTEGER
7737         */
7738        public static final String UNGROUPED_COUNT = "summ_count";
7739
7740        /**
7741         * Read-only count of {@link Contacts} from a specific source that have
7742         * no {@link CommonDataKinds.GroupMembership} entries, and also have phone numbers.
7743         * <p>
7744         * Type: INTEGER
7745         */
7746        public static final String UNGROUPED_WITH_PHONES = "summ_phones";
7747    }
7748
7749    /**
7750     * <p>
7751     * Contacts-specific settings for various {@link Account}'s.
7752     * </p>
7753     * <h2>Columns</h2>
7754     * <table class="jd-sumtable">
7755     * <tr>
7756     * <th colspan='4'>Settings</th>
7757     * </tr>
7758     * <tr>
7759     * <td>String</td>
7760     * <td>{@link #ACCOUNT_NAME}</td>
7761     * <td>read/write-once</td>
7762     * <td>The name of the account instance to which this row belongs.</td>
7763     * </tr>
7764     * <tr>
7765     * <td>String</td>
7766     * <td>{@link #ACCOUNT_TYPE}</td>
7767     * <td>read/write-once</td>
7768     * <td>The type of account to which this row belongs, which when paired with
7769     * {@link #ACCOUNT_NAME} identifies a specific account.</td>
7770     * </tr>
7771     * <tr>
7772     * <td>int</td>
7773     * <td>{@link #SHOULD_SYNC}</td>
7774     * <td>read/write</td>
7775     * <td>Depending on the mode defined by the sync-adapter, this flag controls
7776     * the top-level sync behavior for this data source.</td>
7777     * </tr>
7778     * <tr>
7779     * <td>int</td>
7780     * <td>{@link #UNGROUPED_VISIBLE}</td>
7781     * <td>read/write</td>
7782     * <td>Flag indicating if contacts without any
7783     * {@link CommonDataKinds.GroupMembership} entries should be visible in any
7784     * user interface.</td>
7785     * </tr>
7786     * <tr>
7787     * <td>int</td>
7788     * <td>{@link #ANY_UNSYNCED}</td>
7789     * <td>read-only</td>
7790     * <td>Read-only flag indicating if this {@link #SHOULD_SYNC} or any
7791     * {@link Groups#SHOULD_SYNC} under this account have been marked as
7792     * unsynced.</td>
7793     * </tr>
7794     * <tr>
7795     * <td>int</td>
7796     * <td>{@link #UNGROUPED_COUNT}</td>
7797     * <td>read-only</td>
7798     * <td>Read-only count of {@link Contacts} from a specific source that have
7799     * no {@link CommonDataKinds.GroupMembership} entries.</td>
7800     * </tr>
7801     * <tr>
7802     * <td>int</td>
7803     * <td>{@link #UNGROUPED_WITH_PHONES}</td>
7804     * <td>read-only</td>
7805     * <td>Read-only count of {@link Contacts} from a specific source that have
7806     * no {@link CommonDataKinds.GroupMembership} entries, and also have phone
7807     * numbers.</td>
7808     * </tr>
7809     * </table>
7810     */
7811    public static final class Settings implements SettingsColumns {
7812        /**
7813         * This utility class cannot be instantiated
7814         */
7815        private Settings() {
7816        }
7817
7818        /**
7819         * The content:// style URI for this table
7820         */
7821        public static final Uri CONTENT_URI =
7822                Uri.withAppendedPath(AUTHORITY_URI, "settings");
7823
7824        /**
7825         * The MIME-type of {@link #CONTENT_URI} providing a directory of
7826         * settings.
7827         */
7828        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/setting";
7829
7830        /**
7831         * The MIME-type of {@link #CONTENT_URI} providing a single setting.
7832         */
7833        public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/setting";
7834    }
7835
7836    /**
7837     * API for inquiring about the general status of the provider.
7838     */
7839    public static final class ProviderStatus {
7840
7841        /**
7842         * Not instantiable.
7843         */
7844        private ProviderStatus() {
7845        }
7846
7847        /**
7848         * The content:// style URI for this table.  Requests to this URI can be
7849         * performed on the UI thread because they are always unblocking.
7850         */
7851        public static final Uri CONTENT_URI =
7852                Uri.withAppendedPath(AUTHORITY_URI, "provider_status");
7853
7854        /**
7855         * The MIME-type of {@link #CONTENT_URI} providing a directory of
7856         * settings.
7857         */
7858        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/provider_status";
7859
7860        /**
7861         * An integer representing the current status of the provider.
7862         */
7863        public static final String STATUS = "status";
7864
7865        /**
7866         * Default status of the provider.
7867         */
7868        public static final int STATUS_NORMAL = 0;
7869
7870        /**
7871         * The status used when the provider is in the process of upgrading.  Contacts
7872         * are temporarily unaccessible.
7873         */
7874        public static final int STATUS_UPGRADING = 1;
7875
7876        /**
7877         * The status used during a locale change.
7878         */
7879        public static final int STATUS_CHANGING_LOCALE = 3;
7880
7881        /**
7882         * The status that indicates that there are no accounts and no contacts
7883         * on the device.
7884         */
7885        public static final int STATUS_NO_ACCOUNTS_NO_CONTACTS = 4;
7886    }
7887
7888    /**
7889     * <p>
7890     * API allowing applications to send usage information for each {@link Data} row to the
7891     * Contacts Provider.  Applications can also clear all usage information.
7892     * </p>
7893     * <p>
7894     * With the feedback, Contacts Provider may return more contextually appropriate results for
7895     * Data listing, typically supplied with
7896     * {@link ContactsContract.Contacts#CONTENT_FILTER_URI},
7897     * {@link ContactsContract.CommonDataKinds.Email#CONTENT_FILTER_URI},
7898     * {@link ContactsContract.CommonDataKinds.Phone#CONTENT_FILTER_URI}, and users can benefit
7899     * from better ranked (sorted) lists in applications that show auto-complete list.
7900     * </p>
7901     * <p>
7902     * There is no guarantee for how this feedback is used, or even whether it is used at all.
7903     * The ranking algorithm will make best efforts to use the feedback data, but the exact
7904     * implementation, the storage data structures as well as the resulting sort order is device
7905     * and version specific and can change over time.
7906     * </p>
7907     * <p>
7908     * When updating usage information, users of this API need to use
7909     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} with a Uri constructed
7910     * from {@link DataUsageFeedback#FEEDBACK_URI}. The Uri must contain one or more data id(s) as
7911     * its last path. They also need to append a query parameter to the Uri, to specify the type of
7912     * the communication, which enables the Contacts Provider to differentiate between kinds of
7913     * interactions using the same contact data field (for example a phone number can be used to
7914     * make phone calls or send SMS).
7915     * </p>
7916     * <p>
7917     * Selection and selectionArgs are ignored and must be set to null. To get data ids,
7918     * you may need to call {@link ContentResolver#query(Uri, String[], String, String[], String)}
7919     * toward {@link Data#CONTENT_URI}.
7920     * </p>
7921     * <p>
7922     * {@link ContentResolver#update(Uri, ContentValues, String, String[])} returns a positive
7923     * integer when successful, and returns 0 if no contact with that id was found.
7924     * </p>
7925     * <p>
7926     * Example:
7927     * <pre>
7928     * Uri uri = DataUsageFeedback.FEEDBACK_URI.buildUpon()
7929     *         .appendPath(TextUtils.join(",", dataIds))
7930     *         .appendQueryParameter(DataUsageFeedback.USAGE_TYPE,
7931     *                 DataUsageFeedback.USAGE_TYPE_CALL)
7932     *         .build();
7933     * boolean successful = resolver.update(uri, new ContentValues(), null, null) > 0;
7934     * </pre>
7935     * </p>
7936     * <p>
7937     * Applications can also clear all usage information with:
7938     * <pre>
7939     * boolean successful = resolver.delete(DataUsageFeedback.DELETE_USAGE_URI, null, null) > 0;
7940     * </pre>
7941     * </p>
7942     */
7943    public static final class DataUsageFeedback {
7944
7945        /**
7946         * The content:// style URI for sending usage feedback.
7947         * Must be used with {@link ContentResolver#update(Uri, ContentValues, String, String[])}.
7948         */
7949        public static final Uri FEEDBACK_URI =
7950                Uri.withAppendedPath(Data.CONTENT_URI, "usagefeedback");
7951
7952        /**
7953         * The content:// style URI for deleting all usage information.
7954         * Must be used with {@link ContentResolver#delete(Uri, String, String[])}.
7955         * The {@code where} and {@code selectionArgs} parameters are ignored.
7956         */
7957        public static final Uri DELETE_USAGE_URI =
7958                Uri.withAppendedPath(Contacts.CONTENT_URI, "delete_usage");
7959
7960        /**
7961         * <p>
7962         * Name for query parameter specifying the type of data usage.
7963         * </p>
7964         */
7965        public static final String USAGE_TYPE = "type";
7966
7967        /**
7968         * <p>
7969         * Type of usage for voice interaction, which includes phone call, voice chat, and
7970         * video chat.
7971         * </p>
7972         */
7973        public static final String USAGE_TYPE_CALL = "call";
7974
7975        /**
7976         * <p>
7977         * Type of usage for text interaction involving longer messages, which includes email.
7978         * </p>
7979         */
7980        public static final String USAGE_TYPE_LONG_TEXT = "long_text";
7981
7982        /**
7983         * <p>
7984         * Type of usage for text interaction involving shorter messages, which includes SMS,
7985         * text chat with email addresses.
7986         * </p>
7987         */
7988        public static final String USAGE_TYPE_SHORT_TEXT = "short_text";
7989    }
7990
7991    /**
7992     * <p>
7993     * Contact-specific information about whether or not a contact has been pinned by the user
7994     * at a particular position within the system contact application's user interface.
7995     * </p>
7996     *
7997     * <p>
7998     * This pinning information can be used by individual applications to customize how
7999     * they order particular pinned contacts. For example, a Dialer application could
8000     * use pinned information to order user-pinned contacts in a top row of favorites.
8001     * </p>
8002     *
8003     * <p>
8004     * It is possible for two or more contacts to occupy the same pinned position (due
8005     * to aggregation and sync), so this pinning information should be used on a best-effort
8006     * basis to order contacts in-application rather than an absolute guide on where a contact
8007     * should be positioned. Contacts returned by the ContactsProvider will not be ordered based
8008     * on this information, so it is up to the client application to reorder these contacts within
8009     * their own UI adhering to (or ignoring as appropriate) information stored in the pinned
8010     * column.
8011     * </p>
8012     *
8013     * <p>
8014     * By default, unpinned contacts will have a pinned position of
8015     * {@link PinnedPositions#UNPINNED}. Client-provided pinned positions can be positive
8016     * integers that are greater than 1.
8017     * </p>
8018     */
8019    public static final class PinnedPositions {
8020        /**
8021         * The method to invoke in order to undemote a formerly demoted contact. The contact id of
8022         * the contact must be provided as an argument. If the contact was not previously demoted,
8023         * nothing will be done.
8024         * @hide
8025         */
8026        public static final String UNDEMOTE_METHOD = "undemote";
8027
8028        /**
8029         * Undemotes a formerly demoted contact. If the contact was not previously demoted, nothing
8030         * will be done.
8031         *
8032         * @param contentResolver to perform the undemote operation on.
8033         * @param contactId the id of the contact to undemote.
8034         */
8035        public static void undemote(ContentResolver contentResolver, long contactId) {
8036            contentResolver.call(ContactsContract.AUTHORITY_URI, PinnedPositions.UNDEMOTE_METHOD,
8037                    String.valueOf(contactId), null);
8038        }
8039
8040        /**
8041         * Pins a contact at a provided position, or unpins a contact.
8042         *
8043         * @param contentResolver to perform the pinning operation on.
8044         * @param pinnedPosition the position to pin the contact at. To unpin a contact, use
8045         *         {@link PinnedPositions#UNPINNED}.
8046         */
8047        public static void pin(
8048                ContentResolver contentResolver, long contactId, int pinnedPosition) {
8049            final Uri uri = Uri.withAppendedPath(Contacts.CONTENT_URI, String.valueOf(contactId));
8050            final ContentValues values = new ContentValues();
8051            values.put(Contacts.PINNED, pinnedPosition);
8052            contentResolver.update(uri, values, null, null);
8053        }
8054
8055        /**
8056         * Default value for the pinned position of an unpinned contact.
8057         */
8058        public static final int UNPINNED = 0;
8059
8060        /**
8061         * Value of pinned position for a contact that a user has indicated should be considered
8062         * of the lowest priority. It is up to the client application to determine how to present
8063         * such a contact - for example all the way at the bottom of a contact list, or simply
8064         * just hidden from view.
8065         */
8066        public static final int DEMOTED = -1;
8067    }
8068
8069    /**
8070     * Helper methods to display QuickContact dialogs that display all the information belonging to
8071     * a specific {@link Contacts} entry.
8072     */
8073    public static final class QuickContact {
8074        /**
8075         * Action used to launch the system contacts application and bring up a QuickContact dialog
8076         * for the provided {@link Contacts} entry.
8077         */
8078        public static final String ACTION_QUICK_CONTACT =
8079                "android.provider.action.QUICK_CONTACT";
8080
8081        /**
8082         * Extra used to specify pivot dialog location in screen coordinates.
8083         * @deprecated Use {@link Intent#setSourceBounds(Rect)} instead.
8084         * @hide
8085         */
8086        @Deprecated
8087        public static final String EXTRA_TARGET_RECT = "android.provider.extra.TARGET_RECT";
8088
8089        /**
8090         * Extra used to specify size of QuickContacts. Not all implementations of QuickContacts
8091         * will respect this extra's value.
8092         *
8093         * One of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
8094         */
8095        public static final String EXTRA_MODE = "android.provider.extra.MODE";
8096
8097        /**
8098         * Extra used to specify which mimetype should be prioritized in the QuickContacts UI.
8099         * For example, passing the value {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can
8100         * cause phone numbers to be displayed more prominently in QuickContacts.
8101         */
8102        public static final String EXTRA_PRIORITIZED_MIMETYPE
8103                = "android.provider.extra.PRIORITIZED_MIMETYPE";
8104
8105        /**
8106         * Extra used to indicate a list of specific MIME-types to exclude and not display in the
8107         * QuickContacts dialog. Stored as a {@link String} array.
8108         */
8109        public static final String EXTRA_EXCLUDE_MIMES = "android.provider.extra.EXCLUDE_MIMES";
8110
8111        /**
8112         * Small QuickContact mode, usually presented with minimal actions.
8113         */
8114        public static final int MODE_SMALL = 1;
8115
8116        /**
8117         * Medium QuickContact mode, includes actions and light summary describing
8118         * the {@link Contacts} entry being shown. This may include social
8119         * status and presence details.
8120         */
8121        public static final int MODE_MEDIUM = 2;
8122
8123        /**
8124         * Large QuickContact mode, includes actions and larger, card-like summary
8125         * of the {@link Contacts} entry being shown. This may include detailed
8126         * information, such as a photo.
8127         */
8128        public static final int MODE_LARGE = 3;
8129
8130        /**
8131         * Constructs the QuickContacts intent with a view's rect.
8132         * @hide
8133         */
8134        public static Intent composeQuickContactsIntent(Context context, View target, Uri lookupUri,
8135                int mode, String[] excludeMimes) {
8136            // Find location and bounds of target view, adjusting based on the
8137            // assumed local density.
8138            final float appScale = context.getResources().getCompatibilityInfo().applicationScale;
8139            final int[] pos = new int[2];
8140            target.getLocationOnScreen(pos);
8141
8142            final Rect rect = new Rect();
8143            rect.left = (int) (pos[0] * appScale + 0.5f);
8144            rect.top = (int) (pos[1] * appScale + 0.5f);
8145            rect.right = (int) ((pos[0] + target.getWidth()) * appScale + 0.5f);
8146            rect.bottom = (int) ((pos[1] + target.getHeight()) * appScale + 0.5f);
8147
8148            return composeQuickContactsIntent(context, rect, lookupUri, mode, excludeMimes);
8149        }
8150
8151        /**
8152         * Constructs the QuickContacts intent.
8153         * @hide
8154         */
8155        public static Intent composeQuickContactsIntent(Context context, Rect target,
8156                Uri lookupUri, int mode, String[] excludeMimes) {
8157            // When launching from an Activiy, we don't want to start a new task, but otherwise
8158            // we *must* start a new task.  (Otherwise startActivity() would crash.)
8159            Context actualContext = context;
8160            while ((actualContext instanceof ContextWrapper)
8161                    && !(actualContext instanceof Activity)) {
8162                actualContext = ((ContextWrapper) actualContext).getBaseContext();
8163            }
8164            final int intentFlags = ((actualContext instanceof Activity)
8165                    ? 0 : Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
8166                    // Workaround for b/16898764. Declaring singleTop in manifest doesn't work.
8167                    | Intent.FLAG_ACTIVITY_SINGLE_TOP;
8168
8169            // Launch pivot dialog through intent for now
8170            final Intent intent = new Intent(ACTION_QUICK_CONTACT).addFlags(intentFlags);
8171
8172            intent.setData(lookupUri);
8173            intent.setSourceBounds(target);
8174            intent.putExtra(EXTRA_MODE, mode);
8175            intent.putExtra(EXTRA_EXCLUDE_MIMES, excludeMimes);
8176            return intent;
8177        }
8178
8179        /**
8180         * Trigger a dialog that lists the various methods of interacting with
8181         * the requested {@link Contacts} entry. This may be based on available
8182         * {@link ContactsContract.Data} rows under that contact, and may also
8183         * include social status and presence details.
8184         *
8185         * @param context The parent {@link Context} that may be used as the
8186         *            parent for this dialog.
8187         * @param target Specific {@link View} from your layout that this dialog
8188         *            should be centered around. In particular, if the dialog
8189         *            has a "callout" arrow, it will be pointed and centered
8190         *            around this {@link View}.
8191         * @param lookupUri A {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8192         *            {@link Uri} that describes a specific contact to feature
8193         *            in this dialog.
8194         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
8195         *            {@link #MODE_LARGE}, indicating the desired dialog size,
8196         *            when supported.
8197         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8198         *            to exclude when showing this dialog. For example, when
8199         *            already viewing the contact details card, this can be used
8200         *            to omit the details entry from the dialog.
8201         */
8202        public static void showQuickContact(Context context, View target, Uri lookupUri, int mode,
8203                String[] excludeMimes) {
8204            // Trigger with obtained rectangle
8205            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
8206                    excludeMimes);
8207            startActivityWithErrorToast(context, intent);
8208        }
8209
8210        /**
8211         * Trigger a dialog that lists the various methods of interacting with
8212         * the requested {@link Contacts} entry. This may be based on available
8213         * {@link ContactsContract.Data} rows under that contact, and may also
8214         * include social status and presence details.
8215         *
8216         * @param context The parent {@link Context} that may be used as the
8217         *            parent for this dialog.
8218         * @param target Specific {@link Rect} that this dialog should be
8219         *            centered around, in screen coordinates. In particular, if
8220         *            the dialog has a "callout" arrow, it will be pointed and
8221         *            centered around this {@link Rect}. If you are running at a
8222         *            non-native density, you need to manually adjust using
8223         *            {@link DisplayMetrics#density} before calling.
8224         * @param lookupUri A
8225         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8226         *            {@link Uri} that describes a specific contact to feature
8227         *            in this dialog.
8228         * @param mode Any of {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or
8229         *            {@link #MODE_LARGE}, indicating the desired dialog size,
8230         *            when supported.
8231         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8232         *            to exclude when showing this dialog. For example, when
8233         *            already viewing the contact details card, this can be used
8234         *            to omit the details entry from the dialog.
8235         */
8236        public static void showQuickContact(Context context, Rect target, Uri lookupUri, int mode,
8237                String[] excludeMimes) {
8238            Intent intent = composeQuickContactsIntent(context, target, lookupUri, mode,
8239                    excludeMimes);
8240            startActivityWithErrorToast(context, intent);
8241        }
8242
8243        /**
8244         * Trigger a dialog that lists the various methods of interacting with
8245         * the requested {@link Contacts} entry. This may be based on available
8246         * {@link ContactsContract.Data} rows under that contact, and may also
8247         * include social status and presence details.
8248         *
8249         * @param context The parent {@link Context} that may be used as the
8250         *            parent for this dialog.
8251         * @param target Specific {@link View} from your layout that this dialog
8252         *            should be centered around. In particular, if the dialog
8253         *            has a "callout" arrow, it will be pointed and centered
8254         *            around this {@link View}.
8255         * @param lookupUri A
8256         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8257         *            {@link Uri} that describes a specific contact to feature
8258         *            in this dialog.
8259         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8260         *            to exclude when showing this dialog. For example, when
8261         *            already viewing the contact details card, this can be used
8262         *            to omit the details entry from the dialog.
8263         * @param prioritizedMimeType This mimetype should be prioritized in the QuickContacts UI.
8264         *             For example, passing the value
8265         *             {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can cause phone numbers to be
8266         *             displayed more prominently in QuickContacts.
8267         */
8268        public static void showQuickContact(Context context, View target, Uri lookupUri,
8269                String[] excludeMimes, String prioritizedMimeType) {
8270            // Use MODE_LARGE instead of accepting mode as a parameter. The different mode
8271            // values defined in ContactsContract only affect very old implementations
8272            // of QuickContacts.
8273            Intent intent = composeQuickContactsIntent(context, target, lookupUri, MODE_LARGE,
8274                    excludeMimes);
8275            intent.putExtra(EXTRA_PRIORITIZED_MIMETYPE, prioritizedMimeType);
8276            startActivityWithErrorToast(context, intent);
8277        }
8278
8279        /**
8280         * Trigger a dialog that lists the various methods of interacting with
8281         * the requested {@link Contacts} entry. This may be based on available
8282         * {@link ContactsContract.Data} rows under that contact, and may also
8283         * include social status and presence details.
8284         *
8285         * @param context The parent {@link Context} that may be used as the
8286         *            parent for this dialog.
8287         * @param target Specific {@link Rect} that this dialog should be
8288         *            centered around, in screen coordinates. In particular, if
8289         *            the dialog has a "callout" arrow, it will be pointed and
8290         *            centered around this {@link Rect}. If you are running at a
8291         *            non-native density, you need to manually adjust using
8292         *            {@link DisplayMetrics#density} before calling.
8293         * @param lookupUri A
8294         *            {@link ContactsContract.Contacts#CONTENT_LOOKUP_URI} style
8295         *            {@link Uri} that describes a specific contact to feature
8296         *            in this dialog.
8297         * @param excludeMimes Optional list of {@link Data#MIMETYPE} MIME-types
8298         *            to exclude when showing this dialog. For example, when
8299         *            already viewing the contact details card, this can be used
8300         *            to omit the details entry from the dialog.
8301         * @param prioritizedMimeType This mimetype should be prioritized in the QuickContacts UI.
8302         *             For example, passing the value
8303         *             {@link CommonDataKinds.Phone#CONTENT_ITEM_TYPE} can cause phone numbers to be
8304         *             displayed more prominently in QuickContacts.
8305         */
8306        public static void showQuickContact(Context context, Rect target, Uri lookupUri,
8307                String[] excludeMimes, String prioritizedMimeType) {
8308            // Use MODE_LARGE instead of accepting mode as a parameter. The different mode
8309            // values defined in ContactsContract only affect very old implementations
8310            // of QuickContacts.
8311            Intent intent = composeQuickContactsIntent(context, target, lookupUri, MODE_LARGE,
8312                    excludeMimes);
8313            intent.putExtra(EXTRA_PRIORITIZED_MIMETYPE, prioritizedMimeType);
8314            startActivityWithErrorToast(context, intent);
8315        }
8316
8317        private static void startActivityWithErrorToast(Context context, Intent intent) {
8318            try {
8319              context.startActivity(intent);
8320            } catch (ActivityNotFoundException e) {
8321                Toast.makeText(context, com.android.internal.R.string.quick_contacts_not_available,
8322                                Toast.LENGTH_SHORT).show();
8323            }
8324        }
8325    }
8326
8327    /**
8328     * Helper class for accessing full-size photos by photo file ID.
8329     * <p>
8330     * Usage example:
8331     * <dl>
8332     * <dt>Retrieving a full-size photo by photo file ID (see
8333     * {@link ContactsContract.ContactsColumns#PHOTO_FILE_ID})
8334     * </dt>
8335     * <dd>
8336     * <pre>
8337     * public InputStream openDisplayPhoto(long photoFileId) {
8338     *     Uri displayPhotoUri = ContentUris.withAppendedId(DisplayPhoto.CONTENT_URI, photoKey);
8339     *     try {
8340     *         AssetFileDescriptor fd = getContentResolver().openAssetFileDescriptor(
8341     *             displayPhotoUri, "r");
8342     *         return fd.createInputStream();
8343     *     } catch (IOException e) {
8344     *         return null;
8345     *     }
8346     * }
8347     * </pre>
8348     * </dd>
8349     * </dl>
8350     * </p>
8351     */
8352    public static final class DisplayPhoto {
8353        /**
8354         * no public constructor since this is a utility class
8355         */
8356        private DisplayPhoto() {}
8357
8358        /**
8359         * The content:// style URI for this class, which allows access to full-size photos,
8360         * given a key.
8361         */
8362        public static final Uri CONTENT_URI = Uri.withAppendedPath(AUTHORITY_URI, "display_photo");
8363
8364        /**
8365         * This URI allows the caller to query for the maximum dimensions of a display photo
8366         * or thumbnail.  Requests to this URI can be performed on the UI thread because
8367         * they are always unblocking.
8368         */
8369        public static final Uri CONTENT_MAX_DIMENSIONS_URI =
8370                Uri.withAppendedPath(AUTHORITY_URI, "photo_dimensions");
8371
8372        /**
8373         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8374         * contain this column, populated with the maximum height and width (in pixels)
8375         * that will be stored for a display photo.  Larger photos will be down-sized to
8376         * fit within a square of this many pixels.
8377         */
8378        public static final String DISPLAY_MAX_DIM = "display_max_dim";
8379
8380        /**
8381         * Queries to {@link ContactsContract.DisplayPhoto#CONTENT_MAX_DIMENSIONS_URI} will
8382         * contain this column, populated with the height and width (in pixels) for photo
8383         * thumbnails.
8384         */
8385        public static final String THUMBNAIL_MAX_DIM = "thumbnail_max_dim";
8386    }
8387
8388    /**
8389     * Contains helper classes used to create or manage {@link android.content.Intent Intents}
8390     * that involve contacts.
8391     */
8392    public static final class Intents {
8393        /**
8394         * This is the intent that is fired when a search suggestion is clicked on.
8395         */
8396        public static final String SEARCH_SUGGESTION_CLICKED =
8397                "android.provider.Contacts.SEARCH_SUGGESTION_CLICKED";
8398
8399        /**
8400         * This is the intent that is fired when a search suggestion for dialing a number
8401         * is clicked on.
8402         */
8403        public static final String SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED =
8404                "android.provider.Contacts.SEARCH_SUGGESTION_DIAL_NUMBER_CLICKED";
8405
8406        /**
8407         * This is the intent that is fired when a search suggestion for creating a contact
8408         * is clicked on.
8409         */
8410        public static final String SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED =
8411                "android.provider.Contacts.SEARCH_SUGGESTION_CREATE_CONTACT_CLICKED";
8412
8413        /**
8414         * This is the intent that is fired when the contacts database is created. <p> The
8415         * READ_CONTACT permission is required to receive these broadcasts.
8416         */
8417        public static final String CONTACTS_DATABASE_CREATED =
8418                "android.provider.Contacts.DATABASE_CREATED";
8419
8420        /**
8421         * Starts an Activity that lets the user pick a contact to attach an image to.
8422         * After picking the contact it launches the image cropper in face detection mode.
8423         */
8424        public static final String ATTACH_IMAGE =
8425                "com.android.contacts.action.ATTACH_IMAGE";
8426
8427        /**
8428         * This is the intent that is fired when the user clicks the "invite to the network" button
8429         * on a contact.  Only sent to an activity which is explicitly registered by a contact
8430         * provider which supports the "invite to the network" feature.
8431         * <p>
8432         * {@link Intent#getData()} contains the lookup URI for the contact.
8433         */
8434        public static final String INVITE_CONTACT =
8435                "com.android.contacts.action.INVITE_CONTACT";
8436
8437        /**
8438         * Takes as input a data URI with a mailto: or tel: scheme. If a single
8439         * contact exists with the given data it will be shown. If no contact
8440         * exists, a dialog will ask the user if they want to create a new
8441         * contact with the provided details filled in. If multiple contacts
8442         * share the data the user will be prompted to pick which contact they
8443         * want to view.
8444         * <p>
8445         * For <code>mailto:</code> URIs, the scheme specific portion must be a
8446         * raw email address, such as one built using
8447         * {@link Uri#fromParts(String, String, String)}.
8448         * <p>
8449         * For <code>tel:</code> URIs, the scheme specific portion is compared
8450         * to existing numbers using the standard caller ID lookup algorithm.
8451         * The number must be properly encoded, for example using
8452         * {@link Uri#fromParts(String, String, String)}.
8453         * <p>
8454         * Any extras from the {@link Insert} class will be passed along to the
8455         * create activity if there are no contacts to show.
8456         * <p>
8457         * Passing true for the {@link #EXTRA_FORCE_CREATE} extra will skip
8458         * prompting the user when the contact doesn't exist.
8459         */
8460        public static final String SHOW_OR_CREATE_CONTACT =
8461                "com.android.contacts.action.SHOW_OR_CREATE_CONTACT";
8462
8463        /**
8464         * Starts an Activity that lets the user select the multiple phones from a
8465         * list of phone numbers which come from the contacts or
8466         * {@link #EXTRA_PHONE_URIS}.
8467         * <p>
8468         * The phone numbers being passed in through {@link #EXTRA_PHONE_URIS}
8469         * could belong to the contacts or not, and will be selected by default.
8470         * <p>
8471         * The user's selection will be returned from
8472         * {@link android.app.Activity#onActivityResult(int, int, android.content.Intent)}
8473         * if the resultCode is
8474         * {@link android.app.Activity#RESULT_OK}, the array of picked phone
8475         * numbers are in the Intent's
8476         * {@link #EXTRA_PHONE_URIS}; otherwise, the
8477         * {@link android.app.Activity#RESULT_CANCELED} is returned if the user
8478         * left the Activity without changing the selection.
8479         *
8480         * @hide
8481         */
8482        public static final String ACTION_GET_MULTIPLE_PHONES =
8483                "com.android.contacts.action.GET_MULTIPLE_PHONES";
8484
8485        /**
8486         * A broadcast action which is sent when any change has been made to the profile, such
8487         * as the profile name or the picture.  A receiver must have
8488         * the android.permission.READ_PROFILE permission.
8489         *
8490         * @hide
8491         */
8492        public static final String ACTION_PROFILE_CHANGED =
8493                "android.provider.Contacts.PROFILE_CHANGED";
8494
8495        /**
8496         * Used with {@link #SHOW_OR_CREATE_CONTACT} to force creating a new
8497         * contact if no matching contact found. Otherwise, default behavior is
8498         * to prompt user with dialog before creating.
8499         * <p>
8500         * Type: BOOLEAN
8501         */
8502        public static final String EXTRA_FORCE_CREATE =
8503                "com.android.contacts.action.FORCE_CREATE";
8504
8505        /**
8506         * Used with {@link #SHOW_OR_CREATE_CONTACT} to specify an exact
8507         * description to be shown when prompting user about creating a new
8508         * contact.
8509         * <p>
8510         * Type: STRING
8511         */
8512        public static final String EXTRA_CREATE_DESCRIPTION =
8513            "com.android.contacts.action.CREATE_DESCRIPTION";
8514
8515        /**
8516         * Used with {@link #ACTION_GET_MULTIPLE_PHONES} as the input or output value.
8517         * <p>
8518         * The phone numbers want to be picked by default should be passed in as
8519         * input value. These phone numbers could belong to the contacts or not.
8520         * <p>
8521         * The phone numbers which were picked by the user are returned as output
8522         * value.
8523         * <p>
8524         * Type: array of URIs, the tel URI is used for the phone numbers which don't
8525         * belong to any contact, the content URI is used for phone id in contacts.
8526         *
8527         * @hide
8528         */
8529        public static final String EXTRA_PHONE_URIS =
8530            "com.android.contacts.extra.PHONE_URIS";
8531
8532        /**
8533         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8534         * dialog location using screen coordinates. When not specified, the
8535         * dialog will be centered.
8536         *
8537         * @hide
8538         */
8539        @Deprecated
8540        public static final String EXTRA_TARGET_RECT = "target_rect";
8541
8542        /**
8543         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to specify a
8544         * desired dialog style, usually a variation on size. One of
8545         * {@link #MODE_SMALL}, {@link #MODE_MEDIUM}, or {@link #MODE_LARGE}.
8546         *
8547         * @hide
8548         */
8549        @Deprecated
8550        public static final String EXTRA_MODE = "mode";
8551
8552        /**
8553         * Value for {@link #EXTRA_MODE} to show a small-sized dialog.
8554         *
8555         * @hide
8556         */
8557        @Deprecated
8558        public static final int MODE_SMALL = 1;
8559
8560        /**
8561         * Value for {@link #EXTRA_MODE} to show a medium-sized dialog.
8562         *
8563         * @hide
8564         */
8565        @Deprecated
8566        public static final int MODE_MEDIUM = 2;
8567
8568        /**
8569         * Value for {@link #EXTRA_MODE} to show a large-sized dialog.
8570         *
8571         * @hide
8572         */
8573        @Deprecated
8574        public static final int MODE_LARGE = 3;
8575
8576        /**
8577         * Optional extra used with {@link #SHOW_OR_CREATE_CONTACT} to indicate
8578         * a list of specific MIME-types to exclude and not display. Stored as a
8579         * {@link String} array.
8580         *
8581         * @hide
8582         */
8583        @Deprecated
8584        public static final String EXTRA_EXCLUDE_MIMES = "exclude_mimes";
8585
8586        /**
8587         * Convenience class that contains string constants used
8588         * to create contact {@link android.content.Intent Intents}.
8589         */
8590        public static final class Insert {
8591            /** The action code to use when adding a contact */
8592            public static final String ACTION = Intent.ACTION_INSERT;
8593
8594            /**
8595             * If present, forces a bypass of quick insert mode.
8596             */
8597            public static final String FULL_MODE = "full_mode";
8598
8599            /**
8600             * The extra field for the contact name.
8601             * <P>Type: String</P>
8602             */
8603            public static final String NAME = "name";
8604
8605            // TODO add structured name values here.
8606
8607            /**
8608             * The extra field for the contact phonetic name.
8609             * <P>Type: String</P>
8610             */
8611            public static final String PHONETIC_NAME = "phonetic_name";
8612
8613            /**
8614             * The extra field for the contact company.
8615             * <P>Type: String</P>
8616             */
8617            public static final String COMPANY = "company";
8618
8619            /**
8620             * The extra field for the contact job title.
8621             * <P>Type: String</P>
8622             */
8623            public static final String JOB_TITLE = "job_title";
8624
8625            /**
8626             * The extra field for the contact notes.
8627             * <P>Type: String</P>
8628             */
8629            public static final String NOTES = "notes";
8630
8631            /**
8632             * The extra field for the contact phone number.
8633             * <P>Type: String</P>
8634             */
8635            public static final String PHONE = "phone";
8636
8637            /**
8638             * The extra field for the contact phone number type.
8639             * <P>Type: Either an integer value from
8640             * {@link CommonDataKinds.Phone},
8641             *  or a string specifying a custom label.</P>
8642             */
8643            public static final String PHONE_TYPE = "phone_type";
8644
8645            /**
8646             * The extra field for the phone isprimary flag.
8647             * <P>Type: boolean</P>
8648             */
8649            public static final String PHONE_ISPRIMARY = "phone_isprimary";
8650
8651            /**
8652             * The extra field for an optional second contact phone number.
8653             * <P>Type: String</P>
8654             */
8655            public static final String SECONDARY_PHONE = "secondary_phone";
8656
8657            /**
8658             * The extra field for an optional second contact phone number type.
8659             * <P>Type: Either an integer value from
8660             * {@link CommonDataKinds.Phone},
8661             *  or a string specifying a custom label.</P>
8662             */
8663            public static final String SECONDARY_PHONE_TYPE = "secondary_phone_type";
8664
8665            /**
8666             * The extra field for an optional third contact phone number.
8667             * <P>Type: String</P>
8668             */
8669            public static final String TERTIARY_PHONE = "tertiary_phone";
8670
8671            /**
8672             * The extra field for an optional third contact phone number type.
8673             * <P>Type: Either an integer value from
8674             * {@link CommonDataKinds.Phone},
8675             *  or a string specifying a custom label.</P>
8676             */
8677            public static final String TERTIARY_PHONE_TYPE = "tertiary_phone_type";
8678
8679            /**
8680             * The extra field for the contact email address.
8681             * <P>Type: String</P>
8682             */
8683            public static final String EMAIL = "email";
8684
8685            /**
8686             * The extra field for the contact email type.
8687             * <P>Type: Either an integer value from
8688             * {@link CommonDataKinds.Email}
8689             *  or a string specifying a custom label.</P>
8690             */
8691            public static final String EMAIL_TYPE = "email_type";
8692
8693            /**
8694             * The extra field for the email isprimary flag.
8695             * <P>Type: boolean</P>
8696             */
8697            public static final String EMAIL_ISPRIMARY = "email_isprimary";
8698
8699            /**
8700             * The extra field for an optional second contact email address.
8701             * <P>Type: String</P>
8702             */
8703            public static final String SECONDARY_EMAIL = "secondary_email";
8704
8705            /**
8706             * The extra field for an optional second contact email type.
8707             * <P>Type: Either an integer value from
8708             * {@link CommonDataKinds.Email}
8709             *  or a string specifying a custom label.</P>
8710             */
8711            public static final String SECONDARY_EMAIL_TYPE = "secondary_email_type";
8712
8713            /**
8714             * The extra field for an optional third contact email address.
8715             * <P>Type: String</P>
8716             */
8717            public static final String TERTIARY_EMAIL = "tertiary_email";
8718
8719            /**
8720             * The extra field for an optional third contact email type.
8721             * <P>Type: Either an integer value from
8722             * {@link CommonDataKinds.Email}
8723             *  or a string specifying a custom label.</P>
8724             */
8725            public static final String TERTIARY_EMAIL_TYPE = "tertiary_email_type";
8726
8727            /**
8728             * The extra field for the contact postal address.
8729             * <P>Type: String</P>
8730             */
8731            public static final String POSTAL = "postal";
8732
8733            /**
8734             * The extra field for the contact postal address type.
8735             * <P>Type: Either an integer value from
8736             * {@link CommonDataKinds.StructuredPostal}
8737             *  or a string specifying a custom label.</P>
8738             */
8739            public static final String POSTAL_TYPE = "postal_type";
8740
8741            /**
8742             * The extra field for the postal isprimary flag.
8743             * <P>Type: boolean</P>
8744             */
8745            public static final String POSTAL_ISPRIMARY = "postal_isprimary";
8746
8747            /**
8748             * The extra field for an IM handle.
8749             * <P>Type: String</P>
8750             */
8751            public static final String IM_HANDLE = "im_handle";
8752
8753            /**
8754             * The extra field for the IM protocol
8755             */
8756            public static final String IM_PROTOCOL = "im_protocol";
8757
8758            /**
8759             * The extra field for the IM isprimary flag.
8760             * <P>Type: boolean</P>
8761             */
8762            public static final String IM_ISPRIMARY = "im_isprimary";
8763
8764            /**
8765             * The extra field that allows the client to supply multiple rows of
8766             * arbitrary data for a single contact created using the {@link Intent#ACTION_INSERT}
8767             * or edited using {@link Intent#ACTION_EDIT}. It is an ArrayList of
8768             * {@link ContentValues}, one per data row. Supplying this extra is
8769             * similar to inserting multiple rows into the {@link Data} table,
8770             * except the user gets a chance to see and edit them before saving.
8771             * Each ContentValues object must have a value for {@link Data#MIMETYPE}.
8772             * If supplied values are not visible in the editor UI, they will be
8773             * dropped.  Duplicate data will dropped.  Some fields
8774             * like {@link CommonDataKinds.Email#TYPE Email.TYPE} may be automatically
8775             * adjusted to comply with the constraints of the specific account type.
8776             * For example, an Exchange contact can only have one phone numbers of type Home,
8777             * so the contact editor may choose a different type for this phone number to
8778             * avoid dropping the valueable part of the row, which is the phone number.
8779             * <p>
8780             * Example:
8781             * <pre>
8782             *  ArrayList&lt;ContentValues&gt; data = new ArrayList&lt;ContentValues&gt;();
8783             *
8784             *  ContentValues row1 = new ContentValues();
8785             *  row1.put(Data.MIMETYPE, Organization.CONTENT_ITEM_TYPE);
8786             *  row1.put(Organization.COMPANY, "Android");
8787             *  data.add(row1);
8788             *
8789             *  ContentValues row2 = new ContentValues();
8790             *  row2.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
8791             *  row2.put(Email.TYPE, Email.TYPE_CUSTOM);
8792             *  row2.put(Email.LABEL, "Green Bot");
8793             *  row2.put(Email.ADDRESS, "android@android.com");
8794             *  data.add(row2);
8795             *
8796             *  Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
8797             *  intent.putParcelableArrayListExtra(Insert.DATA, data);
8798             *
8799             *  startActivity(intent);
8800             * </pre>
8801             */
8802            public static final String DATA = "data";
8803
8804            /**
8805             * Used to specify the account in which to create the new contact.
8806             * <p>
8807             * If this value is not provided, the user is presented with a disambiguation
8808             * dialog to chose an account
8809             * <p>
8810             * Type: {@link Account}
8811             */
8812            public static final String EXTRA_ACCOUNT = "android.provider.extra.ACCOUNT";
8813
8814            /**
8815             * Used to specify the data set within the account in which to create the
8816             * new contact.
8817             * <p>
8818             * This value is optional - if it is not specified, the contact will be
8819             * created in the base account, with no data set.
8820             * <p>
8821             * Type: String
8822             */
8823            public static final String EXTRA_DATA_SET = "android.provider.extra.DATA_SET";
8824        }
8825    }
8826}
8827