VoicemailContract.java revision 651212d37db9aa6d03b30a8a09a2a44627862eea
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
17package android.provider;
18
19import android.Manifest;
20import android.annotation.SdkConstant;
21import android.annotation.SdkConstant.SdkConstantType;
22import android.content.Intent;
23import android.database.ContentObserver;
24import android.net.Uri;
25import 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#READ_WRITE_OWN_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 */
65public 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     * Extra included in {@link Intent#ACTION_PROVIDER_CHANGED} broadcast intents to indicate if the
83     * receiving package made this change.
84     */
85    public static final String EXTRA_SELF_CHANGE = "com.android.voicemail.extra.SELF_CHANGE";
86
87    /**
88     * Name of the source package field, which must be same across all voicemail related tables.
89     * This is an internal field.
90     * @hide
91     */
92    public static final String SOURCE_PACKAGE_FIELD = "source_package";
93
94    /** Defines fields exposed through the /voicemail path of this content provider. */
95    public static final class Voicemails implements BaseColumns {
96        /** Not instantiable. */
97        private Voicemails() {
98        }
99
100        /** URI to insert/retrieve voicemails. */
101        public static final Uri CONTENT_URI =
102            Uri.parse("content://" + AUTHORITY + "/voicemail");
103
104        /** The MIME type for a collection of voicemails. */
105        public static final String DIR_TYPE = "vnd.android.cursor.dir/voicemails";
106
107        /** The MIME type for a single voicemail. */
108        public static final String ITEM_TYPE = "vnd.android.cursor.item/voicemail";
109
110        /**
111         * Phone number of the voicemail sender.
112         * <P>Type: TEXT</P>
113         */
114        public static final String NUMBER = Calls.NUMBER;
115        /**
116         * The date the voicemail was sent, in milliseconds since the epoch
117         * <P>Type: INTEGER (long)</P>
118         */
119        public static final String DATE = Calls.DATE;
120        /**
121         * The duration of the voicemail in seconds.
122         * <P>Type: INTEGER (long)</P>
123         */
124        public static final String DURATION = Calls.DURATION;
125        /**
126         * Whether this is a new voicemail (i.e. has not been heard).
127         * <P>Type: INTEGER (boolean)</P>
128         */
129        public static final String NEW = Calls.NEW;
130        /**
131         * Whether this item has been read or otherwise consumed by the user.
132         * <P>Type: INTEGER (boolean)</P>
133         * @hide
134         */
135        public static final String IS_READ = Calls.IS_READ;
136        /**
137         * The mail box state of the voicemail. This field is currently not used by the system.
138         * <P> Possible values: {@link #STATE_INBOX}, {@link #STATE_DELETED},
139         * {@link #STATE_UNDELETED}.
140         * <P>Type: INTEGER</P>
141         * @hide
142         */
143        public static final String STATE = "state";
144        /**
145         * Value of {@link #STATE} when the voicemail is in inbox.
146         * @hide
147         */
148        public static int STATE_INBOX = 0;
149        /**
150         * Value of {@link #STATE} when the voicemail has been marked as deleted.
151         * @hide
152         */
153        public static int STATE_DELETED = 1;
154        /**
155         * Value of {@link #STATE} when the voicemail has marked as undeleted.
156         * @hide
157         */
158        public static int STATE_UNDELETED = 2;
159        /**
160         * Package name of the source application that inserted the voicemail.
161         * <P>Type: TEXT</P>
162         */
163        public static final String SOURCE_PACKAGE = SOURCE_PACKAGE_FIELD;
164        /**
165         * Application-specific data available to the source application that
166         * inserted the voicemail. This is typically used to store the source
167         * specific message id to identify this voicemail on the remote
168         * voicemail server.
169         * <P>Type: TEXT</P>
170         * <P> Note that this is NOT the voicemail media content data.
171         */
172        public static final String SOURCE_DATA = "source_data";
173        /**
174         * Whether the media content for this voicemail is available for
175         * consumption.
176         * <P>Type: INTEGER (boolean)</P>
177         */
178        public static final String HAS_CONTENT = "has_content";
179        /**
180         * MIME type of the media content for the voicemail.
181         * <P>Type: TEXT</P>
182         */
183        public static final String MIME_TYPE = "mime_type";
184        /**
185         * Path to the media content file. Internal only field.
186         * @hide
187         */
188        public static final String _DATA = "_data";
189
190        /**
191         * A convenience method to build voicemail URI specific to a source package by appending
192         * {@link VoicemailContract#PARAM_KEY_SOURCE_PACKAGE} param to the base URI.
193         */
194        public static Uri buildSourceUri(String packageName) {
195            return Voicemails.CONTENT_URI.buildUpon()
196                    .appendQueryParameter(PARAM_KEY_SOURCE_PACKAGE, packageName).build();
197        }
198    }
199
200    /** Defines fields exposed through the /status path of this content provider. */
201    public static final class Status implements BaseColumns {
202        /** URI to insert/retrieve status of voicemail source. */
203        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/status");
204        /** The MIME type for a collection of voicemail source statuses. */
205        public static final String DIR_TYPE = "vnd.android.cursor.dir/voicemail.source.status";
206        /** The MIME type for a single voicemail source status entry. */
207        public static final String ITEM_TYPE = "vnd.android.cursor.item/voicemail.source.status";
208
209        /** Not instantiable. */
210        private Status() {
211        }
212        /**
213         * The package name of the voicemail source. There can only be a one entry per source.
214         * <P>Type: TEXT</P>
215         */
216        public static final String SOURCE_PACKAGE = SOURCE_PACKAGE_FIELD;
217        /**
218         * The URI to call to invoke source specific voicemail settings screen. On a user request
219         * to setup voicemail an intent with action VIEW with this URI will be fired by the system.
220         * <P>Type: TEXT</P>
221         */
222        public static final String SETTINGS_URI = "settings_uri";
223        /**
224         * The URI to call when the user requests to directly access the voicemail from the remote
225         * server. In case of an IVR voicemail system this is typically set to the the voicemail
226         * number specified using a tel:/ URI.
227         * <P>Type: TEXT</P>
228         */
229        public static final String VOICEMAIL_ACCESS_URI = "voicemail_access_uri";
230        /**
231         * The configuration state of the voicemail source.
232         * <P> Possible values:
233         * {@link #CONFIGURATION_STATE_OK},
234         * {@link #CONFIGURATION_STATE_NOT_CONFIGURED},
235         * {@link #CONFIGURATION_STATE_CAN_BE_CONFIGURED}
236         * <P>Type: INTEGER</P>
237         */
238        public static final String CONFIGURATION_STATE = "configuration_state";
239        /** Value of {@link #CONFIGURATION_STATE} to indicate an all OK configuration status. */
240        public static final int CONFIGURATION_STATE_OK = 0;
241        /**
242         * Value of {@link #CONFIGURATION_STATE} to indicate the visual voicemail is not
243         * yet configured on this device.
244         */
245        public static final int CONFIGURATION_STATE_NOT_CONFIGURED = 1;
246        /**
247         * Value of {@link #CONFIGURATION_STATE} to indicate the visual voicemail is not
248         * yet configured on this device but can be configured by the user.
249         * <p> This state must be used when the source has verified that the current user can be
250         * upgraded to visual voicemail and would like to show a set up invitation message.
251         */
252        public static final int CONFIGURATION_STATE_CAN_BE_CONFIGURED = 2;
253        /**
254         * The data channel state of the voicemail source. This the channel through which the source
255         * pulls voicemail data from a remote server.
256         * <P> Possible values:
257         * {@link #DATA_CHANNEL_STATE_OK},
258         * {@link #DATA_CHANNEL_STATE_NO_CONNECTION}
259         * </P>
260         * <P>Type: INTEGER</P>
261         */
262        public static final String DATA_CHANNEL_STATE = "data_channel_state";
263        /**
264         *  Value of {@link #DATA_CHANNEL_STATE} to indicate that data channel is working fine.
265         */
266        public static final int DATA_CHANNEL_STATE_OK = 0;
267        /**
268         * Value of {@link #DATA_CHANNEL_STATE} to indicate that data channel connection is not
269         * working.
270         */
271        public static final int DATA_CHANNEL_STATE_NO_CONNECTION = 1;
272        /**
273         * The notification channel state of the voicemail source. This is the channel through which
274         * the source gets notified of new voicemails on the remote server.
275         * <P> Possible values:
276         * {@link #NOTIFICATION_CHANNEL_STATE_OK},
277         * {@link #NOTIFICATION_CHANNEL_STATE_NO_CONNECTION},
278         * {@link #NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING}
279         * </P>
280         * <P>Type: INTEGER</P>
281         */
282        public static final String NOTIFICATION_CHANNEL_STATE = "notification_channel_state";
283        /**
284         * Value of {@link #NOTIFICATION_CHANNEL_STATE} to indicate that the notification channel is
285         * working fine.
286         */
287        public static final int NOTIFICATION_CHANNEL_STATE_OK = 0;
288        /**
289         * Value of {@link #NOTIFICATION_CHANNEL_STATE} to indicate that the notification channel
290         * connection is not working.
291         */
292        public static final int NOTIFICATION_CHANNEL_STATE_NO_CONNECTION = 1;
293        /**
294         * Value of {@link #NOTIFICATION_CHANNEL_STATE} to indicate that there are messages waiting
295         * on the server but the details are not known.
296         * <p> Use this state when the notification can only tell that there are pending messages on
297         * the server but no details of the sender/time etc are known.
298         */
299        public static final int NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING = 2;
300
301        /**
302         * A convenience method to build status URI specific to a source package by appending
303         * {@link VoicemailContract#PARAM_KEY_SOURCE_PACKAGE} param to the base URI.
304         */
305        public static Uri buildSourceUri(String packageName) {
306            return Status.CONTENT_URI.buildUpon()
307                    .appendQueryParameter(PARAM_KEY_SOURCE_PACKAGE, packageName).build();
308        }
309    }
310}
311