1 /* 2 * Copyright (C) 2021 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.telephony.qns.wfc; 18 19 import static com.android.internal.annotations.VisibleForTesting.Visibility.PACKAGE; 20 21 import android.content.Context; 22 import android.os.PersistableBundle; 23 import android.telephony.CarrierConfigManager; 24 import android.util.Log; 25 26 import com.android.internal.annotations.VisibleForTesting; 27 28 /** This class supports loading WFC config */ 29 public class WfcCarrierConfigManager { 30 private static final String TAG = WfcActivationActivity.TAG; 31 private final int mSubId; 32 private final Context mContext; 33 protected int mCurrCarrierId; 34 35 private boolean mIsShowVowifiPortalAfterTimeout; 36 private boolean mIsJsCallbackForVowifiPortal; 37 38 private int mVowifiRegistrationTimerForVowifiActivation; 39 40 private String mVowifiEntitlementServerUrl; 41 42 /** 43 * The address of the VoWiFi entitlement server for Emergency Address Registration. 44 * 45 * <p>Note: this is effective only if the {@link #KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING} 46 * is set to the QNS app. 47 */ 48 public static final String KEY_QNS_VOWIFI_ENTITLEMENT_SERVER_URL_STRING = 49 "qns.vowifi_entitlement_server_url_string"; 50 51 /** 52 * Specifies the wait time in milliseconds that VoWiFi registration in VoWiFi activation 53 * process. 54 * 55 * <p>Note: this is effective only if the {@link #KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING} 56 * is set to the QNS app. 57 */ 58 public static final String KEY_QNS_VOWIFI_REGISTATION_TIMER_FOR_VOWIFI_ACTIVATION_INT = 59 "qns.vowifi_registation_timer_for_vowifi_activation_int"; 60 61 /** 62 * Indicates whether to pop up a web portal of the carrier or to turn on WFC directly when 63 * {@link #KEY_QNS_VOWIFI_REGISTATION_TIMER_FOR_VOWIFI_ACTIVATION_INT} is expired in VoWiFi 64 * activation process 65 * 66 * <p>{@code true} - show the VoWiFi portal after the timer expires. {@code false} 67 * - turn on WFC UI after the timer expires. 68 * 69 * <p>Note: this is effective only if the {@link #KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING} 70 * is set to the QNS app. 71 */ 72 public static final String KEY_QNS_SHOW_VOWIFI_PORTAL_AFTER_TIMEOUT_BOOL = 73 "qns.show_vowifi_portal_after_timeout_bool"; 74 75 /** 76 * Indicates whether web portal {@link #KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING} of the 77 * carrier supports JavaScript callback interfaces 78 * 79 * <p>{@code true} - use webview with JavaScript callback interfaces to display web content. 80 * {@code false} - use chrome with custom tabs to display web content. 81 * 82 * <p>Note: this is effective only if the {@link #KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING} 83 * is set to the QNS app. 84 */ 85 public static final String KEY_QNS_JS_CALLBACK_FOR_VOWIFI_PORTAL_BOOL = 86 "qns.js_callback_for_vowifi_portal_bool"; 87 88 public static final int CONFIG_DEFAULT_VOWIFI_REGISTATION_TIMER = 120000; 89 WfcCarrierConfigManager(Context context, int subId)90 WfcCarrierConfigManager(Context context, int subId) { 91 mSubId = subId; 92 mContext = context; 93 } 94 getDefaultBooleanValueForKey(String key)95 private static boolean getDefaultBooleanValueForKey(String key) { 96 Log.d(TAG, "Use default value for key: " + key); 97 switch (key) { 98 case KEY_QNS_SHOW_VOWIFI_PORTAL_AFTER_TIMEOUT_BOOL: 99 return true; 100 case KEY_QNS_JS_CALLBACK_FOR_VOWIFI_PORTAL_BOOL: 101 return false; 102 default: 103 break; 104 } 105 return false; 106 } 107 getDefaultStringValueForKey(String key)108 private static String getDefaultStringValueForKey(String key) { 109 Log.d(TAG, "Use default value for key: " + key); 110 switch (key) { 111 case KEY_QNS_VOWIFI_ENTITLEMENT_SERVER_URL_STRING: 112 return ""; 113 default: 114 break; 115 } 116 return ""; 117 } 118 getDefaultIntValueForKey(String key)119 private static int getDefaultIntValueForKey(String key) { 120 Log.d(TAG, "Use default value for key: " + key); 121 switch (key) { 122 case KEY_QNS_VOWIFI_REGISTATION_TIMER_FOR_VOWIFI_ACTIVATION_INT: 123 return CONFIG_DEFAULT_VOWIFI_REGISTATION_TIMER; 124 default: 125 break; 126 } 127 return 0; 128 } 129 readFromCarrierConfigManager(Context context)130 private PersistableBundle readFromCarrierConfigManager(Context context) { 131 PersistableBundle carrierConfigBundle; 132 CarrierConfigManager carrierConfigManager = 133 context.getSystemService(CarrierConfigManager.class); 134 135 if (carrierConfigManager == null) { 136 throw new IllegalStateException("Carrier config manager is null."); 137 } 138 carrierConfigBundle = carrierConfigManager.getConfigForSubId(mSubId); 139 140 return carrierConfigBundle; 141 } 142 143 @VisibleForTesting loadConfigurations()144 void loadConfigurations() { 145 PersistableBundle carrierConfigBundle = readFromCarrierConfigManager(mContext); 146 Log.d(TAG, "CarrierConfig Bundle for subId: " + mSubId + carrierConfigBundle); 147 loadConfigurationsFromCarrierConfig(carrierConfigBundle); 148 } 149 150 @VisibleForTesting loadConfigurationsFromCarrierConfig(PersistableBundle carrierConfigBundle)151 void loadConfigurationsFromCarrierConfig(PersistableBundle carrierConfigBundle) { 152 mVowifiEntitlementServerUrl = 153 getStringConfig(carrierConfigBundle, 154 KEY_QNS_VOWIFI_ENTITLEMENT_SERVER_URL_STRING); 155 mVowifiRegistrationTimerForVowifiActivation = 156 getIntConfig( 157 carrierConfigBundle, 158 KEY_QNS_VOWIFI_REGISTATION_TIMER_FOR_VOWIFI_ACTIVATION_INT); 159 mIsShowVowifiPortalAfterTimeout = 160 getBooleanConfig(carrierConfigBundle, 161 KEY_QNS_SHOW_VOWIFI_PORTAL_AFTER_TIMEOUT_BOOL); 162 mIsJsCallbackForVowifiPortal = 163 getBooleanConfig(carrierConfigBundle, 164 KEY_QNS_JS_CALLBACK_FOR_VOWIFI_PORTAL_BOOL); 165 } 166 getBooleanConfig(PersistableBundle bundleCarrier, String key)167 private boolean getBooleanConfig(PersistableBundle bundleCarrier, String key) { 168 if (bundleCarrier == null || bundleCarrier.get(key) == null) { 169 return getDefaultBooleanValueForKey(key); 170 } 171 return bundleCarrier.getBoolean(key); 172 } 173 getIntConfig(PersistableBundle bundleCarrier, String key)174 private int getIntConfig(PersistableBundle bundleCarrier, String key) { 175 if (bundleCarrier == null || bundleCarrier.get(key) == null) { 176 return getDefaultIntValueForKey(key); 177 } 178 return bundleCarrier.getInt(key); 179 } 180 getStringConfig(PersistableBundle bundleCarrier, String key)181 private String getStringConfig(PersistableBundle bundleCarrier, String key) { 182 if (bundleCarrier == null || bundleCarrier.get(key) == null) { 183 return getDefaultStringValueForKey(key); 184 } 185 return bundleCarrier.getString(key); 186 } 187 188 /** 189 * This method returns the URL of the VoWiFi entitlement server for an emergency address 190 * registration 191 */ 192 @VisibleForTesting(visibility = PACKAGE) getVowifiEntitlementServerUrl()193 String getVowifiEntitlementServerUrl() { 194 return mVowifiEntitlementServerUrl; 195 } 196 197 /** 198 * This method returns the wait timer in milliseconds that VoWiFi registration in VoWiFi 199 * activation process 200 */ 201 @VisibleForTesting(visibility = PACKAGE) getVowifiRegistrationTimerForVowifiActivation()202 int getVowifiRegistrationTimerForVowifiActivation() { 203 return mVowifiRegistrationTimerForVowifiActivation; 204 } 205 206 /** 207 * This method returns true if a web portal of the carrier is poped up when 208 * {@link #KEY_QNS_VOWIFI_REGISTATION_TIMER_FOR_VOWIFI_ACTIVATION_INT} is expired in VoWiFi 209 * activation process; Otherwise, WFC is tuned on directly. 210 */ 211 @VisibleForTesting(visibility = PACKAGE) isShowVowifiPortalAfterTimeout()212 boolean isShowVowifiPortalAfterTimeout() { 213 return mIsShowVowifiPortalAfterTimeout; 214 } 215 216 /** 217 * This method returns true if JavaScript callback interface is not support for web portal 218 * {@link #KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING} of the carrier 219 */ 220 @VisibleForTesting(visibility = PACKAGE) supportJsCallbackForVowifiPortal()221 boolean supportJsCallbackForVowifiPortal() { 222 return mIsJsCallbackForVowifiPortal; 223 } 224 } 225