1 /*
2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "cellular_call_config.h"
17
18 #include "cellular_call_data_struct.h"
19 #include "cellular_call_hisysevent.h"
20 #include "cellular_call_register.h"
21 #include "cellular_call_service.h"
22 #include "core_manager_inner.h"
23 #include "module_service_utils.h"
24 #include "parameters.h"
25 #include "string_ex.h"
26 #include "telephony_types.h"
27
28 namespace OHOS {
29 namespace Telephony {
30 const int32_t SIM_PRESENT = 1;
31 const int32_t SIM_ABSENT = 0;
32 const int32_t IMS_SWITCH_VALUE_DISABLED = 0;
33 const int32_t IMS_SWITCH_VALUE_ENABLED = 1;
34 const int32_t IMS_SWITCH_VALUE_UNKNOWN = -1;
35 const int32_t IMS_SWITCH_STATUS_OFF = 0;
36 const int32_t IMS_SWITCH_STATUS_ON = 1;
37 const int32_t VONR_SWITCH_VALUE_UNKNOWN = -1;
38 const int32_t VONR_SWITCH_STATUS_OFF = 0;
39 const int32_t VONR_SWITCH_STATUS_ON = 1;
40 const int32_t SAVE_IMS_SWITCH_FAILED = 0;
41 const int32_t SAVE_IMS_SWITCH_SUCCESS_CHANGED = 1;
42 const int32_t SAVE_IMS_SWITCH_SUCCESS_NOT_CHANGED = 2;
43 const int32_t INVALID_SIM_ID = 0;
44 const int32_t IMS_GBA_BIT = 0x02;
45 const int32_t SYSTEM_PARAMETER_LENGTH = 0x02;
46 const int MCC_LEN = 3;
47 const std::string LAST_ICCID_KEY = "persist.telephony.last_iccid";
48 const std::string VONR_STATE = "persist.telephony.vonrswitch";
49
50 std::map<int32_t, int32_t> CellularCallConfig::modeMap_;
51 std::map<int32_t, int32_t> CellularCallConfig::modeTempMap_;
52 std::map<int32_t, bool> CellularCallConfig::imsSwitchOnByDefault_;
53 std::map<int32_t, bool> CellularCallConfig::hideImsSwitch_;
54 std::map<int32_t, bool> CellularCallConfig::volteSupported_;
55 std::map<int32_t, std::vector<int32_t>> CellularCallConfig::nrModeSupportedList_;
56 std::map<int32_t, bool> CellularCallConfig::volteProvisioningSupported_;
57 std::map<int32_t, bool> CellularCallConfig::ssOverUtSupported_;
58 std::map<int32_t, bool> CellularCallConfig::imsGbaRequired_;
59 std::map<int32_t, bool> CellularCallConfig::utProvisioningSupported_;
60 std::map<int32_t, bool> CellularCallConfig::imsPreferForEmergency_;
61 std::map<int32_t, int32_t> CellularCallConfig::callWaitingServiceClass_;
62 std::map<int32_t, std::vector<std::string>> CellularCallConfig::imsCallDisconnectResoninfoMapping_;
63 std::map<int32_t, bool> CellularCallConfig::forceVolteSwitchOn_;
64 std::map<int32_t, int32_t> CellularCallConfig::vonrSwithStatus_;
65 std::mutex mutex_;
66 std::mutex CellularCallConfig::operatorMutex_;
67 std::map<int32_t, std::vector<EmergencyCall>> CellularCallConfig::eccListRadioMap_;
68 std::map<int32_t, std::vector<EmergencyCall>> CellularCallConfig::eccListConfigMap_;
69 std::vector<EmergencyCall> CellularCallConfig::eccList3gppHasSim_;
70 std::vector<EmergencyCall> CellularCallConfig::eccList3gppNoSim_;
71 std::map<int32_t, std::vector<EmergencyCall>> CellularCallConfig::allEccList_;
72 std::map<int32_t, int32_t> CellularCallConfig::simState_;
73 std::map<int32_t, bool> CellularCallConfig::readyToCall_;
74 bool CellularCallConfig::isOperatorConfigInit_ = false;
75
InitDefaultOperatorConfig()76 void CellularCallConfig::InitDefaultOperatorConfig()
77 {
78 std::lock_guard<std::mutex> lock(operatorMutex_);
79 for (int32_t i = DEFAULT_SIM_SLOT_ID; i < SIM_SLOT_COUNT; ++i) {
80 CellularCallConfig::imsSwitchOnByDefault_.insert(std::pair<int, bool>(i, true));
81 CellularCallConfig::hideImsSwitch_.insert(std::pair<int, bool>(i, false));
82 CellularCallConfig::volteSupported_.insert(std::pair<int, bool>(i, false));
83 CellularCallConfig::nrModeSupportedList_.insert(std::pair<int, std::vector<int32_t>>(
84 i, std::vector<int32_t> { CARRIER_NR_AVAILABILITY_NSA, CARRIER_NR_AVAILABILITY_SA }));
85 CellularCallConfig::volteProvisioningSupported_.insert(std::pair<int, bool>(i, false));
86 CellularCallConfig::ssOverUtSupported_.insert(std::pair<int, bool>(i, false));
87 CellularCallConfig::imsGbaRequired_.insert(std::pair<int, bool>(i, false));
88 CellularCallConfig::utProvisioningSupported_.insert(std::pair<int, bool>(i, false));
89 CellularCallConfig::imsPreferForEmergency_.insert(std::pair<int, bool>(i, true));
90 CellularCallConfig::callWaitingServiceClass_.insert(
91 std::pair<int, int32_t>(i, DEFAULT_CALL_WAITING_SERVICE_CLASS_CONFIG));
92 CellularCallConfig::imsCallDisconnectResoninfoMapping_.insert(
93 std::pair<int, std::vector<std::string>>(i, IMS_CALL_DISCONNECT_REASONINFO_MAPPING_CONFIG));
94 CellularCallConfig::forceVolteSwitchOn_.insert(std::pair<int, bool>(i, false));
95 CellularCallConfig::readyToCall_.insert(std::pair<int, bool>(i, true));
96 CellularCallConfig::vonrSwithStatus_.insert(std::pair<int, int>(i, VONR_SWITCH_VALUE_UNKNOWN));
97 }
98 }
99
CellularCallConfig()100 CellularCallConfig::CellularCallConfig()
101 {
102 if (!isOperatorConfigInit_) {
103 InitDefaultOperatorConfig();
104 isOperatorConfigInit_ = true;
105 }
106 }
107
SetDomainPreferenceMode(int32_t slotId,int32_t mode)108 int32_t CellularCallConfig::SetDomainPreferenceMode(int32_t slotId, int32_t mode)
109 {
110 if (mode < DomainPreferenceMode::CS_VOICE_ONLY || mode > DomainPreferenceMode::IMS_PS_VOICE_ONLY) {
111 TELEPHONY_LOGE("SetDomainPreferenceMode return, mode out of range!");
112 return CALL_ERR_PARAMETER_OUT_OF_RANGE;
113 }
114 modeTempMap_[slotId] = mode;
115 return configRequest_.SetDomainPreferenceModeRequest(slotId, mode);
116 }
117
GetDomainPreferenceMode(int32_t slotId)118 int32_t CellularCallConfig::GetDomainPreferenceMode(int32_t slotId)
119 {
120 return configRequest_.GetDomainPreferenceModeRequest(slotId);
121 }
122
SetImsSwitchStatus(int32_t slotId,bool active)123 int32_t CellularCallConfig::SetImsSwitchStatus(int32_t slotId, bool active)
124 {
125 TELEPHONY_LOGI(
126 "CellularCallConfig::SetImsSwitchStatus entry, slotId: %{public}d, active: %{public}d", slotId, active);
127 if (!volteSupported_[slotId]) {
128 TELEPHONY_LOGE("Enable ims switch failed due to volte is not supported.");
129 return CALL_ERR_VOLTE_NOT_SUPPORT;
130 }
131 if (active && !IsVolteProvisioned(slotId)) {
132 TELEPHONY_LOGE("Enable ims switch failed due to volte provisioning disabled.");
133 return CALL_ERR_VOLTE_PROVISIONING_DISABLED;
134 }
135 int32_t simId = CoreManagerInner::GetInstance().GetSimId(slotId);
136 if (simId <= INVALID_SIM_ID) {
137 TELEPHONY_LOGE("failed due to invalid sim id %{public}d", simId);
138 return TELEPHONY_ERR_SLOTID_INVALID;
139 }
140
141 active = ChangeImsSwitchWithOperatorConfig(slotId, active);
142 int32_t ret = SaveImsSwitch(slotId, BooleanToImsSwitchValue(active));
143 if (ret == SAVE_IMS_SWITCH_FAILED) {
144 return TELEPHONY_ERR_DATABASE_WRITE_FAIL;
145 } else if (ret == SAVE_IMS_SWITCH_SUCCESS_NOT_CHANGED) {
146 return TELEPHONY_SUCCESS;
147 }
148
149 SimState simState = SimState::SIM_STATE_UNKNOWN;
150 CoreManagerInner::GetInstance().GetSimState(slotId, simState);
151 TELEPHONY_LOGI("active: %{public}d simState : %{public}d", active, simState);
152 if (simState == SimState::SIM_STATE_LOADED || simState == SimState::SIM_STATE_READY) {
153 UpdateImsCapabilities(slotId, !active);
154 }
155 return TELEPHONY_SUCCESS;
156 }
157
GetImsSwitchStatus(int32_t slotId,bool & enabled)158 int32_t CellularCallConfig::GetImsSwitchStatus(int32_t slotId, bool &enabled)
159 {
160 TELEPHONY_LOGD("entry, slotId: %{public}d", slotId);
161 auto itorHide = hideImsSwitch_.find(slotId);
162 if (itorHide != hideImsSwitch_.end()) {
163 if (itorHide->second) {
164 auto itorSwitch = imsSwitchOnByDefault_.find(slotId);
165 if (itorSwitch != imsSwitchOnByDefault_.end()) {
166 enabled = imsSwitchOnByDefault_[slotId];
167 }
168 } else {
169 int32_t imsSwitchStatus = GetSwitchStatus(slotId);
170 enabled = imsSwitchStatus;
171 }
172 } else {
173 TELEPHONY_LOGE("do not find hideImsSwitch");
174 int32_t imsSwitchStatus = GetSwitchStatus(slotId);
175 enabled = imsSwitchStatus;
176 }
177 return TELEPHONY_SUCCESS;
178 }
179
SetVoNRSwitchStatus(int32_t slotId,int32_t state)180 int32_t CellularCallConfig::SetVoNRSwitchStatus(int32_t slotId, int32_t state)
181 {
182 TELEPHONY_LOGI(
183 "CellularCallConfig::SetVoNRSwitchStatus entry, slotId: %{public}d, state: %{public}d", slotId, state);
184 if (!IsVonrSupported(slotId, IsGbaValid(slotId))) {
185 TELEPHONY_LOGE("Enable VoNR switch failed due to VoNR is not supported.");
186 return TELEPHONY_ERR_FAIL;
187 }
188 SimState simState = SimState::SIM_STATE_UNKNOWN;
189 CoreManagerInner::GetInstance().GetSimState(slotId, simState);
190 if (simState == SimState::SIM_STATE_LOADED || simState == SimState::SIM_STATE_READY) {
191 configRequest_.SetVoNRSwitchStatusRequest(slotId, state);
192 vonrSwithStatus_[slotId] = state;
193 return TELEPHONY_SUCCESS;
194 }
195 return TELEPHONY_ERR_NO_SIM_CARD;
196 }
197
GetVoNRSwitchStatus(int32_t slotId,int32_t & state)198 int32_t CellularCallConfig::GetVoNRSwitchStatus(int32_t slotId, int32_t &state)
199 {
200 if (!IsVonrSupported(slotId, IsGbaValid(slotId))) {
201 TELEPHONY_LOGE("Enable VoNR switch failed due to VoNR is not supported.");
202 state = VONR_SWITCH_STATUS_OFF;
203 return TELEPHONY_SUCCESS;
204 }
205 state = ObtainVoNRState(slotId);
206 return TELEPHONY_SUCCESS;
207 }
208
HandleSimStateChanged(int32_t slotId)209 void CellularCallConfig::HandleSimStateChanged(int32_t slotId)
210 {
211 TELEPHONY_LOGI("CellularCallConfig::HandleSimStateChanged entry, slotId: %{public}d", slotId);
212 if (IsNeedUpdateEccListWhenSimStateChanged(slotId)) {
213 MergeEccCallList(slotId);
214 SetEmergencyCallList(slotId);
215 }
216 }
217
HandleSimRecordsLoaded(int32_t slotId)218 void CellularCallConfig::HandleSimRecordsLoaded(int32_t slotId)
219 {
220 SimState simState = SimState::SIM_STATE_UNKNOWN;
221 CoreManagerInner::GetInstance().GetSimState(slotId, simState);
222 TELEPHONY_LOGI("HandleSimRecordsLoaded slotId: %{public}d, sim state is :%{public}d", slotId, simState);
223 }
224
HandleOperatorConfigChanged(int32_t slotId)225 void CellularCallConfig::HandleOperatorConfigChanged(int32_t slotId)
226 {
227 OperatorConfig operatorConfig;
228 int32_t ret = CoreManagerInner::GetInstance().GetOperatorConfigs(slotId, operatorConfig);
229 if (ret != TELEPHONY_SUCCESS) {
230 TELEPHONY_LOGE("failed due to get operator config");
231 return;
232 }
233 UpdateEccWhenOperatorConfigChange(slotId, operatorConfig);
234 int32_t result = ParseAndCacheOperatorConfigs(slotId, operatorConfig);
235 if (result != TELEPHONY_SUCCESS) {
236 TELEPHONY_LOGE("failed due to parse operator config");
237 return;
238 }
239
240 ResetImsSwitch(slotId);
241 UpdateImsCapabilities(slotId, true);
242 }
243
ParseAndCacheOperatorConfigs(int32_t slotId,OperatorConfig & poc)244 int32_t CellularCallConfig::ParseAndCacheOperatorConfigs(int32_t slotId, OperatorConfig &poc)
245 {
246 TELEPHONY_LOGI("CellularCallConfig::ParseAndCacheOperatorConfigs start. slotId %{public}d", slotId);
247 std::lock_guard<std::mutex> lock(operatorMutex_);
248 if (!IsValidSlotId(slotId)) {
249 TELEPHONY_LOGE(" invalid slot id %{public}d", slotId);
250 return TELEPHONY_ERROR;
251 }
252
253 ParseBoolOperatorConfigs(slotId, imsSwitchOnByDefault_, poc, KEY_IMS_SWITCH_ON_BY_DEFAULT_BOOL);
254 ParseBoolOperatorConfigs(slotId, hideImsSwitch_, poc, KEY_HIDE_IMS_SWITCH_BOOL);
255 ParseBoolOperatorConfigs(slotId, volteSupported_, poc, KEY_VOLTE_SUPPORTED_BOOL);
256 ParseBoolOperatorConfigs(slotId, volteProvisioningSupported_, poc, KEY_VOLTE_PROVISIONING_SUPPORTED_BOOL);
257 ParseBoolOperatorConfigs(slotId, ssOverUtSupported_, poc, KEY_SS_OVER_UT_SUPPORTED_BOOL);
258 ParseBoolOperatorConfigs(slotId, imsGbaRequired_, poc, KEY_IMS_GBA_REQUIRED_BOOL);
259 ParseBoolOperatorConfigs(slotId, utProvisioningSupported_, poc, KEY_UT_PROVISIONING_SUPPORTED_BOOL);
260 ParseBoolOperatorConfigs(slotId, imsPreferForEmergency_, poc, KEY_IMS_PREFER_FOR_EMERGENCY_BOOL);
261 ParseBoolOperatorConfigs(slotId, forceVolteSwitchOn_, poc, KEY_FORCE_VOLTE_SWITCH_ON_BOOL);
262
263 if (poc.intArrayValue.count(KEY_NR_MODE_SUPPORTED_LIST_INT_ARRAY) > 0) {
264 nrModeSupportedList_[slotId] = poc.intArrayValue[KEY_NR_MODE_SUPPORTED_LIST_INT_ARRAY];
265 }
266 if (poc.intValue.count(KEY_CALL_WAITING_SERVICE_CLASS_INT) > 0) {
267 callWaitingServiceClass_[slotId] = poc.intValue[KEY_CALL_WAITING_SERVICE_CLASS_INT];
268 }
269 if (poc.stringArrayValue.count(KEY_IMS_CALL_DISCONNECT_REASONINFO_MAPPING_STRING_ARRAY) > 0) {
270 imsCallDisconnectResoninfoMapping_[slotId] =
271 poc.stringArrayValue[KEY_IMS_CALL_DISCONNECT_REASONINFO_MAPPING_STRING_ARRAY];
272 }
273 return TELEPHONY_SUCCESS;
274 }
275
ParseBoolOperatorConfigs(int32_t slotId,std::map<int32_t,bool> & config,OperatorConfig & poc,std::string configName)276 void CellularCallConfig::ParseBoolOperatorConfigs(
277 int32_t slotId, std::map<int32_t, bool> &config, OperatorConfig &poc, std::string configName)
278 {
279 auto it = poc.boolValue.find(configName);
280 if (it != poc.boolValue.end()) {
281 config[slotId] = it->second;
282 } else {
283 TELEPHONY_LOGE("do't find operator config %{public}s", configName.c_str());
284 }
285 }
286
ResetImsSwitch(int32_t slotId)287 void CellularCallConfig::ResetImsSwitch(int32_t slotId)
288 {
289 bool hasSimCard = false;
290 CoreManagerInner::GetInstance().HasSimCard(slotId, hasSimCard);
291 if (!hasSimCard) {
292 TELEPHONY_LOGE("return due to no sim card");
293 return;
294 }
295 std::u16string iccId;
296 CoreManagerInner::GetInstance().GetSimIccId(slotId, iccId);
297 if (IsSimChanged(slotId, Str16ToStr8(iccId)) && forceVolteSwitchOn_[slotId]) {
298 int32_t ret = CoreManagerInner::GetInstance().SaveImsSwitch(
299 slotId, BooleanToImsSwitchValue(imsSwitchOnByDefault_[slotId]));
300 if (ret != TELEPHONY_SUCCESS) {
301 TELEPHONY_LOGE("SaveImsSwitch failed");
302 }
303 }
304 }
305
UpdateImsCapabilities(int32_t slotId,bool needUpdateUtCapability)306 void CellularCallConfig::UpdateImsCapabilities(int32_t slotId, bool needUpdateUtCapability)
307 {
308 bool isGbaValid = IsGbaValid(slotId);
309 ImsCapabilityList imsCapabilityList;
310
311 UpdateImsVoiceCapabilities(slotId, isGbaValid, imsCapabilityList);
312 if (needUpdateUtCapability) {
313 UpdateImsUtCapabilities(slotId, isGbaValid, imsCapabilityList);
314 }
315 configRequest_.UpdateImsCapabilities(slotId, imsCapabilityList);
316 configRequest_.SetImsSwitchStatusRequest(slotId, IsNeedTurnOnIms(imsCapabilityList));
317 }
318
IsGbaValid(int32_t slotId)319 bool CellularCallConfig::IsGbaValid(int32_t slotId)
320 {
321 if (imsGbaRequired_[slotId]) {
322 std::u16string simist = CoreManagerInner::GetInstance().GetSimIst(slotId);
323 std::string simistStr = Str16ToStr8(simist);
324 // If carrier requires that IMS is only available if GBA capable SIM is used,
325 // then this function checks GBA bit in EF IST.
326 // Format of EF IST is defined in 3GPP TS 31.103 (Section 4.2.7).
327 if (!simistStr.empty() && simistStr.length() > 1) {
328 bool result = (IMS_GBA_BIT & simistStr.at(1)) != 0;
329 return result;
330 }
331 }
332 return true;
333 }
334
UpdateImsVoiceCapabilities(int32_t slotId,bool isGbaValid,ImsCapabilityList & imsCapabilityList)335 void CellularCallConfig::UpdateImsVoiceCapabilities(
336 int32_t slotId, bool isGbaValid, ImsCapabilityList &imsCapabilityList)
337 {
338 bool imsSwitch = false;
339 GetImsSwitchStatus(slotId, imsSwitch);
340 ImsCapability volteCapability;
341 volteCapability.imsCapabilityType = ImsCapabilityType::CAPABILITY_TYPE_VOICE;
342 volteCapability.imsRadioTech = ImsRegTech::IMS_REG_TECH_LTE;
343 volteCapability.enable = volteSupported_[slotId] && isGbaValid && imsSwitch && IsVolteProvisioned(slotId);
344 imsCapabilityList.imsCapabilities.push_back(volteCapability);
345
346 int32_t vonrSwitch = VONR_SWITCH_STATUS_OFF;
347 GetVoNRSwitchStatus(slotId, vonrSwitch);
348 bool vonrSwitchEnabled = vonrSwitch == VONR_SWITCH_STATUS_ON;
349 ImsCapability vonrCapability;
350 vonrCapability.imsCapabilityType = ImsCapabilityType::CAPABILITY_TYPE_VOICE;
351 vonrCapability.imsRadioTech = ImsRegTech::IMS_REG_TECH_NR;
352 vonrCapability.enable = volteCapability.enable && IsVonrSupported(slotId, isGbaValid) && vonrSwitchEnabled;
353 imsCapabilityList.imsCapabilities.push_back(vonrCapability);
354 }
355
UpdateImsUtCapabilities(int32_t slotId,bool isGbaValid,ImsCapabilityList & imsCapabilityList)356 void CellularCallConfig::UpdateImsUtCapabilities(int32_t slotId, bool isGbaValid, ImsCapabilityList &imsCapabilityList)
357 {
358 ImsCapability utCapability;
359 utCapability.imsCapabilityType = ImsCapabilityType::CAPABILITY_TYPE_UT;
360 utCapability.imsRadioTech = ImsRegTech::IMS_REG_TECH_LTE;
361 utCapability.enable = ssOverUtSupported_[slotId] && isGbaValid && IsUtProvisioned(slotId);
362 imsCapabilityList.imsCapabilities.push_back(utCapability);
363 }
364
IsVolteProvisioned(int32_t slotId)365 bool CellularCallConfig::IsVolteProvisioned(int32_t slotId)
366 {
367 if (volteProvisioningSupported_[slotId]) {
368 int32_t volteFeatureValue;
369 int32_t result = configRequest_.GetImsFeatureValueRequest(FeatureType::TYPE_VOICE_OVER_LTE, volteFeatureValue);
370 if (result != TELEPHONY_SUCCESS) {
371 TELEPHONY_LOGE("get volte feature value failed");
372 return false;
373 }
374 return volteFeatureValue == ImsFeatureIntResult::IMS_FEATURE_INT_VALUE_ENABLED;
375 }
376 return true;
377 }
378
IsVonrSupported(int32_t slotId,bool isGbaValid)379 bool CellularCallConfig::IsVonrSupported(int32_t slotId, bool isGbaValid)
380 {
381 if (std::find(nrModeSupportedList_[slotId].begin(), nrModeSupportedList_[slotId].end(),
382 CARRIER_NR_AVAILABILITY_SA) == nrModeSupportedList_[slotId].end()) {
383 return false;
384 }
385 return isGbaValid;
386 }
387
IsUtProvisioned(int32_t slotId)388 bool CellularCallConfig::IsUtProvisioned(int32_t slotId)
389 {
390 if (utProvisioningSupported_[slotId]) {
391 int32_t utFeatureValue;
392 int32_t result = configRequest_.GetImsFeatureValueRequest(FeatureType::TYPE_SS_OVER_UT, utFeatureValue);
393 if (result != TELEPHONY_SUCCESS) {
394 TELEPHONY_LOGE("get ut feature value failed");
395 return false;
396 }
397 return utFeatureValue == ImsFeatureIntResult::IMS_FEATURE_INT_VALUE_ENABLED;
398 }
399 return true;
400 }
401
BuildEmergencyCall(int32_t slotId,const EmergencyInfo & from)402 EmergencyCall CellularCallConfig::BuildEmergencyCall(int32_t slotId, const EmergencyInfo &from)
403 {
404 EmergencyCall to = {};
405 to.eccNum = from.eccNum;
406 to.eccType = EccType(from.category);
407 to.simpresent = SimpresentType(from.simpresent);
408 to.mcc = from.mcc;
409 to.abnormalService = AbnormalServiceType(from.abnormalService);
410 return to;
411 }
412
IsNeedTurnOnIms(const ImsCapabilityList & imsCapabilityList)413 bool CellularCallConfig::IsNeedTurnOnIms(const ImsCapabilityList &imsCapabilityList)
414 {
415 for (auto imsCapabilitie : imsCapabilityList.imsCapabilities) {
416 if (imsCapabilitie.imsCapabilityType == ImsCapabilityType::CAPABILITY_TYPE_VOICE
417 || imsCapabilitie.imsCapabilityType == ImsCapabilityType::CAPABILITY_TYPE_VIDEO) {
418 if (imsCapabilitie.enable) {
419 return true;
420 }
421 }
422 }
423 return false;
424 }
425
IsSimChanged(int32_t slotId,std::string iccid)426 bool CellularCallConfig::IsSimChanged(int32_t slotId, std::string iccid)
427 {
428 const int32_t sysparaSize = SYSTEM_PARAMETER_LENGTH;
429 char lastIccid[sysparaSize] = { 0 };
430 std::string key = LAST_ICCID_KEY + std::to_string(slotId);
431 GetParameter(key.c_str(), "", lastIccid, sysparaSize);
432
433 if (iccid.compare(lastIccid) != 0) {
434 SetParameter(key.c_str(), iccid.c_str());
435 return true;
436 }
437 return false;
438 }
439
ChangeImsSwitchWithOperatorConfig(int32_t slotId,bool active)440 bool CellularCallConfig::ChangeImsSwitchWithOperatorConfig(int32_t slotId, bool active)
441 {
442 auto itorHide = hideImsSwitch_.find(slotId);
443 if (itorHide != hideImsSwitch_.end()) {
444 if (itorHide->second) {
445 auto itorSwitch = imsSwitchOnByDefault_.find(slotId);
446 if (itorSwitch != imsSwitchOnByDefault_.end()) {
447 active = imsSwitchOnByDefault_[slotId];
448 return active;
449 }
450 }
451 }
452 TELEPHONY_LOGE("do not find hideImsSwitch or imsSwitchOnByDefault config");
453 return active;
454 }
455
SaveImsSwitch(int32_t slotId,int32_t imsSwitchValue)456 int32_t CellularCallConfig::SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue)
457 {
458 int32_t lastImsSwitchValue;
459 int32_t queryRet = CoreManagerInner::GetInstance().QueryImsSwitch(slotId, lastImsSwitchValue);
460 if (queryRet != TELEPHONY_SUCCESS) {
461 TELEPHONY_LOGE("query ims switch failed");
462 return SAVE_IMS_SWITCH_FAILED;
463 }
464
465 if (imsSwitchValue == lastImsSwitchValue) {
466 TELEPHONY_LOGI("ims switch status do not change, imsSwitchValue: %{public}d", imsSwitchValue);
467 return SAVE_IMS_SWITCH_SUCCESS_NOT_CHANGED;
468 }
469 int32_t saveRet = CoreManagerInner::GetInstance().SaveImsSwitch(slotId, imsSwitchValue);
470 if (saveRet != TELEPHONY_SUCCESS) {
471 TELEPHONY_LOGE("save ims switch failed!");
472 return SAVE_IMS_SWITCH_FAILED;
473 }
474 return SAVE_IMS_SWITCH_SUCCESS_CHANGED;
475 }
476
SaveVoNRState(int32_t slotId,int32_t state)477 void CellularCallConfig::SaveVoNRState(int32_t slotId, int32_t state)
478 {
479 CellularCallHiSysEvent::WriteVoNRSwitchChangeEvent(state);
480 TELEPHONY_LOGI("slotId: %{public}d, switchState: %{public}d", slotId, state);
481 std::string vonrState = std::to_string(state);
482 std::string vonrStateKey = VONR_STATE + std::to_string(slotId);
483 SetParameter(vonrStateKey.c_str(), vonrState.c_str());
484 }
485
ObtainVoNRState(int32_t slotId)486 int32_t CellularCallConfig::ObtainVoNRState(int32_t slotId)
487 {
488 std::string vonrStateKey = VONR_STATE + std::to_string(slotId);
489
490 int32_t vonrState = GetIntParameter(vonrStateKey.c_str(), VONR_SWITCH_STATUS_ON);
491 TELEPHONY_LOGI("slotId: %{public}d, switchState: %{public}d", slotId, vonrState);
492 return vonrState;
493 }
494
HandleSetLteImsSwitchResult(int32_t slotId,HRilErrType result)495 void CellularCallConfig::HandleSetLteImsSwitchResult(int32_t slotId, HRilErrType result)
496 {
497 TELEPHONY_LOGI("CellularCallConfig::HandleSetLteImsSwitchResult entry, slotId: %{public}d", slotId);
498 if (result != HRilErrType::NONE) {
499 TELEPHONY_LOGE("HandleSetLteImsSwitchResult set ims switch to modem failed!");
500 // need to reset the Ims Switch parameter and notify APP to update UI.
501 }
502 }
503
HandleSetVoNRSwitchResult(int32_t slotId,HRilErrType result)504 void CellularCallConfig::HandleSetVoNRSwitchResult(int32_t slotId, HRilErrType result)
505 {
506 TELEPHONY_LOGD("CellularCallConfig::HandleSetVoNRSwitchResult entry, slotId: %{public}d", slotId);
507 if (result != HRilErrType::NONE) {
508 TELEPHONY_LOGE("HandleSetVoNRSwitchResult set vonr switch to modem failed!");
509 return;
510 }
511 SaveVoNRState(slotId, vonrSwithStatus_[slotId]);
512 ImsCapabilityList imsCapabilityList;
513 UpdateImsVoiceCapabilities(slotId, IsGbaValid(slotId), imsCapabilityList);
514 configRequest_.UpdateImsCapabilities(slotId, imsCapabilityList);
515 }
516
GetDomainPreferenceModeResponse(int32_t slotId,int32_t mode)517 void CellularCallConfig::GetDomainPreferenceModeResponse(int32_t slotId, int32_t mode)
518 {
519 modeMap_[slotId] = mode;
520 }
521
GetImsSwitchStatusResponse(int32_t slotId,int32_t active)522 void CellularCallConfig::GetImsSwitchStatusResponse(int32_t slotId, int32_t active) {}
523
GetPreferenceMode(int32_t slotId) const524 int32_t CellularCallConfig::GetPreferenceMode(int32_t slotId) const
525 {
526 return modeMap_[slotId];
527 }
528
GetSwitchStatus(int32_t slotId) const529 int32_t CellularCallConfig::GetSwitchStatus(int32_t slotId) const
530 {
531 TELEPHONY_LOGI("CellularCallConfig::GetSwitchStatus entry, slotId: %{public}d", slotId);
532 int32_t imsSwitchStatus = IMS_SWITCH_VALUE_UNKNOWN;
533 int32_t ret = CoreManagerInner::GetInstance().QueryImsSwitch(slotId, imsSwitchStatus);
534 if (ret != TELEPHONY_SUCCESS || imsSwitchStatus == IMS_SWITCH_VALUE_UNKNOWN) {
535 TELEPHONY_LOGW("get ims switch failed, return default ims switch in operator config");
536 imsSwitchStatus = imsSwitchOnByDefault_[slotId] ? IMS_SWITCH_STATUS_ON : IMS_SWITCH_STATUS_OFF;
537 }
538 TELEPHONY_LOGI("imsSwitchStatus : %{public}d", imsSwitchStatus);
539 return imsSwitchStatus;
540 }
541
SetImsConfig(ImsConfigItem item,const std::string & value)542 int32_t CellularCallConfig::SetImsConfig(ImsConfigItem item, const std::string &value)
543 {
544 return configRequest_.SetImsConfigRequest(item, value);
545 }
546
SetImsConfig(ImsConfigItem item,int32_t value)547 int32_t CellularCallConfig::SetImsConfig(ImsConfigItem item, int32_t value)
548 {
549 return configRequest_.SetImsConfigRequest(item, value);
550 }
551
GetImsConfig(ImsConfigItem item)552 int32_t CellularCallConfig::GetImsConfig(ImsConfigItem item)
553 {
554 return configRequest_.GetImsConfigRequest(item);
555 }
556
SetImsFeatureValue(FeatureType type,int32_t value)557 int32_t CellularCallConfig::SetImsFeatureValue(FeatureType type, int32_t value)
558 {
559 return configRequest_.SetImsFeatureValueRequest(type, value);
560 }
561
GetImsFeatureValue(FeatureType type)562 int32_t CellularCallConfig::GetImsFeatureValue(FeatureType type)
563 {
564 int32_t imsFeatureValue;
565 int32_t ret = configRequest_.GetImsFeatureValueRequest(type, imsFeatureValue);
566 GetImsFeatureValueResponse response;
567 response.result = ret;
568 response.value = imsFeatureValue;
569 DelayedSingleton<CellularCallRegister>::GetInstance()->ReportGetImsFeatureResult(response);
570 return ret;
571 }
572
CtrlCamera(const std::u16string & cameraId,int32_t callingUid,int32_t callingPid)573 int32_t CellularCallConfig::CtrlCamera(const std::u16string &cameraId, int32_t callingUid, int32_t callingPid)
574 {
575 return configRequest_.CtrlCameraRequest(cameraId, callingUid, callingPid);
576 }
577
SetPreviewWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)578 int32_t CellularCallConfig::SetPreviewWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
579 {
580 return configRequest_.SetPreviewWindowRequest(x, y, z, width, height);
581 }
582
SetDisplayWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)583 int32_t CellularCallConfig::SetDisplayWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
584 {
585 return configRequest_.SetDisplayWindowRequest(x, y, z, width, height);
586 }
587
SetCameraZoom(float zoomRatio)588 int32_t CellularCallConfig::SetCameraZoom(float zoomRatio)
589 {
590 return configRequest_.SetCameraZoomRequest(zoomRatio);
591 }
592
SetPauseImage(const std::u16string & path)593 int32_t CellularCallConfig::SetPauseImage(const std::u16string &path)
594 {
595 return configRequest_.SetPauseImageRequest(path);
596 }
597
SetDeviceDirection(int32_t rotation)598 int32_t CellularCallConfig::SetDeviceDirection(int32_t rotation)
599 {
600 return configRequest_.SetDeviceDirectionRequest(rotation);
601 }
602
SetTempMode(int32_t slotId)603 void CellularCallConfig::SetTempMode(int32_t slotId)
604 {
605 modeMap_[slotId] = modeTempMap_[slotId];
606 }
607
InitModeActive()608 void CellularCallConfig::InitModeActive()
609 {
610 int32_t slotId = DEFAULT_SIM_SLOT_ID;
611 modeMap_[slotId] = DomainPreferenceMode::IMS_PS_VOICE_PREFERRED;
612 eccListRadioMap_.clear();
613 eccList3gppHasSim_.clear();
614 eccList3gppNoSim_.clear();
615 eccListConfigMap_.clear();
616 allEccList_.clear();
617 eccList3gppHasSim_.push_back(BuildDefaultEmergencyCall("112"));
618 eccList3gppHasSim_.push_back(BuildDefaultEmergencyCall("991"));
619 eccList3gppNoSim_.push_back(BuildDefaultEmergencyCall("112"));
620 eccList3gppNoSim_.push_back(BuildDefaultEmergencyCall("991"));
621 eccList3gppNoSim_.push_back(BuildDefaultEmergencyCall("000"));
622 eccList3gppNoSim_.push_back(BuildDefaultEmergencyCall("08"));
623 eccList3gppNoSim_.push_back(BuildDefaultEmergencyCall("110"));
624 eccList3gppNoSim_.push_back(BuildDefaultEmergencyCall("118"));
625 eccList3gppNoSim_.push_back(BuildDefaultEmergencyCall("119"));
626 eccList3gppNoSim_.push_back(BuildDefaultEmergencyCall("999"));
627 TELEPHONY_LOGD("InitModeActive finish");
628 }
629
BuildDefaultEmergencyCall(const std::string & number)630 EmergencyCall CellularCallConfig::BuildDefaultEmergencyCall(const std::string &number)
631 {
632 EmergencyCall emergencyCall;
633 emergencyCall.eccNum = number;
634 emergencyCall.eccType = EccType::TYPE_CATEGORY;
635 emergencyCall.simpresent = SimpresentType::TYPE_HAS_CARD;
636 emergencyCall.mcc = "";
637 emergencyCall.abnormalService = AbnormalServiceType::TYPE_ALL;
638 return emergencyCall;
639 }
640
UpdateEccWhenOperatorConfigChange(int32_t slotId,OperatorConfig & opc)641 void CellularCallConfig::UpdateEccWhenOperatorConfigChange(int32_t slotId, OperatorConfig &opc)
642 {
643 eccListConfigMap_[slotId].clear();
644 std::vector<EmergencyCall> configVector;
645 std::string mcc = GetMcc(slotId);
646 if (mcc.empty()) {
647 TELEPHONY_LOGE("MergeEccCallList countryCode is null");
648 return;
649 }
650 std::vector<std::string> callList = opc.stringArrayValue[KEY_EMERGENCY_CALL_STRING_ARRAY];
651 for (auto call : callList) {
652 auto emergencyCall = BuildDefaultEmergencyCall(call);
653 emergencyCall.mcc = mcc;
654 configVector.push_back(emergencyCall);
655 }
656 eccListConfigMap_[slotId] = configVector;
657 TELEPHONY_LOGI("UpdateEccWhenOperatorConfigChange slotId %{public}d config call size %{public}zu success", slotId,
658 callList.size());
659 MergeEccCallList(slotId);
660 SetEmergencyCallList(slotId);
661 }
662
MergeEccCallList(int32_t slotId_)663 void CellularCallConfig::MergeEccCallList(int32_t slotId_)
664 {
665 std::lock_guard<std::mutex> lock(mutex_);
666 allEccList_[slotId_].clear();
667 for (auto ecc : eccListRadioMap_[slotId_]) {
668 allEccList_[slotId_].push_back(ecc);
669 }
670 TELEPHONY_LOGI("MergeEccCallList merge radio slotId %{public}d size %{public}d", slotId_,
671 static_cast<int32_t>(eccListRadioMap_[slotId_].size()));
672 for (auto ecc : eccListConfigMap_[slotId_]) {
673 allEccList_[slotId_].push_back(ecc);
674 }
675 TELEPHONY_LOGI("MergeEccCallList merge config slotId %{public}d size %{public}zu", slotId_,
676 eccListConfigMap_[slotId_].size());
677 SimState simState = SimState::SIM_STATE_UNKNOWN;
678 CoreManagerInner::GetInstance().GetSimState(slotId_, simState);
679 if (simState != SimState::SIM_STATE_NOT_PRESENT) {
680 std::string mcc = GetMcc(slotId_);
681 if (mcc.empty()) {
682 TELEPHONY_LOGE("MergeEccCallList countryCode is null");
683 return;
684 }
685 for (auto ecc : eccList3gppHasSim_) {
686 ecc.mcc = mcc;
687 allEccList_[slotId_].push_back(ecc);
688 }
689 } else {
690 for (auto ecc : eccList3gppNoSim_) {
691 allEccList_[slotId_].push_back(ecc);
692 }
693 }
694 UniqueEccCallList(slotId_);
695 }
696
UniqueEccCallList(int32_t slotId_)697 void CellularCallConfig::UniqueEccCallList(int32_t slotId_)
698 {
699 std::vector<EmergencyCall> uniques;
700 for (auto call : allEccList_[slotId_]) {
701 if (std::find(uniques.begin(), uniques.end(), call) == uniques.end()) {
702 uniques.push_back(call);
703 }
704 }
705 TELEPHONY_LOGI("UniqueEccCallList end slotId %{public}d from size %{public}zu to size %{public}zu", slotId_,
706 allEccList_[slotId_].size(), uniques.size());
707 }
708
GetMcc(int32_t slotId_)709 std::string CellularCallConfig::GetMcc(int32_t slotId_)
710 {
711 std::u16string operatorNumeric;
712 CoreManagerInner::GetInstance().GetSimOperatorNumeric(slotId_, operatorNumeric);
713 std::string imsi = Str16ToStr8(operatorNumeric);
714 int len = static_cast<int>(imsi.length());
715 std::string mcc = imsi;
716 if (len >= MCC_LEN) {
717 mcc = imsi.substr(0, MCC_LEN);
718 }
719 TELEPHONY_LOGI("getMcc slotd %{public}d mcc %{public}s end", slotId_, mcc.c_str());
720 return mcc;
721 }
722
SetEmergencyCallList(int32_t slotId)723 int32_t CellularCallConfig::SetEmergencyCallList(int32_t slotId)
724 {
725 TELEPHONY_LOGD("SetEmergencyCallList start");
726 return SetEmergencyCallList(slotId, allEccList_[slotId]);
727 }
728
SetMute(int32_t slotId,int32_t mute)729 int32_t CellularCallConfig::SetMute(int32_t slotId, int32_t mute)
730 {
731 return configRequest_.SetMuteRequest(slotId, mute);
732 }
733
GetMute(int32_t slotId)734 int32_t CellularCallConfig::GetMute(int32_t slotId)
735 {
736 return configRequest_.GetMuteRequest(slotId);
737 }
738
GetEmergencyCallList(int32_t slotId)739 int32_t CellularCallConfig::GetEmergencyCallList(int32_t slotId)
740 {
741 return configRequest_.GetEmergencyCallListRequest(slotId);
742 }
743
SetEmergencyCallList(int32_t slotId,const std::vector<EmergencyCall> & eccVec)744 int32_t CellularCallConfig::SetEmergencyCallList(int32_t slotId, const std::vector<EmergencyCall> &eccVec)
745 {
746 TELEPHONY_LOGD("SetEmergencyCallList start %{public}d", slotId);
747 std::lock_guard<std::mutex> lock(mutex_);
748 std::vector<EmergencyCall> uniques;
749 for (auto call : eccVec) {
750 if (std::find(eccListRadioMap_[slotId].begin(), eccListRadioMap_[slotId].end(), call) ==
751 eccListRadioMap_[slotId].end()) {
752 uniques.push_back(call);
753 }
754 }
755 TELEPHONY_LOGI("select end slotId %{public}d from size %{public}zu to size %{public}zu", slotId, eccVec.size(),
756 uniques.size());
757 if (uniques.size() <= 0) {
758 TELEPHONY_LOGI("SetEmergencyCallList eccList has exit");
759 return TELEPHONY_ERR_SUCCESS;
760 }
761 TELEPHONY_LOGI("SetEmergencyCallList refresh size %{public}zu", uniques.size());
762 for (auto ecc : uniques) {
763 allEccList_[slotId].push_back(ecc);
764 }
765 return configRequest_.SetEmergencyCallListRequest(slotId, uniques);
766 }
767
IsNeedUpdateEccListWhenSimStateChanged(int32_t slotId)768 bool CellularCallConfig::IsNeedUpdateEccListWhenSimStateChanged(int32_t slotId)
769 {
770 SimState simState = SimState::SIM_STATE_UNKNOWN;
771 CoreManagerInner::GetInstance().GetSimState(slotId, simState);
772 int32_t simStateForEcc;
773 switch (simState) {
774 case SimState::SIM_STATE_READY:
775 case SimState::SIM_STATE_LOADED: {
776 simStateForEcc = SIM_PRESENT;
777 break;
778 }
779 default: {
780 simStateForEcc = SIM_ABSENT;
781 break;
782 }
783 }
784 bool result = (simState_[slotId] != simStateForEcc);
785 simState_[slotId] = simStateForEcc;
786 return result;
787 }
788
UpdateEmergencyCallFromRadio(int32_t slotId,const EmergencyInfoList & eccList)789 void CellularCallConfig::UpdateEmergencyCallFromRadio(int32_t slotId, const EmergencyInfoList &eccList)
790 {
791 TELEPHONY_LOGI("UpdateEmergencyCallFromRadio %{publid}d size %{public}d", slotId, eccList.callSize);
792 eccListRadioMap_[slotId] = std::vector<EmergencyCall>();
793 for (auto ecc : eccList.calls) {
794 TELEPHONY_LOGI("UpdateEmergencyCallFromRadio , data: eccNum %{public}s mcc %{public}s", ecc.eccNum.c_str(),
795 ecc.mcc.c_str());
796 eccListRadioMap_[slotId].push_back(BuildEmergencyCall(slotId, ecc));
797 }
798 MergeEccCallList(slotId);
799 }
800
GetEccCallList(int32_t slotId)801 std::vector<EmergencyCall> CellularCallConfig::GetEccCallList(int32_t slotId)
802 {
803 TELEPHONY_LOGD("GetEccCallList start %{publiic}d", slotId);
804 std::lock_guard<std::mutex> lock(mutex_);
805 TELEPHONY_LOGD("GetEccCallList size %{publiic}zu", allEccList_[slotId].size());
806 for (auto ecc : allEccList_[slotId]) {
807 TELEPHONY_LOGI("GetEccCallList, data: eccNum %{public}s mcc %{public}s", ecc.eccNum.c_str(), ecc.mcc.c_str());
808 }
809 return allEccList_[slotId];
810 }
811
BooleanToImsSwitchValue(bool value)812 int32_t CellularCallConfig::BooleanToImsSwitchValue(bool value)
813 {
814 return value ? IMS_SWITCH_VALUE_ENABLED : IMS_SWITCH_VALUE_DISABLED;
815 }
816
GetImsSwitchOnByDefaultConfig(int32_t slotId)817 bool CellularCallConfig::GetImsSwitchOnByDefaultConfig(int32_t slotId)
818 {
819 if (!IsValidSlotId(slotId)) {
820 TELEPHONY_LOGE("invalid slot id");
821 return true;
822 }
823 return imsSwitchOnByDefault_[slotId];
824 }
825
GethideImsSwitchConfig(int32_t slotId)826 bool CellularCallConfig::GethideImsSwitchConfig(int32_t slotId)
827 {
828 if (!IsValidSlotId(slotId)) {
829 TELEPHONY_LOGE("invalid slot id");
830 return false;
831 }
832 return hideImsSwitch_[slotId];
833 }
834
GetvolteSupportedConfig(int32_t slotId)835 bool CellularCallConfig::GetvolteSupportedConfig(int32_t slotId)
836 {
837 if (!IsValidSlotId(slotId)) {
838 TELEPHONY_LOGE("invalid slot id");
839 return false;
840 }
841 return volteSupported_[slotId];
842 }
843
GetNrModeSupportedListConfig(int32_t slotId)844 std::vector<int32_t> CellularCallConfig::GetNrModeSupportedListConfig(int32_t slotId)
845 {
846 if (!IsValidSlotId(slotId)) {
847 TELEPHONY_LOGE("invalid slot id");
848 return std::vector<int32_t> { CARRIER_NR_AVAILABILITY_NSA, CARRIER_NR_AVAILABILITY_SA };
849 }
850 return nrModeSupportedList_[slotId];
851 }
852
GetVolteProvisioningSupportedConfig(int32_t slotId)853 bool CellularCallConfig::GetVolteProvisioningSupportedConfig(int32_t slotId)
854 {
855 if (!IsValidSlotId(slotId)) {
856 TELEPHONY_LOGE("invalid slot id");
857 return false;
858 }
859 return volteProvisioningSupported_[slotId];
860 }
861
GetSsOverUtSupportedConfig(int32_t slotId)862 bool CellularCallConfig::GetSsOverUtSupportedConfig(int32_t slotId)
863 {
864 if (!IsValidSlotId(slotId)) {
865 TELEPHONY_LOGE("invalid slot id");
866 return false;
867 }
868 return ssOverUtSupported_[slotId];
869 }
870
GetImsGbaRequiredConfig(int32_t slotId)871 bool CellularCallConfig::GetImsGbaRequiredConfig(int32_t slotId)
872 {
873 if (!IsValidSlotId(slotId)) {
874 TELEPHONY_LOGE("invalid slot id");
875 return false;
876 }
877 return imsGbaRequired_[slotId];
878 }
879
GetUtProvisioningSupportedConfig(int32_t slotId)880 bool CellularCallConfig::GetUtProvisioningSupportedConfig(int32_t slotId)
881 {
882 if (!IsValidSlotId(slotId)) {
883 TELEPHONY_LOGE("invalid slot id");
884 return false;
885 }
886 return utProvisioningSupported_[slotId];
887 }
888
GetImsPreferForEmergencyConfig(int32_t slotId)889 bool CellularCallConfig::GetImsPreferForEmergencyConfig(int32_t slotId)
890 {
891 if (!IsValidSlotId(slotId)) {
892 TELEPHONY_LOGE("invalid slot id");
893 return true;
894 }
895 return imsPreferForEmergency_[slotId];
896 }
897
GetCallWaitingServiceClassConfig(int32_t slotId)898 std::int32_t CellularCallConfig::GetCallWaitingServiceClassConfig(int32_t slotId)
899 {
900 if (!IsValidSlotId(slotId)) {
901 TELEPHONY_LOGE("invalid slot id");
902 return 1;
903 }
904 return callWaitingServiceClass_[slotId];
905 }
906
GetImsCallDisconnectResoninfoMappingConfig(int32_t slotId)907 std::vector<std::string> CellularCallConfig::GetImsCallDisconnectResoninfoMappingConfig(int32_t slotId)
908 {
909 std::lock_guard<std::mutex> lock(operatorMutex_);
910 if (!IsValidSlotId(slotId)) {
911 TELEPHONY_LOGE("invalid slot id");
912 return std::vector<std::string> {};
913 }
914 return imsCallDisconnectResoninfoMapping_[slotId];
915 }
916
GetForceVolteSwitchOnConfig(int32_t slotId)917 bool CellularCallConfig::GetForceVolteSwitchOnConfig(int32_t slotId)
918 {
919 if (!IsValidSlotId(slotId)) {
920 TELEPHONY_LOGE("invalid slot id");
921 return false;
922 }
923 return forceVolteSwitchOn_[slotId];
924 }
925
IsValidSlotId(int32_t slotId)926 bool CellularCallConfig::IsValidSlotId(int32_t slotId)
927 {
928 int32_t count = SIM_SLOT_COUNT;
929 if ((slotId >= DEFAULT_SIM_SLOT_ID) && (slotId < count)) {
930 return true;
931 }
932
933 TELEPHONY_LOGE("SlotId is InValid = %{public}d", slotId);
934 return false;
935 }
936
SetReadyToCall(int32_t slotId,bool isReadyToCall)937 void CellularCallConfig::SetReadyToCall(int32_t slotId, bool isReadyToCall)
938 {
939 if (!IsValidSlotId(slotId)) {
940 TELEPHONY_LOGE("invalid slot id");
941 return;
942 }
943 readyToCall_[slotId] = isReadyToCall;
944 }
945
IsReadyToCall(int32_t slotId)946 bool CellularCallConfig::IsReadyToCall(int32_t slotId)
947 {
948 if (!IsValidSlotId(slotId)) {
949 TELEPHONY_LOGE("invalid slot id");
950 return false;
951 }
952 return readyToCall_[slotId];
953 }
954 } // namespace Telephony
955 } // namespace OHOS
956