VoicemailContract.java revision 31b594e129e0fc5840be66ef539c0b6b0afe7f90
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 item has been read or otherwise consumed by the user.
127         * <P>Type: INTEGER (boolean)</P>
128         */
129        public static final String IS_READ = Calls.IS_READ;
130        /**
131         * The mail box state of the voicemail. This field is currently not used by the system.
132         * <P> Possible values: {@link #STATE_INBOX}, {@link #STATE_DELETED},
133         * {@link #STATE_UNDELETED}.
134         * <P>Type: INTEGER</P>
135         * @hide
136         */
137        public static final String STATE = "state";
138        /**
139         * Value of {@link #STATE} when the voicemail is in inbox.
140         * @hide
141         */
142        public static int STATE_INBOX = 0;
143        /**
144         * Value of {@link #STATE} when the voicemail has been marked as deleted.
145         * @hide
146         */
147        public static int STATE_DELETED = 1;
148        /**
149         * Value of {@link #STATE} when the voicemail has marked as undeleted.
150         * @hide
151         */
152        public static int STATE_UNDELETED = 2;
153        /**
154         * Package name of the source application that inserted the voicemail.
155         * <P>Type: TEXT</P>
156         */
157        public static final String SOURCE_PACKAGE = SOURCE_PACKAGE_FIELD;
158        /**
159         * Application-specific data available to the source application that
160         * inserted the voicemail. This is typically used to store the source
161         * specific message id to identify this voicemail on the remote
162         * voicemail server.
163         * <P>Type: TEXT</P>
164         * <P> Note that this is NOT the voicemail media content data.
165         */
166        public static final String SOURCE_DATA = "source_data";
167        /**
168         * Whether the media content for this voicemail is available for
169         * consumption.
170         * <P>Type: INTEGER (boolean)</P>
171         */
172        public static final String HAS_CONTENT = "has_content";
173        /**
174         * MIME type of the media content for the voicemail.
175         * <P>Type: TEXT</P>
176         */
177        public static final String MIME_TYPE = "mime_type";
178        /**
179         * Path to the media content file. Internal only field.
180         * @hide
181         */
182        public static final String _DATA = "_data";
183
184        /**
185         * A convenience method to build voicemail URI specific to a source package by appending
186         * {@link VoicemailContract#PARAM_KEY_SOURCE_PACKAGE} param to the base URI.
187         */
188        public static Uri buildSourceUri(String packageName) {
189            return Voicemails.CONTENT_URI.buildUpon()
190                    .appendQueryParameter(PARAM_KEY_SOURCE_PACKAGE, packageName).build();
191        }
192    }
193
194    /** Defines fields exposed through the /status path of this content provider. */
195    public static final class Status implements BaseColumns {
196        /** URI to insert/retrieve status of voicemail source. */
197        public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/status");
198        /** The MIME type for a collection of voicemail source statuses. */
199        public static final String DIR_TYPE = "vnd.android.cursor.dir/voicemail.source.status";
200        /** The MIME type for a single voicemail source status entry. */
201        public static final String ITEM_TYPE = "vnd.android.cursor.item/voicemail.source.status";
202
203        /** Not instantiable. */
204        private Status() {
205        }
206        /**
207         * The package name of the voicemail source. There can only be a one entry per source.
208         * <P>Type: TEXT</P>
209         */
210        public static final String SOURCE_PACKAGE = SOURCE_PACKAGE_FIELD;
211        /**
212         * The URI to call to invoke source specific voicemail settings screen. On a user request
213         * to setup voicemail an intent with action VIEW with this URI will be fired by the system.
214         * <P>Type: TEXT</P>
215         */
216        public static final String SETTINGS_URI = "settings_uri";
217        /**
218         * The URI to call when the user requests to directly access the voicemail from the remote
219         * server. In case of an IVR voicemail system this is typically set to the the voicemail
220         * number specified using a tel:/ URI.
221         * <P>Type: TEXT</P>
222         */
223        public static final String VOICEMAIL_ACCESS_URI = "voicemail_access_uri";
224        /**
225         * The configuration state of the voicemail source.
226         * <P> Possible values:
227         * {@link #CONFIGURATION_STATE_OK},
228         * {@link #CONFIGURATION_STATE_NOT_CONFIGURED},
229         * {@link #CONFIGURATION_STATE_CAN_BE_CONFIGURED}
230         * <P>Type: INTEGER</P>
231         */
232        public static final String CONFIGURATION_STATE = "configuration_state";
233        /** Value of {@link #CONFIGURATION_STATE} to indicate an all OK configuration status. */
234        public static final int CONFIGURATION_STATE_OK = 0;
235        /**
236         * Value of {@link #CONFIGURATION_STATE} to indicate the visual voicemail is not
237         * yet configured on this device.
238         */
239        public static final int CONFIGURATION_STATE_NOT_CONFIGURED = 1;
240        /**
241         * Value of {@link #CONFIGURATION_STATE} to indicate the visual voicemail is not
242         * yet configured on this device but can be configured by the user.
243         * <p> This state must be used when the source has verified that the current user can be
244         * upgraded to visual voicemail and would like to show a set up invitation message.
245         */
246        public static final int CONFIGURATION_STATE_CAN_BE_CONFIGURED = 2;
247        /**
248         * The data channel state of the voicemail source. This the channel through which the source
249         * pulls voicemail data from a remote server.
250         * <P> Possible values:
251         * {@link #DATA_CHANNEL_STATE_OK},
252         * {@link #DATA_CHANNEL_STATE_NO_CONNECTION}
253         * </P>
254         * <P>Type: INTEGER</P>
255         */
256        public static final String DATA_CHANNEL_STATE = "data_channel_state";
257        /**
258         *  Value of {@link #DATA_CHANNEL_STATE} to indicate that data channel is working fine.
259         */
260        public static final int DATA_CHANNEL_STATE_OK = 0;
261        /**
262         * Value of {@link #DATA_CHANNEL_STATE} to indicate that data channel connection is not
263         * working.
264         */
265        public static final int DATA_CHANNEL_STATE_NO_CONNECTION = 1;
266        /**
267         * The notification channel state of the voicemail source. This is the channel through which
268         * the source gets notified of new voicemails on the remote server.
269         * <P> Possible values:
270         * {@link #NOTIFICATION_CHANNEL_STATE_OK},
271         * {@link #NOTIFICATION_CHANNEL_STATE_NO_CONNECTION},
272         * {@link #NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING}
273         * </P>
274         * <P>Type: INTEGER</P>
275         */
276        public static final String NOTIFICATION_CHANNEL_STATE = "notification_channel_state";
277        /**
278         * Value of {@link #NOTIFICATION_CHANNEL_STATE} to indicate that the notification channel is
279         * working fine.
280         */
281        public static final int NOTIFICATION_CHANNEL_STATE_OK = 0;
282        /**
283         * Value of {@link #NOTIFICATION_CHANNEL_STATE} to indicate that the notification channel
284         * connection is not working.
285         */
286        public static final int NOTIFICATION_CHANNEL_STATE_NO_CONNECTION = 1;
287        /**
288         * Value of {@link #NOTIFICATION_CHANNEL_STATE} to indicate that there are messages waiting
289         * on the server but the details are not known.
290         * <p> Use this state when the notification can only tell that there are pending messages on
291         * the server but no details of the sender/time etc are known.
292         */
293        public static final int NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING = 2;
294
295        /**
296         * A convenience method to build status URI specific to a source package by appending
297         * {@link VoicemailContract#PARAM_KEY_SOURCE_PACKAGE} param to the base URI.
298         */
299        public static Uri buildSourceUri(String packageName) {
300            return Status.CONTENT_URI.buildUpon()
301                    .appendQueryParameter(PARAM_KEY_SOURCE_PACKAGE, packageName).build();
302        }
303    }
304}
305