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 ImsManagerFacade(FacadeManager manager)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.") imsFactoryReset()53 public void imsFactoryReset() { 54 mImsManager.factoryReset(); 55 } 56 57 @Rpc(description = "Return True if Enhanced 4g Lte mode is enabled by platform.") imsIsEnhanced4gLteModeSettingEnabledByPlatform()58 public boolean imsIsEnhanced4gLteModeSettingEnabledByPlatform() { 59 return mImsManager.isVolteEnabledByPlatform(); 60 } 61 62 @Rpc(description = "Return True if Enhanced 4g Lte mode is enabled by user.") imsIsEnhanced4gLteModeSettingEnabledByUser()63 public boolean imsIsEnhanced4gLteModeSettingEnabledByUser() { 64 return mImsManager.isEnhanced4gLteModeSettingEnabledByUser(); 65 } 66 67 @Rpc(description = "Set Enhanced 4G mode.") imsSetEnhanced4gMode( @pcParametername = "enable") Boolean enable)68 public void imsSetEnhanced4gMode( 69 @RpcParameter(name = "enable") Boolean enable) { 70 mImsManager.setEnhanced4gLteModeSetting(enable); 71 } 72 73 @Rpc(description = "Check for VoLTE Provisioning.") imsIsVolteProvisionedOnDevice()74 public boolean imsIsVolteProvisionedOnDevice() { 75 return mImsManager.isVolteProvisionedOnDevice(); 76 } 77 78 @Rpc(description = "Set Modem Provisioning for VoLTE") imsSetVolteProvisioning( @pcParametername = "enable") Boolean enable)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.") imsIsWfcEnabledByPlatform()92 public boolean imsIsWfcEnabledByPlatform() { 93 return ImsManager.isWfcEnabledByPlatform(mContext); 94 } 95 96 @Rpc(description = "Set whether or not WFC is enabled during roaming") imsSetWfcRoamingSetting( @pcParametername = "enable") Boolean enable)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.") imsIsWfcRoamingEnabledByUser()105 public boolean imsIsWfcRoamingEnabledByUser() { 106 return mImsManager.isWfcEnabledByPlatform(); 107 } 108 109 @Rpc(description = "Set the Wifi Calling Mode of operation") imsSetWfcMode( @pcParametername = "mode") String mode)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.isWfcEnabledByPlatform() 132 && mImsManager.isWfcEnabledByUser()) { 133 mImsManager.setWfcSetting(false); 134 } 135 return; 136 default: 137 throw new IllegalArgumentException("Invalid WfcMode"); 138 } 139 140 if (mImsManager.isWfcEnabledByPlatform() 141 && !mImsManager.isWfcEnabledByUser()) { 142 mImsManager.setWfcSetting(true); 143 } 144 mImsManager.setWfcMode(mode_val); 145 146 return; 147 } 148 149 @Rpc(description = "Return current WFC Mode if Enabled.") imsGetWfcMode()150 public String imsGetWfcMode() { 151 if (!mImsManager.isWfcEnabledByUser()) { 152 return TelephonyConstants.WFC_MODE_DISABLED; 153 } 154 return TelephonyUtils.getWfcModeString( 155 mImsManager.getWfcMode()); 156 } 157 158 @Rpc(description = "Return True if WiFi Calling is enabled by user.") imsIsWfcEnabledByUser()159 public boolean imsIsWfcEnabledByUser() { 160 return mImsManager.isWfcEnabledByUser(); 161 } 162 163 @Rpc(description = "Set whether or not WFC is enabled") imsSetWfcSetting( @pcParametername = "enable") Boolean enable)164 public void imsSetWfcSetting( 165 @RpcParameter(name = "enable") Boolean enable) { 166 mImsManager.setWfcSetting(enable); 167 } 168 169 /************************** 170 * Begin VT APIs 171 **************************/ 172 173 @Rpc(description = "Return True if Video Calling is enabled by the platform.") imsIsVtEnabledByPlatform()174 public boolean imsIsVtEnabledByPlatform() { 175 return mImsManager.isVtEnabledByPlatform(); 176 } 177 178 @Rpc(description = "Return True if Video Calling is provisioned for this device.") imsIsVtProvisionedOnDevice()179 public boolean imsIsVtProvisionedOnDevice() { 180 return mImsManager.isVtProvisionedOnDevice(); 181 } 182 183 @Rpc(description = "Set Video Telephony Enabled") imsSetVtSetting(Boolean enabled)184 public void imsSetVtSetting(Boolean enabled) { 185 mImsManager.setVtSetting(enabled); 186 } 187 188 @Rpc(description = "Return user enabled status for Video Telephony") imsIsVtEnabledByUser()189 public boolean imsIsVtEnabledByUser() { 190 return mImsManager.isVtEnabledByUser(); 191 } 192 193 @Override shutdown()194 public void shutdown() { 195 196 } 197 } 198