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