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