Home | History | Annotate | Download | only in phone
      1 /*
      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 
     17 package com.android.phone;
     18 
     19 import android.content.Context;
     20 import android.net.ConnectivityManager;
     21 import android.net.NetworkInfo;
     22 import android.telephony.CarrierConfigManager;
     23 import android.util.Log;
     24 
     25 import com.android.ims.ImsConfig;
     26 import com.android.ims.ImsManager;
     27 import com.android.phone.PhoneGlobals;
     28 
     29 public class ImsUtil {
     30     private static final String LOG_TAG = ImsUtil.class.getSimpleName();
     31     private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
     32 
     33     private static boolean sImsPhoneSupported = false;
     34 
     35     private ImsUtil() {
     36     }
     37 
     38     static {
     39         PhoneGlobals app = PhoneGlobals.getInstance();
     40         sImsPhoneSupported = true;
     41     }
     42 
     43     /**
     44      * @return {@code true} if this device supports voice calls using the built-in SIP stack.
     45      */
     46     static boolean isImsPhoneSupported() {
     47         return sImsPhoneSupported;
     48 
     49     }
     50 
     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     /**
     63      * @return {@code true} if the device is configured to use "Wi-Fi only" mode. If WFC is not
     64      * enabled, this will return {@code false}.
     65      */
     66     public static boolean isWfcModeWifiOnly(Context context) {
     67         boolean isWifiOnlyMode =
     68                 ImsManager.getWfcMode(context) == ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY;
     69         if (DBG) Log.d(LOG_TAG, "isWfcModeWifiOnly :: isWifiOnlyMode" + isWifiOnlyMode);
     70         return isWfcEnabled(context) && isWifiOnlyMode;
     71     }
     72 
     73     /**
     74      * When a call cannot be placed, determines if the use of WFC should be promoted, per the
     75      * carrier config.  Use of WFC is promoted to the user if the device is connected to a WIFI
     76      * network, WFC is disabled, and the carrier config indicates that the features should be
     77      * promoted.
     78      *
     79      * @return {@code true} if use of WFC should be promoted, {@code false} otherwise.
     80      */
     81     public static boolean shouldPromoteWfc(Context context) {
     82         CarrierConfigManager cfgManager = (CarrierConfigManager) context
     83                 .getSystemService(Context.CARRIER_CONFIG_SERVICE);
     84         if (cfgManager == null || !cfgManager.getConfig()
     85                 .getBoolean(CarrierConfigManager.KEY_CARRIER_PROMOTE_WFC_ON_CALL_FAIL_BOOL)) {
     86             return false;
     87         }
     88 
     89         ConnectivityManager cm =
     90                 (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     91         if (cm != null) {
     92             NetworkInfo ni = cm.getActiveNetworkInfo();
     93             if (ni != null && ni.isConnected()) {
     94                 return ni.getType() == ConnectivityManager.TYPE_WIFI && !isWfcEnabled(context);
     95             }
     96         }
     97         return false;
     98     }
     99 }
    100