• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 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 SimFileInit;
24 class SimFile : public IccFile {
25 public:
26     explicit SimFile(std::shared_ptr<SimStateManager> simStateManager);
27     void StartLoad();
28     std::string ObtainMsisdnNumber();
29     std::string ObtainSimOperator();
30     std::string ObtainMCC();
31     std::string ObtainMNC();
32     std::string ObtainIsoCountryCode();
33     int ObtainSpnCondition(bool roaming, const std::string &operatorNum);
34     int ObtainCallForwardStatus();
35     std::shared_ptr<UsimFunctionHandle> ObtainUsimFunctionHandle();
36     bool UpdateMsisdnNumber(
37         const std::string &alphaTag, const std::string &number);
38     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
39     ~SimFile() = default;
40     bool ProcessIccReady(const AppExecFwk::InnerEvent::Pointer &event);
41     bool UpdateVoiceMail(const std::string &mailName, const std::string &mailNumber);
42     bool SetVoiceMailCount(int32_t voiceMailCount);
43     bool SetVoiceCallForwarding(bool enable, const std::string &number);
44     void ProcessIccRefresh(int msgId);
45     std::string GetVoiceMailNumber();
46     void SetVoiceMailNumber(const std::string mailNumber);
47     void ClearData();
48     static std::vector<std::string> indiaMcc_;
49 
50 public:
51     enum {
52         RELOAD_ICCID_EVENT = 0,
53         RELOAD_IMSI_EVENT = 1,
54     };
55 
56 protected:
57     enum SpnStatus {
58         OBTAIN_SPN_NONE,
59         OBTAIN_SPN_START,
60         OBTAIN_SPN_GENERAL,
61         OBTAIN_OPERATOR_NAMESTRING,
62         OBTAIN_OPERATOR_NAME_SHORTFORM
63     };
64     void ProcessFileLoaded(bool response);
65     void OnAllFilesFetched();
66     void LoadSimFiles();
67     bool ProcessIccLocked(const AppExecFwk::InnerEvent::Pointer &event);
68     void ObtainCallForwardFiles();
69     void UpdateSimLanguage();
70     int callForwardStatus_ = 0;
71     std::string cphsInfo_ = IccFileController::NULLSTR;
72     bool cspPlmnOn_ = false;
73     unsigned char *efMWIS_ = nullptr;
74     unsigned char *efCphsMwi_ = nullptr;
75     unsigned char *efCff_ = nullptr;
76     unsigned char *efCfis_ = nullptr;
77     std::string efMWISStr_;
78     std::string efCphsMwisStr_;
79     std::string efCffStr_;
80     std::string efCfisStr_;
81     std::string efLi_ = IccFileController::NULLSTR;
82     std::string efPl_ = IccFileController::NULLSTR;
83     SpnStatus spnStatus_ = OBTAIN_SPN_NONE;
84     int displayConditionOfSpn_ = 0;
85     std::vector<std::string> spdiNetworks_;
86     std::shared_ptr<UsimFunctionHandle> UsimFunctionHandle_ = nullptr;
87 
88 private:
89     using FileProcessFunc = std::function<bool(const AppExecFwk::InnerEvent::Pointer &event)>;
90     std::map<int, FileProcessFunc> memberFuncMap_;
91     void ObtainSpnPhase(bool start, const AppExecFwk::InnerEvent::Pointer &event);
92     std::string AnalysisBcdPlmn(std::string data, std::string description);
93     void ProcessElementaryFileCsp(std::string data);
94     void AnalysisElementaryFileSpdi(std::string data);
95     void ProcessSmses(std::string messages);
96     void ProcessSms(std::string data);
97 
98     void ProcessSpnGeneral(const AppExecFwk::InnerEvent::Pointer &event);
99     void ProcessSpnCphs(const AppExecFwk::InnerEvent::Pointer &event);
100     void ProcessSpnShortCphs(const AppExecFwk::InnerEvent::Pointer &event);
101     bool ProcessGetAdDone(const AppExecFwk::InnerEvent::Pointer &event);
102     bool ProcessVoiceMailCphs(const AppExecFwk::InnerEvent::Pointer &event);
103     bool ProcessGetMwisDone(const AppExecFwk::InnerEvent::Pointer &event);
104     bool ProcessGetMbdnDone(const AppExecFwk::InnerEvent::Pointer &event);
105     bool ProcessGetCphsMailBoxDone(const AppExecFwk::InnerEvent::Pointer &event);
106     bool ProcessGetMbiDone(const AppExecFwk::InnerEvent::Pointer &event);
107     bool ProcessGetCfisDone(const AppExecFwk::InnerEvent::Pointer &event);
108     bool ProcessGetCffDone(const AppExecFwk::InnerEvent::Pointer &event);
109     bool ProcessObtainIMSIDone(const AppExecFwk::InnerEvent::Pointer &event);
110     bool ProcessGetIccIdDone(const AppExecFwk::InnerEvent::Pointer &event);
111     bool ProcessGetPlmnActDone(const AppExecFwk::InnerEvent::Pointer &event);
112     bool ProcessGetOplmnActDone(const AppExecFwk::InnerEvent::Pointer &event);
113     bool ProcessGetSpdiDone(const AppExecFwk::InnerEvent::Pointer &event);
114     bool ProcessGetMsisdnDone(const AppExecFwk::InnerEvent::Pointer &event);
115     bool ProcessSetMsisdnDone(const AppExecFwk::InnerEvent::Pointer &event);
116     bool ProcessObtainGid1Done(const AppExecFwk::InnerEvent::Pointer &event);
117     bool ProcessObtainGid2Done(const AppExecFwk::InnerEvent::Pointer &event);
118     bool ProcessSmsOnSim(const AppExecFwk::InnerEvent::Pointer &event);
119     bool ProcessGetCspCphs(const AppExecFwk::InnerEvent::Pointer &event);
120     bool ProcessGetInfoCphs(const AppExecFwk::InnerEvent::Pointer &event);
121     bool ProcessGetSstDone(const AppExecFwk::InnerEvent::Pointer &event);
122     bool ProcessGetSmsDone(const AppExecFwk::InnerEvent::Pointer &event);
123     bool ProcessGetAllSmsDone(const AppExecFwk::InnerEvent::Pointer &event);
124     bool ProcessGetHplmActDone(const AppExecFwk::InnerEvent::Pointer &event);
125     bool ProcessGetEhplmnDone(const AppExecFwk::InnerEvent::Pointer &event);
126     bool ProcessGetPnnDone(const AppExecFwk::InnerEvent::Pointer &event);
127     bool ProcessGetOplDone(const AppExecFwk::InnerEvent::Pointer &event);
128     bool ProcessGetOpl5gDone(const AppExecFwk::InnerEvent::Pointer &event);
129     bool ProcessUpdateDone(const AppExecFwk::InnerEvent::Pointer &event);
130     bool ProcessSetCphsMailbox(const AppExecFwk::InnerEvent::Pointer &event);
131     bool ProcessGetFplmnDone(const AppExecFwk::InnerEvent::Pointer &event);
132     bool ProcessSetMbdn(const AppExecFwk::InnerEvent::Pointer &event);
133     bool ProcessMarkSms(const AppExecFwk::InnerEvent::Pointer &event);
134     bool ProcessObtainSpnPhase(const AppExecFwk::InnerEvent::Pointer &event);
135     bool ProcessObtainLiLanguage(const AppExecFwk::InnerEvent::Pointer &event);
136     bool ProcessObtainPlLanguage(const AppExecFwk::InnerEvent::Pointer &event);
137     bool ProcessReloadIccid(const AppExecFwk::InnerEvent::Pointer &event);
138     bool ProcessReloadImsi(const AppExecFwk::InnerEvent::Pointer &event);
139     void DelayGetImsi();
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     bool hasRetryGetImsi_ = false;
162     static const uint8_t CPHS_VOICE_MAIL_MASK = 0x30;
163     static const uint8_t CPHS_VOICE_MAIL_EXSIT = 0x30;
164     static const int CFIS_BCD_NUMBER_LENGTH_OFFSET = 2;
165     static const int CFIS_TON_NPI_OFFSET = 3;
166     static const int CFIS_ADN_CAPABILITY_ID_OFFSET = 14;
167     static const int CFIS_ADN_EXTENSION_ID_OFFSET = 15;
168     int ObtainExtensionElementaryFile(int ef);
169     bool CphsVoiceMailAvailable();
170     bool EfCfisAvailable(int32_t size);
171     void GetCphsMailBox();
172     std::string ParseSpn(const std::string &rawData, int curState);
173     void ParsePnn(const std::vector<std::string> &records);
174     void ParseOpl(const std::vector<std::string> &records);
175     void ParseOpl5g(const std::vector<std::string> &records);
176     bool FillNumber(std::shared_ptr<unsigned char> efCfisData, int32_t efCfisSize, const std::string &number);
177     bool VoiceMailNotEditToSim();
178     bool IsServiceAvailable(UsimService service);
179     friend class SimFileInit;
180     std::shared_ptr<SimFileInit> simFileInit_;
181     std::string serviceTable_;
182 };
183 } // namespace Telephony
184 } // namespace OHOS
185 
186 #endif // OHOS_SIM_FILE_H
187