blob: 4d8ff801d9a820c32c853209c0058d78554ef6a0 [file] [log] [blame]
Etan Cohen0ca1c802014-07-07 15:35:48 -07001/*
2 * Copyright 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.phone;
18
Andrew Leea6bc3122015-01-29 14:47:34 -080019import android.content.Context;
Tyler Gunn0bb4d302016-07-07 10:28:39 -070020import android.net.ConnectivityManager;
21import android.net.NetworkInfo;
22import android.telephony.CarrierConfigManager;
Malcolm Chen995721f2017-12-12 18:19:27 -080023import android.telephony.SubscriptionManager;
Andrew Leea6bc3122015-01-29 14:47:34 -080024import android.util.Log;
25
26import com.android.ims.ImsConfig;
27import com.android.ims.ImsManager;
Etan Cohen0ca1c802014-07-07 15:35:48 -070028import com.android.phone.PhoneGlobals;
29
30public class ImsUtil {
Andrew Leea6bc3122015-01-29 14:47:34 -080031 private static final String LOG_TAG = ImsUtil.class.getSimpleName();
32 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
Andrew Lee77527ac2014-10-21 16:57:39 -070033
Andrew Lee77527ac2014-10-21 16:57:39 -070034 private static boolean sImsPhoneSupported = false;
35
Etan Cohen0ca1c802014-07-07 15:35:48 -070036 private ImsUtil() {
37 }
38
Etan Cohen0ca1c802014-07-07 15:35:48 -070039 static {
40 PhoneGlobals app = PhoneGlobals.getInstance();
41 sImsPhoneSupported = true;
42 }
43
44 /**
Andrew Leea6bc3122015-01-29 14:47:34 -080045 * @return {@code true} if this device supports voice calls using the built-in SIP stack.
Etan Cohen0ca1c802014-07-07 15:35:48 -070046 */
47 static boolean isImsPhoneSupported() {
48 return sImsPhoneSupported;
Andrew Lee77527ac2014-10-21 16:57:39 -070049
50 }
Andrew Leea6bc3122015-01-29 14:47:34 -080051
52 /**
53 * @return {@code true} if WFC is supported by the platform and has been enabled by the user.
54 */
55 public static boolean isWfcEnabled(Context context) {
Malcolm Chen995721f2017-12-12 18:19:27 -080056 ImsManager imsManager = getDefaultImsManagerInstance(context);
57 boolean isEnabledByPlatform = imsManager.isWfcEnabledByPlatform();
58 boolean isEnabledByUser = imsManager.isWfcEnabledByUser();
Andrew Leea6bc3122015-01-29 14:47:34 -080059 if (DBG) Log.d(LOG_TAG, "isWfcEnabled :: isEnabledByPlatform=" + isEnabledByPlatform);
60 if (DBG) Log.d(LOG_TAG, "isWfcEnabled :: isEnabledByUser=" + isEnabledByUser);
61 return isEnabledByPlatform && isEnabledByUser;
62 }
63
64 /**
65 * @return {@code true} if the device is configured to use "Wi-Fi only" mode. If WFC is not
66 * enabled, this will return {@code false}.
67 */
68 public static boolean isWfcModeWifiOnly(Context context) {
Malcolm Chen995721f2017-12-12 18:19:27 -080069 boolean isWifiOnlyMode = getDefaultImsManagerInstance(context).getWfcMode()
70 == ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY;
Andrew Leea6bc3122015-01-29 14:47:34 -080071 if (DBG) Log.d(LOG_TAG, "isWfcModeWifiOnly :: isWifiOnlyMode" + isWifiOnlyMode);
72 return isWfcEnabled(context) && isWifiOnlyMode;
73 }
Tyler Gunn0bb4d302016-07-07 10:28:39 -070074
75 /**
76 * When a call cannot be placed, determines if the use of WFC should be promoted, per the
77 * carrier config. Use of WFC is promoted to the user if the device is connected to a WIFI
Meng Wange57bf022017-02-14 17:51:18 -080078 * network, WFC is disabled but provisioned, and the carrier config indicates that the
79 * features should be promoted.
Tyler Gunn0bb4d302016-07-07 10:28:39 -070080 *
81 * @return {@code true} if use of WFC should be promoted, {@code false} otherwise.
82 */
83 public static boolean shouldPromoteWfc(Context context) {
84 CarrierConfigManager cfgManager = (CarrierConfigManager) context
85 .getSystemService(Context.CARRIER_CONFIG_SERVICE);
86 if (cfgManager == null || !cfgManager.getConfig()
87 .getBoolean(CarrierConfigManager.KEY_CARRIER_PROMOTE_WFC_ON_CALL_FAIL_BOOL)) {
88 return false;
89 }
90
Malcolm Chen995721f2017-12-12 18:19:27 -080091 if (!getDefaultImsManagerInstance(context).isWfcProvisionedOnDevice()) {
Meng Wange57bf022017-02-14 17:51:18 -080092 return false;
93 }
94
Tyler Gunn0bb4d302016-07-07 10:28:39 -070095 ConnectivityManager cm =
96 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
97 if (cm != null) {
98 NetworkInfo ni = cm.getActiveNetworkInfo();
99 if (ni != null && ni.isConnected()) {
100 return ni.getType() == ConnectivityManager.TYPE_WIFI && !isWfcEnabled(context);
101 }
102 }
103 return false;
104 }
Malcolm Chen995721f2017-12-12 18:19:27 -0800105
106 private static ImsManager getDefaultImsManagerInstance(Context context) {
107 return ImsManager.getInstance(context, SubscriptionManager.getDefaultVoicePhoneId());
108 }
Etan Cohen0ca1c802014-07-07 15:35:48 -0700109}