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