ImsConfig.java revision 5aec2e957365f20b2e75d3b8c7034e3289729b81
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 get operation values.
251     */
252    public static class OperationValuesConstants {
253        /**
254         * Values related to Video Quality
255         */
256        public static final int VIDEO_QUALITY_UNKNOWN = -1;
257        public static final int VIDEO_QUALITY_LOW = 0;
258        public static final int VIDEO_QUALITY_HIGH = 1;
259    }
260
261   /**
262    * Defines IMS feature value.
263    */
264    public static class FeatureValueConstants {
265        public static final int OFF = 0;
266        public static final int ON = 1;
267    }
268
269    /**
270     * Defines IMS feature value.
271     */
272    public static class WfcModeFeatureValueConstants {
273        public static final int WIFI_ONLY = 0;
274        public static final int CELLULAR_PREFERRED = 1;
275        public static final int WIFI_PREFERRED = 2;
276    }
277
278    public ImsConfig(IImsConfig iconfig, Context context) {
279        if (DBG) Rlog.d(TAG, "ImsConfig creates");
280        miConfig = iconfig;
281        mContext = context;
282    }
283
284    /**
285     * Gets the provisioned value for IMS service/capabilities parameters used by IMS stack.
286     * This function should not be called from the mainthread as it could block the
287     * mainthread.
288     *
289     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
290     * @return the value in Integer format.
291     *
292     * @throws ImsException if calling the IMS service results in an error.
293     */
294    public int getProvisionedValue(int item) throws ImsException {
295        int ret = 0;
296        try {
297            ret = miConfig.getProvisionedValue(item);
298        }  catch (RemoteException e) {
299            throw new ImsException("getValue()", e,
300                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
301        }
302        if (DBG) Rlog.d(TAG, "getProvisionedValue(): item = " + item + ", ret =" + ret);
303
304        return ret;
305    }
306
307    /**
308     * Gets the provisioned value for IMS service/capabilities parameters used by IMS stack.
309     * This function should not be called from the mainthread as it could block the
310     * mainthread.
311     *
312     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
313     * @return value in String format.
314     *
315     * @throws ImsException if calling the IMS service results in an error.
316     */
317    public String getProvisionedStringValue(int item) throws ImsException {
318        String ret = "Unknown";
319        try {
320            ret = miConfig.getProvisionedStringValue(item);
321        }  catch (RemoteException e) {
322            throw new ImsException("getProvisionedStringValue()", e,
323                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
324        }
325        if (DBG) Rlog.d(TAG, "getProvisionedStringValue(): item = " + item + ", ret =" + ret);
326
327        return ret;
328    }
329
330    /**
331     * Sets the value for IMS service/capabilities parameters by
332     * the operator device management entity.
333     * This function should not be called from main thread as it could block
334     * mainthread.
335     *
336     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
337     * @param value in Integer format.
338     * @return as defined in com.android.ims.ImsConfig#OperationStatusConstants
339     *
340     * @throws ImsException if calling the IMS service results in an error.
341     */
342    public int setProvisionedValue(int item, int value)
343            throws ImsException {
344        mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
345        int ret = ImsConfig.OperationStatusConstants.UNKNOWN;
346        if (DBG) {
347            Rlog.d(TAG, "setProvisionedValue(): item = " + item +
348                    "value = " + value);
349        }
350        try {
351            ret = miConfig.setProvisionedValue(item, value);
352        }  catch (RemoteException e) {
353            throw new ImsException("setProvisionedValue()", e,
354                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
355        }
356        if (DBG) {
357            Rlog.d(TAG, "setProvisionedValue(): item = " + item +
358                    " value = " + value + " ret = " + ret);
359        }
360        return ret;
361    }
362
363    /**
364     * Sets the value for IMS service/capabilities parameters by
365     * the operator device management entity.
366     * This function should not be called from main thread as it could block
367     * mainthread.
368     *
369     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
370     * @param value in String format.
371     * @return as defined in com.android.ims.ImsConfig#OperationStatusConstants
372     *
373     * @throws ImsException if calling the IMS service results in an error.
374     */
375    public int setProvisionedStringValue(int item, String value)
376            throws ImsException {
377        mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
378        int ret = ImsConfig.OperationStatusConstants.UNKNOWN;
379        try {
380            ret = miConfig.setProvisionedStringValue(item, value);
381        }  catch (RemoteException e) {
382            throw new ImsException("setProvisionedStringValue()", e,
383                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
384        }
385        if (DBG) {
386            Rlog.d(TAG, "setProvisionedStringValue(): item = " + item +
387                    ", value =" + value);
388        }
389        return ret;
390    }
391
392    /**
393     * Gets the value for IMS feature item for specified network type.
394     *
395     * @param feature, defined as in FeatureConstants.
396     * @param network, defined as in android.telephony.TelephonyManager#NETWORK_TYPE_XXX.
397     * @param listener, provided to be notified for the feature on/off status.
398     * @return void
399     *
400     * @throws ImsException if calling the IMS service results in an error.
401     */
402    public void getFeatureValue(int feature, int network,
403            ImsConfigListener listener) throws ImsException {
404        if (DBG) {
405            Rlog.d(TAG, "getFeatureValue: feature = " + feature + ", network =" + network +
406                    ", listener =" + listener);
407        }
408        try {
409            miConfig.getFeatureValue(feature, network, listener);
410        } catch (RemoteException e) {
411            throw new ImsException("getFeatureValue()", e,
412                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
413        }
414    }
415
416    /**
417     * Sets the value for IMS feature item for specified network type.
418     *
419     * @param feature, as defined in FeatureConstants.
420     * @param network, as defined in android.telephony.TelephonyManager#NETWORK_TYPE_XXX.
421     * @param value, as defined in FeatureValueConstants.
422     * @param listener, provided if caller needs to be notified for set result.
423     * @return void
424     *
425     * @throws ImsException if calling the IMS service results in an error.
426     */
427    public void setFeatureValue(int feature, int network, int value,
428            ImsConfigListener listener) throws ImsException {
429        mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
430        if (DBG) {
431            Rlog.d(TAG, "setFeatureValue: feature = " + feature + ", network =" + network +
432                    ", value =" + value + ", listener =" + listener);
433        }
434        try {
435            miConfig.setFeatureValue(feature, network, value, listener);
436        } catch (RemoteException e) {
437            throw new ImsException("setFeatureValue()", e,
438                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
439        }
440    }
441
442    /**
443     * Gets the value for IMS Volte provisioned.
444     * It should be the same as operator provisioned value if applies.
445     *
446     * @return boolean
447     *
448     * @throws ImsException if calling the IMS service results in an error.
449     */
450    public boolean getVolteProvisioned() throws ImsException {
451        try {
452           return miConfig.getVolteProvisioned();
453        } catch (RemoteException e) {
454            throw new ImsException("getVolteProvisioned()", e,
455                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
456        }
457    }
458
459    /**
460     * Gets the value for IMS feature item for video call quality.
461     *
462     * @param listener, provided if caller needs to be notified for set result.
463     * @return void
464     *
465     * @throws ImsException if calling the IMS service results in an error.
466     */
467    public void getVideoQuality(ImsConfigListener listener) throws ImsException {
468        try {
469            miConfig.getVideoQuality(listener);
470        } catch (RemoteException e) {
471            throw new ImsException("getVideoQuality()", e,
472                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
473        }
474    }
475
476    /**
477     * Sets the value for IMS feature item video quality.
478     *
479     * @param quality, defines the value of video quality.
480     * @param listener, provided if caller needs to be notified for set result.
481     * @return void
482     *
483     * @throws ImsException if calling the IMS service results in an error.
484     */
485     public void setVideoQuality(int quality, ImsConfigListener listener) throws ImsException {
486        try {
487            miConfig.setVideoQuality(quality, listener);
488        } catch (RemoteException e) {
489            throw new ImsException("setVideoQuality()", e,
490                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
491        }
492     }
493}
494