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