• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2024 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_ICC_FILE_H
17 #define OHOS_ICC_FILE_H
18 #include <shared_mutex>
19 #include <set>
20 #include <ffrt.h>
21 
22 #include "common_event.h"
23 #include "common_event_manager.h"
24 #include "common_event_support.h"
25 #include "i_tel_ril_manager.h"
26 #include "icc_dialling_numbers_handler.h"
27 #include "icc_file_controller.h"
28 #include "mcc_pool.h"
29 #include "observer_handler.h"
30 #include "plmn_file.h"
31 #include "sim_constant.h"
32 #include "sim_state_manager.h"
33 #include "tel_event_handler.h"
34 #include "telephony_log_wrapper.h"
35 #include "usim_function_handle.h"
36 #include "voice_mail_constants.h"
37 #include "want.h"
38 #include "i_icc_file.h"
39 
40 namespace OHOS {
41 namespace Telephony {
42 class IccFile : public IIccFileExt, public TelEventHandler {
43 public:
44     explicit IccFile(const std::string &name, std::shared_ptr<SimStateManager> simStateManager);
45     void Init();
46     virtual void StartLoad();
47     std::string ObtainIMSI();
48     std::set<std::string> ObtainEhPlmns();
49     std::set<std::string> ObtainSpdiPlmns();
50     virtual std::string ObtainMCC();
51     virtual std::string ObtainMNC();
52     void UpdateImsi(std::string imsi);
53     void UpdateIccId(std::string iccid);
54     std::string ObtainIccId();
55     std::string ObtainDecIccId();
56     std::string ObtainGid1();
57     std::string ObtainGid2();
58     std::string ObtainMsisdnNumber();
59     virtual std::string ObtainSimOperator();
60     virtual std::string ObtainIsoCountryCode();
61     virtual int ObtainCallForwardStatus();
62     virtual int ObtainSpnCondition(bool roaming, const std::string &operatorNum) = 0;
63     bool LoadedOrNot();
64     void UpdateLoaded(bool loaded);
65     virtual bool UpdateMsisdnNumber(
66         const std::string &alphaTag, const std::string &number);
67     virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
68     virtual ~IccFile();
69     virtual bool ProcessIccReady(const AppExecFwk::InnerEvent::Pointer &event) = 0;
70     std::string ObtainDiallingNumberInfo();
71     std::string ObtainNAI();
72     std::string ObtainHomeNameOfPnn();
73     std::string ObtainMsisdnAlphaStatus();
74     int32_t ObtainVoiceMailCount();
75     std::string ObtainSPN();
76     std::string ObtainEons(const std::string &plmn, int32_t lac, bool longNameRequired);
77     std::string ObtainVoiceMailInfo();
78     bool ObtainFilesFetched();
79     std::string ObtainIccLanguage();
80     virtual std::shared_ptr<UsimFunctionHandle> ObtainUsimFunctionHandle();
81     std::string ObtainSpNameFromEfSpn();
82     int ObtainLengthOfMnc();
83     virtual void RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what);
84     virtual void UnRegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &observerCallBack, int what);
85     void SetRilAndFileController(const std::shared_ptr<Telephony::ITelRilManager> &ril,
86         const std::shared_ptr<IccFileController> &file, const std::shared_ptr<IccDiallingNumbersHandler> &handler);
87     struct IccFileLoaded {
88         virtual std::string ObtainElementaryFileName() = 0;
89         virtual void ProcessParseFile(const AppExecFwk::InnerEvent::Pointer &event) = 0;
90     };
91     virtual bool UpdateVoiceMail(const std::string &mailName, const std::string &mailNumber) = 0;
92     virtual bool SetVoiceMailCount(int32_t voiceMailCount) = 0;
93     virtual bool SetVoiceCallForwarding(bool enable, const std::string &number) = 0;
94     virtual std::string GetVoiceMailNumber() = 0;
95     virtual void SetVoiceMailNumber(const std::string mailNumber) = 0;
96     virtual void ProcessIccRefresh(int msgId) = 0;
97     bool HasSimCard();
98     void UnInit();
99     virtual void ClearData();
100     void ProcessIccLocked();
101     void SetId(int id);
102     bool GetIsVoiceMailFixed();
103     void LoadVoiceMail();
104     bool ExecutOriginalSimIoRequest(int32_t filedId, int fileIdDone);
105     void OnOpkeyLoad(const std::string opKey, const std::string opName);
106     void FileChangeToExt(const std::string fileName, const FileChangeType fileLoad);
107     void ProcessExtGetFileDone(const AppExecFwk::InnerEvent::Pointer &event);
108     void SetIccFile(std::shared_ptr<OHOS::Telephony::IIccFileExt> &iccFile);
109     void AddRecordsToLoadNum();
110     void DeleteOperatorCache();
111     void UpdateOpkeyConfig();
112     virtual void ProcessExtGetFileResponse();
113 
114 protected:
115     virtual void ProcessFileLoaded(bool response) = 0;
116     virtual void OnAllFilesFetched() = 0;
117     bool LockQueriedOrNot();
118     void UpdateSPN(const std::string spn);
119     void SaveCountryCode();
120     std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr;
121     std::shared_ptr<IccFileController> fileController_ = nullptr;
122     std::shared_ptr<SimStateManager> stateManager_ = nullptr;
123     std::string imsi_ = "";
124     std::string iccId_ = "";
125     std::string decIccId_ = "";
126     std::string spn_ = "";
127     std::string spnCphs_ = "";
128     std::string spnShortCphs_ = "";
129     std::string gid1_ = "";
130     std::string gid2_ = "";
131     std::string msisdn_ = "";
132     std::string msisdnTag_ = "";
133     std::string lastMsisdn_ = "";
134     std::string lastMsisdnTag_ = "";
135     std::string voiceMailNum_ = "";
136     int32_t efMWISSize_ = 0;
137     int32_t efCphsMwiSize_ = 0;
138     int32_t efCfisSize_ = 0;
139     int32_t efCffSize_ = 0;
140     int32_t callForwardingStatus = CALL_FORWARDING_STATUS_UNKNOWN;
141     bool voiceMailWaiting_ = false;
142     int32_t voiceMailCount_ = DEFAULT_VOICE_MAIL_COUNT;
143     std::string voiceMailTag_ = "";
144     std::string lastVoiceMailNum_ = "";
145     std::string lastVoiceMailTag_ = "";
146     std::string operatorNumeric_ = "";
147     std::string mcc_ = "";
148     std::string mnc_ = "";
149     bool voiceMailFixedOrNot_ = false;
150     std::string pnnHomeName_ = "";
151     std::string iccLanguage_ = "";
152     PlmnFile *hplmnRAT_ = nullptr;
153     PlmnFile *oplmnRAT_ = nullptr;
154     PlmnFile *plmnRAT_ = nullptr;
155     std::string fplmns_ = "";
156     std::set<std::string> spdiPlmns_;
157     std::set<std::string> ehplmns_;
158     std::vector<std::shared_ptr<PlmnNetworkName>> pnnFiles_;
159     std::vector<std::shared_ptr<OperatorPlmnInfo>> oplFiles_;
160     std::vector<std::shared_ptr<OperatorPlmnInfo>> opl5gFiles_;
161     bool isOplFileResponsed_ = false;
162     bool isOpl5gFileResponsed_ = false;
163     bool isOpl5gFilesPresent_ = false;
164     int lengthOfMnc_ = UNINITIALIZED_MNC;
165     int indexOfMailbox_ = 1;
166     int fileToGet_ = 0;
167     bool loaded_ = false;
168     bool fileQueried_ = false;
169     bool lockQueried_ = false;
170     bool waitResult_ = false;
171     static std::mutex mtx_;
172     std::condition_variable processWait_;
173     const int HEXADECIMAL = 16;
174     const size_t OPL_5G_LENGTH = 10;
175     const uint8_t BYTE_NUM = 0xFF;
176     const uint8_t BYTE_NUM2 = 0x01;
177     const uint8_t BYTE_NUM3 = 0x0F;
178     const uint8_t BYTE_NUM4 = 0x0A;
179     const uint8_t BYTE_NUM5 = 0x05;
180     const uint8_t BYTE_NUM6 = 0xFE;
181     const uint8_t BYTE_NUM7 = 0xF0;
182     const int DATA_STEP = 2;
183     const unsigned long LENGTH_TWO = 2;
184     static std::unique_ptr<ObserverHandler> filesFetchedObser_;
185     std::unique_ptr<ObserverHandler> lockedFilesFetchedObser_ = nullptr;
186     std::unique_ptr<ObserverHandler> networkLockedFilesFetchedObser_ = nullptr;
187     std::unique_ptr<ObserverHandler> recordsEventsObser_ = nullptr;
188     std::unique_ptr<ObserverHandler> networkSelectionModeAutomaticObser_ = nullptr;
189     std::unique_ptr<ObserverHandler> spnUpdatedObser_ = nullptr;
190     std::unique_ptr<ObserverHandler> recordsOverrideObser_ = nullptr;
191     virtual AppExecFwk::InnerEvent::Pointer BuildCallerInfo(int eventId);
192     virtual AppExecFwk::InnerEvent::Pointer BuildCallerInfo(int eventId, int arg1, int arg2);
193     virtual AppExecFwk::InnerEvent::Pointer BuildCallerInfo(int eventId, std::shared_ptr<void> loader);
194     bool PublishSimFileEvent(const std::string &event, int eventCode, const std::string &eventData);
195     void UpdateIccLanguage(const std::string &langLi, const std::string &langPl);
196     std::string ObtainValidLanguage(const std::string &langData);
197     void SwapPairsForIccId(std::string &iccId);
198     void GetFullIccid(std::string &iccId);
199     std::shared_ptr<IccDiallingNumbersHandler> diallingNumberHandler_ = nullptr;
200     AppExecFwk::InnerEvent::Pointer CreateDiallingNumberPointer(
201         int eventid, int efId, int index, std::shared_ptr<void> pobj);
202     void NotifyRegistrySimState(CardType type, SimState state, LockReason reason);
203     int slotId_ = 0;
204     void SetVoiceMailByOperator(std::string spn);
205     std::shared_ptr<VoiceMailConstants> voiceMailConfig_ = nullptr;
206     std::shared_mutex voiceMailMutex_;
207     bool isOnOpkeyLoaded_{false};
208     bool isSimRecordLoaded_{false};
209 
210 private:
211     std::atomic<bool> isVoiceMailFixed_{false};
212     void ResetVoiceMailVariable();
213     bool ProcessIccFileObtained(const AppExecFwk::InnerEvent::Pointer &event);
214     void RegisterImsiLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler);
215     void UnregisterImsiLoaded(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
216     void RegisterAllFilesLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler);
217     void UnregisterAllFilesLoaded(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
218     void RegisterOpkeyLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler);
219     void UnregisterOpkeyLoaded(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
220     void RegisterOperatorCacheDel(std::shared_ptr<AppExecFwk::EventHandler> eventHandler);
221     void UnregisterOperatorCacheDel(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
222     void RegisterIccidLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler);
223     void UnregisterIccidLoaded(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
224     void RegisterOperatorConfigUpdate(std::shared_ptr<AppExecFwk::EventHandler> eventHandler);
225     void UnregisterOperatorConfigUpdate(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
226     void AddRecordsOverrideObser();
227     bool ObtainEonsExternRules(const std::vector<std::shared_ptr<OperatorPlmnInfo>> oplFiles, bool roaming,
228         std::string &eons, bool longNameRequired, const std::string &plmn);
229     ffrt::shared_mutex iccFileMutex_;
230 };
231 } // namespace Telephony
232 } // namespace OHOS
233 
234 #endif // OHOS_ICC_FILE_H
235