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