• 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 "event_handler.h"
20 #include "event_runner.h"
21 #include "hril_modem_parcel.h"
22 #include "sim_file_controller.h"
23 #include "usim_file_controller.h"
24 #include "i_tel_ril_manager.h"
25 #include "ruim_file.h"
26 #include "ruim_file_controller.h"
27 #include "sim_file.h"
28 #include "isim_file.h"
29 #include "isim_file_controller.h"
30 #include "csim_file_controller.h"
31 #include "telephony_log_wrapper.h"
32 
33 namespace OHOS {
34 namespace Telephony {
35 class SimFileManager : public AppExecFwk::EventHandler {
36 public:
37     using HANDLE = std::shared_ptr<AppExecFwk::EventHandler>;
38     SimFileManager(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
39         std::shared_ptr<Telephony::ITelRilManager> telRilManager,
40         std::shared_ptr<Telephony::SimStateManager> state);
41     virtual ~SimFileManager();
42     void Init(int slotId);
43     void ClearData();
44     std::u16string GetSimOperatorNumeric();
45     std::u16string GetISOCountryCodeForSim();
46     std::u16string GetSimSpn();
47     std::u16string GetSimEons(const std::string &plmn, int32_t lac, bool longNameRequired);
48     std::u16string GetSimIccId();
49     std::u16string GetIMSI();
50     std::u16string GetLocaleFromDefaultSim();
51     std::u16string GetSimGid1();
52     std::u16string GetSimGid2();
53     std::u16string GetSimTelephoneNumber();
54     std::u16string GetSimTeleNumberIdentifier();
55     std::u16string GetSimIst();
56     std::u16string GetVoiceMailIdentifier();
57     std::u16string GetVoiceMailNumber();
58     std::u16string GetOpName();
59     std::u16string GetOpKey();
60     std::u16string GetOpKeyExt();
61     void SetOpName(const std::string &opName);
62     void SetOpKey(const std::string &opKey);
63     void SetOpKeyExt(const std::string &opKeyExt);
64     int ObtainSpnCondition(bool roaming, const std::string &operatorNum);
65     void RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what);
66     void UnRegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &observerCallBack, int what);
67     void SetImsi(std::string imsi);
68     std::shared_ptr<IccFile> GetIccFile();
69     std::shared_ptr<IccFileController> GetIccFileController();
70     std::shared_ptr<IccDiallingNumbersHandler> ObtainDiallingNumberHandler();
71     bool SetVoiceMailInfo(const std::u16string &mailName, const std::u16string &mailNumber);
72     bool HasSimCard();
73     void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event);
74     static std::shared_ptr<SimFileManager> CreateInstance(
75         const std::shared_ptr<Telephony::ITelRilManager> &ril,
76         const std::shared_ptr<SimStateManager> &simState);
77     enum class HandleRunningState { STATE_NOT_START, STATE_RUNNING };
78     enum class IccType { ICC_TYPE_CDMA, ICC_TYPE_GSM, ICC_TYPE_IMS, ICC_TYPE_USIM };
79 
80 protected:
81     std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr;
82     std::shared_ptr<IccFileController> fileController_ = nullptr;
83     std::shared_ptr<IccFile> simFile_ = nullptr;
84     std::shared_ptr<IccDiallingNumbersHandler> diallingNumberHandler_ = nullptr;
85     std::shared_ptr<AppExecFwk::EventRunner> eventLoopRecord_ = nullptr;
86     std::shared_ptr<AppExecFwk::EventRunner> eventLoopFileController_ = nullptr;
87     HandleRunningState stateRecord_ = HandleRunningState::STATE_NOT_START;
88     HandleRunningState stateHandler_ = HandleRunningState::STATE_NOT_START;
89     std::shared_ptr<Telephony::SimStateManager> simStateManager_ = nullptr;
90     int slotId_ = 0;
91     IccType iccType_ = IccType::ICC_TYPE_USIM;
92     std::map<IccType, std::shared_ptr<IccFile>> iccFileCache_;
93     std::map<IccType, std::shared_ptr<IccFileController>> iccFileControllerCache_;
94 
95 private:
96     bool InitDiallingNumberHandler();
97     IccType GetIccTypeByCardType(CardType type);
98     IccType GetIccTypeByTech(const std::shared_ptr<VoiceRadioTechnology> &tech);
99     bool InitSimFile(IccType type);
100     bool InitIccFileController(IccType type);
101     void ChangeSimFileByCardType(IccType type);
102     bool IsValidType(IccType type);
103     std::string opName_;
104     std::string opKey_;
105     std::string opKeyExt_;
106 };
107 } // namespace Telephony
108 } // namespace OHOS
109 #endif // OHOS_SIM_FILE_MANAGER_H