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
40    /**
41     * Broadcast action: the feature enable status was changed
42     *
43     * @hide
44     */
45    public static final String ACTION_IMS_FEATURE_CHANGED =
46            "com.android.intent.action.IMS_FEATURE_CHANGED";
47
48    /**
49     * Broadcast action: the configuration was changed
50     *
51     * @hide
52     */
53    public static final String ACTION_IMS_CONFIG_CHANGED =
54            "com.android.intent.action.IMS_CONFIG_CHANGED";
55
56    /**
57     * Extra parameter "item" of intent ACTION_IMS_FEATURE_CHANGED and ACTION_IMS_CONFIG_CHANGED.
58     * It is the value of FeatureConstants or ConfigConstants.
59     *
60     * @hide
61     */
62    public static final String EXTRA_CHANGED_ITEM = "item";
63
64    /**
65     * Extra parameter "value" of intent ACTION_IMS_FEATURE_CHANGED and ACTION_IMS_CONFIG_CHANGED.
66     * It is the new value of "item".
67     *
68     * @hide
69     */
70    public static final String EXTRA_NEW_VALUE = "value";
71
72    /**
73    * Defines IMS service/capability feature constants.
74    */
75    public static class FeatureConstants {
76        public static final int FEATURE_TYPE_UNKNOWN = -1;
77
78        /**
79         * FEATURE_TYPE_VOLTE supports features defined in 3GPP and
80         * GSMA IR.92 over LTE.
81         */
82        public static final int FEATURE_TYPE_VOICE_OVER_LTE = 0;
83
84        /**
85         * FEATURE_TYPE_LVC supports features defined in 3GPP and
86         * GSMA IR.94 over LTE.
87         */
88        public static final int FEATURE_TYPE_VIDEO_OVER_LTE = 1;
89
90        /**
91         * FEATURE_TYPE_VOICE_OVER_WIFI supports features defined in 3GPP and
92         * GSMA IR.92 over WiFi.
93         */
94        public static final int FEATURE_TYPE_VOICE_OVER_WIFI = 2;
95
96        /**
97         * FEATURE_TYPE_VIDEO_OVER_WIFI supports features defined in 3GPP and
98         * GSMA IR.94 over WiFi.
99         */
100        public static final int FEATURE_TYPE_VIDEO_OVER_WIFI = 3;
101
102        /**
103         * FEATURE_TYPE_UT supports features defined in 3GPP and
104         * GSMA IR.92 over LTE.
105         */
106        public static final int FEATURE_TYPE_UT_OVER_LTE = 4;
107
108       /**
109         * FEATURE_TYPE_UT_OVER_WIFI supports features defined in 3GPP and
110         * GSMA IR.92 over WiFi.
111         */
112        public static final int FEATURE_TYPE_UT_OVER_WIFI = 5;
113    }
114
115    /**
116    * Defines IMS service/capability parameters.
117    */
118    public static class ConfigConstants {
119
120        // Define IMS config items
121        public static final int CONFIG_START = 0;
122
123        // Define operator provisioned config items
124        public static final int PROVISIONED_CONFIG_START = CONFIG_START;
125
126        /**
127         * AMR CODEC Mode Value set, 0-7 in comma separated sequence.
128         * Value is in String format.
129         */
130        public static final int VOCODER_AMRMODESET = CONFIG_START;
131
132        /**
133         * Wide Band AMR CODEC Mode Value set,0-7 in comma separated sequence.
134         * Value is in String format.
135         */
136        public static final int VOCODER_AMRWBMODESET = 1;
137
138        /**
139         * SIP Session Timer value (seconds).
140         * Value is in Integer format.
141         */
142        public static final int SIP_SESSION_TIMER = 2;
143
144        /**
145         * Minimum SIP Session Expiration Timer in (seconds).
146         * Value is in Integer format.
147         */
148        public static final int MIN_SE = 3;
149
150        /**
151         * SIP_INVITE cancellation time out value (in milliseconds). Integer format.
152         * Value is in Integer format.
153         */
154        public static final int CANCELLATION_TIMER = 4;
155
156        /**
157         * Delay time when an iRAT transition from eHRPD/HRPD/1xRTT to LTE.
158         * Value is in Integer format.
159         */
160        public static final int TDELAY = 5;
161
162        /**
163         * Silent redial status of Enabled (True), or Disabled (False).
164         * Value is in Integer format.
165         */
166        public static final int SILENT_REDIAL_ENABLE = 6;
167
168        /**
169         * SIP T1 timer value in milliseconds. See RFC 3261 for define.
170         * Value is in Integer format.
171         */
172        public static final int SIP_T1_TIMER = 7;
173
174        /**
175         * SIP T2 timer value in milliseconds.  See RFC 3261 for define.
176         * Value is in Integer format.
177         */
178        public static final int SIP_T2_TIMER  = 8;
179
180         /**
181         * SIP TF timer value in milliseconds.  See RFC 3261 for define.
182         * Value is in Integer format.
183         */
184        public static final int SIP_TF_TIMER = 9;
185
186        /**
187         * VoLTE status for VLT/s status of Enabled (1), or Disabled (0).
188         * Value is in Integer format.
189         */
190        public static final int VLT_SETTING_ENABLED = 10;
191
192        /**
193         * VoLTE status for LVC/s status of Enabled (1), or Disabled (0).
194         * Value is in Integer format.
195         */
196        public static final int LVC_SETTING_ENABLED = 11;
197        /**
198         * Domain Name for the device to populate the request URI for REGISTRATION.
199         * Value is in String format.
200         */
201        public static final int DOMAIN_NAME = 12;
202         /**
203         * Device Outgoing SMS based on either 3GPP or 3GPP2 standards.
204         * Value is in Integer format. 3GPP2(0), 3GPP(1)
205         */
206        public static final int SMS_FORMAT = 13;
207         /**
208         * Turns IMS ON/OFF on the device.
209         * Value is in Integer format. ON (1), OFF(0).
210         */
211        public static final int SMS_OVER_IP = 14;
212        /**
213         * Requested expiration for Published Online availability.
214         * Value is in Integer format.
215         */
216        public static final int PUBLISH_TIMER = 15;
217        /**
218         * Requested expiration for Published Offline availability.
219         * Value is in Integer format.
220         */
221        public static final int PUBLISH_TIMER_EXTENDED = 16;
222        /**
223         *
224         * Value is in Integer format.
225         */
226        public static final int CAPABILITY_DISCOVERY_ENABLED = 17;
227        /**
228         * Period of time the capability information of the  contact is cached on handset.
229         * Value is in Integer format.
230         */
231        public static final int CAPABILITIES_CACHE_EXPIRATION = 18;
232        /**
233         * Peiod of time the availability information of a contact is cached on device.
234         * Value is in Integer format.
235         */
236        public static final int AVAILABILITY_CACHE_EXPIRATION = 19;
237        /**
238         * Interval between successive capabilities polling.
239         * Value is in Integer format.
240         */
241        public static final int CAPABILITIES_POLL_INTERVAL = 20;
242        /**
243         * Minimum time between two published messages from the device.
244         * Value is in Integer format.
245         */
246        public static final int SOURCE_THROTTLE_PUBLISH = 21;
247        /**
248         * The Maximum number of MDNs contained in one Request Contained List.
249         * Value is in Integer format.
250         */
251        public static final int MAX_NUMENTRIES_IN_RCL = 22;
252        /**
253         * Expiration timer for subscription of a Request Contained List, used in capability polling.
254         * Value is in Integer format.
255         */
256        public static final int CAPAB_POLL_LIST_SUB_EXP = 23;
257        /**
258         * Applies compression to LIST Subscription.
259         * Value is in Integer format. Enable (1), Disable(0).
260         */
261        public static final int GZIP_FLAG = 24;
262        /**
263         * VOLTE Status for EAB/s status of Enabled (1), or Disabled (0).
264         * Value is in Integer format.
265         */
266        public static final int EAB_SETTING_ENABLED = 25;
267        /**
268         * Wi-Fi calling roaming status.
269         * Value is in Integer format. ON (1), OFF(0).
270         */
271        public static final int VOICE_OVER_WIFI_ROAMING = 26;
272        /**
273         * Wi-Fi calling modem - WfcModeFeatureValueConstants.
274         * Value is in Integer format.
275         */
276        public static final int VOICE_OVER_WIFI_MODE = 27;
277        /**
278         * VOLTE Status for voice over wifi status of Enabled (1), or Disabled (0).
279         * Value is in Integer format.
280         */
281        public static final int VOICE_OVER_WIFI_SETTING_ENABLED = 28;
282        /**
283         * Mobile data enabled.
284         * Value is in Integer format. On (1), OFF(0).
285         */
286        public static final int MOBILE_DATA_ENABLED = 29;
287        /**
288         * VoLTE user opted in status.
289         * Value is in Integer format. Opted-in (1) Opted-out (0).
290         */
291        public static final int VOLTE_USER_OPT_IN_STATUS = 30;
292        /**
293         * Proxy for Call Session Control Function(P-CSCF) address for Local-BreakOut(LBO).
294         * Value is in String format.
295         */
296        public static final int LBO_PCSCF_ADDRESS = 31;
297        /**
298         * Keep Alive Enabled for SIP.
299         * Value is in Integer format. On(1), OFF(0).
300         */
301        public static final int KEEP_ALIVE_ENABLED = 32;
302        /**
303         * Registration retry Base Time value in seconds.
304         * Value is in Integer format.
305         */
306        public static final int REGISTRATION_RETRY_BASE_TIME_SEC = 33;
307        /**
308         * Registration retry Max Time value in seconds.
309         * Value is in Integer format.
310         */
311        public static final int REGISTRATION_RETRY_MAX_TIME_SEC = 34;
312        /**
313         * Smallest RTP port for speech codec.
314         * Value is in integer format.
315         */
316        public static final int SPEECH_START_PORT = 35;
317        /**
318         * Largest RTP port for speech code.
319         * Value is in Integer format.
320         */
321        public static final int SPEECH_END_PORT = 36;
322        /**
323         * SIP Timer A's value in milliseconds. Timer A is the INVITE request
324         * retransmit interval, for UDP only.
325         * Value is in Integer format.
326         */
327        public static final int SIP_INVITE_REQ_RETX_INTERVAL_MSEC = 37;
328        /**
329         * SIP Timer B's value in milliseconds. Timer B is the wait time for
330         * INVITE message to be acknowledged.
331         * Value is in Integer format.
332         */
333        public static final int SIP_INVITE_RSP_WAIT_TIME_MSEC = 38;
334        /**
335         * SIP Timer D's value in milliseconds. Timer D is the wait time for
336         * response retransmits of the invite client transactions.
337         * Value is in Integer format.
338         */
339        public static final int SIP_INVITE_RSP_RETX_WAIT_TIME_MSEC = 39;
340        /**
341         * SIP Timer E's value in milliseconds. Timer E is the value Non-INVITE
342         * request retransmit interval, for UDP only.
343         * Value is in Integer format.
344         */
345        public static final int SIP_NON_INVITE_REQ_RETX_INTERVAL_MSEC = 40;
346        /**
347         * SIP Timer F's value in milliseconds. Timer F is the Non-INVITE transaction
348         * timeout timer.
349         * Value is in Integer format.
350         */
351        public static final int SIP_NON_INVITE_TXN_TIMEOUT_TIMER_MSEC = 41;
352        /**
353         * SIP Timer G's value in milliseconds. Timer G is the value of INVITE response
354         * retransmit interval.
355         * Value is in Integer format.
356         */
357        public static final int SIP_INVITE_RSP_RETX_INTERVAL_MSEC = 42;
358        /**
359         * SIP Timer H's value in milliseconds. Timer H is the value of wait time for
360         * ACK receipt.
361         * Value is in Integer format.
362         */
363        public static final int SIP_ACK_RECEIPT_WAIT_TIME_MSEC = 43;
364        /**
365         * SIP Timer I's value in milliseconds. Timer I is the value of wait time for
366         * ACK retransmits.
367         * Value is in Integer format.
368         */
369        public static final int SIP_ACK_RETX_WAIT_TIME_MSEC = 44;
370        /**
371         * SIP Timer J's value in milliseconds. Timer J is the value of wait time for
372         * non-invite request retransmission.
373         * Value is in Integer format.
374         */
375        public static final int SIP_NON_INVITE_REQ_RETX_WAIT_TIME_MSEC = 45;
376        /**
377         * SIP Timer K's value in milliseconds. Timer K is the value of wait time for
378         * non-invite response retransmits.
379         * Value is in Integer format.
380         */
381        public static final int SIP_NON_INVITE_RSP_RETX_WAIT_TIME_MSEC = 46;
382        /**
383         * AMR WB octet aligned dynamic payload type.
384         * Value is in Integer format.
385         */
386        public static final int AMR_WB_OCTET_ALIGNED_PT = 47;
387        /**
388         * AMR WB bandwidth efficient payload type.
389         * Value is in Integer format.
390         */
391        public static final int AMR_WB_BANDWIDTH_EFFICIENT_PT = 48;
392        /**
393         * AMR octet aligned dynamic payload type.
394         * Value is in Integer format.
395         */
396        public static final int AMR_OCTET_ALIGNED_PT = 49;
397        /**
398         * AMR bandwidth efficient payload type.
399         * Value is in Integer format.
400         */
401        public static final int AMR_BANDWIDTH_EFFICIENT_PT = 50;
402        /**
403         * DTMF WB payload type.
404         * Value is in Integer format.
405         */
406        public static final int DTMF_WB_PT = 51;
407        /**
408         * DTMF NB payload type.
409         * Value is in Integer format.
410         */
411        public static final int DTMF_NB_PT = 52;
412        /**
413         * AMR Default encoding mode.
414         * Value is in Integer format.
415         */
416        public static final int AMR_DEFAULT_MODE = 53;
417        /**
418         * SMS Public Service Identity.
419         * Value is in String format.
420         */
421        public static final int SMS_PSI = 54;
422        /**
423         * Video Quality - VideoQualityFeatureValuesConstants.
424         * Value is in Integer format.
425         */
426        public static final int VIDEO_QUALITY = 55;
427
428
429        // Expand the operator config items as needed here, need to change
430        // PROVISIONED_CONFIG_END after that.
431        public static final int PROVISIONED_CONFIG_END = VIDEO_QUALITY;
432
433        // Expand the operator config items as needed here.
434    }
435
436    /**
437    * Defines IMS set operation status.
438    */
439    public static class OperationStatusConstants {
440        public static final int UNKNOWN = -1;
441        public static final int SUCCESS = 0;
442        public static final int FAILED =  1;
443        public static final int UNSUPPORTED_CAUSE_NONE = 2;
444        public static final int UNSUPPORTED_CAUSE_RAT = 3;
445        public static final int UNSUPPORTED_CAUSE_DISABLED = 4;
446    }
447
448    /**
449     * Defines IMS get operation values.
450     */
451    public static class OperationValuesConstants {
452        /**
453         * Values related to Video Quality
454         */
455        public static final int VIDEO_QUALITY_UNKNOWN = -1;
456        public static final int VIDEO_QUALITY_LOW = 0;
457        public static final int VIDEO_QUALITY_HIGH = 1;
458    }
459
460    /**
461     * Defines IMS video quality feature value.
462     */
463    public static class VideoQualityFeatureValuesConstants {
464        public static final int LOW = 0;
465        public static final int HIGH = 1;
466    }
467
468   /**
469    * Defines IMS feature value.
470    */
471    public static class FeatureValueConstants {
472        public static final int OFF = 0;
473        public static final int ON = 1;
474    }
475
476    /**
477     * Defines IMS feature value.
478     */
479    public static class WfcModeFeatureValueConstants {
480        public static final int WIFI_ONLY = 0;
481        public static final int CELLULAR_PREFERRED = 1;
482        public static final int WIFI_PREFERRED = 2;
483    }
484
485    public ImsConfig(IImsConfig iconfig, Context context) {
486        if (DBG) Rlog.d(TAG, "ImsConfig creates");
487        miConfig = iconfig;
488        mContext = context;
489    }
490
491    /**
492     * Gets the provisioned value for IMS service/capabilities parameters used by IMS stack.
493     * This function should not be called from the mainthread as it could block the
494     * mainthread.
495     *
496     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
497     * @return the value in Integer format.
498     *
499     * @throws ImsException if calling the IMS service results in an error.
500     */
501    public int getProvisionedValue(int item) throws ImsException {
502        int ret = 0;
503        try {
504            ret = miConfig.getProvisionedValue(item);
505        }  catch (RemoteException e) {
506            throw new ImsException("getValue()", e,
507                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
508        }
509        if (DBG) Rlog.d(TAG, "getProvisionedValue(): item = " + item + ", ret =" + ret);
510
511        return ret;
512    }
513
514    /**
515     * Gets the provisioned value for IMS service/capabilities parameters used by IMS stack.
516     * This function should not be called from the mainthread as it could block the
517     * mainthread.
518     *
519     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
520     * @return value in String format.
521     *
522     * @throws ImsException if calling the IMS service results in an error.
523     */
524    public String getProvisionedStringValue(int item) throws ImsException {
525        String ret = "Unknown";
526        try {
527            ret = miConfig.getProvisionedStringValue(item);
528        }  catch (RemoteException e) {
529            throw new ImsException("getProvisionedStringValue()", e,
530                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
531        }
532        if (DBG) Rlog.d(TAG, "getProvisionedStringValue(): item = " + item + ", ret =" + ret);
533
534        return ret;
535    }
536
537    /**
538     * Sets the value for IMS service/capabilities parameters by
539     * the operator device management entity.
540     * This function should not be called from main thread as it could block
541     * mainthread.
542     *
543     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
544     * @param value in Integer format.
545     * @return as defined in com.android.ims.ImsConfig#OperationStatusConstants
546     *
547     * @throws ImsException if calling the IMS service results in an error.
548     */
549    public int setProvisionedValue(int item, int value)
550            throws ImsException {
551        int ret = ImsConfig.OperationStatusConstants.UNKNOWN;
552        if (DBG) {
553            Rlog.d(TAG, "setProvisionedValue(): item = " + item +
554                    "value = " + value);
555        }
556        try {
557            ret = miConfig.setProvisionedValue(item, value);
558        }  catch (RemoteException e) {
559            throw new ImsException("setProvisionedValue()", e,
560                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
561        }
562        if (DBG) {
563            Rlog.d(TAG, "setProvisionedValue(): item = " + item +
564                    " value = " + value + " ret = " + ret);
565        }
566        return ret;
567    }
568
569    /**
570     * Sets the value for IMS service/capabilities parameters by
571     * the operator device management entity.
572     * This function should not be called from main thread as it could block
573     * mainthread.
574     *
575     * @param item, as defined in com.android.ims.ImsConfig#ConfigConstants.
576     * @param value in String format.
577     * @return as defined in com.android.ims.ImsConfig#OperationStatusConstants
578     *
579     * @throws ImsException if calling the IMS service results in an error.
580     */
581    public int setProvisionedStringValue(int item, String value)
582            throws ImsException {
583        int ret = ImsConfig.OperationStatusConstants.UNKNOWN;
584        try {
585            ret = miConfig.setProvisionedStringValue(item, value);
586        }  catch (RemoteException e) {
587            throw new ImsException("setProvisionedStringValue()", e,
588                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
589        }
590        if (DBG) {
591            Rlog.d(TAG, "setProvisionedStringValue(): item = " + item +
592                    ", value =" + value);
593        }
594        return ret;
595    }
596
597    /**
598     * Gets the value for IMS feature item for specified network type.
599     *
600     * @param feature, defined as in FeatureConstants.
601     * @param network, defined as in android.telephony.TelephonyManager#NETWORK_TYPE_XXX.
602     * @param listener, provided to be notified for the feature on/off status.
603     * @return void
604     *
605     * @throws ImsException if calling the IMS service results in an error.
606     */
607    public void getFeatureValue(int feature, int network,
608            ImsConfigListener listener) throws ImsException {
609        if (DBG) {
610            Rlog.d(TAG, "getFeatureValue: feature = " + feature + ", network =" + network +
611                    ", listener =" + listener);
612        }
613        try {
614            miConfig.getFeatureValue(feature, network, listener);
615        } catch (RemoteException e) {
616            throw new ImsException("getFeatureValue()", e,
617                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
618        }
619    }
620
621    /**
622     * Sets the value for IMS feature item for specified network type.
623     *
624     * @param feature, as defined in FeatureConstants.
625     * @param network, as defined in android.telephony.TelephonyManager#NETWORK_TYPE_XXX.
626     * @param value, as defined in FeatureValueConstants.
627     * @param listener, provided if caller needs to be notified for set result.
628     * @return void
629     *
630     * @throws ImsException if calling the IMS service results in an error.
631     */
632    public void setFeatureValue(int feature, int network, int value,
633            ImsConfigListener listener) throws ImsException {
634        if (DBG) {
635            Rlog.d(TAG, "setFeatureValue: feature = " + feature + ", network =" + network +
636                    ", value =" + value + ", listener =" + listener);
637        }
638        try {
639            miConfig.setFeatureValue(feature, network, value, listener);
640        } catch (RemoteException e) {
641            throw new ImsException("setFeatureValue()", e,
642                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
643        }
644    }
645
646    /**
647     * Gets the value for IMS Volte provisioned.
648     * It should be the same as operator provisioned value if applies.
649     *
650     * @return boolean
651     *
652     * @throws ImsException if calling the IMS service results in an error.
653     */
654    public boolean getVolteProvisioned() throws ImsException {
655        try {
656           return miConfig.getVolteProvisioned();
657        } catch (RemoteException e) {
658            throw new ImsException("getVolteProvisioned()", e,
659                    ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
660        }
661    }
662}
663