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