• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 "telephony_errors.h"
19 #include "radio_event.h"
20 namespace OHOS {
21 namespace Telephony {
SimManager(std::shared_ptr<ITelRilManager> telRilManager)22 SimManager::SimManager(std::shared_ptr<ITelRilManager> telRilManager) : telRilManager_(telRilManager)
23 {
24     TELEPHONY_LOGI("SimManager::SimManager()");
25 }
26 
OnInit(int32_t slotCount)27 bool SimManager::OnInit(int32_t slotCount)
28 {
29     TELEPHONY_LOGI("SimManager OnInit, slotCount = %{public}d", slotCount);
30     slotCount_ = slotCount;
31     // Program memory
32     simStateManager_.resize(slotCount);
33     simFileManager_.resize(slotCount);
34     simSmsManager_.resize(slotCount);
35     simAccountManager_.resize(slotCount);
36     iccDiallingNumbersManager_.resize(slotCount);
37     stkManager_.resize(slotCount);
38     // Many card create
39     for (int32_t slotId = 0; slotId < slotCount; slotId++) {
40         simStateManager_[slotId] = std::make_shared<SimStateManager>(telRilManager_);
41         if (simStateManager_[slotId] != nullptr) {
42             simStateManager_[slotId]->Init(slotId);
43         }
44         simFileManager_[slotId] = SimFileManager::CreateInstance(telRilManager_, simStateManager_[slotId]);
45         if (simFileManager_[slotId] != nullptr) {
46             simFileManager_[slotId]->Init(slotId);
47         }
48         simSmsManager_[slotId] = std::make_shared<SimSmsManager>(
49             telRilManager_, simFileManager_[slotId], simStateManager_[slotId]);
50         if (simSmsManager_[slotId] != nullptr) {
51             simSmsManager_[slotId]->Init(slotId);
52         }
53         simAccountManager_[slotId] = std::make_shared<SimAccountManager>(
54             telRilManager_, simStateManager_[slotId], simFileManager_[slotId]);
55         if (simAccountManager_[slotId] != nullptr) {
56             simAccountManager_[slotId]->Init(slotId);
57         }
58         iccDiallingNumbersManager_[slotId] =
59             IccDiallingNumbersManager::CreateInstance(simFileManager_[slotId], simStateManager_[slotId]);
60         if (iccDiallingNumbersManager_[slotId] != nullptr) {
61             iccDiallingNumbersManager_[slotId]->Init();
62         }
63         stkManager_[slotId] = std::make_shared<StkManager>(telRilManager_, simStateManager_[slotId]);
64         if (stkManager_[slotId] != nullptr) {
65             stkManager_[slotId]->Init(slotId);
66         }
67         if (simStateManager_[DEFAULT_SIM_SLOT_ID] != nullptr && slotId == DEFAULT_SIM_SLOT_ID) {
68             simStateManager_[DEFAULT_SIM_SLOT_ID]->RefreshSimState(DEFAULT_SIM_SLOT_ID);
69         }
70     }
71     TELEPHONY_LOGI("SimManager OnInit success");
72     return true;
73 }
74 
SetNetworkSearchManager(int32_t slotCount,std::shared_ptr<INetworkSearch> networkSearchManager)75 void SimManager::SetNetworkSearchManager(int32_t slotCount, std::shared_ptr<INetworkSearch> networkSearchManager)
76 {
77     TELEPHONY_LOGI("SimManager::SetNetworkSearchManager");
78     for (int32_t slotId = 0; slotId < slotCount; slotId++) {
79         if (simAccountManager_[slotId] == nullptr) {
80             TELEPHONY_LOGE("SimManager::SetNetworkSearchManager failed by nullptr");
81             return;
82         }
83         simAccountManager_[slotId]->SetNetworkSearchManager(networkSearchManager);
84     }
85     return;
86 }
87 
HasSimCard(int32_t slotId)88 bool SimManager::HasSimCard(int32_t slotId)
89 {
90     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
91         TELEPHONY_LOGE("simStateManager is null!");
92         return false;
93     }
94     return simStateManager_[slotId]->HasSimCard();
95 }
96 
GetSimState(int32_t slotId)97 int32_t SimManager::GetSimState(int32_t slotId)
98 {
99     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
100         TELEPHONY_LOGE("simStateManager is null!");
101         return TELEPHONY_ERROR;
102     }
103     return static_cast<int32_t>(simStateManager_[slotId]->GetSimState());
104 }
105 
GetCardType(int32_t slotId)106 int32_t SimManager::GetCardType(int32_t slotId)
107 {
108     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
109         TELEPHONY_LOGE("simStateManager is null!");
110         return TELEPHONY_ERROR;
111     }
112     return static_cast<int32_t>(simStateManager_[slotId]->GetCardType());
113 }
114 
UnlockPin(int32_t slotId,std::string pin,LockStatusResponse & response)115 bool SimManager::UnlockPin(int32_t slotId, std::string pin, LockStatusResponse &response)
116 {
117     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
118         TELEPHONY_LOGE("simStateManager is null!");
119         return false;
120     }
121     return simStateManager_[slotId]->UnlockPin(slotId, pin, response);
122 }
123 
UnlockPuk(int32_t slotId,std::string newPin,std::string puk,LockStatusResponse & response)124 bool SimManager::UnlockPuk(int32_t slotId, std::string newPin, std::string puk, LockStatusResponse &response)
125 {
126     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
127         TELEPHONY_LOGE("simStateManager is null!");
128         return false;
129     }
130     return simStateManager_[slotId]->UnlockPuk(slotId, newPin, puk, response);
131 }
132 
AlterPin(int32_t slotId,std::string newPin,std::string oldPin,LockStatusResponse & response)133 bool SimManager::AlterPin(int32_t slotId, std::string newPin, std::string oldPin, LockStatusResponse &response)
134 {
135     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
136         TELEPHONY_LOGE("simStateManager is null!");
137         return false;
138     }
139     return simStateManager_[slotId]->AlterPin(slotId, newPin, oldPin, response);
140 }
141 
SetLockState(int32_t slotId,const LockInfo & options,LockStatusResponse & response)142 bool SimManager::SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response)
143 {
144     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
145         TELEPHONY_LOGE("simStateManager is null!");
146         return false;
147     }
148     return simStateManager_[slotId]->SetLockState(slotId, options, response);
149 }
150 
GetLockState(int32_t slotId,LockType lockType)151 int32_t SimManager::GetLockState(int32_t slotId, LockType lockType)
152 {
153     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
154         TELEPHONY_LOGE("simStateManager is null!");
155         return TELEPHONY_ERROR;
156     }
157     return simStateManager_[slotId]->GetLockState(slotId, lockType);
158 }
159 
RefreshSimState(int32_t slotId)160 int32_t SimManager::RefreshSimState(int32_t slotId)
161 {
162     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
163         TELEPHONY_LOGE("simStateManager is null!");
164         return TELEPHONY_ERROR;
165     }
166     return simStateManager_[slotId]->RefreshSimState(slotId);
167 }
168 
UnlockPin2(int32_t slotId,std::string pin2,LockStatusResponse & response)169 bool SimManager::UnlockPin2(int32_t slotId, std::string pin2, LockStatusResponse &response)
170 {
171     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
172         TELEPHONY_LOGE("simStateManager is null!");
173         return false;
174     }
175     return simStateManager_[slotId]->UnlockPin2(slotId, pin2, response);
176 }
177 
UnlockPuk2(int32_t slotId,std::string newPin2,std::string puk2,LockStatusResponse & response)178 bool SimManager::UnlockPuk2(int32_t slotId, std::string newPin2, std::string puk2, LockStatusResponse &response)
179 {
180     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
181         TELEPHONY_LOGE("simStateManager is null!");
182         return false;
183     }
184     return simStateManager_[slotId]->UnlockPuk2(slotId, newPin2, puk2, response);
185 }
186 
AlterPin2(int32_t slotId,std::string newPin2,std::string oldPin2,LockStatusResponse & response)187 bool SimManager::AlterPin2(int32_t slotId, std::string newPin2, std::string oldPin2, LockStatusResponse &response)
188 {
189     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
190         TELEPHONY_LOGE("simStateManager is null!");
191         return false;
192     }
193     return simStateManager_[slotId]->AlterPin2(slotId, newPin2, oldPin2, response);
194 }
195 
UnlockSimLock(int32_t slotId,const PersoLockInfo & lockInfo,LockStatusResponse & response)196 bool SimManager::UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response)
197 {
198     if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
199         TELEPHONY_LOGE("simStateManager is null!");
200         return false;
201     }
202     return simStateManager_[slotId]->UnlockSimLock(slotId, lockInfo, response);
203 }
204 
IsSimActive(int32_t slotId)205 bool SimManager::IsSimActive(int32_t slotId)
206 {
207     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
208         TELEPHONY_LOGE("simAccountManager is null!");
209         return false;
210     }
211     return simAccountManager_[slotId]->IsSimActive(slotId);
212 }
213 
SetActiveSim(int32_t slotId,int32_t enable)214 bool SimManager::SetActiveSim(int32_t slotId, int32_t enable)
215 {
216     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
217         TELEPHONY_LOGE("simAccountManager is null!");
218         return false;
219     }
220     return simAccountManager_[slotId]->SetActiveSim(slotId, enable);
221 }
222 
GetSimAccountInfo(int32_t slotId,IccAccountInfo & info)223 bool SimManager::GetSimAccountInfo(int32_t slotId, IccAccountInfo &info)
224 {
225     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
226         TELEPHONY_LOGE("simAccountManager is null!");
227         return false;
228     }
229     return simAccountManager_[slotId]->GetSimAccountInfo(slotId, info);
230 }
231 
SetDefaultVoiceSlotId(int32_t slotId)232 bool SimManager::SetDefaultVoiceSlotId(int32_t slotId)
233 {
234     if ((!IsValidSlotId(slotId)) || (simAccountManager_[DEFAULT_SIM_SLOT_ID] == nullptr)) {
235         TELEPHONY_LOGE("simAccountManager is null!");
236         return false;
237     }
238     return simAccountManager_[DEFAULT_SIM_SLOT_ID]->SetDefaultVoiceSlotId(slotId);
239 }
240 
SetDefaultSmsSlotId(int32_t slotId)241 bool SimManager::SetDefaultSmsSlotId(int32_t slotId)
242 {
243     if ((!IsValidSlotId(slotId)) || (simAccountManager_[DEFAULT_SIM_SLOT_ID] == nullptr)) {
244         TELEPHONY_LOGE("simAccountManager is null!");
245         return false;
246     }
247     return simAccountManager_[DEFAULT_SIM_SLOT_ID]->SetDefaultSmsSlotId(slotId);
248 }
249 
SetDefaultCellularDataSlotId(int32_t slotId)250 bool SimManager::SetDefaultCellularDataSlotId(int32_t slotId)
251 {
252     if ((!IsValidSlotId(slotId)) || (simAccountManager_[DEFAULT_SIM_SLOT_ID] == nullptr)) {
253         TELEPHONY_LOGE("simAccountManager is null!");
254         return false;
255     }
256     return simAccountManager_[DEFAULT_SIM_SLOT_ID]->SetDefaultCellularDataSlotId(slotId);
257 }
258 
SetPrimarySlotId(int32_t slotId)259 bool SimManager::SetPrimarySlotId(int32_t slotId)
260 {
261     if ((!IsValidSlotId(slotId)) || (simAccountManager_[DEFAULT_SIM_SLOT_ID] == nullptr)) {
262         TELEPHONY_LOGE("simAccountManager is null!");
263         return false;
264     }
265     return simAccountManager_[DEFAULT_SIM_SLOT_ID]->SetPrimarySlotId(slotId);
266 }
267 
SetShowNumber(int32_t slotId,const std::u16string number)268 bool SimManager::SetShowNumber(int32_t slotId, const std::u16string number)
269 {
270     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
271         TELEPHONY_LOGE("simAccountManager is null!");
272         return false;
273     }
274     return simAccountManager_[slotId]->SetShowNumber(slotId, number);
275 }
276 
SetShowName(int32_t slotId,const std::u16string name)277 bool SimManager::SetShowName(int32_t slotId, const std::u16string name)
278 {
279     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
280         TELEPHONY_LOGE("simAccountManager is null!");
281         return false;
282     }
283     return simAccountManager_[slotId]->SetShowName(slotId, name);
284 }
285 
GetDefaultVoiceSlotId()286 int32_t SimManager::GetDefaultVoiceSlotId()
287 {
288     if (simAccountManager_[DEFAULT_SIM_SLOT_ID] == nullptr) {
289         TELEPHONY_LOGE("simAccountManager is null!");
290         return TELEPHONY_ERROR;
291     }
292     return simAccountManager_[DEFAULT_SIM_SLOT_ID]->GetDefaultVoiceSlotId();
293 }
294 
GetDefaultSmsSlotId()295 int32_t SimManager::GetDefaultSmsSlotId()
296 {
297     if (simAccountManager_[DEFAULT_SIM_SLOT_ID] == nullptr) {
298         TELEPHONY_LOGE("simAccountManager is null!");
299         return TELEPHONY_ERROR;
300     }
301     return simAccountManager_[DEFAULT_SIM_SLOT_ID]->GetDefaultSmsSlotId();
302 }
303 
GetDefaultCellularDataSlotId()304 int32_t SimManager::GetDefaultCellularDataSlotId()
305 {
306     if (simAccountManager_[DEFAULT_SIM_SLOT_ID] == nullptr) {
307         TELEPHONY_LOGE("simAccountManager is null!");
308         return TELEPHONY_ERROR;
309     }
310     return simAccountManager_[DEFAULT_SIM_SLOT_ID]->GetDefaultCellularDataSlotId();
311 }
312 
GetPrimarySlotId()313 int32_t SimManager::GetPrimarySlotId()
314 {
315     if (simAccountManager_[DEFAULT_SIM_SLOT_ID] == nullptr) {
316         TELEPHONY_LOGE("simAccountManager is null!");
317         return TELEPHONY_ERROR;
318     }
319     return simAccountManager_[DEFAULT_SIM_SLOT_ID]->GetPrimarySlotId();
320 }
321 
GetShowNumber(int32_t slotId)322 std::u16string SimManager::GetShowNumber(int32_t slotId)
323 {
324     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
325         TELEPHONY_LOGE("simAccountManager is null!");
326         return u"";
327     }
328     return simAccountManager_[slotId]->GetShowNumber(slotId);
329 }
330 
GetShowName(int32_t slotId)331 std::u16string SimManager::GetShowName(int32_t slotId)
332 {
333     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
334         TELEPHONY_LOGE("simAccountManager is null!");
335         return u"";
336     }
337     return simAccountManager_[slotId]->GetShowName(slotId);
338 }
339 
GetActiveSimAccountInfoList(std::vector<IccAccountInfo> & iccAccountInfoList)340 bool SimManager::GetActiveSimAccountInfoList(std::vector<IccAccountInfo> &iccAccountInfoList)
341 {
342     if (simAccountManager_[DEFAULT_SIM_SLOT_ID] == nullptr) {
343         TELEPHONY_LOGE("simAccountManager is null!");
344         return false;
345     }
346     return simAccountManager_[DEFAULT_SIM_SLOT_ID]->GetActiveSimAccountInfoList(iccAccountInfoList);
347 }
348 
GetOperatorConfigs(int slotId,OperatorConfig & poc)349 bool SimManager::GetOperatorConfigs(int slotId, OperatorConfig &poc)
350 {
351     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
352         TELEPHONY_LOGE("simAccountManager is null!");
353         return false;
354     }
355     return simAccountManager_[slotId]->GetOperatorConfigs(slotId, poc);
356 }
357 
HasOperatorPrivileges(const int32_t slotId)358 bool SimManager::HasOperatorPrivileges(const int32_t slotId)
359 {
360     TELEPHONY_LOGI("SimManager::HasOperatorPrivileges slotId:%{public}d", slotId);
361     if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
362         TELEPHONY_LOGE("simAccountManager_ can not be null!");
363         return false;
364     }
365     return simAccountManager_[slotId]->HasOperatorPrivileges(slotId);
366 }
367 
SendEnvelopeCmd(int32_t slotId,const std::string & cmd)368 bool SimManager::SendEnvelopeCmd(int32_t slotId, const std::string &cmd)
369 {
370     if ((!IsValidSlotId(slotId)) || (stkManager_[slotId] == nullptr)) {
371         TELEPHONY_LOGE("stkManager is null!");
372         return false;
373     }
374     return stkManager_[slotId]->SendEnvelopeCmd(slotId, cmd);
375 }
376 
SendTerminalResponseCmd(int32_t slotId,const std::string & cmd)377 bool SimManager::SendTerminalResponseCmd(int32_t slotId, const std::string &cmd)
378 {
379     if ((!IsValidSlotId(slotId)) || (stkManager_[slotId] == nullptr)) {
380         TELEPHONY_LOGE("stkManager is null!");
381         return false;
382     }
383     return stkManager_[slotId]->SendTerminalResponseCmd(slotId, cmd);
384 }
385 
GetSimOperatorNumeric(int32_t slotId)386 std::u16string SimManager::GetSimOperatorNumeric(int32_t slotId)
387 {
388     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
389         TELEPHONY_LOGE("simFileManager is null!");
390         return u"";
391     }
392     return simFileManager_[slotId]->GetSimOperatorNumeric();
393 }
394 
GetISOCountryCodeForSim(int32_t slotId)395 std::u16string SimManager::GetISOCountryCodeForSim(int32_t slotId)
396 {
397     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
398         TELEPHONY_LOGE("simFileManager is null!");
399         return u"";
400     }
401     return simFileManager_[slotId]->GetISOCountryCodeForSim();
402 }
403 
GetSimSpn(int32_t slotId)404 std::u16string SimManager::GetSimSpn(int32_t slotId)
405 {
406     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
407         TELEPHONY_LOGE("simFileManager is null");
408         return std::u16string();
409     }
410     return simFileManager_[slotId]->GetSimSpn();
411 }
412 
GetSimIccId(int32_t slotId)413 std::u16string SimManager::GetSimIccId(int32_t slotId)
414 {
415     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
416         TELEPHONY_LOGE("simFileManager is null!");
417         return u"";
418     }
419     return simFileManager_[slotId]->GetSimIccId();
420 }
421 
GetIMSI(int32_t slotId)422 std::u16string SimManager::GetIMSI(int32_t slotId)
423 {
424     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
425         TELEPHONY_LOGE("simFileManager is null!");
426         return u"";
427     }
428     return simFileManager_[slotId]->GetIMSI();
429 }
430 
GetLocaleFromDefaultSim(int32_t slotId)431 std::u16string SimManager::GetLocaleFromDefaultSim(int32_t slotId)
432 {
433     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
434         TELEPHONY_LOGE("simFileManager is null!");
435         return u"";
436     }
437     return simFileManager_[slotId]->GetLocaleFromDefaultSim();
438 }
439 
GetSimGid1(int32_t slotId)440 std::u16string SimManager::GetSimGid1(int32_t slotId)
441 {
442     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
443         TELEPHONY_LOGE("simFileManager is null!");
444         return u"";
445     }
446     return simFileManager_[slotId]->GetSimGid1();
447 }
448 
GetSimTelephoneNumber(int32_t slotId)449 std::u16string SimManager::GetSimTelephoneNumber(int32_t slotId)
450 {
451     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
452         TELEPHONY_LOGE("simFileManager is null!");
453         return u"";
454     }
455     return simFileManager_[slotId]->GetSimTelephoneNumber();
456 }
457 
GetSimTeleNumberIdentifier(const int32_t slotId)458 std::u16string SimManager::GetSimTeleNumberIdentifier(const int32_t slotId)
459 {
460     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
461         TELEPHONY_LOGE("simFileManager is null!");
462         return u"";
463     }
464     return simFileManager_[slotId]->GetSimTeleNumberIdentifier();
465 }
466 
GetVoiceMailIdentifier(int32_t slotId)467 std::u16string SimManager::GetVoiceMailIdentifier(int32_t slotId)
468 {
469     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
470         TELEPHONY_LOGE("simFileManager is null!");
471         return u"";
472     }
473     return simFileManager_[slotId]->GetVoiceMailIdentifier();
474 }
475 
GetVoiceMailNumber(int32_t slotId)476 std::u16string SimManager::GetVoiceMailNumber(int32_t slotId)
477 {
478     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
479         TELEPHONY_LOGE("simFileManager is null!");
480         return u"";
481     }
482     return simFileManager_[slotId]->GetVoiceMailNumber();
483 }
484 
ObtainSpnCondition(int32_t slotId,bool roaming,std::string operatorNum)485 int32_t SimManager::ObtainSpnCondition(int32_t slotId, bool roaming, std::string operatorNum)
486 {
487     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
488         TELEPHONY_LOGE("simFileManager is null");
489         return TELEPHONY_ERROR;
490     }
491     return simFileManager_[slotId]->ObtainSpnCondition(roaming, operatorNum);
492 }
493 
SetVoiceMailInfo(int32_t slotId,const std::u16string & mailName,const std::u16string & mailNumber)494 bool SimManager::SetVoiceMailInfo(int32_t slotId, const std::u16string &mailName, const std::u16string &mailNumber)
495 {
496     if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
497         TELEPHONY_LOGE("simFileManager is null");
498         return false;
499     }
500     return simFileManager_[slotId]->SetVoiceMailInfo(mailName, mailNumber);
501 }
502 
AddSmsToIcc(int32_t slotId,int status,std::string & pdu,std::string & smsc)503 bool SimManager::AddSmsToIcc(int32_t slotId, int status, std::string &pdu, std::string &smsc)
504 {
505     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
506         TELEPHONY_LOGE("simSmsManager_ is null!");
507         return false;
508     }
509     return simSmsManager_[slotId]->AddSmsToIcc(status, pdu, smsc);
510 }
511 
UpdateSmsIcc(int32_t slotId,int index,int status,std::string & pduData,std::string & smsc)512 bool SimManager::UpdateSmsIcc(int32_t slotId, int index, int status, std::string &pduData, std::string &smsc)
513 {
514     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
515         TELEPHONY_LOGE("simSmsManager_ is null!");
516         return false;
517     }
518     return simSmsManager_[slotId]->UpdateSmsIcc(index, status, pduData, smsc);
519 }
520 
DelSmsIcc(int32_t slotId,int index)521 bool SimManager::DelSmsIcc(int32_t slotId, int index)
522 {
523     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
524         TELEPHONY_LOGE("simSmsManager_ is null!");
525         return false;
526     }
527     return simSmsManager_[slotId]->DelSmsIcc(index);
528 }
529 
ObtainAllSmsOfIcc(int32_t slotId)530 std::vector<std::string> SimManager::ObtainAllSmsOfIcc(int32_t slotId)
531 {
532     std::vector<std::string> result;
533     if ((!IsValidSlotId(slotId)) || (simSmsManager_[slotId] == nullptr)) {
534         TELEPHONY_LOGE("simSmsManager_ is null!");
535         return result;
536     }
537     return simSmsManager_[slotId]->ObtainAllSmsOfIcc();
538 }
539 
QueryIccDiallingNumbers(int slotId,int type)540 std::vector<std::shared_ptr<DiallingNumbersInfo>> SimManager::QueryIccDiallingNumbers(int slotId, int type)
541 {
542     std::vector<std::shared_ptr<DiallingNumbersInfo>> result;
543     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
544         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
545         return result;
546     }
547     return iccDiallingNumbersManager_[slotId]->QueryIccDiallingNumbers(type);
548 }
549 
AddIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)550 bool SimManager::AddIccDiallingNumbers(
551     int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
552 {
553     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
554         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
555         return false;
556     }
557     return iccDiallingNumbersManager_[slotId]->AddIccDiallingNumbers(type, diallingNumber);
558 }
559 
DelIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)560 bool SimManager::DelIccDiallingNumbers(
561     int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
562 {
563     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
564         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
565         return false;
566     }
567     return iccDiallingNumbersManager_[slotId]->DelIccDiallingNumbers(type, diallingNumber);
568 }
569 
UpdateIccDiallingNumbers(int slotId,int type,const std::shared_ptr<DiallingNumbersInfo> & diallingNumber)570 bool SimManager::UpdateIccDiallingNumbers(
571     int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber)
572 {
573     if ((!IsValidSlotId(slotId)) || (iccDiallingNumbersManager_[slotId] == nullptr)) {
574         TELEPHONY_LOGE("iccDiallingNumbersManager is null!");
575         return false;
576     }
577     return iccDiallingNumbersManager_[slotId]->UpdateIccDiallingNumbers(type, diallingNumber);
578 }
579 
RegisterCoreNotify(int32_t slotId,const std::shared_ptr<AppExecFwk::EventHandler> & handler,int what)580 void SimManager::RegisterCoreNotify(int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what)
581 {
582     if ((what >= RadioEvent::RADIO_IMSI_LOADED_READY) && (what <= RadioEvent::RADIO_SIM_RECORDS_LOADED)) {
583         if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
584             TELEPHONY_LOGE("simFileManager is null");
585             return;
586         }
587         simFileManager_[slotId]->RegisterCoreNotify(handler, what);
588     } else if ((what >= RadioEvent::RADIO_SIM_STATE_CHANGE) &&
589         (what <= RadioEvent::RADIO_SIM_STATE_SIMLOCK)) {
590         if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
591             TELEPHONY_LOGE("simStateManager_ is null");
592             return;
593         }
594         simStateManager_[slotId]->RegisterCoreNotify(handler, what);
595     } else if (what == RadioEvent::RADIO_SIM_ACCOUNT_LOADED) {
596         if ((!IsValidSlotId(slotId)) || (simAccountManager_[slotId] == nullptr)) {
597             TELEPHONY_LOGE("simAccountManager_ RegisterCoreNotify is null");
598             return;
599         }
600         simAccountManager_[slotId]->RegisterCoreNotify(handler, what);
601     } else {
602         TELEPHONY_LOGE("SimManager::RegisterCoreNotify faild");
603     }
604 }
605 
UnRegisterCoreNotify(int32_t slotId,const std::shared_ptr<AppExecFwk::EventHandler> & observerCallBack,int what)606 void SimManager::UnRegisterCoreNotify(
607     int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &observerCallBack, int what)
608 {
609     if (what >= RadioEvent::RADIO_IMSI_LOADED_READY && what <= RadioEvent::RADIO_SIM_RECORDS_LOADED) {
610         if ((!IsValidSlotId(slotId)) || (simFileManager_[slotId] == nullptr)) {
611             TELEPHONY_LOGE("simFileManager is null");
612             return;
613         }
614         simFileManager_[slotId]->UnRegisterCoreNotify(observerCallBack, what);
615     } else if (what >= RadioEvent::RADIO_SIM_STATE_CHANGE && what <= RadioEvent::RADIO_SIM_STATE_SIMLOCK) {
616         if ((!IsValidSlotId(slotId)) || (simStateManager_[slotId] == nullptr)) {
617             TELEPHONY_LOGE("simStateManager_ is null");
618             return;
619         }
620         simStateManager_[slotId]->UnRegisterCoreNotify(observerCallBack, what);
621     } else {
622         TELEPHONY_LOGE("SimManager::UnRegisterCoreNotify faild");
623     }
624 }
625 
IsValidSlotId(int32_t slotId)626 bool SimManager::IsValidSlotId(int32_t slotId)
627 {
628     if ((slotId < SLOT_ID_ZERO) || (slotId >= slotCount_)) {
629         TELEPHONY_LOGE("slotId is invalid, slotId = %{public}d", slotId);
630         return false;
631     }
632     TELEPHONY_LOGI("slotId is valid, slotId = %{public}d", slotId);
633     return true;
634 }
635 
~SimManager()636 SimManager::~SimManager() {}
637 } // namespace Telephony
638 } // namespace OHOS
639