Home | History | Annotate | Download | only in provider
      1 /*
      2  * Copyright (C) 2011 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.Manifest;
     20 import android.annotation.SdkConstant;
     21 import android.annotation.SdkConstant.SdkConstantType;
     22 import android.content.Intent;
     23 import android.database.ContentObserver;
     24 import android.net.Uri;
     25 import android.provider.CallLog.Calls;
     26 
     27 /**
     28  * The contract between the voicemail provider and applications. Contains
     29  * definitions for the supported URIs and columns.
     30  *
     31  * <P>The content providers exposes two tables through this interface:
     32  * <ul>
     33  *   <li> Voicemails table: This stores the actual voicemail records. The
     34  *   columns and URIs for accessing this table are defined by the
     35  *   {@link Voicemails} class.
     36  *   </li>
     37  *   <li> Status table: This provides a way for the voicemail source application
     38  *   to convey its current state to the system. The columns and URIS for
     39  *   accessing this table are defined by the {@link Status} class.
     40  *   </li>
     41  * </ul>
     42  *
     43  * <P> The minimum permission needed to access this content provider is
     44  * {@link Manifest.permission#ADD_VOICEMAIL}
     45  *
     46  * <P>Voicemails are inserted by what is called as a "voicemail source"
     47  * application, which is responsible for syncing voicemail data between a remote
     48  * server and the local voicemail content provider. "voicemail source"
     49  * application should always set the {@link #PARAM_KEY_SOURCE_PACKAGE} in the
     50  * URI to identify its package.
     51  *
     52  * <P>In addition to the {@link ContentObserver} notifications the voicemail
     53  * provider also generates broadcast intents to notify change for applications
     54  * that are not active and therefore cannot listen to ContentObserver
     55  * notifications. Broadcast intents with following actions are generated:
     56  * <ul>
     57  *   <li> {@link #ACTION_NEW_VOICEMAIL} is generated for each new voicemail
     58  *   inserted.
     59  *   </li>
     60  *   <li> {@link Intent#ACTION_PROVIDER_CHANGED} is generated for any change
     61  *    made into the database, including new voicemail.
     62  *   </li>
     63  * </ul>
     64  */
     65 public class VoicemailContract {
     66     /** Not instantiable. */
     67     private VoicemailContract() {
     68     }
     69 
     70     /** The authority used by the voicemail provider. */
     71     public static final String AUTHORITY = "com.android.voicemail";
     72     /**
     73      * Parameter key used in the URI to specify the voicemail source package name.
     74      * <p> This field must be set in all requests that originate from a voicemail source.
     75      */
     76     public static final String PARAM_KEY_SOURCE_PACKAGE = "source_package";
     77 
     78     /** Broadcast intent when a new voicemail record is inserted. */
     79     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
     80     public static final String ACTION_NEW_VOICEMAIL = "android.intent.action.NEW_VOICEMAIL";
     81 
     82     /**
     83      * Broadcast intent to request a voicemail source to fetch voicemail content of a specific
     84      * voicemail from the remote server. The voicemail to fetch is specified by the data uri
     85      * of the intent.
     86      * <p>
     87      * All voicemail sources are expected to handle this event. After storing the content
     88      * the application should also set {@link Voicemails#HAS_CONTENT} to 1;
     89      */
     90     @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
     91     public static final String ACTION_FETCH_VOICEMAIL = "android.intent.action.FETCH_VOICEMAIL";
     92 
     93     /**
     94      * Extra included in {@link Intent#ACTION_PROVIDER_CHANGED} broadcast intents to indicate if the
     95      * receiving package made this change.
     96      */
     97     public static final String EXTRA_SELF_CHANGE = "com.android.voicemail.extra.SELF_CHANGE";
     98 
     99     /**
    100      * Name of the source package field, which must be same across all voicemail related tables.
    101      * This is an internal field.
    102      * @hide
    103      */
    104     public static final String SOURCE_PACKAGE_FIELD = "source_package";
    105 
    106     /** Defines fields exposed through the /voicemail path of this content provider. */
    107     public static final class Voicemails implements BaseColumns, OpenableColumns {
    108         /** Not instantiable. */
    109         private Voicemails() {
    110         }
    111 
    112         /** URI to insert/retrieve voicemails. */
    113         public static final Uri CONTENT_URI =
    114             Uri.parse("content://" + AUTHORITY + "/voicemail");
    115 
    116         /** The MIME type for a collection of voicemails. */
    117         public static final String DIR_TYPE = "vnd.android.cursor.dir/voicemails";
    118 
    119         /** The MIME type for a single voicemail. */
    120         public static final String ITEM_TYPE = "vnd.android.cursor.item/voicemail";
    121 
    122         /**
    123          * Phone number of the voicemail sender.
    124          * <P>Type: TEXT</P>
    125          */
    126         public static final String NUMBER = Calls.NUMBER;
    127         /**
    128          * The date the voicemail was sent, in milliseconds since the epoch
    129          * <P>Type: INTEGER (long)</P>
    130          */
    131         public static final String DATE = Calls.DATE;
    132         /**
    133          * The duration of the voicemail in seconds.
    134          * <P>Type: INTEGER (long)</P>
    135          */
    136         public static final String DURATION = Calls.DURATION;
    137         /**
    138          * Whether this item has been read or otherwise consumed by the user.
    139          * <P>Type: INTEGER (boolean)</P>
    140          */
    141         public static final String IS_READ = Calls.IS_READ;
    142         /**
    143          * The mail box state of the voicemail. This field is currently not used by the system.
    144          * <P> Possible values: {@link #STATE_INBOX}, {@link #STATE_DELETED},
    145          * {@link #STATE_UNDELETED}.
    146          * <P>Type: INTEGER</P>
    147          * @hide
    148          */
    149         public static final String STATE = "state";
    150         /**
    151          * Value of {@link #STATE} when the voicemail is in inbox.
    152          * @hide
    153          */
    154         public static int STATE_INBOX = 0;
    155         /**
    156          * Value of {@link #STATE} when the voicemail has been marked as deleted.
    157          * @hide
    158          */
    159         public static int STATE_DELETED = 1;
    160         /**
    161          * Value of {@link #STATE} when the voicemail has marked as undeleted.
    162          * @hide
    163          */
    164         public static int STATE_UNDELETED = 2;
    165         /**
    166          * Package name of the source application that inserted the voicemail.
    167          * <P>Type: TEXT</P>
    168          */
    169         public static final String SOURCE_PACKAGE = SOURCE_PACKAGE_FIELD;
    170         /**
    171          * Application-specific data available to the source application that
    172          * inserted the voicemail. This is typically used to store the source
    173          * specific message id to identify this voicemail on the remote
    174          * voicemail server.
    175          * <P>Type: TEXT</P>
    176          * <P> Note that this is NOT the voicemail media content data.
    177          */
    178         public static final String SOURCE_DATA = "source_data";
    179         /**
    180          * Whether the media content for this voicemail is available for
    181          * consumption.
    182          * <P>Type: INTEGER (boolean)</P>
    183          */
    184         public static final String HAS_CONTENT = "has_content";
    185         /**
    186          * MIME type of the media content for the voicemail.
    187          * <P>Type: TEXT</P>
    188          */
    189         public static final String MIME_TYPE = "mime_type";
    190         /**
    191          * The transcription of the voicemail entry. This will only be populated if the voicemail
    192          * entry has a valid transcription.
    193          * <P>Type: TEXT</P>
    194          */
    195         public static final String TRANSCRIPTION = "transcription";
    196         /**
    197          * Path to the media content file. Internal only field.
    198          * @hide
    199          */
    200         public static final String _DATA = "_data";
    201 
    202         /**
    203          * A convenience method to build voicemail URI specific to a source package by appending
    204          * {@link VoicemailContract#PARAM_KEY_SOURCE_PACKAGE} param to the base URI.
    205          */
    206         public static Uri buildSourceUri(String packageName) {
    207             return Voicemails.CONTENT_URI.buildUpon()
    208                     .appendQueryParameter(PARAM_KEY_SOURCE_PACKAGE, packageName).build();
    209         }
    210     }
    211 
    212     /** Defines fields exposed through the /status path of this content provider. */
    213     public static final class Status implements BaseColumns {
    214         /** URI to insert/retrieve status of voicemail source. */
    215         public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/status");
    216         /** The MIME type for a collection of voicemail source statuses. */
    217         public static final String DIR_TYPE = "vnd.android.cursor.dir/voicemail.source.status";
    218         /** The MIME type for a single voicemail source status entry. */
    219         public static final String ITEM_TYPE = "vnd.android.cursor.item/voicemail.source.status";
    220 
    221         /** Not instantiable. */
    222         private Status() {
    223         }
    224         /**
    225          * The package name of the voicemail source. There can only be a one entry per source.
    226          * <P>Type: TEXT</P>
    227          */
    228         public static final String SOURCE_PACKAGE = SOURCE_PACKAGE_FIELD;
    229         /**
    230          * The URI to call to invoke source specific voicemail settings screen. On a user request
    231          * to setup voicemail an intent with action VIEW with this URI will be fired by the system.
    232          * <P>Type: TEXT</P>
    233          */
    234         public static final String SETTINGS_URI = "settings_uri";
    235         /**
    236          * The URI to call when the user requests to directly access the voicemail from the remote
    237          * server. In case of an IVR voicemail system this is typically set to the the voicemail
    238          * number specified using a tel:/ URI.
    239          * <P>Type: TEXT</P>
    240          */
    241         public static final String VOICEMAIL_ACCESS_URI = "voicemail_access_uri";
    242         /**
    243          * The configuration state of the voicemail source.
    244          * <P> Possible values:
    245          * {@link #CONFIGURATION_STATE_OK},
    246          * {@link #CONFIGURATION_STATE_NOT_CONFIGURED},
    247          * {@link #CONFIGURATION_STATE_CAN_BE_CONFIGURED}
    248          * <P>Type: INTEGER</P>
    249          */
    250         public static final String CONFIGURATION_STATE = "configuration_state";
    251         /** Value of {@link #CONFIGURATION_STATE} to indicate an all OK configuration status. */
    252         public static final int CONFIGURATION_STATE_OK = 0;
    253         /**
    254          * Value of {@link #CONFIGURATION_STATE} to indicate the visual voicemail is not
    255          * yet configured on this device.
    256          */
    257         public static final int CONFIGURATION_STATE_NOT_CONFIGURED = 1;
    258         /**
    259          * Value of {@link #CONFIGURATION_STATE} to indicate the visual voicemail is not
    260          * yet configured on this device but can be configured by the user.
    261          * <p> This state must be used when the source has verified that the current user can be
    262          * upgraded to visual voicemail and would like to show a set up invitation message.
    263          */
    264         public static final int CONFIGURATION_STATE_CAN_BE_CONFIGURED = 2;
    265         /**
    266          * The data channel state of the voicemail source. This the channel through which the source
    267          * pulls voicemail data from a remote server.
    268          * <P> Possible values:
    269          * {@link #DATA_CHANNEL_STATE_OK},
    270          * {@link #DATA_CHANNEL_STATE_NO_CONNECTION}
    271          * </P>
    272          * <P>Type: INTEGER</P>
    273          */
    274         public static final String DATA_CHANNEL_STATE = "data_channel_state";
    275         /**
    276          *  Value of {@link #DATA_CHANNEL_STATE} to indicate that data channel is working fine.
    277          */
    278         public static final int DATA_CHANNEL_STATE_OK = 0;
    279         /**
    280          * Value of {@link #DATA_CHANNEL_STATE} to indicate that data channel connection is not
    281          * working.
    282          */
    283         public static final int DATA_CHANNEL_STATE_NO_CONNECTION = 1;
    284         /**
    285          * The notification channel state of the voicemail source. This is the channel through which
    286          * the source gets notified of new voicemails on the remote server.
    287          * <P> Possible values:
    288          * {@link #NOTIFICATION_CHANNEL_STATE_OK},
    289          * {@link #NOTIFICATION_CHANNEL_STATE_NO_CONNECTION},
    290          * {@link #NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING}
    291          * </P>
    292          * <P>Type: INTEGER</P>
    293          */
    294         public static final String NOTIFICATION_CHANNEL_STATE = "notification_channel_state";
    295         /**
    296          * Value of {@link #NOTIFICATION_CHANNEL_STATE} to indicate that the notification channel is
    297          * working fine.
    298          */
    299         public static final int NOTIFICATION_CHANNEL_STATE_OK = 0;
    300         /**
    301          * Value of {@link #NOTIFICATION_CHANNEL_STATE} to indicate that the notification channel
    302          * connection is not working.
    303          */
    304         public static final int NOTIFICATION_CHANNEL_STATE_NO_CONNECTION = 1;
    305         /**
    306          * Value of {@link #NOTIFICATION_CHANNEL_STATE} to indicate that there are messages waiting
    307          * on the server but the details are not known.
    308          * <p> Use this state when the notification can only tell that there are pending messages on
    309          * the server but no details of the sender/time etc are known.
    310          */
    311         public static final int NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING = 2;
    312 
    313         /**
    314          * A convenience method to build status URI specific to a source package by appending
    315          * {@link VoicemailContract#PARAM_KEY_SOURCE_PACKAGE} param to the base URI.
    316          */
    317         public static Uri buildSourceUri(String packageName) {
    318             return Status.CONTENT_URI.buildUpon()
    319                     .appendQueryParameter(PARAM_KEY_SOURCE_PACKAGE, packageName).build();
    320         }
    321     }
    322 }
    323