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