ImsConfig.java revision 3fd20025b87ff6828182d21668dd0b7a4a0435ec
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        // Expand the operator config items as needed here, need to change
220        // PROVISIONED_CONFIG_END after that.
221        public static final int PROVISIONED_CONFIG_END = EAB_SETTING_ENABLED;
222
223        // Expand the operator config items as needed here.
224    }
225
226    /**
227    * Defines IMS set operation status.
228    */
229    public static class OperationStatusConstants {
230        public static final int UNKNOWN = -1;
231        public static final int SUCCESS = 0;
232        public static final int FAILED =  1;
233        public static final int UNSUPPORTED_CAUSE_NONE = 2;
234        public static final int UNSUPPORTED_CAUSE_RAT = 3;
235        public static final int UNSUPPORTED_CAUSE_DISABLED = 4;
236    }
237
238   /**
239    * Defines IMS feature value.
240    */
241    public static class FeatureValueConstants {
242        public static final int OFF = 0;
243        public static final int ON = 1;
244    }
245
246    public ImsConfig(IImsConfig iconfig, Context context) {
247        if (DBG) Rlog.d(TAG, "ImsConfig creates");
248        miConfig = iconfig;
249        mContext = context;
250    }
251
252    /**
253     * Gets the provisioned value for IMS service/capabilities parameters used by IMS stack.
254     * This function should not be called from the mainthread as it could block the
255     * mainthread.
256     *
257     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
258     * @return the value in Integer format.
259     *
260     * @throws ImsException if calling the IMS service results in an error.
261     */
262    public int getProvisionedValue(int item) throws ImsException {
263        int ret = 0;
264        try {
265            ret = miConfig.getProvisionedValue(item);
266        }  catch (RemoteException e) {
267            throw new ImsException("getValue()", e,
268                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
269        }
270        if (DBG) Rlog.d(TAG, "getProvisionedValue(): item = " + item + ", ret =" + ret);
271
272        return ret;
273    }
274
275    /**
276     * Gets the provisioned value for IMS service/capabilities parameters used by IMS stack.
277     * This function should not be called from the mainthread as it could block the
278     * mainthread.
279     *
280     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
281     * @return value in String format.
282     *
283     * @throws ImsException if calling the IMS service results in an error.
284     */
285    public String getProvisionedStringValue(int item) throws ImsException {
286        String ret = "Unknown";
287        try {
288            ret = miConfig.getProvisionedStringValue(item);
289        }  catch (RemoteException e) {
290            throw new ImsException("getProvisionedStringValue()", e,
291                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
292        }
293        if (DBG) Rlog.d(TAG, "getProvisionedStringValue(): item = " + item + ", ret =" + ret);
294
295        return ret;
296    }
297
298    /**
299     * Sets the value for IMS service/capabilities parameters by
300     * the operator device management entity.
301     * This function should not be called from main thread as it could block
302     * mainthread.
303     *
304     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
305     * @param value in Integer format.
306     * @return as defined in com.android.ims.ImsConfig#OperationStatusConstants
307     *
308     * @throws ImsException if calling the IMS service results in an error.
309     */
310    public int setProvisionedValue(int item, int value)
311            throws ImsException {
312        mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
313        int ret = ImsConfig.OperationStatusConstants.UNKNOWN;
314        if (DBG) {
315            Rlog.d(TAG, "setProvisionedValue(): item = " + item +
316                    "value = " + value);
317        }
318        try {
319            ret = miConfig.setProvisionedValue(item, value);
320        }  catch (RemoteException e) {
321            throw new ImsException("setProvisionedValue()", e,
322                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
323        }
324        if (DBG) {
325            Rlog.d(TAG, "setProvisionedValue(): item = " + item +
326                    " value = " + value + " ret = " + ret);
327        }
328        return ret;
329    }
330
331    /**
332     * Sets the value for IMS service/capabilities parameters by
333     * the operator device management entity.
334     * This function should not be called from main thread as it could block
335     * mainthread.
336     *
337     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
338     * @param value in String format.
339     * @return as defined in com.android.ims.ImsConfig#OperationStatusConstants
340     *
341     * @throws ImsException if calling the IMS service results in an error.
342     */
343    public int setProvisionedStringValue(int item, String value)
344            throws ImsException {
345        mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
346        int ret = ImsConfig.OperationStatusConstants.UNKNOWN;
347        try {
348            ret = miConfig.setProvisionedStringValue(item, value);
349        }  catch (RemoteException e) {
350            throw new ImsException("setProvisionedStringValue()", e,
351                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
352        }
353        if (DBG) {
354            Rlog.d(TAG, "setProvisionedStringValue(): item = " + item +
355                    ", value =" + value);
356        }
357        return ret;
358    }
359
360    /**
361     * Gets the value for IMS feature item for specified network type.
362     *
363     * @param feature, defined as in FeatureConstants.
364     * @param network, defined as in android.telephony.TelephonyManager#NETWORK_TYPE_XXX.
365     * @param listener, provided to be notified for the feature on/off status.
366     * @return void
367     *
368     * @throws ImsException if calling the IMS service results in an error.
369     */
370    public void getFeatureValue(int feature, int network,
371            ImsConfigListener listener) throws ImsException {
372        if (DBG) {
373            Rlog.d(TAG, "getFeatureValue: feature = " + feature + ", network =" + network +
374                    ", listener =" + listener);
375        }
376        try {
377            miConfig.getFeatureValue(feature, network, listener);
378        } catch (RemoteException e) {
379            throw new ImsException("getFeatureValue()", e,
380                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
381        }
382    }
383
384    /**
385     * Sets the value for IMS feature item for specified network type.
386     *
387     * @param feature, as defined in FeatureConstants.
388     * @param network, as defined in android.telephony.TelephonyManager#NETWORK_TYPE_XXX.
389     * @param value, as defined in FeatureValueConstants.
390     * @param listener, provided if caller needs to be notified for set result.
391     * @return void
392     *
393     * @throws ImsException if calling the IMS service results in an error.
394     */
395    public void setFeatureValue(int feature, int network, int value,
396            ImsConfigListener listener) throws ImsException {
397        mContext.enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, null);
398        if (DBG) {
399            Rlog.d(TAG, "setFeatureValue: feature = " + feature + ", network =" + network +
400                    ", value =" + value + ", listener =" + listener);
401        }
402        try {
403            miConfig.setFeatureValue(feature, network, value, listener);
404        } catch (RemoteException e) {
405            throw new ImsException("setFeatureValue()", e,
406                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
407        }
408    }
409
410    /**
411     * Gets the value for IMS Volte provisioned.
412     * It should be the same as operator provisioned value if applies.
413     *
414     * @return boolean
415     *
416     * @throws ImsException if calling the IMS service results in an error.
417     */
418    public boolean getVolteProvisioned() throws ImsException {
419        try {
420           return miConfig.getVolteProvisioned();
421        } catch (RemoteException e) {
422            throw new ImsException("getVolteProvisioned()", e,
423                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
424        }
425    }
426}
427