Home | History | Annotate | Download | only in telephony
      1 /*
      2  * Copyright (C) 2017 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.googlecode.android_scripting.facade.telephony;
     18 
     19 import android.app.Service;
     20 import android.content.Context;
     21 import android.telephony.SubscriptionManager;
     22 
     23 import com.android.ims.ImsConfig;
     24 import com.android.ims.ImsException;
     25 import com.android.ims.ImsManager;
     26 
     27 import com.googlecode.android_scripting.facade.FacadeManager;
     28 import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
     29 import com.googlecode.android_scripting.rpc.Rpc;
     30 import com.googlecode.android_scripting.rpc.RpcParameter;
     31 
     32 /**
     33  * Exposes ImsManager functionality.
     34  */
     35 public class ImsManagerFacade extends RpcReceiver {
     36 
     37     private final Service mService;
     38     private final Context mContext;
     39     private ImsManager mImsManager;
     40 
     41     public ImsManagerFacade(FacadeManager manager) {
     42         super(manager);
     43         mService = manager.getService();
     44         mContext = mService.getBaseContext();
     45         mImsManager = ImsManager.getInstance(mContext,
     46                 SubscriptionManager.getDefaultVoicePhoneId());
     47     }
     48 
     49     /**
     50     * Reset IMS settings to factory default.
     51     */
     52     @Rpc(description = "Resets ImsManager settings to factory default.")
     53     public void imsFactoryReset() {
     54         mImsManager.factoryResetSlot();
     55     }
     56 
     57     @Rpc(description = "Return True if Enhanced 4g Lte mode is enabled by platform.")
     58     public boolean imsIsEnhanced4gLteModeSettingEnabledByPlatform() {
     59         return mImsManager.isVolteEnabledByPlatformForSlot();
     60     }
     61 
     62     @Rpc(description = "Return True if Enhanced 4g Lte mode is enabled by user.")
     63     public boolean imsIsEnhanced4gLteModeSettingEnabledByUser() {
     64         return mImsManager.isEnhanced4gLteModeSettingEnabledByUserForSlot();
     65     }
     66 
     67     @Rpc(description = "Set Enhanced 4G mode.")
     68     public void imsSetEnhanced4gMode(
     69             @RpcParameter(name = "enable") Boolean enable) {
     70         mImsManager.setEnhanced4gLteModeSettingForSlot(enable);
     71     }
     72 
     73     @Rpc(description = "Check for VoLTE Provisioning.")
     74     public boolean imsIsVolteProvisionedOnDevice() {
     75         return mImsManager.isVolteProvisionedOnDeviceForSlot();
     76     }
     77 
     78     @Rpc(description = "Set Modem Provisioning for VoLTE")
     79     public void imsSetVolteProvisioning(
     80             @RpcParameter(name = "enable") Boolean enable)
     81             throws ImsException{
     82         mImsManager.getConfigInterface().setProvisionedValue(
     83                 ImsConfig.ConfigConstants.VLT_SETTING_ENABLED,
     84                 enable? 1 : 0);
     85     }
     86 
     87     /**************************
     88      * Begin WFC Calling APIs
     89      **************************/
     90 
     91     @Rpc(description = "Return True if WiFi Calling is enabled for platform.")
     92     public boolean imsIsWfcEnabledByPlatform() {
     93         return ImsManager.isWfcEnabledByPlatform(mContext);
     94     }
     95 
     96     @Rpc(description = "Set whether or not WFC is enabled during roaming")
     97     public void imsSetWfcRoamingSetting(
     98                         @RpcParameter(name = "enable")
     99             Boolean enable) {
    100         mImsManager.setWfcRoamingSetting(mContext, enable);
    101 
    102     }
    103 
    104     @Rpc(description = "Return True if WiFi Calling is enabled during roaming.")
    105     public boolean imsIsWfcRoamingEnabledByUser() {
    106         return mImsManager.isWfcEnabledByPlatformForSlot();
    107     }
    108 
    109     @Rpc(description = "Set the Wifi Calling Mode of operation")
    110     public void imsSetWfcMode(
    111                         @RpcParameter(name = "mode")
    112             String mode)
    113             throws IllegalArgumentException {
    114 
    115         int mode_val;
    116 
    117         switch (mode.toUpperCase()) {
    118             case TelephonyConstants.WFC_MODE_WIFI_ONLY:
    119                 mode_val =
    120                         ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY;
    121                 break;
    122             case TelephonyConstants.WFC_MODE_CELLULAR_PREFERRED:
    123                 mode_val =
    124                         ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED;
    125                 break;
    126             case TelephonyConstants.WFC_MODE_WIFI_PREFERRED:
    127                 mode_val =
    128                         ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED;
    129                 break;
    130             case TelephonyConstants.WFC_MODE_DISABLED:
    131                 if (mImsManager.isWfcEnabledByPlatformForSlot()
    132                         && mImsManager.isWfcEnabledByUserForSlot()) {
    133                     mImsManager.setWfcSettingForSlot(false);
    134                 }
    135                 return;
    136             default:
    137                 throw new IllegalArgumentException("Invalid WfcMode");
    138         }
    139 
    140         if (mImsManager.isWfcEnabledByPlatformForSlot()
    141                 && !mImsManager.isWfcEnabledByUserForSlot()) {
    142             mImsManager.setWfcSettingForSlot(true);
    143         }
    144         mImsManager.setWfcModeForSlot(mode_val);
    145 
    146         return;
    147     }
    148 
    149     @Rpc(description = "Return current WFC Mode if Enabled.")
    150     public String imsGetWfcMode() {
    151         if (!mImsManager.isWfcEnabledByUserForSlot()) {
    152             return TelephonyConstants.WFC_MODE_DISABLED;
    153         }
    154         return TelephonyUtils.getWfcModeString(
    155             mImsManager.getWfcModeForSlot());
    156     }
    157 
    158     @Rpc(description = "Return True if WiFi Calling is enabled by user.")
    159     public boolean imsIsWfcEnabledByUser() {
    160         return mImsManager.isWfcEnabledByUserForSlot();
    161     }
    162 
    163     @Rpc(description = "Set whether or not WFC is enabled")
    164     public void imsSetWfcSetting(
    165                         @RpcParameter(name = "enable")  Boolean enable) {
    166         mImsManager.setWfcSettingForSlot(enable);
    167     }
    168 
    169     /**************************
    170      * Begin VT APIs
    171      **************************/
    172 
    173     @Rpc(description = "Return True if Video Calling is enabled by the platform.")
    174     public boolean imsIsVtEnabledByPlatform() {
    175         return mImsManager.isVtEnabledByPlatformForSlot();
    176     }
    177 
    178     @Rpc(description = "Return True if Video Calling is provisioned for this device.")
    179     public boolean imsIsVtProvisionedOnDevice() {
    180         return mImsManager.isVtProvisionedOnDeviceForSlot();
    181     }
    182 
    183     @Rpc(description = "Set Video Telephony Enabled")
    184     public void imsSetVtSetting(Boolean enabled) {
    185         mImsManager.setVtSettingForSlot(enabled);
    186     }
    187 
    188     @Rpc(description = "Return user enabled status for Video Telephony")
    189     public boolean imsIsVtEnabledByUser() {
    190         return mImsManager.isVtEnabledByUserForSlot();
    191     }
    192 
    193     @Override
    194     public void shutdown() {
    195 
    196     }
    197 }
    198