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