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