ImsConfig.java revision f31e6fc36deb4447ff7c2041378dcff9e33865b9
1/*
2 * Copyright (c) 2014 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 com.android.ims;
18
19import android.content.Context;
20import android.os.RemoteException;
21import android.telephony.Rlog;
22
23import com.android.ims.ImsConfigListener;
24import com.android.ims.ImsReasonInfo;
25import com.android.ims.internal.IImsConfig;
26/**
27 * Provides APIs to get/set the IMS service feature/capability/parameters.
28 * The config items include:
29 * 1) Items provisioned by the operator.
30 * 2) Items configured by user. Mainly service feature class.
31 *
32 * @hide
33 */
34public class ImsConfig {
35    private static final String TAG = "ImsConfig";
36    private boolean DBG = true;
37    private final IImsConfig miConfig;
38    private Context mContext;
39    private static final String MODIFY_PHONE_STATE = android.Manifest.permission.MODIFY_PHONE_STATE;
40
41    /**
42    * Defines IMS service/capability feature constants.
43    */
44    public static class FeatureConstants {
45        public static final int FEATURE_TYPE_UNKNOWN = -1;
46
47        /**
48         * FEATURE_TYPE_VOLTE supports features defined in 3GPP and
49         * GSMA IR.92 over LTE.
50         */
51        public static final int FEATURE_TYPE_VOICE_OVER_LTE = 0;
52
53        /**
54         * FEATURE_TYPE_LVC supports features defined in 3GPP and
55         * GSMA IR.94 over LTE.
56         */
57        public static final int FEATURE_TYPE_VIDEO_OVER_LTE = 1;
58
59        /**
60         * FEATURE_TYPE_VOICE_OVER_WIFI supports features defined in 3GPP and
61         * GSMA IR.92 over WiFi.
62         */
63        public static final int FEATURE_TYPE_VOICE_OVER_WIFI = 2;
64
65        /**
66         * FEATURE_TYPE_VIDEO_OVER_WIFI supports features defined in 3GPP and
67         * GSMA IR.94 over WiFi.
68         */
69        public static final int FEATURE_TYPE_VIDEO_OVER_WIFI = 3;
70    }
71
72    /**
73    * Defines IMS service/capability parameters.
74    */
75    public static class ConfigConstants {
76
77        // Define IMS config items
78        public static final int CONFIG_START = 0;
79
80        // Define operator provisioned config items
81        public static final int PROVISIONED_CONFIG_START = CONFIG_START;
82
83        /**
84         * AMR CODEC Mode Value set, 0-7 in comma separated sequence.
85         * Value is in String format.
86         */
87        public static final int VOCODER_AMRMODESET = CONFIG_START;
88
89        /**
90         * Wide Band AMR CODEC Mode Value set,0-7 in comma separated sequence.
91         * Value is in String format.
92         */
93        public static final int VOCODER_AMRWBMODESET = 1;
94
95        /**
96         * SIP Session Timer value (seconds).
97         * Value is in Integer format.
98         */
99        public static final int SIP_SESSION_TIMER = 2;
100
101        /**
102         * Minimum SIP Session Expiration Timer in (seconds).
103         * Value is in Integer format.
104         */
105        public static final int MIN_SE = 3;
106
107        /**
108         * SIP_INVITE cancellation time out value (in milliseconds). Integer format.
109         * Value is in Integer format.
110         */
111        public static final int CANCELLATION_TIMER = 4;
112
113        /**
114         * Delay time when an iRAT transition from eHRPD/HRPD/1xRTT to LTE.
115         * Value is in Integer format.
116         */
117        public static final int TDELAY = 5;
118
119        /**
120         * Silent redial status of Enabled (True), or Disabled (False).
121         * Value is in Integer format.
122         */
123        public static final int SILENT_REDIAL_ENABLE = 6;
124
125        /**
126         * SIP T1 timer value in milliseconds. See RFC 3261 for define.
127         * Value is in Integer format.
128         */
129        public static final int SIP_T1_TIMER = 7;
130
131        /**
132         * SIP T2 timer value in milliseconds.  See RFC 3261 for define.
133         * Value is in Integer format.
134         */
135        public static final int SIP_T2_TIMER  = 8;
136
137         /**
138         * SIP TF timer value in milliseconds.  See RFC 3261 for define.
139         * Value is in Integer format.
140         */
141        public static final int SIP_TF_TIMER = 9;
142
143        /**
144         * VoLTE status for VLT/s status of Enabled (1), or Disabled (0).
145         * Value is in Integer format.
146         */
147        public static final int VLT_SETTING_ENABLED = 10;
148
149        /**
150         * VoLTE status for LVC/s status of Enabled (1), or Disabled (0).
151         * Value is in Integer format.
152         */
153        public static final int LVC_SETTING_ENABLED = 11;
154        /**
155         * Domain Name for the device to populate the request URI for REGISTRATION.
156         * Value is in String format.
157         */
158        public static final int DOMAIN_NAME = 12;
159         /**
160         * Device Outgoing SMS based on either 3GPP or 3GPP2 standards.
161         * Value is in Integer format. 3GPP2(0), 3GPP(1)
162         */
163        public static final int SMS_FORMAT = 13;
164         /**
165         * Turns IMS ON/OFF on the device.
166         * Value is in Integer format. ON (1), OFF(0).
167         */
168        public static final int SMS_OVER_IP = 14;
169        /**
170         * Requested expiration for Published Online availability.
171         * Value is in Integer format.
172         */
173        public static final int PUBLISH_TIMER = 15;
174        /**
175         * Requested expiration for Published Offline availability.
176         * Value is in Integer format.
177         */
178        public static final int PUBLISH_TIMER_EXTENDED = 16;
179        /**
180         * Period of time the capability information of the  contact is cached on handset.
181         * Value is in Integer format.
182         */
183        public static final int CAPABILITIES_CACHE_EXPIRATION = 17;
184        /**
185         * Peiod of time the availability information of a contact is cached on device.
186         * Value is in Integer format.
187         */
188        public static final int AVAILABILITY_CACHE_EXPIRATION = 18;
189        /**
190         * Interval between successive capabilities polling.
191         * Value is in Integer format.
192         */
193        public static final int CAPABILITIES_POLL_INTERVAL = 19;
194        /**
195         * Minimum time between two published messages from the device.
196         * Value is in Integer format.
197         */
198        public static final int SOURCE_THROTTLE_PUBLISH = 20;
199        /**
200         * The Maximum number of MDNs contained in one Request Contained List.
201         * Value is in Integer format.
202         */
203        public static final int MAX_NUMENTRIES_IN_RCL = 21;
204        /**
205         * Expiration timer for subscription of a Request Contained List, used in capability polling.
206         * Value is in Integer format.
207         */
208        public static final int CAPAB_POLL_LIST_SUB_EXP = 22;
209        /**
210         * Applies compression to LIST Subscription.
211         * Value is in Integer format. Enable (1), Disable(0).
212         */
213        public static final int GZIP_FLAG = 23;
214        /**
215         * VOLTE Status for EAB/s status of Enabled (1), or Disabled (0).
216         * Value is in Integer format.
217         */
218        public static final int EAB_SETTING_ENABLED = 24;
219        /**
220         * Wi-Fi calling roaming status.
221         * Value is in Integer format. ON (1), OFF(0).
222         */
223        public static final int VOICE_OVER_WIFI_ROAMING = 25;
224        /**
225         * Wi-Fi calling modem - WfcModeFeatureValueConstants.
226         * Value is in Integer format.
227         */
228        public static final int VOICE_OVER_WIFI_MODE = 26;
229
230        // Expand the operator config items as needed here, need to change
231        // PROVISIONED_CONFIG_END after that.
232        public static final int PROVISIONED_CONFIG_END = VOICE_OVER_WIFI_MODE;
233
234        // Expand the operator config items as needed here.
235    }
236
237    /**
238    * Defines IMS set operation status.
239    */
240    public static class OperationStatusConstants {
241        public static final int UNKNOWN = -1;
242        public static final int SUCCESS = 0;
243        public static final int FAILED =  1;
244        public static final int UNSUPPORTED_CAUSE_NONE = 2;
245        public static final int UNSUPPORTED_CAUSE_RAT = 3;
246        public static final int UNSUPPORTED_CAUSE_DISABLED = 4;
247    }
248
249   /**
250    * Defines IMS feature value.
251    */
252    public static class FeatureValueConstants {
253        public static final int OFF = 0;
254        public static final int ON = 1;
255    }
256
257    /**
258     * Defines IMS feature value.
259     */
260    public static class WfcModeFeatureValueConstants {
261        public static final int WIFI_ONLY = 0;
262        public static final int CELLULAR_PREFERRED = 1;
263        public static final int WIFI_PREFERRED = 2;
264    }
265
266    public ImsConfig(IImsConfig iconfig, Context context) {
267        if (DBG) Rlog.d(TAG, "ImsConfig creates");
268        miConfig = iconfig;
269        mContext = context;
270    }
271
272    /**
273     * Gets the provisioned value for IMS service/capabilities parameters used by IMS stack.
274     * This function should not be called from the mainthread as it could block the
275     * mainthread.
276     *
277     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
278     * @return the value in Integer format.
279     *
280     * @throws ImsException if calling the IMS service results in an error.
281     */
282    public int getProvisionedValue(int item) throws ImsException {
283        int ret = 0;
284        try {
285            ret = miConfig.getProvisionedValue(item);
286        }  catch (RemoteException e) {
287            throw new ImsException("getValue()", e,
288                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
289        }
290        if (DBG) Rlog.d(TAG, "getProvisionedValue(): item = " + item + ", ret =" + ret);
291
292        return ret;
293    }
294
295    /**
296     * Gets the provisioned value for IMS service/capabilities parameters used by IMS stack.
297     * This function should not be called from the mainthread as it could block the
298     * mainthread.
299     *
300     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
301     * @return value in String format.
302     *
303     * @throws ImsException if calling the IMS service results in an error.
304     */
305    public String getProvisionedStringValue(int item) throws ImsException {
306        String ret = "Unknown";
307        try {
308            ret = miConfig.getProvisionedStringValue(item);
309        }  catch (RemoteException e) {
310            throw new ImsException("getProvisionedStringValue()", e,
311                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
312        }
313        if (DBG) Rlog.d(TAG, "getProvisionedStringValue(): item = " + item + ", ret =" + ret);
314
315        return ret;
316    }
317
318    /**
319     * Sets the value for IMS service/capabilities parameters by
320     * the operator device management entity.
321     * This function should not be called from main thread as it could block
322     * mainthread.
323     *
324     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
325     * @param value in Integer format.
326     * @return as defined in com.android.ims.ImsConfig#OperationStatusConstants
327     *
328     * @throws ImsException if calling the IMS service results in an error.
329     */
330    public int setProvisionedValue(int item, int value)
331            throws ImsException {
332        mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
333        int ret = ImsConfig.OperationStatusConstants.UNKNOWN;
334        if (DBG) {
335            Rlog.d(TAG, "setProvisionedValue(): item = " + item +
336                    "value = " + value);
337        }
338        try {
339            ret = miConfig.setProvisionedValue(item, value);
340        }  catch (RemoteException e) {
341            throw new ImsException("setProvisionedValue()", e,
342                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
343        }
344        if (DBG) {
345            Rlog.d(TAG, "setProvisionedValue(): item = " + item +
346                    " value = " + value + " ret = " + ret);
347        }
348        return ret;
349    }
350
351    /**
352     * Sets the value for IMS service/capabilities parameters by
353     * the operator device management entity.
354     * This function should not be called from main thread as it could block
355     * mainthread.
356     *
357     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
358     * @param value in String format.
359     * @return as defined in com.android.ims.ImsConfig#OperationStatusConstants
360     *
361     * @throws ImsException if calling the IMS service results in an error.
362     */
363    public int setProvisionedStringValue(int item, String value)
364            throws ImsException {
365        mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
366        int ret = ImsConfig.OperationStatusConstants.UNKNOWN;
367        try {
368            ret = miConfig.setProvisionedStringValue(item, value);
369        }  catch (RemoteException e) {
370            throw new ImsException("setProvisionedStringValue()", e,
371                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
372        }
373        if (DBG) {
374            Rlog.d(TAG, "setProvisionedStringValue(): item = " + item +
375                    ", value =" + value);
376        }
377        return ret;
378    }
379
380    /**
381     * Gets the value for IMS feature item for specified network type.
382     *
383     * @param feature, defined as in FeatureConstants.
384     * @param network, defined as in android.telephony.TelephonyManager#NETWORK_TYPE_XXX.
385     * @param listener, provided to be notified for the feature on/off status.
386     * @return void
387     *
388     * @throws ImsException if calling the IMS service results in an error.
389     */
390    public void getFeatureValue(int feature, int network,
391            ImsConfigListener listener) throws ImsException {
392        if (DBG) {
393            Rlog.d(TAG, "getFeatureValue: feature = " + feature + ", network =" + network +
394                    ", listener =" + listener);
395        }
396        try {
397            miConfig.getFeatureValue(feature, network, listener);
398        } catch (RemoteException e) {
399            throw new ImsException("getFeatureValue()", e,
400                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
401        }
402    }
403
404    /**
405     * Sets the value for IMS feature item for specified network type.
406     *
407     * @param feature, as defined in FeatureConstants.
408     * @param network, as defined in android.telephony.TelephonyManager#NETWORK_TYPE_XXX.
409     * @param value, as defined in FeatureValueConstants.
410     * @param listener, provided if caller needs to be notified for set result.
411     * @return void
412     *
413     * @throws ImsException if calling the IMS service results in an error.
414     */
415    public void setFeatureValue(int feature, int network, int value,
416            ImsConfigListener listener) throws ImsException {
417        mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
418        if (DBG) {
419            Rlog.d(TAG, "setFeatureValue: feature = " + feature + ", network =" + network +
420                    ", value =" + value + ", listener =" + listener);
421        }
422        try {
423            miConfig.setFeatureValue(feature, network, value, listener);
424        } catch (RemoteException e) {
425            throw new ImsException("setFeatureValue()", e,
426                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
427        }
428    }
429
430    /**
431     * Gets the value for IMS Volte provisioned.
432     * It should be the same as operator provisioned value if applies.
433     *
434     * @return boolean
435     *
436     * @throws ImsException if calling the IMS service results in an error.
437     */
438    public boolean getVolteProvisioned() throws ImsException {
439        try {
440           return miConfig.getVolteProvisioned();
441        } catch (RemoteException e) {
442            throw new ImsException("getVolteProvisioned()", e,
443                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
444        }
445    }
446}
447