• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 
17 package android.telephony.ims;
18 
19 import android.Manifest;
20 import android.annotation.CallbackExecutor;
21 import android.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.annotation.RequiresPermission;
24 import android.annotation.SdkConstant;
25 import android.annotation.StringDef;
26 import android.annotation.SystemApi;
27 import android.annotation.WorkerThread;
28 import android.content.pm.PackageManager;
29 import android.os.Binder;
30 import android.os.RemoteException;
31 import android.os.ServiceSpecificException;
32 import android.telephony.CarrierConfigManager;
33 import android.telephony.SubscriptionManager;
34 import android.telephony.TelephonyFrameworkInitializer;
35 import android.telephony.TelephonyManager;
36 import android.telephony.ims.aidl.IImsConfigCallback;
37 import android.telephony.ims.aidl.IRcsConfigCallback;
38 import android.telephony.ims.feature.MmTelFeature;
39 import android.telephony.ims.feature.RcsFeature;
40 import android.telephony.ims.stub.ImsConfigImplBase;
41 import android.telephony.ims.stub.ImsRegistrationImplBase;
42 
43 import com.android.internal.telephony.ITelephony;
44 
45 import java.lang.annotation.Retention;
46 import java.lang.annotation.RetentionPolicy;
47 import java.util.concurrent.Executor;
48 
49 /**
50  * Manages IMS provisioning and configuration parameters, as well as callbacks for apps to listen
51  * to changes in these configurations.
52  *
53  * IMS provisioning keys are defined per carrier or OEM using OMA-DM or other provisioning
54  * applications and may vary. It is up to the carrier and OEM applications to ensure that the
55  * correct provisioning keys are being used when integrating with a vendor's ImsService.
56  *
57  * Note: For compatibility purposes, the integer values [0 - 99] used in
58  * {@link #setProvisioningIntValue(int, int)} have been reserved for existing provisioning keys
59  * previously defined in the Android framework. Please do not redefine new provisioning keys in this
60  * range or it may generate collisions with existing keys. Some common constants have also been
61  * defined in this class to make integrating with other system apps easier.
62  * @hide
63  */
64 @SystemApi
65 public class ProvisioningManager {
66 
67     /**@hide*/
68     @StringDef(prefix = "STRING_QUERY_RESULT_ERROR_", value = {
69             STRING_QUERY_RESULT_ERROR_GENERIC,
70             STRING_QUERY_RESULT_ERROR_NOT_READY
71     })
72     @Retention(RetentionPolicy.SOURCE)
73     public @interface StringResultError {}
74 
75     /**
76      * The query from {@link #getProvisioningStringValue(int)} has resulted in an unspecified error.
77      */
78     public static final String STRING_QUERY_RESULT_ERROR_GENERIC =
79             "STRING_QUERY_RESULT_ERROR_GENERIC";
80 
81     /**
82      * The query from {@link #getProvisioningStringValue(int)} has resulted in an error because the
83      * ImsService implementation was not ready for provisioning queries.
84      */
85     public static final String STRING_QUERY_RESULT_ERROR_NOT_READY =
86             "STRING_QUERY_RESULT_ERROR_NOT_READY";
87 
88     /**
89      * There is no existing configuration for the queried provisioning key.
90      * @hide
91      */
92     public static final int PROVISIONING_RESULT_UNKNOWN = -1;
93 
94     /**
95      * The integer result of provisioning for the queried key is disabled.
96      */
97     public static final int PROVISIONING_VALUE_DISABLED = 0;
98 
99     /**
100      * The integer result of provisioning for the queried key is enabled.
101      */
102     public static final int PROVISIONING_VALUE_ENABLED = 1;
103 
104 
105     // Inheriting values from ImsConfig for backwards compatibility.
106     /**
107      * AMR CODEC Mode Value set, 0-7 in comma separated sequence.
108      * <p>
109      * This corresponds to the {@code mode-set} parameter for the AMR codec.
110      * See 3GPP TS 26.101 Table 1A for more information.
111      * <p>
112      * <UL>
113      *     <LI>0 - AMR 4.75 kbit/s</LI>
114      *     <LI>1 - AMR 5.15 kbit/s</LI>
115      *     <LI>2 - AMR 5.90 kbit/s</LI>
116      *     <LI>3 - AMR 6.70 kbit/s (PDC-EFR)</LI>
117      *     <LI>4 - AMR 7.40 kbit/s (TDMA-EFR)</LI>
118      *     <LI>5 - AMR 7.95 kbit/s</LI>
119      *     <LI>6 - AMR 10.2 kbit/s</LI>
120      *     <LI>7 - AMR 12.2 kbit/s (GSM-EFR)</LI>
121      * </UL>
122      * <p>
123      * Value is in String format.
124      * @see #setProvisioningIntValue(int, int)
125      * @see #getProvisioningIntValue(int)
126      * @hide
127      */
128     public static final int KEY_AMR_CODEC_MODE_SET_VALUES = 0;
129 
130     /**
131      * Wide Band AMR CODEC Mode Value set,0-7 in comma separated sequence.
132      * <p>
133      * This corresponds to the {@code mode-set} parameter for the AMR wideband codec.
134      * See 3GPP TS 26.101 Table 1A for more information.
135      * <p>
136      * <UL>
137      *     <LI>0 - AMR 4.75 kbit/s</LI>
138      *     <LI>1 - AMR 5.15 kbit/s</LI>
139      *     <LI>2 - AMR 5.90 kbit/s</LI>
140      *     <LI>3 - AMR 6.70 kbit/s (PDC-EFR)</LI>
141      *     <LI>4 - AMR 7.40 kbit/s (TDMA-EFR)</LI>
142      *     <LI>5 - AMR 7.95 kbit/s</LI>
143      *     <LI>6 - AMR 10.2 kbit/s</LI>
144      *     <LI>7 - AMR 12.2 kbit/s (GSM-EFR)</LI>
145      * </UL>
146      * <p>
147      * Value is in String format.
148      * @see #setProvisioningStringValue(int, String)
149      * @see #getProvisioningStringValue(int)
150      * @hide
151      */
152     public static final int KEY_AMR_WB_CODEC_MODE_SET_VALUES = 1;
153 
154     /**
155      * SIP Session Timer value (seconds).
156      * <p>
157      * See RFC4028 for more information.
158      * <p>
159      * Value is in Integer format.
160      * @see #setProvisioningIntValue(int, int)
161      * @see #getProvisioningIntValue(int)
162      * @hide
163      */
164     public static final int KEY_SIP_SESSION_TIMER_SEC = 2;
165 
166     /**
167      * Minimum SIP Session Expiration Timer in (seconds).
168      * <p>
169      * See RFC4028 for more information.
170      * <p>
171      * Value is in Integer format.
172      * @see #setProvisioningIntValue(int, int)
173      * @see #getProvisioningIntValue(int)
174      * @hide
175      */
176     public static final int KEY_MINIMUM_SIP_SESSION_EXPIRATION_TIMER_SEC = 3;
177 
178     /**
179      * SIP_INVITE cancellation time out value (in milliseconds). Integer format.
180      * <p>
181      * See RFC4028 for more information.
182      * <p>
183      * Value is in Integer format.
184      * @see #setProvisioningIntValue(int, int)
185      * @see #getProvisioningIntValue(int)
186      * @hide
187      */
188     public static final int KEY_SIP_INVITE_CANCELLATION_TIMER_MS = 4;
189 
190     /**
191      * Delay time when an iRAT transitions from eHRPD/HRPD/1xRTT to LTE.
192      * Value is in Integer format.
193      * @see #setProvisioningIntValue(int, int)
194      * @see #getProvisioningIntValue(int)
195      * @hide
196      */
197     public static final int KEY_TRANSITION_TO_LTE_DELAY_MS = 5;
198 
199     /**
200      * Silent redial status of Enabled (True), or Disabled (False).
201      * Value is in boolean format.
202      * @see #setProvisioningIntValue(int, int)
203      * @see #getProvisioningIntValue(int)
204      * @hide
205      */
206     public static final int KEY_ENABLE_SILENT_REDIAL = 6;
207 
208     /**
209      * An integer key representing the SIP T1 timer value in milliseconds for the associated
210      * subscription.
211      * <p>
212      * The SIP T1 timer is an estimate of the round-trip time and will retransmit
213      * INVITE transactions that are longer than T1 milliseconds over unreliable transports, doubling
214      * the time before retransmission every time there is no response. See RFC3261, section 17.1.1.1
215      * for more details.
216      * <p>
217      * The value is an integer.
218      * @see #setProvisioningIntValue(int, int)
219      * @see #getProvisioningIntValue(int)
220      * @hide
221      */
222     public static final int KEY_T1_TIMER_VALUE_MS = 7;
223 
224     /**
225      * SIP T2 timer value in milliseconds.  See RFC 3261 for information.
226      * <p>
227      * The T2 timer is the maximum retransmit interval for non-INVITE requests and INVITE responses.
228      * <p>
229      * Value is in Integer format.
230      * @see #setProvisioningIntValue(int, int)
231      * @see #getProvisioningIntValue(int)
232      * @hide
233      */
234     public static final int KEY_T2_TIMER_VALUE_MS = 8;
235 
236     /**
237      * SIP TF timer value in milliseconds.  See RFC 3261 for information.
238      * <p>
239      * The TF timer is the non-INVITE transaction timeout timer.
240      * <p>
241      * Value is in Integer format.
242      * @see #setProvisioningIntValue(int, int)
243      * @see #getProvisioningIntValue(int)
244      * @hide
245      */
246     public static final int KEY_TF_TIMER_VALUE_MS = 9;
247 
248     /**
249      * An integer key representing the voice over LTE (VoLTE) provisioning status for the
250      * associated subscription. Determines whether the user can register for voice services over
251      * LTE.
252      * <p>
253      * Use {@link #PROVISIONING_VALUE_ENABLED} to enable VoLTE provisioning and
254      * {@link #PROVISIONING_VALUE_DISABLED} to disable VoLTE provisioning.
255      * @see #setProvisioningIntValue(int, int)
256      * @see #getProvisioningIntValue(int)
257      * @hide
258      */
259     public static final int KEY_VOLTE_PROVISIONING_STATUS = 10;
260 
261     /**
262      * An integer key representing the video telephony (VT) provisioning status for the
263      * associated subscription. Determines whether the user can register for video services over
264      * LTE.
265      * <p>
266      * Use {@link #PROVISIONING_VALUE_ENABLED} to enable VT provisioning and
267      * {@link #PROVISIONING_VALUE_DISABLED} to disable VT provisioning.
268      * @see #setProvisioningIntValue(int, int)
269      * @see #getProvisioningIntValue(int)
270      * @hide
271      */
272     public static final int KEY_VT_PROVISIONING_STATUS = 11;
273 
274     /**
275      * Domain Name for the device to populate the request URI for REGISTRATION.
276      * Value is in String format.
277      * @see #setProvisioningStringValue(int, String)
278      * @see #getProvisioningStringValue(int)
279      * @hide
280      */
281     public static final int KEY_REGISTRATION_DOMAIN_NAME = 12;
282 
283     /**
284      * Device Outgoing SMS based on either 3GPP or 3GPP2 standards.
285      * Value is in Integer format.
286      * Valid values are {@link #SMS_FORMAT_3GPP} and {@link #SMS_FORMAT_3GPP2}.
287      * @see #setProvisioningIntValue(int, int)
288      * @see #getProvisioningIntValue(int)
289      * @hide
290      */
291     public static final int KEY_SMS_FORMAT = 13;
292 
293     /**
294      * Value used with {@link #KEY_SMS_FORMAT} to indicate 3GPP2 SMS format is used.
295      * See {@link android.telephony.SmsMessage#FORMAT_3GPP2} for more information.
296      * @hide
297      */
298     public static final int SMS_FORMAT_3GPP2 = 0;
299 
300     /**
301      * Value used with {@link #KEY_SMS_FORMAT} to indicate 3GPP SMS format is used.
302      * See {@link android.telephony.SmsMessage#FORMAT_3GPP} for more information.
303      * @hide
304      */
305     public static final int SMS_FORMAT_3GPP = 1;
306 
307     /**
308      * Turns SMS over IMS ON/OFF on the device.
309      * Value is in Integer format. ON (1), OFF(0).
310      * @see #setProvisioningIntValue(int, int)
311      * @see #getProvisioningIntValue(int)
312      * @hide
313      */
314     public static final int KEY_SMS_OVER_IP_ENABLED = 14;
315 
316     /**
317      * An integer key associated with the carrier configured SIP PUBLISH timer, which dictates the
318      * expiration time in seconds for published online availability in RCS presence.
319      * <p>
320      * Value is in Integer format.
321      * @see #setProvisioningIntValue(int, int)
322      * @see #getProvisioningIntValue(int)
323      * @hide
324      */
325     public static final int KEY_RCS_PUBLISH_TIMER_SEC = 15;
326 
327     /**
328      * An integer key associated with the carrier configured expiration time in seconds for
329      * published offline availability in RCS presence provided, which is provided to the network.
330      * <p>
331      * Value is in Integer format.
332      * @see #setProvisioningIntValue(int, int)
333      * @see #getProvisioningIntValue(int)
334      * @hide
335      */
336     public static final int KEY_RCS_PUBLISH_OFFLINE_AVAILABILITY_TIMER_SEC = 16;
337 
338     /**
339      * An integer key associated with whether or not capability discovery is provisioned for this
340      * subscription. Any capability requests will be ignored by the RCS service.
341      * <p>
342      * The value is an integer, either {@link #PROVISIONING_VALUE_DISABLED} if capability
343      * discovery is disabled or {@link #PROVISIONING_VALUE_ENABLED} if capability discovery is
344      * enabled.
345      * @see #setProvisioningIntValue(int, int)
346      * @see #getProvisioningIntValue(int)
347      * @hide
348      */
349     public static final int KEY_RCS_CAPABILITY_DISCOVERY_ENABLED = 17;
350 
351     /**
352      * An integer key associated with the period of time in seconds the capability information of
353      * each contact is cached on the device.
354      * <p>
355      * Seconds are used because this is usually measured in the span of days.
356      * <p>
357      * Value is in Integer format.
358      * @see #setProvisioningIntValue(int, int)
359      * @see #getProvisioningIntValue(int)
360      * @hide
361      */
362     public static final int KEY_RCS_CAPABILITIES_CACHE_EXPIRATION_SEC = 18;
363 
364     /**
365      * An integer key associated with the period of time in seconds that the availability
366      * information of a contact is cached on the device, which is based on the carrier provisioning
367      * configuration from the network.
368      * <p>
369      * Value is in Integer format.
370      * @see #setProvisioningIntValue(int, int)
371      * @see #getProvisioningIntValue(int)
372      * @hide
373      */
374     public static final int KEY_RCS_AVAILABILITY_CACHE_EXPIRATION_SEC = 19;
375 
376     /**
377      * An integer key associated with the carrier configured interval in seconds expected between
378      * successive capability polling attempts, which is based on the carrier provisioning
379      * configuration from the network.
380      * <p>
381      * Value is in Integer format.
382      * @see #setProvisioningIntValue(int, int)
383      * @see #getProvisioningIntValue(int)
384      * @hide
385      */
386     public static final int KEY_RCS_CAPABILITIES_POLL_INTERVAL_SEC = 20;
387 
388     /**
389      * An integer key representing the minimum time allowed between two consecutive presence publish
390      * messages from the device in milliseconds.
391      * <p>
392      * Value is in Integer format.
393      * @see #setProvisioningIntValue(int, int)
394      * @see #getProvisioningIntValue(int)
395      * @hide
396      */
397     public static final int KEY_RCS_PUBLISH_SOURCE_THROTTLE_MS = 21;
398 
399     /**
400      * An integer key associated with the maximum number of MDNs contained in one SIP Request
401      * Contained List (RCS) used to retrieve the RCS capabilities of the contacts book.
402      * <p>
403      * Value is in Integer format.
404      * @see #setProvisioningIntValue(int, int)
405      * @see #getProvisioningIntValue(int)
406      * @hide
407      */
408     public static final int KEY_RCS_MAX_NUM_ENTRIES_IN_RCL = 22;
409 
410     /**
411      * An integer associated with the expiration timer used during the SIP subscription of a
412      * Request Contained List (RCL), which is used to retrieve the RCS capabilities of the contact
413      * book. This timer value is sent in seconds to the network.
414      * <p>
415      * Value is in Integer format.
416      * @see #setProvisioningIntValue(int, int)
417      * @see #getProvisioningIntValue(int)
418      * @hide
419      */
420     public static final int KEY_RCS_CAPABILITY_POLL_LIST_SUB_EXP_SEC = 23;
421 
422     /**
423      * Applies compression to LIST Subscription.
424      * Value is in Integer format. Enable (1), Disable(0).
425      * @see #setProvisioningIntValue(int, int)
426      * @see #getProvisioningIntValue(int)
427      * @hide
428      */
429     public static final int KEY_USE_GZIP_FOR_LIST_SUBSCRIPTION = 24;
430 
431     /**
432      * An integer key representing the RCS enhanced address book (EAB) provisioning status for the
433      * associated subscription. Determines whether or not SIP OPTIONS or presence will be used to
434      * retrieve RCS capabilities for the user's contacts.
435      * <p>
436      * Use {@link #PROVISIONING_VALUE_ENABLED} to enable EAB provisioning and
437      * {@link #PROVISIONING_VALUE_DISABLED} to disable EAB provisioning.
438      * @see #setProvisioningIntValue(int, int)
439      * @see #getProvisioningIntValue(int)
440      * @hide
441      */
442     public static final int KEY_EAB_PROVISIONING_STATUS = 25;
443 
444     /**
445      * Override the user-defined WiFi Roaming enabled setting for this subscription, defined in
446      * {@link SubscriptionManager#WFC_ROAMING_ENABLED_CONTENT_URI}, for the purposes of provisioning
447      * the subscription for WiFi Calling.
448      *
449      * @see #getProvisioningIntValue(int)
450      * @see #setProvisioningIntValue(int, int)
451      */
452     public static final int KEY_VOICE_OVER_WIFI_ROAMING_ENABLED_OVERRIDE = 26;
453 
454     /**
455      * Override the user-defined WiFi mode for this subscription, defined in
456      * {@link SubscriptionManager#WFC_MODE_CONTENT_URI}, for the purposes of provisioning
457      * this subscription for WiFi Calling.
458      *
459      * Valid values for this key are:
460      * {@link ImsMmTelManager#WIFI_MODE_WIFI_ONLY},
461      * {@link ImsMmTelManager#WIFI_MODE_CELLULAR_PREFERRED}, or
462      * {@link ImsMmTelManager#WIFI_MODE_WIFI_PREFERRED}.
463      *
464      * @see #getProvisioningIntValue(int)
465      * @see #setProvisioningIntValue(int, int)
466      */
467     public static final int KEY_VOICE_OVER_WIFI_MODE_OVERRIDE = 27;
468 
469     /**
470      * Enable voice over wifi.  Enabled (1), or Disabled (0).
471      * Value is in Integer format.
472      * @see #setProvisioningIntValue(int, int)
473      * @see #getProvisioningIntValue(int)
474      * @hide
475      */
476     public static final int KEY_VOICE_OVER_WIFI_ENABLED_OVERRIDE = 28;
477 
478     /**
479      * Mobile data enabled.
480      * Value is in Integer format. On (1), OFF(0).
481      * @see #setProvisioningIntValue(int, int)
482      * @see #getProvisioningIntValue(int)
483      * @hide
484      */
485     public static final int KEY_MOBILE_DATA_ENABLED = 29;
486 
487     /**
488      * VoLTE user opted in status.
489      * Value is in Integer format. Opted-in (1) Opted-out (0).
490      * @see #setProvisioningIntValue(int, int)
491      * @see #getProvisioningIntValue(int)
492      * @hide
493      */
494     public static final int KEY_VOLTE_USER_OPT_IN_STATUS = 30;
495 
496     /**
497      * Proxy for Call Session Control Function(P-CSCF) address for Local-BreakOut(LBO).
498      * Value is in String format.
499      * @hide
500      */
501     public static final int KEY_LOCAL_BREAKOUT_PCSCF_ADDRESS = 31;
502 
503     /**
504      * Keep Alive Enabled for SIP.
505      * Value is in Integer format.
506      * @see #setProvisioningIntValue(int, int)
507      * @see #getProvisioningIntValue(int)
508      * @hide
509      */
510     public static final int KEY_SIP_KEEP_ALIVE_ENABLED = 32;
511 
512     /**
513      * Registration retry Base Time value in seconds, which is based off of the carrier
514      * configuration.
515      * Value is in Integer format.
516      * @see #setProvisioningIntValue(int, int)
517      * @see #getProvisioningIntValue(int)
518      * @hide
519      */
520     public static final int KEY_REGISTRATION_RETRY_BASE_TIME_SEC = 33;
521 
522     /**
523      * Registration retry Max Time value in seconds, which is based off of the carrier
524      * configuration.
525      * Value is in Integer format.
526      * @see #setProvisioningIntValue(int, int)
527      * @see #getProvisioningIntValue(int)
528      * @hide
529      */
530     public static final int KEY_REGISTRATION_RETRY_MAX_TIME_SEC = 34;
531 
532     /**
533      * Smallest RTP port for speech codec.
534      * Value is in integer format.
535      * @see #setProvisioningIntValue(int, int)
536      * @see #getProvisioningIntValue(int)
537      * @hide
538      */
539 
540     public static final int KEY_RTP_SPEECH_START_PORT = 35;
541 
542     /**
543      * Largest RTP port for speech code.
544      * Value is in Integer format.
545      * @see #setProvisioningIntValue(int, int)
546      * @see #getProvisioningIntValue(int)
547      * @hide
548      */
549     public static final int KEY_RTP_SPEECH_END_PORT = 36;
550 
551     /**
552      * SIP Timer A's value in milliseconds. Timer A is the INVITE request retransmit interval (in
553      * milliseconds), for UDP only.
554      * Value is in Integer format.
555      * @see #setProvisioningIntValue(int, int)
556      * @see #getProvisioningIntValue(int)
557      * @hide
558      */
559     public static final int KEY_SIP_INVITE_REQUEST_TRANSMIT_INTERVAL_MS = 37;
560 
561     /**
562      * SIP Timer B's value in milliseconds. Timer B is the wait time for INVITE message to be,
563      * in milliseconds.
564      * Value is in Integer format.
565      * @see #setProvisioningIntValue(int, int)
566      * @see #getProvisioningIntValue(int)
567      * @hide
568      */
569     public static final int KEY_SIP_INVITE_ACK_WAIT_TIME_MS = 38;
570 
571     /**
572      * SIP Timer D's value in milliseconds. Timer D is the wait time for response retransmits of
573      * the invite client transactions, in milliseconds.
574      * Value is in Integer format.
575      * @see #setProvisioningIntValue(int, int)
576      * @see #getProvisioningIntValue(int)
577      * @hide
578      */
579     public static final int KEY_SIP_INVITE_RESPONSE_RETRANSMIT_WAIT_TIME_MS = 39;
580 
581     /**
582      * SIP Timer E's value in milliseconds. Timer E is the value Non-INVITE request retransmit
583      * interval (in milliseconds), for UDP only.
584      * Value is in Integer format.
585      * @see #setProvisioningIntValue(int, int)
586      * @see #getProvisioningIntValue(int)
587      * @hide
588      */
589     public static final int KEY_SIP_NON_INVITE_REQUEST_RETRANSMIT_INTERVAL_MS = 40;
590 
591     /**
592      * SIP Timer F's value in milliseconds. Timer F is the Non-INVITE transaction timeout timer,
593      * in milliseconds.
594      * Value is in Integer format.
595      * @see #setProvisioningIntValue(int, int)
596      * @see #getProvisioningIntValue(int)
597      * @hide
598      */
599     public static final int KEY_SIP_NON_INVITE_TRANSACTION_TIMEOUT_TIMER_MS = 41;
600 
601     /**
602      * SIP Timer G's value in milliseconds. Timer G is the value of INVITE response
603      * retransmit interval.
604      * Value is in Integer format.
605      * @see #setProvisioningIntValue(int, int)
606      * @see #getProvisioningIntValue(int)
607      * @hide
608      */
609     public static final int KEY_SIP_INVITE_RESPONSE_RETRANSMIT_INTERVAL_MS = 42;
610 
611     /**
612      * SIP Timer H's value in milliseconds. Timer H is the value of wait time for
613      * ACK receipt.
614      * Value is in Integer format.
615      * @see #setProvisioningIntValue(int, int)
616      * @see #getProvisioningIntValue(int)
617      * @hide
618      */
619     public static final int KEY_SIP_ACK_RECEIPT_WAIT_TIME_MS = 43;
620 
621     /**
622      * SIP Timer I's value in milliseconds. Timer I is the value of wait time for
623      * ACK retransmits.
624      * Value is in Integer format.
625      * @see #setProvisioningIntValue(int, int)
626      * @see #getProvisioningIntValue(int)
627      * @hide
628      */
629     public static final int KEY_SIP_ACK_RETRANSMIT_WAIT_TIME_MS = 44;
630 
631     /**
632      * SIP Timer J's value in milliseconds. Timer J is the value of wait time for
633      * non-invite request retransmission.
634      * Value is in Integer format.
635      * @see #setProvisioningIntValue(int, int)
636      * @see #getProvisioningIntValue(int)
637      * @hide
638      */
639     public static final int KEY_SIP_NON_INVITE_REQUEST_RETRANSMISSION_WAIT_TIME_MS = 45;
640 
641     /**
642      * SIP Timer K's value in milliseconds. Timer K is the value of wait time for
643      * non-invite response retransmits.
644      * Value is in Integer format.
645      * @see #setProvisioningIntValue(int, int)
646      * @see #getProvisioningIntValue(int)
647      * @hide
648      */
649     public static final int KEY_SIP_NON_INVITE_RESPONSE_RETRANSMISSION_WAIT_TIME_MS = 46;
650 
651     /**
652      * AMR WB octet aligned dynamic payload type.
653      * Value is in Integer format.
654      * @see #setProvisioningIntValue(int, int)
655      * @see #getProvisioningIntValue(int)
656      * @hide
657      */
658     public static final int KEY_AMR_WB_OCTET_ALIGNED_PAYLOAD_TYPE = 47;
659 
660     /**
661      * AMR WB bandwidth efficient payload type.
662      * Value is in Integer format.
663      * @see #setProvisioningIntValue(int, int)
664      * @see #getProvisioningIntValue(int)
665      * @hide
666      */
667     public static final int KEY_AMR_WB_BANDWIDTH_EFFICIENT_PAYLOAD_TYPE = 48;
668 
669     /**
670      * AMR octet aligned dynamic payload type.
671      * Value is in Integer format.
672      * @see #setProvisioningIntValue(int, int)
673      * @see #getProvisioningIntValue(int)
674      * @hide
675      */
676     public static final int KEY_AMR_OCTET_ALIGNED_PAYLOAD_TYPE = 49;
677 
678     /**
679      * AMR bandwidth efficient payload type.
680      * Value is in Integer format.
681      * @see #setProvisioningIntValue(int, int)
682      * @see #getProvisioningIntValue(int)
683      * @hide
684      */
685     public static final int KEY_AMR_BANDWIDTH_EFFICIENT_PAYLOAD_TYPE = 50;
686 
687     /**
688      * DTMF WB payload type.
689      * Value is in Integer format.
690      * @see #setProvisioningIntValue(int, int)
691      * @see #getProvisioningIntValue(int)
692      * @hide
693      */
694     public static final int KEY_DTMF_WB_PAYLOAD_TYPE = 51;
695 
696     /**
697      * DTMF NB payload type.
698      * Value is in Integer format.
699      * @see #setProvisioningIntValue(int, int)
700      * @see #getProvisioningIntValue(int)
701      * @hide
702      */
703     public static final int KEY_DTMF_NB_PAYLOAD_TYPE = 52;
704 
705     /**
706      * AMR Default encoding mode.
707      * Value is in Integer format.
708      * @see #setProvisioningIntValue(int, int)
709      * @see #getProvisioningIntValue(int)
710      * @hide
711      */
712     public static final int KEY_AMR_DEFAULT_ENCODING_MODE = 53;
713 
714     /**
715      * SMS Public Service Identity.
716      * Value is in String format.
717      * @hide
718      */
719     public static final int KEY_SMS_PUBLIC_SERVICE_IDENTITY = 54;
720 
721     /**
722      * Video Quality - VideoQualityFeatureValuesConstants.
723      * Valid values are: {@link #VIDEO_QUALITY_HIGH} and {@link #VIDEO_QUALITY_LOW}.
724      * Value is in Integer format.
725      * @see #setProvisioningIntValue(int, int)
726      * @see #getProvisioningIntValue(int)
727      * @hide
728      */
729     public static final int KEY_VIDEO_QUALITY = 55;
730 
731     /**
732      * Used with {@link #KEY_VIDEO_QUALITY} to indicate low video quality.
733      * @hide
734      */
735     public static final int VIDEO_QUALITY_LOW = 0;
736 
737     /**
738      * Used with {@link #KEY_VIDEO_QUALITY} to indicate high video quality.
739      * @hide
740      */
741     public static final int VIDEO_QUALITY_HIGH = 1;
742 
743     /**
744      * LTE to WIFI handover threshold.
745      * Handover from LTE to WiFi if LTE < THLTE1 and WiFi >= {@link #KEY_WIFI_THRESHOLD_A}.
746      * Value is in Integer format.
747      * @see #setProvisioningIntValue(int, int)
748      * @see #getProvisioningIntValue(int)
749      * @hide
750      */
751     public static final int KEY_LTE_THRESHOLD_1 = 56;
752 
753     /**
754      * WIFI to LTE handover threshold.
755      * Handover from WiFi to LTE if LTE >= {@link #KEY_LTE_THRESHOLD_3} or (WiFi < {@link
756      * #KEY_WIFI_THRESHOLD_B} and LTE >= {@link #KEY_LTE_THRESHOLD_2}).
757      * Value is in Integer format.
758      *
759      * @see #setProvisioningIntValue(int, int)
760      * @see #getProvisioningIntValue(int)
761      * @hide
762      */
763     public static final int KEY_LTE_THRESHOLD_2 = 57;
764 
765     /**
766      * LTE to WIFI handover threshold.
767      * Handover from WiFi to LTE if LTE >= {@link #KEY_LTE_THRESHOLD_3} or (WiFi < {@link
768      * #KEY_WIFI_THRESHOLD_B} and LTE >= {@link #KEY_LTE_THRESHOLD_2}).
769      * Value is in Integer format.
770      *
771      * @see #setProvisioningIntValue(int, int)
772      * @see #getProvisioningIntValue(int)
773      * @hide
774      */
775     public static final int KEY_LTE_THRESHOLD_3 = 58;
776 
777     /**
778      * 1x to WIFI handover threshold.
779      * Handover from 1x to WiFi if 1x < {@link #KEY_1X_THRESHOLD}.
780      * Value is in Integer format.
781      * @see #setProvisioningIntValue(int, int)
782      * @see #getProvisioningIntValue(int)
783      * @hide
784      */
785     public static final int KEY_1X_THRESHOLD = 59;
786 
787     /**
788      * LTE to WIFI threshold A.
789      * Handover from LTE to WiFi if LTE < {@link #KEY_LTE_THRESHOLD_1} and WiFi >= {@link
790      * #KEY_WIFI_THRESHOLD_A}.
791      * Value is in Integer format.
792      *
793      * @see #setProvisioningIntValue(int, int)
794      * @see #getProvisioningIntValue(int)
795      * @hide
796      */
797     public static final int KEY_WIFI_THRESHOLD_A = 60;
798 
799     /**
800      * WiFi to LTRE handover threshold B.
801      * Handover from WiFi to LTE if LTE >= {@link #KEY_LTE_THRESHOLD_3} or (WiFi <
802      * {@link #KEY_WIFI_THRESHOLD_B} and LTE >= {@link #KEY_LTE_THRESHOLD_2}).
803      * Value is in Integer format.
804      * @see #setProvisioningIntValue(int, int)
805      * @see #getProvisioningIntValue(int)
806      * @hide
807      */
808     public static final int KEY_WIFI_THRESHOLD_B = 61;
809 
810     /**
811      * LTE ePDG timer (in seconds).
812      * Device shall not handover back to LTE until the T_ePDG_LTE timer expires.
813      * Value is in Integer format.
814      * @see #setProvisioningIntValue(int, int)
815      * @see #getProvisioningIntValue(int)
816      * @hide
817      */
818     public static final int KEY_LTE_EPDG_TIMER_SEC = 62;
819 
820     /**
821      * WiFi ePDG timer (in seconds).
822      * Device shall not handover back to WiFi until the T_ePDG_WiFi timer expires.
823      * Value is in Integer format.
824      * @see #setProvisioningIntValue(int, int)
825      * @see #getProvisioningIntValue(int)
826      * @hide
827      */
828     public static final int KEY_WIFI_EPDG_TIMER_SEC = 63;
829 
830     /**
831      * 1x ePDG timer (in seconds).
832      * Device shall not re-register on 1x until the T_ePDG_1x timer expires.
833      * @hide
834      */
835     public static final int KEY_1X_EPDG_TIMER_SEC = 64;
836 
837     /**
838      * MultiEndpoint status: Enabled (1), or Disabled (0).
839      * Value is in Integer format.
840      * @see #setProvisioningIntValue(int, int)
841      * @see #getProvisioningIntValue(int)
842      * @hide
843      */
844     public static final int KEY_MULTIENDPOINT_ENABLED = 65;
845 
846     /**
847      * RTT status: Enabled (1), or Disabled (0).
848      * Value is in Integer format.
849      * @see #setProvisioningIntValue(int, int)
850      * @see #getProvisioningIntValue(int)
851      * @hide
852      */
853     public static final int KEY_RTT_ENABLED = 66;
854 
855     /**
856      * An obfuscated string defined by the carrier to indicate VoWiFi entitlement status.
857      *
858      * <p>Implementation note: how to generate the value and how it affects VoWiFi service
859      * should follow carrier requirements. For example, set an empty string could result in
860      * VoWiFi being disabled by IMS service, and set to a specific string could enable.
861      *
862      * <p>Value is in String format.
863      * @see #setProvisioningStringValue(int, String)
864      * @see #getProvisioningStringValue(int)
865      */
866     public static final int KEY_VOICE_OVER_WIFI_ENTITLEMENT_ID = 67;
867 
868     /**
869      * An integer key representing the voice over IMS opt-in provisioning status for the
870      * associated subscription. Determines whether the user can see for voice services over
871      * IMS.
872      *
873      * <p> The flag will force to show the VoLTE option in settings irrespective of others VoLTE
874      * carrier config which hide the VoLTE option (e.g.
875      * {@link CarrierConfigManager#KEY_HIDE_ENHANCED_4G_LTE_BOOL}).
876      *
877      * <p>Use {@link #PROVISIONING_VALUE_ENABLED} to enable VoIMS provisioning and
878      * {@link #PROVISIONING_VALUE_DISABLED} to disable VoIMS  provisioning.
879      * @see #setProvisioningIntValue(int, int)
880      * @see #getProvisioningIntValue(int)
881      * @hide
882      */
883     public static final int KEY_VOIMS_OPT_IN_STATUS = 68;
884 
885     /**
886      * Callback for IMS provisioning changes.
887      */
888     public static class Callback {
889 
890         private static class CallbackBinder extends IImsConfigCallback.Stub {
891 
892             private final Callback mLocalConfigurationCallback;
893             private Executor mExecutor;
894 
CallbackBinder(Callback localConfigurationCallback)895             private CallbackBinder(Callback localConfigurationCallback) {
896                 mLocalConfigurationCallback = localConfigurationCallback;
897             }
898 
899             @Override
onIntConfigChanged(int item, int value)900             public final void onIntConfigChanged(int item, int value) {
901                 final long callingIdentity = Binder.clearCallingIdentity();
902                 try {
903                     mExecutor.execute(() ->
904                             mLocalConfigurationCallback.onProvisioningIntChanged(item, value));
905                 } finally {
906                     restoreCallingIdentity(callingIdentity);
907                 }
908             }
909 
910             @Override
onStringConfigChanged(int item, String value)911             public final void onStringConfigChanged(int item, String value) {
912                 final long callingIdentity = Binder.clearCallingIdentity();
913                 try {
914                     mExecutor.execute(() ->
915                             mLocalConfigurationCallback.onProvisioningStringChanged(item, value));
916                 } finally {
917                     restoreCallingIdentity(callingIdentity);
918                 }
919             }
920 
setExecutor(Executor executor)921             private void setExecutor(Executor executor) {
922                 mExecutor = executor;
923             }
924         }
925 
926         private final CallbackBinder mBinder = new CallbackBinder(this);
927 
928         /**
929          * Called when a provisioning item has changed.
930          * @param item the IMS provisioning key constant, as defined by the OEM.
931          * @param value the new integer value of the IMS provisioning key.
932          */
onProvisioningIntChanged(int item, int value)933         public void onProvisioningIntChanged(int item, int value) {
934             // Base Implementation
935         }
936 
937         /**
938          * Called when a provisioning item has changed.
939          * @param item the IMS provisioning key constant, as defined by the OEM.
940          * @param value the new String value of the IMS configuration constant.
941          */
onProvisioningStringChanged(int item, @NonNull String value)942         public void onProvisioningStringChanged(int item, @NonNull String value) {
943             // Base Implementation
944         }
945 
946         /**@hide*/
getBinder()947         public final IImsConfigCallback getBinder() {
948             return mBinder;
949         }
950 
951         /**@hide*/
setExecutor(Executor executor)952         public void setExecutor(Executor executor) {
953             mBinder.setExecutor(executor);
954         }
955     }
956 
957     private int mSubId;
958 
959     /**
960      * The callback for RCS provisioning changes.
961      */
962     public static class RcsProvisioningCallback {
963         private static class CallbackBinder extends IRcsConfigCallback.Stub {
964 
965             private final RcsProvisioningCallback mLocalCallback;
966             private Executor mExecutor;
967 
CallbackBinder(RcsProvisioningCallback localCallback)968             private CallbackBinder(RcsProvisioningCallback localCallback) {
969                 mLocalCallback = localCallback;
970             }
971 
972             @Override
onConfigurationChanged(byte[] configXml)973             public void onConfigurationChanged(byte[] configXml) {
974                 final long identity = Binder.clearCallingIdentity();
975                 try {
976                     mExecutor.execute(() -> mLocalCallback.onConfigurationChanged(configXml));
977                 } finally {
978                     Binder.restoreCallingIdentity(identity);
979                 }
980             }
981 
982             @Override
onAutoConfigurationErrorReceived(int errorCode, String errorString)983             public void onAutoConfigurationErrorReceived(int errorCode, String errorString) {
984                 final long identity = Binder.clearCallingIdentity();
985                 try {
986                     mExecutor.execute(() -> mLocalCallback.onAutoConfigurationErrorReceived(
987                             errorCode, errorString));
988                 } finally {
989                     Binder.restoreCallingIdentity(identity);
990                 }
991             }
992 
993             @Override
onConfigurationReset()994             public void onConfigurationReset() {
995                 final long identity = Binder.clearCallingIdentity();
996                 try {
997                     mExecutor.execute(() -> mLocalCallback.onConfigurationReset());
998                 } finally {
999                     Binder.restoreCallingIdentity(identity);
1000                 }
1001             }
1002 
1003             @Override
onRemoved()1004             public void onRemoved() {
1005                 final long identity = Binder.clearCallingIdentity();
1006                 try {
1007                     mExecutor.execute(() -> mLocalCallback.onRemoved());
1008                 } finally {
1009                     Binder.restoreCallingIdentity(identity);
1010                 }
1011             }
1012 
1013             @Override
onPreProvisioningReceived(byte[] configXml)1014             public void onPreProvisioningReceived(byte[] configXml) {
1015                 final long identity = Binder.clearCallingIdentity();
1016                 try {
1017                     mExecutor.execute(() -> mLocalCallback.onPreProvisioningReceived(configXml));
1018                 } finally {
1019                     Binder.restoreCallingIdentity(identity);
1020                 }
1021             }
1022 
setExecutor(Executor executor)1023             private void setExecutor(Executor executor) {
1024                 mExecutor = executor;
1025             }
1026         }
1027 
1028         private final CallbackBinder mBinder = new CallbackBinder(this);
1029 
1030         /**
1031          * RCS configuration received via OTA provisioning. Configuration may change
1032          * due to various triggers defined in GSMA RCC.14 for ACS(auto configuration
1033          * server) or other operator defined triggers. If RCS provisioning is already
1034          * completed at the time of callback registration, then this method shall be
1035          * invoked with the current configuration.
1036          * @param configXml The RCS configuration XML received by OTA. It is defined
1037          * by GSMA RCC.07.
1038          */
onConfigurationChanged(@onNull byte[] configXml)1039         public void onConfigurationChanged(@NonNull byte[] configXml) {}
1040 
1041         /**
1042          * Errors during autoconfiguration connection setup are notified by the
1043          * ACS(auto configuration server) client using this interface.
1044          * @param errorCode HTTP error received during connection setup defined in
1045          * GSMA RCC.14 2.4.3, like {@link java.net.HttpURLConnection#HTTP_UNAUTHORIZED},
1046          * {@link java.net.HttpURLConnection#HTTP_FORBIDDEN}, etc.
1047          * @param errorString reason phrase received with the error
1048          */
onAutoConfigurationErrorReceived(int errorCode, @NonNull String errorString)1049         public void onAutoConfigurationErrorReceived(int errorCode,
1050                 @NonNull String errorString) {}
1051 
1052         /**
1053          * When the previously valid RCS configuration is cleaned up by telephony for
1054          * any case like SIM removed, default messaging application changed, etc.,
1055          * this method will be invoked to notify the application regarding this change.
1056          */
onConfigurationReset()1057         public void onConfigurationReset() {}
1058 
1059         /**
1060          * When the RCS application is no longer the Default messaging application,
1061          * or when the subscription associated with this callback is removed (SIM
1062          * removed, ESIM swap,etc...), callback will automatically be removed and
1063          * the below method is invoked. There is a possibility that the method is
1064          * invoked after the subscription has become inactive
1065          */
onRemoved()1066         public void onRemoved() {}
1067 
1068         /**
1069          * Some carriers using ACS (auto configuration server) may send a carrier-specific
1070          * pre-provisioning configuration XML if the user has not been provisioned for RCS
1071          * services yet. When this provisioning XML is received, the framework will move
1072          * into a "not provisioned" state for RCS. In order for provisioning to proceed,
1073          * the application must parse this configuration XML and perform the carrier specific
1074          * opt-in flow for RCS services. If the user accepts, {@link #triggerRcsReconfiguration}
1075          * must be called in order for the device to move out of this state and try to fetch
1076          * the RCS provisioning information.
1077          *
1078          * @param configXml the pre-provisioning config in carrier specified format.
1079          */
onPreProvisioningReceived(@onNull byte[] configXml)1080         public void onPreProvisioningReceived(@NonNull byte[] configXml) {}
1081 
1082         /**@hide*/
getBinder()1083         public final IRcsConfigCallback getBinder() {
1084             return mBinder;
1085         }
1086 
1087         /**@hide*/
setExecutor(Executor executor)1088         public void setExecutor(Executor executor) {
1089             mBinder.setExecutor(executor);
1090         }
1091     }
1092 
1093     /**
1094      * Create a new {@link ProvisioningManager} for the subscription specified.
1095      *
1096      * @param subId The ID of the subscription that this ProvisioningManager will use.
1097      * @see android.telephony.SubscriptionManager#getActiveSubscriptionInfoList()
1098      * @throws IllegalArgumentException if the subscription is invalid.
1099      */
createForSubscriptionId(int subId)1100     public static @NonNull ProvisioningManager createForSubscriptionId(int subId) {
1101         if (!SubscriptionManager.isValidSubscriptionId(subId)) {
1102             throw new IllegalArgumentException("Invalid subscription ID");
1103         }
1104 
1105         return new ProvisioningManager(subId);
1106     }
1107 
ProvisioningManager(int subId)1108     private ProvisioningManager(int subId) {
1109         mSubId = subId;
1110     }
1111 
1112     /**
1113      * Register a new {@link Callback} to listen to changes to changes in IMS provisioning.
1114      *
1115      * When the subscription associated with this callback is removed (SIM removed, ESIM swap,
1116      * etc...), this callback will automatically be removed.
1117      * @param executor The {@link Executor} to call the callback methods on
1118      * @param callback The provisioning callbackto be registered.
1119      * @see #unregisterProvisioningChangedCallback(Callback)
1120      * @see SubscriptionManager.OnSubscriptionsChangedListener
1121      * @throws IllegalArgumentException if the subscription associated with this callback is not
1122      * active (SIM is not inserted, ESIM inactive) or the subscription is invalid.
1123      * @throws ImsException if the subscription associated with this callback is valid, but
1124      * the {@link ImsService} associated with the subscription is not available. This can happen if
1125      * the service crashed, for example. See {@link ImsException#getCode()} for a more detailed
1126      * reason.
1127      */
1128     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
registerProvisioningChangedCallback(@onNull @allbackExecutor Executor executor, @NonNull Callback callback)1129     public void registerProvisioningChangedCallback(@NonNull @CallbackExecutor Executor executor,
1130             @NonNull Callback callback) throws ImsException {
1131         callback.setExecutor(executor);
1132         try {
1133             getITelephony().registerImsProvisioningChangedCallback(mSubId, callback.getBinder());
1134         } catch (ServiceSpecificException e) {
1135             throw new ImsException(e.getMessage(), e.errorCode);
1136         } catch (RemoteException | IllegalStateException e) {
1137             throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
1138         }
1139     }
1140 
1141     /**
1142      * Unregister an existing {@link Callback}. When the subscription associated with this
1143      * callback is removed (SIM removed, ESIM swap, etc...), this callback will automatically be
1144      * removed. If this method is called for an inactive subscription, it will result in a no-op.
1145      * @param callback The existing {@link Callback} to be removed.
1146      * @see #registerProvisioningChangedCallback(Executor, Callback)
1147      *
1148      * @throws IllegalArgumentException if the subscription associated with this callback is
1149      * invalid.
1150      */
1151     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
unregisterProvisioningChangedCallback(@onNull Callback callback)1152     public void unregisterProvisioningChangedCallback(@NonNull Callback callback) {
1153         try {
1154             getITelephony().unregisterImsProvisioningChangedCallback(mSubId, callback.getBinder());
1155         } catch (RemoteException e) {
1156             throw e.rethrowAsRuntimeException();
1157         }
1158     }
1159 
1160     /**
1161      * Query for the integer value associated with the provided key.
1162      *
1163      * This operation is blocking and should not be performed on the UI thread.
1164      *
1165      * @param key An integer that represents the provisioning key, which is defined by the OEM.
1166      * @return an integer value for the provided key, or
1167      * {@link ImsConfigImplBase#CONFIG_RESULT_UNKNOWN} if the key doesn't exist.
1168      * @throws IllegalArgumentException if the key provided was invalid.
1169      */
1170     @WorkerThread
1171     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
getProvisioningIntValue(int key)1172     public int getProvisioningIntValue(int key) {
1173         try {
1174             return getITelephony().getImsProvisioningInt(mSubId, key);
1175         } catch (RemoteException e) {
1176             throw e.rethrowAsRuntimeException();
1177         }
1178     }
1179 
1180     /**
1181      * Query for the String value associated with the provided key.
1182      *
1183      * This operation is blocking and should not be performed on the UI thread.
1184      *
1185      * @param key A String that represents the provisioning key, which is defined by the OEM.
1186      * @return a String value for the provided key, {@code null} if the key doesn't exist, or
1187      * {@link StringResultError} if there was an error getting the value for the provided key.
1188      * @throws IllegalArgumentException if the key provided was invalid.
1189      */
1190     @WorkerThread
1191     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
getProvisioningStringValue(int key)1192     public @Nullable @StringResultError String getProvisioningStringValue(int key) {
1193         try {
1194             return getITelephony().getImsProvisioningString(mSubId, key);
1195         } catch (RemoteException e) {
1196             throw e.rethrowAsRuntimeException();
1197         }
1198     }
1199 
1200     /**
1201      * Set the integer value associated with the provided key.
1202      *
1203      * This operation is blocking and should not be performed on the UI thread.
1204      *
1205      * Use {@link #setProvisioningStringValue(int, String)} with proper namespacing (to be defined
1206      * per OEM or carrier) when possible instead to avoid key collision if needed.
1207      * @param key An integer that represents the provisioning key, which is defined by the OEM.
1208      * @param value a integer value for the provided key.
1209      * @return the result of setting the configuration value.
1210      */
1211     @WorkerThread
1212     @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
setProvisioningIntValue(int key, int value)1213     public @ImsConfigImplBase.SetConfigResult int setProvisioningIntValue(int key, int value) {
1214         try {
1215             return getITelephony().setImsProvisioningInt(mSubId, key, value);
1216         } catch (RemoteException e) {
1217             throw e.rethrowAsRuntimeException();
1218         }
1219     }
1220 
1221     /**
1222      * Set the String value associated with the provided key.
1223      *
1224      * This operation is blocking and should not be performed on the UI thread.
1225      *
1226      * @param key A String that represents the provisioning key, which is defined by the OEM and
1227      *     should be appropriately namespaced to avoid collision.
1228      * @param value a String value for the provided key.
1229      * @return the result of setting the configuration value.
1230      */
1231     @WorkerThread
1232     @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
setProvisioningStringValue(int key, @NonNull String value)1233     public @ImsConfigImplBase.SetConfigResult int setProvisioningStringValue(int key,
1234             @NonNull String value) {
1235         try {
1236             return getITelephony().setImsProvisioningString(mSubId, key, value);
1237         } catch (RemoteException e) {
1238             throw e.rethrowAsRuntimeException();
1239         }
1240     }
1241 
1242     /**
1243      * Set the provisioning status for the IMS MmTel capability using the specified subscription.
1244      *
1245      * Provisioning may or may not be required, depending on the carrier configuration. If
1246      * provisioning is not required for the carrier associated with this subscription or the device
1247      * does not support the capability/technology combination specified, this operation will be a
1248      * no-op.
1249      *
1250      * @see CarrierConfigManager#KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL
1251      * @see CarrierConfigManager#KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL
1252      * @param isProvisioned true if the device is provisioned for UT over IMS, false otherwise.
1253      */
1254     @WorkerThread
1255     @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
setProvisioningStatusForCapability( @mTelFeature.MmTelCapabilities.MmTelCapability int capability, @ImsRegistrationImplBase.ImsRegistrationTech int tech, boolean isProvisioned)1256     public void setProvisioningStatusForCapability(
1257             @MmTelFeature.MmTelCapabilities.MmTelCapability int capability,
1258             @ImsRegistrationImplBase.ImsRegistrationTech int tech,  boolean isProvisioned) {
1259         try {
1260             getITelephony().setImsProvisioningStatusForCapability(mSubId, capability, tech,
1261                     isProvisioned);
1262         } catch (RemoteException e) {
1263             throw e.rethrowAsRuntimeException();
1264         }
1265     }
1266 
1267     /**
1268      * Get the provisioning status for the IMS MmTel capability specified.
1269      *
1270      * If provisioning is not required for the queried
1271      * {@link MmTelFeature.MmTelCapabilities.MmTelCapability} and
1272      * {@link ImsRegistrationImplBase.ImsRegistrationTech} combination specified, this method will
1273      * always return {@code true}.
1274      *
1275      * @see CarrierConfigManager#KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL
1276      * @see CarrierConfigManager#KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL
1277      * @return true if the device is provisioned for the capability or does not require
1278      * provisioning, false if the capability does require provisioning and has not been
1279      * provisioned yet.
1280      */
1281     @WorkerThread
1282     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
getProvisioningStatusForCapability( @mTelFeature.MmTelCapabilities.MmTelCapability int capability, @ImsRegistrationImplBase.ImsRegistrationTech int tech)1283     public boolean getProvisioningStatusForCapability(
1284             @MmTelFeature.MmTelCapabilities.MmTelCapability int capability,
1285             @ImsRegistrationImplBase.ImsRegistrationTech int tech) {
1286         try {
1287             return getITelephony().getImsProvisioningStatusForCapability(mSubId, capability, tech);
1288         } catch (RemoteException e) {
1289             throw e.rethrowAsRuntimeException();
1290         }
1291     }
1292 
1293     /**
1294      * Get the provisioning status for the IMS RCS capability specified.
1295      *
1296      * If provisioning is not required for the queried
1297      * {@link RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag} this method will always return
1298      * {@code true}.
1299      *
1300      * @see CarrierConfigManager#KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL
1301      * @return true if the device is provisioned for the capability or does not require
1302      * provisioning, false if the capability does require provisioning and has not been
1303      * provisioned yet.
1304      */
1305     @WorkerThread
1306     @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
getRcsProvisioningStatusForCapability( @csFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability)1307     public boolean getRcsProvisioningStatusForCapability(
1308             @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability) {
1309         try {
1310             return getITelephony().getRcsProvisioningStatusForCapability(mSubId, capability);
1311         } catch (RemoteException e) {
1312             throw e.rethrowAsRuntimeException();
1313         }
1314     }
1315 
1316     /**
1317      * Set the provisioning status for the IMS RCS capability using the specified subscription.
1318      *
1319      * Provisioning may or may not be required, depending on the carrier configuration. If
1320      * provisioning is not required for the carrier associated with this subscription or the device
1321      * does not support the capability/technology combination specified, this operation will be a
1322      * no-op.
1323      *
1324      * @see CarrierConfigManager#KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL
1325      * @param isProvisioned true if the device is provisioned for the RCS capability specified,
1326      *                      false otherwise.
1327      */
1328     @WorkerThread
1329     @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
setRcsProvisioningStatusForCapability( @csFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability, boolean isProvisioned)1330     public void setRcsProvisioningStatusForCapability(
1331             @RcsFeature.RcsImsCapabilities.RcsImsCapabilityFlag int capability,
1332             boolean isProvisioned) {
1333         try {
1334             getITelephony().setRcsProvisioningStatusForCapability(mSubId, capability,
1335                     isProvisioned);
1336         } catch (RemoteException e) {
1337             throw e.rethrowAsRuntimeException();
1338         }
1339     }
1340 
1341     /**
1342      * Notify the framework that an RCS autoconfiguration XML file has been received for
1343      * provisioning.
1344      * <p>
1345      * Requires Permission: Manifest.permission.MODIFY_PHONE_STATE or that the calling app has
1346      * carrier privileges (see {@link TelephonyManager#hasCarrierPrivileges}).
1347      * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed.
1348      * @param isCompressed The XML file is compressed in gzip format and must be decompressed
1349      *         before being read.
1350      *
1351      */
1352     @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE)
notifyRcsAutoConfigurationReceived(@onNull byte[] config, boolean isCompressed)1353     public void notifyRcsAutoConfigurationReceived(@NonNull byte[] config, boolean isCompressed) {
1354         if (config == null) {
1355             throw new IllegalArgumentException("Must include a non-null config XML file.");
1356         }
1357         try {
1358             getITelephony().notifyRcsAutoConfigurationReceived(mSubId, config, isCompressed);
1359         } catch (RemoteException e) {
1360             throw e.rethrowAsRuntimeException();
1361         }
1362 
1363     }
1364 
1365     /**
1366      * Provides the single registration capability of the device and the carrier.
1367      *
1368      * <p>This intent only provides the capability and not the current provisioning status of
1369      * the RCS VoLTE single registration feature. Only default messaging application may receive
1370      * the intent.
1371      *
1372      * <p>Contains {@link #EXTRA_SUBSCRIPTION_ID} to specify the subscription index for which
1373      * the intent is valid. and {@link #EXTRA_STATUS} to specify RCS VoLTE single registration
1374      * status.
1375      */
1376     @RequiresPermission(Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION)
1377     @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION)
1378     public static final String ACTION_RCS_SINGLE_REGISTRATION_CAPABILITY_UPDATE =
1379             "android.telephony.ims.action.RCS_SINGLE_REGISTRATION_CAPABILITY_UPDATE";
1380 
1381     /**
1382      * Integer extra to specify subscription index.
1383      */
1384     public static final String EXTRA_SUBSCRIPTION_ID =
1385             "android.telephony.ims.extra.SUBSCRIPTION_ID";
1386 
1387     /**
1388      * Integer extra to specify RCS single registration status
1389      *
1390      * <p>The value can be {@link #STATUS_CAPABLE}, {@link #STATUS_DEVICE_NOT_CAPABLE},
1391      * {@link #STATUS_CARRIER_NOT_CAPABLE}, or bitwise OR of
1392      * {@link #STATUS_DEVICE_NOT_CAPABLE} and {@link #STATUS_CARRIER_NOT_CAPABLE}.
1393      */
1394     public static final String EXTRA_STATUS = "android.telephony.ims.extra.STATUS";
1395 
1396     /**
1397      * RCS VoLTE single registration is supported by the device and carrier.
1398      */
1399     public static final int STATUS_CAPABLE                       = 0;
1400 
1401     /**
1402      * RCS VoLTE single registration is not supported by the device.
1403      */
1404     public static final int STATUS_DEVICE_NOT_CAPABLE            = 0x01;
1405 
1406     /**
1407      * RCS VoLTE single registration is not supported by the carrier
1408      */
1409     public static final int STATUS_CARRIER_NOT_CAPABLE           = 0x01 << 1;
1410 
1411     /**
1412      * Provide the client configuration parameters of the RCS application.
1413      *
1414      * <p>When this application is also the default messaging application, and RCS
1415      * provisioning is done using autoconfiguration, then these parameters shall be
1416      * sent in the HTTP get request to fetch the RCS provisioning. RCS client
1417      * configuration must be provided by the application before registering for the
1418      * provisioning status events {@link #registerRcsProvisioningCallback()}
1419      * When the IMS/RCS service receives the RCS client configuration, it will detect
1420      * the change in the configuration, and trigger the auto-configuration as needed.
1421      * @param rcc RCS client configuration {@link RcsClientConfiguration}
1422      */
1423     @RequiresPermission(Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION)
setRcsClientConfiguration( @onNull RcsClientConfiguration rcc)1424     public void setRcsClientConfiguration(
1425             @NonNull RcsClientConfiguration rcc) throws ImsException {
1426         try {
1427             getITelephony().setRcsClientConfiguration(mSubId, rcc);
1428         } catch (ServiceSpecificException e) {
1429             throw new ImsException(e.getMessage(), e.errorCode);
1430         } catch (RemoteException | IllegalStateException e) {
1431             throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
1432         }
1433     }
1434 
1435     /**
1436      * Returns a flag to indicate whether or not the device supports IMS single registration for
1437      * MMTEL and RCS features as well as if the carrier has provisioned the feature.
1438      *
1439      * <p> Requires Permission:
1440      * <ul>
1441      *     <li>{@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE},</li>
1442      *     <li>{@link android.Manifest.permission#PERFORM_IMS_SINGLE_REGISTRATION},</li>
1443      *     <li>or that the caller has carrier privileges (see
1444      *         {@link TelephonyManager#hasCarrierPrivileges()}).</li>
1445      * </ul>
1446      * @return true if IMS single registration is capable at this time, or false otherwise
1447      * @throws ImsException If the remote ImsService is not available for
1448      * any reason or the subscription associated with this instance is no
1449      * longer active. See {@link ImsException#getCode()} for more
1450      * information.
1451      * @see PackageManager#FEATURE_TELEPHONY_IMS_SINGLE_REGISTRATION for whether or not this
1452      * device supports IMS single registration.
1453      */
1454     @RequiresPermission(anyOf = {Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1455             Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION})
isRcsVolteSingleRegistrationCapable()1456     public boolean isRcsVolteSingleRegistrationCapable() throws ImsException {
1457         try {
1458             return getITelephony().isRcsVolteSingleRegistrationCapable(mSubId);
1459         } catch (RemoteException | IllegalStateException e) {
1460             throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
1461         }
1462     }
1463 
1464    /**
1465     * Registers a new {@link RcsProvisioningCallback} to listen to changes to
1466     * RCS provisioning xml.
1467     *
1468     * <p>RCS application must be the default messaging application and must
1469     * have already registered its {@link RcsClientConfiguration} by using
1470     * {@link #setRcsClientConfiguration} before it registers the provisioning
1471     * callback. If ProvisioningManager has a valid RCS configuration at the
1472     * time of callback registration and a reconfiguration is not required
1473     * due to RCS client parameters change, then the callback shall be invoked
1474     * immediately with the xml.
1475     * When the subscription associated with this callback is removed (SIM removed,
1476     * ESIM swap,etc...), this callback will automatically be removed.
1477     * <p> Requires Permission:
1478     * <ul>
1479     *     <li>{@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE},</li>
1480     *     <li>{@link android.Manifest.permission#PERFORM_IMS_SINGLE_REGISTRATION},</li>
1481     *     <li>or that the caller has carrier privileges (see
1482     *         {@link TelephonyManager#hasCarrierPrivileges()}).</li>
1483     * </ul>
1484     *
1485     * @param executor The {@link Executor} to call the callback methods on
1486     * @param callback The rcs provisioning callback to be registered.
1487     * @see #unregisterRcsProvisioningCallback(RcsProvisioningCallback)
1488     * @see SubscriptionManager.OnSubscriptionsChangedListener
1489     * @throws IllegalArgumentException if the subscription associated with this
1490     * callback is not active (SIM is not inserted, ESIM inactive) or the
1491     * subscription is invalid.
1492     * @throws ImsException if the subscription associated with this callback is
1493     * valid, but the {@link ImsService} associated with the subscription is not
1494     * available. This can happen if the service crashed, for example.
1495     * It shall also throw this exception when the RCS client parameters for the
1496     * application are not valid. In that case application must set the client
1497     * params (See {@link #setRcsClientConfiguration}) and re register the
1498     * callback.
1499     * See {@link ImsException#getCode()} for a more detailed reason.
1500     */
1501     @RequiresPermission(anyOf = {Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1502             Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION})
registerRcsProvisioningCallback( @onNull @allbackExecutor Executor executor, @NonNull RcsProvisioningCallback callback)1503     public void registerRcsProvisioningCallback(
1504             @NonNull @CallbackExecutor Executor executor,
1505             @NonNull RcsProvisioningCallback callback) throws ImsException {
1506         callback.setExecutor(executor);
1507         try {
1508             getITelephony().registerRcsProvisioningCallback(mSubId, callback.getBinder());
1509         } catch (ServiceSpecificException e) {
1510             throw new ImsException(e.getMessage(), e.errorCode);
1511         } catch (RemoteException | IllegalStateException e) {
1512             throw new ImsException(e.getMessage(), ImsException.CODE_ERROR_SERVICE_UNAVAILABLE);
1513         }
1514     }
1515 
1516     /**
1517      * Unregister an existing {@link RcsProvisioningCallback}. Application can
1518      * unregister when its no longer interested in the provisioning updates
1519      * like when a user disables RCS from the UI/settings.
1520      * When the subscription associated with this callback is removed (SIM
1521      * removed, ESIM swap, etc...), this callback will automatically be
1522      * removed. If this method is called for an inactive subscription, it
1523      * will result in a no-op.
1524      * <p> Requires Permission:
1525      * <ul>
1526      *     <li>{@link android.Manifest.permission#READ_PRIVILEGED_PHONE_STATE},</li>
1527      *     <li>{@link android.Manifest.permission#PERFORM_IMS_SINGLE_REGISTRATION},</li>
1528      *     <li>or that the caller has carrier privileges (see
1529      *         {@link TelephonyManager#hasCarrierPrivileges()}).</li>
1530      * </ul>
1531      *
1532      * @param callback The existing {@link RcsProvisioningCallback} to be
1533      * removed.
1534      * @see #registerRcsProvisioningCallback(Executor, RcsProvisioningCallback)
1535      * @throws IllegalArgumentException if the subscription associated with
1536      * this callback is invalid.
1537      */
1538     @RequiresPermission(anyOf = {Manifest.permission.READ_PRIVILEGED_PHONE_STATE,
1539             Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION})
unregisterRcsProvisioningCallback( @onNull RcsProvisioningCallback callback)1540     public void unregisterRcsProvisioningCallback(
1541             @NonNull RcsProvisioningCallback callback) {
1542         try {
1543             getITelephony().unregisterRcsProvisioningCallback(
1544                     mSubId, callback.getBinder());
1545         } catch (RemoteException e) {
1546             throw e.rethrowAsRuntimeException();
1547         }
1548     }
1549 
1550     /**
1551      * Reconfiguration triggered by the RCS application. Most likely cause
1552      * is the 403 forbidden to a HTTP request.
1553      *
1554      * <p>When this api is called, the RCS configuration for the associated
1555      * subscription will be removed, and the application which has registered
1556      * {@link RcsProvisioningCallback} may expect to receive
1557      * {@link RcsProvisioningCallback#onConfigurationReset}, then
1558      * {@link RcsProvisioningCallback#onConfigurationChanged} when the new
1559      * RCS configuration is received and notified by
1560      * {@link #notifyRcsAutoConfigurationReceived}
1561      */
1562     @RequiresPermission(Manifest.permission.PERFORM_IMS_SINGLE_REGISTRATION)
triggerRcsReconfiguration()1563     public void triggerRcsReconfiguration() {
1564         try {
1565             getITelephony().triggerRcsReconfiguration(mSubId);
1566         } catch (RemoteException e) {
1567             throw e.rethrowAsRuntimeException();
1568         }
1569     }
1570 
getITelephony()1571     private static ITelephony getITelephony() {
1572         ITelephony binder = ITelephony.Stub.asInterface(
1573                 TelephonyFrameworkInitializer
1574                         .getTelephonyServiceManager()
1575                         .getTelephonyServiceRegisterer()
1576                         .get());
1577         if (binder == null) {
1578             throw new RuntimeException("Could not find Telephony Service.");
1579         }
1580         return binder;
1581     }
1582 }
1583