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