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 ImsManagerFacade(FacadeManager manager)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.") imsIsEnhanced4gLteModeSettingEnabledByPlatform()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.") imsIsEnhanced4gLteModeSettingEnabledByUser()56 public boolean imsIsEnhanced4gLteModeSettingEnabledByUser() { 57 return ImsManager.isEnhanced4gLteModeSettingEnabledByUser(mContext); 58 } 59 60 @Rpc(description = "Set Enhanced 4G mode.") imsSetEnhanced4gMode( @pcParametername = "enable") Boolean enable)61 public void imsSetEnhanced4gMode( 62 @RpcParameter(name = "enable") Boolean enable) { 63 ImsManager.setEnhanced4gLteModeSetting(mContext, enable); 64 } 65 66 @Rpc(description = "Check for VoLTE Provisioning.") imsIsVolteProvisionedOnDevice()67 public boolean imsIsVolteProvisionedOnDevice() { 68 return mImsManager.isVolteProvisionedOnDevice(mContext); 69 } 70 71 @Rpc(description = "Set Modem Provisioning for VoLTE") imsSetVolteProvisioning( @pcParametername = "enable") Boolean enable)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.") imsIsWfcEnabledByPlatform()85 public boolean imsIsWfcEnabledByPlatform() { 86 return ImsManager.isWfcEnabledByPlatform(mContext); 87 } 88 89 @Rpc(description = "Set whether or not WFC is enabled during roaming") imsSetWfcRoamingSetting( @pcParametername = "enable") Boolean enable)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.") imsIsWfcRoamingEnabledByUser()98 public boolean imsIsWfcRoamingEnabledByUser() { 99 return ImsManager.isWfcRoamingEnabledByUser(mContext); 100 } 101 102 @Rpc(description = "Set the Wifi Calling Mode of operation") imsSetWfcMode( @pcParametername = "mode") String mode)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.") imsGetWfcMode()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.") imsIsWfcEnabledByUser()152 public boolean imsIsWfcEnabledByUser() { 153 return ImsManager.isWfcEnabledByUser(mContext); 154 } 155 156 @Rpc(description = "Set whether or not WFC is enabled") imsSetWfcSetting( @pcParametername = "enable") Boolean enable)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.") imsIsVtEnabledByPlatform()167 public boolean imsIsVtEnabledByPlatform() { 168 return ImsManager.isVtEnabledByPlatform(mContext); 169 } 170 171 @Rpc(description = "Return True if Video Calling is provisioned for this device.") imsIsVtProvisionedOnDevice()172 public boolean imsIsVtProvisionedOnDevice() { 173 return ImsManager.isVtProvisionedOnDevice(mContext); 174 } 175 176 @Rpc(description = "Set Video Telephony Enabled") imsSetVtSetting(Boolean enabled)177 public void imsSetVtSetting(Boolean enabled) { 178 ImsManager.setVtSetting(mContext, enabled); 179 } 180 181 @Rpc(description = "Return user enabled status for Video Telephony") imsIsVtEnabledByUser()182 public boolean imsIsVtEnabledByUser() { 183 return ImsManager.isVtEnabledByUser(mContext); 184 } 185 186 @Override shutdown()187 public void shutdown() { 188 189 } 190 } 191