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