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