• 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_SIM_FILE_MANAGER_H
17 #define OHOS_SIM_FILE_MANAGER_H
18 
19 #include "common_event_subscriber.h"
20 #include "csim_file_controller.h"
21 #include "event_handler.h"
22 #include "event_runner.h"
23 #include "i_tel_ril_manager.h"
24 #include "isim_file.h"
25 #include "isim_file_controller.h"
26 #include "ruim_file.h"
27 #include "ruim_file_controller.h"
28 #include "sim_file.h"
29 #include "sim_file_controller.h"
30 #include "system_ability_status_change_stub.h"
31 #include "tel_ril_modem_parcel.h"
32 #include "telephony_log_wrapper.h"
33 #include "usim_file_controller.h"
34 #include "esim_state_type.h"
35 
36 namespace OHOS {
37 namespace Telephony {
38 class SimFileManager : public TelEventHandler, public EventFwk::CommonEventSubscriber {
39 public:
40     using HANDLE = std::shared_ptr<AppExecFwk::EventHandler>;
41     SimFileManager(
42         const EventFwk::CommonEventSubscribeInfo &sp, std::weak_ptr<Telephony::ITelRilManager> telRilManager,
43         std::weak_ptr<Telephony::SimStateManager> state);
44     virtual ~SimFileManager();
45     void Init(int slotId);
46     void ClearData();
47     std::u16string GetSimOperatorNumeric();
48     std::u16string GetISOCountryCodeForSim();
49     std::u16string GetSimSpn();
50     std::u16string GetSimEons(const std::string &plmn, int32_t lac, bool longNameRequired);
51     std::u16string GetSimIccId();
52     std::u16string GetSimDecIccId();
53     std::u16string GetIMSI();
54     std::u16string GetMCC();
55     std::u16string GetMNC();
56     std::u16string GetLocaleFromDefaultSim();
57     std::u16string GetSimGid1();
58     std::u16string GetSimGid2();
59     std::u16string GetSimTelephoneNumber();
60     std::u16string GetSimTeleNumberIdentifier();
61     std::u16string GetSimIst();
62     std::u16string GetVoiceMailIdentifier();
63     std::u16string GetVoiceMailNumber();
64     std::set<std::string> GetEhPlmns();
65     std::set<std::string> GetSpdiPlmns();
66     int32_t GetVoiceMailCount();
67     bool SetVoiceMailCount(int32_t voiceMailCount);
68     bool SetVoiceCallForwarding(bool enable, const std::string &number);
69     std::u16string GetOpName();
70     std::u16string GetOpKey();
71     std::u16string GetOpKeyExt();
72     void SetOpName(const std::string &opName);
73     void SetOpKey(const std::string &opKey);
74     void SetOpKeyExt(const std::string &opKeyExt);
75     int ObtainSpnCondition(bool roaming, const std::string &operatorNum);
76     void RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what);
77     void UnRegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &observerCallBack, int what);
78     void SetImsi(std::string imsi);
79     std::shared_ptr<IccFile> GetIccFile();
80     std::shared_ptr<IccFileController> GetIccFileController();
81     std::shared_ptr<IccDiallingNumbersHandler> ObtainDiallingNumberHandler();
82     bool SetVoiceMailInfo(const std::u16string &mailName, const std::u16string &mailNumber);
83     bool SetSimTelephoneNumber(const std::u16string &alphaTag, const std::u16string &phoneNumber);
84     bool HasSimCard();
85     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
86     void OnReceiveEvent(const EventFwk::CommonEventData &data) override;
87     void UpdateOpkeyConfig();
88     bool IsCTSimCard();
89     static std::shared_ptr<SimFileManager> CreateInstance(
90         std::weak_ptr<Telephony::ITelRilManager> ril, std::weak_ptr<SimStateManager> simState);
91     enum class HandleRunningState { STATE_NOT_START, STATE_RUNNING };
92     enum class IccType { ICC_TYPE_CDMA, ICC_TYPE_GSM, ICC_TYPE_IMS, ICC_TYPE_USIM };
93 
94 protected:
95     std::weak_ptr<Telephony::ITelRilManager> telRilManager_;
96     std::shared_ptr<IccFileController> fileController_ = nullptr;
97     std::shared_ptr<IccFile> simFile_ = nullptr;
98     std::shared_ptr<IccDiallingNumbersHandler> diallingNumberHandler_ = nullptr;
99     HandleRunningState stateRecord_ = HandleRunningState::STATE_NOT_START;
100     HandleRunningState stateHandler_ = HandleRunningState::STATE_NOT_START;
101     std::weak_ptr<Telephony::SimStateManager> simStateManager_;
102     int32_t slotId_ = 0;
103     IccType iccType_ = IccType::ICC_TYPE_USIM;
104     std::map<IccType, std::shared_ptr<IccFile>> iccFileCache_;
105     std::map<IccType, std::shared_ptr<IccFileController>> iccFileControllerCache_;
106 
107 private:
108     bool InitDiallingNumberHandler();
109     IccType GetIccTypeByCardType(CardType type);
110     IccType GetIccTypeByTech(const std::shared_ptr<VoiceRadioTechnology> &tech);
111     bool InitSimFile(IccType type);
112     bool InitIccFileController(IccType type);
113     void ChangeSimFileByCardType(IccType type);
114     bool IsValidType(IccType type);
115     bool IsCTCardType(CardType type);
116     bool IsCTIccId(std::string iccId);
117     std::string opName_;
118     std::string opKey_;
119     std::string opKeyExt_;
120 
121     const std::string VM_NUMBER_KEY = "persist.telephony.voicemail.gsm";
122     const std::string VM_NUMBER_CDMA_KEY = "persist.telephony.voicemail.cdma";
123     void SetVoiceMailParamGsm(const std::u16string mailNumber, bool isSavedIccRecords);
124     void SetVoiceMailParamCdma(const std::u16string mailNumber);
125     std::string GetVoiceMailNumberKey();
126     std::string GetVoiceMailNumberCdmaKey();
127     std::string GetVoiceMailNumberFromParam();
128     void SetVoiceMailSimImsiParam(std::string imsi);
129     void StoreVoiceMailNumber(const std::u16string mailNumber, bool isSavedIccRecoeds);
130     std::string GetVoiceMailSimImsiFromParam();
131     void HandleVoiceTechChanged(std::shared_ptr<VoiceRadioTechnology> tech);
132     void HandleIccRefresh();
133     void HandleOperatorConfigChanged();
134     void HandleSimRecordsLoaded();
135     void HandleSimIccidLoaded(std::string iccid);
136     bool IsPhoneTypeGsm(int32_t slotId);
137     std::string EncryptImsi(const std::string imsi);
138     bool IsEncryptImsiEmpty(const std::string encryptImsi);
139     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
140 };
141 } // namespace Telephony
142 } // namespace OHOS
143 #endif // OHOS_SIM_FILE_MANAGER_H
144