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