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