• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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_MANAGER_H
17 #define OHOS_SIM_MANAGER_H
18 
19 #include "event_handler.h"
20 #include "i_sim_manager.h"
21 #include "i_tel_ril_manager.h"
22 #include "multi_sim_controller.h"
23 #include "multi_sim_monitor.h"
24 #include "sim_state_manager.h"
25 #include "sim_file_manager.h"
26 #include "sim_sms_manager.h"
27 #include "sim_account_manager.h"
28 #include "icc_dialling_numbers_manager.h"
29 #include "stk_manager.h"
30 
31 namespace OHOS {
32 namespace Telephony {
33 const int32_t SLOT_ID_ZERO = 0;
34 const int32_t SIM_IO_DATA_MIN_LEN = 6;
35 const int32_t SIM_IO_DATA_STR_LEN = 2;
36 const int32_t SIM_IO_DATA_P1_OFFSET = 0;
37 const int32_t SIM_IO_DATA_P2_OFFSET = 2;
38 const int32_t SIM_IO_DATA_P3_OFFSET = 4;
39 const int32_t SIM_IO_HEX_SIGN = 16;
40 class SimManager : public ISimManager {
41 public:
42     explicit SimManager(std::shared_ptr<ITelRilManager> telRilManager);
43     virtual ~SimManager();
44     // Init
45     bool OnInit(int32_t slotCount) override;
46     int32_t InitTelExtraModule(int32_t slotId) override;
47     // SimState
48     int32_t HasSimCard(int32_t slotId, bool &hasSimCard) override;
49     int32_t GetSimState(int32_t slotId, SimState &simState) override;
50     int32_t GetSimIccStatus(int32_t slotId, IccSimStatus &iccStatus) override;
51     int32_t GetCardType(int32_t slotId, CardType &cardType) override;
52     int32_t SetModemInit(int32_t slotId, bool state) override;
53     int32_t UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response) override;
54     int32_t UnlockPuk(
55         int32_t slotId, const std::string &newPin, const std::string &puk, LockStatusResponse &response) override;
56     int32_t AlterPin(
57         int32_t slotId, const std::string &newPin, const std::string &oldPin, LockStatusResponse &response) override;
58     int32_t SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response) override;
59     int32_t GetLockState(int32_t slotId, LockType lockType, LockState &lockState) override;
60     int32_t RefreshSimState(int32_t slotId) override;
61     int32_t UnlockPin2(int32_t slotId, const std::string &pin2, LockStatusResponse &response) override;
62     int32_t UnlockPuk2(
63         int32_t slotId, const std::string &newPin2, const std::string &puk2, LockStatusResponse &response) override;
64     int32_t AlterPin2(
65         int32_t slotId, const std::string &newPin2, const std::string &oldPin2, LockStatusResponse &response) override;
66     int32_t UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response) override;
67     // SimAccount
68     bool IsSimActive(int32_t slotId) override;
69     int32_t SetActiveSim(int32_t slotId, int32_t enable) override;
70     int32_t SetActiveSimSatellite(int32_t slotId, int32_t enable) override;
71     int32_t GetSimAccountInfo(int32_t slotId, bool denied, IccAccountInfo &info) override;
72     int32_t ResetSimLoadAccount(int32_t slotId) override;
73     int32_t SetDefaultVoiceSlotId(int32_t slotId) override;
74     int32_t SetDefaultSmsSlotId(int32_t slotId) override;
75     int32_t SetDefaultCellularDataSlotId(int32_t slotId) override;
76     int32_t SetPrimarySlotId(int32_t slotId) override;
77     int32_t SetShowNumber(int32_t slotId, const std::u16string &number) override;
78     int32_t SetShowName(int32_t slotId, const std::u16string &name) override;
79     int32_t GetDefaultVoiceSlotId() override;
80     int32_t GetDefaultVoiceSimId(int32_t &simId) override;
81     int32_t GetDefaultSmsSlotId() override;
82     int32_t GetDefaultSmsSimId(int32_t &simId) override;
83     int32_t GetDefaultCellularDataSlotId() override;
84     int32_t GetDefaultCellularDataSimId(int32_t &simId) override;
85     int32_t GetPrimarySlotId(int32_t &slotId) override;
86     int32_t GetShowNumber(int32_t slotId, std::u16string &showNumber) override;
87     int32_t GetShowName(int32_t slotId, std::u16string &showName) override;
88     int32_t GetSlotId(int32_t simId) override;
89     int32_t GetSimId(int32_t slotId) override;
90     int32_t GetActiveSimAccountInfoList(bool denied, std::vector<IccAccountInfo> &iccAccountInfoList) override;
91     int32_t GetOperatorConfigs(int32_t slotId, OperatorConfig &poc) override;
92     int32_t UpdateOperatorConfigs(int32_t slotId) override;
93     int32_t HasOperatorPrivileges(const int32_t slotId, bool &hasOperatorPrivileges) override;
94     int32_t SimAuthentication(
95         int32_t slotId, AuthType authType, const std::string &authData, SimAuthenticationResponse &response) override;
96     int32_t GetRadioProtocolTech(int32_t slotId) override;
97     void GetRadioProtocol(int32_t slotId) override;
98     int32_t GetDsdsMode(int32_t &dsdsMode) override;
99     int32_t SetDsdsMode(int32_t dsdsMode) override;
100     int32_t SendSimMatchedOperatorInfo(
101         int32_t slotId, int32_t state, const std::string &operName, const std::string &operKey) override;
102     // STK
103     int32_t SendEnvelopeCmd(int32_t slotId, const std::string &cmd) override;
104     int32_t SendTerminalResponseCmd(int32_t slotId, const std::string &cmd) override;
105     int32_t SendCallSetupRequestResult(int32_t slotId, bool accept) override;
106     // SimFile
107     int32_t GetSimOperatorNumeric(int32_t slotId, std::u16string &operatorNumeric) override;
108     int32_t GetISOCountryCodeForSim(int32_t slotId, std::u16string &countryCode) override;
109     int32_t GetSimSpn(int32_t slotId, std::u16string &spn) override;
110     std::u16string GetSimEons(int32_t slotId, const std::string &plmn, int32_t lac, bool longNameRequired) override;
111     int32_t GetSimIccId(int32_t slotId, std::u16string &iccId) override;
112     int32_t GetIMSI(int32_t slotId, std::u16string &imsi) override;
113     std::u16string GetLocaleFromDefaultSim(int32_t slotId) override;
114     int32_t GetSimGid1(int32_t slotId, std::u16string &gid1) override;
115     std::u16string GetSimGid2(int32_t slotId) override;
116     int32_t GetOpName(int32_t slotId, std::u16string &opname) override;
117     int32_t GetOpKey(int32_t slotId, std::u16string &opkey) override;
118     int32_t GetOpKeyExt(int32_t slotId, std::u16string &opkeyExt) override;
119     int32_t GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber) override;
120     int32_t GetVoiceMailNumber(int32_t slotId, std::u16string &voiceMailNumber) override;
121     int32_t GetVoiceMailCount(int32_t slotId, int32_t &voiceMailCount) override;
122     int32_t SetVoiceMailCount(int32_t slotId, int32_t voiceMailCount) override;
123     int32_t SetVoiceCallForwarding(int32_t slotId, bool enable, const std::string &number) override;
124     int32_t GetVoiceMailIdentifier(int32_t slotId, std::u16string &voiceMailIdentifier) override;
125     std::u16string GetSimTeleNumberIdentifier(const int32_t slotId) override;
126     std::u16string GetSimIst(int32_t slotId) override;
127     int ObtainSpnCondition(int32_t slotId, bool roaming, std::string operatorNum) override;
128     int32_t SetVoiceMailInfo(int32_t slotId, const std::u16string &mailName, const std::u16string &mailNumber) override;
129     int32_t IsCTSimCard(int32_t slotId, bool &isCTSimCard) override;
130     // SimSms
131     int32_t AddSmsToIcc(int32_t slotId, int status, std::string &pdu, std::string &smsc) override;
132     int32_t UpdateSmsIcc(
133         int32_t slotId, int index, int status, std::string &pduData, std::string &smsc) override;
134     int32_t DelSmsIcc(int32_t slotId, int index) override;
135     std::vector<std::string> ObtainAllSmsOfIcc(int32_t slotId) override;
136     // IccDiallingNumbers
137     int32_t AddIccDiallingNumbers(
138         int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override;
139     int32_t DelIccDiallingNumbers(
140         int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override;
141     int32_t UpdateIccDiallingNumbers(
142         int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override;
143     int32_t QueryIccDiallingNumbers(
144         int slotId, int type, std::vector<std::shared_ptr<DiallingNumbersInfo>> &result) override;
145     // Event register
146     void RegisterCoreNotify(int32_t slotId, const HANDLE &handler, int what) override;
147     void UnRegisterCoreNotify(int32_t slotId, const HANDLE &observerCallBack, int what) override;
148     // Ims Switch
149     int32_t SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue) override;
150     int32_t QueryImsSwitch(int32_t, int32_t &imsSwitchValue) override;
151     int32_t RegisterSimAccountCallback(
152         const int32_t tokenId, const sptr<SimAccountCallback> &callback) override;
153     int32_t UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback) override;
154 
155     bool IsSetActiveSimInProgress(int32_t slotId) override;
156     bool IsSetPrimarySlotIdInProgress() override;
157     int32_t GetSimIO(int32_t slotId, int32_t command, int32_t fileId,
158         const std::string &data, const std::string &path, SimAuthenticationResponse &response) override;
159     int32_t SavePrimarySlotId(int32_t slotId) override;
160     bool IsDataShareError() override;
161     void ResetDataShareError() override;
162     void UpdateImsCapFromChip(int32_t slotId, const ImsCapFromChip &imsCapFromChip) override;
163     int32_t GetDefaultMainSlotByIccId() override;
164 #ifdef CORE_SERVICE_SUPPORT_ESIM
165     int32_t GetEid(int32_t slotId, std::u16string &eId) override;
166     int32_t GetEuiccProfileInfoList(int32_t slotId, GetEuiccProfileInfoListInnerResult &euiccProfileInfoList) override;
167     int32_t GetEuiccInfo(int32_t slotId, EuiccInfo &eUiccInfo) override;
168     int32_t DisableProfile(
169         int32_t slotId, int32_t portIndex, const std::u16string &iccId, bool refresh, int32_t &enumResult) override;
170     int32_t GetSmdsAddress(int32_t slotId, int32_t portIndex, std::u16string &smdsAddress) override;
171     int32_t GetRulesAuthTable(int32_t slotId, int32_t portIndex, EuiccRulesAuthTable &eUiccRulesAuthTable) override;
172     int32_t GetEuiccChallenge(int32_t slotId, int32_t portIndex, ResponseEsimInnerResult &responseResult) override;
173     int32_t GetDefaultSmdpAddress(int32_t slotId, std::u16string &defaultSmdpAddress) override;
174     int32_t CancelSession(int32_t slotId, const std::u16string &transactionId, CancelReason cancelReason,
175         ResponseEsimInnerResult &responseResult) override;
176     int32_t GetProfile(
177         int32_t slotId, int32_t portIndex, const std::u16string &iccId, EuiccProfile &eUiccProfile) override;
178     int32_t ResetMemory(int32_t slotId, ResetOption resetOption, int32_t &enumResult) override;
179     int32_t SetDefaultSmdpAddress(
180         int32_t slotId, const std::u16string &defaultSmdpAddress, int32_t &enumResult) override;
181     bool IsSupported(int32_t slotId) override;
182     int32_t SendApduData(int32_t slotId, const std::u16string &aid, const EsimApduData &apduData,
183         ResponseEsimInnerResult &responseResult) override;
184     int32_t PrepareDownload(int32_t slotId, const DownLoadConfigInfo &downLoadConfigInfo,
185         ResponseEsimInnerResult &responseResult) override;
186     int32_t LoadBoundProfilePackage(int32_t slotId, int32_t portIndex, const std::u16string &boundProfilePackage,
187         ResponseEsimBppResult &responseResult) override;
188     int32_t ListNotifications(int32_t slotId, int32_t portIndex, Event events,
189         EuiccNotificationList &notificationList) override;
190     int32_t RetrieveNotificationList(
191         int32_t slotId, int32_t portIndex, Event events, EuiccNotificationList &notificationList) override;
192     int32_t RetrieveNotification(
193         int32_t slotId, int32_t portIndex, int32_t seqNumber, EuiccNotification &notification) override;
194     int32_t RemoveNotificationFromList(
195         int32_t slotId, int32_t portIndex, int32_t seqNumber, int32_t &enumResult) override;
196     int32_t GetEuiccInfo2(int32_t slotId, int32_t portIndex, EuiccInfo2 &euiccInfo2) override;
197     int32_t AuthenticateServer(int32_t slotId, const AuthenticateConfigInfo &authenticateConfigInfo,
198         ResponseEsimInnerResult &responseResult) override;
199     int32_t DeleteProfile(int32_t slotId, const std::u16string &iccId, int32_t &enumResult) override;
200     int32_t SwitchToProfile(int32_t slotId, int32_t portIndex, const std::u16string &iccId,
201         bool forceDisableProfile, int32_t &enumResult) override;
202     int32_t SetProfileNickname(
203         int32_t slotId, const std::u16string &iccId, const std::u16string &nickname, int32_t &enumResult) override;
204 #endif
205 
206 private:
207     bool IsValidSlotId(int32_t slotId);
208     template<class N>
209     bool IsValidSlotId(int32_t slotId, std::vector<N> vec);
210     bool IsValidAuthType(AuthType authType);
211     bool IsValidSlotIdForDefault(int32_t slotId);
212     void InitMultiSimObject();
213     void InitSingleSimObject();
214     void InitBaseManager(int32_t slotId);
215     bool HasSimCardInner(int32_t slotId);
216 
217 private:
218     std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr;
219     std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager_;
220     std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager_;
221     std::vector<std::shared_ptr<Telephony::SimSmsManager>> simSmsManager_;
222     std::vector<std::shared_ptr<Telephony::SimAccountManager>> simAccountManager_;
223     std::vector<std::shared_ptr<Telephony::IccDiallingNumbersManager>> iccDiallingNumbersManager_;
224     std::vector<std::shared_ptr<Telephony::StkManager>> stkManager_;
225     std::shared_ptr<MultiSimController> multiSimController_ = nullptr;
226     std::shared_ptr<MultiSimMonitor> multiSimMonitor_ = nullptr;
227     std::shared_ptr<AppExecFwk::EventRunner> controllerRunner_ = nullptr;
228     std::shared_ptr<AppExecFwk::EventRunner> monitorRunner_;
229     int32_t slotCount_ = SLOT_ID_ZERO;
230     int32_t dsdsMode_ = DSDS_MODE_V2;
231     std::shared_mutex mtx_;
232 };
233 } // namespace Telephony
234 } // namespace OHOS
235 #endif // OHOS_SIM_MANAGER_H
236