1 /* 2 * Copyright (C) 2019 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.annotation.NonNull; 20 import android.annotation.SdkConstant; 21 import android.annotation.SuppressLint; 22 import android.annotation.SystemApi; 23 import android.annotation.SystemService; 24 import android.content.Context; 25 import android.telephony.BinderCacheManager; 26 import android.telephony.SubscriptionManager; 27 import android.telephony.TelephonyFrameworkInitializer; 28 import android.telephony.ims.aidl.IImsRcsController; 29 30 import com.android.internal.telephony.ITelephony; 31 32 /** 33 * Provides access to information about Telephony IMS services on the device. 34 */ 35 @SystemService(Context.TELEPHONY_IMS_SERVICE) 36 public class ImsManager { 37 38 /** 39 * <p>Broadcast Action: Indicates that a previously allowed IMS operation was rejected by the 40 * network due to the network returning a "forbidden" response. This may be due to a 41 * provisioning change from the network. 42 * May include the {@link SubscriptionManager#EXTRA_SUBSCRIPTION_INDEX} extra to also specify 43 * which subscription the operation was rejected for. 44 * <p class="note"> 45 * Carrier applications may listen to this broadcast to be notified of possible IMS provisioning 46 * issues. 47 * @hide 48 */ 49 // Moved from TelephonyIntents, need to keep backwards compatibility with OEM apps that have 50 // this value hard-coded in BroadcastReceiver. 51 @SuppressLint("ActionValue") 52 @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) 53 public static final String ACTION_FORBIDDEN_NO_SERVICE_AUTHORIZATION = 54 "com.android.internal.intent.action.ACTION_FORBIDDEN_NO_SERVICE_AUTHORIZATION"; 55 56 /** 57 * An intent action indicating that IMS registration for WiFi calling has resulted in an error. 58 * Contains error information that should be displayed to the user. 59 * <p> 60 * This intent will contain the following extra key/value pairs: 61 * {@link #EXTRA_WFC_REGISTRATION_FAILURE_TITLE} 62 * and {@link #EXTRA_WFC_REGISTRATION_FAILURE_MESSAGE}, which contain carrier specific 63 * error information that should be displayed to the user. 64 * <p> 65 * Usage: This intent is sent as an ordered broadcast. If the settings application is going 66 * to show the error information specified to the user, it should respond to 67 * {@link android.content.BroadcastReceiver#setResultCode(int)} with 68 * {@link android.app.Activity#RESULT_CANCELED}, which will signal to the framework that the 69 * event was handled. If the framework does not receive a response to the ordered broadcast, 70 * it will then show a notification to the user indicating that there was a registration 71 * failure. 72 */ 73 @SdkConstant(SdkConstant.SdkConstantType.BROADCAST_INTENT_ACTION) 74 public static final String ACTION_WFC_IMS_REGISTRATION_ERROR = 75 "android.telephony.ims.action.WFC_IMS_REGISTRATION_ERROR"; 76 77 /** 78 * An extra key corresponding to a {@link CharSequence} value which contains the carrier 79 * specific title to be displayed as part of the message shown to the user when there is an 80 * error registering for WiFi calling. 81 */ 82 public static final String EXTRA_WFC_REGISTRATION_FAILURE_TITLE = 83 "android.telephony.ims.extra.WFC_REGISTRATION_FAILURE_TITLE"; 84 85 /** 86 * An extra key corresponding to a {@link CharSequence} value which contains the carrier 87 * specific message to be displayed as part of the message shown to the user when there is an 88 * error registering for WiFi calling. 89 */ 90 public static final String EXTRA_WFC_REGISTRATION_FAILURE_MESSAGE = 91 "android.telephony.ims.extra.WFC_REGISTRATION_FAILURE_MESSAGE"; 92 93 // Cache Telephony Binder interfaces, one cache per process. 94 private static final BinderCacheManager<ITelephony> sTelephonyCache = 95 new BinderCacheManager<>(ImsManager::getITelephonyInterface); 96 private static final BinderCacheManager<IImsRcsController> sRcsCache = 97 new BinderCacheManager<>(ImsManager::getIImsRcsControllerInterface); 98 99 private final Context mContext; 100 101 /** 102 * Use {@link Context#getSystemService(String)} to get an instance of this class. 103 * @hide 104 */ ImsManager(@onNull Context context)105 public ImsManager(@NonNull Context context) { 106 mContext = context; 107 } 108 109 /** 110 * Create an instance of ImsRcsManager for the subscription id specified. 111 * 112 * @param subscriptionId The ID of the subscription that this ImsRcsManager will use. 113 * @throws IllegalArgumentException if the subscription is invalid. 114 * @return a ImsRcsManager instance with the specific subscription ID. 115 */ 116 @NonNull getImsRcsManager(int subscriptionId)117 public ImsRcsManager getImsRcsManager(int subscriptionId) { 118 if (!SubscriptionManager.isValidSubscriptionId(subscriptionId)) { 119 throw new IllegalArgumentException("Invalid subscription ID: " + subscriptionId); 120 } 121 122 return new ImsRcsManager(mContext, subscriptionId, sRcsCache); 123 } 124 125 /** 126 * Create an instance of ImsMmTelManager for the subscription id specified. 127 * 128 * @param subscriptionId The ID of the subscription that this ImsMmTelManager will use. 129 * @throws IllegalArgumentException if the subscription is invalid. 130 * @return a ImsMmTelManager instance with the specific subscription ID. 131 */ 132 @NonNull getImsMmTelManager(int subscriptionId)133 public ImsMmTelManager getImsMmTelManager(int subscriptionId) { 134 if (!SubscriptionManager.isValidSubscriptionId(subscriptionId)) { 135 throw new IllegalArgumentException("Invalid subscription ID: " + subscriptionId); 136 } 137 138 return new ImsMmTelManager(subscriptionId, sTelephonyCache); 139 } 140 141 /** 142 * Create an instance of {@link SipDelegateManager} for the subscription id specified. 143 * <p> 144 * Allows an IMS application to forward SIP traffic through the device's IMS service, 145 * which is used for cellular carriers that require the device to share a single IMS 146 * registration for both MMTEL and RCS features. 147 * @param subscriptionId The ID of the subscription that this {@link SipDelegateManager} will 148 * be bound to. 149 * @throws IllegalArgumentException if the subscription is invalid. 150 * @return a {@link SipDelegateManager} instance for the specified subscription ID. 151 * @hide 152 */ 153 @SystemApi 154 @NonNull getSipDelegateManager(int subscriptionId)155 public SipDelegateManager getSipDelegateManager(int subscriptionId) { 156 if (!SubscriptionManager.isValidSubscriptionId(subscriptionId)) { 157 throw new IllegalArgumentException("Invalid subscription ID: " + subscriptionId); 158 } 159 160 return new SipDelegateManager(mContext, subscriptionId, sRcsCache); 161 } 162 getIImsRcsControllerInterface()163 private static IImsRcsController getIImsRcsControllerInterface() { 164 return IImsRcsController.Stub.asInterface( 165 TelephonyFrameworkInitializer 166 .getTelephonyServiceManager() 167 .getTelephonyImsServiceRegisterer() 168 .get()); 169 } 170 getITelephonyInterface()171 private static ITelephony getITelephonyInterface() { 172 return ITelephony.Stub.asInterface( 173 TelephonyFrameworkInitializer 174 .getTelephonyServiceManager() 175 .getTelephonyServiceRegisterer() 176 .get()); 177 } 178 } 179