• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2024 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 "ffrt.h"
20 #include "radio_event.h"
21 #include "str_convert.h"
22 #include "telephony_errors.h"
23 #include "telephony_ext_wrapper.h"
24 #include "telephony_permission.h"
25 
26 namespace OHOS {
27 namespace Telephony {
SimManager(std::shared_ptr<ITelRilManager> telRilManager)28 SimManager::SimManager(std::shared_ptr<ITelRilManager> telRilManager) : telRilManager_(telRilManager)
29 {
30     TELEPHONY_LOGI("SimManager::SimManager()");
31 }
32 
~SimManager()33 SimManager::~SimManager() {}
34 
OnInit(int32_t slotCount)35 bool SimManager::OnInit(int32_t slotCount)
36 {
37     TELEPHONY_LOGI("SimManager OnInit, slotCount = %{public}d", slotCount);
38     slotCount_ = slotCount;
39     InitMultiSimObject();
40     InitSingleSimObject();
41     TELEPHONY_LOGD("SimManager OnInit success");
42     return true;
43 }
44 
InitMultiSimObject()45 void SimManager::InitMultiSimObject()
46 {
47     // Program memory
48     std::lock_guard<ffrt::shared_mutex> lck(mtx_);
49     if (slotCount_ <0 || slotCount_ > MAX_SLOT_COUNT) {
50         TELEPHONY_LOGI("SimManager InitMultiSimObject, slotCount = %{public}d is out of range", slotCount_);
51         return;
52     }
53     simStateManager_.resize(slotCount_);
54     simFileManager_.resize(slotCount_);
55     simSmsManager_.resize(slotCount_);
56     simAccountManager_.resize(slotCount_);
57     iccDiallingNumbersManager_.resize(slotCount_);
58     stkManager_.resize(slotCount_);
59     // Many card create
60     for (int32_t slotId = 0; slotId < slotCount_; slotId++) {
61         InitBaseManager(slotId);
62         simSmsManager_[slotId] =
63             std::make_shared<SimSmsManager>(telRilManager_, simFileManager_[slotId], simStateManager_[slotId]);
64         if (simSmsManager_[slotId] != nullptr) {
65             simSmsManager_[slotId]->Init(slotId);
66         }
67         iccDiallingNumbersManager_[slotId] = IccDiallingNumbersManager::CreateInstance(
68             std::weak_ptr<SimFileManager>(simFileManager_[slotId]), simStateManager_[slotId]);
69         if (iccDiallingNumbersManager_[slotId] != nullptr) {
70             iccDiallingNumbersManager_[slotId]->Init();
71         }
72         stkManager_[slotId] = std::make_shared<StkManager>(telRilManager_, simStateManager_[slotId]);
73         if (stkManager_[slotId] != nullptr) {
74             stkManager_[slotId]->Init(slotId);
75         }
76         if (simStateManager_[slotId] != nullptr) {
77             ffrt::submit([=]() {
78                 simStateManager_[slotId]->RefreshSimState(slotId);
79             });
80         }
81     }
82 }
83 
InitTelExtraModule(int32_t slotId)84 int32_t SimManager::InitTelExtraModule(int32_t slotId)
85 {
86     if (slotId != SIM_SLOT_2) {
87         return TELEPHONY_ERROR;
88     }
89     std::lock_guard<ffrt::shared_mutex> lck(mtx_);
90     if (simStateManager_.size() == MAX_SLOT_COUNT) {
91         TELEPHONY_LOGI("SimManager InitTelExtraModule, slotId = %{public}d, has been inited, return.", slotId);
92         return TELEPHONY_SUCCESS;
93     }
94     // Program memory
95     simStateManager_.resize(MAX_SLOT_COUNT);
96     simFileManager_.resize(MAX_SLOT_COUNT);
97     simAccountManager_.resize(MAX_SLOT_COUNT);
98     InitBaseManager(slotId);
99     multiSimController_->AddExtraManagers(simStateManager_[slotId], simFileManager_[slotId]);
100     multiSimMonitor_->AddExtraManagers(simStateManager_[slotId], simFileManager_[slotId]);
101     slotCount_ = MAX_SLOT_COUNT;
102     return TELEPHONY_SUCCESS;
103 }
104 
InitBaseManager(int32_t slotId)105 void SimManager::InitBaseManager(int32_t slotId)
106 {
107     if (slotId < 0 || slotId >= static_cast<int32_t>(simStateManager_.size())) {
108         return;
109     }
110     simStateManager_[slotId] = std::make_shared<SimStateManager>(telRilManager_);
111     if (simStateManager_[slotId] != nullptr) {
112         simStateManager_[slotId]->Init(slotId);
113     }
114     simFileManager_[slotId] = SimFileManager::CreateInstance(std::weak_ptr<ITelRilManager>(telRilManager_),
115         std::weak_ptr<SimStateManager>(simStateManager_[slotId]));
116     if (simFileManager_[slotId] != nullptr) {
117         simFileManager_[slotId]->Init(slotId);
118     }
119     simAccountManager_[slotId] =
120         std::make_shared<SimAccountManager>(telRilManager_, simStateManager_[slotId], simFileManager_[slotId]);
121     if (simAccountManager_[slotId] != nullptr) {
122         simAccountManager_[slotId]->Init(slotId);
123     }
124 }
125 
InitSingleSimObject()126 void SimManager::InitSingleSimObject()
127 {
128     multiSimController_ = std::make_shared<MultiSimController>(telRilManager_, simStateManager_, simFileManager_);
129     if (multiSimController_ == nullptr) {
130         TELEPHONY_LOGE("SimManager::InitSingleSimObject multiSimController init failed");
131         return;
132     }
133     multiSimController_->Init();
134     std::vector<std::weak_ptr<Telephony::SimFileManager>> simFileManager;
135     for (auto simFile : simFileManager_) {
136         simFileManager.push_back(std::weak_ptr<Telephony::SimFileManager>(simFile));
137     }
138     multiSimMonitor_ = std::make_shared<MultiSimMonitor>(multiSimController_, simStateManager_, simFileManager);
139     if (multiSimMonitor_ == nullptr) {
140         TELEPHONY_LOGE("SimAccountManager:: multiSimMonitor is null");
141         return;
142     }
143     multiSimMonitor_->Init();
144 }
145 
HasSimCard(int32_t slotId,bool & hasSimCard)146 int32_t SimManager::HasSimCard(int32_t slotId, bool &hasSimCard)
147 {
148     std::shared_lock<ffrt::shared_mutex> lck(mtx_);
149     if ((!IsValidSlotId(slotId, simStateManager_)) || (simStateManager_[slotId] == nullptr)) {
150         TELEPHONY_LOGE("simStateManager is null!");
151         return TELEPHONY_ERR_LOCAL_PTR_NULL;
152     }
153     if (simStateManager_[slotId]->HasSimCard()) {
154         hasSimCard = true;
155         return TELEPHONY_ERR_SUCCESS;
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         simState = SimState::SIM_STATE_NOT_PRESENT;
171         return TELEPHONY_ERR_SUCCESS;
172     }
173     simState = simStateManager_[slotId]->GetSimState();
174     return TELEPHONY_ERR_SUCCESS;
175 }
176 
GetSimIccStatus(int32_t slotId,IccSimStatus & iccStatus)177 int32_t SimManager::GetSimIccStatus(int32_t slotId, IccSimStatus &iccStatus)
178 {
179     if (!HasSimCardInner(slotId)) {
180         iccStatus = IccSimStatus::ICC_CARD_ABSENT;
181         return TELEPHONY_ERR_SUCCESS;
182     }
183     iccStatus = simStateManager_[slotId]->GetSimIccStatus();
184     return TELEPHONY_ERR_SUCCESS;
185 }
186 
GetCardType(int32_t slotId,CardType & cardType)187 int32_t SimManager::GetCardType(int32_t slotId, CardType &cardType)
188 {
189     if (!HasSimCardInner(slotId)) {
190         TELEPHONY_LOGE("slot%{public}d GetCardType has no sim card!", slotId);
191         return TELEPHONY_ERR_NO_SIM_CARD;
192     }
193     cardType = simStateManager_[slotId]->GetCardType();
194     return TELEPHONY_ERR_SUCCESS;
195 }
196 
SetModemInit(int32_t slotId,bool state)197 int32_t SimManager::SetModemInit(int32_t slotId, bool state)
198 {
199     if ((!IsValidSlotId(slotId, simStateManager_)) || (simStateManager_[slotId] == nullptr)) {
200         TELEPHONY_LOGE("slot%{public}d simStateManager_ is nullptr!", slotId);
201         return TELEPHONY_ERR_LOCAL_PTR_NULL;
202     }
203     return simStateManager_[slotId]->SetModemInit(state);
204 }
205 
UnlockPin(int32_t slotId,const std::string & pin,LockStatusResponse & response)206 int32_t SimManager::UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response)
207 {
208     if (!HasSimCardInner(slotId)) {
209         TELEPHONY_LOGE("UnlockPin has no sim card!");
210         return TELEPHONY_ERR_NO_SIM_CARD;
211     }
212     return simStateManager_[slotId]->UnlockPin(slotId, pin, response);
213 }
214 
UnlockPuk(int32_t slotId,const std::string & newPin,const std::string & puk,LockStatusResponse & response)215 int32_t SimManager::UnlockPuk(
216     int32_t slotId, const std::string &newPin, const std::string &puk, LockStatusResponse &response)
217 {
218     if (!HasSimCardInner(slotId)) {
219         TELEPHONY_LOGE("UnlockPuk has no sim card!");
220         return TELEPHONY_ERR_NO_SIM_CARD;
221     }
222     return simStateManager_[slotId]->UnlockPuk(slotId, newPin, puk, response);
223 }
224 
AlterPin(int32_t slotId,const std::string & newPin,const std::string & oldPin,LockStatusResponse & response)225 int32_t SimManager::AlterPin(
226     int32_t slotId, const std::string &newPin, const std::string &oldPin, LockStatusResponse &response)
227 {
228     if (!HasSimCardInner(slotId)) {
229         TELEPHONY_LOGE("AlterPin has no sim card!");
230         return TELEPHONY_ERR_NO_SIM_CARD;
231     }
232     return simStateManager_[slotId]->AlterPin(slotId, newPin, oldPin, response);
233 }
234 
SetLockState(int32_t slotId,const LockInfo & options,LockStatusResponse & response)235 int32_t SimManager::SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response)
236 {
237     if (!HasSimCardInner(slotId)) {
238         TELEPHONY_LOGE("SetLockState has no sim card!");
239         return TELEPHONY_ERR_NO_SIM_CARD;
240     }
241     return simStateManager_[slotId]->SetLockState(slotId, options, response);
242 }
243 
GetLockState(int32_t slotId,LockType lockType,LockState & lockState)244 int32_t SimManager::GetLockState(int32_t slotId, LockType lockType, LockState &lockState)
245 {
246     if (!HasSimCardInner(slotId)) {
247         TELEPHONY_LOGE("GetLockState has no sim card!");
248         return TELEPHONY_ERR_NO_SIM_CARD;
249     }
250     return simStateManager_[slotId]->GetLockState(slotId, lockType, lockState);
251 }
252 
RefreshSimState(int32_t slotId)253 int32_t SimManager::RefreshSimState(int32_t slotId)
254 {
255     if ((!IsValidSlotId(slotId, simStateManager_)) || (simStateManager_[slotId] == nullptr)) {
256         TELEPHONY_LOGE("simStateManager is null!");
257         return TELEPHONY_ERROR;
258     }
259     return simStateManager_[slotId]->RefreshSimState(slotId);
260 }
261 
UnlockPin2(int32_t slotId,const std::string & pin2,LockStatusResponse & response)262 int32_t SimManager::UnlockPin2(int32_t slotId, const std::string &pin2, LockStatusResponse &response)
263 {
264     if (!HasSimCardInner(slotId)) {
265         TELEPHONY_LOGE("UnlockPin2 has no sim card!");
266         return TELEPHONY_ERR_NO_SIM_CARD;
267     }
268     return simStateManager_[slotId]->UnlockPin2(slotId, pin2, response);
269 }
270 
UnlockPuk2(int32_t slotId,const std::string & newPin2,const std::string & puk2,LockStatusResponse & response)271 int32_t SimManager::UnlockPuk2(
272     int32_t slotId, const std::string &newPin2, const std::string &puk2, LockStatusResponse &response)
273 {
274     if (!HasSimCardInner(slotId)) {
275         TELEPHONY_LOGE("UnlockPuk2 has no sim card!");
276         return TELEPHONY_ERR_NO_SIM_CARD;
277     }
278     return simStateManager_[slotId]->UnlockPuk2(slotId, newPin2, puk2, response);
279 }
280 
AlterPin2(int32_t slotId,const std::string & newPin2,const std::string & oldPin2,LockStatusResponse & response)281 int32_t SimManager::AlterPin2(
282     int32_t slotId, const std::string &newPin2, const std::string &oldPin2, LockStatusResponse &response)
283 {
284     if (!HasSimCardInner(slotId)) {
285         TELEPHONY_LOGE("AlterPin2 has no sim card!");
286         return TELEPHONY_ERR_NO_SIM_CARD;
287     }
288     return simStateManager_[slotId]->AlterPin2(slotId, newPin2, oldPin2, response);
289 }
290 
UnlockSimLock(int32_t slotId,const PersoLockInfo & lockInfo,LockStatusResponse & response)291 int32_t SimManager::UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response)
292 {
293     if (!HasSimCardInner(slotId)) {
294         TELEPHONY_LOGE("UnlockSimLock has no sim card!");
295         return TELEPHONY_ERR_NO_SIM_CARD;
296     }
297     return simStateManager_[slotId]->UnlockSimLock(slotId, lockInfo, response);
298 }
299 
IsSimActive(int32_t slotId)300 bool SimManager::IsSimActive(int32_t slotId)
301 {
302     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
303         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
304         return false;
305     }
306     return multiSimController_->IsSimActive(slotId);
307 }
308 
SetActiveSim(int32_t slotId,int32_t enable)309 int32_t SimManager::SetActiveSim(int32_t slotId, int32_t enable)
310 {
311     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
312         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
313         return TELEPHONY_ERR_LOCAL_PTR_NULL;
314     }
315     int32_t ret = multiSimController_->SetActiveSim(slotId, enable);
316     if (ret == TELEPHONY_ERR_SUCCESS && multiSimMonitor_ != nullptr) {
317         multiSimMonitor_->NotifySimAccountChanged();
318     }
319     return ret;
320 }
321 
SetActiveSimSatellite(int32_t slotId,int32_t enable)322 int32_t SimManager::SetActiveSimSatellite(int32_t slotId, int32_t enable)
323 {
324     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
325         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
326         return TELEPHONY_ERR_LOCAL_PTR_NULL;
327     }
328     int32_t ret = multiSimController_->SetActiveSimSatellite(slotId, enable);
329     if (ret == TELEPHONY_ERR_SUCCESS && multiSimMonitor_ != nullptr) {
330         multiSimMonitor_->NotifySimAccountChanged();
331     }
332     return ret;
333 }
334 
ResetSimLoadAccount(int32_t slotId)335 int32_t SimManager::ResetSimLoadAccount(int32_t slotId)
336 {
337     if ((!IsValidSlotId(slotId)) || (multiSimMonitor_ == nullptr)) {
338         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
339         return TELEPHONY_ERR_LOCAL_PTR_NULL;
340     }
341     multiSimMonitor_->ResetSimLoadAccount(slotId);
342     return TELEPHONY_ERR_SUCCESS;
343 }
344 
GetSimAccountInfo(int32_t slotId,bool denied,IccAccountInfo & info)345 int32_t SimManager::GetSimAccountInfo(int32_t slotId, bool denied, IccAccountInfo &info)
346 {
347     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
348         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
349         return TELEPHONY_ERR_LOCAL_PTR_NULL;
350     }
351     return multiSimController_->GetSimAccountInfo(slotId, denied, info);
352 }
353 
SetDefaultVoiceSlotId(int32_t slotId)354 int32_t SimManager::SetDefaultVoiceSlotId(int32_t slotId)
355 {
356     if (!IsValidSlotIdForDefault(slotId)) {
357         TELEPHONY_LOGE("slotId is invalid for default.");
358         return TELEPHONY_ERR_SLOTID_INVALID;
359     }
360     if (multiSimController_ == nullptr) {
361         TELEPHONY_LOGE("multiSimController_ is nullptr.");
362         return TELEPHONY_ERR_LOCAL_PTR_NULL;
363     }
364     int32_t ret = multiSimController_->SetDefaultVoiceSlotId(slotId);
365     if (ret == TELEPHONY_ERR_SUCCESS && multiSimMonitor_ != nullptr) {
366         multiSimMonitor_->NotifySimAccountChanged();
367     }
368     return ret;
369 }
370 
SetDefaultSmsSlotId(int32_t slotId)371 int32_t SimManager::SetDefaultSmsSlotId(int32_t slotId)
372 {
373     if (!IsValidSlotIdForDefault(slotId)) {
374         TELEPHONY_LOGE("slotId is invalid for default.");
375         return TELEPHONY_ERR_SLOTID_INVALID;
376     }
377     if (multiSimController_ == nullptr) {
378         TELEPHONY_LOGE("multiSimController_ is nullptr.");
379         return TELEPHONY_ERR_LOCAL_PTR_NULL;
380     }
381     int32_t ret = multiSimController_->SetDefaultSmsSlotId(slotId);
382     if (ret == TELEPHONY_ERR_SUCCESS && multiSimMonitor_ != nullptr) {
383         multiSimMonitor_->NotifySimAccountChanged();
384     }
385     return ret;
386 }
387 
SetDefaultCellularDataSlotId(int32_t slotId)388 int32_t SimManager::SetDefaultCellularDataSlotId(int32_t slotId)
389 {
390     if (!IsValidSlotId(slotId)) {
391         TELEPHONY_LOGE("slotId is invalid for default.");
392         return TELEPHONY_ERR_SLOTID_INVALID;
393     }
394     if (multiSimController_ == nullptr) {
395         TELEPHONY_LOGE("multiSimController_ is nullptr.");
396         return TELEPHONY_ERR_LOCAL_PTR_NULL;
397     }
398     int32_t ret = multiSimController_->SetDefaultCellularDataSlotId(slotId);
399     if (ret == TELEPHONY_ERR_SUCCESS && multiSimMonitor_ != nullptr) {
400         multiSimMonitor_->NotifySimAccountChanged();
401     }
402     return ret;
403 }
404 
SetPrimarySlotId(int32_t slotId,bool isUserSet)405 int32_t SimManager::SetPrimarySlotId(int32_t slotId, bool isUserSet)
406 {
407     if (!IsValidSlotId(slotId)) {
408         TELEPHONY_LOGE("slotId is invalid for default.");
409         return TELEPHONY_ERR_SLOTID_INVALID;
410     }
411     if (multiSimController_ == nullptr) {
412         TELEPHONY_LOGE("multiSimController_ is nullptr.");
413         return TELEPHONY_ERR_LOCAL_PTR_NULL;
414     }
415     int32_t ret = multiSimController_->SetPrimarySlotId(slotId, isUserSet);
416     if (ret == TELEPHONY_ERR_SUCCESS && multiSimMonitor_ != nullptr) {
417         multiSimMonitor_->NotifySimAccountChanged();
418     }
419     return ret;
420 }
421 
SetShowNumber(int32_t slotId,const std::u16string & number)422 int32_t SimManager::SetShowNumber(int32_t slotId, const std::u16string &number)
423 {
424     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
425         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
426         return TELEPHONY_ERR_LOCAL_PTR_NULL;
427     }
428     return multiSimController_->SetShowNumber(slotId, number);
429 }
430 
SetShowName(int32_t slotId,const std::u16string & name)431 int32_t SimManager::SetShowName(int32_t slotId, const std::u16string &name)
432 {
433     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
434         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
435         return TELEPHONY_ERR_LOCAL_PTR_NULL;
436     }
437     return multiSimController_->SetShowName(slotId, name);
438 }
439 
GetDefaultVoiceSlotId()440 int32_t SimManager::GetDefaultVoiceSlotId()
441 {
442     if (slotCount_ == std::atoi(DEFAULT_SLOT_COUNT)) {
443         TELEPHONY_LOGI("default slotId is 0 for single card version");
444         return DEFAULT_SIM_SLOT_ID;
445     }
446     if (multiSimController_ == nullptr) {
447         TELEPHONY_LOGE("multiSimController_ is nullptr");
448         return TELEPHONY_ERROR;
449     }
450     return multiSimController_->GetDefaultVoiceSlotId();
451 }
452 
GetDefaultVoiceSimId(int32_t & simId)453 int32_t SimManager::GetDefaultVoiceSimId(int32_t &simId)
454 {
455     if (multiSimController_ == nullptr) {
456         TELEPHONY_LOGE("multiSimController_ is nullptr");
457         return TELEPHONY_ERR_LOCAL_PTR_NULL;
458     }
459     int32_t result = multiSimController_->GetDefaultVoiceSlotId();
460     if (result < DEFAULT_SIM_SLOT_ID) {
461         TELEPHONY_LOGI("DefaultVoiceSlotId is invalid");
462         simId = INVALID_VALUE;
463         return TELEPHONY_ERR_SUCCESS;
464     }
465     int32_t defaultSimId = GetSimId(result);
466     if (defaultSimId <= DEFAULT_SIM_SLOT_ID) {
467         TELEPHONY_LOGI("simId  is invalid");
468         simId = INVALID_VALUE;
469     } else {
470         simId = defaultSimId;
471     }
472     return TELEPHONY_ERR_SUCCESS;
473 }
474 
GetDefaultSmsSlotId()475 int32_t SimManager::GetDefaultSmsSlotId()
476 {
477     if (slotCount_ == std::atoi(DEFAULT_SLOT_COUNT)) {
478         TELEPHONY_LOGI("default slotId is 0 for single card version");
479         return DEFAULT_SIM_SLOT_ID;
480     }
481     if (multiSimController_ == nullptr) {
482         TELEPHONY_LOGE("multiSimController_ is nullptr");
483         return TELEPHONY_ERROR;
484     }
485     return multiSimController_->GetDefaultSmsSlotId();
486 }
487 
GetDefaultSmsSimId(int32_t & simId)488 int32_t SimManager::GetDefaultSmsSimId(int32_t &simId)
489 {
490     if (multiSimController_ == nullptr) {
491         TELEPHONY_LOGE("multiSimController_ is nullptr");
492         return TELEPHONY_ERR_LOCAL_PTR_NULL;
493     }
494     int32_t result = multiSimController_->GetDefaultSmsSlotId();
495     if (result < DEFAULT_SIM_SLOT_ID) {
496         TELEPHONY_LOGI("DefaultSmsSlotId is invalid");
497         simId = INVALID_VALUE;
498         return TELEPHONY_ERR_SUCCESS;
499     }
500     int32_t defaultSimId = GetSimId(result);
501     if (defaultSimId <= DEFAULT_SIM_SLOT_ID) {
502         TELEPHONY_LOGI("simId  is invalid");
503         simId = INVALID_VALUE;
504     } else {
505         simId = defaultSimId;
506     }
507     return TELEPHONY_ERR_SUCCESS;
508 }
509 
GetDefaultCellularDataSlotId()510 int32_t SimManager::GetDefaultCellularDataSlotId()
511 {
512     if (slotCount_ == std::atoi(DEFAULT_SLOT_COUNT)) {
513         TELEPHONY_LOGI("default slotId is 0 for single card version");
514         return DEFAULT_SIM_SLOT_ID;
515     }
516     if (multiSimController_ == nullptr) {
517         TELEPHONY_LOGE("multiSimController_ is nullptr");
518         return TELEPHONY_ERROR;
519     }
520     return multiSimController_->GetDefaultCellularDataSlotId();
521 }
522 
GetDefaultCellularDataSimId(int32_t & simId)523 int32_t SimManager::GetDefaultCellularDataSimId(int32_t &simId)
524 {
525     if (multiSimController_ == nullptr) {
526         TELEPHONY_LOGE("multiSimController_ is nullptr");
527         return TELEPHONY_ERR_LOCAL_PTR_NULL;
528     }
529     int32_t result = multiSimController_->GetDefaultCellularDataSlotId();
530     if (result < DEFAULT_SIM_SLOT_ID) {
531         TELEPHONY_LOGE("DefaultCellularDataSlotId is invalid");
532         return TELEPHONY_ERR_NO_SIM_CARD;
533     }
534     int32_t defaultSimId = GetSimId(result);
535     if (defaultSimId <= DEFAULT_SIM_SLOT_ID) {
536         TELEPHONY_LOGE("simId  is invalid");
537         return TELEPHONY_ERR_FAIL;
538     }
539     simId = defaultSimId;
540     return TELEPHONY_ERR_SUCCESS;
541 }
542 
GetDsdsMode(int32_t & dsdsMode)543 int32_t SimManager::GetDsdsMode(int32_t &dsdsMode)
544 {
545     if (slotCount_ == std::atoi(DEFAULT_SLOT_COUNT)) {
546         TELEPHONY_LOGI(" default dsds mode is 0 for single card version");
547         dsdsMode = DSDS_MODE_V2;
548         return TELEPHONY_ERR_SUCCESS;
549     }
550     dsdsMode = dsdsMode_;
551     return TELEPHONY_ERR_SUCCESS;
552 }
553 
SetDsdsMode(int32_t dsdsMode)554 int32_t SimManager::SetDsdsMode(int32_t dsdsMode)
555 {
556     dsdsMode_ = dsdsMode;
557     return TELEPHONY_ERR_SUCCESS;
558 }
559 
GetPrimarySlotId(int32_t & slotId)560 int32_t SimManager::GetPrimarySlotId(int32_t &slotId)
561 {
562     if (slotCount_ == std::atoi(DEFAULT_SLOT_COUNT)) {
563         TELEPHONY_LOGI(" default slotId is 0 for single card version");
564         slotId = DEFAULT_SIM_SLOT_ID;
565         return TELEPHONY_ERR_SUCCESS;
566     }
567     if (multiSimController_ == nullptr) {
568         TELEPHONY_LOGE("multiSimController_ is nullptr");
569         return TELEPHONY_ERR_LOCAL_PTR_NULL;
570     }
571     slotId = multiSimController_->GetPrimarySlotId();
572     return TELEPHONY_ERR_SUCCESS;
573 }
574 
GetShowNumber(int32_t slotId,std::u16string & showNumber)575 int32_t SimManager::GetShowNumber(int32_t slotId, std::u16string &showNumber)
576 {
577     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
578         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
579         return TELEPHONY_ERR_LOCAL_PTR_NULL;
580     }
581     return multiSimController_->GetShowNumber(slotId, showNumber);
582 }
583 
GetShowName(int32_t slotId,std::u16string & showName)584 int32_t SimManager::GetShowName(int32_t slotId, std::u16string &showName)
585 {
586     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
587         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
588         return TELEPHONY_ERR_LOCAL_PTR_NULL;
589     }
590     return multiSimController_->GetShowName(slotId, showName);
591 }
592 
GetActiveSimAccountInfoList(bool denied,std::vector<IccAccountInfo> & iccAccountInfoList)593 int32_t SimManager::GetActiveSimAccountInfoList(bool denied, std::vector<IccAccountInfo> &iccAccountInfoList)
594 {
595     if (multiSimController_ == nullptr) {
596         TELEPHONY_LOGE("multiSimController_ is nullptr");
597         return TELEPHONY_ERR_LOCAL_PTR_NULL;
598     }
599     return multiSimController_->GetActiveSimAccountInfoList(denied, iccAccountInfoList);
600 }
601 
GetSlotId(int32_t simId)602 int32_t SimManager::GetSlotId(int32_t simId)
603 {
604     if (TELEPHONY_EXT_WRAPPER.getSlotIdExt_) {
605         int32_t slotId;
606         if (TELEPHONY_EXT_WRAPPER.getSlotIdExt_(simId, slotId)) {
607             TELEPHONY_LOGI("getSlotIdExt_, simId:%{public}d, slotId:%{public}d", simId, slotId);
608             return slotId;
609         }
610     }
611     if (multiSimController_ == nullptr) {
612         TELEPHONY_LOGE("multiSimController_ is nullptr");
613         return TELEPHONY_ERROR;
614     }
615     return multiSimController_->GetSlotId(simId);
616 }
617 
GetSimId(int32_t slotId)618 int32_t SimManager::GetSimId(int32_t slotId)
619 {
620     if (TELEPHONY_EXT_WRAPPER.getSimIdExt_) {
621         int32_t simId;
622         if (TELEPHONY_EXT_WRAPPER.getSimIdExt_(slotId, simId)) {
623             TELEPHONY_LOGI("getSimIdExt_, slotId:%{public}d, simId:%{public}d", slotId, simId);
624             return simId;
625         }
626     }
627     IccAccountInfo accountInfo;
628     if (GetSimAccountInfo(slotId, false, accountInfo) == TELEPHONY_ERR_SUCCESS) {
629         return accountInfo.simId;
630     }
631     TELEPHONY_LOGE("GetSimAccountInfo fail!");
632     return TELEPHONY_ERROR;
633 }
634 
GetOperatorConfigs(int32_t slotId,OperatorConfig & poc)635 int32_t SimManager::GetOperatorConfigs(int32_t slotId, OperatorConfig &poc)
636 {
637     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
638         TELEPHONY_LOGE("simAccountManager is null!");
639         return TELEPHONY_ERR_LOCAL_PTR_NULL;
640     }
641     return simAccountManager_[slotId]->GetOperatorConfigs(slotId, poc);
642 }
643 
UpdateOperatorConfigs(int32_t slotId)644 int32_t SimManager::UpdateOperatorConfigs(int32_t slotId)
645 {
646     if (!TelephonyPermission::CheckPermission(Permission::SET_TELEPHONY_STATE)) {
647         TELEPHONY_LOGE("permission denied!");
648         return TELEPHONY_ERR_PERMISSION_ERR;
649     }
650     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
651         TELEPHONY_LOGE("slotId %{public}d is invalid or simAccountManager is null!", slotId);
652         return TELEPHONY_ERR_LOCAL_PTR_NULL;
653     }
654     return simAccountManager_[slotId]->UpdateOperatorConfigs(slotId);
655 }
656 
HasOperatorPrivileges(const int32_t slotId,bool & hasOperatorPrivileges)657 int32_t SimManager::HasOperatorPrivileges(const int32_t slotId, bool &hasOperatorPrivileges)
658 {
659     TELEPHONY_LOGI("SimManager::HasOperatorPrivileges slotId:%{public}d", slotId);
660     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
661         TELEPHONY_LOGE("simAccountManager_ can not be null!");
662         return TELEPHONY_ERR_LOCAL_PTR_NULL;
663     }
664     return simAccountManager_[slotId]->HasOperatorPrivileges(slotId, hasOperatorPrivileges);
665 }
666 
SimAuthentication(int32_t slotId,AuthType authType,const std::string & authData,SimAuthenticationResponse & response)667 int32_t SimManager::SimAuthentication(
668     int32_t slotId, AuthType authType, const std::string &authData, SimAuthenticationResponse &response)
669 {
670     if (!HasSimCardInner(slotId)) {
671         TELEPHONY_LOGE("SimAuthentication has no sim card!");
672         return TELEPHONY_ERR_NO_SIM_CARD;
673     }
674     if (!IsValidAuthType(authType)) {
675         TELEPHONY_LOGE("SimAuthentication authType is invalid!");
676         return TELEPHONY_ERR_ARGUMENT_INVALID;
677     }
678     if (simStateManager_[slotId] == nullptr) {
679         TELEPHONY_LOGE("simStateManager_ can not be null!");
680         return TELEPHONY_ERR_LOCAL_PTR_NULL;
681     }
682     return simStateManager_[slotId]->SimAuthentication(slotId, authType, authData, response);
683 }
684 
SendSimMatchedOperatorInfo(int32_t slotId,int32_t state,const std::string & operName,const std::string & operKey)685 int32_t SimManager::SendSimMatchedOperatorInfo(
686     int32_t slotId, int32_t state, const std::string &operName, const std::string &operKey)
687 {
688     if (simStateManager_.empty() || simStateManager_[slotId] == nullptr) {
689         TELEPHONY_LOGE("simStateManager_ can not be null!");
690         return TELEPHONY_ERR_LOCAL_PTR_NULL;
691     }
692     return simStateManager_[slotId]->SendSimMatchedOperatorInfo(slotId, state, operName, operKey);
693 }
694 
GetRadioProtocolTech(int32_t slotId)695 int32_t SimManager::GetRadioProtocolTech(int32_t slotId)
696 {
697     TELEPHONY_LOGI("SimManager::GetRadioProtocolTech slotId:%{public}d", slotId);
698     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
699         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
700         return static_cast<int32_t>(RadioProtocolTech::RADIO_PROTOCOL_TECH_UNKNOWN);
701     }
702     return multiSimController_->GetRadioProtocolTech(slotId);
703 }
704 
GetRadioProtocol(int32_t slotId)705 void SimManager::GetRadioProtocol(int32_t slotId)
706 {
707     TELEPHONY_LOGI("SimManager::GetRadioProtocol slotId:%{public}d", slotId);
708     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
709         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
710         return;
711     }
712     return multiSimController_->GetRadioProtocol(slotId);
713 }
714 
SendEnvelopeCmd(int32_t slotId,const std::string & cmd)715 int32_t SimManager::SendEnvelopeCmd(int32_t slotId, const std::string &cmd)
716 {
717     if ((!IsValidSlotId(slotId)) || (stkManager_[slotId] == nullptr)) {
718         TELEPHONY_LOGE("stkManager is null!");
719         return TELEPHONY_ERR_LOCAL_PTR_NULL;
720     }
721     if (!HasSimCardInner(slotId)) {
722         TELEPHONY_LOGE("SendEnvelopeCmd has no sim card!");
723         return TELEPHONY_ERR_NO_SIM_CARD;
724     }
725     return stkManager_[slotId]->SendEnvelopeCmd(slotId, cmd);
726 }
727 
SendTerminalResponseCmd(int32_t slotId,const std::string & cmd)728 int32_t SimManager::SendTerminalResponseCmd(int32_t slotId, const std::string &cmd)
729 {
730     if ((!IsValidSlotId(slotId)) || (stkManager_[slotId] == nullptr)) {
731         TELEPHONY_LOGE("stkManager is null!");
732         return TELEPHONY_ERR_LOCAL_PTR_NULL;
733     }
734     if (!HasSimCardInner(slotId)) {
735         TELEPHONY_LOGE("SendTerminalResponseCmd has no sim card!");
736         return TELEPHONY_ERR_NO_SIM_CARD;
737     }
738     return stkManager_[slotId]->SendTerminalResponseCmd(slotId, cmd);
739 }
740 
SendCallSetupRequestResult(int32_t slotId,bool accept)741 int32_t SimManager::SendCallSetupRequestResult(int32_t slotId, bool accept)
742 {
743     if (!IsValidSlotId(slotId)) {
744         TELEPHONY_LOGE("slotId is invalid!");
745         return TELEPHONY_ERR_SLOTID_INVALID;
746     }
747     if (stkManager_[slotId] == nullptr) {
748         TELEPHONY_LOGE("stkManager is null!");
749         return TELEPHONY_ERR_LOCAL_PTR_NULL;
750     }
751     if (!HasSimCardInner(slotId)) {
752         TELEPHONY_LOGE("SendCallSetupRequestResult has no sim card!");
753         return TELEPHONY_ERR_NO_SIM_CARD;
754     }
755     return stkManager_[slotId]->SendCallSetupRequestResult(slotId, accept);
756 }
757 
GetSimOperatorNumeric(int32_t slotId,std::u16string & operatorNumeric)758 int32_t SimManager::GetSimOperatorNumeric(int32_t slotId, std::u16string &operatorNumeric)
759 {
760     if (!HasSimCardInner(slotId)) {
761         return TELEPHONY_ERR_NO_SIM_CARD;
762     }
763     std::shared_lock<ffrt::shared_mutex> lck(mtx_);
764     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
765         TELEPHONY_LOGE("simFileManager is null!");
766         return TELEPHONY_ERR_LOCAL_PTR_NULL;
767     }
768     operatorNumeric = simFileManager_[slotId]->GetSimOperatorNumeric();
769     return TELEPHONY_ERR_SUCCESS;
770 }
771 
GetISOCountryCodeForSim(int32_t slotId,std::u16string & countryCode)772 int32_t SimManager::GetISOCountryCodeForSim(int32_t slotId, std::u16string &countryCode)
773 {
774     if (!HasSimCardInner(slotId)) {
775         TELEPHONY_LOGE("GetISOCountryCodeForSim has no sim card!");
776         return TELEPHONY_ERR_NO_SIM_CARD;
777     }
778     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
779         TELEPHONY_LOGE("simFileManager is null!");
780         return TELEPHONY_ERR_LOCAL_PTR_NULL;
781     }
782     countryCode = simFileManager_[slotId]->GetISOCountryCodeForSim();
783     return TELEPHONY_ERR_SUCCESS;
784 }
785 
GetSimSpn(int32_t slotId,std::u16string & spn)786 int32_t SimManager::GetSimSpn(int32_t slotId, std::u16string &spn)
787 {
788     if (!HasSimCardInner(slotId)) {
789         TELEPHONY_LOGE("GetSimSpn has no sim card!");
790         return TELEPHONY_ERR_NO_SIM_CARD;
791     }
792     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
793         TELEPHONY_LOGE("simFileManager is null");
794         return TELEPHONY_ERR_LOCAL_PTR_NULL;
795     }
796     spn = simFileManager_[slotId]->GetSimSpn();
797     return TELEPHONY_ERR_SUCCESS;
798 }
799 
GetSimEons(int32_t slotId,const std::string & plmn,int32_t lac,bool longNameRequired)800 std::u16string SimManager::GetSimEons(int32_t slotId, const std::string &plmn, int32_t lac, bool longNameRequired)
801 {
802     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
803         TELEPHONY_LOGE("simFileManager is null");
804         return std::u16string();
805     }
806 
807     return simFileManager_[slotId]->GetSimEons(plmn, lac, longNameRequired);
808 }
809 
GetSimIccId(int32_t slotId,std::u16string & iccId)810 int32_t SimManager::GetSimIccId(int32_t slotId, std::u16string &iccId)
811 {
812     if (!HasSimCardInner(slotId)) {
813         TELEPHONY_LOGE("GetSimIccId has no sim card!");
814         return TELEPHONY_ERR_NO_SIM_CARD;
815     }
816     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
817         TELEPHONY_LOGE("simFileManager is null!");
818         return TELEPHONY_ERR_LOCAL_PTR_NULL;
819     }
820     iccId = simFileManager_[slotId]->GetSimIccId();
821     return TELEPHONY_ERR_SUCCESS;
822 }
823 
GetIMSI(int32_t slotId,std::u16string & imsi)824 int32_t SimManager::GetIMSI(int32_t slotId, std::u16string &imsi)
825 {
826     if (!HasSimCardInner(slotId)) {
827         TELEPHONY_LOGE("GetIMSI has no sim card!");
828         return TELEPHONY_ERR_NO_SIM_CARD;
829     }
830     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
831         TELEPHONY_LOGE("simFileManager is null!");
832         return TELEPHONY_ERR_LOCAL_PTR_NULL;
833     }
834     imsi = simFileManager_[slotId]->GetIMSI();
835     return TELEPHONY_ERR_SUCCESS;
836 }
837 
GetEhPlmns(int32_t slotId,std::set<std::string> & ehPlmns)838 int32_t SimManager::GetEhPlmns(int32_t slotId, std::set<std::string> &ehPlmns)
839 {
840     if (!HasSimCardInner(slotId)) {
841         TELEPHONY_LOGE("GetEhPlmns has no sim card!");
842         return TELEPHONY_ERR_NO_SIM_CARD;
843     }
844     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
845         TELEPHONY_LOGE("simFileManager is null!");
846         return TELEPHONY_ERR_LOCAL_PTR_NULL;
847     }
848     ehPlmns = simFileManager_[slotId]->GetEhPlmns();
849     return TELEPHONY_ERR_SUCCESS;
850 }
851 
GetSpdiPlmns(int32_t slotId,std::set<std::string> & spdiPlmns)852 int32_t SimManager::GetSpdiPlmns(int32_t slotId, std::set<std::string> &spdiPlmns)
853 {
854     if (!HasSimCardInner(slotId)) {
855         TELEPHONY_LOGE("GetSpdiPlmns has no sim card!");
856         return TELEPHONY_ERR_NO_SIM_CARD;
857     }
858     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
859         TELEPHONY_LOGE("simFileManager is null!");
860         return TELEPHONY_ERR_LOCAL_PTR_NULL;
861     }
862     spdiPlmns = simFileManager_[slotId]->GetSpdiPlmns();
863     return TELEPHONY_ERR_SUCCESS;
864 }
865 
GetLocaleFromDefaultSim(int32_t slotId)866 std::u16string SimManager::GetLocaleFromDefaultSim(int32_t slotId)
867 {
868     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
869         TELEPHONY_LOGE("simFileManager is null!");
870         return u"";
871     }
872     return simFileManager_[slotId]->GetLocaleFromDefaultSim();
873 }
874 
GetSimGid1(int32_t slotId,std::u16string & gid1)875 int32_t SimManager::GetSimGid1(int32_t slotId, std::u16string &gid1)
876 {
877     if (!HasSimCardInner(slotId)) {
878         TELEPHONY_LOGE("GetSimGid1 has no sim card!");
879         return TELEPHONY_ERR_NO_SIM_CARD;
880     }
881     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
882         TELEPHONY_LOGE("simFileManager is null!");
883         return TELEPHONY_ERR_LOCAL_PTR_NULL;
884     }
885     gid1 = simFileManager_[slotId]->GetSimGid1();
886     return TELEPHONY_ERR_SUCCESS;
887 }
888 
GetSimGid2(int32_t slotId)889 std::u16string SimManager::GetSimGid2(int32_t slotId)
890 {
891     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
892         TELEPHONY_LOGE("simFileManager is null!");
893         return u"";
894     }
895     return simFileManager_[slotId]->GetSimGid2();
896 }
897 
GetOpName(int32_t slotId,std::u16string & opname)898 int32_t SimManager::GetOpName(int32_t slotId, std::u16string &opname)
899 {
900     std::shared_lock<ffrt::shared_mutex> lck(mtx_);
901     if (!IsValidSlotId(slotId, simFileManager_)) {
902         TELEPHONY_LOGE("slotId is invalid! %{public}d", slotId);
903         return TELEPHONY_ERR_SLOTID_INVALID;
904     }
905     if (simFileManager_[slotId] == nullptr) {
906         TELEPHONY_LOGE("simFileManager is null! %{public}d", slotId);
907         return TELEPHONY_ERR_LOCAL_PTR_NULL;
908     }
909     opname = simFileManager_[slotId]->GetOpName();
910     return TELEPHONY_ERR_SUCCESS;
911 }
912 
GetOpKey(int32_t slotId,std::u16string & opkey)913 int32_t SimManager::GetOpKey(int32_t slotId, std::u16string &opkey)
914 {
915     if (!IsValidSlotId(slotId, simFileManager_)) {
916         TELEPHONY_LOGE("slotId is invalid! %{public}d", slotId);
917         return TELEPHONY_ERR_SLOTID_INVALID;
918     }
919     if (simFileManager_[slotId] == nullptr) {
920         TELEPHONY_LOGE("simFileManager is null! %{public}d", slotId);
921         return TELEPHONY_ERR_LOCAL_PTR_NULL;
922     }
923     opkey = simFileManager_[slotId]->GetOpKey();
924     return TELEPHONY_ERR_SUCCESS;
925 }
926 
GetOpKeyExt(int32_t slotId,std::u16string & opkeyExt)927 int32_t SimManager::GetOpKeyExt(int32_t slotId, std::u16string &opkeyExt)
928 {
929     if (!IsValidSlotId(slotId, simFileManager_)) {
930         TELEPHONY_LOGE("slotId is invalid! %{public}d", slotId);
931         return TELEPHONY_ERR_SLOTID_INVALID;
932     }
933     if (simFileManager_[slotId] == nullptr) {
934         TELEPHONY_LOGE("simFileManager is null! %{public}d", slotId);
935         return TELEPHONY_ERR_LOCAL_PTR_NULL;
936     }
937     opkeyExt = simFileManager_[slotId]->GetOpKeyExt();
938     return TELEPHONY_ERR_SUCCESS;
939 }
940 
GetSimTelephoneNumber(int32_t slotId,std::u16string & telephoneNumber)941 int32_t SimManager::GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber)
942 {
943     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
944         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
945         return TELEPHONY_ERR_LOCAL_PTR_NULL;
946     }
947     return multiSimController_->GetSimTelephoneNumber(slotId, telephoneNumber);
948 }
949 
GetSimTeleNumberIdentifier(const int32_t slotId)950 std::u16string SimManager::GetSimTeleNumberIdentifier(const 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]->GetSimTeleNumberIdentifier();
957 }
958 
GetVoiceMailIdentifier(int32_t slotId,std::u16string & voiceMailIdentifier)959 int32_t SimManager::GetVoiceMailIdentifier(int32_t slotId, std::u16string &voiceMailIdentifier)
960 {
961     if (!HasSimCardInner(slotId)) {
962         TELEPHONY_LOGE("GetVoiceMailIdentifier has no sim card!");
963         return TELEPHONY_ERR_NO_SIM_CARD;
964     }
965     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
966         TELEPHONY_LOGE("simFileManager is null!");
967         return TELEPHONY_ERR_LOCAL_PTR_NULL;
968     }
969     voiceMailIdentifier = simFileManager_[slotId]->GetVoiceMailIdentifier();
970     return TELEPHONY_ERR_SUCCESS;
971 }
972 
GetVoiceMailNumber(int32_t slotId,std::u16string & voiceMailNumber)973 int32_t SimManager::GetVoiceMailNumber(int32_t slotId, std::u16string &voiceMailNumber)
974 {
975     if (!HasSimCardInner(slotId)) {
976         TELEPHONY_LOGE("GetVoiceMailNumber has no sim card!");
977         return TELEPHONY_ERR_NO_SIM_CARD;
978     }
979     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
980         TELEPHONY_LOGE("simFileManager is null!");
981         return TELEPHONY_ERR_LOCAL_PTR_NULL;
982     }
983     voiceMailNumber = simFileManager_[slotId]->GetVoiceMailNumber();
984     return TELEPHONY_ERR_SUCCESS;
985 }
986 
GetVoiceMailCount(int32_t slotId,int32_t & voiceMailCount)987 int32_t SimManager::GetVoiceMailCount(int32_t slotId, int32_t &voiceMailCount)
988 {
989     if (!HasSimCardInner(slotId)) {
990         TELEPHONY_LOGE("GetVoiceMailCount has no sim card!");
991         return TELEPHONY_ERR_NO_SIM_CARD;
992     }
993     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
994         TELEPHONY_LOGE("simFileManager is null!");
995         return TELEPHONY_ERR_LOCAL_PTR_NULL;
996     }
997     voiceMailCount = simFileManager_[slotId]->GetVoiceMailCount();
998     return TELEPHONY_ERR_SUCCESS;
999 }
1000 
SetVoiceMailCount(int32_t slotId,int32_t voiceMailCount)1001 int32_t SimManager::SetVoiceMailCount(int32_t slotId, int32_t voiceMailCount)
1002 {
1003     if (!HasSimCardInner(slotId)) {
1004         TELEPHONY_LOGE("SetVoiceMailCount has no sim card!");
1005         return TELEPHONY_ERR_NO_SIM_CARD;
1006     }
1007     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
1008         TELEPHONY_LOGE("simFileManager is null!");
1009         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1010     }
1011     if (simFileManager_[slotId]->SetVoiceMailCount(voiceMailCount)) {
1012         return TELEPHONY_ERR_SUCCESS;
1013     }
1014     return CORE_ERR_SIM_CARD_UPDATE_FAILED;
1015 }
1016 
SetVoiceCallForwarding(int32_t slotId,bool enable,const std::string & number)1017 int32_t SimManager::SetVoiceCallForwarding(int32_t slotId, bool enable, const std::string &number)
1018 {
1019     if (!HasSimCardInner(slotId)) {
1020         TELEPHONY_LOGE("SetVoiceCallForwarding has no sim card!");
1021         return TELEPHONY_ERR_NO_SIM_CARD;
1022     }
1023     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
1024         TELEPHONY_LOGE("simFileManager is null!");
1025         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1026     }
1027     if (simFileManager_[slotId]->SetVoiceCallForwarding(enable, number)) {
1028         return TELEPHONY_ERR_SUCCESS;
1029     }
1030     return CORE_ERR_SIM_CARD_UPDATE_FAILED;
1031 }
1032 
ObtainSpnCondition(int32_t slotId,bool roaming,std::string operatorNum)1033 int32_t SimManager::ObtainSpnCondition(int32_t slotId, bool roaming, std::string operatorNum)
1034 {
1035     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
1036         TELEPHONY_LOGE("simFileManager is null");
1037         return TELEPHONY_ERROR;
1038     }
1039     return simFileManager_[slotId]->ObtainSpnCondition(roaming, operatorNum);
1040 }
1041 
SetVoiceMailInfo(int32_t slotId,const std::u16string & mailName,const std::u16string & mailNumber)1042 int32_t SimManager::SetVoiceMailInfo(int32_t slotId, const std::u16string &mailName, const std::u16string &mailNumber)
1043 {
1044     if (!HasSimCardInner(slotId)) {
1045         TELEPHONY_LOGE("SetVoiceMailInfo has no sim card!");
1046         return TELEPHONY_ERR_NO_SIM_CARD;
1047     }
1048     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
1049         TELEPHONY_LOGE("simFileManager is null");
1050         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1051     }
1052     if (!simFileManager_[slotId]->SetVoiceMailInfo(mailName, mailNumber)) {
1053         return CORE_ERR_SIM_CARD_UPDATE_FAILED;
1054     }
1055     return TELEPHONY_ERR_SUCCESS;
1056 }
1057 
IsCTSimCard(int32_t slotId,bool & isCTSimCard)1058 int32_t SimManager::IsCTSimCard(int32_t slotId, bool &isCTSimCard)
1059 {
1060     if (!HasSimCardInner(slotId)) {
1061         TELEPHONY_LOGE("IsCTSimCard has no sim card!");
1062         return TELEPHONY_ERR_NO_SIM_CARD;
1063     }
1064     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
1065         TELEPHONY_LOGE("simFileManager is null!");
1066         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1067     }
1068     isCTSimCard = simFileManager_[slotId]->IsCTSimCard();
1069     return TELEPHONY_ERR_SUCCESS;
1070 }
1071 
AddSmsToIcc(int32_t slotId,int status,std::string & pdu,std::string & smsc)1072 int32_t SimManager::AddSmsToIcc(int32_t slotId, int status, std::string &pdu, std::string &smsc)
1073 {
1074     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
1075         TELEPHONY_LOGE("simSmsManager_ is null!");
1076         return TELEPHONY_ERR_SLOTID_INVALID;
1077     }
1078     return simSmsManager_[slotId]->AddSmsToIcc(status, pdu, smsc);
1079 }
1080 
UpdateSmsIcc(int32_t slotId,int index,int status,std::string & pduData,std::string & smsc)1081 int32_t SimManager::UpdateSmsIcc(int32_t slotId, int index, int status, std::string &pduData, std::string &smsc)
1082 {
1083     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
1084         TELEPHONY_LOGE("simSmsManager_ is null!");
1085         return TELEPHONY_ERR_SLOTID_INVALID;
1086     }
1087     return simSmsManager_[slotId]->UpdateSmsIcc(index, status, pduData, smsc);
1088 }
1089 
DelSmsIcc(int32_t slotId,int index)1090 int32_t SimManager::DelSmsIcc(int32_t slotId, int index)
1091 {
1092     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
1093         TELEPHONY_LOGE("simSmsManager_ is null!");
1094         return TELEPHONY_ERR_SLOTID_INVALID;
1095     }
1096     return simSmsManager_[slotId]->DelSmsIcc(index);
1097 }
1098 
ObtainAllSmsOfIcc(int32_t slotId)1099 std::vector<std::string> SimManager::ObtainAllSmsOfIcc(int32_t slotId)
1100 {
1101     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
1102         TELEPHONY_LOGE("simSmsManager_ is null!");
1103         std::vector<std::string> result;
1104         return result;
1105     }
1106     return simSmsManager_[slotId]->ObtainAllSmsOfIcc();
1107 }
1108 
QueryIccDiallingNumbers(int slotId,int type,std::vector<std::shared_ptr<DiallingNumbersInfo>> & result)1109 int32_t SimManager::QueryIccDiallingNumbers(
1110     int slotId, int type, std::vector<std::shared_ptr<DiallingNumbersInfo>> &result)
1111 {
1112     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
1113         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
1114         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1115     }
1116     return iccDiallingNumbersManager_[slotId]->QueryIccDiallingNumbers(type, result);
1117 }
1118 
AddIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)1119 int32_t SimManager::AddIccDiallingNumbers(
1120     int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
1121 {
1122     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
1123         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
1124         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1125     }
1126     return iccDiallingNumbersManager_[slotId]->AddIccDiallingNumbers(type, diallingNumber);
1127 }
1128 
DelIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)1129 int32_t SimManager::DelIccDiallingNumbers(
1130     int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
1131 {
1132     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
1133         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
1134         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1135     }
1136     return iccDiallingNumbersManager_[slotId]->DelIccDiallingNumbers(type, diallingNumber);
1137 }
1138 
UpdateIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)1139 int32_t SimManager::UpdateIccDiallingNumbers(
1140     int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
1141 {
1142     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
1143         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
1144         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1145     }
1146     return iccDiallingNumbersManager_[slotId]->UpdateIccDiallingNumbers(type, diallingNumber);
1147 }
1148 
RegisterCoreNotify(int32_t slotId,const std::shared_ptr<AppExecFwk::EventHandler> & handler,int what)1149 void SimManager::RegisterCoreNotify(int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what)
1150 {
1151     if ((what >= RadioEvent::RADIO_IMSI_LOADED_READY) && (what <= RadioEvent::RADIO_SIM_RECORDS_LOADED)) {
1152         std::shared_lock<ffrt::shared_mutex> lck(mtx_);
1153         if ((simFileManager_.empty() || !IsValidSlotId(slotId, simFileManager_)) ||
1154             (simFileManager_[slotId] == nullptr)) {
1155             TELEPHONY_LOGE("slotId is invalid or simFileManager_ is nullptr");
1156             return;
1157         }
1158         simFileManager_[slotId]->RegisterCoreNotify(handler, what);
1159     } else if ((what >= RadioEvent::RADIO_SIM_STATE_CHANGE) && (what <= RadioEvent::RADIO_SIM_STATE_SIMLOCK)) {
1160         std::shared_lock<ffrt::shared_mutex> lck(mtx_);
1161         if ((simStateManager_.empty() || !IsValidSlotId(slotId, simStateManager_)) ||
1162             (simStateManager_[slotId] == nullptr)) {
1163             TELEPHONY_LOGE("slotId is invalid or simStateManager_ is nullptr");
1164             return;
1165         }
1166         simStateManager_[slotId]->RegisterCoreNotify(handler, what);
1167     } else if (what == RadioEvent::RADIO_SIM_ACCOUNT_LOADED) {
1168         // IsVSimSlotId is used for the callback function can be registered in the VSIM card.
1169         if ((multiSimMonitor_ == nullptr) || (!IsValidSlotId(slotId) && !multiSimMonitor_->IsVSimSlotId(slotId))) {
1170             TELEPHONY_LOGE("slotId is invalid or multiSimMonitor_ is nullptr !");
1171             return;
1172         }
1173         multiSimMonitor_->RegisterCoreNotify(slotId, handler, what);
1174     } else {
1175         TELEPHONY_LOGE("SimManager::RegisterCoreNotify faild");
1176     }
1177 }
1178 
UnRegisterCoreNotify(int32_t slotId,const std::shared_ptr<AppExecFwk::EventHandler> & observerCallBack,int what)1179 void SimManager::UnRegisterCoreNotify(
1180     int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &observerCallBack, int what)
1181 {
1182     if (what >= RadioEvent::RADIO_IMSI_LOADED_READY && what <= RadioEvent::RADIO_SIM_RECORDS_LOADED) {
1183         if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
1184             TELEPHONY_LOGE("simFileManager is null");
1185             return;
1186         }
1187         simFileManager_[slotId]->UnRegisterCoreNotify(observerCallBack, what);
1188     } else if (what >= RadioEvent::RADIO_SIM_STATE_CHANGE && what <= RadioEvent::RADIO_SIM_STATE_SIMLOCK) {
1189         if ((!IsValidSlotId(slotId, simStateManager_)) || (simStateManager_[slotId] == nullptr)) {
1190             TELEPHONY_LOGE("simStateManager_ is null");
1191             return;
1192         }
1193         simStateManager_[slotId]->UnRegisterCoreNotify(observerCallBack, what);
1194     } else {
1195         TELEPHONY_LOGE("SimManager::UnRegisterCoreNotify faild");
1196     }
1197 }
1198 
IsValidSlotId(int32_t slotId)1199 bool SimManager::IsValidSlotId(int32_t slotId)
1200 {
1201     if ((slotId < SLOT_ID_ZERO) || (slotId >= slotCount_)) {
1202         TELEPHONY_LOGE("slotId is invalid, slotId = %{public}d", slotId);
1203         return false;
1204     }
1205     return true;
1206 }
1207 
1208 template<class N>
IsValidSlotId(int32_t slotId,std::vector<N> vec)1209 bool SimManager::IsValidSlotId(int32_t slotId, std::vector<N> vec)
1210 {
1211     if ((slotId < SLOT_ID_ZERO) || (slotId >= static_cast<int32_t>(vec.size()))) {
1212         TELEPHONY_LOGE("slotId is invalid by vec.size(), slotId = %{public}d", slotId);
1213         return false;
1214     }
1215     return true;
1216 }
1217 
IsValidAuthType(AuthType authType)1218 bool SimManager::IsValidAuthType(AuthType authType)
1219 {
1220     return (authType == AuthType::SIM_AUTH_EAP_SIM_TYPE || authType == AuthType::SIM_AUTH_EAP_AKA_TYPE);
1221 }
1222 
IsValidSlotIdForDefault(int32_t slotId)1223 bool SimManager::IsValidSlotIdForDefault(int32_t slotId)
1224 {
1225     if ((slotId < DEFAULT_SIM_SLOT_ID_REMOVE) || (slotId >= slotCount_)) {
1226         TELEPHONY_LOGE("slotId is invalid, slotId = %{public}d", slotId);
1227         return false;
1228     }
1229     TELEPHONY_LOGD("slotId is valid, slotId = %{public}d", slotId);
1230     return true;
1231 }
1232 
GetSimIst(int32_t slotId)1233 std::u16string SimManager::GetSimIst(int32_t slotId)
1234 {
1235     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
1236         TELEPHONY_LOGE("simFileManager is null!");
1237         return u"";
1238     }
1239     return simFileManager_[slotId]->GetSimIst();
1240 }
1241 
SaveImsSwitch(int32_t slotId,int32_t imsSwitchValue)1242 int32_t SimManager::SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue)
1243 {
1244     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
1245         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
1246         return TELEPHONY_ERR_ARGUMENT_INVALID;
1247     }
1248     return multiSimController_->SaveImsSwitch(slotId, imsSwitchValue);
1249 }
1250 
QueryImsSwitch(int32_t slotId,int32_t & imsSwitchValue)1251 int32_t SimManager::QueryImsSwitch(int32_t slotId, int32_t &imsSwitchValue)
1252 {
1253     if ((!IsValidSlotId(slotId)) || (multiSimController_ == nullptr)) {
1254         TELEPHONY_LOGE("slotId is invalid or multiSimController_ is nullptr");
1255         return TELEPHONY_ERR_ARGUMENT_INVALID;
1256     }
1257     return multiSimController_->QueryImsSwitch(slotId, imsSwitchValue);
1258 }
1259 
RegisterSimAccountCallback(const int32_t tokenId,const sptr<SimAccountCallback> & callback)1260 int32_t SimManager::RegisterSimAccountCallback(const int32_t tokenId, const sptr<SimAccountCallback> &callback)
1261 {
1262     if (multiSimMonitor_ == nullptr) {
1263         TELEPHONY_LOGE("multiSimMonitor is null");
1264         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1265     }
1266     return multiSimMonitor_->RegisterSimAccountCallback(tokenId, callback);
1267 }
1268 
UnregisterSimAccountCallback(const sptr<SimAccountCallback> & callback)1269 int32_t SimManager::UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback)
1270 {
1271     if (multiSimMonitor_ == nullptr) {
1272         TELEPHONY_LOGE("multiSimMonitor is null");
1273         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1274     }
1275     return multiSimMonitor_->UnregisterSimAccountCallback(callback);
1276 }
1277 
IsSetActiveSimInProgress(int32_t slotId)1278 bool SimManager::IsSetActiveSimInProgress(int32_t slotId)
1279 {
1280     if (multiSimController_ == nullptr) {
1281         TELEPHONY_LOGE("multiSimController_ is nullptr");
1282         return false;
1283     }
1284     return multiSimController_->IsSetActiveSimInProgress(slotId);
1285 }
1286 
IsSetPrimarySlotIdInProgress()1287 bool SimManager::IsSetPrimarySlotIdInProgress()
1288 {
1289     if (multiSimController_ == nullptr) {
1290         TELEPHONY_LOGE("multiSimController_ is nullptr");
1291         return false;
1292     }
1293     return multiSimController_->IsSetPrimarySlotIdInProgress();
1294 }
1295 
GetSimIO(int32_t slotId,int32_t command,int32_t fileId,const std::string & data,const std::string & path,SimAuthenticationResponse & response)1296 int32_t SimManager::GetSimIO(int32_t slotId, int32_t command,
1297     int32_t fileId, const std::string &data, const std::string &path, SimAuthenticationResponse &response)
1298 {
1299     if (!HasSimCardInner(slotId)) {
1300         TELEPHONY_LOGE("SimAuthentication has no sim card!");
1301         return TELEPHONY_ERR_NO_SIM_CARD;
1302     }
1303     if (data.length() < SIM_IO_DATA_MIN_LEN) {
1304         TELEPHONY_LOGE("SIM IO input data length invalid");
1305         return TELEPHONY_ERR_FAIL;
1306     }
1307     SimIoRequestInfo requestInfo;
1308     requestInfo.p1 = static_cast<int>(strtol(
1309         data.substr(SIM_IO_DATA_P1_OFFSET, SIM_IO_DATA_STR_LEN).c_str(), nullptr, SIM_IO_HEX_SIGN));
1310     requestInfo.p2 = static_cast<int>(strtol(
1311         data.substr(SIM_IO_DATA_P2_OFFSET, SIM_IO_DATA_STR_LEN).c_str(), nullptr, SIM_IO_HEX_SIGN));
1312     requestInfo.p3 = static_cast<int>(strtol(
1313         data.substr(SIM_IO_DATA_P3_OFFSET, SIM_IO_DATA_STR_LEN).c_str(), nullptr, SIM_IO_HEX_SIGN));
1314     requestInfo.command = command;
1315     requestInfo.fileId = fileId;
1316     requestInfo.data = data.substr(SIM_IO_DATA_MIN_LEN, data.length() - SIM_IO_DATA_MIN_LEN);
1317     requestInfo.path = path;
1318     return simStateManager_[slotId]->GetSimIO(slotId, requestInfo, response);
1319 }
1320 
SavePrimarySlotId(int32_t slotId)1321 int32_t SimManager::SavePrimarySlotId(int32_t slotId)
1322 {
1323     if (!IsValidSlotId(slotId) || multiSimController_ == nullptr) {
1324         TELEPHONY_LOGE("slotId: %{public}d is invalid or multiSimController_ is nullptr", slotId);
1325         return TELEPHONY_ERR_ARGUMENT_INVALID;
1326     }
1327     return multiSimController_->SavePrimarySlotId(slotId);
1328 }
1329 
IsDataShareError()1330 bool SimManager::IsDataShareError()
1331 {
1332     if (multiSimController_ == nullptr) {
1333         TELEPHONY_LOGE("multiSimController_ is nullptr");
1334         return TELEPHONY_ERR_ARGUMENT_INVALID;
1335     }
1336     return multiSimController_->IsDataShareError();
1337 }
1338 
ResetDataShareError()1339 void SimManager::ResetDataShareError()
1340 {
1341     if (multiSimController_ == nullptr) {
1342         TELEPHONY_LOGE("multiSimController_ is nullptr");
1343         return;
1344     }
1345     multiSimController_->ResetDataShareError();
1346 }
1347 
UpdateImsCapFromChip(int32_t slotId,const ImsCapFromChip & imsCapFromChip)1348 void SimManager::UpdateImsCapFromChip(int32_t slotId, const ImsCapFromChip &imsCapFromChip)
1349 {
1350     if ((!IsValidSlotId(slotId, simFileManager_)) || (simFileManager_[slotId] == nullptr)) {
1351         TELEPHONY_LOGE("slotId %{public}d is invalid or simFileManager is null!", slotId);
1352         return;
1353     }
1354     simAccountManager_[slotId]->UpdateImsCapFromChip(slotId, imsCapFromChip);
1355 }
1356 
GetDefaultMainSlotByIccId()1357 int32_t SimManager::GetDefaultMainSlotByIccId()
1358 {
1359     if (multiSimController_ == nullptr) {
1360         TELEPHONY_LOGE("multiSimController_ is nullptr");
1361         return INVALID_VALUE;
1362     }
1363     return multiSimController_->GetDefaultMainSlotByIccId();
1364 }
1365 
GetSimLabel(int32_t slotId,SimLabel & simLabel)1366 int32_t SimManager::GetSimLabel(int32_t slotId, SimLabel &simLabel)
1367 {
1368     if (!HasSimCardInner(slotId)) {
1369         simLabel.index = slotId + 1;
1370         return TELEPHONY_ERR_SUCCESS;
1371     }
1372     if (multiSimController_ == nullptr) {
1373         TELEPHONY_LOGE("multiSimController_ is nullptr");
1374         return INVALID_VALUE;
1375     }
1376     return multiSimController_->GetSimLabel(slotId, simLabel);
1377 }
1378 
InsertEsimData(const std::string & iccId,int32_t esimLabel,const std::string & operatorName)1379 int32_t SimManager::InsertEsimData(const std::string &iccId, int32_t esimLabel, const std::string &operatorName)
1380 {
1381     if (multiSimController_ == nullptr) {
1382         TELEPHONY_LOGE("multiSimController_ is nullptr");
1383         return INVALID_VALUE;
1384     }
1385     int32_t ret = multiSimController_->InsertEsimData(iccId, esimLabel, operatorName);
1386     if (ret == TELEPHONY_ERR_SUCCESS && multiSimMonitor_ != nullptr) {
1387         multiSimMonitor_->NotifySimAccountChanged();
1388     }
1389     return ret;
1390 }
1391 
SetSimLabelIndex(const std::string & iccId,int32_t labelIndex)1392 int32_t SimManager::SetSimLabelIndex(const std::string &iccId, int32_t labelIndex)
1393 {
1394     if (multiSimController_ == nullptr) {
1395         TELEPHONY_LOGE("multiSimController_ is nullptr");
1396         return INVALID_VALUE;
1397     }
1398     int32_t ret = multiSimController_->SetSimLabelIndex(iccId, labelIndex);
1399     if (ret == TELEPHONY_ERR_SUCCESS && multiSimMonitor_ != nullptr) {
1400         multiSimMonitor_->NotifySimAccountChanged();
1401     }
1402     return ret;
1403 }
1404 
NotifySimSlotsMapping(int32_t slotId)1405 int32_t SimManager::NotifySimSlotsMapping(int32_t slotId)
1406 {
1407     if (!HasSimCardInner(slotId)) {
1408         TELEPHONY_LOGE("NotifySimSlotsMapping has no sim card!");
1409         return TELEPHONY_ERR_NO_SIM_CARD;
1410     }
1411     multiSimController_->isSimSlotsMapping_[slotId] = true;
1412     return simStateManager_[slotId]->NotifySimSlotsMapping(slotId);
1413 }
1414 
GetAllSimAccountInfoList(bool denied,std::vector<IccAccountInfo> & iccAccountInfoList)1415 int32_t SimManager::GetAllSimAccountInfoList(bool denied, std::vector<IccAccountInfo> &iccAccountInfoList)
1416 {
1417     if (multiSimController_ == nullptr) {
1418         TELEPHONY_LOGE("multiSimController_ is nullptr");
1419         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1420     }
1421     return multiSimController_->GetAllSimAccountInfoList(denied, iccAccountInfoList);
1422 }
1423 } // namespace Telephony
1424 } // namespace OHOS