• 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 SimFileParse;
25 class SimFile : public IccFile {
26 public:
27     explicit SimFile(std::shared_ptr<SimStateManager> simStateManager);
28     void StartLoad();
29     std::string ObtainMsisdnNumber();
30     std::string ObtainSimOperator();
31     std::string ObtainMCC();
32     std::string ObtainMNC();
33     std::string ObtainIsoCountryCode();
34     int ObtainSpnCondition(bool roaming, const std::string &operatorNum);
35     int ObtainCallForwardStatus();
36     std::shared_ptr<UsimFunctionHandle> ObtainUsimFunctionHandle();
37     bool UpdateMsisdnNumber(
38         const std::string &alphaTag, const std::string &number);
39     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
40     ~SimFile() = default;
41     bool ProcessIccReady(const AppExecFwk::InnerEvent::Pointer &event);
42     bool UpdateVoiceMail(const std::string &mailName, const std::string &mailNumber);
43     bool SetVoiceMailCount(int32_t voiceMailCount);
44     bool SetVoiceCallForwarding(bool enable, const std::string &number);
45     void ProcessIccRefresh(int msgId);
46     std::string GetVoiceMailNumber();
47     void SetVoiceMailNumber(const std::string mailNumber);
48     void ClearData();
49     static std::vector<std::string> indiaMcc_;
50 
51 public:
52     enum {
53         RELOAD_ICCID_EVENT = 0,
54         RELOAD_IMSI_EVENT = 1,
55     };
56 
57 protected:
58     enum SpnStatus {
59         OBTAIN_SPN_NONE,
60         OBTAIN_SPN_START,
61         OBTAIN_SPN_GENERAL,
62         OBTAIN_OPERATOR_NAMESTRING,
63         OBTAIN_OPERATOR_NAME_SHORTFORM
64     };
65     void ProcessFileLoaded(bool response);
66     void OnAllFilesFetched();
67     void LoadSimFiles();
68     bool ProcessIccLocked(const AppExecFwk::InnerEvent::Pointer &event);
69     void ObtainCallForwardFiles();
70     void UpdateSimLanguage();
71     int callForwardStatus_ = 0;
72     std::string cphsInfo_ = IccFileController::NULLSTR;
73     bool cspPlmnOn_ = false;
74     unsigned char *efMWIS_ = nullptr;
75     unsigned char *efCphsMwi_ = nullptr;
76     unsigned char *efCff_ = nullptr;
77     unsigned char *efCfis_ = nullptr;
78     std::string efMWISStr_;
79     std::string efCphsMwisStr_;
80     std::string efCffStr_;
81     std::string efCfisStr_;
82     std::string efLi_ = IccFileController::NULLSTR;
83     std::string efPl_ = IccFileController::NULLSTR;
84     SpnStatus spnStatus_ = OBTAIN_SPN_NONE;
85     int displayConditionOfSpn_ = 0;
86     std::vector<std::string> spdiNetworks_;
87     std::shared_ptr<UsimFunctionHandle> UsimFunctionHandle_ = nullptr;
88 
89 private:
90     using FileProcessFunc = std::function<bool(const AppExecFwk::InnerEvent::Pointer &event)>;
91     std::map<int, FileProcessFunc> memberFuncMap_;
92     void ObtainSpnPhase(bool start, const AppExecFwk::InnerEvent::Pointer &event);
93     std::string AnalysisBcdPlmn(std::string data, std::string description);
94     void ProcessElementaryFileCsp(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     bool ProcessGetSpnCphsDone(const AppExecFwk::InnerEvent::Pointer &event);
141     bool ProcessGetSpnShortCphsDone(const AppExecFwk::InnerEvent::Pointer &event);
142     void StartObtainSpn();
143     void LoadSimOtherFile();
144     void LoadSimOtherFileExt();
145 
146     void CheckMncLengthForAdDone();
147     void CheckMncLengthForImsiDone();
148     bool CheckMncLen(std::string imsi, int imsiSize, int mncLen, int mccmncLen, bool isCheckUninitMnc);
149     bool IsIndiaMcc(std::string mccCode);
150     void OnMccMncLoaded(std::string imsi);
151     bool IsContinueGetSpn(bool start, SpnStatus curStatus, SpnStatus &newStatus);
152     std::atomic<int32_t> reloadIccidCount_ = 3;
153     const int MNC_INDEX = 7;
154     const int MCC_LEN = 3;
155     const int MNC_LONG_LEN = 3;
156     const int MNC_LEN = 2;
157     const int MCCMNC_LEN = 6;
158     const int MCCMNC_SHORT_LEN = 5;
159     const int LOAD_STEP = 1;
160     const int INVALID_BYTES_NUM = 1;
161     const int SPN_CHAR_POS = 0;
162     const int MAIL_DELAY_TIME = 50 * 1000;
163     const int RELOAD_ICCID_COUNT = 3;
164     bool hasRetryGetImsi_ = false;
165     static const uint8_t CPHS_VOICE_MAIL_MASK = 0x30;
166     static const uint8_t CPHS_VOICE_MAIL_EXSIT = 0x30;
167     static const int CFIS_BCD_NUMBER_LENGTH_OFFSET = 2;
168     static const int CFIS_TON_NPI_OFFSET = 3;
169     static const int CFIS_ADN_CAPABILITY_ID_OFFSET = 14;
170     static const int CFIS_ADN_EXTENSION_ID_OFFSET = 15;
171     int ObtainExtensionElementaryFile(int ef);
172     bool CphsVoiceMailAvailable();
173     bool EfCfisAvailable(int32_t size);
174     void GetCphsMailBox();
175     bool FillNumber(std::shared_ptr<unsigned char> efCfisData, int32_t efCfisSize, const std::string &number);
176     bool VoiceMailNotEditToSim();
177     bool IsAvailable(uint8_t offset, uint8_t mask);
178     bool IsSimServiceAvailable(UsimService service);
179     bool IsUsimServiceAvailable(UsimService service);
180     bool IsServiceAvailable(UsimService service);
181     friend class SimFileInit;
182     std::shared_ptr<SimFileInit> simFileInit_;
183     friend class SimFileParse;
184     std::shared_ptr<SimFileParse> simFileParse_;
185     std::string serviceTable_;
186 };
187 } // namespace Telephony
188 } // namespace OHOS
189 
190 #endif // OHOS_SIM_FILE_H
191