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