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 #ifndef OHOS_SIM_FILE_H 17 #define OHOS_SIM_FILE_H 18 19 #include "icc_file.h" 20 21 namespace OHOS { 22 namespace Telephony { 23 class SimFile : public IccFile { 24 public: 25 explicit SimFile(std::shared_ptr<SimStateManager> simStateManager); 26 void StartLoad(); 27 std::string ObtainMsisdnNumber(); 28 std::string ObtainSimOperator(); 29 std::string ObtainMCC(); 30 std::string ObtainMNC(); 31 std::string ObtainIsoCountryCode(); 32 int ObtainSpnCondition(bool roaming, const std::string &operatorNum); 33 int ObtainCallForwardStatus(); 34 std::shared_ptr<UsimFunctionHandle> ObtainUsimFunctionHandle(); 35 bool UpdateMsisdnNumber( 36 const std::string &alphaTag, const std::string &number); 37 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); 38 ~SimFile() = default; 39 bool ProcessIccReady(const AppExecFwk::InnerEvent::Pointer &event); 40 bool UpdateVoiceMail(const std::string &mailName, const std::string &mailNumber); 41 bool SetVoiceMailCount(int32_t voiceMailCount); 42 bool SetVoiceCallForwarding(bool enable, const std::string &number); 43 void ProcessIccRefresh(int msgId); 44 std::string GetVoiceMailNumber(); 45 void SetVoiceMailNumber(const std::string mailNumber); 46 void ClearData(); 47 static std::vector<std::string> indiaMcc_; 48 49 public: 50 enum { 51 RELOAD_ICCID_EVENT = 0, 52 }; 53 54 protected: 55 enum SpnStatus { 56 OBTAIN_SPN_NONE, 57 OBTAIN_SPN_START, 58 OBTAIN_SPN_GENERAL, 59 OBTAIN_OPERATOR_NAMESTRING, 60 OBTAIN_OPERATOR_NAME_SHORTFORM 61 }; 62 void ProcessFileLoaded(bool response); 63 void OnAllFilesFetched(); 64 void LoadSimFiles(); 65 bool ProcessIccLocked(const AppExecFwk::InnerEvent::Pointer &event); 66 void ObtainCallForwardFiles(); 67 void UpdateSimLanguage(); 68 int callForwardStatus_ = 0; 69 std::string cphsInfo_ = IccFileController::NULLSTR; 70 bool cspPlmnOn_ = false; 71 unsigned char *efMWIS_ = nullptr; 72 unsigned char *efCphsMwi_ = nullptr; 73 unsigned char *efCff_ = nullptr; 74 unsigned char *efCfis_ = nullptr; 75 std::string efMWISStr_; 76 std::string efCphsMwisStr_; 77 std::string efCffStr_; 78 std::string efCfisStr_; 79 std::string efLi_ = IccFileController::NULLSTR; 80 std::string efPl_ = IccFileController::NULLSTR; 81 SpnStatus spnStatus_ = OBTAIN_SPN_NONE; 82 int displayConditionOfSpn_ = 0; 83 std::vector<std::string> spdiNetworks_; 84 std::shared_ptr<UsimFunctionHandle> UsimFunctionHandle_ = nullptr; 85 86 private: 87 using FileProcessFunc = std::function<bool(const AppExecFwk::InnerEvent::Pointer &event)>; 88 std::map<int, FileProcessFunc> memberFuncMap_; 89 void InitMemberFunc(); 90 void InitBaseMemberFunc(); 91 void InitObtainMemberFunc(); 92 void InitPlmnMemberFunc(); 93 void ObtainSpnPhase(bool start, const AppExecFwk::InnerEvent::Pointer &event); 94 std::string AnalysisBcdPlmn(std::string data, std::string description); 95 void ProcessElementaryFileCsp(std::string data); 96 void AnalysisElementaryFileSpdi(std::string data); 97 void ProcessSmses(std::string messages); 98 void ProcessSms(std::string data); 99 100 void ProcessSpnGeneral(const AppExecFwk::InnerEvent::Pointer &event); 101 void ProcessSpnCphs(const AppExecFwk::InnerEvent::Pointer &event); 102 void ProcessSpnShortCphs(const AppExecFwk::InnerEvent::Pointer &event); 103 bool ProcessGetAdDone(const AppExecFwk::InnerEvent::Pointer &event); 104 bool ProcessVoiceMailCphs(const AppExecFwk::InnerEvent::Pointer &event); 105 bool ProcessGetMwisDone(const AppExecFwk::InnerEvent::Pointer &event); 106 bool ProcessGetMbdnDone(const AppExecFwk::InnerEvent::Pointer &event); 107 bool ProcessGetCphsMailBoxDone(const AppExecFwk::InnerEvent::Pointer &event); 108 bool ProcessGetMbiDone(const AppExecFwk::InnerEvent::Pointer &event); 109 bool ProcessGetCfisDone(const AppExecFwk::InnerEvent::Pointer &event); 110 bool ProcessGetCffDone(const AppExecFwk::InnerEvent::Pointer &event); 111 bool ProcessObtainIMSIDone(const AppExecFwk::InnerEvent::Pointer &event); 112 bool ProcessGetIccIdDone(const AppExecFwk::InnerEvent::Pointer &event); 113 bool ProcessGetPlmnActDone(const AppExecFwk::InnerEvent::Pointer &event); 114 bool ProcessGetOplmnActDone(const AppExecFwk::InnerEvent::Pointer &event); 115 bool ProcessGetSpdiDone(const AppExecFwk::InnerEvent::Pointer &event); 116 bool ProcessGetMsisdnDone(const AppExecFwk::InnerEvent::Pointer &event); 117 bool ProcessSetMsisdnDone(const AppExecFwk::InnerEvent::Pointer &event); 118 bool ProcessObtainGid1Done(const AppExecFwk::InnerEvent::Pointer &event); 119 bool ProcessObtainGid2Done(const AppExecFwk::InnerEvent::Pointer &event); 120 bool ProcessSmsOnSim(const AppExecFwk::InnerEvent::Pointer &event); 121 bool ProcessGetCspCphs(const AppExecFwk::InnerEvent::Pointer &event); 122 bool ProcessGetInfoCphs(const AppExecFwk::InnerEvent::Pointer &event); 123 bool ProcessGetSstDone(const AppExecFwk::InnerEvent::Pointer &event); 124 bool ProcessGetSmsDone(const AppExecFwk::InnerEvent::Pointer &event); 125 bool ProcessGetAllSmsDone(const AppExecFwk::InnerEvent::Pointer &event); 126 bool ProcessGetHplmActDone(const AppExecFwk::InnerEvent::Pointer &event); 127 bool ProcessGetEhplmnDone(const AppExecFwk::InnerEvent::Pointer &event); 128 bool ProcessGetPnnDone(const AppExecFwk::InnerEvent::Pointer &event); 129 bool ProcessGetOplDone(const AppExecFwk::InnerEvent::Pointer &event); 130 bool ProcessGetOpl5gDone(const AppExecFwk::InnerEvent::Pointer &event); 131 bool ProcessUpdateDone(const AppExecFwk::InnerEvent::Pointer &event); 132 bool ProcessSetCphsMailbox(const AppExecFwk::InnerEvent::Pointer &event); 133 bool ProcessGetFplmnDone(const AppExecFwk::InnerEvent::Pointer &event); 134 bool ProcessSetMbdn(const AppExecFwk::InnerEvent::Pointer &event); 135 bool ProcessMarkSms(const AppExecFwk::InnerEvent::Pointer &event); 136 bool ProcessObtainSpnPhase(const AppExecFwk::InnerEvent::Pointer &event); 137 bool ProcessObtainLiLanguage(const AppExecFwk::InnerEvent::Pointer &event); 138 bool ProcessObtainPlLanguage(const AppExecFwk::InnerEvent::Pointer &event); 139 bool ProcessReloadIccid(const AppExecFwk::InnerEvent::Pointer &event); 140 void StartObtainSpn(); 141 void LoadSimOtherFile(); 142 143 void CheckMncLengthForAdDone(); 144 void CheckMncLengthForImsiDone(); 145 bool CheckMncLen(std::string imsi, int imsiSize, int mncLen, int mccmncLen, bool isCheckUninitMnc); 146 bool IsIndiaMcc(std::string mccCode); 147 void OnMccMncLoaded(std::string imsi); 148 bool IsContinueGetSpn(bool start, SpnStatus curStatus, SpnStatus &newStatus); 149 std::atomic<int32_t> reloadIccidCount_ = 3; 150 const int MNC_INDEX = 7; 151 const int MCC_LEN = 3; 152 const int MNC_LONG_LEN = 3; 153 const int MNC_LEN = 2; 154 const int MCCMNC_LEN = 6; 155 const int MCCMNC_SHORT_LEN = 5; 156 const int LOAD_STEP = 1; 157 const int INVALID_BYTES_NUM = 1; 158 const int SPN_CHAR_POS = 0; 159 const int MAIL_DELAY_TIME = 50 * 1000; 160 const int RELOAD_ICCID_COUNT = 3; 161 static const uint8_t CPHS_VOICE_MAIL_MASK = 0x30; 162 static const uint8_t CPHS_VOICE_MAIL_EXSIT = 0x30; 163 static const int CFIS_BCD_NUMBER_LENGTH_OFFSET = 2; 164 static const int CFIS_TON_NPI_OFFSET = 3; 165 static const int CFIS_ADN_CAPABILITY_ID_OFFSET = 14; 166 static const int CFIS_ADN_EXTENSION_ID_OFFSET = 15; 167 int ObtainExtensionElementaryFile(int ef); 168 bool CphsVoiceMailAvailable(); 169 bool EfCfisAvailable(int32_t size); 170 void GetCphsMailBox(); 171 std::string ParseSpn(const std::string &rawData, int curState); 172 void ParsePnn(const std::vector<std::string> &records); 173 void ParseOpl(const std::vector<std::string> &records); 174 void ParseOpl5g(const std::vector<std::string> &records); 175 bool FillNumber(std::shared_ptr<unsigned char> efCfisData, int32_t efCfisSize, const std::string &number); 176 bool VoiceMailNotEditToSim(); 177 }; 178 } // namespace Telephony 179 } // namespace OHOS 180 181 #endif // OHOS_SIM_FILE_H 182