• 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     std::string ObtainSPN();
66     std::string ObtainEons(const std::string &plmn, int32_t lac, bool longNameRequired);
67     std::string ObtainVoiceMailInfo();
68     bool ObtainFilesFetched();
69     std::string ObtainIccLanguage();
70     virtual std::shared_ptr<UsimFunctionHandle> ObtainUsimFunctionHandle();
71     std::string ObtainSpNameFromEfSpn();
72     int ObtainLengthOfMnc();
73     virtual void RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what);
74     virtual void UnRegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &observerCallBack, int what);
75     void SetRilAndFileController(const std::shared_ptr<Telephony::ITelRilManager> &ril,
76         const std::shared_ptr<IccFileController> &file, const std::shared_ptr<IccDiallingNumbersHandler> &handler);
77     struct IccFileLoaded {
78         virtual std::string ObtainElementaryFileName() = 0;
79         virtual void ProcessParseFile(const AppExecFwk::InnerEvent::Pointer &event) = 0;
80     };
81     virtual bool UpdateVoiceMail(const std::string &mailName, const std::string &mailNumber) = 0;
82     bool HasSimCard();
83     void UnInit();
84     void ClearData();
SetId(int id)85     void SetId(int id)
86     {
87         slotId_ = id;
88     }
89 
90 protected:
91     virtual void ProcessIccRefresh(int msgId) = 0;
92     virtual void ProcessFileLoaded(bool response) = 0;
93     virtual void OnAllFilesFetched() = 0;
94     bool LockQueriedOrNot();
95     void UpdateSPN(const std::string spn);
96     void SaveCountryCode();
97     std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr;
98     std::shared_ptr<IccFileController> fileController_ = nullptr;
99     std::shared_ptr<SimStateManager> stateManager_ = nullptr;
100     std::string imsi_ = "";
101     std::string iccId_ = ""; // decimals
102     std::string spn_ = "";
103     std::string gid1_ = "";
104     std::string gid2_ = "";
105     std::string msisdn_ = "";
106     std::string msisdnTag_ = "";
107     std::string lastMsisdn_ = "";
108     std::string lastMsisdnTag_ = "";
109     std::string voiceMailNum_ = "";
110     std::string voiceMailTag_ = "";
111     std::string lastVoiceMailNum_ = "";
112     std::string lastVoiceMailTag_ = "";
113     std::string operatorNumeric_ = "";
114     bool voiceMailFixedOrNot_ = false;
115     std::string pnnHomeName_ = "";
116     std::string iccLanguage_ = "";
117     PlmnFile *hplmnRAT_ = nullptr;
118     PlmnFile *oplmnRAT_ = nullptr;
119     PlmnFile *plmnRAT_ = nullptr;
120     std::string ehplmns_ = "";
121     std::string fplmns_ = "";
122     std::vector<std::shared_ptr<PlmnNetworkName>> pnnFiles_;
123     std::vector<std::shared_ptr<OperatorPlmnInfo>> oplFiles_;
124     int lengthOfMnc_ = DEFAULT_MNC;
125     int indexOfMailbox_ = 1;
126     int fileToGet_ = 0;
127     bool loaded_ = false;
128     bool fileQueried_ = false;
129     bool lockQueried_ = false;
130     bool waitResult_ = false;
131     static std::mutex mtx_;
132     std::condition_variable processWait_;
133     const uint8_t BYTE_NUM = 0xff;
134     const int DATA_STEP = 2;
135     static std::unique_ptr<ObserverHandler> filesFetchedObser_;
136     std::unique_ptr<ObserverHandler> lockedFilesFetchedObser_ = nullptr;
137     std::unique_ptr<ObserverHandler> networkLockedFilesFetchedObser_ = nullptr;
138     std::unique_ptr<ObserverHandler> imsiReadyObser_ = nullptr;
139     std::unique_ptr<ObserverHandler> recordsEventsObser_ = nullptr;
140     std::unique_ptr<ObserverHandler> networkSelectionModeAutomaticObser_ = nullptr;
141     std::unique_ptr<ObserverHandler> spnUpdatedObser_ = nullptr;
142     std::unique_ptr<ObserverHandler> recordsOverrideObser_ = nullptr;
143     virtual AppExecFwk::InnerEvent::Pointer BuildCallerInfo(int eventId);
144     virtual AppExecFwk::InnerEvent::Pointer BuildCallerInfo(int eventId, int arg1, int arg2);
145     virtual AppExecFwk::InnerEvent::Pointer BuildCallerInfo(int eventId, std::shared_ptr<void> loader);
146     bool PublishSimFileEvent(const std::string &event, int eventCode, const std::string &eventData);
147     void UpdateIccLanguage(const std::string &langLi, const std::string &langPl);
148     std::string ObtainValidLanguage(const std::string &langData);
149     std::shared_ptr<IccDiallingNumbersHandler> diallingNumberHandler_ = nullptr;
150     AppExecFwk::InnerEvent::Pointer CreateDiallingNumberPointer(
151         int eventid, int efId, int index, std::shared_ptr<void> pobj);
152     void NotifyRegistrySimState(CardType type, SimState state, LockReason reason);
153     int slotId_ = 0;
154 
155 private:
156     bool ProcessIccFileObtained(const AppExecFwk::InnerEvent::Pointer &event);
157     void RegisterImsiLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler);
158     void UnregisterImsiLoaded(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
159     void RegisterAllFilesLoaded(std::shared_ptr<AppExecFwk::EventHandler> eventHandler);
160     void UnregisterAllFilesLoaded(const std::shared_ptr<AppExecFwk::EventHandler> &handler);
161 };
162 } // namespace Telephony
163 } // namespace OHOS
164 
165 #endif // OHOS_ICC_FILE_H
166