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