Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2016 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
      5  * use this file except in compliance with the License. You may obtain a copy of
      6  * 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, WITHOUT
     12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
     13  * License for the specific language governing permissions and limitations under
     14  * the License.
     15  */
     16 
     17 package com.googlecode.android_scripting.facade.telephony;
     18 
     19 import android.app.Service;
     20 import android.content.Context;
     21 import android.content.SharedPreferences;
     22 import android.telephony.SubscriptionManager;
     23 
     24 import com.android.ims.ImsException;
     25 import com.android.ims.ImsManager;
     26 import com.android.ims.ImsConfig;
     27 import com.googlecode.android_scripting.Log;
     28 import com.googlecode.android_scripting.facade.FacadeManager;
     29 import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
     30 import com.googlecode.android_scripting.rpc.Rpc;
     31 import com.googlecode.android_scripting.rpc.RpcParameter;
     32 
     33 /**
     34  * Exposes ImsManager functionality.
     35  */
     36 public class ImsManagerFacade extends RpcReceiver {
     37 
     38     private final Service mService;
     39     private final Context mContext;
     40     private ImsManager mImsManager;
     41 
     42     public ImsManagerFacade(FacadeManager manager) {
     43         super(manager);
     44         mService = manager.getService();
     45         mContext = mService.getBaseContext();
     46         mImsManager = ImsManager.getInstance(mContext,
     47                 SubscriptionManager.getDefaultVoicePhoneId());
     48     }
     49 
     50     @Rpc(description = "Return True if Enhanced 4g Lte mode is enabled by platform.")
     51     public boolean imsIsEnhanced4gLteModeSettingEnabledByPlatform() {
     52         return ImsManager.isVolteEnabledByPlatform(mContext);
     53     }
     54 
     55     @Rpc(description = "Return True if Enhanced 4g Lte mode is enabled by user.")
     56     public boolean imsIsEnhanced4gLteModeSettingEnabledByUser() {
     57         return ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mContext);
     58     }
     59 
     60     @Rpc(description = "Set Enhanced 4G mode.")
     61     public void imsSetEnhanced4gMode(
     62             @RpcParameter(name = "enable") Boolean enable) {
     63         ImsManager.setEnhanced4gLteModeSetting(mContext, enable);
     64     }
     65 
     66     @Rpc(description = "Check for VoLTE Provisioning.")
     67     public boolean imsIsVolteProvisionedOnDevice() {
     68         return mImsManager.isVolteProvisionedOnDevice(mContext);
     69     }
     70 
     71     @Rpc(description = "Set Modem Provisioning for VoLTE")
     72     public void imsSetVolteProvisioning(
     73             @RpcParameter(name = "enable") Boolean enable)
     74             throws ImsException{
     75         mImsManager.getConfigInterface().setProvisionedValue(
     76                 ImsConfig.ConfigConstants.VLT_SETTING_ENABLED,
     77                 enable? 1 : 0);
     78     }
     79 
     80     /**************************
     81      * Begin WFC Calling APIs
     82      **************************/
     83 
     84     @Rpc(description = "Return True if WiFi Calling is enabled for platform.")
     85     public boolean imsIsWfcEnabledByPlatform() {
     86         return ImsManager.isWfcEnabledByPlatform(mContext);
     87     }
     88 
     89     @Rpc(description = "Set whether or not WFC is enabled during roaming")
     90     public void imsSetWfcRoamingSetting(
     91                         @RpcParameter(name = "enable")
     92             Boolean enable) {
     93         ImsManager.setWfcRoamingSetting(mContext, enable);
     94 
     95     }
     96 
     97     @Rpc(description = "Return True if WiFi Calling is enabled during roaming.")
     98     public boolean imsIsWfcRoamingEnabledByUser() {
     99         return ImsManager.isWfcRoamingEnabledByUser(mContext);
    100     }
    101 
    102     @Rpc(description = "Set the Wifi Calling Mode of operation")
    103     public void imsSetWfcMode(
    104                         @RpcParameter(name = "mode")
    105             String mode)
    106             throws IllegalArgumentException {
    107 
    108         int mode_val;
    109 
    110         switch (mode.toUpperCase()) {
    111             case TelephonyConstants.WFC_MODE_WIFI_ONLY:
    112                 mode_val =
    113                         ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY;
    114                 break;
    115             case TelephonyConstants.WFC_MODE_CELLULAR_PREFERRED:
    116                 mode_val =
    117                         ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED;
    118                 break;
    119             case TelephonyConstants.WFC_MODE_WIFI_PREFERRED:
    120                 mode_val =
    121                         ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED;
    122                 break;
    123             case TelephonyConstants.WFC_MODE_DISABLED:
    124                 if (ImsManager.isWfcEnabledByPlatform(mContext) &&
    125                         ImsManager.isWfcEnabledByUser(mContext) == true) {
    126                     ImsManager.setWfcSetting(mContext, false);
    127                 }
    128                 return;
    129             default:
    130                 throw new IllegalArgumentException("Invalid WfcMode");
    131         }
    132 
    133         ImsManager.setWfcMode(mContext, mode_val);
    134         if (ImsManager.isWfcEnabledByPlatform(mContext) &&
    135                 ImsManager.isWfcEnabledByUser(mContext) == false) {
    136             ImsManager.setWfcSetting(mContext, true);
    137         }
    138 
    139         return;
    140     }
    141 
    142     @Rpc(description = "Return current WFC Mode if Enabled.")
    143     public String imsGetWfcMode() {
    144         if(ImsManager.isWfcEnabledByUser(mContext) == false) {
    145             return TelephonyConstants.WFC_MODE_DISABLED;
    146         }
    147         return TelephonyUtils.getWfcModeString(
    148             ImsManager.getWfcMode(mContext));
    149     }
    150 
    151     @Rpc(description = "Return True if WiFi Calling is enabled by user.")
    152     public boolean imsIsWfcEnabledByUser() {
    153         return ImsManager.isWfcEnabledByUser(mContext);
    154     }
    155 
    156     @Rpc(description = "Set whether or not WFC is enabled")
    157     public void imsSetWfcSetting(
    158                         @RpcParameter(name = "enable")  Boolean enable) {
    159         ImsManager.setWfcSetting(mContext,enable);
    160     }
    161 
    162     /**************************
    163      * Begin VT APIs
    164      **************************/
    165 
    166     @Rpc(description = "Return True if Video Calling is enabled by the platform.")
    167     public boolean imsIsVtEnabledByPlatform() {
    168         return ImsManager.isVtEnabledByPlatform(mContext);
    169     }
    170 
    171     @Override
    172     public void shutdown() {
    173 
    174     }
    175 }
    176