1 /*
2 * Copyright (C) 2021 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 "icc_file.h"
17
18 #include "core_manager_inner.h"
19 #include "if_system_ability_manager.h"
20 #include "inner_event.h"
21 #include "iservice_registry.h"
22 #include "radio_event.h"
23 #include "system_ability_definition.h"
24 #include "telephony_ext_wrapper.h"
25 #include "tel_event_handler.h"
26 #include "telephony_state_registry_client.h"
27
28 using namespace std;
29 using namespace OHOS::AppExecFwk;
30 using namespace OHOS::EventFwk;
31
32 namespace OHOS {
33 namespace Telephony {
34 std::unique_ptr<ObserverHandler> IccFile::filesFetchedObser_ = nullptr;
IccFile(const std::string & name,std::shared_ptr<SimStateManager> simStateManager)35 IccFile::IccFile(const std::string &name, std::shared_ptr<SimStateManager> simStateManager)
36 : TelEventHandler(name), stateManager_(simStateManager)
37 {
38 if (stateManager_ == nullptr) {
39 TELEPHONY_LOGE("IccFile::IccFile set NULL SIMStateManager!!");
40 }
41 if (filesFetchedObser_ == nullptr) {
42 filesFetchedObser_ = std::make_unique<ObserverHandler>();
43 }
44 if (filesFetchedObser_ == nullptr) {
45 TELEPHONY_LOGE("IccFile::IccFile filesFetchedObser_ create nullptr.");
46 return;
47 }
48
49 lockedFilesFetchedObser_ = std::make_unique<ObserverHandler>();
50 if (lockedFilesFetchedObser_ == nullptr) {
51 TELEPHONY_LOGE("IccFile::IccFile lockedFilesFetchedObser_ create nullptr.");
52 return;
53 }
54 networkLockedFilesFetchedObser_ = std::make_unique<ObserverHandler>();
55 if (networkLockedFilesFetchedObser_ == nullptr) {
56 TELEPHONY_LOGE("IccFile::IccFile networkLockedFilesFetchedObser_ create nullptr.");
57 return;
58 }
59 imsiReadyObser_ = std::make_unique<ObserverHandler>();
60 if (imsiReadyObser_ == nullptr) {
61 TELEPHONY_LOGE("IccFile::IccFile imsiReadyObser_ create nullptr.");
62 return;
63 }
64 recordsEventsObser_ = std::make_unique<ObserverHandler>();
65 if (recordsEventsObser_ == nullptr) {
66 TELEPHONY_LOGE("IccFile::IccFile recordsEventsObser_ create nullptr.");
67 return;
68 }
69 networkSelectionModeAutomaticObser_ = std::make_unique<ObserverHandler>();
70 if (networkSelectionModeAutomaticObser_ == nullptr) {
71 TELEPHONY_LOGE("IccFile::IccFile networkSelectionModeAutomaticObser_ create nullptr.");
72 return;
73 }
74 spnUpdatedObser_ = std::make_unique<ObserverHandler>();
75 if (spnUpdatedObser_ == nullptr) {
76 TELEPHONY_LOGE("IccFile::IccFile spnUpdatedObser_ create nullptr.");
77 return;
78 }
79 recordsOverrideObser_ = std::make_unique<ObserverHandler>();
80 if (recordsOverrideObser_ == nullptr) {
81 TELEPHONY_LOGE("IccFile::IccFile recordsOverrideObser_ create nullptr.");
82 return;
83 }
84 TELEPHONY_LOGI("simmgr IccFile::IccFile finish");
85 }
86
Init()87 void IccFile::Init()
88 {
89 if (stateManager_ != nullptr) {
90 stateManager_->RegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_READY);
91 stateManager_->RegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_LOCKED);
92 stateManager_->RegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_SIMLOCK);
93 }
94 }
95
StartLoad()96 void IccFile::StartLoad()
97 {
98 TELEPHONY_LOGI("IccFile::StarLoad start");
99 }
100
SetId(int id)101 void IccFile::SetId(int id)
102 {
103 slotId_ = id;
104 TELEPHONY_LOGI("IccFile::SetId, slotId %{public}d.", id);
105 voiceMailConfig_ = std::make_shared<VoiceMailConstants>(id);
106 }
107
GetIsVoiceMailFixed()108 bool IccFile::GetIsVoiceMailFixed()
109 {
110 return isVoiceMailFixed_;
111 }
112
SetVoiceMailByOperator(std::string spn)113 void IccFile::SetVoiceMailByOperator(std::string spn)
114 {
115 if (voiceMailConfig_ == nullptr) {
116 TELEPHONY_LOGE("IccFile::SetVoiceMailByOperator, voiceMailConfig_ is null.");
117 return;
118 }
119 if (voiceMailConfig_->ContainsCarrier(spn)) {
120 std::unique_lock<std::shared_mutex> lock(voiceMailMutex_);
121 isVoiceMailFixed_ = voiceMailConfig_->GetVoiceMailFixed(spn);
122 voiceMailNum_ = voiceMailConfig_->GetVoiceMailNumber(spn);
123 voiceMailTag_ = voiceMailConfig_->GetVoiceMailTag(spn);
124 } else {
125 TELEPHONY_LOGI("IccFile::SetVoiceMailByOperator, ContainsCarrier fail.");
126 std::unique_lock<std::shared_mutex> lock(voiceMailMutex_);
127 isVoiceMailFixed_ = false;
128 }
129 }
130
ObtainIMSI()131 std::string IccFile::ObtainIMSI()
132 {
133 if (imsi_.empty()) {
134 TELEPHONY_LOGI("IccFile::ObtainIMSI is null:");
135 }
136 return imsi_;
137 }
138
UpdateImsi(std::string imsi)139 void IccFile::UpdateImsi(std::string imsi)
140 {
141 imsi_ = imsi;
142 }
143
ObtainIccId()144 std::string IccFile::ObtainIccId()
145 {
146 return iccId_;
147 }
148
ObtainDecIccId()149 std::string IccFile::ObtainDecIccId()
150 {
151 return decIccId_;
152 }
153
ObtainGid1()154 std::string IccFile::ObtainGid1()
155 {
156 return gid1_;
157 }
158
ObtainGid2()159 std::string IccFile::ObtainGid2()
160 {
161 return gid2_;
162 }
163
ObtainMsisdnNumber()164 std::string IccFile::ObtainMsisdnNumber()
165 {
166 return msisdn_;
167 }
168
LoadedOrNot()169 bool IccFile::LoadedOrNot()
170 {
171 return loaded_;
172 }
173
UpdateLoaded(bool loaded)174 void IccFile::UpdateLoaded(bool loaded)
175 {
176 loaded_ = loaded;
177 }
178
ObtainSimOperator()179 std::string IccFile::ObtainSimOperator()
180 {
181 return operatorNumeric_;
182 }
183
ObtainIsoCountryCode()184 std::string IccFile::ObtainIsoCountryCode()
185 {
186 return "";
187 }
188
ObtainCallForwardStatus()189 int IccFile::ObtainCallForwardStatus()
190 {
191 return ICC_CALL_FORWARD_TYPE_UNKNOWN;
192 }
193
UpdateMsisdnNumber(const std::string & alphaTag,const std::string & number)194 bool IccFile::UpdateMsisdnNumber(const std::string &alphaTag, const std::string &number)
195 {
196 return false;
197 }
198
ObtainFilesFetched()199 bool IccFile::ObtainFilesFetched()
200 {
201 return (fileToGet_ == 0) && fileQueried_;
202 }
203
LockQueriedOrNot()204 bool IccFile::LockQueriedOrNot()
205 {
206 return (fileToGet_ == 0) && lockQueried_;
207 }
208
ObtainDiallingNumberInfo()209 std::string IccFile::ObtainDiallingNumberInfo()
210 {
211 return "";
212 }
213
ObtainNAI()214 std::string IccFile::ObtainNAI()
215 {
216 return "";
217 }
218
ObtainHomeNameOfPnn()219 std::string IccFile::ObtainHomeNameOfPnn()
220 {
221 return pnnHomeName_;
222 }
223
ObtainMsisdnAlphaStatus()224 std::string IccFile::ObtainMsisdnAlphaStatus()
225 {
226 return msisdnTag_;
227 }
228
ObtainVoiceMailCount()229 int32_t IccFile::ObtainVoiceMailCount()
230 {
231 return voiceMailCount_;
232 }
233
ObtainSPN()234 std::string IccFile::ObtainSPN()
235 {
236 return spn_;
237 }
238
ObtainEons(const std::string & plmn,int32_t lac,bool longNameRequired)239 std::string IccFile::ObtainEons(const std::string &plmn, int32_t lac, bool longNameRequired)
240 {
241 std::vector<std::shared_ptr<OperatorPlmnInfo>> oplFiles = oplFiles_;
242 sptr<NetworkState> networkState = nullptr;
243 CoreManagerInner::GetInstance().GetNetworkStatus(slotId_, networkState);
244 if (networkState != nullptr && !(opl5gFiles_.empty())) {
245 NrState nrState = networkState->GetNrState();
246 if (nrState == NrState::NR_NSA_STATE_SA_ATTACHED) {
247 oplFiles = opl5gFiles_;
248 }
249 }
250 bool roaming = (plmn.compare(operatorNumeric_) == 0 ? false : true);
251 TELEPHONY_LOGI("ObtainEons roaming:%{public}d", roaming);
252 if (plmn.empty() || pnnFiles_.empty() || (oplFiles.empty() && roaming)) {
253 TELEPHONY_LOGE("ObtainEons is empty");
254 return "";
255 }
256 int pnnIndex = 1;
257 for (std::shared_ptr<OperatorPlmnInfo> opl : oplFiles) {
258 if (opl == nullptr) {
259 continue;
260 }
261 pnnIndex = -1;
262 TELEPHONY_LOGD("ObtainEons plmn:%{public}s, opl->plmnNumeric:%{public}s, lac:%{public}d, "
263 "opl->lacStart:%{public}d, opl->lacEnd:%{public}d, opl->pnnRecordId:%{public}d",
264 plmn.c_str(), opl->plmnNumeric.c_str(), lac, opl->lacStart, opl->lacEnd, opl->pnnRecordId);
265 if (plmn.compare(opl->plmnNumeric) == 0 &&
266 ((opl->lacStart == 0 && opl->lacEnd == 0xfffe) || (opl->lacStart <= lac && opl->lacEnd >= lac))) {
267 pnnIndex = opl->pnnRecordId;
268 break;
269 }
270 }
271 std::string eons = "";
272 if (pnnIndex >= 1 && pnnIndex <= static_cast<int>(pnnFiles_.size())) {
273 TELEPHONY_LOGI("ObtainEons longNameRequired:%{public}d, longName:%{public}s, shortName:%{public}s,",
274 longNameRequired, pnnFiles_.at(pnnIndex - 1)->longName.c_str(),
275 pnnFiles_.at(pnnIndex - 1)->shortName.c_str());
276 if (longNameRequired) {
277 eons = pnnFiles_.at(pnnIndex - 1)->longName;
278 } else {
279 eons = pnnFiles_.at(pnnIndex - 1)->shortName;
280 }
281 }
282 return eons;
283 }
284
ObtainVoiceMailInfo()285 std::string IccFile::ObtainVoiceMailInfo()
286 {
287 return voiceMailTag_;
288 }
289
ObtainIccLanguage()290 std::string IccFile::ObtainIccLanguage()
291 {
292 return iccLanguage_;
293 }
294
ObtainUsimFunctionHandle()295 std::shared_ptr<UsimFunctionHandle> IccFile::ObtainUsimFunctionHandle()
296 {
297 return std::make_shared<UsimFunctionHandle>(nullptr, 0);
298 }
299
ObtainSpNameFromEfSpn()300 std::string IccFile::ObtainSpNameFromEfSpn()
301 {
302 return "";
303 }
304
ObtainLengthOfMnc()305 int IccFile::ObtainLengthOfMnc()
306 {
307 return lengthOfMnc_;
308 }
309
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)310 void IccFile::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
311 {
312 if (event == nullptr) {
313 TELEPHONY_LOGE("event is nullptr!");
314 return;
315 }
316 auto id = event->GetInnerEventId();
317 bool result = false;
318 TELEPHONY_LOGD("IccFile::ProcessEvent id %{public}d", id);
319 switch (id) {
320 case MSG_SIM_OBTAIN_ICC_FILE_DONE:
321 result = ProcessIccFileObtained(event);
322 ProcessFileLoaded(result);
323 break;
324 case MSG_ICC_REFRESH:
325 ProcessIccRefresh(MSG_ID_DEFAULT);
326 break;
327 default:
328 break;
329 }
330 }
331
LoadVoiceMail()332 void IccFile::LoadVoiceMail()
333 {
334 if (voiceMailConfig_ == nullptr) {
335 TELEPHONY_LOGE("IccFile::LoadVoiceMail, voiceMailConfig_ is null.");
336 return;
337 }
338 voiceMailConfig_->ResetVoiceMailLoadedFlag();
339 std::string operatorNumeric = ObtainSimOperator();
340 SetVoiceMailByOperator(operatorNumeric);
341 }
342
RegisterImsiLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler)343 void IccFile::RegisterImsiLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler)
344 {
345 int eventCode = RadioEvent::RADIO_IMSI_LOADED_READY;
346 if (imsiReadyObser_ != nullptr) {
347 imsiReadyObser_->RegObserver(eventCode, eventHandler);
348 }
349 if (!ObtainIMSI().empty()) {
350 if (eventHandler != nullptr) {
351 TelEventHandler::SendTelEvent(eventHandler, RadioEvent::RADIO_IMSI_LOADED_READY);
352 }
353 }
354 }
355
UnregisterImsiLoaded(const std::shared_ptr<AppExecFwk::EventHandler> & handler)356 void IccFile::UnregisterImsiLoaded(const std::shared_ptr<AppExecFwk::EventHandler> &handler)
357 {
358 if (imsiReadyObser_ != nullptr) {
359 imsiReadyObser_->Remove(RadioEvent::RADIO_IMSI_LOADED_READY, handler);
360 }
361 }
362
RegisterAllFilesLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler)363 void IccFile::RegisterAllFilesLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler)
364 {
365 int eventCode = RadioEvent::RADIO_SIM_RECORDS_LOADED;
366 if (filesFetchedObser_ != nullptr) {
367 filesFetchedObser_->RegObserver(eventCode, eventHandler);
368 }
369 TELEPHONY_LOGD("IccFile::RegisterAllFilesLoaded: registerd");
370 if (ObtainFilesFetched()) {
371 TELEPHONY_LOGI("IccFile::RegisterAllFilesLoaded: notify");
372 if (eventHandler != nullptr) {
373 TelEventHandler::SendTelEvent(eventHandler, RadioEvent::RADIO_SIM_RECORDS_LOADED, slotId_, 0);
374 }
375 PublishSimFileEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED,
376 static_cast<int32_t>(SimState::SIM_STATE_LOADED), "");
377 }
378 }
379
UnregisterAllFilesLoaded(const std::shared_ptr<AppExecFwk::EventHandler> & handler)380 void IccFile::UnregisterAllFilesLoaded(const std::shared_ptr<AppExecFwk::EventHandler> &handler)
381 {
382 if (filesFetchedObser_ != nullptr) {
383 filesFetchedObser_->Remove(RadioEvent::RADIO_SIM_RECORDS_LOADED, handler);
384 }
385 }
386
RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> & handler,int what)387 void IccFile::RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what)
388 {
389 switch (what) {
390 case RadioEvent::RADIO_SIM_RECORDS_LOADED:
391 RegisterAllFilesLoaded(handler);
392 break;
393 case RadioEvent::RADIO_IMSI_LOADED_READY:
394 RegisterImsiLoaded(handler);
395 break;
396 default:
397 TELEPHONY_LOGI("RegisterCoreNotify default");
398 }
399 }
400
UnRegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> & handler,int what)401 void IccFile::UnRegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what)
402 {
403 switch (what) {
404 case RadioEvent::RADIO_SIM_RECORDS_LOADED:
405 UnregisterAllFilesLoaded(handler);
406 break;
407 case RadioEvent::RADIO_IMSI_LOADED_READY:
408 UnregisterImsiLoaded(handler);
409 break;
410 default:
411 TELEPHONY_LOGI("RegisterCoreNotify default");
412 }
413 }
414
UpdateSPN(const std::string spn)415 void IccFile::UpdateSPN(const std::string spn)
416 {
417 if (spn_ != spn) {
418 spnUpdatedObser_->NotifyObserver(MSG_SIM_SPN_UPDATED);
419 spn_ = spn;
420 }
421 }
422
BuildCallerInfo(int eventId)423 AppExecFwk::InnerEvent::Pointer IccFile::BuildCallerInfo(int eventId)
424 {
425 std::unique_ptr<FileToControllerMsg> object = std::make_unique<FileToControllerMsg>();
426 int eventParam = 0;
427 AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(eventId, object, eventParam);
428 if (event == nullptr) {
429 TELEPHONY_LOGE("event is nullptr!");
430 return AppExecFwk::InnerEvent::Pointer(nullptr, nullptr);
431 }
432 event->SetOwner(shared_from_this());
433 return event;
434 }
435
BuildCallerInfo(int eventId,int arg1,int arg2)436 AppExecFwk::InnerEvent::Pointer IccFile::BuildCallerInfo(int eventId, int arg1, int arg2)
437 {
438 std::unique_ptr<FileToControllerMsg> object = std::make_unique<FileToControllerMsg>();
439 object->arg1 = arg1;
440 object->arg2 = arg2;
441 int eventParam = 0;
442 AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(eventId, object, eventParam);
443 if (event == nullptr) {
444 TELEPHONY_LOGE("event is nullptr!");
445 return AppExecFwk::InnerEvent::Pointer(nullptr, nullptr);
446 }
447 event->SetOwner(shared_from_this());
448 return event;
449 }
450
BuildCallerInfo(int eventId,std::shared_ptr<void> loader)451 AppExecFwk::InnerEvent::Pointer IccFile::BuildCallerInfo(int eventId, std::shared_ptr<void> loader)
452 {
453 std::unique_ptr<FileToControllerMsg> object = std::make_unique<FileToControllerMsg>();
454 object->iccLoader = loader;
455 int eventParam = 0;
456 AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(eventId, object, eventParam);
457 if (event == nullptr) {
458 TELEPHONY_LOGE("event is nullptr!");
459 return AppExecFwk::InnerEvent::Pointer(nullptr, nullptr);
460 }
461 event->SetOwner(shared_from_this());
462 return event;
463 }
464
PublishSimFileEvent(const std::string & event,int eventCode,const std::string & eventData)465 bool IccFile::PublishSimFileEvent(const std::string &event, int eventCode, const std::string &eventData)
466 {
467 Want want;
468 want.SetAction(event);
469 CommonEventData data;
470 data.SetWant(want);
471 data.SetCode(eventCode);
472 data.SetData(eventData);
473 CommonEventPublishInfo publishInfo;
474 publishInfo.SetOrdered(false);
475 bool publishResult = CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
476 TELEPHONY_LOGI("IccFile::PublishSimEvent result : %{public}d", publishResult);
477 return publishResult;
478 }
479
ProcessIccFileObtained(const AppExecFwk::InnerEvent::Pointer & event)480 bool IccFile::ProcessIccFileObtained(const AppExecFwk::InnerEvent::Pointer &event)
481 {
482 bool isFileProcessResponse = true;
483 std::shared_ptr<ControllerToFileMsg> fd = event->GetSharedObject<ControllerToFileMsg>();
484 std::shared_ptr<void> baseLoad = fd->iccLoader;
485 if (baseLoad != nullptr) {
486 std::shared_ptr<IccFileLoaded> destLoad = std::static_pointer_cast<IccFileLoaded>(baseLoad);
487 destLoad->ProcessParseFile(event);
488 TELEPHONY_LOGI("ProcessIccFileObtained item %{public}s", destLoad->ObtainElementaryFileName().c_str());
489 } else {
490 isFileProcessResponse = false;
491 TELEPHONY_LOGE("IccFile::ProcessIccFileObtained null base ponter");
492 }
493 return isFileProcessResponse;
494 }
495
UpdateIccLanguage(const std::string & langLi,const std::string & langPl)496 void IccFile::UpdateIccLanguage(const std::string &langLi, const std::string &langPl)
497 {
498 iccLanguage_ = ObtainValidLanguage(langLi);
499 if (iccLanguage_.empty()) {
500 iccLanguage_ = ObtainValidLanguage(langPl);
501 }
502 TELEPHONY_LOGI("IccFile::UpdateIccLanguage end is %{public}s", iccLanguage_.c_str());
503 }
504
ObtainValidLanguage(const std::string & langData)505 std::string IccFile::ObtainValidLanguage(const std::string &langData)
506 {
507 if (langData.empty()) {
508 TELEPHONY_LOGE("langData null data!!");
509 return "";
510 }
511 int langDataLen = 0;
512 std::shared_ptr<unsigned char> ucc = SIMUtils::HexStringConvertToBytes(langData, langDataLen);
513 if (ucc == nullptr) {
514 TELEPHONY_LOGE("ucc is nullptr!!");
515 return "";
516 }
517 unsigned char *data = ucc.get();
518
519 if (data == nullptr) {
520 TELEPHONY_LOGE("data is nullptr!!");
521 return "";
522 }
523
524 int dataLen = static_cast<int>(strlen(reinterpret_cast<char *>(data)));
525 TELEPHONY_LOGI("ObtainValidLanguage all is %{public}s---%{public}d, dataLen:%{public}d",
526 data, langDataLen, dataLen);
527 if (langDataLen > dataLen) {
528 langDataLen = dataLen;
529 }
530 for (int i = 0; (i + 1) < langDataLen; i += DATA_STEP) {
531 std::string langName((char *)data, i, DATA_STEP);
532 TELEPHONY_LOGI("ObtainValidLanguage item is %{public}d--%{public}s", i, langName.c_str());
533 if (!langName.empty()) {
534 return langName;
535 }
536 }
537 return "";
538 }
539
SwapPairsForIccId(std::string & iccId)540 void IccFile::SwapPairsForIccId(std::string &iccId)
541 {
542 std::string result = "";
543 for (size_t i = 0; i < iccId.length() - 1; i += DATA_STEP) {
544 if (iccId[i + 1] > '9') {
545 break;
546 }
547 result += iccId[i + 1];
548 if (iccId[i] == 'F') {
549 continue;
550 }
551 if (iccId[i] > '9') {
552 break;
553 }
554 result += iccId[i];
555 }
556 iccId = result;
557 }
558
GetFullIccid(std::string & iccId)559 void IccFile::GetFullIccid(std::string &iccId)
560 {
561 std::string result = "";
562 for (size_t i = 0; i < iccId.length() - 1; i += DATA_STEP) {
563 result += iccId[i + 1];
564 result += iccId[i];
565 }
566 iccId = result;
567 }
568
~IccFile()569 IccFile::~IccFile() {}
570
SetRilAndFileController(const std::shared_ptr<Telephony::ITelRilManager> & ril,const std::shared_ptr<IccFileController> & file,const std::shared_ptr<IccDiallingNumbersHandler> & handler)571 void IccFile::SetRilAndFileController(const std::shared_ptr<Telephony::ITelRilManager> &ril,
572 const std::shared_ptr<IccFileController> &file, const std::shared_ptr<IccDiallingNumbersHandler> &handler)
573 {
574 telRilManager_ = ril;
575 if (telRilManager_ == nullptr) {
576 TELEPHONY_LOGE("IccFile set NULL TelRilManager!!");
577 }
578
579 fileController_ = file;
580 if (fileController_ == nullptr) {
581 TELEPHONY_LOGE("IccFile set NULL File Controller!!");
582 }
583 diallingNumberHandler_ = handler;
584 if (fileController_ == nullptr) {
585 TELEPHONY_LOGE("IccFile set NULL File Controller!!");
586 }
587 }
588
CreateDiallingNumberPointer(int eventid,int efId,int index,std::shared_ptr<void> pobj)589 AppExecFwk::InnerEvent::Pointer IccFile::CreateDiallingNumberPointer(
590 int eventid, int efId, int index, std::shared_ptr<void> pobj)
591 {
592 std::unique_ptr<DiallingNumbersHandleHolder> holder = std::make_unique<DiallingNumbersHandleHolder>();
593 holder->fileID = efId;
594 holder->index = index;
595 holder->diallingNumber = pobj;
596 int eventParam = 0;
597 AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(eventid, holder, eventParam);
598 if (event == nullptr) {
599 TELEPHONY_LOGE("event is nullptr!");
600 return AppExecFwk::InnerEvent::Pointer(nullptr, nullptr);
601 }
602 event->SetOwner(shared_from_this());
603 return event;
604 }
605
606
NotifyRegistrySimState(CardType type,SimState state,LockReason reason)607 void IccFile::NotifyRegistrySimState(CardType type, SimState state, LockReason reason)
608 {
609 int32_t result =
610 DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateSimState(slotId_, type, state, reason);
611 TELEPHONY_LOGI("NotifyRegistrySimState msgId is %{public}d ret %{public}d", state, result);
612 }
613
HasSimCard()614 bool IccFile::HasSimCard()
615 {
616 return (stateManager_ != nullptr) ? stateManager_->HasSimCard() : false;
617 }
618
ResetVoiceMailVariable()619 void IccFile::ResetVoiceMailVariable()
620 {
621 std::unique_lock<std::shared_mutex> lock(voiceMailMutex_);
622 isVoiceMailFixed_ = false;
623 voiceMailNum_ = "";
624 voiceMailTag_ = "";
625 if (TELEPHONY_EXT_WRAPPER.resetVoiceMailManagerExt_ != nullptr) {
626 TELEPHONY_EXT_WRAPPER.resetVoiceMailManagerExt_(slotId_);
627 }
628 }
629
ClearData()630 void IccFile::ClearData()
631 {
632 imsi_ = "";
633 iccId_ = "";
634 decIccId_ = "";
635 UpdateSPN("");
636 UpdateLoaded(false);
637 operatorNumeric_ = "";
638 indexOfMailbox_ = 1;
639 msisdn_ = "";
640 gid1_ = "";
641 gid2_ = "";
642 msisdnTag_ = "";
643 fileQueried_ = false;
644 ResetVoiceMailVariable();
645 }
UnInit()646 void IccFile::UnInit()
647 {
648 if (stateManager_ != nullptr) {
649 stateManager_->UnRegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_READY);
650 stateManager_->UnRegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_LOCKED);
651 stateManager_->UnRegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_SIMLOCK);
652 }
653 ClearData();
654 }
655
SaveCountryCode()656 void IccFile::SaveCountryCode()
657 {
658 std::string countryCode = ObtainIsoCountryCode();
659 std::string key = COUNTRY_CODE_KEY + std::to_string(slotId_);
660 SetParameter(key.c_str(), countryCode.c_str());
661 }
662 } // namespace Telephony
663 } // namespace OHOS
664