blob: 8ee77737db5d148dfa2333b9aab1c94d70f0be5c [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;
Andrew Leea6bc3122015-01-29 14:47:34 -080023import android.util.Log;
24
25import com.android.ims.ImsConfig;
26import com.android.ims.ImsManager;
Etan Cohen0ca1c802014-07-07 15:35:48 -070027import com.android.phone.PhoneGlobals;
28
29public class ImsUtil {
Andrew Leea6bc3122015-01-29 14:47:34 -080030 private static final String LOG_TAG = ImsUtil.class.getSimpleName();
31 private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
Andrew Lee77527ac2014-10-21 16:57:39 -070032
Andrew Lee77527ac2014-10-21 16:57:39 -070033 private static boolean sImsPhoneSupported = false;
34
Etan Cohen0ca1c802014-07-07 15:35:48 -070035 private ImsUtil() {
36 }
37
Etan Cohen0ca1c802014-07-07 15:35:48 -070038 static {
39 PhoneGlobals app = PhoneGlobals.getInstance();
40 sImsPhoneSupported = true;
41 }
42
43 /**
Andrew Leea6bc3122015-01-29 14:47:34 -080044 * @return {@code true} if this device supports voice calls using the built-in SIP stack.
Etan Cohen0ca1c802014-07-07 15:35:48 -070045 */
46 static boolean isImsPhoneSupported() {
47 return sImsPhoneSupported;
Andrew Lee77527ac2014-10-21 16:57:39 -070048
49 }
Andrew Leea6bc3122015-01-29 14:47:34 -080050
51 /**
52 * @return {@code true} if WFC is supported by the platform and has been enabled by the user.
53 */
54 public static boolean isWfcEnabled(Context context) {
55 boolean isEnabledByPlatform = ImsManager.isWfcEnabledByPlatform(context);
56 boolean isEnabledByUser = ImsManager.isWfcEnabledByUser(context);
57 if (DBG) Log.d(LOG_TAG, "isWfcEnabled :: isEnabledByPlatform=" + isEnabledByPlatform);
58 if (DBG) Log.d(LOG_TAG, "isWfcEnabled :: isEnabledByUser=" + isEnabledByUser);
59 return isEnabledByPlatform && isEnabledByUser;
60 }
61
62 /**
Meng Wange57bf022017-02-14 17:51:18 -080063 * @return {@code true} if WFC is provisioned on the device.
64 */
65 public static boolean isWfcProvisioned(Context context) {
66 CarrierConfigManager cfgManager = (CarrierConfigManager) context
67 .getSystemService(Context.CARRIER_CONFIG_SERVICE);
68 if (cfgManager != null
69 && cfgManager.getConfig().getBoolean(
70 CarrierConfigManager.KEY_CARRIER_VOLTE_OVERRIDE_WFC_PROVISIONING_BOOL)
71 && !ImsManager.isVolteProvisionedOnDevice(context)) {
72 return false;
73 }
74 return ImsManager.isWfcProvisionedOnDevice(context);
75 }
76
77 /**
Andrew Leea6bc3122015-01-29 14:47:34 -080078 * @return {@code true} if the device is configured to use "Wi-Fi only" mode. If WFC is not
79 * enabled, this will return {@code false}.
80 */
81 public static boolean isWfcModeWifiOnly(Context context) {
82 boolean isWifiOnlyMode =
83 ImsManager.getWfcMode(context) == ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY;
84 if (DBG) Log.d(LOG_TAG, "isWfcModeWifiOnly :: isWifiOnlyMode" + isWifiOnlyMode);
85 return isWfcEnabled(context) && isWifiOnlyMode;
86 }
Tyler Gunn0bb4d302016-07-07 10:28:39 -070087
88 /**
89 * When a call cannot be placed, determines if the use of WFC should be promoted, per the
90 * 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 -080091 * network, WFC is disabled but provisioned, and the carrier config indicates that the
92 * features should be promoted.
Tyler Gunn0bb4d302016-07-07 10:28:39 -070093 *
94 * @return {@code true} if use of WFC should be promoted, {@code false} otherwise.
95 */
96 public static boolean shouldPromoteWfc(Context context) {
97 CarrierConfigManager cfgManager = (CarrierConfigManager) context
98 .getSystemService(Context.CARRIER_CONFIG_SERVICE);
99 if (cfgManager == null || !cfgManager.getConfig()
100 .getBoolean(CarrierConfigManager.KEY_CARRIER_PROMOTE_WFC_ON_CALL_FAIL_BOOL)) {
101 return false;
102 }
103
Meng Wange57bf022017-02-14 17:51:18 -0800104 if (!isWfcProvisioned(context)) {
105 return false;
106 }
107
Tyler Gunn0bb4d302016-07-07 10:28:39 -0700108 ConnectivityManager cm =
109 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
110 if (cm != null) {
111 NetworkInfo ni = cm.getActiveNetworkInfo();
112 if (ni != null && ni.isConnected()) {
113 return ni.getType() == ConnectivityManager.TYPE_WIFI && !isWfcEnabled(context);
114 }
115 }
116 return false;
117 }
Etan Cohen0ca1c802014-07-07 15:35:48 -0700118}