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