• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "sim_manager.h"
17 
18 #include "core_service_errors.h"
19 #include "radio_event.h"
20 #include "telephony_errors.h"
21 
22 namespace OHOS {
23 namespace Telephony {
SimManager(std::shared_ptr<ITelRilManager> telRilManager)24 SimManager::SimManager(std::shared_ptr<ITelRilManager> telRilManager) : telRilManager_(telRilManager)
25 {
26     TELEPHONY_LOGI("SimManager::SimManager()");
27 }
28 
~SimManager()29 SimManager::~SimManager()
30 {
31     if (multiSimMonitor_ != nullptr) {
32         for (int32_t slotId = 0; slotId < slotCount_; slotId++) {
33             multiSimMonitor_->UnRegisterForIccLoaded(slotId);
34             multiSimMonitor_->UnRegisterForSimStateChanged(slotId);
35         }
36     }
37 }
38 
OnInit(int32_t slotCount)39 bool SimManager::OnInit(int32_t slotCount)
40 {
41     TELEPHONY_LOGI("SimManager OnInit, slotCount = %{public}d", slotCount);
42     slotCount_ = slotCount;
43     InitMultiSimObject();
44     InitSingleSimObject();
45     TELEPHONY_LOGI("SimManager OnInit success");
46     return true;
47 }
48 
InitMultiSimObject()49 void SimManager::InitMultiSimObject()
50 {
51     // Program memory
52     simStateManager_.resize(slotCount_);
53     simFileManager_.resize(slotCount_);
54     simSmsManager_.resize(slotCount_);
55     simAccountManager_.resize(slotCount_);
56     iccDiallingNumbersManager_.resize(slotCount_);
57     stkManager_.resize(slotCount_);
58     // Many card create
59     for (int32_t slotId = 0; slotId < slotCount_; slotId++) {
60         simStateManager_[slotId] = std::make_shared<SimStateManager>(telRilManager_);
61         if (simStateManager_[slotId] != nullptr) {
62             simStateManager_[slotId]->Init(slotId);
63         }
64         simFileManager_[slotId] = SimFileManager::CreateInstance(telRilManager_, simStateManager_[slotId]);
65         if (simFileManager_[slotId] != nullptr) {
66             simFileManager_[slotId]->Init(slotId);
67         }
68         simSmsManager_[slotId] = std::make_shared<SimSmsManager>(
69             telRilManager_, simFileManager_[slotId], simStateManager_[slotId]);
70         if (simSmsManager_[slotId] != nullptr) {
71             simSmsManager_[slotId]->Init(slotId);
72         }
73         simAccountManager_[slotId] = std::make_shared<SimAccountManager>(
74             telRilManager_, simStateManager_[slotId], simFileManager_[slotId]);
75         if (simAccountManager_[slotId] != nullptr) {
76             simAccountManager_[slotId]->Init(slotId);
77         }
78         iccDiallingNumbersManager_[slotId] =
79             IccDiallingNumbersManager::CreateInstance(simFileManager_[slotId], simStateManager_[slotId]);
80         if (iccDiallingNumbersManager_[slotId] != nullptr) {
81             iccDiallingNumbersManager_[slotId]->Init();
82         }
83         stkManager_[slotId] = std::make_shared<StkManager>(telRilManager_, simStateManager_[slotId]);
84         if (stkManager_[slotId] != nullptr) {
85             stkManager_[slotId]->Init(slotId);
86         }
87         if (simStateManager_[DEFAULT_SIM_SLOT_ID] != nullptr && slotId == DEFAULT_SIM_SLOT_ID) {
88             simStateManager_[DEFAULT_SIM_SLOT_ID]->RefreshSimState(DEFAULT_SIM_SLOT_ID);
89         }
90     }
91 }
92 
InitSingleSimObject()93 void SimManager::InitSingleSimObject()
94 {
95     controllerRunner_ = AppExecFwk::EventRunner::Create("MultiSimController");
96     if (controllerRunner_.get() == nullptr) {
97         TELEPHONY_LOGE("SimManager::InitSingleSimObject get controllerRunner_ failed");
98         return;
99     }
100     multiSimController_ = std::make_shared<MultiSimController>(
101         telRilManager_, simStateManager_, simFileManager_, controllerRunner_);
102     if (multiSimController_ == nullptr) {
103         TELEPHONY_LOGE("SimManager::InitSingleSimObject multiSimController init failed");
104         return;
105     }
106     multiSimController_->Init();
107 
108     monitorRunner_ = AppExecFwk::EventRunner::Create("MultiSimMonitor");
109     if (monitorRunner_.get() == nullptr) {
110         TELEPHONY_LOGE("get monitorRunner_ failed");
111         return;
112     }
113     multiSimMonitor_ = std::make_shared<MultiSimMonitor>(
114         monitorRunner_, multiSimController_, simStateManager_, simFileManager_);
115     if (multiSimMonitor_ == nullptr) {
116         TELEPHONY_LOGE("SimAccountManager:: multiSimMonitor is null");
117         return;
118     }
119     multiSimMonitor_->Init();
120     for (int32_t slotId = 0; slotId < slotCount_; slotId++) {
121         multiSimMonitor_->RegisterForIccLoaded(slotId);
122         multiSimMonitor_->RegisterForSimStateChanged(slotId);
123     }
124 }
125 
SetNetworkSearchManager(std::shared_ptr<INetworkSearch> networkSearchManager)126 void SimManager::SetNetworkSearchManager(std::shared_ptr<INetworkSearch> networkSearchManager)
127 {
128     TELEPHONY_LOGI("SimManager::SetNetworkSearchManager");
129     if (multiSimController_ == nullptr) {
130         TELEPHONY_LOGE("SimManager::SetNetworkSearchManager multiSimController_ is nullptr");
131         return;
132     }
133     multiSimController_->SetNetworkSearchManager(networkSearchManager);
134     return;
135 }
136 
HasSimCard(int32_t slotId,bool & hasSimCard)137 int32_t SimManager::HasSimCard(int32_t slotId, bool &hasSimCard)
138 {
139     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
140         TELEPHONY_LOGE("simStateManager is null!");
141         return TELEPHONY_ERR_LOCAL_PTR_NULL;
142     }
143     if (simStateManager_[slotId]->HasSimCard()) {
144         TELEPHONY_LOGE("HasSimCard is true!");
145         hasSimCard = true;
146         return TELEPHONY_ERR_SUCCESS;
147     }
148     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
149         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
150         return TELEPHONY_ERR_LOCAL_PTR_NULL;
151     }
152     if (multiSimController_->IsSimActivatable(slotId)) {
153         hasSimCard = true;
154     } else {
155         hasSimCard = false;
156     }
157     return TELEPHONY_ERR_SUCCESS;
158 }
159 
HasSimCardInner(int32_t slotId)160 bool SimManager::HasSimCardInner(int32_t slotId)
161 {
162     bool hasSimCard = false;
163     HasSimCard(slotId, hasSimCard);
164     return hasSimCard;
165 }
166 
GetSimState(int32_t slotId,SimState & simState)167 int32_t SimManager::GetSimState(int32_t slotId, SimState &simState)
168 {
169     if (!HasSimCardInner(slotId)) {
170         TELEPHONY_LOGE("GetSimState has no sim card!");
171         simState = SimState::SIM_STATE_NOT_PRESENT;
172         return TELEPHONY_ERR_SUCCESS;
173     }
174     simState = simStateManager_[slotId]->GetSimState();
175     return TELEPHONY_ERR_SUCCESS;
176 }
177 
GetCardType(int32_t slotId,CardType & cardType)178 int32_t SimManager::GetCardType(int32_t slotId, CardType &cardType)
179 {
180     if (!HasSimCardInner(slotId)) {
181         TELEPHONY_LOGE("GetCardType has no sim card!");
182         return TELEPHONY_ERR_NO_SIM_CARD;
183     }
184     cardType = simStateManager_[slotId]->GetCardType();
185     return TELEPHONY_ERR_SUCCESS;
186 }
187 
UnlockPin(int32_t slotId,const std::string & pin,LockStatusResponse & response)188 int32_t SimManager::UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response)
189 {
190     if (!HasSimCardInner(slotId)) {
191         TELEPHONY_LOGE("UnlockPin has no sim card!");
192         return TELEPHONY_ERR_NO_SIM_CARD;
193     }
194     return simStateManager_[slotId]->UnlockPin(slotId, pin, response);
195 }
196 
UnlockPuk(int32_t slotId,const std::string & newPin,const std::string & puk,LockStatusResponse & response)197 int32_t SimManager::UnlockPuk(
198     int32_t slotId, const std::string &newPin, const std::string &puk, LockStatusResponse &response)
199 {
200     if (!HasSimCardInner(slotId)) {
201         TELEPHONY_LOGE("UnlockPuk has no sim card!");
202         return TELEPHONY_ERR_NO_SIM_CARD;
203     }
204     return simStateManager_[slotId]->UnlockPuk(slotId, newPin, puk, response);
205 }
206 
AlterPin(int32_t slotId,const std::string & newPin,const std::string & oldPin,LockStatusResponse & response)207 int32_t SimManager::AlterPin(
208     int32_t slotId, const std::string &newPin, const std::string &oldPin, LockStatusResponse &response)
209 {
210     if (!HasSimCardInner(slotId)) {
211         TELEPHONY_LOGE("AlterPin has no sim card!");
212         return TELEPHONY_ERR_NO_SIM_CARD;
213     }
214     return simStateManager_[slotId]->AlterPin(slotId, newPin, oldPin, response);
215 }
216 
SetLockState(int32_t slotId,const LockInfo & options,LockStatusResponse & response)217 int32_t SimManager::SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response)
218 {
219     if (!HasSimCardInner(slotId)) {
220         TELEPHONY_LOGE("SetLockState has no sim card!");
221         return TELEPHONY_ERR_NO_SIM_CARD;
222     }
223     return simStateManager_[slotId]->SetLockState(slotId, options, response);
224 }
225 
GetLockState(int32_t slotId,LockType lockType,LockState & lockState)226 int32_t SimManager::GetLockState(int32_t slotId, LockType lockType, LockState &lockState)
227 {
228     if (!HasSimCardInner(slotId)) {
229         TELEPHONY_LOGE("GetLockState has no sim card!");
230         return TELEPHONY_ERR_NO_SIM_CARD;
231     }
232     return simStateManager_[slotId]->GetLockState(slotId, lockType, lockState);
233 }
234 
RefreshSimState(int32_t slotId)235 int32_t SimManager::RefreshSimState(int32_t slotId)
236 {
237     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
238         TELEPHONY_LOGE("simStateManager is null!");
239         return TELEPHONY_ERROR;
240     }
241     return simStateManager_[slotId]->RefreshSimState(slotId);
242 }
243 
UnlockPin2(int32_t slotId,const std::string & pin2,LockStatusResponse & response)244 int32_t SimManager::UnlockPin2(int32_t slotId, const std::string &pin2, LockStatusResponse &response)
245 {
246     if (!HasSimCardInner(slotId)) {
247         TELEPHONY_LOGE("UnlockPin2 has no sim card!");
248         return TELEPHONY_ERR_NO_SIM_CARD;
249     }
250     return simStateManager_[slotId]->UnlockPin2(slotId, pin2, response);
251 }
252 
UnlockPuk2(int32_t slotId,const std::string & newPin2,const std::string & puk2,LockStatusResponse & response)253 int32_t SimManager::UnlockPuk2(
254     int32_t slotId, const std::string &newPin2, const std::string &puk2, LockStatusResponse &response)
255 {
256     if (!HasSimCardInner(slotId)) {
257         TELEPHONY_LOGE("UnlockPuk2 has no sim card!");
258         return TELEPHONY_ERR_NO_SIM_CARD;
259     }
260     return simStateManager_[slotId]->UnlockPuk2(slotId, newPin2, puk2, response);
261 }
262 
AlterPin2(int32_t slotId,const std::string & newPin2,const std::string & oldPin2,LockStatusResponse & response)263 int32_t SimManager::AlterPin2(
264     int32_t slotId, const std::string &newPin2, const std::string &oldPin2, LockStatusResponse &response)
265 {
266     if (!HasSimCardInner(slotId)) {
267         TELEPHONY_LOGE("AlterPin2 has no sim card!");
268         return TELEPHONY_ERR_NO_SIM_CARD;
269     }
270     return simStateManager_[slotId]->AlterPin2(slotId, newPin2, oldPin2, response);
271 }
272 
UnlockSimLock(int32_t slotId,const PersoLockInfo & lockInfo,LockStatusResponse & response)273 int32_t SimManager::UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response)
274 {
275     if (!HasSimCardInner(slotId)) {
276         TELEPHONY_LOGE("UnlockSimLock has no sim card!");
277         return TELEPHONY_ERR_NO_SIM_CARD;
278     }
279     return simStateManager_[slotId]->UnlockSimLock(slotId, lockInfo, response);
280 }
281 
IsSimActive(int32_t slotId)282 bool SimManager::IsSimActive(int32_t slotId)
283 {
284     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
285         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
286         return false;
287     }
288     return multiSimController_->IsSimActive(slotId);
289 }
290 
SetActiveSim(int32_t slotId,int32_t enable)291 int32_t SimManager::SetActiveSim(int32_t slotId, int32_t enable)
292 {
293     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
294         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
295         return TELEPHONY_ERR_LOCAL_PTR_NULL;
296     }
297     return multiSimController_->SetActiveSim(slotId, enable);
298 }
299 
GetSimAccountInfo(int32_t slotId,IccAccountInfo & info)300 int32_t SimManager::GetSimAccountInfo(int32_t slotId, IccAccountInfo &info)
301 {
302     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
303         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
304         return TELEPHONY_ERR_LOCAL_PTR_NULL;
305     }
306     return multiSimController_->GetSimAccountInfo(slotId, info);
307 }
308 
SetDefaultVoiceSlotId(int32_t slotId)309 int32_t SimManager::SetDefaultVoiceSlotId(int32_t slotId)
310 {
311     if (!IsValidSlotIdForDefault(slotId)) {
312         TELEPHONY_LOGE("slotId is invalid for default.");
313         return TELEPHONY_ERR_SLOTID_INVALID;
314     }
315     if (multiSimController_ == nullptr) {
316         TELEPHONY_LOGE("multiSimController_ is nullptr.");
317         return TELEPHONY_ERR_LOCAL_PTR_NULL;
318     }
319     return multiSimController_->SetDefaultVoiceSlotId(slotId);
320 }
321 
SetDefaultSmsSlotId(int32_t slotId)322 int32_t SimManager::SetDefaultSmsSlotId(int32_t slotId)
323 {
324     if (!IsValidSlotIdForDefault(slotId)) {
325         TELEPHONY_LOGE("slotId is invalid for default.");
326         return TELEPHONY_ERR_SLOTID_INVALID;
327     }
328     if (multiSimController_ == nullptr) {
329         TELEPHONY_LOGE("multiSimController_ is nullptr.");
330         return TELEPHONY_ERR_LOCAL_PTR_NULL;
331     }
332     return multiSimController_->SetDefaultSmsSlotId(slotId);
333 }
334 
SetDefaultCellularDataSlotId(int32_t slotId)335 int32_t SimManager::SetDefaultCellularDataSlotId(int32_t slotId)
336 {
337     if (!IsValidSlotIdForDefault(slotId)) {
338         TELEPHONY_LOGE("slotId is invalid for default.");
339         return TELEPHONY_ERR_SLOTID_INVALID;
340     }
341     if (multiSimController_ == nullptr) {
342         TELEPHONY_LOGE("multiSimController_ is nullptr.");
343         return TELEPHONY_ERR_LOCAL_PTR_NULL;
344     }
345     int32_t ret = multiSimController_->SetDefaultCellularDataSlotId(slotId);
346     if (ret == TELEPHONY_ERR_SUCCESS && multiSimMonitor_ != nullptr) {
347         multiSimMonitor_->NotifySimAccountChanged();
348     }
349     return ret;
350 }
351 
SetPrimarySlotId(int32_t slotId)352 int32_t SimManager::SetPrimarySlotId(int32_t slotId)
353 {
354     if (!IsValidSlotId(slotId)) {
355         TELEPHONY_LOGE("slotId is invalid for default.");
356         return TELEPHONY_ERR_SLOTID_INVALID;
357     }
358     if (multiSimController_ == nullptr) {
359         TELEPHONY_LOGE("multiSimController_ is nullptr.");
360         return TELEPHONY_ERR_LOCAL_PTR_NULL;
361     }
362     return multiSimController_->SetPrimarySlotId(slotId);
363 }
364 
SetShowNumber(int32_t slotId,const std::u16string & number)365 int32_t SimManager::SetShowNumber(int32_t slotId, const std::u16string &number)
366 {
367     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
368         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
369         return TELEPHONY_ERR_LOCAL_PTR_NULL;
370     }
371     return multiSimController_->SetShowNumber(slotId, number);
372 }
373 
SetShowName(int32_t slotId,const std::u16string & name)374 int32_t SimManager::SetShowName(int32_t slotId, const std::u16string &name)
375 {
376     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
377         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
378         return TELEPHONY_ERR_LOCAL_PTR_NULL;
379     }
380     return multiSimController_->SetShowName(slotId, name);
381 }
382 
GetDefaultVoiceSlotId()383 int32_t SimManager::GetDefaultVoiceSlotId()
384 {
385     if (slotCount_ == std::atoi(DEFAULT_SLOT_COUNT)) {
386         TELEPHONY_LOGI("default slotId is 0 for single card version");
387         return DEFAULT_SIM_SLOT_ID;
388     }
389     if (multiSimController_ == nullptr) {
390         TELEPHONY_LOGE("multiSimController_ is nullptr");
391         return TELEPHONY_ERROR;
392     }
393     return multiSimController_->GetDefaultVoiceSlotId();
394 }
395 
GetDefaultSmsSlotId()396 int32_t SimManager::GetDefaultSmsSlotId()
397 {
398     if (slotCount_ == std::atoi(DEFAULT_SLOT_COUNT)) {
399         TELEPHONY_LOGI("default slotId is 0 for single card version");
400         return DEFAULT_SIM_SLOT_ID;
401     }
402     if (multiSimController_ == nullptr) {
403         TELEPHONY_LOGE("multiSimController_ is nullptr");
404         return TELEPHONY_ERROR;
405     }
406     return multiSimController_->GetDefaultSmsSlotId();
407 }
408 
GetDefaultCellularDataSlotId()409 int32_t SimManager::GetDefaultCellularDataSlotId()
410 {
411     if (slotCount_ == std::atoi(DEFAULT_SLOT_COUNT)) {
412         TELEPHONY_LOGI("default slotId is 0 for single card version");
413         return DEFAULT_SIM_SLOT_ID;
414     }
415     if (multiSimController_ == nullptr) {
416         TELEPHONY_LOGE("multiSimController_ is nullptr");
417         return TELEPHONY_ERROR;
418     }
419     return multiSimController_->GetDefaultCellularDataSlotId();
420 }
421 
GetPrimarySlotId(int32_t & slotId)422 int32_t SimManager::GetPrimarySlotId(int32_t &slotId)
423 {
424     if (slotCount_ == std::atoi(DEFAULT_SLOT_COUNT)) {
425         TELEPHONY_LOGI(" default slotId is 0 for single card version");
426         slotId = DEFAULT_SIM_SLOT_ID;
427         return TELEPHONY_ERR_SUCCESS;
428     }
429     if (multiSimController_ == nullptr) {
430         TELEPHONY_LOGE("multiSimController_ is nullptr");
431         return TELEPHONY_ERR_LOCAL_PTR_NULL;
432     }
433     slotId = multiSimController_->GetPrimarySlotId();
434     return TELEPHONY_ERR_SUCCESS;
435 }
436 
GetShowNumber(int32_t slotId,std::u16string & showNumber)437 int32_t SimManager::GetShowNumber(int32_t slotId, std::u16string &showNumber)
438 {
439     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
440         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
441         return TELEPHONY_ERR_LOCAL_PTR_NULL;
442     }
443     return multiSimController_->GetShowNumber(slotId, showNumber);
444 }
445 
GetShowName(int32_t slotId,std::u16string & showName)446 int32_t SimManager::GetShowName(int32_t slotId, std::u16string &showName)
447 {
448     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
449         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
450         return TELEPHONY_ERR_LOCAL_PTR_NULL;
451     }
452     return multiSimController_->GetShowName(slotId, showName);
453 }
454 
GetActiveSimAccountInfoList(std::vector<IccAccountInfo> & iccAccountInfoList)455 int32_t SimManager::GetActiveSimAccountInfoList(std::vector<IccAccountInfo> &iccAccountInfoList)
456 {
457     if (multiSimController_ == nullptr) {
458         TELEPHONY_LOGE("multiSimController_ is nullptr");
459         return TELEPHONY_ERR_LOCAL_PTR_NULL;
460     }
461     return multiSimController_->GetActiveSimAccountInfoList(iccAccountInfoList);
462 }
463 
GetSlotId(int32_t simId)464 int32_t SimManager::GetSlotId(int32_t simId)
465 {
466     if (multiSimController_ == nullptr) {
467         TELEPHONY_LOGE("multiSimController_ is nullptr");
468         return TELEPHONY_ERROR;
469     }
470     return multiSimController_->GetSlotId(simId);
471 }
472 
GetSimId(int32_t slotId)473 int32_t SimManager::GetSimId(int32_t slotId)
474 {
475     IccAccountInfo accountInfo;
476     if (GetSimAccountInfo(slotId, accountInfo) == TELEPHONY_ERR_SUCCESS) {
477         return accountInfo.simId;
478     }
479     TELEPHONY_LOGE("GetSimAccountInfo fail!");
480     return TELEPHONY_ERROR;
481 }
482 
GetOperatorConfigs(int32_t slotId,OperatorConfig & poc)483 int32_t SimManager::GetOperatorConfigs(int32_t slotId, OperatorConfig &poc)
484 {
485     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
486         TELEPHONY_LOGE("simAccountManager is null!");
487         return TELEPHONY_ERR_LOCAL_PTR_NULL;
488     }
489     return simAccountManager_[slotId]->GetOperatorConfigs(slotId, poc);
490 }
491 
HasOperatorPrivileges(const int32_t slotId,bool & hasOperatorPrivileges)492 int32_t SimManager::HasOperatorPrivileges(const int32_t slotId, bool &hasOperatorPrivileges)
493 {
494     TELEPHONY_LOGI("SimManager::HasOperatorPrivileges slotId:%{public}d", slotId);
495     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
496         TELEPHONY_LOGE("simAccountManager_ can not be null!");
497         return TELEPHONY_ERR_LOCAL_PTR_NULL;
498     }
499     return simAccountManager_[slotId]->HasOperatorPrivileges(slotId, hasOperatorPrivileges);
500 }
501 
SimAuthentication(int32_t slotId,const std::string & aid,const std::string & authData,SimAuthenticationResponse & response)502 int32_t SimManager::SimAuthentication(
503     int32_t slotId, const std::string &aid, const std::string &authData, SimAuthenticationResponse &response)
504 {
505     TELEPHONY_LOGI("SimManager::SimAuthentication slotId:%{public}d", slotId);
506     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
507         TELEPHONY_LOGE("simStateManager_ can not be null!");
508         return TELEPHONY_ERR_LOCAL_PTR_NULL;
509     }
510     return simStateManager_[slotId]->SimAuthentication(slotId, aid, authData, response);
511 }
512 
GetRadioProtocolTech(int32_t slotId)513 int32_t SimManager::GetRadioProtocolTech(int32_t slotId)
514 {
515     TELEPHONY_LOGI("SimManager::GetRadioProtocolTech slotId:%{public}d", slotId);
516     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
517         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
518         return static_cast<int32_t>(RadioProtocolTech::RADIO_PROTOCOL_TECH_UNKNOWN);
519     }
520     return multiSimController_->GetRadioProtocolTech(slotId);
521 }
522 
GetRadioProtocol(int32_t slotId)523 void SimManager::GetRadioProtocol(int32_t slotId)
524 {
525     TELEPHONY_LOGI("SimManager::GetRadioProtocol slotId:%{public}d", slotId);
526     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
527         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
528         return;
529     }
530     return multiSimController_->GetRadioProtocol(slotId);
531 }
532 
SendEnvelopeCmd(int32_t slotId,const std::string & cmd)533 int32_t SimManager::SendEnvelopeCmd(int32_t slotId, const std::string &cmd)
534 {
535     if ((!IsValidSlotId(slotId)) || (stkManager_[slotId] == nullptr)) {
536         TELEPHONY_LOGE("stkManager is null!");
537         return TELEPHONY_ERR_LOCAL_PTR_NULL;
538     }
539     if (!HasSimCardInner(slotId)) {
540         TELEPHONY_LOGE("SendEnvelopeCmd has no sim card!");
541         return TELEPHONY_ERR_NO_SIM_CARD;
542     }
543     return stkManager_[slotId]->SendEnvelopeCmd(slotId, cmd);
544 }
545 
SendTerminalResponseCmd(int32_t slotId,const std::string & cmd)546 int32_t SimManager::SendTerminalResponseCmd(int32_t slotId, const std::string &cmd)
547 {
548     if ((!IsValidSlotId(slotId)) || (stkManager_[slotId] == nullptr)) {
549         TELEPHONY_LOGE("stkManager is null!");
550         return TELEPHONY_ERR_LOCAL_PTR_NULL;
551     }
552     if (!HasSimCardInner(slotId)) {
553         TELEPHONY_LOGE("SendTerminalResponseCmd has no sim card!");
554         return TELEPHONY_ERR_NO_SIM_CARD;
555     }
556     return stkManager_[slotId]->SendTerminalResponseCmd(slotId, cmd);
557 }
558 
SendCallSetupRequestResult(int32_t slotId,bool accept)559 int32_t SimManager::SendCallSetupRequestResult(int32_t slotId, bool accept)
560 {
561     if (!IsValidSlotId(slotId)) {
562         TELEPHONY_LOGE("slotId is invalid!");
563         return TELEPHONY_ERR_SLOTID_INVALID;
564     }
565     if (stkManager_[slotId] == nullptr) {
566         TELEPHONY_LOGE("stkManager is null!");
567         return TELEPHONY_ERR_LOCAL_PTR_NULL;
568     }
569     if (!HasSimCardInner(slotId)) {
570         TELEPHONY_LOGE("SendCallSetupRequestResult has no sim card!");
571         return TELEPHONY_ERR_NO_SIM_CARD;
572     }
573     return stkManager_[slotId]->SendCallSetupRequestResult(slotId, accept);
574 }
575 
GetSimOperatorNumeric(int32_t slotId,std::u16string & operatorNumeric)576 int32_t SimManager::GetSimOperatorNumeric(int32_t slotId, std::u16string &operatorNumeric)
577 {
578     if (!HasSimCardInner(slotId)) {
579         TELEPHONY_LOGE("GetSimOperatorNumeric has no sim card!");
580         return TELEPHONY_ERR_NO_SIM_CARD;
581     }
582     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
583         TELEPHONY_LOGE("simFileManager is null!");
584         return TELEPHONY_ERR_LOCAL_PTR_NULL;
585     }
586     operatorNumeric = simFileManager_[slotId]->GetSimOperatorNumeric();
587     return TELEPHONY_ERR_SUCCESS;
588 }
589 
GetISOCountryCodeForSim(int32_t slotId,std::u16string & countryCode)590 int32_t SimManager::GetISOCountryCodeForSim(int32_t slotId, std::u16string &countryCode)
591 {
592     if (!HasSimCardInner(slotId)) {
593         TELEPHONY_LOGE("GetISOCountryCodeForSim has no sim card!");
594         return TELEPHONY_ERR_NO_SIM_CARD;
595     }
596     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
597         TELEPHONY_LOGE("simFileManager is null!");
598         return TELEPHONY_ERR_LOCAL_PTR_NULL;
599     }
600     countryCode = simFileManager_[slotId]->GetISOCountryCodeForSim();
601     return TELEPHONY_ERR_SUCCESS;
602 }
603 
GetSimSpn(int32_t slotId,std::u16string & spn)604 int32_t SimManager::GetSimSpn(int32_t slotId, std::u16string &spn)
605 {
606     if (!HasSimCardInner(slotId)) {
607         TELEPHONY_LOGE("GetSimSpn has no sim card!");
608         return TELEPHONY_ERR_NO_SIM_CARD;
609     }
610     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
611         TELEPHONY_LOGE("simFileManager is null");
612         return TELEPHONY_ERR_LOCAL_PTR_NULL;
613     }
614     spn = simFileManager_[slotId]->GetSimSpn();
615     return TELEPHONY_ERR_SUCCESS;
616 }
617 
GetSimEons(int32_t slotId,const std::string & plmn,int32_t lac,bool longNameRequired)618 std::u16string SimManager::GetSimEons(int32_t slotId, const std::string &plmn, int32_t lac,
619     bool longNameRequired)
620 {
621     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
622         TELEPHONY_LOGE("simFileManager is null");
623         return std::u16string();
624     }
625 
626     return simFileManager_[slotId]->GetSimEons(plmn, lac, longNameRequired);
627 }
628 
GetSimIccId(int32_t slotId,std::u16string & iccId)629 int32_t SimManager::GetSimIccId(int32_t slotId, std::u16string &iccId)
630 {
631     if (!HasSimCardInner(slotId)) {
632         TELEPHONY_LOGE("GetSimIccId has no sim card!");
633         return TELEPHONY_ERR_NO_SIM_CARD;
634     }
635     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
636         TELEPHONY_LOGE("simFileManager is null!");
637         return TELEPHONY_ERR_LOCAL_PTR_NULL;
638     }
639     iccId = simFileManager_[slotId]->GetSimIccId();
640     return TELEPHONY_ERR_SUCCESS;
641 }
642 
GetIMSI(int32_t slotId,std::u16string & imsi)643 int32_t SimManager::GetIMSI(int32_t slotId, std::u16string &imsi)
644 {
645     if (!HasSimCardInner(slotId)) {
646         TELEPHONY_LOGE("GetIMSI has no sim card!");
647         return TELEPHONY_ERR_NO_SIM_CARD;
648     }
649     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
650         TELEPHONY_LOGE("simFileManager is null!");
651         return TELEPHONY_ERR_LOCAL_PTR_NULL;
652     }
653     imsi = simFileManager_[slotId]->GetIMSI();
654     return TELEPHONY_ERR_SUCCESS;
655 }
656 
GetLocaleFromDefaultSim(int32_t slotId)657 std::u16string SimManager::GetLocaleFromDefaultSim(int32_t slotId)
658 {
659     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
660         TELEPHONY_LOGE("simFileManager is null!");
661         return u"";
662     }
663     return simFileManager_[slotId]->GetLocaleFromDefaultSim();
664 }
665 
GetSimGid1(int32_t slotId,std::u16string & gid1)666 int32_t SimManager::GetSimGid1(int32_t slotId, std::u16string &gid1)
667 {
668     if (!HasSimCardInner(slotId)) {
669         TELEPHONY_LOGE("GetSimGid1 has no sim card!");
670         return TELEPHONY_ERR_NO_SIM_CARD;
671     }
672     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
673         TELEPHONY_LOGE("simFileManager is null!");
674         return TELEPHONY_ERR_LOCAL_PTR_NULL;
675     }
676     gid1 = simFileManager_[slotId]->GetSimGid1();
677     return TELEPHONY_ERR_SUCCESS;
678 }
679 
GetSimGid2(int32_t slotId)680 std::u16string SimManager::GetSimGid2(int32_t slotId)
681 {
682     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
683         TELEPHONY_LOGE("simFileManager is null!");
684         return u"";
685     }
686     return simFileManager_[slotId]->GetSimGid2();
687 }
688 
GetOpName(int32_t slotId,std::u16string & opname)689 int32_t SimManager::GetOpName(int32_t slotId, std::u16string &opname)
690 {
691     if (!IsValidSlotId(slotId)) {
692         TELEPHONY_LOGE("slotId is invalid! %{public}d", slotId);
693         return TELEPHONY_ERR_SLOTID_INVALID;
694     }
695     if (simFileManager_[slotId] == nullptr) {
696         TELEPHONY_LOGE("simFileManager is null! %{public}d", slotId);
697         return TELEPHONY_ERR_LOCAL_PTR_NULL;
698     }
699     opname = simFileManager_[slotId]->GetOpName();
700     return TELEPHONY_ERR_SUCCESS;
701 }
702 
GetOpKey(int32_t slotId,std::u16string & opkey)703 int32_t SimManager::GetOpKey(int32_t slotId, std::u16string &opkey)
704 {
705     if (!IsValidSlotId(slotId)) {
706         TELEPHONY_LOGE("slotId is invalid! %{public}d", slotId);
707         return TELEPHONY_ERR_SLOTID_INVALID;
708     }
709     if (simFileManager_[slotId] == nullptr) {
710         TELEPHONY_LOGE("simFileManager is null! %{public}d", slotId);
711         return TELEPHONY_ERR_LOCAL_PTR_NULL;
712     }
713     opkey = simFileManager_[slotId]->GetOpKey();
714     return TELEPHONY_ERR_SUCCESS;
715 }
716 
GetOpKeyExt(int32_t slotId,std::u16string & opkeyExt)717 int32_t SimManager::GetOpKeyExt(int32_t slotId, std::u16string &opkeyExt)
718 {
719     if (!IsValidSlotId(slotId)) {
720         TELEPHONY_LOGE("slotId is invalid! %{public}d", slotId);
721         return TELEPHONY_ERR_SLOTID_INVALID;
722     }
723     if (simFileManager_[slotId] == nullptr) {
724         TELEPHONY_LOGE("simFileManager is null! %{public}d", slotId);
725         return TELEPHONY_ERR_LOCAL_PTR_NULL;
726     }
727     opkeyExt = simFileManager_[slotId]->GetOpKeyExt();
728     return TELEPHONY_ERR_SUCCESS;
729 }
730 
GetSimTelephoneNumber(int32_t slotId,std::u16string & telephoneNumber)731 int32_t SimManager::GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber)
732 {
733     if (!HasSimCardInner(slotId)) {
734         TELEPHONY_LOGE("GetSimTelephoneNumber has no sim card!");
735         return TELEPHONY_ERR_NO_SIM_CARD;
736     }
737     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
738         TELEPHONY_LOGE("simFileManager is null!");
739         return TELEPHONY_ERR_LOCAL_PTR_NULL;
740     }
741     telephoneNumber = simFileManager_[slotId]->GetSimTelephoneNumber();
742     return TELEPHONY_ERR_SUCCESS;
743 }
744 
GetSimTeleNumberIdentifier(const int32_t slotId)745 std::u16string SimManager::GetSimTeleNumberIdentifier(const int32_t slotId)
746 {
747     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
748         TELEPHONY_LOGE("simFileManager is null!");
749         return u"";
750     }
751     return simFileManager_[slotId]->GetSimTeleNumberIdentifier();
752 }
753 
GetVoiceMailIdentifier(int32_t slotId,std::u16string & voiceMailIdentifier)754 int32_t SimManager::GetVoiceMailIdentifier(int32_t slotId, std::u16string &voiceMailIdentifier)
755 {
756     if (!HasSimCardInner(slotId)) {
757         TELEPHONY_LOGE("GetVoiceMailIdentifier has no sim card!");
758         return TELEPHONY_ERR_NO_SIM_CARD;
759     }
760     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
761         TELEPHONY_LOGE("simFileManager is null!");
762         return TELEPHONY_ERR_LOCAL_PTR_NULL;
763     }
764     voiceMailIdentifier = simFileManager_[slotId]->GetVoiceMailIdentifier();
765     return TELEPHONY_ERR_SUCCESS;
766 }
767 
GetVoiceMailNumber(int32_t slotId,std::u16string & voiceMailNumber)768 int32_t SimManager::GetVoiceMailNumber(int32_t slotId, std::u16string &voiceMailNumber)
769 {
770     if (!HasSimCardInner(slotId)) {
771         TELEPHONY_LOGE("GetVoiceMailNumber has no sim card!");
772         return TELEPHONY_ERR_NO_SIM_CARD;
773     }
774     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
775         TELEPHONY_LOGE("simFileManager is null!");
776         return TELEPHONY_ERR_LOCAL_PTR_NULL;
777     }
778     voiceMailNumber = simFileManager_[slotId]->GetVoiceMailNumber();
779     return TELEPHONY_ERR_SUCCESS;
780 }
781 
ObtainSpnCondition(int32_t slotId,bool roaming,std::string operatorNum)782 int32_t SimManager::ObtainSpnCondition(int32_t slotId, bool roaming, std::string operatorNum)
783 {
784     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
785         TELEPHONY_LOGE("simFileManager is null");
786         return TELEPHONY_ERROR;
787     }
788     return simFileManager_[slotId]->ObtainSpnCondition(roaming, operatorNum);
789 }
790 
SetVoiceMailInfo(int32_t slotId,const std::u16string & mailName,const std::u16string & mailNumber)791 int32_t SimManager::SetVoiceMailInfo(int32_t slotId, const std::u16string &mailName, const std::u16string &mailNumber)
792 {
793     if (!HasSimCardInner(slotId)) {
794         TELEPHONY_LOGE("SetVoiceMailInfo has no sim card!");
795         return TELEPHONY_ERR_NO_SIM_CARD;
796     }
797     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
798         TELEPHONY_LOGE("simFileManager is null");
799         return TELEPHONY_ERR_LOCAL_PTR_NULL;
800     }
801     if (!simFileManager_[slotId]->SetVoiceMailInfo(mailName, mailNumber)) {
802         return CORE_ERR_SIM_CARD_UPDATE_FAILED;
803     }
804     return TELEPHONY_ERR_SUCCESS;
805 }
806 
AddSmsToIcc(int32_t slotId,int status,std::string & pdu,std::string & smsc)807 int32_t SimManager::AddSmsToIcc(int32_t slotId, int status, std::string &pdu, std::string &smsc)
808 {
809     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
810         TELEPHONY_LOGE("simSmsManager_ is null!");
811         return TELEPHONY_ERR_SLOTID_INVALID;
812     }
813     return simSmsManager_[slotId]->AddSmsToIcc(status, pdu, smsc);
814 }
815 
UpdateSmsIcc(int32_t slotId,int index,int status,std::string & pduData,std::string & smsc)816 int32_t SimManager::UpdateSmsIcc(int32_t slotId, int index, int status, std::string &pduData, std::string &smsc)
817 {
818     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
819         TELEPHONY_LOGE("simSmsManager_ is null!");
820         return TELEPHONY_ERR_SLOTID_INVALID;
821     }
822     return simSmsManager_[slotId]->UpdateSmsIcc(index, status, pduData, smsc);
823 }
824 
DelSmsIcc(int32_t slotId,int index)825 int32_t SimManager::DelSmsIcc(int32_t slotId, int index)
826 {
827     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
828         TELEPHONY_LOGE("simSmsManager_ is null!");
829         return TELEPHONY_ERR_SLOTID_INVALID;
830     }
831     return simSmsManager_[slotId]->DelSmsIcc(index);
832 }
833 
ObtainAllSmsOfIcc(int32_t slotId)834 std::vector<std::string> SimManager::ObtainAllSmsOfIcc(int32_t slotId)
835 {
836     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
837         TELEPHONY_LOGE("simSmsManager_ is null!");
838         std::vector<std::string> result;
839         return result;
840     }
841     return simSmsManager_[slotId]->ObtainAllSmsOfIcc();
842 }
843 
QueryIccDiallingNumbers(int slotId,int type,std::vector<std::shared_ptr<DiallingNumbersInfo>> & result)844 int32_t SimManager::QueryIccDiallingNumbers(
845     int slotId, int type, std::vector<std::shared_ptr<DiallingNumbersInfo>> &result)
846 {
847     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
848         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
849         return TELEPHONY_ERR_LOCAL_PTR_NULL;
850     }
851     return iccDiallingNumbersManager_[slotId]->QueryIccDiallingNumbers(type, result);
852 }
853 
AddIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)854 int32_t SimManager::AddIccDiallingNumbers(
855     int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
856 {
857     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
858         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
859         return TELEPHONY_ERR_LOCAL_PTR_NULL;
860     }
861     return iccDiallingNumbersManager_[slotId]->AddIccDiallingNumbers(type, diallingNumber);
862 }
863 
DelIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)864 int32_t SimManager::DelIccDiallingNumbers(
865     int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
866 {
867     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
868         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
869         return TELEPHONY_ERR_LOCAL_PTR_NULL;
870     }
871     return iccDiallingNumbersManager_[slotId]->DelIccDiallingNumbers(type, diallingNumber);
872 }
873 
UpdateIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)874 int32_t SimManager::UpdateIccDiallingNumbers(
875     int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
876 {
877     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
878         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
879         return TELEPHONY_ERR_LOCAL_PTR_NULL;
880     }
881     return iccDiallingNumbersManager_[slotId]->UpdateIccDiallingNumbers(type, diallingNumber);
882 }
883 
RegisterCoreNotify(int32_t slotId,const std::shared_ptr<AppExecFwk::EventHandler> & handler,int what)884 void SimManager::RegisterCoreNotify(int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what)
885 {
886     if ((what >= RadioEvent::RADIO_IMSI_LOADED_READY) && (what <= RadioEvent::RADIO_SIM_RECORDS_LOADED)) {
887         if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
888             TELEPHONY_LOGE("slotId is invalid or simFileManager_ is nullptr");
889             return;
890         }
891         simFileManager_[slotId]->RegisterCoreNotify(handler, what);
892     } else if ((what >= RadioEvent::RADIO_SIM_STATE_CHANGE) &&
893         (what <= RadioEvent::RADIO_SIM_STATE_SIMLOCK)) {
894         if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
895             TELEPHONY_LOGE("slotId is invalid or simStateManager_ is nullptr");
896             return;
897         }
898         simStateManager_[slotId]->RegisterCoreNotify(handler, what);
899     } else if (what == RadioEvent::RADIO_SIM_ACCOUNT_LOADED) {
900         if ((!IsValidSlotId(slotId)) || (multiSimMonitor_ == nullptr)) {
901             TELEPHONY_LOGE("slotId is invalid or multiSimMonitor_ is nullptr");
902             return;
903         }
904         multiSimMonitor_->RegisterCoreNotify(handler, what);
905     } else {
906         TELEPHONY_LOGE("SimManager::RegisterCoreNotify faild");
907     }
908 }
909 
UnRegisterCoreNotify(int32_t slotId,const std::shared_ptr<AppExecFwk::EventHandler> & observerCallBack,int what)910 void SimManager::UnRegisterCoreNotify(
911     int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &observerCallBack, int what)
912 {
913     if (what >= RadioEvent::RADIO_IMSI_LOADED_READY && what <= RadioEvent::RADIO_SIM_RECORDS_LOADED) {
914         if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
915             TELEPHONY_LOGE("simFileManager is null");
916             return;
917         }
918         simFileManager_[slotId]->UnRegisterCoreNotify(observerCallBack, what);
919     } else if (what >= RadioEvent::RADIO_SIM_STATE_CHANGE && what <= RadioEvent::RADIO_SIM_STATE_SIMLOCK) {
920         if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
921             TELEPHONY_LOGE("simStateManager_ is null");
922             return;
923         }
924         simStateManager_[slotId]->UnRegisterCoreNotify(observerCallBack, what);
925     } else {
926         TELEPHONY_LOGE("SimManager::UnRegisterCoreNotify faild");
927     }
928 }
929 
IsValidSlotId(int32_t slotId)930 bool SimManager::IsValidSlotId(int32_t slotId)
931 {
932     if ((slotId < SLOT_ID_ZERO) || (slotId >= slotCount_)) {
933         TELEPHONY_LOGE("slotId is invalid, slotId = %{public}d", slotId);
934         return false;
935     }
936     TELEPHONY_LOGI("slotId is valid, slotId = %{public}d", slotId);
937     return true;
938 }
939 
IsValidSlotIdForDefault(int32_t slotId)940 bool SimManager::IsValidSlotIdForDefault(int32_t slotId)
941 {
942     if ((slotId < DEFAULT_SIM_SLOT_ID_REMOVE) || (slotId >= slotCount_)) {
943         TELEPHONY_LOGE("slotId is invalid, slotId = %{public}d", slotId);
944         return false;
945     }
946     TELEPHONY_LOGI("slotId is valid, slotId = %{public}d", slotId);
947     return true;
948 }
949 
GetSimIst(int32_t slotId)950 std::u16string SimManager::GetSimIst(int32_t slotId)
951 {
952     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
953         TELEPHONY_LOGE("simFileManager is null!");
954         return u"";
955     }
956     return simFileManager_[slotId]->GetSimIst();
957 }
958 
SaveImsSwitch(int32_t slotId,int32_t imsSwitchValue)959 int32_t SimManager::SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue)
960 {
961     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
962         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
963         return TELEPHONY_ERR_ARGUMENT_INVALID;
964     }
965     return multiSimController_->SaveImsSwitch(slotId, imsSwitchValue);
966 }
967 
QueryImsSwitch(int32_t slotId,int32_t & imsSwitchValue)968 int32_t SimManager::QueryImsSwitch(int32_t slotId, int32_t &imsSwitchValue)
969 {
970     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
971         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
972         return TELEPHONY_ERR_ARGUMENT_INVALID;
973     }
974     return multiSimController_->QueryImsSwitch(slotId, imsSwitchValue);
975 }
976 
RegisterSimAccountCallback(const std::string & bundleName,const sptr<SimAccountCallback> & callback)977 int32_t SimManager::RegisterSimAccountCallback(const std::string &bundleName, const sptr<SimAccountCallback> &callback)
978 {
979     if (multiSimMonitor_ == nullptr) {
980         TELEPHONY_LOGE("multiSimMonitor is null");
981         return TELEPHONY_ERR_LOCAL_PTR_NULL;
982     }
983     return multiSimMonitor_->RegisterSimAccountCallback(bundleName, callback);
984 }
985 
UnregisterSimAccountCallback(const std::string & bundleName)986 int32_t SimManager::UnregisterSimAccountCallback(const std::string &bundleName)
987 {
988     if (multiSimMonitor_ == nullptr) {
989         TELEPHONY_LOGE("multiSimMonitor is null");
990         return TELEPHONY_ERR_LOCAL_PTR_NULL;
991     }
992     return multiSimMonitor_->UnregisterSimAccountCallback(bundleName);
993 }
994 } // namespace Telephony
995 } // namespace OHOS
996