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