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_file.h"
17
18 #include <unistd.h>
19
20 #include "common_event_manager.h"
21 #include "common_event_support.h"
22 #include "radio_event.h"
23 #include "telephony_common_utils.h"
24
25 using namespace std;
26 using namespace OHOS::AppExecFwk;
27 using namespace OHOS::EventFwk;
28
29 namespace OHOS {
30 namespace Telephony {
31 std::mutex IccFile::mtx_;
SimFile(const std::shared_ptr<AppExecFwk::EventRunner> & runner,std::shared_ptr<SimStateManager> simStateManager)32 SimFile::SimFile(
33 const std::shared_ptr<AppExecFwk::EventRunner> &runner, std::shared_ptr<SimStateManager> simStateManager)
34 : IccFile(runner, simStateManager)
35 {
36 fileQueried_ = false;
37 displayConditionOfSpn_ = SPN_INVALID;
38 InitMemberFunc();
39 }
40
StartLoad()41 void SimFile::StartLoad()
42 {
43 TELEPHONY_LOGI("SimFile::StartLoad() start");
44 LoadSimFiles();
45 }
46
ObtainSimOperator()47 std::string SimFile::ObtainSimOperator()
48 {
49 if (operatorNumeric_.empty()) {
50 std::string imsi = ObtainIMSI();
51 if (imsi.empty()) {
52 TELEPHONY_LOGE("SimFile ObtainSimOperator: IMSI is null");
53 return "";
54 }
55 if ((lengthOfMnc_ == UNINITIALIZED_MNC) || (lengthOfMnc_ == UNKNOWN_MNC)) {
56 TELEPHONY_LOGE("SimFile ObtainSimOperator: mncLength invalid");
57 return "";
58 }
59 int length = MCC_LEN + lengthOfMnc_;
60 int imsiLen = static_cast<int>(imsi.size());
61 operatorNumeric_ = ((imsiLen >= length) ? imsi.substr(0, MCC_LEN + lengthOfMnc_) : "");
62 }
63 return operatorNumeric_;
64 }
65
ObtainIsoCountryCode()66 std::string SimFile::ObtainIsoCountryCode()
67 {
68 std::string numeric = ObtainSimOperator();
69 if (numeric.empty()) {
70 TELEPHONY_LOGE("SimFile ObtainIsoCountryCode: numeric is null");
71 return "";
72 }
73 int len = static_cast<int>(numeric.length());
74 std::string mcc = numeric.substr(0, MCC_LEN);
75 if (len >= MCC_LEN && IsValidDecValue(mcc)) {
76 std::string iso = MccPool::MccCountryCode(std::stoi(mcc));
77 return iso;
78 } else {
79 return "";
80 }
81 }
82
ObtainCallForwardStatus()83 int SimFile::ObtainCallForwardStatus()
84 {
85 return callForwardStatus_;
86 }
87
UpdateMsisdnNumber(const std::string & alphaTag,const std::string & number,const AppExecFwk::InnerEvent::Pointer & onComplete)88 void SimFile::UpdateMsisdnNumber(
89 const std::string &alphaTag, const std::string &number, const AppExecFwk::InnerEvent::Pointer &onComplete)
90 {}
91
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)92 void SimFile::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
93 {
94 if (event == nullptr) {
95 TELEPHONY_LOGE("event is nullptr!");
96 return;
97 }
98 auto id = event->GetInnerEventId();
99 TELEPHONY_LOGI("SimFile::ProcessEvent id %{public}d", id);
100 auto itFunc = memberFuncMap_.find(id);
101 if (itFunc != memberFuncMap_.end()) {
102 auto memberFunc = itFunc->second;
103 if (memberFunc != nullptr) {
104 bool isFileProcessResponse = (this->*memberFunc)(event);
105 ProcessFileLoaded(isFileProcessResponse);
106 }
107 } else {
108 IccFile::ProcessEvent(event);
109 }
110 }
111
ProcessIccRefresh(int msgId)112 void SimFile::ProcessIccRefresh(int msgId)
113 {
114 switch (msgId) {
115 case ELEMENTARY_FILE_MBDN:
116 fileToGet_++;
117 break;
118 case ELEMENTARY_FILE_MAILBOX_CPHS:
119 fileToGet_++;
120 break;
121 case ELEMENTARY_FILE_CSP_CPHS:
122 fileToGet_++;
123 break;
124 case ELEMENTARY_FILE_FDN:
125 break;
126 case ELEMENTARY_FILE_MSISDN:
127 fileToGet_++;
128 break;
129 case ELEMENTARY_FILE_CFIS:
130 case ELEMENTARY_FILE_CFF_CPHS:
131 break;
132 default:
133 LoadSimFiles();
134 break;
135 }
136 }
137
ProcessFileLoaded(bool response)138 void SimFile::ProcessFileLoaded(bool response)
139 {
140 if (!response) {
141 return;
142 }
143 fileToGet_ -= LOAD_STEP;
144 TELEPHONY_LOGI("SimFile ProcessFileLoaded Done: %{public}d requested: %{public}d", fileToGet_, fileQueried_);
145 if (ObtainFilesFetched()) {
146 OnAllFilesFetched();
147 } else if (LockQueriedOrNot()) {
148 UpdateSimLanguage();
149 } else if (fileToGet_ < 0) {
150 fileToGet_ = 0;
151 }
152 }
153
OnAllFilesFetched()154 void SimFile::OnAllFilesFetched()
155 {
156 UpdateSimLanguage();
157 UpdateLoaded(true);
158 TELEPHONY_LOGI("SimFile SimFile::OnAllFilesFetched: start notify");
159 if (filesFetchedObser_ != nullptr) {
160 filesFetchedObser_->NotifyObserver(RadioEvent::RADIO_SIM_RECORDS_LOADED, slotId_);
161 }
162 PublishSimFileEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED, ICC_STATE_LOADED, "");
163 }
164
ProcessIccReady(const AppExecFwk::InnerEvent::Pointer & event)165 bool SimFile::ProcessIccReady(const AppExecFwk::InnerEvent::Pointer &event)
166 {
167 TELEPHONY_LOGI("SimFile::SIM_STATE_READY received");
168 CardType cardType = stateManager_->GetCardType();
169 if (cardType == CardType::SINGLE_MODE_USIM_CARD || cardType == CardType::SINGLE_MODE_SIM_CARD) {
170 LoadSimFiles();
171 } else {
172 TELEPHONY_LOGI("invalid SimFile::SIM_STATE_READY received %{public}d", cardType);
173 }
174 return false;
175 }
176
ProcessIccLocked(const AppExecFwk::InnerEvent::Pointer & event)177 bool SimFile::ProcessIccLocked(const AppExecFwk::InnerEvent::Pointer &event)
178 {
179 TELEPHONY_LOGI("only fetch ELEMENTARY_FILE_LI, ELEMENTARY_FILE_PL and ELEMENTARY_FILE_ICCID in locked state");
180 lockQueried_ = true;
181 AppExecFwk::InnerEvent::Pointer eventIccId = BuildCallerInfo(MSG_SIM_OBTAIN_ICCID_DONE);
182 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_ICCID, eventIccId);
183 fileToGet_++;
184 return false;
185 }
186
ObtainCallForwardFiles()187 void SimFile::ObtainCallForwardFiles()
188 {
189 fileQueried_ = true;
190
191 AppExecFwk::InnerEvent::Pointer eventCFIS = BuildCallerInfo(MSG_SIM_OBTAIN_CFIS_DONE);
192 fileController_->ObtainLinearFixedFile(ELEMENTARY_FILE_CFIS, 1, eventCFIS);
193 fileToGet_++;
194
195 AppExecFwk::InnerEvent::Pointer eventCFF = BuildCallerInfo(MSG_SIM_OBTAIN_CFF_DONE);
196 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_CFF_CPHS, eventCFF);
197 fileToGet_++;
198 }
199
LoadSimFiles()200 void SimFile::LoadSimFiles()
201 {
202 TELEPHONY_LOGI("SimFile LoadSimFiles started");
203 fileQueried_ = true;
204
205 AppExecFwk::InnerEvent::Pointer eventIMSI = BuildCallerInfo(MSG_SIM_OBTAIN_IMSI_DONE);
206 telRilManager_->GetImsi(slotId_, eventIMSI);
207 fileToGet_++;
208
209 AppExecFwk::InnerEvent::Pointer eventIccId = BuildCallerInfo(MSG_SIM_OBTAIN_ICCID_DONE);
210 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_ICCID, eventIccId);
211 fileToGet_++;
212
213 AppExecFwk::InnerEvent::Pointer eventSpn = AppExecFwk::InnerEvent::Pointer(nullptr, nullptr);
214 ObtainSpnPhase(true, eventSpn);
215
216 AppExecFwk::InnerEvent::Pointer eventGid1 = BuildCallerInfo(MSG_SIM_OBTAIN_GID1_DONE);
217 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_GID1, eventGid1);
218 fileToGet_++;
219
220 AppExecFwk::InnerEvent::Pointer eventGid2 = BuildCallerInfo(MSG_SIM_OBTAIN_GID2_DONE);
221 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_GID2, eventGid2);
222 fileToGet_++;
223
224 AppExecFwk::InnerEvent::Pointer eventPnn = BuildCallerInfo(MSG_SIM_OBTAIN_PNN_DONE);
225 fileController_->ObtainAllLinearFixedFile(ELEMENTARY_FILE_PNN, eventPnn);
226 fileToGet_++;
227
228 AppExecFwk::InnerEvent::Pointer eventOpl = BuildCallerInfo(MSG_SIM_OBTAIN_OPL_DONE);
229 fileController_->ObtainAllLinearFixedFile(ELEMENTARY_FILE_OPL, eventOpl);
230 fileToGet_++;
231
232 AppExecFwk::InnerEvent::Pointer phoneNumberEvent =
233 CreateDiallingNumberPointer(MSG_SIM_OBTAIN_MSISDN_DONE, 0, 0, nullptr);
234 diallingNumberHandler_->GetDiallingNumbers(
235 ELEMENTARY_FILE_MSISDN, ObtainExtensionElementaryFile(ELEMENTARY_FILE_MSISDN), 1, phoneNumberEvent);
236 fileToGet_++;
237
238 AppExecFwk::InnerEvent::Pointer eventMBI = BuildCallerInfo(MSG_SIM_OBTAIN_MBI_DONE);
239 fileController_->ObtainLinearFixedFile(ELEMENTARY_FILE_MBI, 1, eventMBI);
240 fileToGet_++;
241
242 AppExecFwk::InnerEvent::Pointer eventAD = BuildCallerInfo(MSG_SIM_OBTAIN_AD_DONE);
243 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_AD, eventAD);
244 fileToGet_++;
245 }
246
ObtainSpnPhase(bool start,const AppExecFwk::InnerEvent::Pointer & event)247 void SimFile::ObtainSpnPhase(bool start, const AppExecFwk::InnerEvent::Pointer &event)
248 {
249 SpnStatus curStatus = spnStatus_;
250 if (!IsContinueGetSpn(start, curStatus, spnStatus_)) {
251 return;
252 }
253
254 TELEPHONY_LOGI("SimFile::ObtainSpnPhase state is %{public}d", spnStatus_);
255 if (spnStatus_ == OBTAIN_SPN_START) {
256 StartObtainSpn();
257 } else if (spnStatus_ == OBTAIN_SPN_GENERAL) {
258 ProcessSpnGeneral(event);
259 } else if (spnStatus_ == OBTAIN_OPERATOR_NAMESTRING) {
260 ProcessSpnCphs(event);
261 } else if (spnStatus_ == OBTAIN_OPERATOR_NAME_SHORTFORM) {
262 ProcessSpnShortCphs(event);
263 } else {
264 spnStatus_ = SpnStatus::OBTAIN_SPN_NONE;
265 }
266 }
267
StartObtainSpn()268 void SimFile::StartObtainSpn()
269 {
270 UpdateSPN(IccFileController::NULLSTR);
271 AppExecFwk::InnerEvent::Pointer eventSPN = BuildCallerInfo(MSG_SIM_OBTAIN_SPN_DONE);
272 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_SPN, eventSPN);
273 fileToGet_++;
274 spnStatus_ = SpnStatus::OBTAIN_SPN_GENERAL;
275 }
276
ProcessSpnGeneral(const AppExecFwk::InnerEvent::Pointer & event)277 void SimFile::ProcessSpnGeneral(const AppExecFwk::InnerEvent::Pointer &event)
278 {
279 if (event == nullptr) {
280 TELEPHONY_LOGE("event is nullptr!");
281 return;
282 }
283 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
284 if (fd != nullptr && fd->exception == nullptr) {
285 std::string iccData = fd->resultData;
286 int length = 0;
287 std::shared_ptr<unsigned char> hexData = SIMUtils::HexStringConvertToBytes(iccData, length);
288 if (hexData != nullptr) {
289 unsigned char *byteData = hexData.get();
290 unsigned char value = byteData[0];
291 displayConditionOfSpn_ = (BYTE_NUM & value);
292 }
293 std::string str = ParseSpn(iccData, spnStatus_);
294 UpdateSPN(str);
295 std::string spn = ObtainSPN();
296 if (spn.empty() || !spn.size()) {
297 spnStatus_ = SpnStatus::OBTAIN_OPERATOR_NAMESTRING;
298 } else {
299 TELEPHONY_LOGI("SimFile Load Spn3Gpp done");
300 spnStatus_ = SpnStatus::OBTAIN_SPN_NONE;
301 }
302 } else {
303 spnStatus_ = SpnStatus::OBTAIN_OPERATOR_NAMESTRING;
304 }
305
306 if (spnStatus_ == SpnStatus::OBTAIN_OPERATOR_NAMESTRING) {
307 AppExecFwk::InnerEvent::Pointer eventCphs = BuildCallerInfo(MSG_SIM_OBTAIN_SPN_DONE);
308 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_SPN_CPHS, eventCphs);
309 fileToGet_++;
310 }
311 }
312
ProcessSpnCphs(const AppExecFwk::InnerEvent::Pointer & event)313 void SimFile::ProcessSpnCphs(const AppExecFwk::InnerEvent::Pointer &event)
314 {
315 if (event == nullptr) {
316 TELEPHONY_LOGE("event is nullptr!");
317 return;
318 }
319 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
320 if (fd != nullptr && fd->exception == nullptr) {
321 std::string iccData = fd->resultData;
322 UpdateSPN(ParseSpn(iccData, spnStatus_));
323 std::string spn = ObtainSPN();
324 if (spn.empty() || !spn.size()) {
325 spnStatus_ = SpnStatus::OBTAIN_OPERATOR_NAME_SHORTFORM;
326 } else {
327 displayConditionOfSpn_ = 0;
328 TELEPHONY_LOGI("SimFile Load ELEMENTARY_FILE_SPN_CPHS done: %{public}s", spn.c_str());
329 spnStatus_ = SpnStatus::OBTAIN_SPN_NONE;
330 }
331 } else {
332 spnStatus_ = SpnStatus::OBTAIN_OPERATOR_NAME_SHORTFORM;
333 }
334
335 if (spnStatus_ == SpnStatus::OBTAIN_OPERATOR_NAME_SHORTFORM) {
336 AppExecFwk::InnerEvent::Pointer eventShortCphs = BuildCallerInfo(MSG_SIM_OBTAIN_SPN_DONE);
337 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_SPN_SHORT_CPHS, eventShortCphs);
338 fileToGet_++;
339 }
340 }
341
ProcessSpnShortCphs(const AppExecFwk::InnerEvent::Pointer & event)342 void SimFile::ProcessSpnShortCphs(const AppExecFwk::InnerEvent::Pointer &event)
343 {
344 if (event == nullptr) {
345 TELEPHONY_LOGE("event is nullptr!");
346 return;
347 }
348 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
349 if (fd != nullptr && fd->exception == nullptr) {
350 std::string iccData = fd->resultData;
351 UpdateSPN(ParseSpn(iccData, spnStatus_));
352 std::string spn = ObtainSPN();
353 if (spn.empty() || !spn.size()) {
354 TELEPHONY_LOGI("SimFile No SPN loaded");
355 } else {
356 displayConditionOfSpn_ = 0;
357 TELEPHONY_LOGI("SimFile Load ELEMENTARY_FILE_SPN_SHORT_CPHS");
358 }
359 } else {
360 UpdateSPN(IccFileController::NULLSTR);
361 TELEPHONY_LOGI("SimFile No SPN get in either CHPS or 3GPP");
362 }
363 spnStatus_ = SpnStatus::OBTAIN_SPN_NONE;
364 }
365
ParseSpn(const std::string & rawData,int spnStatus)366 std::string SimFile::ParseSpn(const std::string &rawData, int spnStatus)
367 {
368 int offset = 0;
369 int length = 0;
370 std::shared_ptr<unsigned char> bytesRaw = SIMUtils::HexStringConvertToBytes(rawData, length);
371 std::shared_ptr<unsigned char> bytesNew = nullptr;
372 if (bytesRaw == nullptr) {
373 TELEPHONY_LOGI("ParseSpn invalid data: %{public}s", rawData.c_str());
374 return "";
375 }
376 if (spnStatus == OBTAIN_SPN_GENERAL) {
377 offset = 0;
378 length -= INVALID_BYTES_NUM;
379 bytesNew = std::shared_ptr<unsigned char>(
380 bytesRaw.get() + INVALID_BYTES_NUM, [bytesRaw](unsigned char *) {}); // first is 0, +1
381 } else if ((spnStatus == OBTAIN_OPERATOR_NAMESTRING) || (spnStatus == OBTAIN_OPERATOR_NAME_SHORTFORM)) {
382 offset = 0;
383 bytesNew = bytesRaw;
384 } else {
385 return "";
386 }
387 std::string ret = SIMUtils::DiallingNumberStringFieldConvertToString(bytesNew, offset, length, SPN_CHAR_POS);
388 TELEPHONY_LOGI("SimFile::ParseSpn success");
389 return ret;
390 }
391
ParsePnn(const std::vector<std::string> & records)392 void SimFile::ParsePnn(const std::vector<std::string> &records)
393 {
394 pnnFiles_.clear();
395 if (records.empty()) {
396 TELEPHONY_LOGI("ParsePnn records is empty");
397 return;
398 }
399 for (const auto &dataPnn : records) {
400 TELEPHONY_LOGI("ParsePnn: %{public}s", dataPnn.c_str());
401 int recordLen = 0;
402 std::shared_ptr<unsigned char> data = SIMUtils::HexStringConvertToBytes(dataPnn, recordLen);
403 if (data == nullptr) {
404 TELEPHONY_LOGI("ParsePnn data is nullptr");
405 continue;
406 }
407 unsigned char *tlv = data.get();
408 std::shared_ptr<PlmnNetworkName> file = std::make_shared<PlmnNetworkName>();
409 int tagAndLength = NETWORK_NAME_LENGTH + 1;
410 if (recordLen > tagAndLength) {
411 if (recordLen >= (tagAndLength + static_cast<int>(tlv[NETWORK_NAME_LENGTH])) &&
412 tlv[NETWORK_NAME_IEI] == (unsigned char)LONG_NAME_FLAG) {
413 file->longName =
414 SIMUtils::Gsm7bitConvertToString(tlv + NETWORK_NAME_TEXT_STRING, tlv[NETWORK_NAME_LENGTH] - 1);
415 }
416 int shortNameOffset = tagAndLength + tlv[NETWORK_NAME_LENGTH];
417 if (recordLen > (shortNameOffset + tagAndLength)) {
418 if (recordLen >= (shortNameOffset + tagAndLength +
419 static_cast<int>(tlv[shortNameOffset + NETWORK_NAME_LENGTH])) &&
420 tlv[shortNameOffset + NETWORK_NAME_IEI] == (unsigned char)SHORT_NAME_FLAG) {
421 file->shortName =
422 SIMUtils::Gsm7bitConvertToString(tlv + (shortNameOffset + NETWORK_NAME_TEXT_STRING),
423 tlv[shortNameOffset + NETWORK_NAME_LENGTH] - 1);
424 }
425 }
426 }
427 TELEPHONY_LOGI("longName: %{public}s, shortName: %{public}s", file->longName.c_str(), file->shortName.c_str());
428 if (!file->longName.empty() || !file->shortName.empty()) {
429 pnnFiles_.push_back(file);
430 }
431 }
432 }
433
ParseOpl(const std::vector<std::string> & records)434 void SimFile::ParseOpl(const std::vector<std::string> &records)
435 {
436 oplFiles_.clear();
437 if (records.empty()) {
438 TELEPHONY_LOGI("ParseOpl records is empty");
439 return;
440 }
441 for (const auto &dataOpl : records) {
442 TELEPHONY_LOGI("ParseOpl: %{public}s", dataOpl.c_str());
443 if (dataOpl.size() != (BYTE_LENGTH + BYTE_LENGTH)) {
444 continue;
445 }
446 std::string plmn = SIMUtils::BcdPlmnConvertToString(dataOpl, 0);
447 if (plmn.empty()) {
448 continue;
449 }
450 std::shared_ptr<OperatorPlmnInfo> file = std::make_shared<OperatorPlmnInfo>();
451 file->plmnNumeric = plmn;
452 int base = 16; // convert to hexadecimal
453 file->lacStart = stoi(dataOpl.substr(MCCMNC_LEN, HALF_BYTE_LEN), 0, base);
454 file->lacEnd = stoi(dataOpl.substr(MCCMNC_LEN + HALF_BYTE_LEN, HALF_BYTE_LEN), 0, base);
455 file->pnnRecordId = stoi(dataOpl.substr(MCCMNC_LEN + BYTE_LENGTH, HALF_LEN), 0, base);
456 TELEPHONY_LOGI("plmnNumeric: %{public}s, lacStart: %{public}d, lacEnd: %{public}d, pnnRecordId: %{public}d",
457 file->plmnNumeric.c_str(), file->lacStart, file->lacEnd, file->pnnRecordId);
458 oplFiles_.push_back(file);
459 }
460 }
461
ObtainUsimFunctionHandle()462 std::shared_ptr<UsimFunctionHandle> SimFile::ObtainUsimFunctionHandle()
463 {
464 return UsimFunctionHandle_;
465 }
466
UpdateSimLanguage()467 void SimFile::UpdateSimLanguage()
468 {
469 AppExecFwk::InnerEvent::Pointer eventLILAN = BuildCallerInfo(MSG_SIM_OBTAIN_LI_LANGUAGE_DONE);
470 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_LI, eventLILAN);
471 }
472
ProcessObtainLiLanguage(const AppExecFwk::InnerEvent::Pointer & event)473 bool SimFile::ProcessObtainLiLanguage(const AppExecFwk::InnerEvent::Pointer &event)
474 {
475 if (event == nullptr) {
476 TELEPHONY_LOGE("event is nullptr!");
477 return true;
478 }
479 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
480 if (fd != nullptr && fd->exception == nullptr) {
481 efLi_ = fd->resultData;
482 if (efLi_.empty() || !efLi_.size()) {
483 TELEPHONY_LOGI("efLi_ No language loaded");
484 AppExecFwk::InnerEvent::Pointer eventPLLAN = BuildCallerInfo(MSG_SIM_OBTAIN_PL_LANGUAGE_DONE);
485 fileController_->ObtainBinaryFile(ELEMENTARY_FILE_PL, eventPLLAN);
486 } else {
487 TELEPHONY_LOGI("efLi_ language loaded");
488 UpdateIccLanguage(efLi_, efPl_);
489 }
490 }
491 return true;
492 }
493
ProcessObtainPlLanguage(const AppExecFwk::InnerEvent::Pointer & event)494 bool SimFile::ProcessObtainPlLanguage(const AppExecFwk::InnerEvent::Pointer &event)
495 {
496 if (event == nullptr) {
497 TELEPHONY_LOGE("event is nullptr!");
498 return true;
499 }
500 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
501 if (fd != nullptr && fd->exception == nullptr) {
502 efPl_ = fd->resultData;
503 if (efPl_.empty() || !efPl_.size()) {
504 TELEPHONY_LOGI("efPl_ No language loaded");
505 } else {
506 TELEPHONY_LOGI("efPl_ language loaded");
507 UpdateIccLanguage(efLi_, efPl_);
508 }
509 }
510 return true;
511 }
512
AnalysisBcdPlmn(std::string data,std::string description)513 std::string SimFile::AnalysisBcdPlmn(std::string data, std::string description)
514 {
515 return "";
516 }
517
ProcessElementaryFileCsp(std::string data)518 void SimFile::ProcessElementaryFileCsp(std::string data) {}
519
AnalysisElementaryFileSpdi(std::string data)520 void SimFile::AnalysisElementaryFileSpdi(std::string data) {}
521
ProcessSmses(std::string messages)522 void SimFile::ProcessSmses(std::string messages) {}
523
ProcessSms(std::string data)524 void SimFile::ProcessSms(std::string data) {}
525
ProcessObtainGid1Done(const AppExecFwk::InnerEvent::Pointer & event)526 bool SimFile::ProcessObtainGid1Done(const AppExecFwk::InnerEvent::Pointer &event)
527 {
528 bool isFileProcessResponse = true;
529 if (event == nullptr) {
530 TELEPHONY_LOGE("event is nullptr!");
531 return isFileProcessResponse;
532 }
533 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
534 if (fd == nullptr) {
535 TELEPHONY_LOGE("fd is nullptr!");
536 return isFileProcessResponse;
537 }
538 std::string iccData = fd->resultData;
539 char *rawData = const_cast<char *>(iccData.c_str());
540 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
541
542 if (fd->exception != nullptr) {
543 TELEPHONY_LOGE("SimFile failed in get GID1 ");
544 gid1_ = "";
545 return isFileProcessResponse;
546 }
547
548 gid1_ = iccData;
549 TELEPHONY_LOGI("SimFile GID1: %{public}s", fileData);
550 return isFileProcessResponse;
551 }
552
ProcessObtainGid2Done(const AppExecFwk::InnerEvent::Pointer & event)553 bool SimFile::ProcessObtainGid2Done(const AppExecFwk::InnerEvent::Pointer &event)
554 {
555 bool isFileProcessResponse = true;
556 if (event == nullptr) {
557 TELEPHONY_LOGE("event is nullptr!");
558 return isFileProcessResponse;
559 }
560 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
561 if (fd == nullptr) {
562 TELEPHONY_LOGE("fd is nullptr!");
563 return isFileProcessResponse;
564 }
565 std::string iccData = fd->resultData;
566 char *rawData = const_cast<char *>(iccData.c_str());
567 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
568
569 if (fd->exception != nullptr) {
570 TELEPHONY_LOGE("SimFile failed in get GID2 ");
571 gid2_ = "";
572 return isFileProcessResponse;
573 }
574
575 gid2_ = iccData;
576 TELEPHONY_LOGI("SimFile GID2: %{public}s", fileData);
577 return isFileProcessResponse;
578 }
579
ProcessGetMsisdnDone(const AppExecFwk::InnerEvent::Pointer & event)580 bool SimFile::ProcessGetMsisdnDone(const AppExecFwk::InnerEvent::Pointer &event)
581 {
582 bool isFileProcessResponse = true;
583 if (event == nullptr) {
584 TELEPHONY_LOGE("event is nullptr!");
585 return isFileProcessResponse;
586 }
587 std::unique_ptr<DiallingNumbersHandlerResult> fd = event->GetUniqueObject<DiallingNumbersHandlerResult>();
588 if (fd == nullptr) {
589 TELEPHONY_LOGE("fd is nullptr!");
590 return isFileProcessResponse;
591 }
592 std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::static_pointer_cast<DiallingNumbersInfo>(fd->result);
593 if (fd->exception != nullptr) {
594 TELEPHONY_LOGE("SimFile Invalid or missing EF[MSISDN]");
595 return isFileProcessResponse;
596 }
597 msisdn_ = Str16ToStr8(diallingNumber->GetNumber());
598 msisdnTag_ = Str16ToStr8(diallingNumber->GetName());
599 return isFileProcessResponse;
600 }
601
ProcessSetMsisdnDone(const AppExecFwk::InnerEvent::Pointer & event)602 bool SimFile::ProcessSetMsisdnDone(const AppExecFwk::InnerEvent::Pointer &event)
603 {
604 bool isFileProcessResponse = false;
605 if (event == nullptr) {
606 TELEPHONY_LOGE("event is nullptr!");
607 return isFileProcessResponse;
608 }
609 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
610 if (fd == nullptr) {
611 TELEPHONY_LOGE("fd is nullptr!");
612 return isFileProcessResponse;
613 }
614 std::string iccData = fd->resultData;
615 if (fd->exception == nullptr) {
616 msisdn_ = lastMsisdn_;
617 msisdnTag_ = lastMsisdnTag_;
618 TELEPHONY_LOGI("SimFile Success to update EF[MSISDN]");
619 }
620 return isFileProcessResponse;
621 }
622
ProcessGetSpdiDone(const AppExecFwk::InnerEvent::Pointer & event)623 bool SimFile::ProcessGetSpdiDone(const AppExecFwk::InnerEvent::Pointer &event)
624 {
625 bool isFileProcessResponse = true;
626 if (event == nullptr) {
627 TELEPHONY_LOGE("event is nullptr!");
628 return isFileProcessResponse;
629 }
630 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
631 if (fd == nullptr) {
632 TELEPHONY_LOGE("fd is nullptr!");
633 return isFileProcessResponse;
634 }
635 std::string iccData = fd->resultData;
636 char *rawData = const_cast<char *>(iccData.c_str());
637 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
638
639 if (fd->exception != nullptr) {
640 return isFileProcessResponse;
641 }
642 TELEPHONY_LOGI("SimFile MSG_SIM_OBTAIN_SPDI_DONE data:%{public}s", fileData);
643 AnalysisElementaryFileSpdi(iccData);
644 return isFileProcessResponse;
645 }
646
ProcessGetCfisDone(const AppExecFwk::InnerEvent::Pointer & event)647 bool SimFile::ProcessGetCfisDone(const AppExecFwk::InnerEvent::Pointer &event)
648 {
649 bool isFileProcessResponse = true;
650 if (event == nullptr) {
651 TELEPHONY_LOGE("event is nullptr!");
652 return isFileProcessResponse;
653 }
654 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
655 if (fd == nullptr) {
656 TELEPHONY_LOGE("fd is nullptr!");
657 return isFileProcessResponse;
658 }
659 std::string iccData = fd->resultData;
660 char *rawData = const_cast<char *>(iccData.c_str());
661 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
662
663 if (fd->exception != nullptr) {
664 efCfis_ = nullptr;
665 } else {
666 TELEPHONY_LOGI("ELEMENTARY_FILE_CFIS: %{public}s", fileData);
667 efCfis_ = fileData;
668 }
669 return isFileProcessResponse;
670 }
671
ProcessGetMbiDone(const AppExecFwk::InnerEvent::Pointer & event)672 bool SimFile::ProcessGetMbiDone(const AppExecFwk::InnerEvent::Pointer &event)
673 {
674 bool isFileProcessResponse = true;
675 if (event == nullptr) {
676 TELEPHONY_LOGE("event is nullptr!");
677 return isFileProcessResponse;
678 }
679 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
680 if (fd == nullptr) {
681 TELEPHONY_LOGE("fd is nullptr!");
682 return isFileProcessResponse;
683 }
684 std::string iccData = fd->resultData;
685 char *rawData = const_cast<char *>(iccData.c_str());
686 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
687 if (fd->exception == nullptr) {
688 int dataLen = 0;
689 std::shared_ptr<unsigned char> dataByte = SIMUtils::HexStringConvertToBytes(iccData, dataLen);
690 int index = (dataByte != nullptr) ? (dataByte.get()[0] & BYTE_NUM) : 0;
691 if (index != 0 && index != BYTE_NUM) {
692 indexOfMailbox_ = index;
693 TELEPHONY_LOGI("fetch valid mailbox number for MBDN");
694 }
695 }
696 TELEPHONY_LOGI("ELEMENTARY_FILE_MBI data is:%{public}s id: %{public}d", fileData, indexOfMailbox_);
697 fileToGet_ += LOAD_STEP;
698 AppExecFwk::InnerEvent::Pointer mbdnEvent = CreateDiallingNumberPointer(MSG_SIM_OBTAIN_MBDN_DONE, 0, 0, nullptr);
699 diallingNumberHandler_->GetDiallingNumbers(ELEMENTARY_FILE_MBDN, ELEMENTARY_FILE_EXT6, indexOfMailbox_, mbdnEvent);
700 return isFileProcessResponse;
701 }
702
ProcessGetMbdnDone(const AppExecFwk::InnerEvent::Pointer & event)703 bool SimFile::ProcessGetMbdnDone(const AppExecFwk::InnerEvent::Pointer &event)
704 {
705 bool isFileProcessResponse = true;
706 if (event == nullptr) {
707 TELEPHONY_LOGE("event is nullptr!");
708 return isFileProcessResponse;
709 }
710 std::unique_ptr<DiallingNumbersHandlerResult> fd = event->GetUniqueObject<DiallingNumbersHandlerResult>();
711 if (fd == nullptr) {
712 TELEPHONY_LOGE("fd is nullptr!");
713 return isFileProcessResponse;
714 }
715 bool hasException = fd->exception == nullptr;
716 TELEPHONY_LOGI("ProcessGetMbdnDone start %{public}d", hasException);
717 voiceMailNum_ = IccFileController::NULLSTR;
718 voiceMailTag_ = IccFileController::NULLSTR;
719 if (fd->exception != nullptr) {
720 TELEPHONY_LOGE("SimFile failed missing EF MBDN");
721 GetCphsMailBox();
722 return isFileProcessResponse;
723 }
724 std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::static_pointer_cast<DiallingNumbersInfo>(fd->result);
725 if (diallingNumber == nullptr) {
726 TELEPHONY_LOGE("ProcessGetMbdnDone get null diallingNumber!!");
727 return isFileProcessResponse;
728 }
729
730 if (diallingNumber->IsEmpty()) {
731 GetCphsMailBox();
732 return isFileProcessResponse;
733 }
734 voiceMailNum_ = Str16ToStr8(diallingNumber->GetNumber());
735 voiceMailTag_ = Str16ToStr8(diallingNumber->GetName());
736 TELEPHONY_LOGI("ProcessGetMbdnDone success");
737 return isFileProcessResponse;
738 }
739
ProcessGetCphsMailBoxDone(const AppExecFwk::InnerEvent::Pointer & event)740 bool SimFile::ProcessGetCphsMailBoxDone(const AppExecFwk::InnerEvent::Pointer &event)
741 {
742 bool isFileProcessResponse = true;
743 if (event == nullptr) {
744 TELEPHONY_LOGE("event is nullptr!");
745 return isFileProcessResponse;
746 }
747 std::unique_ptr<DiallingNumbersHandlerResult> fd = event->GetUniqueObject<DiallingNumbersHandlerResult>();
748 if (fd == nullptr) {
749 TELEPHONY_LOGE("fd is nullptr!");
750 return isFileProcessResponse;
751 }
752 bool hasException = fd->exception == nullptr;
753 TELEPHONY_LOGI("ProcessGetCphsMailBoxDone start %{public}d", hasException);
754 voiceMailNum_ = IccFileController::NULLSTR;
755 voiceMailTag_ = IccFileController::NULLSTR;
756 if (fd->exception != nullptr) {
757 TELEPHONY_LOGE("SimFile failed missing CPHS MAILBOX");
758 return isFileProcessResponse;
759 }
760 std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::static_pointer_cast<DiallingNumbersInfo>(fd->result);
761 if (diallingNumber == nullptr) {
762 TELEPHONY_LOGE("GetCphsMailBoxDone get null diallingNumber!!");
763 return isFileProcessResponse;
764 }
765
766 voiceMailNum_ = Str16ToStr8(diallingNumber->GetNumber());
767 voiceMailTag_ = Str16ToStr8(diallingNumber->GetName());
768 TELEPHONY_LOGI("GetCphsMailBoxDone success");
769 return isFileProcessResponse;
770 }
771
GetCphsMailBox()772 void SimFile::GetCphsMailBox()
773 {
774 fileToGet_ += LOAD_STEP;
775 AppExecFwk::InnerEvent::Pointer cphsEvent =
776 CreateDiallingNumberPointer(MSG_SIM_OBTAIN_CPHS_MAILBOX_DONE, 0, 0, nullptr);
777 diallingNumberHandler_->GetDiallingNumbers(ELEMENTARY_FILE_MAILBOX_CPHS, ELEMENTARY_FILE_EXT1, 1, cphsEvent);
778 }
779
ProcessGetMwisDone(const AppExecFwk::InnerEvent::Pointer & event)780 bool SimFile::ProcessGetMwisDone(const AppExecFwk::InnerEvent::Pointer &event)
781 {
782 bool isFileProcessResponse = true;
783 if (event == nullptr) {
784 TELEPHONY_LOGE("event is nullptr!");
785 return isFileProcessResponse;
786 }
787 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
788 if (fd == nullptr) {
789 TELEPHONY_LOGE("fd is nullptr!");
790 return isFileProcessResponse;
791 }
792 std::string iccData = fd->resultData;
793 char *rawData = const_cast<char *>(iccData.c_str());
794 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
795 TELEPHONY_LOGI("SimFile ELEMENTARY_FILE_MWIS : %{public}s", rawData);
796 if (fd->exception != nullptr) {
797 TELEPHONY_LOGE("MSG_SIM_OBTAIN_MWIS_DONE exception = ");
798 return isFileProcessResponse;
799 }
800 unsigned char value = fileData[0];
801 if ((value & BYTE_NUM) == BYTE_NUM) {
802 TELEPHONY_LOGI("SimFiles: Uninitialized record MWIS");
803 return isFileProcessResponse;
804 }
805 efMWIS_ = fileData;
806 return isFileProcessResponse;
807 }
808
ProcessVoiceMailCphs(const AppExecFwk::InnerEvent::Pointer & event)809 bool SimFile::ProcessVoiceMailCphs(const AppExecFwk::InnerEvent::Pointer &event)
810 {
811 bool isFileProcessResponse = true;
812 if (event == nullptr) {
813 TELEPHONY_LOGE("event is nullptr!");
814 return isFileProcessResponse;
815 }
816 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
817 if (fd == nullptr) {
818 TELEPHONY_LOGE("fd is nullptr!");
819 return isFileProcessResponse;
820 }
821 std::string iccData = fd->resultData;
822 char *rawData = const_cast<char *>(iccData.c_str());
823 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
824 TELEPHONY_LOGI("SimFile ELEMENTARY_FILE_CPHS_MWI: %{public}s", rawData);
825 if (fd->exception != nullptr) {
826 TELEPHONY_LOGE("MSG_SIM_OBTAIN_VOICE_MAIL_INDICATOR_CPHS_DONE exception = ");
827 return isFileProcessResponse;
828 }
829 efCphsMwi_ = fileData;
830 return isFileProcessResponse;
831 }
832
ProcessGetIccIdDone(const AppExecFwk::InnerEvent::Pointer & event)833 bool SimFile::ProcessGetIccIdDone(const AppExecFwk::InnerEvent::Pointer &event)
834 {
835 bool isFileProcessResponse = true;
836 if (event == nullptr) {
837 TELEPHONY_LOGE("event is nullptr!");
838 return isFileProcessResponse;
839 }
840 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
841 if (fd == nullptr) {
842 TELEPHONY_LOGE("fd is nullptr!");
843 return isFileProcessResponse;
844 }
845 if (fd->exception == nullptr) {
846 std::string iccData = fd->resultData;
847 TELEPHONY_LOGI("SimFile::ProcessEvent ICCID result success");
848 iccId_ = iccData;
849 }
850 return isFileProcessResponse;
851 }
852
ProcessObtainIMSIDone(const AppExecFwk::InnerEvent::Pointer & event)853 bool SimFile::ProcessObtainIMSIDone(const AppExecFwk::InnerEvent::Pointer &event)
854 {
855 bool isFileProcessResponse = true;
856 if (event == nullptr) {
857 TELEPHONY_LOGE("event is nullptr!");
858 return isFileProcessResponse;
859 }
860 std::shared_ptr<std::string> sharedObject = event->GetSharedObject<std::string>();
861 if (sharedObject == nullptr) {
862 TELEPHONY_LOGE("fd is nullptr!");
863 return isFileProcessResponse;
864 }
865 if (sharedObject != nullptr) {
866 imsi_ = *sharedObject;
867 TELEPHONY_LOGI("SimFile::ProcessEvent IMSI received success");
868 SaveCountryCode();
869 TELEPHONY_LOGI("SimFile::ObtainIsoCountryCode result success");
870 if (!imsi_.empty()) {
871 imsiReadyObser_->NotifyObserver(RadioEvent::RADIO_IMSI_LOADED_READY);
872 }
873 }
874 return isFileProcessResponse;
875 }
876
ProcessGetCffDone(const AppExecFwk::InnerEvent::Pointer & event)877 bool SimFile::ProcessGetCffDone(const AppExecFwk::InnerEvent::Pointer &event)
878 {
879 bool isFileProcessResponse = true;
880 if (event == nullptr) {
881 TELEPHONY_LOGE("event is nullptr!");
882 return isFileProcessResponse;
883 }
884 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
885 if (fd == nullptr) {
886 TELEPHONY_LOGE("fd is nullptr!");
887 return isFileProcessResponse;
888 }
889 std::string iccData = fd->resultData;
890 char *rawData = const_cast<char *>(iccData.c_str());
891 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
892 if (fd->exception != nullptr) {
893 efCff_ = nullptr;
894 } else {
895 TELEPHONY_LOGI("SimFile ELEMENTARY_FILE_CFF_CPHS: %{public}s", rawData);
896 efCff_ = fileData;
897 }
898 return isFileProcessResponse;
899 }
900
ProcessGetAdDone(const AppExecFwk::InnerEvent::Pointer & event)901 bool SimFile::ProcessGetAdDone(const AppExecFwk::InnerEvent::Pointer &event)
902 {
903 bool isFileProcessResponse = true;
904 if (event == nullptr) {
905 TELEPHONY_LOGE("event is nullptr!");
906 return isFileProcessResponse;
907 }
908 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
909 if (fd == nullptr) {
910 TELEPHONY_LOGE("fd is nullptr!");
911 return isFileProcessResponse;
912 }
913 std::string iccData = fd->resultData;
914 bool doneData = true;
915 if (!ObtainIMSI().empty()) {
916 std::string imsi = ObtainIMSI();
917 int mcc = atoi(imsi.substr(0, MCC_LEN).c_str());
918 lengthOfMnc_ = MccPool::ShortestMncLengthFromMcc(mcc);
919 TELEPHONY_LOGI("SimFile [TestMode] lengthOfMnc_= %{public}d", lengthOfMnc_);
920 } else {
921 char *rawData = const_cast<char *>(iccData.c_str());
922 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
923 if (fd->exception != nullptr) {
924 doneData = false;
925 }
926 TELEPHONY_LOGI("SimFile ELEMENTARY_FILE_AD: %{public}s", rawData);
927 int dataSize = static_cast<int>(iccData.size());
928 if (dataSize <= MCC_LEN) {
929 TELEPHONY_LOGI("SimFile MNC length dataSize = %{public}d", dataSize);
930 doneData = false;
931 }
932 if (doneData) {
933 lengthOfMnc_ = fileData[MCC_LEN] & 0xf;
934 TELEPHONY_LOGI("setting4 lengthOfMnc_= %{public}d", lengthOfMnc_);
935 }
936 }
937
938 if (doneData && (lengthOfMnc_ == 0xf)) {
939 lengthOfMnc_ = UNKNOWN_MNC;
940 } else if (doneData && (lengthOfMnc_ != MNC_LEN) && (lengthOfMnc_ != MCC_LEN)) {
941 lengthOfMnc_ = UNINITIALIZED_MNC;
942 }
943 TELEPHONY_LOGI("update5 length Mnc_= %{public}d", lengthOfMnc_);
944 CheckMncLength();
945 return isFileProcessResponse;
946 }
947
CheckMncLength()948 void SimFile::CheckMncLength()
949 {
950 std::string imsi = ObtainIMSI();
951 int imsiSize = static_cast<int>(imsi.size());
952 if (((lengthOfMnc_ == UNINITIALIZED_MNC) || (lengthOfMnc_ == UNKNOWN_MNC) || (lengthOfMnc_ == MNC_LEN)) &&
953 ((!imsi.empty()) && (imsiSize >= MCCMNC_LEN))) {
954 std::string mccMncCode = imsi.substr(0, MCCMNC_LEN);
955 TELEPHONY_LOGI("SimFile mccMncCode= %{public}s", mccMncCode.c_str());
956 if (MccPool::LengthIsThreeMnc(mccMncCode)) {
957 lengthOfMnc_ = MCC_LEN;
958 TELEPHONY_LOGI("SimFile update6 lengthOfMnc_= %{public}d", lengthOfMnc_);
959 }
960 }
961
962 if (lengthOfMnc_ == UNKNOWN_MNC || lengthOfMnc_ == UNINITIALIZED_MNC) {
963 if (!imsi.empty()) {
964 int mcc = atoi(imsi.substr(0, MCC_LEN).c_str());
965 lengthOfMnc_ = MccPool::ShortestMncLengthFromMcc(mcc);
966 TELEPHONY_LOGI("SimFile update7 lengthOfMnc_= %{public}d", lengthOfMnc_);
967 } else {
968 lengthOfMnc_ = UNKNOWN_MNC;
969 TELEPHONY_LOGI(
970 "MNC length not present in ELEMENTARY_FILE_AD setting9 lengthOfMnc_= %{public}d", lengthOfMnc_);
971 }
972 }
973 int lenNum = MCC_LEN + lengthOfMnc_;
974 int sz = static_cast<int>(imsi.size());
975 bool cond = sz >= lenNum;
976 if ((!imsi.empty()) && (lengthOfMnc_ != UNKNOWN_MNC) && cond) {
977 operatorNumeric_ = imsi.substr(0, lenNum);
978 }
979 }
980
ProcessSmsOnSim(const AppExecFwk::InnerEvent::Pointer & event)981 bool SimFile::ProcessSmsOnSim(const AppExecFwk::InnerEvent::Pointer &event)
982 {
983 bool isFileProcessResponse = false;
984 if (event == nullptr) {
985 TELEPHONY_LOGE("event is nullptr!");
986 return isFileProcessResponse;
987 }
988 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
989 if (fd == nullptr) {
990 TELEPHONY_LOGE("fd is nullptr!");
991 return isFileProcessResponse;
992 }
993 std::string iccData = fd->resultData;
994 int index = atoi(iccData.c_str());
995 if (fd->exception != nullptr || index == INVALID_VALUE) {
996 TELEPHONY_LOGE("exception on SMS_ON_SIM with index: %{public}d", index);
997 } else {
998 TELEPHONY_LOGI("READ ELEMENTARY_FILE_SMS RECORD index= %{public}d", index);
999 AppExecFwk::InnerEvent::Pointer eventSMS = BuildCallerInfo(MSG_SIM_OBTAIN_SMS_DONE);
1000 fileController_->ObtainLinearFixedFile(ELEMENTARY_FILE_SMS, index, eventSMS);
1001 }
1002 return isFileProcessResponse;
1003 }
1004
ProcessGetAllSmsDone(const AppExecFwk::InnerEvent::Pointer & event)1005 bool SimFile::ProcessGetAllSmsDone(const AppExecFwk::InnerEvent::Pointer &event)
1006 {
1007 bool isFileProcessResponse = true;
1008 if (event == nullptr) {
1009 TELEPHONY_LOGE("event is nullptr!");
1010 return isFileProcessResponse;
1011 }
1012 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1013 if (fd == nullptr) {
1014 TELEPHONY_LOGE("fd is nullptr!");
1015 return isFileProcessResponse;
1016 }
1017 std::string iccData = fd->resultData;
1018 if (fd->exception != nullptr) {
1019 return isFileProcessResponse;
1020 }
1021 ProcessSmses(iccData);
1022 return isFileProcessResponse;
1023 }
1024
ProcessGetSmsDone(const AppExecFwk::InnerEvent::Pointer & event)1025 bool SimFile::ProcessGetSmsDone(const AppExecFwk::InnerEvent::Pointer &event)
1026 {
1027 bool isFileProcessResponse = false;
1028 if (event == nullptr) {
1029 TELEPHONY_LOGE("event is nullptr!");
1030 return isFileProcessResponse;
1031 }
1032 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1033 if (fd == nullptr) {
1034 TELEPHONY_LOGE("fd is nullptr!");
1035 return isFileProcessResponse;
1036 }
1037 std::string iccData = fd->resultData;
1038 if (fd->exception == nullptr) {
1039 ProcessSms(iccData);
1040 } else {
1041 TELEPHONY_LOGI("SimFile exception on GET_SMS ");
1042 }
1043 return isFileProcessResponse;
1044 }
1045
ProcessGetPlmnActDone(const AppExecFwk::InnerEvent::Pointer & event)1046 bool SimFile::ProcessGetPlmnActDone(const AppExecFwk::InnerEvent::Pointer &event)
1047 {
1048 bool isFileProcessResponse = true;
1049 if (event == nullptr) {
1050 TELEPHONY_LOGE("event is nullptr!");
1051 return isFileProcessResponse;
1052 }
1053 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1054 if (fd == nullptr) {
1055 TELEPHONY_LOGE("fd is nullptr!");
1056 return isFileProcessResponse;
1057 }
1058 std::string iccData = fd->resultData;
1059 char *rawData = const_cast<char *>(iccData.c_str());
1060 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
1061
1062 if (fd->exception != nullptr || iccData.empty()) {
1063 TELEPHONY_LOGE("Failed fetch User PLMN ");
1064 } else {
1065 TELEPHONY_LOGI("fetch a PlmnRAT, iccData= %{public}s", fileData);
1066 }
1067 return isFileProcessResponse;
1068 }
1069
1070 // Process operator plmn
ProcessGetOplmnActDone(const AppExecFwk::InnerEvent::Pointer & event)1071 bool SimFile::ProcessGetOplmnActDone(const AppExecFwk::InnerEvent::Pointer &event)
1072 {
1073 bool isFileProcessResponse = true;
1074 if (event == nullptr) {
1075 TELEPHONY_LOGE("event is nullptr!");
1076 return isFileProcessResponse;
1077 }
1078 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1079 if (fd == nullptr) {
1080 TELEPHONY_LOGE("fd is nullptr!");
1081 return isFileProcessResponse;
1082 }
1083 std::string iccData = fd->resultData;
1084 char *rawData = const_cast<char *>(iccData.c_str());
1085 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
1086
1087 if (fd->exception != nullptr || iccData.empty()) {
1088 TELEPHONY_LOGE("Failed fetch Operator PLMN");
1089 } else {
1090 TELEPHONY_LOGI("fetch a OPlmnRAT, iccData= %{public}s", fileData);
1091 }
1092 return isFileProcessResponse;
1093 }
1094
ProcessGetCspCphs(const AppExecFwk::InnerEvent::Pointer & event)1095 bool SimFile::ProcessGetCspCphs(const AppExecFwk::InnerEvent::Pointer &event)
1096 {
1097 bool isFileProcessResponse = true;
1098 if (event == nullptr) {
1099 TELEPHONY_LOGE("event is nullptr!");
1100 return isFileProcessResponse;
1101 }
1102 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1103 if (fd == nullptr) {
1104 TELEPHONY_LOGE("fd is nullptr!");
1105 return isFileProcessResponse;
1106 }
1107 std::string iccData = fd->resultData;
1108 char *rawData = const_cast<char *>(iccData.c_str());
1109 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
1110
1111 if (fd->exception != nullptr) {
1112 TELEPHONY_LOGE("Exception to get ELEMENTARY_FILE_CSP data ");
1113 return isFileProcessResponse;
1114 }
1115 TELEPHONY_LOGI("SimFile MSG_SIM_OBTAIN_CSP_CPHS_DONE data:%{public}s", fileData);
1116 TELEPHONY_LOGI("ELEMENTARY_FILE_CSP: %{public}s", fileData);
1117 ProcessElementaryFileCsp(iccData);
1118 return isFileProcessResponse;
1119 }
1120
ProcessGetInfoCphs(const AppExecFwk::InnerEvent::Pointer & event)1121 bool SimFile::ProcessGetInfoCphs(const AppExecFwk::InnerEvent::Pointer &event)
1122 {
1123 bool isFileProcessResponse = true;
1124 if (event == nullptr) {
1125 TELEPHONY_LOGE("event is nullptr!");
1126 return isFileProcessResponse;
1127 }
1128 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1129 if (fd == nullptr) {
1130 TELEPHONY_LOGE("fd is nullptr!");
1131 return isFileProcessResponse;
1132 }
1133 if (fd->exception != nullptr) {
1134 return isFileProcessResponse;
1135 }
1136 cphsInfo_ = fd->resultData;
1137 TELEPHONY_LOGI("SimFile::ProcessGetInfoCphs success");
1138 return isFileProcessResponse;
1139 }
1140
ProcessGetSstDone(const AppExecFwk::InnerEvent::Pointer & event)1141 bool SimFile::ProcessGetSstDone(const AppExecFwk::InnerEvent::Pointer &event)
1142 {
1143 bool isFileProcessResponse = true;
1144 if (event == nullptr) {
1145 TELEPHONY_LOGE("event is nullptr!");
1146 return isFileProcessResponse;
1147 }
1148 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1149 if (fd == nullptr) {
1150 TELEPHONY_LOGE("fd is nullptr!");
1151 return isFileProcessResponse;
1152 }
1153 std::string iccData = fd->resultData;
1154 char *rawData = const_cast<char *>(iccData.c_str());
1155 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
1156
1157 if (fd->exception != nullptr) {
1158 return isFileProcessResponse;
1159 }
1160 TELEPHONY_LOGI("SimFile MSG_SIM_OBTAIN_SST_DONE data:%{public}s", fileData);
1161 return isFileProcessResponse;
1162 }
1163
ProcessGetPnnDone(const AppExecFwk::InnerEvent::Pointer & event)1164 bool SimFile::ProcessGetPnnDone(const AppExecFwk::InnerEvent::Pointer &event)
1165 {
1166 TELEPHONY_LOGI("ProcessGetPnnDone: start");
1167 bool isFileProcessResponse = true;
1168 if (event == nullptr) {
1169 TELEPHONY_LOGE("event is nullptr!");
1170 return isFileProcessResponse;
1171 }
1172 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1173 if (fd != nullptr) {
1174 if (fd->exception != nullptr) {
1175 TELEPHONY_LOGE("ProcessGetPnnDone: get error result");
1176 return isFileProcessResponse;
1177 }
1178 } else {
1179 std::shared_ptr<MultiRecordResult> object = event->GetSharedObject<MultiRecordResult>();
1180 if (object != nullptr) {
1181 TELEPHONY_LOGI("ProcessGetPnnDone: %{public}d", object->resultLength);
1182 if (object->exception == nullptr) {
1183 ParsePnn(object->fileResults);
1184 }
1185 for (std::string str : object->fileResults) {
1186 TELEPHONY_LOGI("ProcessGetPnnDone: %{public}s", str.c_str());
1187 }
1188 } else {
1189 TELEPHONY_LOGE("ProcessGetPnnDone: get null pointer!!!");
1190 }
1191 }
1192 return isFileProcessResponse;
1193 }
1194
ProcessGetOplDone(const AppExecFwk::InnerEvent::Pointer & event)1195 bool SimFile::ProcessGetOplDone(const AppExecFwk::InnerEvent::Pointer &event)
1196 {
1197 TELEPHONY_LOGI("ProcessGetOplDone: start");
1198 bool isFileProcessResponse = true;
1199 if (event == nullptr) {
1200 TELEPHONY_LOGE("event is nullptr!");
1201 return isFileProcessResponse;
1202 }
1203 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1204 if (fd != nullptr) {
1205 if (fd->exception != nullptr) {
1206 TELEPHONY_LOGE("ProcessGetOplDone: get error result");
1207 return isFileProcessResponse;
1208 }
1209 } else {
1210 std::shared_ptr<MultiRecordResult> object = event->GetSharedObject<MultiRecordResult>();
1211 if (object != nullptr) {
1212 TELEPHONY_LOGI("ProcessGetOplDone: %{public}d", object->resultLength);
1213 if (object->exception == nullptr) {
1214 ParseOpl(object->fileResults);
1215 }
1216 for (std::string str : object->fileResults) {
1217 TELEPHONY_LOGI("ProcessGetOplDone: %{public}s", str.c_str());
1218 }
1219 } else {
1220 TELEPHONY_LOGE("ProcessGetOplDone: get null pointer!!!");
1221 }
1222 }
1223 return isFileProcessResponse;
1224 }
1225
ProcessUpdateDone(const AppExecFwk::InnerEvent::Pointer & event)1226 bool SimFile::ProcessUpdateDone(const AppExecFwk::InnerEvent::Pointer &event)
1227 {
1228 bool isFileProcessResponse = false;
1229 if (event == nullptr) {
1230 TELEPHONY_LOGE("event is nullptr!");
1231 return isFileProcessResponse;
1232 }
1233 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1234 if (fd == nullptr) {
1235 TELEPHONY_LOGE("fd is nullptr!");
1236 return isFileProcessResponse;
1237 }
1238 std::string iccData = fd->resultData;
1239 if (fd->exception != nullptr) {
1240 TELEPHONY_LOGE("SimFile failed to update");
1241 }
1242 return isFileProcessResponse;
1243 }
1244
ProcessSetCphsMailbox(const AppExecFwk::InnerEvent::Pointer & event)1245 bool SimFile::ProcessSetCphsMailbox(const AppExecFwk::InnerEvent::Pointer &event)
1246 {
1247 bool isFileProcessResponse = true;
1248 if (event == nullptr) {
1249 TELEPHONY_LOGE("event is nullptr!");
1250 return isFileProcessResponse;
1251 }
1252 std::unique_ptr<DiallingNumbersHandlerResult> fd = event->GetUniqueObject<DiallingNumbersHandlerResult>();
1253 std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::static_pointer_cast<DiallingNumbersInfo>(fd->result);
1254 if (fd->exception == nullptr) {
1255 voiceMailNum_ = Str16ToStr8(diallingNumber->GetNumber());
1256 voiceMailTag_ = Str16ToStr8(diallingNumber->GetName());
1257 waitResult_ = true;
1258 processWait_.notify_all();
1259 TELEPHONY_LOGI("set cphs voicemail success");
1260 } else {
1261 processWait_.notify_all();
1262 TELEPHONY_LOGE("set cphs voicemail failed with exception!!");
1263 }
1264 return isFileProcessResponse;
1265 }
1266
1267 // Process forbidden PLMNs
ProcessGetHplmActDone(const AppExecFwk::InnerEvent::Pointer & event)1268 bool SimFile::ProcessGetHplmActDone(const AppExecFwk::InnerEvent::Pointer &event)
1269 {
1270 bool isFileProcessResponse = true;
1271 if (event == nullptr) {
1272 TELEPHONY_LOGE("event is nullptr!");
1273 return isFileProcessResponse;
1274 }
1275 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1276 if (fd == nullptr) {
1277 TELEPHONY_LOGE("fd is nullptr!");
1278 return isFileProcessResponse;
1279 }
1280 std::string iccData = fd->resultData;
1281 char *rawData = const_cast<char *>(iccData.c_str());
1282 unsigned char *fileData = reinterpret_cast<unsigned char *>(rawData);
1283
1284 if (fd->exception != nullptr || iccData.empty()) {
1285 TELEPHONY_LOGE("Failed to fetch forbidden PLMN");
1286 return isFileProcessResponse;
1287 } else {
1288 TELEPHONY_LOGI("fetch a FPlmnRAT, iccData=%{public}s", fileData);
1289 }
1290 return isFileProcessResponse;
1291 }
1292
1293 // Process Equivalent Home PLMNs
ProcessGetEhplmnDone(const AppExecFwk::InnerEvent::Pointer & event)1294 bool SimFile::ProcessGetEhplmnDone(const AppExecFwk::InnerEvent::Pointer &event)
1295 {
1296 bool isFileProcessResponse = true;
1297 if (event == nullptr) {
1298 TELEPHONY_LOGE("event is nullptr!");
1299 return isFileProcessResponse;
1300 }
1301 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1302 if (fd == nullptr) {
1303 TELEPHONY_LOGE("fd is nullptr!");
1304 return isFileProcessResponse;
1305 }
1306 std::string iccData = fd->resultData;
1307 if (fd->exception != nullptr || iccData.empty()) {
1308 TELEPHONY_LOGE("Failed fetch Equivalent Home PLMNs");
1309 return isFileProcessResponse;
1310 }
1311 return isFileProcessResponse;
1312 }
1313
1314 // Process forbidden PLMNs
ProcessGetFplmnDone(const AppExecFwk::InnerEvent::Pointer & event)1315 bool SimFile::ProcessGetFplmnDone(const AppExecFwk::InnerEvent::Pointer &event)
1316 {
1317 bool loadResponse = true;
1318 if (event == nullptr) {
1319 TELEPHONY_LOGE("event is nullptr!");
1320 return loadResponse;
1321 }
1322 std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
1323 if (fd == nullptr) {
1324 TELEPHONY_LOGE("fd is nullptr!");
1325 return loadResponse;
1326 }
1327 std::string iccData = fd->resultData;
1328 if (fd->exception != nullptr || iccData.empty()) {
1329 TELEPHONY_LOGE("Failed to get forbidden PLMNs");
1330 return loadResponse;
1331 }
1332 if (fd->arg1 == ICC_CONTROLLER_REQ_SEND_RESPONSE) {
1333 TELEPHONY_LOGI("getForbiddenPlmns and send result");
1334 loadResponse = false;
1335 }
1336 return loadResponse;
1337 }
1338
ProcessSetMbdn(const AppExecFwk::InnerEvent::Pointer & event)1339 bool SimFile::ProcessSetMbdn(const AppExecFwk::InnerEvent::Pointer &event)
1340 {
1341 bool isFileProcessResponse = true;
1342 if (event == nullptr) {
1343 TELEPHONY_LOGE("event is nullptr!");
1344 return isFileProcessResponse;
1345 }
1346 bool hasNotify = false;
1347 std::unique_ptr<DiallingNumbersHandlerResult> fd = event->GetUniqueObject<DiallingNumbersHandlerResult>();
1348 std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::static_pointer_cast<DiallingNumbersInfo>(fd->result);
1349 if (fd->exception == nullptr) {
1350 voiceMailNum_ = Str16ToStr8(diallingNumber->GetNumber());
1351 voiceMailTag_ = Str16ToStr8(diallingNumber->GetName());
1352 waitResult_ = true;
1353 processWait_.notify_all();
1354 hasNotify = true;
1355 TELEPHONY_LOGI("set voicemail name success");
1356 }
1357
1358 if (CphsVoiceMailAvailable()) {
1359 std::shared_ptr<DiallingNumbersInfo> diallingNumberCphs = std::make_shared<DiallingNumbersInfo>();
1360 diallingNumberCphs->name_ = Str8ToStr16(voiceMailNum_);
1361 diallingNumberCphs->number_ = Str8ToStr16(voiceMailTag_);
1362 AppExecFwk::InnerEvent::Pointer eventCphs =
1363 CreateDiallingNumberPointer(MSG_SIM_SET_CPHS_MAILBOX_DONE, 0, 0, nullptr);
1364 DiallingNumberUpdateInfor infor;
1365 infor.diallingNumber = diallingNumberCphs;
1366 infor.fileId = ELEMENTARY_FILE_MAILBOX_CPHS;
1367 infor.extFile = ELEMENTARY_FILE_EXT1;
1368 infor.index = 1;
1369 diallingNumberHandler_->UpdateDiallingNumbers(infor, eventCphs);
1370 TELEPHONY_LOGI("set cphs voicemail number as it is available");
1371 } else {
1372 if (!hasNotify) {
1373 processWait_.notify_all();
1374 }
1375 TELEPHONY_LOGI("set voicemail number finished");
1376 }
1377 return isFileProcessResponse;
1378 }
1379
ProcessMarkSms(const AppExecFwk::InnerEvent::Pointer & event)1380 bool SimFile::ProcessMarkSms(const AppExecFwk::InnerEvent::Pointer &event)
1381 {
1382 (void)event;
1383 return false;
1384 }
1385
ProcessObtainSpnPhase(const AppExecFwk::InnerEvent::Pointer & event)1386 bool SimFile::ProcessObtainSpnPhase(const AppExecFwk::InnerEvent::Pointer &event)
1387 {
1388 bool loadResponse = true;
1389 if (event == nullptr) {
1390 TELEPHONY_LOGE("event is nullptr!");
1391 return loadResponse;
1392 }
1393 ObtainSpnPhase(false, event);
1394 return loadResponse;
1395 }
1396
IsContinueGetSpn(bool start,SpnStatus curStatus,SpnStatus & newStatus)1397 bool SimFile::IsContinueGetSpn(bool start, SpnStatus curStatus, SpnStatus &newStatus)
1398 {
1399 if (start) {
1400 switch (curStatus) {
1401 case OBTAIN_SPN_GENERAL:
1402 case OBTAIN_OPERATOR_NAMESTRING:
1403 case OBTAIN_OPERATOR_NAME_SHORTFORM:
1404 case OBTAIN_SPN_START:
1405 newStatus = SpnStatus::OBTAIN_SPN_START;
1406 return false;
1407 default:
1408 newStatus = SpnStatus::OBTAIN_SPN_START;
1409 return true;
1410 }
1411 } else {
1412 return true;
1413 }
1414 }
1415
InitMemberFunc()1416 void SimFile::InitMemberFunc()
1417 {
1418 memberFuncMap_[RadioEvent::RADIO_SIM_STATE_READY] = &SimFile::ProcessIccReady;
1419 memberFuncMap_[RadioEvent::RADIO_SIM_STATE_LOCKED] = &SimFile::ProcessIccLocked;
1420 memberFuncMap_[RadioEvent::RADIO_SIM_STATE_SIMLOCK] = &SimFile::ProcessIccLocked;
1421 memberFuncMap_[MSG_SIM_OBTAIN_IMSI_DONE] = &SimFile::ProcessObtainIMSIDone;
1422 memberFuncMap_[MSG_SIM_OBTAIN_ICCID_DONE] = &SimFile::ProcessGetIccIdDone;
1423 memberFuncMap_[MSG_SIM_OBTAIN_MBI_DONE] = &SimFile::ProcessGetMbiDone;
1424 memberFuncMap_[MSG_SIM_OBTAIN_CPHS_MAILBOX_DONE] = &SimFile::ProcessGetCphsMailBoxDone;
1425 memberFuncMap_[MSG_SIM_OBTAIN_MBDN_DONE] = &SimFile::ProcessGetMbdnDone;
1426 memberFuncMap_[MSG_SIM_OBTAIN_MSISDN_DONE] = &SimFile::ProcessGetMsisdnDone;
1427 memberFuncMap_[MSG_SIM_SET_MSISDN_DONE] = &SimFile::ProcessSetMsisdnDone;
1428 memberFuncMap_[MSG_SIM_OBTAIN_MWIS_DONE] = &SimFile::ProcessGetMwisDone;
1429 memberFuncMap_[MSG_SIM_OBTAIN_VOICE_MAIL_INDICATOR_CPHS_DONE] = &SimFile::ProcessVoiceMailCphs;
1430 memberFuncMap_[MSG_SIM_OBTAIN_AD_DONE] = &SimFile::ProcessGetAdDone;
1431 memberFuncMap_[MSG_SIM_OBTAIN_SPN_DONE] = &SimFile::ProcessObtainSpnPhase;
1432 memberFuncMap_[MSG_SIM_OBTAIN_LI_LANGUAGE_DONE] = &SimFile::ProcessObtainLiLanguage;
1433 memberFuncMap_[MSG_SIM_OBTAIN_PL_LANGUAGE_DONE] = &SimFile::ProcessObtainPlLanguage;
1434 memberFuncMap_[MSG_SIM_OBTAIN_CFF_DONE] = &SimFile::ProcessGetCffDone;
1435 memberFuncMap_[MSG_SIM_OBTAIN_SPDI_DONE] = &SimFile::ProcessGetSpdiDone;
1436 memberFuncMap_[MSG_SIM_UPDATE_DONE] = &SimFile::ProcessUpdateDone;
1437 memberFuncMap_[MSG_SIM_OBTAIN_PNN_DONE] = &SimFile::ProcessGetPnnDone;
1438 memberFuncMap_[MSG_SIM_OBTAIN_OPL_DONE] = &SimFile::ProcessGetOplDone;
1439 memberFuncMap_[MSG_SIM_OBTAIN_ALL_SMS_DONE] = &SimFile::ProcessGetAllSmsDone;
1440 memberFuncMap_[MSG_SIM_MARK_SMS_READ_DONE] = &SimFile::ProcessMarkSms;
1441 memberFuncMap_[MSG_SIM_SMS_ON_SIM] = &SimFile::ProcessSmsOnSim;
1442 memberFuncMap_[MSG_SIM_OBTAIN_SMS_DONE] = &SimFile::ProcessGetSmsDone;
1443 memberFuncMap_[MSG_SIM_OBTAIN_SST_DONE] = &SimFile::ProcessGetSstDone;
1444 memberFuncMap_[MSG_SIM_OBTAIN_INFO_CPHS_DONE] = &SimFile::ProcessGetInfoCphs;
1445 memberFuncMap_[MSG_SIM_SET_MBDN_DONE] = &SimFile::ProcessSetMbdn;
1446 memberFuncMap_[MSG_SIM_SET_CPHS_MAILBOX_DONE] = &SimFile::ProcessSetCphsMailbox;
1447 memberFuncMap_[MSG_SIM_OBTAIN_CFIS_DONE] = &SimFile::ProcessGetCfisDone;
1448 memberFuncMap_[MSG_SIM_OBTAIN_CSP_CPHS_DONE] = &SimFile::ProcessGetCspCphs;
1449 memberFuncMap_[MSG_SIM_OBTAIN_GID1_DONE] = &SimFile::ProcessObtainGid1Done;
1450 memberFuncMap_[MSG_SIM_OBTAIN_GID2_DONE] = &SimFile::ProcessObtainGid2Done;
1451 memberFuncMap_[MSG_SIM_OBTAIN_PLMN_W_ACT_DONE] = &SimFile::ProcessGetPlmnActDone;
1452 memberFuncMap_[MSG_SIM_OBTAIN_OPLMN_W_ACT_DONE] = &SimFile::ProcessGetOplmnActDone;
1453 memberFuncMap_[MSG_SIM_OBTAIN_HPLMN_W_ACT_DONE] = &SimFile::ProcessGetHplmActDone;
1454 memberFuncMap_[MSG_SIM_OBTAIN_EHPLMN_DONE] = &SimFile::ProcessGetEhplmnDone;
1455 memberFuncMap_[MSG_SIM_OBTAIN_FPLMN_DONE] = &SimFile::ProcessGetFplmnDone;
1456 }
1457
ObtainSpnCondition(bool roaming,const std::string & operatorNum)1458 int SimFile::ObtainSpnCondition(bool roaming, const std::string &operatorNum)
1459 {
1460 unsigned int cond = 0;
1461 if (displayConditionOfSpn_ <= SPN_INVALID) {
1462 return cond;
1463 }
1464 if (roaming) {
1465 cond = SPN_CONDITION_DISPLAY_PLMN;
1466 if ((static_cast<unsigned int>(displayConditionOfSpn_) & static_cast<unsigned int>(SPN_COND)) == 0) {
1467 cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_SPN);
1468 }
1469 } else {
1470 cond = SPN_CONDITION_DISPLAY_SPN;
1471 if ((static_cast<unsigned int>(displayConditionOfSpn_) & static_cast<unsigned int>(SPN_COND_PLMN)) ==
1472 SPN_COND_PLMN) {
1473 cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_PLMN);
1474 }
1475 }
1476 return cond;
1477 }
1478
ObtainExtensionElementaryFile(int ef)1479 int SimFile::ObtainExtensionElementaryFile(int ef)
1480 {
1481 int ext = 0;
1482 if (ef == ELEMENTARY_FILE_MSISDN) {
1483 ext = ELEMENTARY_FILE_EXT5; // ELEMENTARY_FILE_EXT1
1484 } else {
1485 ext = ELEMENTARY_FILE_EXT1;
1486 }
1487 return ext;
1488 }
1489
UpdateVoiceMail(const std::string & mailName,const std::string & mailNumber)1490 bool SimFile::UpdateVoiceMail(const std::string &mailName, const std::string &mailNumber)
1491 {
1492 waitResult_ = false;
1493 std::shared_ptr<DiallingNumbersInfo> diallingNumber = std::make_shared<DiallingNumbersInfo>();
1494 diallingNumber->name_ = Str8ToStr16(mailName);
1495 diallingNumber->number_ = Str8ToStr16(mailNumber);
1496
1497 if ((indexOfMailbox_) && (indexOfMailbox_ != BYTE_NUM)) {
1498 std::unique_lock<std::mutex> lock(IccFile::mtx_);
1499 TELEPHONY_LOGI("UpdateVoiceMail start MBDN");
1500 AppExecFwk::InnerEvent::Pointer event = CreateDiallingNumberPointer(MSG_SIM_SET_MBDN_DONE, 0, 0, nullptr);
1501 DiallingNumberUpdateInfor infor;
1502 infor.diallingNumber = diallingNumber;
1503 infor.fileId = ELEMENTARY_FILE_MBDN;
1504 infor.extFile = ELEMENTARY_FILE_EXT6;
1505 infor.index = indexOfMailbox_;
1506 diallingNumberHandler_->UpdateDiallingNumbers(infor, event);
1507 processWait_.wait(lock);
1508 } else if (CphsVoiceMailAvailable()) {
1509 std::unique_lock<std::mutex> lock(IccFile::mtx_);
1510 AppExecFwk::InnerEvent::Pointer event =
1511 CreateDiallingNumberPointer(MSG_SIM_SET_CPHS_MAILBOX_DONE, 0, 0, nullptr);
1512 DiallingNumberUpdateInfor infor;
1513 infor.diallingNumber = diallingNumber;
1514 infor.fileId = ELEMENTARY_FILE_MAILBOX_CPHS;
1515 infor.extFile = ELEMENTARY_FILE_EXT1;
1516 infor.index = 1;
1517 diallingNumberHandler_->UpdateDiallingNumbers(infor, event);
1518 processWait_.wait(lock);
1519 } else {
1520 TELEPHONY_LOGE("UpdateVoiceMail indexOfMailbox_ %{public}d is invalid!!", indexOfMailbox_);
1521 }
1522 TELEPHONY_LOGI("UpdateVoiceMail finished %{public}d", waitResult_);
1523 return waitResult_;
1524 }
1525
CphsVoiceMailAvailable()1526 bool SimFile::CphsVoiceMailAvailable()
1527 {
1528 bool available = false;
1529 if (!cphsInfo_.empty()) {
1530 int dataLen = 0;
1531 std::shared_ptr<unsigned char> dataByte = SIMUtils::HexStringConvertToBytes(cphsInfo_, dataLen);
1532 available = (dataByte != nullptr) ? (dataByte.get()[1] & CPHS_VOICE_MAIL_MASK) == CPHS_VOICE_MAIL_EXSIT : false;
1533 }
1534 return available;
1535 }
1536 } // namespace Telephony
1537 } // namespace OHOS
1538