blob: 8e547717ea1578b48f20d17d6d8c0c25552ee6d9 [file] [log] [blame]
Wink Savilleef36ef62014-06-11 08:39:38 -07001/*
2 * Copyright (c) 2013 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
Brad Ebinger172977a2018-01-16 09:36:56 -080019import android.annotation.Nullable;
Wink Savilleef36ef62014-06-11 08:39:38 -070020import android.app.PendingIntent;
21import android.content.Context;
Brad Ebinger172977a2018-01-16 09:36:56 -080022import android.os.Bundle;
Brad Ebinger6ddf28e2018-02-21 16:07:23 -080023import android.os.Handler;
Wink Savilleef36ef62014-06-11 08:39:38 -070024import android.os.IBinder;
Brad Ebinger6ddf28e2018-02-21 16:07:23 -080025import android.os.Looper;
Wink Savilleef36ef62014-06-11 08:39:38 -070026import android.os.Message;
Naveen Kalla525c3a22017-02-06 14:46:42 -080027import android.os.Parcel;
Jonathan Basseri2acea6f2015-07-01 15:00:38 -070028import android.os.PersistableBundle;
Wink Savilleef36ef62014-06-11 08:39:38 -070029import android.os.RemoteException;
Etan Cohenaf55a402014-09-04 22:34:41 -070030import android.os.SystemProperties;
Etan Cohen82f78122014-12-15 10:10:14 -080031import android.telecom.TelecomManager;
Junda Liue7663c02015-06-23 11:16:26 -070032import android.telephony.CarrierConfigManager;
Mohamed Abdalkadere1453f42018-01-19 19:48:31 -080033import android.telephony.ims.stub.ImsRegistrationImplBase;
Wink Savilleef36ef62014-06-11 08:39:38 -070034import android.telephony.Rlog;
Etan Cohen82f78122014-12-15 10:10:14 -080035import android.telephony.SubscriptionManager;
Etan Cohencfc784d2014-08-07 18:40:31 -070036import android.telephony.TelephonyManager;
Brad Ebinger190ed932018-01-23 13:41:32 -080037import android.telephony.ims.ImsCallProfile;
38import android.telephony.ims.ImsReasonInfo;
Brad Ebinger172977a2018-01-16 09:36:56 -080039import android.telephony.ims.aidl.IImsConfig;
40import android.telephony.ims.aidl.IImsSmsListener;
41import android.telephony.ims.feature.CapabilityChangeRequest;
42import android.telephony.ims.feature.ImsFeature;
43import android.telephony.ims.feature.MmTelFeature;
Hall Liue511a202017-08-17 15:49:58 -070044import android.util.Log;
Wink Savilleef36ef62014-06-11 08:39:38 -070045
46import com.android.ims.internal.IImsCallSession;
Uma Maheswari Ramalingam4f2161d2014-07-31 16:01:47 -070047import com.android.ims.internal.IImsEcbm;
Tyler Gunn4d128b62016-04-13 15:44:38 -070048import com.android.ims.internal.IImsMultiEndpoint;
Wink Savilleef36ef62014-06-11 08:39:38 -070049import com.android.ims.internal.IImsUt;
Brad Ebinger190ed932018-01-23 13:41:32 -080050import android.telephony.ims.ImsCallSession;
Brad Ebinger16780ff2017-01-26 11:18:21 -080051import com.android.internal.annotations.VisibleForTesting;
Libin.Tang@motorola.com076c55d2014-06-23 19:46:36 -050052
Jack Yu2f102bd2015-12-28 15:31:48 -080053import java.io.FileDescriptor;
54import java.io.PrintWriter;
Naveen Kalla525c3a22017-02-06 14:46:42 -080055import java.util.ArrayList;
Etan Cohend7727462014-07-12 14:54:10 -070056import java.util.HashMap;
Brad Ebinger16780ff2017-01-26 11:18:21 -080057import java.util.Set;
Malcolm Chen18837ff2017-10-25 17:05:41 -070058import java.util.concurrent.ConcurrentLinkedDeque;
Brad Ebinger44fd8af2017-12-14 14:24:02 -080059import java.util.concurrent.CopyOnWriteArraySet;
Etan Cohend7727462014-07-12 14:54:10 -070060
Wink Savilleef36ef62014-06-11 08:39:38 -070061/**
62 * Provides APIs for IMS services, such as initiating IMS calls, and provides access to
63 * the operator's IMS network. This class is the starting point for any IMS actions.
64 * You can acquire an instance of it with {@link #getInstance getInstance()}.</p>
65 * <p>The APIs in this class allows you to:</p>
66 *
67 * @hide
68 */
69public class ImsManager {
Etan Cohen19604c02014-08-11 14:32:57 -070070
Etan Cohenaf55a402014-09-04 22:34:41 -070071 /*
72 * Debug flag to override configuration flag
73 */
Etan Cohenb651fa52014-10-22 10:51:29 -070074 public static final String PROPERTY_DBG_VOLTE_AVAIL_OVERRIDE = "persist.dbg.volte_avail_ovr";
75 public static final int PROPERTY_DBG_VOLTE_AVAIL_OVERRIDE_DEFAULT = 0;
Etan Cohenea2b5832014-10-23 18:50:35 -070076 public static final String PROPERTY_DBG_VT_AVAIL_OVERRIDE = "persist.dbg.vt_avail_ovr";
77 public static final int PROPERTY_DBG_VT_AVAIL_OVERRIDE_DEFAULT = 0;
Etan Cohena00c9192014-12-23 15:02:29 -080078 public static final String PROPERTY_DBG_WFC_AVAIL_OVERRIDE = "persist.dbg.wfc_avail_ovr";
79 public static final int PROPERTY_DBG_WFC_AVAIL_OVERRIDE_DEFAULT = 0;
Meng Wang9352c432016-06-08 14:22:20 -070080 public static final String PROPERTY_DBG_ALLOW_IMS_OFF_OVERRIDE = "persist.dbg.allow_ims_off";
81 public static final int PROPERTY_DBG_ALLOW_IMS_OFF_OVERRIDE_DEFAULT = 0;
Etan Cohenaf55a402014-09-04 22:34:41 -070082
Wink Savilleef36ef62014-06-11 08:39:38 -070083 /**
Wink Savilleef36ef62014-06-11 08:39:38 -070084 * The result code to be sent back with the incoming call {@link PendingIntent}.
Brad Ebinger172977a2018-01-16 09:36:56 -080085 * @see #open(MmTelFeature.Listener)
Wink Savilleef36ef62014-06-11 08:39:38 -070086 */
87 public static final int INCOMING_CALL_RESULT_CODE = 101;
88
89 /**
90 * Key to retrieve the call ID from an incoming call intent.
Brad Ebinger172977a2018-01-16 09:36:56 -080091 * @see #open(MmTelFeature.Listener)
Wink Savilleef36ef62014-06-11 08:39:38 -070092 */
93 public static final String EXTRA_CALL_ID = "android:imsCallID";
94
95 /**
96 * Action to broadcast when ImsService is up.
97 * Internal use only.
Brad Ebinger16780ff2017-01-26 11:18:21 -080098 * @deprecated
Wink Savilleef36ef62014-06-11 08:39:38 -070099 * @hide
100 */
101 public static final String ACTION_IMS_SERVICE_UP =
102 "com.android.ims.IMS_SERVICE_UP";
103
104 /**
105 * Action to broadcast when ImsService is down.
106 * Internal use only.
Brad Ebinger16780ff2017-01-26 11:18:21 -0800107 * @deprecated
Wink Savilleef36ef62014-06-11 08:39:38 -0700108 * @hide
109 */
110 public static final String ACTION_IMS_SERVICE_DOWN =
111 "com.android.ims.IMS_SERVICE_DOWN";
112
113 /**
Pavel Zhamaitsiak0c2f15c2015-03-12 15:37:54 -0700114 * Action to broadcast when ImsService registration fails.
115 * Internal use only.
116 * @hide
117 */
118 public static final String ACTION_IMS_REGISTRATION_ERROR =
119 "com.android.ims.REGISTRATION_ERROR";
120
121 /**
Etan Cohend7727462014-07-12 14:54:10 -0700122 * Part of the ACTION_IMS_SERVICE_UP or _DOWN intents.
Etan Cohenabbd7882014-09-26 22:35:35 -0700123 * A long value; the phone ID corresponding to the IMS service coming up or down.
Etan Cohend7727462014-07-12 14:54:10 -0700124 * Internal use only.
125 * @hide
126 */
Etan Cohenabbd7882014-09-26 22:35:35 -0700127 public static final String EXTRA_PHONE_ID = "android:phone_id";
Etan Cohend7727462014-07-12 14:54:10 -0700128
129 /**
Wink Savilleef36ef62014-06-11 08:39:38 -0700130 * Action for the incoming call intent for the Phone app.
131 * Internal use only.
132 * @hide
133 */
134 public static final String ACTION_IMS_INCOMING_CALL =
135 "com.android.ims.IMS_INCOMING_CALL";
136
137 /**
138 * Part of the ACTION_IMS_INCOMING_CALL intents.
139 * An integer value; service identifier obtained from {@link ImsManager#open}.
140 * Internal use only.
141 * @hide
142 */
143 public static final String EXTRA_SERVICE_ID = "android:imsServiceId";
144
145 /**
146 * Part of the ACTION_IMS_INCOMING_CALL intents.
147 * An boolean value; Flag to indicate that the incoming call is a normal call or call for USSD.
148 * The value "true" indicates that the incoming call is for USSD.
149 * Internal use only.
150 * @hide
151 */
152 public static final String EXTRA_USSD = "android:ussd";
153
Shriram Ganeshd3adfad2015-05-31 10:06:15 -0700154 /**
155 * Part of the ACTION_IMS_INCOMING_CALL intents.
156 * A boolean value; Flag to indicate whether the call is an unknown
157 * dialing call. Such calls are originated by sending commands (like
158 * AT commands) directly to modem without Android involvement.
159 * Even though they are not incoming calls, they are propagated
160 * to Phone app using same ACTION_IMS_INCOMING_CALL intent.
161 * Internal use only.
162 * @hide
163 */
Anju Mathapati9c033792015-06-16 16:33:16 -0700164 public static final String EXTRA_IS_UNKNOWN_CALL = "android:isUnknown";
Shriram Ganeshd3adfad2015-05-31 10:06:15 -0700165
Malcolm Chen18837ff2017-10-25 17:05:41 -0700166 private static final int SYSTEM_PROPERTY_NOT_SET = -1;
167
168 // -1 indicates a subscriptionProperty value that is never set.
169 private static final int SUB_PROPERTY_NOT_INITIALIZED = -1;
170
Wink Savilleef36ef62014-06-11 08:39:38 -0700171 private static final String TAG = "ImsManager";
172 private static final boolean DBG = true;
173
Brad Ebinger6ddf28e2018-02-21 16:07:23 -0800174 /**
175 * Helper class for managing a connection to the ImsManager when the ImsService is unavailable
176 * or switches to another service.
177 */
178 public static class Connector extends Handler {
179 // Initial condition for ims connection retry.
180 private static final int IMS_RETRY_STARTING_TIMEOUT_MS = 500; // ms
181 // Ceiling bitshift amount for service query timeout, calculated as:
182 // 2^mImsServiceRetryCount * IMS_RETRY_STARTING_TIMEOUT_MS, where
183 // mImsServiceRetryCount ∊ [0, CEILING_SERVICE_RETRY_COUNT].
184 private static final int CEILING_SERVICE_RETRY_COUNT = 6;
185
186 private final Runnable mGetServiceRunnable = () -> {
187 try {
188 getImsService();
189 } catch (ImsException e) {
190 retryGetImsService();
191 }
192 };
193
194 public interface Listener {
195 /**
196 * ImsManager is connected to the underlying IMS implementation.
197 */
198 void connectionReady(ImsManager manager) throws ImsException;
199
200 /**
201 * The underlying IMS implementation is unavailable and can not be used to communicate.
202 */
203 void connectionUnavailable();
204 }
205
206 @VisibleForTesting
207 public interface RetryTimeout {
208 int get();
209 }
210
211 // Callback fires when ImsManager MMTel Feature changes state
212 private MmTelFeatureConnection.IFeatureUpdate mNotifyStatusChangedCallback =
213 new MmTelFeatureConnection.IFeatureUpdate() {
214 @Override
215 public void notifyStateChanged() {
216 try {
217 int status = ImsFeature.STATE_UNAVAILABLE;
218 synchronized (mLock) {
219 if (mImsManager != null) {
220 status = mImsManager.getImsServiceState();
221 }
222 }
223 log("Status Changed: " + status);
224 switch (status) {
225 case ImsFeature.STATE_READY: {
226 notifyReady();
227 break;
228 }
229 case ImsFeature.STATE_INITIALIZING:
230 // fall through
231 case ImsFeature.STATE_UNAVAILABLE: {
232 notifyNotReady();
233 break;
234 }
235 default: {
236 Log.w(TAG, "Unexpected State!");
237 }
238 }
239 } catch (ImsException e) {
240 // Could not get the ImsService, retry!
241 notifyNotReady();
242 retryGetImsService();
243 }
244 }
245
246 @Override
247 public void notifyUnavailable() {
248 notifyNotReady();
249 retryGetImsService();
250 }
251 };
252
253 private final Context mContext;
254 private final int mPhoneId;
255 private final Listener mListener;
256 private final Object mLock = new Object();
257
258 private int mRetryCount = 0;
259 private ImsManager mImsManager;
260
261 @VisibleForTesting
262 public RetryTimeout mRetryTimeout = () -> {
263 synchronized (mLock) {
264 int timeout = (1 << mRetryCount) * IMS_RETRY_STARTING_TIMEOUT_MS;
265 if (mRetryCount <= CEILING_SERVICE_RETRY_COUNT) {
266 mRetryCount++;
267 }
268 return timeout;
269 }
270 };
271
272 public Connector(Context context, int phoneId, Listener listener) {
273 mContext = context;
274 mPhoneId = phoneId;
275 mListener = listener;
276 }
277
278 public Connector(Context context, int phoneId, Listener listener, Looper looper) {
279 super(looper);
280 mContext = context;
281 mPhoneId = phoneId;
282 mListener= listener;
283 }
284
285 /**
286 * Start the creation of a connection to the underlying ImsService implementation. When the
287 * service is connected, {@link Listener#connectionReady(ImsManager)} will be called with
288 * an active ImsManager instance.
289 */
290 public void connect() {
291 mRetryCount = 0;
292 // Send a message to connect to the Ims Service and open a connection through
293 // getImsService().
294 post(mGetServiceRunnable);
295 }
296
297 /**
298 * Disconnect from the ImsService Implementation and clean up. When this is complete,
299 * {@link Listener#connectionUnavailable()} will be called one last time.
300 */
301 public void disconnect() {
302 removeCallbacks(mGetServiceRunnable);
303 synchronized (mLock) {
304 if (mImsManager != null) {
305 mImsManager.removeNotifyStatusChangedCallback(mNotifyStatusChangedCallback);
306 }
307 }
308 notifyNotReady();
309 }
310
311 private void retryGetImsService() {
312 synchronized (mLock) {
313 // remove callback so we do not receive updates from old ImsServiceProxy when
314 // switching between ImsServices.
315 mImsManager.removeNotifyStatusChangedCallback(mNotifyStatusChangedCallback);
316 //Leave mImsManager as null, then CallStateException will be thrown when dialing
317 mImsManager = null;
318 }
319 // Exponential backoff during retry, limited to 32 seconds.
320 loge("Connector: Retrying getting ImsService...");
321 removeCallbacks(mGetServiceRunnable);
322 postDelayed(mGetServiceRunnable, mRetryTimeout.get());
323 }
324
325 private void getImsService() throws ImsException {
326 if (DBG) log("Connector: getImsService");
327 synchronized (mLock) {
328 mImsManager = ImsManager.getInstance(mContext, mPhoneId);
329 // Adding to set, will be safe adding multiple times. If the ImsService is not
330 // active yet, this method will throw an ImsException.
331 mImsManager.addNotifyStatusChangedCallbackIfAvailable(mNotifyStatusChangedCallback);
332 }
333 // Wait for ImsService.STATE_READY to start listening for calls.
334 // Call the callback right away for compatibility with older devices that do not use
335 // states.
336 mNotifyStatusChangedCallback.notifyStateChanged();
337 }
338
339 private void notifyReady() throws ImsException {
340 ImsManager manager;
341 synchronized (mLock) {
Brad Ebinger6ddf28e2018-02-21 16:07:23 -0800342 manager = mImsManager;
343 }
Brad Ebinger0aed76d2018-03-05 16:39:02 -0800344 try {
345 mListener.connectionReady(manager);
346 }
347 catch (ImsException e) {
348 Log.w(TAG, "Connector: notifyReady exception: " + e.getMessage());
349 throw e;
350 }
351 // Only reset retry count if connectionReady does not generate an ImsException/
352 synchronized (mLock) {
353 mRetryCount = 0;
354 }
Brad Ebinger6ddf28e2018-02-21 16:07:23 -0800355 }
356
357 private void notifyNotReady() {
358 mListener.connectionUnavailable();
359 }
360 }
361
Wink Saville1e5a38a2014-10-23 10:24:46 -0700362 private static HashMap<Integer, ImsManager> sImsManagerInstances =
363 new HashMap<Integer, ImsManager>();
Etan Cohend7727462014-07-12 14:54:10 -0700364
Wink Savilleef36ef62014-06-11 08:39:38 -0700365 private Context mContext;
Brad Ebinger16417b42017-03-07 13:48:50 -0800366 private CarrierConfigManager mConfigManager;
Etan Cohenabbd7882014-09-26 22:35:35 -0700367 private int mPhoneId;
Brad Ebinger16780ff2017-01-26 11:18:21 -0800368 private final boolean mConfigDynamicBind;
Brad Ebinger172977a2018-01-16 09:36:56 -0800369 private @Nullable MmTelFeatureConnection mMmTelFeatureConnection = null;
Wink Savilleef36ef62014-06-11 08:39:38 -0700370 private ImsServiceDeathRecipient mDeathRecipient = new ImsServiceDeathRecipient();
371 // Ut interface for the supplementary service configuration
372 private ImsUt mUt = null;
Libin.Tang@motorola.com076c55d2014-06-23 19:46:36 -0500373 // Interface to get/set ims config items
374 private ImsConfig mConfig = null;
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -0700375 private boolean mConfigUpdated = false;
Wink Savilleef36ef62014-06-11 08:39:38 -0700376
Pavel Zhamaitsiakf4b90322016-01-26 14:34:09 -0800377 private ImsConfigListener mImsConfigListener;
378
Uma Maheswari Ramalingam4f2161d2014-07-31 16:01:47 -0700379 // ECBM interface
380 private ImsEcbm mEcbm = null;
381
Tyler Gunn4d128b62016-04-13 15:44:38 -0700382 private ImsMultiEndpoint mMultiEndpoint = null;
383
Brad Ebinger172977a2018-01-16 09:36:56 -0800384 private Set<MmTelFeatureConnection.IFeatureUpdate> mStatusCallbacks =
385 new CopyOnWriteArraySet<>();
Brad Ebinger16780ff2017-01-26 11:18:21 -0800386
Amit Mahajan24f7b162016-07-21 16:33:53 -0700387 public static final String TRUE = "true";
388 public static final String FALSE = "false";
Jack Yu643ffe42016-07-08 14:25:46 -0700389
Naveen Kalla525c3a22017-02-06 14:46:42 -0800390 // mRecentDisconnectReasons stores the last 16 disconnect reasons
391 private static final int MAX_RECENT_DISCONNECT_REASONS = 16;
392 private ConcurrentLinkedDeque<ImsReasonInfo> mRecentDisconnectReasons =
393 new ConcurrentLinkedDeque<>();
394
Wink Savilleef36ef62014-06-11 08:39:38 -0700395 /**
396 * Gets a manager instance.
397 *
398 * @param context application context for creating the manager object
Etan Cohenabbd7882014-09-26 22:35:35 -0700399 * @param phoneId the phone ID for the IMS Service
400 * @return the manager instance corresponding to the phoneId
Wink Savilleef36ef62014-06-11 08:39:38 -0700401 */
Etan Cohenabbd7882014-09-26 22:35:35 -0700402 public static ImsManager getInstance(Context context, int phoneId) {
Etan Cohend7727462014-07-12 14:54:10 -0700403 synchronized (sImsManagerInstances) {
Naveen Kalla525c3a22017-02-06 14:46:42 -0800404 if (sImsManagerInstances.containsKey(phoneId)) {
Brad Ebingerff097922017-06-19 15:43:08 -0700405 ImsManager m = sImsManagerInstances.get(phoneId);
406 // May be null for some tests
407 if (m != null) {
408 m.connectIfServiceIsAvailable();
409 }
410 return m;
Naveen Kalla525c3a22017-02-06 14:46:42 -0800411 }
Wink Savilleef36ef62014-06-11 08:39:38 -0700412
Etan Cohenabbd7882014-09-26 22:35:35 -0700413 ImsManager mgr = new ImsManager(context, phoneId);
414 sImsManagerInstances.put(phoneId, mgr);
Etan Cohend7727462014-07-12 14:54:10 -0700415
416 return mgr;
417 }
Wink Savilleef36ef62014-06-11 08:39:38 -0700418 }
419
Etan Cohen45b5f312014-08-19 15:55:08 -0700420 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800421 * Returns the user configuration of Enhanced 4G LTE Mode setting.
422 *
423 * @deprecated Doesn't support MSIM devices. Use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700424 * {@link #isEnhanced4gLteModeSettingEnabledByUser()} instead.
Etan Cohen45b5f312014-08-19 15:55:08 -0700425 */
426 public static boolean isEnhanced4gLteModeSettingEnabledByUser(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700427 ImsManager mgr = ImsManager.getInstance(context,
428 SubscriptionManager.getDefaultVoicePhoneId());
429 if (mgr != null) {
430 return mgr.isEnhanced4gLteModeSettingEnabledByUser();
Sungmin Choi2f1af952016-02-01 17:15:35 +0900431 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700432 loge("isEnhanced4gLteModeSettingEnabledByUser: ImsManager null, returning default value.");
433 return false;
Etan Cohen45b5f312014-08-19 15:55:08 -0700434 }
435
436 /**
manabu, shimoda96aee542017-10-06 15:39:36 +0900437 * Returns the user configuration of Enhanced 4G LTE Mode setting for slot. If the option is
438 * not editable ({@link CarrierConfigManager#KEY_EDITABLE_ENHANCED_4G_LTE_BOOL} is false), or
439 * the setting is not initialized, this method will return default value specified by
440 * {@link CarrierConfigManager#KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL}.
441 *
442 * Note that even if the setting was set, it may no longer be editable. If this is the case we
443 * return the default value.
Brad Ebinger16417b42017-03-07 13:48:50 -0800444 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700445 public boolean isEnhanced4gLteModeSettingEnabledByUser() {
Malcolm Chen212ca652017-09-28 17:28:45 -0700446 int setting = SubscriptionManager.getIntegerSubscriptionProperty(
447 getSubId(), SubscriptionManager.ENHANCED_4G_MODE_ENABLED,
448 SUB_PROPERTY_NOT_INITIALIZED, mContext);
manabu, shimoda96aee542017-10-06 15:39:36 +0900449 boolean onByDefault = getBooleanCarrierConfig(
450 CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL);
Malcolm Chen212ca652017-09-28 17:28:45 -0700451
manabu, shimoda96aee542017-10-06 15:39:36 +0900452 // If Enhanced 4G LTE Mode is uneditable or not initialized, we use the default value
453 if (!getBooleanCarrierConfig(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL)
454 || setting == SUB_PROPERTY_NOT_INITIALIZED) {
455 return onByDefault;
456 } else {
457 return (setting == ImsConfig.FeatureValueConstants.ON);
458 }
Brad Ebinger16417b42017-03-07 13:48:50 -0800459 }
460
461 /**
462 * Change persistent Enhanced 4G LTE Mode setting.
463 *
Brad Ebinger479f52c2017-08-28 13:19:22 -0700464 * @deprecated Doesn't support MSIM devices. Use {@link #setEnhanced4gLteModeSetting(boolean)}
Brad Ebinger16417b42017-03-07 13:48:50 -0800465 * instead.
Etan Cohen82f78122014-12-15 10:10:14 -0800466 */
467 public static void setEnhanced4gLteModeSetting(Context context, boolean enabled) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700468 ImsManager mgr = ImsManager.getInstance(context,
469 SubscriptionManager.getDefaultVoicePhoneId());
470 if (mgr != null) {
471 mgr.setEnhanced4gLteModeSetting(enabled);
Etan Cohen82f78122014-12-15 10:10:14 -0800472 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700473 loge("setEnhanced4gLteModeSetting: ImsManager null, value not set.");
Etan Cohen82f78122014-12-15 10:10:14 -0800474 }
475
476 /**
manabu, shimoda96aee542017-10-06 15:39:36 +0900477 * Change persistent Enhanced 4G LTE Mode setting. If the option is not editable
Brad Ebinger16417b42017-03-07 13:48:50 -0800478 * ({@link CarrierConfigManager#KEY_EDITABLE_ENHANCED_4G_LTE_BOOL} is false), this method will
manabu, shimoda96aee542017-10-06 15:39:36 +0900479 * set the setting to the default value specified by
480 * {@link CarrierConfigManager#KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL}.
Brad Ebinger16417b42017-03-07 13:48:50 -0800481 *
482 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700483 public void setEnhanced4gLteModeSetting(boolean enabled) {
manabu, shimoda96aee542017-10-06 15:39:36 +0900484 // If editable=false, we must keep default advanced 4G mode.
485 if (!getBooleanCarrierConfig(CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL)) {
486 enabled = getBooleanCarrierConfig(
487 CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL);
488 }
Brad Ebinger16417b42017-03-07 13:48:50 -0800489
Malcolm Chen212ca652017-09-28 17:28:45 -0700490 int prevSetting = SubscriptionManager.getIntegerSubscriptionProperty(
491 getSubId(), SubscriptionManager.ENHANCED_4G_MODE_ENABLED,
492 SUB_PROPERTY_NOT_INITIALIZED, mContext);
Brad Ebinger16417b42017-03-07 13:48:50 -0800493
manabu, shimoda96aee542017-10-06 15:39:36 +0900494 if (prevSetting != (enabled ?
495 ImsConfig.FeatureValueConstants.ON :
496 ImsConfig.FeatureValueConstants.OFF)) {
Malcolm Chen212ca652017-09-28 17:28:45 -0700497 SubscriptionManager.setSubscriptionProperty(getSubId(),
498 SubscriptionManager.ENHANCED_4G_MODE_ENABLED, booleanToPropertyString(enabled));
499 if (isNonTtyOrTtyOnVolteEnabled()) {
500 try {
501 setAdvanced4GMode(enabled);
502 } catch (ImsException ie) {
503 // do nothing
504 }
Brad Ebinger16417b42017-03-07 13:48:50 -0800505 }
506 }
507 }
508
509 /**
Etan Cohen82f78122014-12-15 10:10:14 -0800510 * Indicates whether the call is non-TTY or if TTY - whether TTY on VoLTE is
511 * supported.
Brad Ebinger16417b42017-03-07 13:48:50 -0800512 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700513 * {@link #isNonTtyOrTtyOnVolteEnabled()} instead.
Etan Cohen82f78122014-12-15 10:10:14 -0800514 */
515 public static boolean isNonTtyOrTtyOnVolteEnabled(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700516 ImsManager mgr = ImsManager.getInstance(context,
517 SubscriptionManager.getDefaultVoicePhoneId());
518 if (mgr != null) {
519 return mgr.isNonTtyOrTtyOnVolteEnabled();
520 }
521 loge("isNonTtyOrTtyOnVolteEnabled: ImsManager null, returning default value.");
522 return false;
523 }
524
525 /**
526 * Indicates whether the call is non-TTY or if TTY - whether TTY on VoLTE is
527 * supported on a per slot basis.
528 */
529 public boolean isNonTtyOrTtyOnVolteEnabled() {
530 if (getBooleanCarrierConfig(
fionaxu5803ef02016-03-08 11:48:48 -0800531 CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL)) {
Etan Cohen82f78122014-12-15 10:10:14 -0800532 return true;
533 }
534
Brad Ebinger479f52c2017-08-28 13:19:22 -0700535 TelecomManager tm = (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE);
Hall Liue511a202017-08-17 15:49:58 -0700536 if (tm == null) {
537 Log.w(TAG, "isNonTtyOrTtyOnVolteEnabled: telecom not available");
538 return true;
539 }
540 return tm.getCurrentTtyMode() == TelecomManager.TTY_MODE_OFF;
Etan Cohen82f78122014-12-15 10:10:14 -0800541 }
542
543 /**
Etan Cohenea2b5832014-10-23 18:50:35 -0700544 * Returns a platform configuration for VoLTE which may override the user setting.
Brad Ebinger16417b42017-03-07 13:48:50 -0800545 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700546 * {@link #isVolteEnabledByPlatform()} instead.
Etan Cohen45b5f312014-08-19 15:55:08 -0700547 */
Etan Cohenea2b5832014-10-23 18:50:35 -0700548 public static boolean isVolteEnabledByPlatform(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700549 ImsManager mgr = ImsManager.getInstance(context,
550 SubscriptionManager.getDefaultVoicePhoneId());
551 if (mgr != null) {
552 return mgr.isVolteEnabledByPlatform();
Etan Cohenaf55a402014-09-04 22:34:41 -0700553 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700554 loge("isVolteEnabledByPlatform: ImsManager null, returning default value.");
555 return false;
Etan Cohenb5388a32014-11-26 11:57:47 -0800556 }
557
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -0700558 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800559 * Returns a platform configuration for VoLTE which may override the user setting on a per Slot
560 * basis.
561 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700562 public boolean isVolteEnabledByPlatform() {
Malcolm Chen18837ff2017-10-25 17:05:41 -0700563 // We first read the per slot value. If doesn't exist, we read the general value. If still
564 // doesn't exist, we use the hardcoded default value.
565 if (SystemProperties.getInt(
566 PROPERTY_DBG_VOLTE_AVAIL_OVERRIDE + Integer.toString(mPhoneId),
567 SYSTEM_PROPERTY_NOT_SET) == 1 ||
568 SystemProperties.getInt(PROPERTY_DBG_VOLTE_AVAIL_OVERRIDE,
569 SYSTEM_PROPERTY_NOT_SET) == 1) {
Brad Ebinger16417b42017-03-07 13:48:50 -0800570 return true;
571 }
572
573 return mContext.getResources().getBoolean(
574 com.android.internal.R.bool.config_device_volte_available)
Malcolm Chen212ca652017-09-28 17:28:45 -0700575 && getBooleanCarrierConfig(CarrierConfigManager.KEY_CARRIER_VOLTE_AVAILABLE_BOOL)
Brad Ebinger479f52c2017-08-28 13:19:22 -0700576 && isGbaValid();
Brad Ebinger16417b42017-03-07 13:48:50 -0800577 }
578
579 /**
580 * Indicates whether VoLTE is provisioned on device.
581 *
582 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700583 * {@link #isVolteProvisionedOnDevice()} instead.
Etan Cohenb5388a32014-11-26 11:57:47 -0800584 */
585 public static boolean isVolteProvisionedOnDevice(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700586 ImsManager mgr = ImsManager.getInstance(context,
587 SubscriptionManager.getDefaultVoicePhoneId());
588 if (mgr != null) {
589 return mgr.isVolteProvisionedOnDevice();
Etan Cohenb5388a32014-11-26 11:57:47 -0800590 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700591 loge("isVolteProvisionedOnDevice: ImsManager null, returning default value.");
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -0700592 return true;
593 }
594
595 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800596 * Indicates whether VoLTE is provisioned on this slot.
597 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700598 public boolean isVolteProvisionedOnDevice() {
599 if (getBooleanCarrierConfig(
Brad Ebinger16417b42017-03-07 13:48:50 -0800600 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL)) {
601 return isVolteProvisioned();
602 }
603
604 return true;
605 }
606
607 /**
Meng Wang54fd41a2017-04-12 11:44:47 -0700608 * Indicates whether VoWifi is provisioned on device.
609 *
610 * When CarrierConfig KEY_CARRIER_VOLTE_OVERRIDE_WFC_PROVISIONING_BOOL is true, and VoLTE is not
611 * provisioned on device, this method returns false.
Brad Ebinger16417b42017-03-07 13:48:50 -0800612 *
613 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700614 * {@link #isWfcProvisionedOnDevice()} instead.
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -0700615 */
616 public static boolean isWfcProvisionedOnDevice(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700617 ImsManager mgr = ImsManager.getInstance(context,
618 SubscriptionManager.getDefaultVoicePhoneId());
619 if (mgr != null) {
620 return mgr.isWfcProvisionedOnDevice();
Meng Wang54fd41a2017-04-12 11:44:47 -0700621 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700622 loge("isWfcProvisionedOnDevice: ImsManager null, returning default value.");
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -0700623 return true;
624 }
625
626 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800627 * Indicates whether VoWifi is provisioned on slot.
Meng Wang54fd41a2017-04-12 11:44:47 -0700628 *
629 * When CarrierConfig KEY_CARRIER_VOLTE_OVERRIDE_WFC_PROVISIONING_BOOL is true, and VoLTE is not
630 * provisioned on device, this method returns false.
Brad Ebinger16417b42017-03-07 13:48:50 -0800631 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700632 public boolean isWfcProvisionedOnDevice() {
633 if (getBooleanCarrierConfig(
Meng Wang54fd41a2017-04-12 11:44:47 -0700634 CarrierConfigManager.KEY_CARRIER_VOLTE_OVERRIDE_WFC_PROVISIONING_BOOL)) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700635 if (!isVolteProvisionedOnDevice()) {
Meng Wang54fd41a2017-04-12 11:44:47 -0700636 return false;
637 }
638 }
639
Brad Ebinger479f52c2017-08-28 13:19:22 -0700640 if (getBooleanCarrierConfig(
Brad Ebinger16417b42017-03-07 13:48:50 -0800641 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL)) {
Meng Wang54fd41a2017-04-12 11:44:47 -0700642 return isWfcProvisioned();
Brad Ebinger16417b42017-03-07 13:48:50 -0800643 }
644
645 return true;
646 }
647
648 /**
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -0700649 * Indicates whether VT is provisioned on device
Brad Ebinger16417b42017-03-07 13:48:50 -0800650 *
651 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700652 * {@link #isVtProvisionedOnDevice()} instead.
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -0700653 */
654 public static boolean isVtProvisionedOnDevice(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700655 ImsManager mgr = ImsManager.getInstance(context,
656 SubscriptionManager.getDefaultVoicePhoneId());
657 if (mgr != null) {
658 return mgr.isVtProvisionedOnDevice();
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -0700659 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700660 loge("isVtProvisionedOnDevice: ImsManager null, returning default value.");
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -0700661 return true;
Etan Cohenb651fa52014-10-22 10:51:29 -0700662 }
663
Etan Cohenea2b5832014-10-23 18:50:35 -0700664 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800665 * Indicates whether VT is provisioned on slot.
666 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700667 public boolean isVtProvisionedOnDevice() {
668 if (getBooleanCarrierConfig(
Brad Ebinger16417b42017-03-07 13:48:50 -0800669 CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL)) {
670 return isVtProvisioned();
671 }
672
673 return true;
674 }
675
676 /**
Etan Cohenea2b5832014-10-23 18:50:35 -0700677 * Returns a platform configuration for VT which may override the user setting.
678 *
679 * Note: VT presumes that VoLTE is enabled (these are configuration settings
680 * which must be done correctly).
Brad Ebinger16417b42017-03-07 13:48:50 -0800681 *
682 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700683 * {@link #isVtEnabledByPlatform()} instead.
Etan Cohenea2b5832014-10-23 18:50:35 -0700684 */
Etan Cohenb651fa52014-10-22 10:51:29 -0700685 public static boolean isVtEnabledByPlatform(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700686 ImsManager mgr = ImsManager.getInstance(context,
687 SubscriptionManager.getDefaultVoicePhoneId());
688 if (mgr != null) {
689 return mgr.isVtEnabledByPlatform();
Etan Cohenea2b5832014-10-23 18:50:35 -0700690 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700691 loge("isVtEnabledByPlatform: ImsManager null, returning default value.");
692 return false;
Etan Cohen45b5f312014-08-19 15:55:08 -0700693 }
694
Etan Cohena00c9192014-12-23 15:02:29 -0800695 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800696 * Returns a platform configuration for VT which may override the user setting.
697 *
698 * Note: VT presumes that VoLTE is enabled (these are configuration settings
699 * which must be done correctly).
700 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700701 public boolean isVtEnabledByPlatform() {
Malcolm Chen18837ff2017-10-25 17:05:41 -0700702 // We first read the per slot value. If doesn't exist, we read the general value. If still
703 // doesn't exist, we use the hardcoded default value.
704 if (SystemProperties.getInt(PROPERTY_DBG_VT_AVAIL_OVERRIDE +
705 Integer.toString(mPhoneId), SYSTEM_PROPERTY_NOT_SET) == 1 ||
706 SystemProperties.getInt(
707 PROPERTY_DBG_VT_AVAIL_OVERRIDE, SYSTEM_PROPERTY_NOT_SET) == 1) {
Brad Ebinger16417b42017-03-07 13:48:50 -0800708 return true;
709 }
710
711 return mContext.getResources().getBoolean(
712 com.android.internal.R.bool.config_device_vt_available) &&
Malcolm Chen212ca652017-09-28 17:28:45 -0700713 getBooleanCarrierConfig(CarrierConfigManager.KEY_CARRIER_VT_AVAILABLE_BOOL) &&
Brad Ebinger479f52c2017-08-28 13:19:22 -0700714 isGbaValid();
Brad Ebinger16417b42017-03-07 13:48:50 -0800715 }
716
717 /**
Etan Cohena7d32e82015-05-04 18:02:09 -0700718 * Returns the user configuration of VT setting
Brad Ebinger16417b42017-03-07 13:48:50 -0800719 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700720 * {@link #isVtEnabledByUser()} instead.
Etan Cohena7d32e82015-05-04 18:02:09 -0700721 */
722 public static boolean isVtEnabledByUser(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700723 ImsManager mgr = ImsManager.getInstance(context,
724 SubscriptionManager.getDefaultVoicePhoneId());
725 if (mgr != null) {
726 return mgr.isVtEnabledByUser();
727 }
728 loge("isVtEnabledByUser: ImsManager null, returning default value.");
729 return false;
Etan Cohena7d32e82015-05-04 18:02:09 -0700730 }
731
732 /**
Malcolm Chen212ca652017-09-28 17:28:45 -0700733 * Returns the user configuration of VT setting per slot. If not set, it
734 * returns true as default value.
Brad Ebinger16417b42017-03-07 13:48:50 -0800735 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700736 public boolean isVtEnabledByUser() {
Malcolm Chen212ca652017-09-28 17:28:45 -0700737 int setting = SubscriptionManager.getIntegerSubscriptionProperty(
738 getSubId(), SubscriptionManager.VT_IMS_ENABLED,
739 SUB_PROPERTY_NOT_INITIALIZED, mContext);
740
741 // If it's never set, by default we return true.
manabu, shimoda96aee542017-10-06 15:39:36 +0900742 return (setting == SUB_PROPERTY_NOT_INITIALIZED
743 || setting == ImsConfig.FeatureValueConstants.ON);
Brad Ebinger16417b42017-03-07 13:48:50 -0800744 }
745
746 /**
Etan Cohena7d32e82015-05-04 18:02:09 -0700747 * Change persistent VT enabled setting
Brad Ebinger16417b42017-03-07 13:48:50 -0800748 *
Brad Ebinger479f52c2017-08-28 13:19:22 -0700749 * @deprecated Does not support MSIM devices. Please use {@link #setVtSetting(boolean)} instead.
Etan Cohena7d32e82015-05-04 18:02:09 -0700750 */
751 public static void setVtSetting(Context context, boolean enabled) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700752 ImsManager mgr = ImsManager.getInstance(context,
Etan Cohena7d32e82015-05-04 18:02:09 -0700753 SubscriptionManager.getDefaultVoicePhoneId());
Brad Ebinger479f52c2017-08-28 13:19:22 -0700754 if (mgr != null) {
755 mgr.setVtSetting(enabled);
Etan Cohena7d32e82015-05-04 18:02:09 -0700756 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700757 loge("setVtSetting: ImsManager null, can not set value.");
Etan Cohena7d32e82015-05-04 18:02:09 -0700758 }
759
Brad Ebinger16417b42017-03-07 13:48:50 -0800760 /**
761 * Change persistent VT enabled setting for slot.
762 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700763 public void setVtSetting(boolean enabled) {
Brad Ebinger172977a2018-01-16 09:36:56 -0800764 SubscriptionManager.setSubscriptionProperty(getSubId(), SubscriptionManager.VT_IMS_ENABLED,
Malcolm Chen212ca652017-09-28 17:28:45 -0700765 booleanToPropertyString(enabled));
Brad Ebinger172977a2018-01-16 09:36:56 -0800766
Brad Ebinger16417b42017-03-07 13:48:50 -0800767 try {
Brad Ebinger172977a2018-01-16 09:36:56 -0800768 changeMmTelCapability(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO,
769 ImsRegistrationImplBase.REGISTRATION_TECH_LTE, enabled);
Brad Ebinger16417b42017-03-07 13:48:50 -0800770
771 if (enabled) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700772 log("setVtSetting(b) : turnOnIms");
Brad Ebinger16417b42017-03-07 13:48:50 -0800773 turnOnIms();
Brad Ebinger2384f422018-03-15 16:09:41 -0700774 } else if (isTurnOffImsAllowedByPlatform()
Brad Ebinger479f52c2017-08-28 13:19:22 -0700775 && (!isVolteEnabledByPlatform()
776 || !isEnhanced4gLteModeSettingEnabledByUser())) {
777 log("setVtSetting(b) : imsServiceAllowTurnOff -> turnOffIms");
Brad Ebinger16417b42017-03-07 13:48:50 -0800778 turnOffIms();
779 }
Brad Ebinger172977a2018-01-16 09:36:56 -0800780 } catch (ImsException | RemoteException e) {
781 // The ImsService is down. Since the SubscriptionManager already recorded the user's
782 // preference, it will be resent in updateImsServiceConfig when the ImsPhoneCallTracker
783 // reconnects.
Brad Ebinger479f52c2017-08-28 13:19:22 -0700784 loge("setVtSetting(b): ", e);
Brad Ebinger16417b42017-03-07 13:48:50 -0800785 }
786 }
787
788 /**
Meng Wang9352c432016-06-08 14:22:20 -0700789 * Returns whether turning off ims is allowed by platform.
790 * The platform property may override the carrier config.
Brad Ebinger16417b42017-03-07 13:48:50 -0800791 *
792 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700793 * {@link #isTurnOffImsAllowedByPlatform()} instead.
Meng Wang9352c432016-06-08 14:22:20 -0700794 */
795 private static boolean isTurnOffImsAllowedByPlatform(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700796 ImsManager mgr = ImsManager.getInstance(context,
797 SubscriptionManager.getDefaultVoicePhoneId());
798 if (mgr != null) {
799 return mgr.isTurnOffImsAllowedByPlatform();
Meng Wang9352c432016-06-08 14:22:20 -0700800 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700801 loge("isTurnOffImsAllowedByPlatform: ImsManager null, returning default value.");
802 return true;
Meng Wang9352c432016-06-08 14:22:20 -0700803 }
804
Etan Cohena7d32e82015-05-04 18:02:09 -0700805 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800806 * Returns whether turning off ims is allowed by platform.
807 * The platform property may override the carrier config.
808 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700809 private boolean isTurnOffImsAllowedByPlatform() {
Malcolm Chen18837ff2017-10-25 17:05:41 -0700810 // We first read the per slot value. If doesn't exist, we read the general value. If still
811 // doesn't exist, we use the hardcoded default value.
812 if (SystemProperties.getInt(PROPERTY_DBG_ALLOW_IMS_OFF_OVERRIDE +
813 Integer.toString(mPhoneId), SYSTEM_PROPERTY_NOT_SET) == 1 ||
814 SystemProperties.getInt(
815 PROPERTY_DBG_ALLOW_IMS_OFF_OVERRIDE, SYSTEM_PROPERTY_NOT_SET) == 1) {
Brad Ebinger16417b42017-03-07 13:48:50 -0800816 return true;
817 }
Malcolm Chen18837ff2017-10-25 17:05:41 -0700818
Brad Ebinger479f52c2017-08-28 13:19:22 -0700819 return getBooleanCarrierConfig(
Brad Ebinger16417b42017-03-07 13:48:50 -0800820 CarrierConfigManager.KEY_CARRIER_ALLOW_TURNOFF_IMS_BOOL);
821 }
822
823 /**
Etan Cohena00c9192014-12-23 15:02:29 -0800824 * Returns the user configuration of WFC setting
Brad Ebinger16417b42017-03-07 13:48:50 -0800825 *
826 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700827 * {@link #isWfcEnabledByUser()} instead.
Etan Cohena00c9192014-12-23 15:02:29 -0800828 */
829 public static boolean isWfcEnabledByUser(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700830 ImsManager mgr = ImsManager.getInstance(context,
831 SubscriptionManager.getDefaultVoicePhoneId());
832 if (mgr != null) {
833 return mgr.isWfcEnabledByUser();
834 }
835 loge("isWfcEnabledByUser: ImsManager null, returning default value.");
836 return true;
Etan Cohena00c9192014-12-23 15:02:29 -0800837 }
838
839 /**
Malcolm Chen212ca652017-09-28 17:28:45 -0700840 * Returns the user configuration of WFC setting for slot. If not set, it
841 * queries CarrierConfig value as default.
Brad Ebinger16417b42017-03-07 13:48:50 -0800842 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700843 public boolean isWfcEnabledByUser() {
Malcolm Chen212ca652017-09-28 17:28:45 -0700844 int setting = SubscriptionManager.getIntegerSubscriptionProperty(
845 getSubId(), SubscriptionManager.WFC_IMS_ENABLED,
846 SUB_PROPERTY_NOT_INITIALIZED, mContext);
847
848 // SUB_PROPERTY_NOT_INITIALIZED indicates it's never set in sub db.
849 if (setting == SUB_PROPERTY_NOT_INITIALIZED) {
850 return getBooleanCarrierConfig(
851 CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL);
852 } else {
manabu, shimoda96aee542017-10-06 15:39:36 +0900853 return setting == ImsConfig.FeatureValueConstants.ON;
Malcolm Chen212ca652017-09-28 17:28:45 -0700854 }
Brad Ebinger16417b42017-03-07 13:48:50 -0800855 }
856
857 /**
858 * Change persistent WFC enabled setting.
859 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -0700860 * {@link #setWfcSetting} instead.
Etan Cohena00c9192014-12-23 15:02:29 -0800861 */
862 public static void setWfcSetting(Context context, boolean enabled) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700863 ImsManager mgr = ImsManager.getInstance(context,
Etan Cohena00c9192014-12-23 15:02:29 -0800864 SubscriptionManager.getDefaultVoicePhoneId());
Brad Ebinger479f52c2017-08-28 13:19:22 -0700865 if (mgr != null) {
866 mgr.setWfcSetting(enabled);
Etan Cohena00c9192014-12-23 15:02:29 -0800867 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700868 loge("setWfcSetting: ImsManager null, can not set value.");
Etan Cohena00c9192014-12-23 15:02:29 -0800869 }
870
871 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800872 * Change persistent WFC enabled setting for slot.
873 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700874 public void setWfcSetting(boolean enabled) {
Malcolm Chen212ca652017-09-28 17:28:45 -0700875 SubscriptionManager.setSubscriptionProperty(getSubId(),
876 SubscriptionManager.WFC_IMS_ENABLED, booleanToPropertyString(enabled));
Brad Ebinger16417b42017-03-07 13:48:50 -0800877
Meng Wangeba31e12018-04-17 11:27:21 -0700878 TelephonyManager tm = (TelephonyManager)
879 mContext.getSystemService(Context.TELEPHONY_SERVICE);
880 setWfcNonPersistent(enabled, getWfcMode(tm.isNetworkRoaming(getSubId())));
Meng Wang51c09072017-03-27 10:47:45 -0700881 }
882
883 /**
884 * Non-persistently change WFC enabled setting and WFC mode for slot
885 *
886 * @param wfcMode The WFC preference if WFC is enabled
887 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700888 public void setWfcNonPersistent(boolean enabled, int wfcMode) {
Meng Wang51c09072017-03-27 10:47:45 -0700889 // Force IMS to register over LTE when turning off WFC
890 int imsWfcModeFeatureValue =
891 enabled ? wfcMode : ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED;
892
Brad Ebinger16417b42017-03-07 13:48:50 -0800893 try {
Brad Ebinger172977a2018-01-16 09:36:56 -0800894 changeMmTelCapability(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
895 ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN, enabled);
Brad Ebinger16417b42017-03-07 13:48:50 -0800896
897 if (enabled) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700898 log("setWfcSetting() : turnOnIms");
Brad Ebinger16417b42017-03-07 13:48:50 -0800899 turnOnIms();
Brad Ebinger479f52c2017-08-28 13:19:22 -0700900 } else if (isTurnOffImsAllowedByPlatform()
901 && (!isVolteEnabledByPlatform()
902 || !isEnhanced4gLteModeSettingEnabledByUser())) {
903 log("setWfcSetting() : imsServiceAllowTurnOff -> turnOffIms");
Brad Ebinger16417b42017-03-07 13:48:50 -0800904 turnOffIms();
905 }
906
Brad Ebinger479f52c2017-08-28 13:19:22 -0700907 setWfcModeInternal(imsWfcModeFeatureValue);
Brad Ebinger172977a2018-01-16 09:36:56 -0800908 } catch (ImsException | RemoteException e) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700909 loge("setWfcSetting(): ", e);
Brad Ebinger16417b42017-03-07 13:48:50 -0800910 }
911 }
912
913 /**
914 * Returns the user configuration of WFC preference setting.
915 *
Malcolm Chen212ca652017-09-28 17:28:45 -0700916 * @deprecated Doesn't support MSIM devices. Use {@link #getWfcMode(boolean roaming)} instead.
Etan Cohena00c9192014-12-23 15:02:29 -0800917 */
918 public static int getWfcMode(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700919 ImsManager mgr = ImsManager.getInstance(context,
920 SubscriptionManager.getDefaultVoicePhoneId());
921 if (mgr != null) {
922 return mgr.getWfcMode();
923 }
924 loge("getWfcMode: ImsManager null, returning default value.");
925 return ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY;
Etan Cohena00c9192014-12-23 15:02:29 -0800926 }
927
928 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800929 * Returns the user configuration of WFC preference setting
Malcolm Chen212ca652017-09-28 17:28:45 -0700930 * @deprecated. Use {@link #getWfcMode(boolean roaming)} instead.
Brad Ebinger16417b42017-03-07 13:48:50 -0800931 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700932 public int getWfcMode() {
Malcolm Chen212ca652017-09-28 17:28:45 -0700933 return getWfcMode(false);
Brad Ebinger16417b42017-03-07 13:48:50 -0800934 }
935
936 /**
937 * Change persistent WFC preference setting.
938 *
Brad Ebinger479f52c2017-08-28 13:19:22 -0700939 * @deprecated Doesn't support MSIM devices. Use {@link #setWfcMode(int)} instead.
Etan Cohena00c9192014-12-23 15:02:29 -0800940 */
941 public static void setWfcMode(Context context, int wfcMode) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700942 ImsManager mgr = ImsManager.getInstance(context,
943 SubscriptionManager.getDefaultVoicePhoneId());
944 if (mgr != null) {
945 mgr.setWfcMode(wfcMode);
946 }
947 loge("setWfcMode: ImsManager null, can not set value.");
Pavel Zhamaitsiak9e6eca22015-03-16 15:30:53 -0700948 }
949
Meng Wang37477012016-09-20 09:59:56 -0700950 /**
Brad Ebinger16417b42017-03-07 13:48:50 -0800951 * Change persistent WFC preference setting for slot.
952 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700953 public void setWfcMode(int wfcMode) {
954 if (DBG) log("setWfcMode(i) - setting=" + wfcMode);
Malcolm Chen212ca652017-09-28 17:28:45 -0700955
956 SubscriptionManager.setSubscriptionProperty(getSubId(),
957 SubscriptionManager.WFC_IMS_MODE, Integer.toString(wfcMode));
Brad Ebinger16417b42017-03-07 13:48:50 -0800958
Brad Ebinger479f52c2017-08-28 13:19:22 -0700959 setWfcModeInternal(wfcMode);
Brad Ebinger16417b42017-03-07 13:48:50 -0800960 }
961
962 /**
Suresh Koleti76491082017-04-21 18:39:50 +0530963 * Changes the WFC mode to its default value for Carriers with non-editable WFC settings.
964 */
965 private void updateDefaultWfcMode() {
966 if (DBG) log("updateDefaultWfcMode");
Brad Ebinger479f52c2017-08-28 13:19:22 -0700967 if (!getBooleanCarrierConfig(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL)) {
968 setWfcMode(getIntCarrierConfig(
Suresh Koleti76491082017-04-21 18:39:50 +0530969 CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT));
970 }
971 }
972
973 /**
Meng Wang37477012016-09-20 09:59:56 -0700974 * Returns the user configuration of WFC preference setting
975 *
976 * @param roaming {@code false} for home network setting, {@code true} for roaming setting
Brad Ebinger16417b42017-03-07 13:48:50 -0800977 *
Brad Ebinger479f52c2017-08-28 13:19:22 -0700978 * @deprecated Doesn't support MSIM devices. Use {@link #getWfcMode(boolean)} instead.
Meng Wang37477012016-09-20 09:59:56 -0700979 */
980 public static int getWfcMode(Context context, boolean roaming) {
Brad Ebinger479f52c2017-08-28 13:19:22 -0700981 ImsManager mgr = ImsManager.getInstance(context,
982 SubscriptionManager.getDefaultVoicePhoneId());
983 if (mgr != null) {
984 return mgr.getWfcMode(roaming);
Meng Wang37477012016-09-20 09:59:56 -0700985 }
Brad Ebinger479f52c2017-08-28 13:19:22 -0700986 loge("getWfcMode: ImsManager null, returning default value.");
987 return ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY;
Meng Wang37477012016-09-20 09:59:56 -0700988 }
989
990 /**
Malcolm Chen212ca652017-09-28 17:28:45 -0700991 * Returns the user configuration of WFC preference setting for slot. If not set, it
992 * queries CarrierConfig value as default.
Brad Ebinger16417b42017-03-07 13:48:50 -0800993 *
994 * @param roaming {@code false} for home network setting, {@code true} for roaming setting
995 */
Brad Ebinger479f52c2017-08-28 13:19:22 -0700996 public int getWfcMode(boolean roaming) {
Brad Ebinger16417b42017-03-07 13:48:50 -0800997 int setting = 0;
998 if (!roaming) {
Malcolm Chen212ca652017-09-28 17:28:45 -0700999 setting = SubscriptionManager.getIntegerSubscriptionProperty(
1000 getSubId(), SubscriptionManager.WFC_IMS_MODE,
1001 SUB_PROPERTY_NOT_INITIALIZED, mContext);
1002
1003 // SUB_PROPERTY_NOT_INITIALIZED indicates it's never set in sub db.
1004 if (setting == SUB_PROPERTY_NOT_INITIALIZED) {
1005 setting = getIntCarrierConfig(
1006 CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT);
1007 }
Brad Ebinger479f52c2017-08-28 13:19:22 -07001008 if (DBG) log("getWfcMode - setting=" + setting);
Brad Ebinger16417b42017-03-07 13:48:50 -08001009 } else {
Malcolm Chen212ca652017-09-28 17:28:45 -07001010 setting = SubscriptionManager.getIntegerSubscriptionProperty(
1011 getSubId(), SubscriptionManager.WFC_IMS_ROAMING_MODE,
1012 SUB_PROPERTY_NOT_INITIALIZED, mContext);
1013
1014 // SUB_PROPERTY_NOT_INITIALIZED indicates it's never set in sub db.
1015 if (setting == SUB_PROPERTY_NOT_INITIALIZED) {
1016 setting = getIntCarrierConfig(
1017 CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ROAMING_MODE_INT);
1018 }
1019
Brad Ebinger479f52c2017-08-28 13:19:22 -07001020 if (DBG) log("getWfcMode (roaming) - setting=" + setting);
Brad Ebinger16417b42017-03-07 13:48:50 -08001021 }
1022 return setting;
1023 }
1024
1025 /**
Meng Wang37477012016-09-20 09:59:56 -07001026 * Change persistent WFC preference setting
1027 *
1028 * @param roaming {@code false} for home network setting, {@code true} for roaming setting
Brad Ebinger16417b42017-03-07 13:48:50 -08001029 *
Brad Ebinger479f52c2017-08-28 13:19:22 -07001030 * @deprecated Doesn't support MSIM devices. Please use {@link #setWfcMode(int, boolean)}
1031 * instead.
Meng Wang37477012016-09-20 09:59:56 -07001032 */
1033 public static void setWfcMode(Context context, int wfcMode, boolean roaming) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001034 ImsManager mgr = ImsManager.getInstance(context,
1035 SubscriptionManager.getDefaultVoicePhoneId());
1036 if (mgr != null) {
1037 mgr.setWfcMode(wfcMode, roaming);
Meng Wang37477012016-09-20 09:59:56 -07001038 }
Brad Ebinger479f52c2017-08-28 13:19:22 -07001039 loge("setWfcMode: ImsManager null, can not set value.");
Meng Wang37477012016-09-20 09:59:56 -07001040 }
1041
Brad Ebinger16417b42017-03-07 13:48:50 -08001042 /**
1043 * Change persistent WFC preference setting
1044 *
1045 * @param roaming {@code false} for home network setting, {@code true} for roaming setting
1046 */
Brad Ebinger479f52c2017-08-28 13:19:22 -07001047 public void setWfcMode(int wfcMode, boolean roaming) {
Brad Ebinger16417b42017-03-07 13:48:50 -08001048 if (!roaming) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001049 if (DBG) log("setWfcMode(i,b) - setting=" + wfcMode);
Malcolm Chen212ca652017-09-28 17:28:45 -07001050 SubscriptionManager.setSubscriptionProperty(getSubId(),
1051 SubscriptionManager.WFC_IMS_MODE, Integer.toString(wfcMode));
Brad Ebinger16417b42017-03-07 13:48:50 -08001052 } else {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001053 if (DBG) log("setWfcMode(i,b) (roaming) - setting=" + wfcMode);
Malcolm Chen212ca652017-09-28 17:28:45 -07001054 SubscriptionManager.setSubscriptionProperty(getSubId(),
1055 SubscriptionManager.WFC_IMS_ROAMING_MODE, Integer.toString(wfcMode));
Brad Ebinger16417b42017-03-07 13:48:50 -08001056 }
1057
Brad Ebinger479f52c2017-08-28 13:19:22 -07001058 TelephonyManager tm = (TelephonyManager)
1059 mContext.getSystemService(Context.TELEPHONY_SERVICE);
1060 if (roaming == tm.isNetworkRoaming(getSubId())) {
1061 setWfcModeInternal(wfcMode);
1062 }
1063 }
1064
1065 private int getSubId() {
Brad Ebinger16417b42017-03-07 13:48:50 -08001066 int[] subIds = SubscriptionManager.getSubId(mPhoneId);
1067 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
1068 if (subIds != null && subIds.length >= 1) {
1069 subId = subIds[0];
1070 }
Brad Ebinger479f52c2017-08-28 13:19:22 -07001071 return subId;
Brad Ebinger16417b42017-03-07 13:48:50 -08001072 }
1073
Pavel Zhamaitsiak9e6eca22015-03-16 15:30:53 -07001074 private static void setWfcModeInternal(Context context, int wfcMode) {
Etan Cohena00c9192014-12-23 15:02:29 -08001075 final ImsManager imsManager = ImsManager.getInstance(context,
1076 SubscriptionManager.getDefaultVoicePhoneId());
1077 if (imsManager != null) {
1078 final int value = wfcMode;
Pavel Zhamaitsiak47aeacf2016-03-30 18:54:55 -07001079 Thread thread = new Thread(new Runnable() {
Etan Cohena00c9192014-12-23 15:02:29 -08001080 public void run() {
1081 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08001082 imsManager.getConfigInterface().setConfig(
Etan Cohena00c9192014-12-23 15:02:29 -08001083 ImsConfig.ConfigConstants.VOICE_OVER_WIFI_MODE,
1084 value);
1085 } catch (ImsException e) {
1086 // do nothing
1087 }
1088 }
1089 });
Pavel Zhamaitsiak47aeacf2016-03-30 18:54:55 -07001090 thread.start();
Etan Cohena00c9192014-12-23 15:02:29 -08001091 }
1092 }
1093
Brad Ebinger479f52c2017-08-28 13:19:22 -07001094 private void setWfcModeInternal(int wfcMode) {
Brad Ebinger16417b42017-03-07 13:48:50 -08001095 final int value = wfcMode;
1096 Thread thread = new Thread(() -> {
Malcolm Chen212ca652017-09-28 17:28:45 -07001097 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08001098 getConfigInterface().setConfig(
Malcolm Chen212ca652017-09-28 17:28:45 -07001099 ImsConfig.ConfigConstants.VOICE_OVER_WIFI_MODE, value);
1100 } catch (ImsException e) {
1101 // do nothing
1102 }
Brad Ebinger16417b42017-03-07 13:48:50 -08001103 });
1104 thread.start();
1105 }
1106
Etan Cohena00c9192014-12-23 15:02:29 -08001107 /**
1108 * Returns the user configuration of WFC roaming setting
Brad Ebinger16417b42017-03-07 13:48:50 -08001109 *
1110 * @deprecated Does not support MSIM devices. Please use
Brad Ebinger479f52c2017-08-28 13:19:22 -07001111 * {@link #isWfcRoamingEnabledByUser()} instead.
Etan Cohena00c9192014-12-23 15:02:29 -08001112 */
1113 public static boolean isWfcRoamingEnabledByUser(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001114 ImsManager mgr = ImsManager.getInstance(context,
1115 SubscriptionManager.getDefaultVoicePhoneId());
1116 if (mgr != null) {
1117 return mgr.isWfcRoamingEnabledByUser();
1118 }
1119 loge("isWfcRoamingEnabledByUser: ImsManager null, returning default value.");
1120 return false;
Etan Cohena00c9192014-12-23 15:02:29 -08001121 }
1122
1123 /**
Malcolm Chen212ca652017-09-28 17:28:45 -07001124 * Returns the user configuration of WFC roaming setting for slot. If not set, it
1125 * queries CarrierConfig value as default.
Brad Ebinger16417b42017-03-07 13:48:50 -08001126 */
Brad Ebinger479f52c2017-08-28 13:19:22 -07001127 public boolean isWfcRoamingEnabledByUser() {
Malcolm Chen212ca652017-09-28 17:28:45 -07001128 int setting = SubscriptionManager.getIntegerSubscriptionProperty(
1129 getSubId(), SubscriptionManager.WFC_IMS_ROAMING_ENABLED,
1130 SUB_PROPERTY_NOT_INITIALIZED, mContext);
1131 if (setting == SUB_PROPERTY_NOT_INITIALIZED) {
1132 return getBooleanCarrierConfig(
1133 CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ROAMING_ENABLED_BOOL);
1134 } else {
manabu, shimoda96aee542017-10-06 15:39:36 +09001135 return setting == ImsConfig.FeatureValueConstants.ON;
Malcolm Chen212ca652017-09-28 17:28:45 -07001136 }
Brad Ebinger16417b42017-03-07 13:48:50 -08001137 }
1138
1139 /**
Etan Cohena00c9192014-12-23 15:02:29 -08001140 * Change persistent WFC roaming enabled setting
1141 */
1142 public static void setWfcRoamingSetting(Context context, boolean enabled) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001143 ImsManager mgr = ImsManager.getInstance(context,
Etan Cohena00c9192014-12-23 15:02:29 -08001144 SubscriptionManager.getDefaultVoicePhoneId());
Brad Ebinger479f52c2017-08-28 13:19:22 -07001145 if (mgr != null) {
1146 mgr.setWfcRoamingSetting(enabled);
Etan Cohena00c9192014-12-23 15:02:29 -08001147 }
Brad Ebinger479f52c2017-08-28 13:19:22 -07001148 loge("setWfcRoamingSetting: ImsManager null, value not set.");
Etan Cohena00c9192014-12-23 15:02:29 -08001149 }
1150
1151 /**
Brad Ebinger16417b42017-03-07 13:48:50 -08001152 * Change persistent WFC roaming enabled setting
1153 */
Brad Ebinger479f52c2017-08-28 13:19:22 -07001154 public void setWfcRoamingSetting(boolean enabled) {
Malcolm Chen212ca652017-09-28 17:28:45 -07001155 SubscriptionManager.setSubscriptionProperty(getSubId(),
1156 SubscriptionManager.WFC_IMS_ROAMING_ENABLED, booleanToPropertyString(enabled)
1157 );
Brad Ebinger16417b42017-03-07 13:48:50 -08001158
1159 setWfcRoamingSettingInternal(enabled);
1160 }
1161
1162 private void setWfcRoamingSettingInternal(boolean enabled) {
1163 final int value = enabled
1164 ? ImsConfig.FeatureValueConstants.ON
1165 : ImsConfig.FeatureValueConstants.OFF;
1166 Thread thread = new Thread(() -> {
Malcolm Chen212ca652017-09-28 17:28:45 -07001167 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08001168 getConfigInterface().setConfig(
Malcolm Chen212ca652017-09-28 17:28:45 -07001169 ImsConfig.ConfigConstants.VOICE_OVER_WIFI_ROAMING, value);
1170 } catch (ImsException e) {
1171 // do nothing
1172 }
Brad Ebinger16417b42017-03-07 13:48:50 -08001173 });
1174 thread.start();
1175 }
1176
1177 /**
Etan Cohena00c9192014-12-23 15:02:29 -08001178 * Returns a platform configuration for WFC which may override the user
1179 * setting. Note: WFC presumes that VoLTE is enabled (these are
1180 * configuration settings which must be done correctly).
Brad Ebinger16417b42017-03-07 13:48:50 -08001181 *
Brad Ebinger479f52c2017-08-28 13:19:22 -07001182 * @deprecated Doesn't work for MSIM devices. Use {@link #isWfcEnabledByPlatform()}
Brad Ebinger16417b42017-03-07 13:48:50 -08001183 * instead.
Etan Cohena00c9192014-12-23 15:02:29 -08001184 */
1185 public static boolean isWfcEnabledByPlatform(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001186 ImsManager mgr = ImsManager.getInstance(context,
1187 SubscriptionManager.getDefaultVoicePhoneId());
1188 if (mgr != null) {
1189 return mgr.isWfcEnabledByPlatform();
Etan Cohena00c9192014-12-23 15:02:29 -08001190 }
Brad Ebinger479f52c2017-08-28 13:19:22 -07001191 loge("isWfcEnabledByPlatform: ImsManager null, returning default value.");
1192 return false;
Pavel Zhamaitsiak57911d12015-10-20 14:26:34 -07001193 }
1194
1195 /**
Brad Ebinger16417b42017-03-07 13:48:50 -08001196 * Returns a platform configuration for WFC which may override the user
1197 * setting per slot. Note: WFC presumes that VoLTE is enabled (these are
1198 * configuration settings which must be done correctly).
1199 */
Brad Ebinger479f52c2017-08-28 13:19:22 -07001200 public boolean isWfcEnabledByPlatform() {
Malcolm Chen18837ff2017-10-25 17:05:41 -07001201 // We first read the per slot value. If doesn't exist, we read the general value. If still
1202 // doesn't exist, we use the hardcoded default value.
1203 if (SystemProperties.getInt(PROPERTY_DBG_WFC_AVAIL_OVERRIDE +
1204 Integer.toString(mPhoneId), SYSTEM_PROPERTY_NOT_SET) == 1 ||
1205 SystemProperties.getInt(
1206 PROPERTY_DBG_WFC_AVAIL_OVERRIDE, SYSTEM_PROPERTY_NOT_SET) == 1) {
Brad Ebinger16417b42017-03-07 13:48:50 -08001207 return true;
1208 }
1209
1210 return mContext.getResources().getBoolean(
1211 com.android.internal.R.bool.config_device_wfc_ims_available) &&
Brad Ebinger479f52c2017-08-28 13:19:22 -07001212 getBooleanCarrierConfig(
Brad Ebinger16417b42017-03-07 13:48:50 -08001213 CarrierConfigManager.KEY_CARRIER_WFC_IMS_AVAILABLE_BOOL) &&
Brad Ebinger479f52c2017-08-28 13:19:22 -07001214 isGbaValid();
Etan Cohena00c9192014-12-23 15:02:29 -08001215 }
1216
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001217 /**
Brad Ebinger16417b42017-03-07 13:48:50 -08001218 * If carrier requires that IMS is only available if GBA capable SIM is used,
1219 * then this function checks GBA bit in EF IST.
1220 *
1221 * Format of EF IST is defined in 3GPP TS 31.103 (Section 4.2.7).
1222 */
Brad Ebinger479f52c2017-08-28 13:19:22 -07001223 private boolean isGbaValid() {
1224 if (getBooleanCarrierConfig(
Brad Ebinger16417b42017-03-07 13:48:50 -08001225 CarrierConfigManager.KEY_CARRIER_IMS_GBA_REQUIRED_BOOL)) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001226 final TelephonyManager telephonyManager = new TelephonyManager(mContext, getSubId());
Brad Ebinger16417b42017-03-07 13:48:50 -08001227 String efIst = telephonyManager.getIsimIst();
1228 if (efIst == null) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001229 loge("isGbaValid - ISF is NULL");
Brad Ebinger16417b42017-03-07 13:48:50 -08001230 return true;
1231 }
1232 boolean result = efIst != null && efIst.length() > 1 &&
1233 (0x02 & (byte)efIst.charAt(1)) != 0;
Brad Ebinger479f52c2017-08-28 13:19:22 -07001234 if (DBG) log("isGbaValid - GBA capable=" + result + ", ISF=" + efIst);
Brad Ebinger16417b42017-03-07 13:48:50 -08001235 return result;
1236 }
1237 return true;
1238 }
1239
1240 /**
Malcolm Chen18837ff2017-10-25 17:05:41 -07001241 * Will return with config value or throw an ImsException if we receive an error from
1242 * ImsConfig for that value.
1243 */
1244 private boolean getProvisionedBool(ImsConfig config, int item) throws ImsException {
1245 int value = config.getProvisionedValue(item);
1246 if (value == ImsConfig.OperationStatusConstants.UNKNOWN) {
1247 throw new ImsException("getProvisionedBool failed with error for item: " + item,
1248 ImsReasonInfo.CODE_LOCAL_INTERNAL_ERROR);
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -07001249 }
Malcolm Chen18837ff2017-10-25 17:05:41 -07001250 return config.getProvisionedValue(item) == ImsConfig.FeatureValueConstants.ON;
Pavel Zhamaitsiak002b2042016-06-03 16:05:31 -07001251 }
1252
1253 /**
Malcolm Chen18837ff2017-10-25 17:05:41 -07001254 * Will return with config value or return false if we receive an error from
1255 * ImsConfig for that value.
Brad Ebingerbe6cb672017-08-25 14:55:00 -07001256 */
Malcolm Chen18837ff2017-10-25 17:05:41 -07001257 private boolean getProvisionedBoolNoException(int item) {
1258 try {
1259 ImsConfig config = getConfigInterface();
1260 return getProvisionedBool(config, item);
1261 } catch (ImsException ex) {
1262 return false;
Brad Ebingerbe6cb672017-08-25 14:55:00 -07001263 }
1264 }
1265
1266 /**
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001267 * Sync carrier config and user settings with ImsConfig.
1268 *
1269 * @param context for the manager object
1270 * @param phoneId phone id
1271 * @param force update
Brad Ebinger16417b42017-03-07 13:48:50 -08001272 *
Brad Ebinger479f52c2017-08-28 13:19:22 -07001273 * @deprecated Doesn't support MSIM devices. Use {@link #updateImsServiceConfig(boolean)}
1274 * instead.
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001275 */
1276 public static void updateImsServiceConfig(Context context, int phoneId, boolean force) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001277 ImsManager mgr = ImsManager.getInstance(context, phoneId);
1278 if (mgr != null) {
1279 mgr.updateImsServiceConfig(force);
Pavel Zhamaitsiakfc202992016-03-29 18:07:38 -07001280 }
Brad Ebinger479f52c2017-08-28 13:19:22 -07001281 loge("updateImsServiceConfig: ImsManager null, returning without update.");
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001282 }
1283
Pavel Zhamaitsiakdc16e452015-09-08 17:12:06 -07001284 /**
Brad Ebinger16417b42017-03-07 13:48:50 -08001285 * Sync carrier config and user settings with ImsConfig.
1286 *
Brad Ebinger16417b42017-03-07 13:48:50 -08001287 * @param force update
1288 */
Brad Ebinger479f52c2017-08-28 13:19:22 -07001289 public void updateImsServiceConfig(boolean force) {
Brad Ebinger16417b42017-03-07 13:48:50 -08001290 if (!force) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001291 TelephonyManager tm = new TelephonyManager(mContext, getSubId());
1292 if (tm.getSimState() != TelephonyManager.SIM_STATE_READY) {
1293 log("updateImsServiceConfig: SIM not ready");
Brad Ebinger16417b42017-03-07 13:48:50 -08001294 // Don't disable IMS if SIM is not ready
1295 return;
1296 }
1297 }
1298
1299 if (!mConfigUpdated || force) {
1300 try {
Brad Ebinger16417b42017-03-07 13:48:50 -08001301 // TODO: Extend ImsConfig API and set all feature values in single function call.
1302
1303 // Note: currently the order of updates is set to produce different order of
Brad Ebinger172977a2018-01-16 09:36:56 -08001304 // changeEnabledCapabilities() function calls from setAdvanced4GMode(). This is done
1305 // to differentiate this code path from vendor code perspective.
Brad Ebinger16417b42017-03-07 13:48:50 -08001306 boolean isImsUsed = updateVolteFeatureValue();
1307 isImsUsed |= updateWfcFeatureAndProvisionedValues();
1308 isImsUsed |= updateVideoCallFeatureValue();
1309
Brad Ebinger479f52c2017-08-28 13:19:22 -07001310 if (isImsUsed || !isTurnOffImsAllowedByPlatform()) {
Brad Ebinger16417b42017-03-07 13:48:50 -08001311 // Turn on IMS if it is used.
1312 // Also, if turning off is not allowed for current carrier,
1313 // we need to turn IMS on because it might be turned off before
1314 // phone switched to current carrier.
Brad Ebinger479f52c2017-08-28 13:19:22 -07001315 log("updateImsServiceConfig: turnOnIms");
Brad Ebinger16417b42017-03-07 13:48:50 -08001316 turnOnIms();
1317 } else {
1318 // Turn off IMS if it is not used AND turning off is allowed for carrier.
Brad Ebinger479f52c2017-08-28 13:19:22 -07001319 log("updateImsServiceConfig: turnOffIms");
Brad Ebinger16417b42017-03-07 13:48:50 -08001320 turnOffIms();
1321 }
1322
1323 mConfigUpdated = true;
Brad Ebinger172977a2018-01-16 09:36:56 -08001324 } catch (ImsException | RemoteException e) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001325 loge("updateImsServiceConfig: ", e);
Brad Ebinger16417b42017-03-07 13:48:50 -08001326 mConfigUpdated = false;
1327 }
1328 }
1329 }
1330
1331 /**
Pavel Zhamaitsiakdc16e452015-09-08 17:12:06 -07001332 * Update VoLTE config
1333 * @return whether feature is On
1334 * @throws ImsException
1335 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001336 private boolean updateVolteFeatureValue() throws RemoteException {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001337 boolean available = isVolteEnabledByPlatform();
1338 boolean enabled = isEnhanced4gLteModeSettingEnabledByUser();
1339 boolean isNonTty = isNonTtyOrTtyOnVolteEnabled();
Pavel Zhamaitsiak9510b1c2015-12-18 11:30:49 -08001340 boolean isFeatureOn = available && enabled && isNonTty;
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001341
1342 log("updateVolteFeatureValue: available = " + available
1343 + ", enabled = " + enabled
1344 + ", nonTTY = " + isNonTty);
1345
Brad Ebinger172977a2018-01-16 09:36:56 -08001346 changeMmTelCapability(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
1347 ImsRegistrationImplBase.REGISTRATION_TECH_LTE, isFeatureOn);
Pavel Zhamaitsiakdc16e452015-09-08 17:12:06 -07001348
Pavel Zhamaitsiak9510b1c2015-12-18 11:30:49 -08001349 return isFeatureOn;
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001350 }
1351
Pavel Zhamaitsiakdc16e452015-09-08 17:12:06 -07001352 /**
Jack Yu643ffe42016-07-08 14:25:46 -07001353 * Update video call over LTE config
Pavel Zhamaitsiakdc16e452015-09-08 17:12:06 -07001354 * @return whether feature is On
1355 * @throws ImsException
1356 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001357 private boolean updateVideoCallFeatureValue() throws RemoteException {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001358 boolean available = isVtEnabledByPlatform();
1359 boolean enabled = isVtEnabledByUser();
1360 boolean isNonTty = isNonTtyOrTtyOnVolteEnabled();
Amit Mahajan24f7b162016-07-21 16:33:53 -07001361 boolean isDataEnabled = isDataEnabled();
Brad Ebinger479f52c2017-08-28 13:19:22 -07001362 boolean ignoreDataEnabledChanged = getBooleanCarrierConfig(
Jack Yu57781852016-11-16 17:20:38 -08001363 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS);
Jack Yu643ffe42016-07-08 14:25:46 -07001364
Jack Yu57781852016-11-16 17:20:38 -08001365 boolean isFeatureOn = available && enabled && isNonTty
1366 && (ignoreDataEnabledChanged || isDataEnabled);
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001367
1368 log("updateVideoCallFeatureValue: available = " + available
1369 + ", enabled = " + enabled
Jack Yu643ffe42016-07-08 14:25:46 -07001370 + ", nonTTY = " + isNonTty
Amit Mahajan24f7b162016-07-21 16:33:53 -07001371 + ", data enabled = " + isDataEnabled);
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001372
Brad Ebinger172977a2018-01-16 09:36:56 -08001373 changeMmTelCapability(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO,
1374 ImsRegistrationImplBase.REGISTRATION_TECH_LTE, isFeatureOn);
Pavel Zhamaitsiakdc16e452015-09-08 17:12:06 -07001375
Pavel Zhamaitsiak9510b1c2015-12-18 11:30:49 -08001376 return isFeatureOn;
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001377 }
1378
Pavel Zhamaitsiakdc16e452015-09-08 17:12:06 -07001379 /**
1380 * Update WFC config
1381 * @return whether feature is On
1382 * @throws ImsException
1383 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001384 private boolean updateWfcFeatureAndProvisionedValues() throws RemoteException {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001385 TelephonyManager tm = new TelephonyManager(mContext, getSubId());
1386 boolean isNetworkRoaming = tm.isNetworkRoaming();
1387 boolean available = isWfcEnabledByPlatform();
1388 boolean enabled = isWfcEnabledByUser();
Suresh Koleti76491082017-04-21 18:39:50 +05301389 updateDefaultWfcMode();
Brad Ebinger479f52c2017-08-28 13:19:22 -07001390 int mode = getWfcMode(isNetworkRoaming);
1391 boolean roaming = isWfcRoamingEnabledByUser();
Pavel Zhamaitsiak9510b1c2015-12-18 11:30:49 -08001392 boolean isFeatureOn = available && enabled;
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001393
1394 log("updateWfcFeatureAndProvisionedValues: available = " + available
1395 + ", enabled = " + enabled
1396 + ", mode = " + mode
1397 + ", roaming = " + roaming);
1398
Brad Ebinger172977a2018-01-16 09:36:56 -08001399 changeMmTelCapability(MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
1400 ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN, isFeatureOn);
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001401
Pavel Zhamaitsiak9510b1c2015-12-18 11:30:49 -08001402 if (!isFeatureOn) {
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001403 mode = ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED;
1404 roaming = false;
1405 }
1406 setWfcModeInternal(mContext, mode);
Brad Ebinger16417b42017-03-07 13:48:50 -08001407 setWfcRoamingSettingInternal(roaming);
Pavel Zhamaitsiakdc16e452015-09-08 17:12:06 -07001408
Pavel Zhamaitsiak9510b1c2015-12-18 11:30:49 -08001409 return isFeatureOn;
Pavel Zhamaitsiak8ca52ff2015-09-04 17:08:35 -07001410 }
1411
Brad Ebinger16780ff2017-01-26 11:18:21 -08001412 /**
Brad Ebinger479f52c2017-08-28 13:19:22 -07001413 * Do NOT use this directly, instead use {@link #getInstance(Context, int)}.
Brad Ebinger16780ff2017-01-26 11:18:21 -08001414 */
1415 @VisibleForTesting
1416 public ImsManager(Context context, int phoneId) {
Wink Savilleef36ef62014-06-11 08:39:38 -07001417 mContext = context;
Etan Cohenabbd7882014-09-26 22:35:35 -07001418 mPhoneId = phoneId;
Brad Ebinger16780ff2017-01-26 11:18:21 -08001419 mConfigDynamicBind = mContext.getResources().getBoolean(
1420 com.android.internal.R.bool.config_dynamic_bind_ims);
Brad Ebinger16417b42017-03-07 13:48:50 -08001421 mConfigManager = (CarrierConfigManager) context.getSystemService(
1422 Context.CARRIER_CONFIG_SERVICE);
Brad Ebinger16780ff2017-01-26 11:18:21 -08001423 createImsService();
1424 }
1425
1426 /**
Brad Ebinger16780ff2017-01-26 11:18:21 -08001427 * @return Whether or not ImsManager is configured to Dynamically bind or not to support legacy
1428 * devices.
1429 */
1430 public boolean isDynamicBinding() {
1431 return mConfigDynamicBind;
Wink Savilleef36ef62014-06-11 08:39:38 -07001432 }
1433
Etan Cohenf4311122015-02-26 17:47:13 -08001434 /*
Brad Ebinger0aed76d2018-03-05 16:39:02 -08001435 * Returns a flag indicating whether the IMS service is available. If it is not available or
1436 * busy, it will try to connect before reporting failure.
Etan Cohenf4311122015-02-26 17:47:13 -08001437 */
1438 public boolean isServiceAvailable() {
Brad Ebinger0aed76d2018-03-05 16:39:02 -08001439 // If we are busy resolving dynamic IMS bindings, we are not available yet.
1440 TelephonyManager tm = (TelephonyManager)
1441 mContext.getSystemService(Context.TELEPHONY_SERVICE);
1442 if (tm.isResolvingImsBinding()) {
1443 Log.d(TAG, "isServiceAvailable: resolving IMS binding, returning false");
1444 return false;
1445 }
1446
Brad Ebingerff097922017-06-19 15:43:08 -07001447 connectIfServiceIsAvailable();
Brad Ebinger16780ff2017-01-26 11:18:21 -08001448 // mImsServiceProxy will always create an ImsServiceProxy.
Brad Ebinger172977a2018-01-16 09:36:56 -08001449 return mMmTelFeatureConnection.isBinderAlive();
Etan Cohenf4311122015-02-26 17:47:13 -08001450 }
1451
Suresh Koleticc3139c2017-11-03 18:23:57 +05301452 /*
1453 * Returns a flag indicating whether the IMS service is ready to send requests to lower layers.
1454 */
1455 public boolean isServiceReady() {
1456 connectIfServiceIsAvailable();
Brad Ebinger172977a2018-01-16 09:36:56 -08001457 return mMmTelFeatureConnection.isBinderReady();
Suresh Koleticc3139c2017-11-03 18:23:57 +05301458 }
1459
Brad Ebingerff097922017-06-19 15:43:08 -07001460 /**
1461 * If the service is available, try to reconnect.
1462 */
1463 public void connectIfServiceIsAvailable() {
Brad Ebinger172977a2018-01-16 09:36:56 -08001464 if (mMmTelFeatureConnection == null || !mMmTelFeatureConnection.isBinderAlive()) {
Brad Ebingerff097922017-06-19 15:43:08 -07001465 createImsService();
1466 }
1467 }
1468
Brad Ebinger172977a2018-01-16 09:36:56 -08001469 public void setConfigListener(ImsConfigListener listener) {
Pavel Zhamaitsiakf4b90322016-01-26 14:34:09 -08001470 mImsConfigListener = listener;
1471 }
1472
Brad Ebingerb10b61e2017-04-18 11:45:26 -07001473
1474 /**
1475 * Adds a callback for status changed events if the binder is already available. If it is not,
1476 * this method will throw an ImsException.
1477 */
Brad Ebinger6ddf28e2018-02-21 16:07:23 -08001478 @VisibleForTesting
Brad Ebinger172977a2018-01-16 09:36:56 -08001479 public void addNotifyStatusChangedCallbackIfAvailable(MmTelFeatureConnection.IFeatureUpdate c)
Brad Ebingerb10b61e2017-04-18 11:45:26 -07001480 throws ImsException {
Brad Ebinger172977a2018-01-16 09:36:56 -08001481 if (!mMmTelFeatureConnection.isBinderAlive()) {
Brad Ebingerb10b61e2017-04-18 11:45:26 -07001482 throw new ImsException("Binder is not active!",
1483 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
1484 }
Brad Ebinger16780ff2017-01-26 11:18:21 -08001485 if (c != null) {
1486 mStatusCallbacks.add(c);
1487 }
1488 }
1489
Brad Ebinger6ddf28e2018-02-21 16:07:23 -08001490 void removeNotifyStatusChangedCallback(MmTelFeatureConnection.IFeatureUpdate c) {
Brad Ebinger44fd8af2017-12-14 14:24:02 -08001491 if (c != null) {
1492 mStatusCallbacks.remove(c);
1493 } else {
1494 Log.w(TAG, "removeNotifyStatusChangedCallback: callback is null!");
1495 }
1496 }
1497
Wink Savilleef36ef62014-06-11 08:39:38 -07001498 /**
1499 * Opens the IMS service for making calls and/or receiving generic IMS calls.
Brad Ebinger172977a2018-01-16 09:36:56 -08001500 * The caller may make subsequent calls through {@link #makeCall}.
Wink Savilleef36ef62014-06-11 08:39:38 -07001501 * The IMS service will register the device to the operator's network with the credentials
1502 * (from ISIM) periodically in order to receive calls from the operator's network.
Brad Ebinger172977a2018-01-16 09:36:56 -08001503 * When the IMS service receives a new call, it will call
1504 * {@link MmTelFeature.Listener#onIncomingCall}
1505 * The listener contains a call ID extra {@link #getCallId} and it can be used to take a call.
1506 * @param listener A {@link MmTelFeature.Listener}, which is the interface the
1507 * {@link MmTelFeature} uses to notify the framework of updates
1508 * @throws NullPointerException if {@code listener} is null
Wink Savilleef36ef62014-06-11 08:39:38 -07001509 * @throws ImsException if calling the IMS service results in an error
1510 * @see #getCallId
Wink Savilleef36ef62014-06-11 08:39:38 -07001511 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001512 public void open(MmTelFeature.Listener listener) throws ImsException {
Wink Savilleef36ef62014-06-11 08:39:38 -07001513 checkAndThrowExceptionIfServiceUnavailable();
1514
Wink Savilleef36ef62014-06-11 08:39:38 -07001515 if (listener == null) {
1516 throw new NullPointerException("listener can't be null");
1517 }
1518
Wink Savilleef36ef62014-06-11 08:39:38 -07001519 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08001520 mMmTelFeatureConnection.openConnection(listener);
Wink Savilleef36ef62014-06-11 08:39:38 -07001521 } catch (RemoteException e) {
Brad Ebinger172977a2018-01-16 09:36:56 -08001522 throw new ImsException("open()", e, ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
Wink Savilleef36ef62014-06-11 08:39:38 -07001523 }
Wink Savilleef36ef62014-06-11 08:39:38 -07001524 }
1525
1526 /**
Pavel Zhamaitsiakce410172016-04-15 10:55:56 -07001527 * Adds registration listener to the IMS service.
1528 *
1529 * @param serviceClass a service class specified in {@link ImsServiceClass}
1530 * For VoLTE service, it MUST be a {@link ImsServiceClass#MMTEL}.
1531 * @param listener To listen to IMS registration events; It cannot be null
1532 * @throws NullPointerException if {@code listener} is null
1533 * @throws ImsException if calling the IMS service results in an error
Brad Ebinger9a0280c2017-06-01 15:58:48 -07001534 *
1535 * @deprecated Use {@link #addRegistrationListener(ImsConnectionStateListener)} instead.
Pavel Zhamaitsiakce410172016-04-15 10:55:56 -07001536 */
1537 public void addRegistrationListener(int serviceClass, ImsConnectionStateListener listener)
1538 throws ImsException {
Brad Ebinger9a0280c2017-06-01 15:58:48 -07001539 addRegistrationListener(listener);
1540 }
1541
1542 /**
1543 * Adds registration listener to the IMS service.
1544 *
1545 * @param listener To listen to IMS registration events; It cannot be null
1546 * @throws NullPointerException if {@code listener} is null
1547 * @throws ImsException if calling the IMS service results in an error
Brad Ebinger172977a2018-01-16 09:36:56 -08001548 * @deprecated use {@link #addRegistrationCallback(ImsRegistrationImplBase.Callback)} and
1549 * {@link #addCapabilitiesCallback(ImsFeature.CapabilityCallback)} instead.
Brad Ebinger9a0280c2017-06-01 15:58:48 -07001550 */
Brad Ebinger44fd8af2017-12-14 14:24:02 -08001551 public void addRegistrationListener(ImsConnectionStateListener listener) throws ImsException {
Pavel Zhamaitsiakce410172016-04-15 10:55:56 -07001552 if (listener == null) {
1553 throw new NullPointerException("listener can't be null");
1554 }
Brad Ebinger172977a2018-01-16 09:36:56 -08001555 addRegistrationCallback(listener);
1556 // connect the ImsConnectionStateListener to the new CapabilityCallback.
1557 addCapabilitiesCallback(new ImsFeature.CapabilityCallback() {
1558 @Override
1559 public void onCapabilitiesStatusChanged(ImsFeature.Capabilities config) {
1560 listener.onFeatureCapabilityChangedAdapter(getRegistrationTech(), config);
Brad Ebinger9a0280c2017-06-01 15:58:48 -07001561 }
Brad Ebinger172977a2018-01-16 09:36:56 -08001562 });
1563 log("Registration Callback registered.");
1564 }
1565
1566 /**
1567 * Adds a callback that gets called when IMS registration has changed.
1568 * @param callback A {@link ImsRegistrationImplBase.Callback} that will notify the caller when
1569 * IMS registration status has changed.
1570 * @throws ImsException when the ImsService connection is not available.
1571 */
1572 public void addRegistrationCallback(ImsRegistrationImplBase.Callback callback)
1573 throws ImsException {
1574 if (callback == null) {
1575 throw new NullPointerException("registration callback can't be null");
Brad Ebinger9a0280c2017-06-01 15:58:48 -07001576 }
Brad Ebinger172977a2018-01-16 09:36:56 -08001577
Brad Ebinger172977a2018-01-16 09:36:56 -08001578 try {
1579 mMmTelFeatureConnection.addRegistrationCallback(callback);
1580 log("Registration Callback registered.");
1581 // Only record if there isn't a RemoteException.
1582 } catch (RemoteException e) {
1583 throw new ImsException("addRegistrationCallback(IRIB)", e,
1584 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
1585 }
1586 }
1587
1588 /**
Brad Ebingerd1b1a3c2018-03-08 11:37:35 -08001589 * Removes a previously added registration callback that was added via
1590 * {@link #addRegistrationCallback(ImsRegistrationImplBase.Callback)} .
1591 * @param callback A {@link ImsRegistrationImplBase.Callback} that was previously added.
1592 * @throws ImsException when the ImsService connection is not available.
1593 */
1594 public void removeRegistrationListener(ImsRegistrationImplBase.Callback callback)
1595 throws ImsException {
1596 if (callback == null) {
1597 throw new NullPointerException("registration callback can't be null");
1598 }
1599
1600 try {
1601 mMmTelFeatureConnection.removeRegistrationCallback(callback);
1602 log("Registration callback removed.");
1603 } catch (RemoteException e) {
1604 throw new ImsException("removeRegistrationCallback(IRIB)", e,
1605 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
1606 }
1607 }
1608
1609 /**
Brad Ebinger172977a2018-01-16 09:36:56 -08001610 * Adds a callback that gets called when MMTel capability status has changed, for example when
1611 * Voice over IMS or VT over IMS is not available currently.
1612 * @param callback A {@link ImsFeature.CapabilityCallback} that will notify the caller when
1613 * MMTel capability status has changed.
1614 * @throws ImsException when the ImsService connection is not available.
1615 */
1616 public void addCapabilitiesCallback(ImsFeature.CapabilityCallback callback)
1617 throws ImsException {
1618 if (callback == null) {
1619 throw new NullPointerException("capabilities callback can't be null");
1620 }
1621
1622 checkAndThrowExceptionIfServiceUnavailable();
1623 try {
1624 mMmTelFeatureConnection.addCapabilityCallback(callback);
1625 log("Capability Callback registered.");
1626 // Only record if there isn't a RemoteException.
1627 } catch (RemoteException e) {
1628 throw new ImsException("addCapabilitiesCallback(IF)", e,
1629 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
Pavel Zhamaitsiakce410172016-04-15 10:55:56 -07001630 }
1631 }
1632
1633 /**
Brad Ebinger16780ff2017-01-26 11:18:21 -08001634 * Removes the registration listener from the IMS service.
1635 *
Brad Ebinger16780ff2017-01-26 11:18:21 -08001636 * @param listener Previously registered listener that will be removed. Can not be null.
1637 * @throws NullPointerException if {@code listener} is null
1638 * @throws ImsException if calling the IMS service results in an error
1639 * instead.
1640 */
Brad Ebingerb5f30c72017-02-17 14:54:31 -08001641 public void removeRegistrationListener(ImsConnectionStateListener listener)
Brad Ebinger16780ff2017-01-26 11:18:21 -08001642 throws ImsException {
Brad Ebinger16780ff2017-01-26 11:18:21 -08001643 if (listener == null) {
1644 throw new NullPointerException("listener can't be null");
1645 }
1646
Brad Ebinger172977a2018-01-16 09:36:56 -08001647 checkAndThrowExceptionIfServiceUnavailable();
1648 try {
1649 mMmTelFeatureConnection.removeRegistrationCallback(listener);
1650 log("Registration Callback/Listener registered.");
1651 // Only record if there isn't a RemoteException.
1652 } catch (RemoteException e) {
1653 throw new ImsException("addRegistrationCallback()", e,
1654 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
1655 }
1656 }
1657
1658 public @ImsRegistrationImplBase.ImsRegistrationTech int getRegistrationTech() {
1659 try {
1660 return mMmTelFeatureConnection.getRegistrationTech();
1661 } catch (RemoteException e) {
1662 Log.w(TAG, "getRegistrationTech: no connection to ImsService.");
1663 return ImsRegistrationImplBase.REGISTRATION_TECH_NONE;
Brad Ebinger16780ff2017-01-26 11:18:21 -08001664 }
1665 }
1666
1667 /**
Brad Ebinger172977a2018-01-16 09:36:56 -08001668 * Closes the connection and removes all active callbacks.
Wink Savilleef36ef62014-06-11 08:39:38 -07001669 * All the resources that were allocated to the service are also released.
Wink Savilleef36ef62014-06-11 08:39:38 -07001670 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001671 public void close() {
1672 if (mMmTelFeatureConnection != null) {
1673 mMmTelFeatureConnection.closeConnection();
Wink Savilleef36ef62014-06-11 08:39:38 -07001674 }
Brad Ebinger172977a2018-01-16 09:36:56 -08001675 mUt = null;
1676 mConfig = null;
1677 mEcbm = null;
1678 mMultiEndpoint = null;
Wink Savilleef36ef62014-06-11 08:39:38 -07001679 }
1680
1681 /**
1682 * Gets the configuration interface to provision / withdraw the supplementary service settings.
1683 *
Wink Savilleef36ef62014-06-11 08:39:38 -07001684 * @return the Ut interface instance
1685 * @throws ImsException if getting the Ut interface results in an error
1686 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001687 public ImsUtInterface getSupplementaryServiceConfiguration() throws ImsException {
Brad Ebinger16780ff2017-01-26 11:18:21 -08001688 // FIXME: manage the multiple Ut interfaces based on the session id
Brad Ebinger138b4a62017-06-20 16:29:50 -07001689 if (mUt != null && mUt.isBinderAlive()) {
1690 return mUt;
Wink Savilleef36ef62014-06-11 08:39:38 -07001691 }
1692
Brad Ebinger138b4a62017-06-20 16:29:50 -07001693 checkAndThrowExceptionIfServiceUnavailable();
1694 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08001695 IImsUt iUt = mMmTelFeatureConnection.getUtInterface();
Brad Ebinger138b4a62017-06-20 16:29:50 -07001696
1697 if (iUt == null) {
1698 throw new ImsException("getSupplementaryServiceConfiguration()",
1699 ImsReasonInfo.CODE_UT_NOT_SUPPORTED);
1700 }
1701
1702 mUt = new ImsUt(iUt);
1703 } catch (RemoteException e) {
1704 throw new ImsException("getSupplementaryServiceConfiguration()", e,
1705 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
1706 }
Wink Savilleef36ef62014-06-11 08:39:38 -07001707 return mUt;
1708 }
1709
1710 /**
Wink Savilleef36ef62014-06-11 08:39:38 -07001711 * Creates a {@link ImsCallProfile} from the service capabilities & IMS registration state.
1712 *
Wink Savilleef36ef62014-06-11 08:39:38 -07001713 * @param serviceType a service type that is specified in {@link ImsCallProfile}
1714 * {@link ImsCallProfile#SERVICE_TYPE_NONE}
1715 * {@link ImsCallProfile#SERVICE_TYPE_NORMAL}
1716 * {@link ImsCallProfile#SERVICE_TYPE_EMERGENCY}
1717 * @param callType a call type that is specified in {@link ImsCallProfile}
1718 * {@link ImsCallProfile#CALL_TYPE_VOICE}
1719 * {@link ImsCallProfile#CALL_TYPE_VT}
1720 * {@link ImsCallProfile#CALL_TYPE_VT_TX}
1721 * {@link ImsCallProfile#CALL_TYPE_VT_RX}
1722 * {@link ImsCallProfile#CALL_TYPE_VT_NODIR}
1723 * {@link ImsCallProfile#CALL_TYPE_VS}
1724 * {@link ImsCallProfile#CALL_TYPE_VS_TX}
1725 * {@link ImsCallProfile#CALL_TYPE_VS_RX}
1726 * @return a {@link ImsCallProfile} object
1727 * @throws ImsException if calling the IMS service results in an error
1728 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001729 public ImsCallProfile createCallProfile(int serviceType, int callType) throws ImsException {
Wink Savilleef36ef62014-06-11 08:39:38 -07001730 checkAndThrowExceptionIfServiceUnavailable();
1731
1732 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08001733 return mMmTelFeatureConnection.createCallProfile(serviceType, callType);
Wink Savilleef36ef62014-06-11 08:39:38 -07001734 } catch (RemoteException e) {
1735 throw new ImsException("createCallProfile()", e,
1736 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
1737 }
1738 }
1739
1740 /**
1741 * Creates a {@link ImsCall} to make a call.
1742 *
Wink Savilleef36ef62014-06-11 08:39:38 -07001743 * @param profile a call profile to make the call
1744 * (it contains service type, call type, media information, etc.)
Brad Ebinger172977a2018-01-16 09:36:56 -08001745 * @param callees participants to invite the conference call
Wink Savilleef36ef62014-06-11 08:39:38 -07001746 * @param listener listen to the call events from {@link ImsCall}
1747 * @return a {@link ImsCall} object
1748 * @throws ImsException if calling the IMS service results in an error
1749 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001750 public ImsCall makeCall(ImsCallProfile profile, String[] callees,
Wink Savilleef36ef62014-06-11 08:39:38 -07001751 ImsCall.Listener listener) throws ImsException {
1752 if (DBG) {
Brad Ebinger172977a2018-01-16 09:36:56 -08001753 log("makeCall :: profile=" + profile);
Wink Savilleef36ef62014-06-11 08:39:38 -07001754 }
1755
1756 checkAndThrowExceptionIfServiceUnavailable();
1757
1758 ImsCall call = new ImsCall(mContext, profile);
1759
1760 call.setListener(listener);
Brad Ebinger172977a2018-01-16 09:36:56 -08001761 ImsCallSession session = createCallSession(profile);
Wink Savilleef36ef62014-06-11 08:39:38 -07001762
1763 if ((callees != null) && (callees.length == 1)) {
1764 call.start(session, callees[0]);
1765 } else {
1766 call.start(session, callees);
1767 }
1768
1769 return call;
1770 }
1771
1772 /**
1773 * Creates a {@link ImsCall} to take an incoming call.
1774 *
Brad Ebinger16780ff2017-01-26 11:18:21 -08001775 * @param sessionId a session id which is obtained from {@link ImsManager#open}
Brad Ebinger172977a2018-01-16 09:36:56 -08001776 * @param incomingCallExtras the incoming call broadcast intent
Wink Savilleef36ef62014-06-11 08:39:38 -07001777 * @param listener to listen to the call events from {@link ImsCall}
1778 * @return a {@link ImsCall} object
1779 * @throws ImsException if calling the IMS service results in an error
1780 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001781 public ImsCall takeCall(IImsCallSession session, Bundle incomingCallExtras,
Wink Savilleef36ef62014-06-11 08:39:38 -07001782 ImsCall.Listener listener) throws ImsException {
1783 if (DBG) {
Brad Ebinger172977a2018-01-16 09:36:56 -08001784 log("takeCall :: incomingCall=" + incomingCallExtras);
Wink Savilleef36ef62014-06-11 08:39:38 -07001785 }
1786
1787 checkAndThrowExceptionIfServiceUnavailable();
1788
Brad Ebinger172977a2018-01-16 09:36:56 -08001789 if (incomingCallExtras == null) {
Wink Savilleef36ef62014-06-11 08:39:38 -07001790 throw new ImsException("Can't retrieve session with null intent",
1791 ImsReasonInfo.CODE_LOCAL_ILLEGAL_ARGUMENT);
1792 }
1793
Brad Ebinger172977a2018-01-16 09:36:56 -08001794 String callId = getCallId(incomingCallExtras);
Wink Savilleef36ef62014-06-11 08:39:38 -07001795
1796 if (callId == null) {
1797 throw new ImsException("Call ID missing in the incoming call intent",
1798 ImsReasonInfo.CODE_LOCAL_ILLEGAL_ARGUMENT);
1799 }
1800
1801 try {
Wink Savilleef36ef62014-06-11 08:39:38 -07001802 if (session == null) {
1803 throw new ImsException("No pending session for the call",
1804 ImsReasonInfo.CODE_LOCAL_NO_PENDING_CALL);
1805 }
1806
1807 ImsCall call = new ImsCall(mContext, session.getCallProfile());
1808
1809 call.attachSession(new ImsCallSession(session));
1810 call.setListener(listener);
1811
1812 return call;
1813 } catch (Throwable t) {
1814 throw new ImsException("takeCall()", t, ImsReasonInfo.CODE_UNSPECIFIED);
1815 }
1816 }
1817
1818 /**
Libin.Tang@motorola.com076c55d2014-06-23 19:46:36 -05001819 * Gets the config interface to get/set service/capability parameters.
1820 *
1821 * @return the ImsConfig instance.
1822 * @throws ImsException if getting the setting interface results in an error.
1823 */
1824 public ImsConfig getConfigInterface() throws ImsException {
Brad Ebinger138b4a62017-06-20 16:29:50 -07001825 if (mConfig != null && mConfig.isBinderAlive()) {
1826 return mConfig;
Libin.Tang@motorola.com076c55d2014-06-23 19:46:36 -05001827 }
Brad Ebinger138b4a62017-06-20 16:29:50 -07001828
1829 checkAndThrowExceptionIfServiceUnavailable();
1830 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08001831 IImsConfig config = mMmTelFeatureConnection.getConfigInterface();
Brad Ebinger138b4a62017-06-20 16:29:50 -07001832 if (config == null) {
1833 throw new ImsException("getConfigInterface()",
1834 ImsReasonInfo.CODE_LOCAL_SERVICE_UNAVAILABLE);
1835 }
1836 mConfig = new ImsConfig(config, mContext);
1837 } catch (RemoteException e) {
1838 throw new ImsException("getConfigInterface()", e,
1839 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
1840 }
Libin.Tang@motorola.com076c55d2014-06-23 19:46:36 -05001841 return mConfig;
1842 }
1843
Brad Ebinger172977a2018-01-16 09:36:56 -08001844 public void changeMmTelCapability(
1845 @MmTelFeature.MmTelCapabilities.MmTelCapability int capability,
1846 @ImsRegistrationImplBase.ImsRegistrationTech int radioTech,
1847 boolean isEnabled) throws RemoteException {
1848 CapabilityChangeRequest request = new CapabilityChangeRequest();
1849 if (isEnabled) {
1850 request.addCapabilitiesToEnableForTech(capability, radioTech);
1851 } else {
1852 request.addCapabilitiesToDisableForTech(capability, radioTech);
1853 }
1854 mMmTelFeatureConnection.changeEnabledCapabilities(request, null);
1855 if (mImsConfigListener != null) {
1856 mImsConfigListener.onSetFeatureResponse(capability,
1857 mMmTelFeatureConnection.getRegistrationTech(),
1858 isEnabled ? ImsConfig.FeatureValueConstants.ON
1859 : ImsConfig.FeatureValueConstants.OFF, -1);
1860 }
1861 }
1862
Hall Liub77d8972018-01-22 19:15:05 -08001863 public void setRttEnabled(boolean enabled) {
1864 try {
1865 setAdvanced4GMode(enabled || isEnhanced4gLteModeSettingEnabledByUser());
1866 final int value = enabled ? ImsConfig.FeatureValueConstants.ON :
1867 ImsConfig.FeatureValueConstants.OFF;
1868 Thread thread = new Thread(() -> {
1869 try {
1870 Log.i(ImsManager.class.getSimpleName(), "Setting RTT enabled to " + enabled);
1871 getConfigInterface().setProvisionedValue(
1872 ImsConfig.ConfigConstants.RTT_SETTING_ENABLED, value);
1873 } catch (ImsException e) {
1874 Log.e(ImsManager.class.getSimpleName(), "Unable to set RTT enabled to "
1875 + enabled + ": " + e);
1876 }
1877 });
1878 thread.start();
1879 } catch (ImsException e) {
1880 Log.e(ImsManager.class.getSimpleName(), "Unable to set RTT enabled to " + enabled
1881 + ": " + e);
1882 }
1883 }
1884
Hall Liue511a202017-08-17 15:49:58 -07001885 /**
1886 * Set the TTY mode. This is the actual tty mode (varies depending on peripheral status)
1887 */
1888 public void setTtyMode(int ttyMode) throws ImsException {
Brad Ebinger479f52c2017-08-28 13:19:22 -07001889 if (!getBooleanCarrierConfig(
Hall Liue511a202017-08-17 15:49:58 -07001890 CarrierConfigManager.KEY_CARRIER_VOLTE_TTY_SUPPORTED_BOOL)) {
1891 setAdvanced4GMode((ttyMode == TelecomManager.TTY_MODE_OFF) &&
Brad Ebinger479f52c2017-08-28 13:19:22 -07001892 isEnhanced4gLteModeSettingEnabledByUser());
Hall Liue511a202017-08-17 15:49:58 -07001893 }
1894 }
1895
1896 /**
1897 * Sets the UI TTY mode. This is the preferred TTY mode that the user sets in the call
1898 * settings screen.
1899 */
Brad Ebingerb5f30c72017-02-17 14:54:31 -08001900 public void setUiTTYMode(Context context, int uiTtyMode, Message onComplete)
Shriram Ganeshc403b7b2014-08-14 14:18:57 +05301901 throws ImsException {
1902
Etan Cohen82f78122014-12-15 10:10:14 -08001903 checkAndThrowExceptionIfServiceUnavailable();
Shriram Ganeshc403b7b2014-08-14 14:18:57 +05301904
Etan Cohen82f78122014-12-15 10:10:14 -08001905 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08001906 mMmTelFeatureConnection.setUiTTYMode(uiTtyMode, onComplete);
Etan Cohen82f78122014-12-15 10:10:14 -08001907 } catch (RemoteException e) {
1908 throw new ImsException("setTTYMode()", e,
1909 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
1910 }
Shriram Ganeshc403b7b2014-08-14 14:18:57 +05301911 }
1912
Naveen Kalla525c3a22017-02-06 14:46:42 -08001913 private ImsReasonInfo makeACopy(ImsReasonInfo imsReasonInfo) {
1914 Parcel p = Parcel.obtain();
1915 imsReasonInfo.writeToParcel(p, 0);
1916 p.setDataPosition(0);
1917 ImsReasonInfo clonedReasonInfo = ImsReasonInfo.CREATOR.createFromParcel(p);
1918 p.recycle();
1919 return clonedReasonInfo;
1920 }
1921
1922 /**
1923 * Get Recent IMS Disconnect Reasons.
1924 *
1925 * @return ArrayList of ImsReasonInfo objects. MAX size of the arraylist
1926 * is MAX_RECENT_DISCONNECT_REASONS. The objects are in the
1927 * chronological order.
1928 */
1929 public ArrayList<ImsReasonInfo> getRecentImsDisconnectReasons() {
1930 ArrayList<ImsReasonInfo> disconnectReasons = new ArrayList<>();
1931
1932 for (ImsReasonInfo reason : mRecentDisconnectReasons) {
1933 disconnectReasons.add(makeACopy(reason));
1934 }
1935 return disconnectReasons;
1936 }
Brad Ebinger16417b42017-03-07 13:48:50 -08001937
Brad Ebinger172977a2018-01-16 09:36:56 -08001938 public int getImsServiceState() throws ImsException {
1939 return mMmTelFeatureConnection.getFeatureState();
Brad Ebinger16780ff2017-01-26 11:18:21 -08001940 }
Naveen Kalla525c3a22017-02-06 14:46:42 -08001941
Libin.Tang@motorola.com076c55d2014-06-23 19:46:36 -05001942 /**
Junda Liue7663c02015-06-23 11:16:26 -07001943 * Get the boolean config from carrier config manager.
1944 *
Brad Ebinger16417b42017-03-07 13:48:50 -08001945 * @param key config key defined in CarrierConfigManager
1946 * @return boolean value of corresponding key.
1947 */
Brad Ebinger479f52c2017-08-28 13:19:22 -07001948 private boolean getBooleanCarrierConfig(String key) {
Brad Ebinger16417b42017-03-07 13:48:50 -08001949 int[] subIds = SubscriptionManager.getSubId(mPhoneId);
1950 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
1951 if (subIds != null && subIds.length >= 1) {
1952 subId = subIds[0];
1953 }
1954 PersistableBundle b = null;
1955 if (mConfigManager != null) {
1956 // If an invalid subId is used, this bundle will contain default values.
1957 b = mConfigManager.getConfigForSubId(subId);
1958 }
1959 if (b != null) {
1960 return b.getBoolean(key);
1961 } else {
1962 // Return static default defined in CarrierConfigManager.
1963 return CarrierConfigManager.getDefaultConfig().getBoolean(key);
1964 }
1965 }
1966
1967 /**
fionaxu5803ef02016-03-08 11:48:48 -08001968 * Get the int config from carrier config manager.
1969 *
Brad Ebinger16417b42017-03-07 13:48:50 -08001970 * @param key config key defined in CarrierConfigManager
1971 * @return integer value of corresponding key.
1972 */
Brad Ebinger479f52c2017-08-28 13:19:22 -07001973 private int getIntCarrierConfig(String key) {
Brad Ebinger16417b42017-03-07 13:48:50 -08001974 int[] subIds = SubscriptionManager.getSubId(mPhoneId);
1975 int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
1976 if (subIds != null && subIds.length >= 1) {
1977 subId = subIds[0];
1978 }
1979 PersistableBundle b = null;
1980 if (mConfigManager != null) {
1981 // If an invalid subId is used, this bundle will contain default values.
1982 b = mConfigManager.getConfigForSubId(subId);
1983 }
1984 if (b != null) {
1985 return b.getInt(key);
1986 } else {
1987 // Return static default defined in CarrierConfigManager.
1988 return CarrierConfigManager.getDefaultConfig().getInt(key);
1989 }
1990 }
1991
1992 /**
Wink Savilleef36ef62014-06-11 08:39:38 -07001993 * Gets the call ID from the specified incoming call broadcast intent.
1994 *
Brad Ebinger172977a2018-01-16 09:36:56 -08001995 * @param incomingCallExtras the incoming call broadcast intent
Wink Savilleef36ef62014-06-11 08:39:38 -07001996 * @return the call ID or null if the intent does not contain it
1997 */
Brad Ebinger172977a2018-01-16 09:36:56 -08001998 private static String getCallId(Bundle incomingCallExtras) {
1999 if (incomingCallExtras == null) {
Wink Savilleef36ef62014-06-11 08:39:38 -07002000 return null;
2001 }
2002
Brad Ebinger172977a2018-01-16 09:36:56 -08002003 return incomingCallExtras.getString(EXTRA_CALL_ID);
Wink Savilleef36ef62014-06-11 08:39:38 -07002004 }
2005
2006 /**
Brad Ebingerb10b61e2017-04-18 11:45:26 -07002007 * Checks to see if the ImsService Binder is connected. If it is not, we try to create the
2008 * connection again.
Wink Savilleef36ef62014-06-11 08:39:38 -07002009 */
2010 private void checkAndThrowExceptionIfServiceUnavailable()
2011 throws ImsException {
Brad Ebinger172977a2018-01-16 09:36:56 -08002012 if (mMmTelFeatureConnection == null || !mMmTelFeatureConnection.isBinderAlive()) {
Brad Ebinger16780ff2017-01-26 11:18:21 -08002013 createImsService();
Wink Savilleef36ef62014-06-11 08:39:38 -07002014
Brad Ebinger172977a2018-01-16 09:36:56 -08002015 if (mMmTelFeatureConnection == null) {
Wink Savilleef36ef62014-06-11 08:39:38 -07002016 throw new ImsException("Service is unavailable",
2017 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2018 }
2019 }
2020 }
2021
Brad Ebinger16780ff2017-01-26 11:18:21 -08002022 /**
2023 * Binds the IMS service to make/receive the call. Supports two methods of exposing an
2024 * ImsService:
2025 * 1) com.android.ims.ImsService implementation in ServiceManager (deprecated).
2026 * 2) android.telephony.ims.ImsService implementation through ImsResolver.
2027 */
2028 private void createImsService() {
Brad Ebinger172977a2018-01-16 09:36:56 -08002029 Rlog.i(TAG, "Creating ImsService");
2030 mMmTelFeatureConnection = MmTelFeatureConnection.create(mContext, mPhoneId);
2031
Brad Ebinger44fd8af2017-12-14 14:24:02 -08002032 // Forwarding interface to tell mStatusCallbacks that the Proxy is unavailable.
Brad Ebinger172977a2018-01-16 09:36:56 -08002033 mMmTelFeatureConnection.setStatusCallback(new MmTelFeatureConnection.IFeatureUpdate() {
Brad Ebinger44fd8af2017-12-14 14:24:02 -08002034 @Override
2035 public void notifyStateChanged() {
Brad Ebinger172977a2018-01-16 09:36:56 -08002036 mStatusCallbacks.forEach(MmTelFeatureConnection.IFeatureUpdate::notifyStateChanged);
Brad Ebinger44fd8af2017-12-14 14:24:02 -08002037 }
2038
2039 @Override
2040 public void notifyUnavailable() {
Brad Ebinger172977a2018-01-16 09:36:56 -08002041 mStatusCallbacks.forEach(MmTelFeatureConnection.IFeatureUpdate::notifyUnavailable);
Brad Ebinger44fd8af2017-12-14 14:24:02 -08002042 }
2043 });
Etan Cohend7727462014-07-12 14:54:10 -07002044 }
2045
Wink Savilleef36ef62014-06-11 08:39:38 -07002046 /**
2047 * Creates a {@link ImsCallSession} with the specified call profile.
2048 * Use other methods, if applicable, instead of interacting with
2049 * {@link ImsCallSession} directly.
2050 *
Wink Savilleef36ef62014-06-11 08:39:38 -07002051 * @param profile a call profile to make the call
2052 */
Brad Ebinger172977a2018-01-16 09:36:56 -08002053 private ImsCallSession createCallSession(ImsCallProfile profile) throws ImsException {
Wink Savilleef36ef62014-06-11 08:39:38 -07002054 try {
Brad Ebingerb10b61e2017-04-18 11:45:26 -07002055 // Throws an exception if the ImsService Feature is not ready to accept commands.
Brad Ebinger172977a2018-01-16 09:36:56 -08002056 return new ImsCallSession(mMmTelFeatureConnection.createCallSession(profile));
Wink Savilleef36ef62014-06-11 08:39:38 -07002057 } catch (RemoteException e) {
Brad Ebingerb10b61e2017-04-18 11:45:26 -07002058 Rlog.w(TAG, "CreateCallSession: Error, remote exception: " + e.getMessage());
2059 throw new ImsException("createCallSession()", e,
2060 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2061
Wink Savilleef36ef62014-06-11 08:39:38 -07002062 }
2063 }
2064
Etan Cohena00c9192014-12-23 15:02:29 -08002065 private static void log(String s) {
Wink Savilleef36ef62014-06-11 08:39:38 -07002066 Rlog.d(TAG, s);
2067 }
2068
Etan Cohena00c9192014-12-23 15:02:29 -08002069 private static void loge(String s) {
Wink Savilleef36ef62014-06-11 08:39:38 -07002070 Rlog.e(TAG, s);
2071 }
2072
Etan Cohena00c9192014-12-23 15:02:29 -08002073 private static void loge(String s, Throwable t) {
Wink Savilleef36ef62014-06-11 08:39:38 -07002074 Rlog.e(TAG, s, t);
2075 }
2076
2077 /**
ram7da5a112014-07-16 20:59:27 +05302078 * Used for turning on IMS.if its off already
2079 */
Etan Cohen82f78122014-12-15 10:10:14 -08002080 private void turnOnIms() throws ImsException {
Brad Ebinger172977a2018-01-16 09:36:56 -08002081 TelephonyManager tm = (TelephonyManager)
2082 mContext.getSystemService(Context.TELEPHONY_SERVICE);
2083 tm.enableIms(mPhoneId);
ram7da5a112014-07-16 20:59:27 +05302084 }
2085
Omkar Kolangade75f3ca32014-10-24 11:10:52 -07002086 private boolean isImsTurnOffAllowed() {
Brad Ebinger479f52c2017-08-28 13:19:22 -07002087 return isTurnOffImsAllowedByPlatform()
2088 && (!isWfcEnabledByPlatform()
2089 || !isWfcEnabledByUser());
Omkar Kolangade75f3ca32014-10-24 11:10:52 -07002090 }
2091
Amit Mahajan9cba36d2016-08-11 10:17:23 -07002092 private void setLteFeatureValues(boolean turnOn) {
2093 log("setLteFeatureValues: " + turnOn);
Brad Ebinger172977a2018-01-16 09:36:56 -08002094 CapabilityChangeRequest request = new CapabilityChangeRequest();
2095 if (turnOn) {
2096 request.addCapabilitiesToEnableForTech(
2097 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
2098 ImsRegistrationImplBase.REGISTRATION_TECH_LTE);
2099 } else {
2100 request.addCapabilitiesToDisableForTech(
2101 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE,
2102 ImsRegistrationImplBase.REGISTRATION_TECH_LTE);
2103 }
Pavel Zhamaitsiakff29b9d2016-04-15 12:16:57 -07002104
Brad Ebinger172977a2018-01-16 09:36:56 -08002105 if (isVolteEnabledByPlatform()) {
2106 boolean ignoreDataEnabledChanged = getBooleanCarrierConfig(
2107 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS);
2108 boolean enableViLte = turnOn && isVtEnabledByUser() &&
2109 (ignoreDataEnabledChanged || isDataEnabled());
2110 if (enableViLte) {
2111 request.addCapabilitiesToEnableForTech(
2112 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO,
2113 ImsRegistrationImplBase.REGISTRATION_TECH_LTE);
2114 } else {
2115 request.addCapabilitiesToDisableForTech(
2116 MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO,
2117 ImsRegistrationImplBase.REGISTRATION_TECH_LTE);
Etan Cohenb651fa52014-10-22 10:51:29 -07002118 }
Brad Ebinger172977a2018-01-16 09:36:56 -08002119 }
2120 try {
2121 mMmTelFeatureConnection.changeEnabledCapabilities(request, null);
2122 } catch (RemoteException e) {
2123 Log.e(TAG, "setLteFeatureValues: Exception: " + e.getMessage());
Etan Cohencfc784d2014-08-07 18:40:31 -07002124 }
Amit Mahajan9cba36d2016-08-11 10:17:23 -07002125 }
2126
2127 private void setAdvanced4GMode(boolean turnOn) throws ImsException {
2128 checkAndThrowExceptionIfServiceUnavailable();
2129
2130 // if turnOn: first set feature values then call turnOnIms()
2131 // if turnOff: only set feature values if IMS turn off is not allowed. If turn off is
2132 // allowed, first call turnOffIms() then set feature values
Etan Cohencfc784d2014-08-07 18:40:31 -07002133 if (turnOn) {
Amit Mahajan9cba36d2016-08-11 10:17:23 -07002134 setLteFeatureValues(turnOn);
2135 log("setAdvanced4GMode: turnOnIms");
Etan Cohencfc784d2014-08-07 18:40:31 -07002136 turnOnIms();
Amit Mahajan9cba36d2016-08-11 10:17:23 -07002137 } else {
2138 if (isImsTurnOffAllowed()) {
2139 log("setAdvanced4GMode: turnOffIms");
2140 turnOffIms();
2141 }
2142 setLteFeatureValues(turnOn);
Etan Cohencfc784d2014-08-07 18:40:31 -07002143 }
2144 }
2145
ram7da5a112014-07-16 20:59:27 +05302146 /**
2147 * Used for turning off IMS completely in order to make the device CSFB'ed.
2148 * Once turned off, all calls will be over CS.
2149 */
Etan Cohen82f78122014-12-15 10:10:14 -08002150 private void turnOffIms() throws ImsException {
Brad Ebinger172977a2018-01-16 09:36:56 -08002151 TelephonyManager tm = (TelephonyManager)
2152 mContext.getSystemService(Context.TELEPHONY_SERVICE);
2153 tm.disableIms(mPhoneId);
ram7da5a112014-07-16 20:59:27 +05302154 }
2155
Naveen Kalla525c3a22017-02-06 14:46:42 -08002156 private void addToRecentDisconnectReasons(ImsReasonInfo reason) {
2157 if (reason == null) return;
2158 while (mRecentDisconnectReasons.size() >= MAX_RECENT_DISCONNECT_REASONS) {
2159 mRecentDisconnectReasons.removeFirst();
2160 }
2161 mRecentDisconnectReasons.addLast(reason);
2162 }
2163
ram7da5a112014-07-16 20:59:27 +05302164 /**
Wink Savilleef36ef62014-06-11 08:39:38 -07002165 * Death recipient class for monitoring IMS service.
2166 */
2167 private class ImsServiceDeathRecipient implements IBinder.DeathRecipient {
2168 @Override
2169 public void binderDied() {
Brad Ebinger172977a2018-01-16 09:36:56 -08002170 mMmTelFeatureConnection = null;
Wink Savilleef36ef62014-06-11 08:39:38 -07002171 mUt = null;
Libin.Tang@motorola.com076c55d2014-06-23 19:46:36 -05002172 mConfig = null;
Uma Maheswari Ramalingam4f2161d2014-07-31 16:01:47 -07002173 mEcbm = null;
Tyler Gunn4d128b62016-04-13 15:44:38 -07002174 mMultiEndpoint = null;
Wink Savilleef36ef62014-06-11 08:39:38 -07002175 }
2176 }
2177
2178 /**
Uma Maheswari Ramalingam4f2161d2014-07-31 16:01:47 -07002179 * Gets the ECBM interface to request ECBM exit.
2180 *
Uma Maheswari Ramalingam4f2161d2014-07-31 16:01:47 -07002181 * @return the ECBM interface instance
2182 * @throws ImsException if getting the ECBM interface results in an error
2183 */
Brad Ebinger172977a2018-01-16 09:36:56 -08002184 public ImsEcbm getEcbmInterface() throws ImsException {
Brad Ebinger138b4a62017-06-20 16:29:50 -07002185 if (mEcbm != null && mEcbm.isBinderAlive()) {
2186 return mEcbm;
2187 }
Uma Maheswari Ramalingam4f2161d2014-07-31 16:01:47 -07002188
Brad Ebinger138b4a62017-06-20 16:29:50 -07002189 checkAndThrowExceptionIfServiceUnavailable();
2190 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08002191 IImsEcbm iEcbm = mMmTelFeatureConnection.getEcbmInterface();
Uma Maheswari Ramalingam4f2161d2014-07-31 16:01:47 -07002192
Brad Ebinger138b4a62017-06-20 16:29:50 -07002193 if (iEcbm == null) {
2194 throw new ImsException("getEcbmInterface()",
2195 ImsReasonInfo.CODE_ECBM_NOT_SUPPORTED);
Uma Maheswari Ramalingam4f2161d2014-07-31 16:01:47 -07002196 }
Brad Ebinger138b4a62017-06-20 16:29:50 -07002197 mEcbm = new ImsEcbm(iEcbm);
2198 } catch (RemoteException e) {
2199 throw new ImsException("getEcbmInterface()", e,
2200 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
Uma Maheswari Ramalingam4f2161d2014-07-31 16:01:47 -07002201 }
2202 return mEcbm;
2203 }
Pavel Zhamaitsiak8c065f52015-11-10 14:36:44 -08002204
Mohamed Abdalkader4d68a982018-01-10 13:29:26 -08002205 public void sendSms(int token, int messageRef, String format, String smsc, boolean isRetry,
2206 byte[] pdu) throws ImsException {
2207 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08002208 mMmTelFeatureConnection.sendSms(token, messageRef, format, smsc, isRetry, pdu);
Mohamed Abdalkader4d68a982018-01-10 13:29:26 -08002209 } catch (RemoteException e) {
2210 throw new ImsException("sendSms()", e, ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2211 }
2212 }
2213
2214 public void acknowledgeSms(int token, int messageRef, int result) throws ImsException {
2215 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08002216 mMmTelFeatureConnection.acknowledgeSms(token, messageRef, result);
Mohamed Abdalkader4d68a982018-01-10 13:29:26 -08002217 } catch (RemoteException e) {
2218 throw new ImsException("acknowledgeSms()", e,
2219 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2220 }
2221 }
2222
2223 public void acknowledgeSmsReport(int token, int messageRef, int result) throws ImsException{
2224 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08002225 mMmTelFeatureConnection.acknowledgeSmsReport(token, messageRef, result);
Mohamed Abdalkader4d68a982018-01-10 13:29:26 -08002226 } catch (RemoteException e) {
2227 throw new ImsException("acknowledgeSmsReport()", e,
2228 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2229 }
2230 }
2231
2232 public String getSmsFormat() throws ImsException{
2233 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08002234 return mMmTelFeatureConnection.getSmsFormat();
Mohamed Abdalkader4d68a982018-01-10 13:29:26 -08002235 } catch (RemoteException e) {
2236 throw new ImsException("getSmsFormat()", e,
2237 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2238 }
2239 }
2240
2241 public void setSmsListener(IImsSmsListener listener) throws ImsException {
2242 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08002243 mMmTelFeatureConnection.setSmsListener(listener);
Mohamed Abdalkader4d68a982018-01-10 13:29:26 -08002244 } catch (RemoteException e) {
2245 throw new ImsException("setSmsListener()", e,
2246 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2247 }
2248 }
Mohamed Abdalkadere1453f42018-01-19 19:48:31 -08002249
Brad Ebingerd449b232018-02-12 14:33:05 -08002250 public void onSmsReady() throws ImsException {
Mohamed Abdalkader0e734e12018-01-23 13:11:00 -08002251 try {
Brad Ebinger190ed932018-01-23 13:41:32 -08002252 mMmTelFeatureConnection.onSmsReady();
Mohamed Abdalkader0e734e12018-01-23 13:11:00 -08002253 } catch (RemoteException e) {
2254 throw new ImsException("onSmsReady()", e,
2255 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2256 }
2257 }
2258
Pavel Zhamaitsiak8c065f52015-11-10 14:36:44 -08002259 /**
Brad Ebingerd449b232018-02-12 14:33:05 -08002260 * Determines whether or not a call with the specified numbers should be placed over IMS or over
2261 * CSFB.
2262 * @param isEmergency is at least one call an emergency number.
2263 * @param numbers A {@link String} array containing the numbers in the call being placed. Can
2264 * be multiple numbers in the case of dialing out a conference.
2265 * @return The result of the query, one of the following values:
2266 * - {@link MmTelFeature#PROCESS_CALL_IMS}
2267 * - {@link MmTelFeature#PROCESS_CALL_CSFB}
2268 * @throws ImsException if the ImsService is not available. In this case, we should fall back
2269 * to CSFB anyway.
2270 */
2271 public @MmTelFeature.ProcessCallResult int shouldProcessCall(boolean isEmergency,
2272 String[] numbers) throws ImsException {
2273 try {
2274 return mMmTelFeatureConnection.shouldProcessCall(isEmergency, numbers);
2275 } catch (RemoteException e) {
2276 throw new ImsException("shouldProcessCall()", e,
2277 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2278 }
2279 }
2280
2281 /**
Tyler Gunn4d128b62016-04-13 15:44:38 -07002282 * Gets the Multi-Endpoint interface to subscribe to multi-enpoint notifications..
2283 *
Tyler Gunn4d128b62016-04-13 15:44:38 -07002284 * @return the multi-endpoint interface instance
2285 * @throws ImsException if getting the multi-endpoint interface results in an error
2286 */
Brad Ebinger172977a2018-01-16 09:36:56 -08002287 public ImsMultiEndpoint getMultiEndpointInterface() throws ImsException {
Brad Ebinger138b4a62017-06-20 16:29:50 -07002288 if (mMultiEndpoint != null && mMultiEndpoint.isBinderAlive()) {
2289 return mMultiEndpoint;
Tyler Gunn4d128b62016-04-13 15:44:38 -07002290 }
Brad Ebinger138b4a62017-06-20 16:29:50 -07002291
2292 checkAndThrowExceptionIfServiceUnavailable();
2293 try {
Brad Ebinger172977a2018-01-16 09:36:56 -08002294 IImsMultiEndpoint iImsMultiEndpoint = mMmTelFeatureConnection.getMultiEndpointInterface();
Brad Ebinger138b4a62017-06-20 16:29:50 -07002295
2296 if (iImsMultiEndpoint == null) {
2297 throw new ImsException("getMultiEndpointInterface()",
2298 ImsReasonInfo.CODE_MULTIENDPOINT_NOT_SUPPORTED);
2299 }
2300 mMultiEndpoint = new ImsMultiEndpoint(iImsMultiEndpoint);
2301 } catch (RemoteException e) {
2302 throw new ImsException("getMultiEndpointInterface()", e,
2303 ImsReasonInfo.CODE_LOCAL_IMS_SERVICE_DOWN);
2304 }
2305
Tyler Gunn4d128b62016-04-13 15:44:38 -07002306 return mMultiEndpoint;
2307 }
2308
2309 /**
Pavel Zhamaitsiak8c065f52015-11-10 14:36:44 -08002310 * Resets ImsManager settings back to factory defaults.
2311 *
Brad Ebinger479f52c2017-08-28 13:19:22 -07002312 * @deprecated Doesn't support MSIM devices. Use {@link #factoryReset()} instead.
Brad Ebinger16417b42017-03-07 13:48:50 -08002313 *
Pavel Zhamaitsiak8c065f52015-11-10 14:36:44 -08002314 * @hide
2315 */
2316 public static void factoryReset(Context context) {
Brad Ebinger479f52c2017-08-28 13:19:22 -07002317 ImsManager mgr = ImsManager.getInstance(context,
2318 SubscriptionManager.getDefaultVoicePhoneId());
2319 if (mgr != null) {
2320 mgr.factoryReset();
2321 }
2322 loge("factoryReset: ImsManager null.");
Pavel Zhamaitsiak8c065f52015-11-10 14:36:44 -08002323 }
Jack Yu2f102bd2015-12-28 15:31:48 -08002324
Brad Ebinger16417b42017-03-07 13:48:50 -08002325 /**
2326 * Resets ImsManager settings back to factory defaults.
2327 *
2328 * @hide
2329 */
Brad Ebinger479f52c2017-08-28 13:19:22 -07002330 public void factoryReset() {
Brad Ebinger16417b42017-03-07 13:48:50 -08002331 // Set VoLTE to default
Malcolm Chen212ca652017-09-28 17:28:45 -07002332 SubscriptionManager.setSubscriptionProperty(getSubId(),
manabu, shimoda96aee542017-10-06 15:39:36 +09002333 SubscriptionManager.ENHANCED_4G_MODE_ENABLED,
2334 booleanToPropertyString(getBooleanCarrierConfig(
2335 CarrierConfigManager.KEY_ENHANCED_4G_LTE_ON_BY_DEFAULT_BOOL)));
Brad Ebinger16417b42017-03-07 13:48:50 -08002336
2337 // Set VoWiFi to default
Malcolm Chen212ca652017-09-28 17:28:45 -07002338 SubscriptionManager.setSubscriptionProperty(getSubId(),
2339 SubscriptionManager.WFC_IMS_ENABLED,
2340 booleanToPropertyString(getBooleanCarrierConfig(
2341 CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ENABLED_BOOL)));
Brad Ebinger16417b42017-03-07 13:48:50 -08002342
2343 // Set VoWiFi mode to default
Malcolm Chen212ca652017-09-28 17:28:45 -07002344 SubscriptionManager.setSubscriptionProperty(getSubId(),
2345 SubscriptionManager.WFC_IMS_MODE,
2346 Integer.toString(getIntCarrierConfig(
2347 CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_MODE_INT)));
Brad Ebinger16417b42017-03-07 13:48:50 -08002348
2349 // Set VoWiFi roaming to default
Malcolm Chen212ca652017-09-28 17:28:45 -07002350 SubscriptionManager.setSubscriptionProperty(getSubId(),
2351 SubscriptionManager.WFC_IMS_ROAMING_ENABLED,
2352 booleanToPropertyString(getBooleanCarrierConfig(
2353 CarrierConfigManager.KEY_CARRIER_DEFAULT_WFC_IMS_ROAMING_ENABLED_BOOL)));
Brad Ebinger16417b42017-03-07 13:48:50 -08002354
2355 // Set VT to default
Malcolm Chen212ca652017-09-28 17:28:45 -07002356 SubscriptionManager.setSubscriptionProperty(getSubId(),
2357 SubscriptionManager.VT_IMS_ENABLED, booleanToPropertyString(true));
Brad Ebinger16417b42017-03-07 13:48:50 -08002358
2359 // Push settings to ImsConfig
Brad Ebinger479f52c2017-08-28 13:19:22 -07002360 updateImsServiceConfig(true);
Brad Ebinger16417b42017-03-07 13:48:50 -08002361 }
2362
Amit Mahajan24f7b162016-07-21 16:33:53 -07002363 private boolean isDataEnabled() {
Malcolm Chenb8cd4402018-03-23 18:51:51 -07002364 return new TelephonyManager(mContext, getSubId()).isDataCapable();
Amit Mahajan24f7b162016-07-21 16:33:53 -07002365 }
2366
2367 private boolean isVolteProvisioned() {
Malcolm Chen18837ff2017-10-25 17:05:41 -07002368 return getProvisionedBoolNoException(
2369 ImsConfig.ConfigConstants.VLT_SETTING_ENABLED);
Amit Mahajan24f7b162016-07-21 16:33:53 -07002370 }
2371
2372 private boolean isWfcProvisioned() {
Malcolm Chen18837ff2017-10-25 17:05:41 -07002373 return getProvisionedBoolNoException(
2374 ImsConfig.ConfigConstants.VOICE_OVER_WIFI_SETTING_ENABLED);
Amit Mahajan24f7b162016-07-21 16:33:53 -07002375 }
2376
2377 private boolean isVtProvisioned() {
Malcolm Chen18837ff2017-10-25 17:05:41 -07002378 return getProvisionedBoolNoException(
2379 ImsConfig.ConfigConstants.LVC_SETTING_ENABLED);
Jack Yu643ffe42016-07-08 14:25:46 -07002380 }
2381
Malcolm Chen212ca652017-09-28 17:28:45 -07002382 private static String booleanToPropertyString(boolean bool) {
2383 return bool ? "1" : "0";
2384 }
2385
2386
Jack Yu2f102bd2015-12-28 15:31:48 -08002387 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
2388 pw.println("ImsManager:");
2389 pw.println(" mPhoneId = " + mPhoneId);
2390 pw.println(" mConfigUpdated = " + mConfigUpdated);
Brad Ebinger172977a2018-01-16 09:36:56 -08002391 pw.println(" mImsServiceProxy = " + mMmTelFeatureConnection);
Amit Mahajan24f7b162016-07-21 16:33:53 -07002392 pw.println(" mDataEnabled = " + isDataEnabled());
Brad Ebinger479f52c2017-08-28 13:19:22 -07002393 pw.println(" ignoreDataEnabledChanged = " + getBooleanCarrierConfig(
Jack Yu57781852016-11-16 17:20:38 -08002394 CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS));
Jack Yu2f102bd2015-12-28 15:31:48 -08002395
Brad Ebinger479f52c2017-08-28 13:19:22 -07002396 pw.println(" isGbaValid = " + isGbaValid());
Jack Yu2f102bd2015-12-28 15:31:48 -08002397 pw.println(" isImsTurnOffAllowed = " + isImsTurnOffAllowed());
Brad Ebinger479f52c2017-08-28 13:19:22 -07002398 pw.println(" isNonTtyOrTtyOnVolteEnabled = " + isNonTtyOrTtyOnVolteEnabled());
Jack Yu2f102bd2015-12-28 15:31:48 -08002399
Brad Ebinger479f52c2017-08-28 13:19:22 -07002400 pw.println(" isVolteEnabledByPlatform = " + isVolteEnabledByPlatform());
2401 pw.println(" isVolteProvisionedOnDevice = " + isVolteProvisionedOnDevice());
Jack Yu2f102bd2015-12-28 15:31:48 -08002402 pw.println(" isEnhanced4gLteModeSettingEnabledByUser = " +
Brad Ebinger479f52c2017-08-28 13:19:22 -07002403 isEnhanced4gLteModeSettingEnabledByUser());
2404 pw.println(" isVtEnabledByPlatform = " + isVtEnabledByPlatform());
2405 pw.println(" isVtEnabledByUser = " + isVtEnabledByUser());
Jack Yu2f102bd2015-12-28 15:31:48 -08002406
Brad Ebinger479f52c2017-08-28 13:19:22 -07002407 pw.println(" isWfcEnabledByPlatform = " + isWfcEnabledByPlatform());
2408 pw.println(" isWfcEnabledByUser = " + isWfcEnabledByUser());
2409 pw.println(" getWfcMode = " + getWfcMode());
2410 pw.println(" isWfcRoamingEnabledByUser = " + isWfcRoamingEnabledByUser());
Jack Yu2f102bd2015-12-28 15:31:48 -08002411
Brad Ebinger479f52c2017-08-28 13:19:22 -07002412 pw.println(" isVtProvisionedOnDevice = " + isVtProvisionedOnDevice());
2413 pw.println(" isWfcProvisionedOnDevice = " + isWfcProvisionedOnDevice());
Jack Yu2f102bd2015-12-28 15:31:48 -08002414 pw.flush();
2415 }
Wink Savilleef36ef62014-06-11 08:39:38 -07002416}