• 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 #ifdef CORE_SERVICE_SUPPORT_ESIM
24 #include "esim_file.h"
25 #endif
26 #include "i_tel_ril_manager.h"
27 #include "isim_file.h"
28 #include "isim_file_controller.h"
29 #include "ruim_file.h"
30 #include "ruim_file_controller.h"
31 #include "sim_file.h"
32 #include "sim_file_controller.h"
33 #include "system_ability_status_change_stub.h"
34 #include "tel_ril_modem_parcel.h"
35 #include "telephony_log_wrapper.h"
36 #include "usim_file_controller.h"
37 
38 namespace OHOS {
39 namespace Telephony {
40 class SimFileManager : public TelEventHandler, public EventFwk::CommonEventSubscriber {
41 public:
42     using HANDLE = std::shared_ptr<AppExecFwk::EventHandler>;
43     SimFileManager(
44         const EventFwk::CommonEventSubscribeInfo &sp, std::weak_ptr<Telephony::ITelRilManager> telRilManager,
45         std::weak_ptr<Telephony::SimStateManager> state);
46     virtual ~SimFileManager();
47     void Init(int slotId);
48     void ClearData();
49     std::u16string GetSimOperatorNumeric();
50     std::u16string GetISOCountryCodeForSim();
51     std::u16string GetSimSpn();
52     std::u16string GetSimEons(const std::string &plmn, int32_t lac, bool longNameRequired);
53     std::u16string GetSimIccId();
54     std::u16string GetSimDecIccId();
55     std::u16string GetIMSI();
56     std::u16string GetMCC();
57     std::u16string GetMNC();
58     std::u16string GetLocaleFromDefaultSim();
59     std::u16string GetSimGid1();
60     std::u16string GetSimGid2();
61     std::u16string GetSimTelephoneNumber();
62     std::u16string GetSimTeleNumberIdentifier();
63     std::u16string GetSimIst();
64     std::u16string GetVoiceMailIdentifier();
65     std::u16string GetVoiceMailNumber();
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 #ifdef CORE_SERVICE_SUPPORT_ESIM
94     std::shared_ptr<EsimFile> GetEsimfile();
95     std::u16string GetEid();
96     GetEuiccProfileInfoListInnerResult GetEuiccProfileInfoList();
97     EuiccInfo GetEuiccInfo();
98     int32_t DisableProfile(int32_t portIndex, const std::u16string &iccId);
99     std::u16string GetSmdsAddress(int32_t portIndex);
100     EuiccRulesAuthTable GetRulesAuthTable(int32_t portIndex);
101     ResponseEsimInnerResult GetEuiccChallenge(int32_t portIndex);
102     std::u16string GetDefaultSmdpAddress();
103     ResponseEsimInnerResult CancelSession(const std::u16string &transactionId, CancelReason cancelReason);
104     EuiccProfile GetProfile(int32_t portIndex, const std::u16string &iccId);
105     int32_t ResetMemory(ResetOption resetOption);
106     int32_t SetDefaultSmdpAddress(const std::u16string &defaultSmdpAddress);
107     bool IsSupported();
108     ResponseEsimInnerResult SendApduData(const std::u16string &aid, const EsimApduData &apduData);
109     ResponseEsimInnerResult PrepareDownload(const DownLoadConfigInfo &downLoadConfigInfo);
110     ResponseEsimBppResult LoadBoundProfilePackage(int32_t portIndex, const std::u16string &boundProfilePackage);
111     EuiccNotificationList ListNotifications(int32_t portIndex, Event events);
112     EuiccNotificationList RetrieveNotificationList(int32_t portIndex, Event events);
113     EuiccNotification RetrieveNotification(int32_t portIndex, int32_t seqNumber);
114     int32_t RemoveNotificationFromList(int32_t portIndex, int32_t seqNumber);
115     int32_t DeleteProfile(const std::u16string &iccId);
116     int32_t SwitchToProfile(int32_t portIndex, const std::u16string &iccId, bool forceDisableProfile);
117     int32_t SetProfileNickname(const std::u16string &iccId, const std::u16string &nickname);
118     EuiccInfo2 GetEuiccInfo2(int32_t portIndex);
119     ResponseEsimInnerResult AuthenticateServer(const AuthenticateConfigInfo &authenticateConfigInfo);
120 #endif
121 
122 protected:
123     std::weak_ptr<Telephony::ITelRilManager> telRilManager_;
124     std::shared_ptr<IccFileController> fileController_ = nullptr;
125     std::shared_ptr<IccFile> simFile_ = nullptr;
126 #ifdef CORE_SERVICE_SUPPORT_ESIM
127     std::shared_ptr<EsimFile> eSimFile_ = nullptr;
128 #endif
129     std::shared_ptr<IccDiallingNumbersHandler> diallingNumberHandler_ = nullptr;
130     HandleRunningState stateRecord_ = HandleRunningState::STATE_NOT_START;
131     HandleRunningState stateHandler_ = HandleRunningState::STATE_NOT_START;
132     std::weak_ptr<Telephony::SimStateManager> simStateManager_;
133     int32_t slotId_ = 0;
134     IccType iccType_ = IccType::ICC_TYPE_USIM;
135     std::map<IccType, std::shared_ptr<IccFile>> iccFileCache_;
136     std::map<IccType, std::shared_ptr<IccFileController>> iccFileControllerCache_;
137 
138 private:
139     bool InitDiallingNumberHandler();
140     IccType GetIccTypeByCardType(CardType type);
141     IccType GetIccTypeByTech(const std::shared_ptr<VoiceRadioTechnology> &tech);
142     bool InitSimFile(IccType type);
143     bool InitIccFileController(IccType type);
144     void ChangeSimFileByCardType(IccType type);
145     bool IsValidType(IccType type);
146     bool IsCTCardType(CardType type);
147     bool IsCTIccId(std::string iccId);
148     std::string opName_;
149     std::string opKey_;
150     std::string opKeyExt_;
151 
152     const std::string VM_NUMBER_KEY = "persist.telephony.voicemail.gsm";
153     const std::string VM_NUMBER_CDMA_KEY = "persist.telephony.voicemail.cdma";
154     void SetVoiceMailParamGsm(const std::u16string mailNumber, bool isSavedIccRecords);
155     void SetVoiceMailParamCdma(const std::u16string mailNumber);
156     std::string GetVoiceMailNumberKey();
157     std::string GetVoiceMailNumberCdmaKey();
158     std::string GetVoiceMailNumberFromParam();
159     void SetVoiceMailSimImsiParam(std::string imsi);
160     void StoreVoiceMailNumber(const std::u16string mailNumber, bool isSavedIccRecoeds);
161     std::string GetVoiceMailSimImsiFromParam();
162     void HandleVoiceTechChanged(std::shared_ptr<VoiceRadioTechnology> tech);
163     void HandleIccRefresh();
164     void HandleOperatorConfigChanged();
165     void HandleSimRecordsLoaded();
166     void HandleSimIccidLoaded(std::string iccid);
167     bool IsPhoneTypeGsm(int32_t slotId);
168     std::string EncryptImsi(const std::string imsi);
169     bool IsEncryptImsiEmpty(const std::string encryptImsi);
170     sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr;
171 };
172 } // namespace Telephony
173 } // namespace OHOS
174 #endif // OHOS_SIM_FILE_MANAGER_H
175