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