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