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 "ffrt_inner.h" 20 #include "event_handler.h" 21 #include "i_sim_manager.h" 22 #include "i_tel_ril_manager.h" 23 #include "multi_sim_controller.h" 24 #include "multi_sim_monitor.h" 25 #include "sim_state_manager.h" 26 #include "sim_file_manager.h" 27 #include "sim_sms_manager.h" 28 #include "sim_account_manager.h" 29 #include "icc_dialling_numbers_manager.h" 30 #include "stk_manager.h" 31 32 namespace OHOS { 33 namespace Telephony { 34 const int32_t SLOT_ID_ZERO = 0; 35 const int32_t SIM_IO_DATA_MIN_LEN = 6; 36 const int32_t SIM_IO_DATA_STR_LEN = 2; 37 const int32_t SIM_IO_DATA_P1_OFFSET = 0; 38 const int32_t SIM_IO_DATA_P2_OFFSET = 2; 39 const int32_t SIM_IO_DATA_P3_OFFSET = 4; 40 const int32_t SIM_IO_HEX_SIGN = 16; 41 class SimManager : public ISimManager { 42 public: 43 explicit SimManager(std::shared_ptr<ITelRilManager> telRilManager); 44 virtual ~SimManager(); 45 // Init 46 bool OnInit(int32_t slotCount) override; 47 int32_t InitTelExtraModule(int32_t slotId) override; 48 // SimState 49 int32_t HasSimCard(int32_t slotId, bool &hasSimCard) override; 50 int32_t GetSimState(int32_t slotId, SimState &simState) override; 51 int32_t GetSimIccStatus(int32_t slotId, IccSimStatus &iccStatus) override; 52 int32_t GetCardType(int32_t slotId, CardType &cardType) override; 53 int32_t SetModemInit(int32_t slotId, bool state) override; 54 int32_t UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response) override; 55 int32_t UnlockPuk( 56 int32_t slotId, const std::string &newPin, const std::string &puk, LockStatusResponse &response) override; 57 int32_t AlterPin( 58 int32_t slotId, const std::string &newPin, const std::string &oldPin, LockStatusResponse &response) override; 59 int32_t SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response) override; 60 int32_t GetLockState(int32_t slotId, LockType lockType, LockState &lockState) override; 61 int32_t RefreshSimState(int32_t slotId) override; 62 int32_t UnlockPin2(int32_t slotId, const std::string &pin2, LockStatusResponse &response) override; 63 int32_t UnlockPuk2( 64 int32_t slotId, const std::string &newPin2, const std::string &puk2, LockStatusResponse &response) override; 65 int32_t AlterPin2( 66 int32_t slotId, const std::string &newPin2, const std::string &oldPin2, LockStatusResponse &response) override; 67 int32_t UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response) override; 68 // SimAccount 69 bool IsSimActive(int32_t slotId) override; 70 int32_t SetActiveSim(int32_t slotId, int32_t enable) override; 71 int32_t SetActiveSimSatellite(int32_t slotId, int32_t enable) override; 72 int32_t GetSimAccountInfo(int32_t slotId, bool denied, IccAccountInfo &info) override; 73 int32_t ResetSimLoadAccount(int32_t slotId) override; 74 int32_t SetDefaultVoiceSlotId(int32_t slotId) override; 75 int32_t SetDefaultSmsSlotId(int32_t slotId) override; 76 int32_t SetDefaultCellularDataSlotId(int32_t slotId) override; 77 int32_t SetPrimarySlotId(int32_t slotId, bool isUserSet = false) override; 78 int32_t SetShowNumber(int32_t slotId, const std::u16string &number) override; 79 int32_t SetShowName(int32_t slotId, const std::u16string &name) override; 80 int32_t GetDefaultVoiceSlotId() override; 81 int32_t GetDefaultVoiceSimId(int32_t &simId) override; 82 int32_t GetDefaultSmsSlotId() override; 83 int32_t GetDefaultSmsSimId(int32_t &simId) override; 84 int32_t GetDefaultCellularDataSlotId() override; 85 int32_t GetDefaultCellularDataSimId(int32_t &simId) override; 86 int32_t GetPrimarySlotId(int32_t &slotId) override; 87 int32_t GetShowNumber(int32_t slotId, std::u16string &showNumber) override; 88 int32_t GetShowName(int32_t slotId, std::u16string &showName) override; 89 int32_t GetSlotId(int32_t simId) override; 90 int32_t GetSimId(int32_t slotId) override; 91 int32_t GetActiveSimAccountInfoList(bool denied, std::vector<IccAccountInfo> &iccAccountInfoList) override; 92 int32_t GetOperatorConfigs(int32_t slotId, OperatorConfig &poc) override; 93 int32_t UpdateOperatorConfigs(int32_t slotId) override; 94 int32_t HasOperatorPrivileges(const int32_t slotId, bool &hasOperatorPrivileges) override; 95 int32_t SimAuthentication( 96 int32_t slotId, AuthType authType, const std::string &authData, SimAuthenticationResponse &response) override; 97 int32_t GetRadioProtocolTech(int32_t slotId) override; 98 void GetRadioProtocol(int32_t slotId) override; 99 int32_t GetDsdsMode(int32_t &dsdsMode) override; 100 int32_t SetDsdsMode(int32_t dsdsMode) override; 101 int32_t SendSimMatchedOperatorInfo( 102 int32_t slotId, int32_t state, const std::string &operName, const std::string &operKey) override; 103 // STK 104 int32_t SendEnvelopeCmd(int32_t slotId, const std::string &cmd) override; 105 int32_t SendTerminalResponseCmd(int32_t slotId, const std::string &cmd) override; 106 int32_t SendCallSetupRequestResult(int32_t slotId, bool accept) override; 107 // SimFile 108 int32_t GetSimOperatorNumeric(int32_t slotId, std::u16string &operatorNumeric) override; 109 int32_t GetISOCountryCodeForSim(int32_t slotId, std::u16string &countryCode) override; 110 int32_t GetSimSpn(int32_t slotId, std::u16string &spn) override; 111 std::u16string GetSimEons(int32_t slotId, const std::string &plmn, int32_t lac, bool longNameRequired) override; 112 int32_t GetSimIccId(int32_t slotId, std::u16string &iccId) override; 113 int32_t GetIMSI(int32_t slotId, std::u16string &imsi) override; 114 int32_t GetEhPlmns(int32_t slotId, std::set<std::string> &ehPlmns) override; 115 int32_t GetSpdiPlmns(int32_t slotId, std::set<std::string> &spdiPlmns) override; 116 std::u16string GetLocaleFromDefaultSim(int32_t slotId) override; 117 int32_t GetSimGid1(int32_t slotId, std::u16string &gid1) override; 118 std::u16string GetSimGid2(int32_t slotId) override; 119 int32_t GetOpName(int32_t slotId, std::u16string &opname) override; 120 int32_t GetOpKey(int32_t slotId, std::u16string &opkey) override; 121 int32_t GetOpKeyExt(int32_t slotId, std::u16string &opkeyExt) override; 122 int32_t GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber) override; 123 int32_t GetVoiceMailNumber(int32_t slotId, std::u16string &voiceMailNumber) override; 124 int32_t GetVoiceMailCount(int32_t slotId, int32_t &voiceMailCount) override; 125 int32_t SetVoiceMailCount(int32_t slotId, int32_t voiceMailCount) override; 126 int32_t SetVoiceCallForwarding(int32_t slotId, bool enable, const std::string &number) override; 127 int32_t GetVoiceMailIdentifier(int32_t slotId, std::u16string &voiceMailIdentifier) override; 128 std::u16string GetSimTeleNumberIdentifier(const int32_t slotId) override; 129 std::u16string GetSimIst(int32_t slotId) override; 130 int ObtainSpnCondition(int32_t slotId, bool roaming, std::string operatorNum) override; 131 int32_t SetVoiceMailInfo(int32_t slotId, const std::u16string &mailName, const std::u16string &mailNumber) override; 132 int32_t IsCTSimCard(int32_t slotId, bool &isCTSimCard) override; 133 // SimSms 134 int32_t AddSmsToIcc(int32_t slotId, int status, std::string &pdu, std::string &smsc) override; 135 int32_t UpdateSmsIcc( 136 int32_t slotId, int index, int status, std::string &pduData, std::string &smsc) override; 137 int32_t DelSmsIcc(int32_t slotId, int index) override; 138 std::vector<std::string> ObtainAllSmsOfIcc(int32_t slotId) override; 139 // IccDiallingNumbers 140 int32_t AddIccDiallingNumbers( 141 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override; 142 int32_t DelIccDiallingNumbers( 143 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override; 144 int32_t UpdateIccDiallingNumbers( 145 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override; 146 int32_t QueryIccDiallingNumbers( 147 int slotId, int type, std::vector<std::shared_ptr<DiallingNumbersInfo>> &result) override; 148 // Event register 149 void RegisterCoreNotify(int32_t slotId, const HANDLE &handler, int what) override; 150 void UnRegisterCoreNotify(int32_t slotId, const HANDLE &observerCallBack, int what) override; 151 // Ims Switch 152 int32_t SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue) override; 153 int32_t QueryImsSwitch(int32_t, int32_t &imsSwitchValue) override; 154 int32_t RegisterSimAccountCallback( 155 const int32_t tokenId, const sptr<SimAccountCallback> &callback) override; 156 int32_t UnregisterSimAccountCallback(const sptr<SimAccountCallback> &callback) override; 157 158 bool IsSetActiveSimInProgress(int32_t slotId) override; 159 bool IsSetPrimarySlotIdInProgress() override; 160 int32_t GetSimIO(int32_t slotId, int32_t command, int32_t fileId, 161 const std::string &data, const std::string &path, SimAuthenticationResponse &response) override; 162 int32_t SavePrimarySlotId(int32_t slotId) override; 163 bool IsDataShareError() override; 164 void ResetDataShareError() override; 165 void UpdateImsCapFromChip(int32_t slotId, const ImsCapFromChip &imsCapFromChip) override; 166 int32_t GetDefaultMainSlotByIccId() override; 167 int32_t GetSimLabel(int32_t slotId, SimLabel &simLabel) override; 168 int32_t SetSimLabelIndex(const std::string &iccId, int32_t labelIndex) override; 169 int32_t NotifySimSlotsMapping(int32_t slotId) override; 170 int32_t InsertEsimData(const std::string &iccId, int32_t siLabel, const std::string &operatorName) override; 171 int32_t GetAllSimAccountInfoList(bool denied, std::vector<IccAccountInfo> &iccAccountInfoList) override; 172 173 private: 174 bool IsValidSlotId(int32_t slotId); 175 template<class N> 176 bool IsValidSlotId(int32_t slotId, std::vector<N> vec); 177 bool IsValidAuthType(AuthType authType); 178 bool IsValidSlotIdForDefault(int32_t slotId); 179 void InitMultiSimObject(); 180 void InitSingleSimObject(); 181 void InitBaseManager(int32_t slotId); 182 bool HasSimCardInner(int32_t slotId); 183 184 private: 185 std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr; 186 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager_; 187 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager_; 188 std::vector<std::shared_ptr<Telephony::SimSmsManager>> simSmsManager_; 189 std::vector<std::shared_ptr<Telephony::SimAccountManager>> simAccountManager_; 190 std::vector<std::shared_ptr<Telephony::IccDiallingNumbersManager>> iccDiallingNumbersManager_; 191 std::vector<std::shared_ptr<Telephony::StkManager>> stkManager_; 192 std::shared_ptr<MultiSimController> multiSimController_ = nullptr; 193 std::shared_ptr<MultiSimMonitor> multiSimMonitor_ = nullptr; 194 std::shared_ptr<AppExecFwk::EventRunner> controllerRunner_ = nullptr; 195 std::shared_ptr<AppExecFwk::EventRunner> monitorRunner_; 196 int32_t slotCount_ = SLOT_ID_ZERO; 197 int32_t dsdsMode_ = DSDS_MODE_V2; 198 ffrt::shared_mutex mtx_; 199 }; 200 } // namespace Telephony 201 } // namespace OHOS 202 #endif // OHOS_SIM_MANAGER_H