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 GetCardType(int32_t slotId, CardType &cardType) override; 51 int32_t SetModemInit(int32_t slotId, bool state) override; 52 int32_t UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response) override; 53 int32_t UnlockPuk( 54 int32_t slotId, const std::string &newPin, const std::string &puk, LockStatusResponse &response) override; 55 int32_t AlterPin( 56 int32_t slotId, const std::string &newPin, const std::string &oldPin, LockStatusResponse &response) override; 57 int32_t SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response) override; 58 int32_t GetLockState(int32_t slotId, LockType lockType, LockState &lockState) override; 59 int32_t RefreshSimState(int32_t slotId) override; 60 int32_t UnlockPin2(int32_t slotId, const std::string &pin2, LockStatusResponse &response) override; 61 int32_t UnlockPuk2( 62 int32_t slotId, const std::string &newPin2, const std::string &puk2, LockStatusResponse &response) override; 63 int32_t AlterPin2( 64 int32_t slotId, const std::string &newPin2, const std::string &oldPin2, LockStatusResponse &response) override; 65 int32_t UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response) override; 66 // SimAccount 67 bool IsSimActive(int32_t slotId) override; 68 int32_t SetActiveSim(int32_t slotId, int32_t enable) override; 69 int32_t GetSimAccountInfo(int32_t slotId, bool denied, IccAccountInfo &info) override; 70 int32_t SetDefaultVoiceSlotId(int32_t slotId) override; 71 int32_t SetDefaultSmsSlotId(int32_t slotId) override; 72 int32_t SetDefaultCellularDataSlotId(int32_t slotId) override; 73 int32_t SetPrimarySlotId(int32_t slotId) override; 74 int32_t SetShowNumber(int32_t slotId, const std::u16string &number) override; 75 int32_t SetShowName(int32_t slotId, const std::u16string &name) override; 76 int32_t GetDefaultVoiceSlotId() override; 77 int32_t GetDefaultVoiceSimId(int32_t &simId) override; 78 int32_t GetDefaultSmsSlotId() override; 79 int32_t GetDefaultSmsSimId(int32_t &simId) override; 80 int32_t GetDefaultCellularDataSlotId() override; 81 int32_t GetDefaultCellularDataSimId(int32_t &simId) override; 82 int32_t GetPrimarySlotId(int32_t &slotId) override; 83 int32_t GetShowNumber(int32_t slotId, std::u16string &showNumber) override; 84 int32_t GetShowName(int32_t slotId, std::u16string &showName) override; 85 int32_t GetSlotId(int32_t simId) override; 86 int32_t GetSimId(int32_t slotId) override; 87 int32_t GetActiveSimAccountInfoList(bool denied, std::vector<IccAccountInfo> &iccAccountInfoList) override; 88 int32_t GetOperatorConfigs(int32_t slotId, OperatorConfig &poc) override; 89 int32_t UpdateOperatorConfigs(int32_t slotId) override; 90 int32_t HasOperatorPrivileges(const int32_t slotId, bool &hasOperatorPrivileges) override; 91 int32_t SimAuthentication( 92 int32_t slotId, AuthType authType, const std::string &authData, SimAuthenticationResponse &response) override; 93 int32_t GetRadioProtocolTech(int32_t slotId) override; 94 void GetRadioProtocol(int32_t slotId) override; 95 int32_t GetDsdsMode(int32_t &dsdsMode) override; 96 int32_t SetDsdsMode(int32_t dsdsMode) override; 97 int32_t SendSimMatchedOperatorInfo( 98 int32_t slotId, int32_t state, const std::string &operName, const std::string &operKey) override; 99 // STK 100 int32_t SendEnvelopeCmd(int32_t slotId, const std::string &cmd) override; 101 int32_t SendTerminalResponseCmd(int32_t slotId, const std::string &cmd) override; 102 int32_t SendCallSetupRequestResult(int32_t slotId, bool accept) override; 103 // SimFile 104 int32_t GetSimOperatorNumeric(int32_t slotId, std::u16string &operatorNumeric) override; 105 int32_t GetISOCountryCodeForSim(int32_t slotId, std::u16string &countryCode) override; 106 int32_t GetSimSpn(int32_t slotId, std::u16string &spn) override; 107 std::u16string GetSimEons(int32_t slotId, const std::string &plmn, int32_t lac, bool longNameRequired) override; 108 int32_t GetSimIccId(int32_t slotId, std::u16string &iccId) override; 109 int32_t GetIMSI(int32_t slotId, std::u16string &imsi) override; 110 std::u16string GetLocaleFromDefaultSim(int32_t slotId) override; 111 int32_t GetSimGid1(int32_t slotId, std::u16string &gid1) override; 112 std::u16string GetSimGid2(int32_t slotId) override; 113 int32_t GetOpName(int32_t slotId, std::u16string &opname) override; 114 int32_t GetOpKey(int32_t slotId, std::u16string &opkey) override; 115 int32_t GetOpKeyExt(int32_t slotId, std::u16string &opkeyExt) override; 116 int32_t GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber) override; 117 int32_t GetVoiceMailNumber(int32_t slotId, std::u16string &voiceMailNumber) override; 118 int32_t GetVoiceMailCount(int32_t slotId, int32_t &voiceMailCount) override; 119 int32_t SetVoiceMailCount(int32_t slotId, int32_t voiceMailCount) override; 120 int32_t SetVoiceCallForwarding(int32_t slotId, bool enable, const std::string &number) override; 121 int32_t GetVoiceMailIdentifier(int32_t slotId, std::u16string &voiceMailIdentifier) override; 122 std::u16string GetSimTeleNumberIdentifier(const int32_t slotId) override; 123 std::u16string GetSimIst(int32_t slotId) override; 124 int ObtainSpnCondition(int32_t slotId, bool roaming, std::string operatorNum) override; 125 int32_t SetVoiceMailInfo(int32_t slotId, const std::u16string &mailName, const std::u16string &mailNumber) override; 126 int32_t IsCTSimCard(int32_t slotId, bool &isCTSimCard) override; 127 // SimSms 128 int32_t AddSmsToIcc(int32_t slotId, int status, std::string &pdu, std::string &smsc) override; 129 int32_t UpdateSmsIcc( 130 int32_t slotId, int index, int status, std::string &pduData, std::string &smsc) override; 131 int32_t DelSmsIcc(int32_t slotId, int index) override; 132 std::vector<std::string> ObtainAllSmsOfIcc(int32_t slotId) override; 133 // IccDiallingNumbers 134 int32_t AddIccDiallingNumbers( 135 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override; 136 int32_t DelIccDiallingNumbers( 137 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override; 138 int32_t UpdateIccDiallingNumbers( 139 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override; 140 int32_t QueryIccDiallingNumbers( 141 int slotId, int type, std::vector<std::shared_ptr<DiallingNumbersInfo>> &result) override; 142 // Event register 143 void RegisterCoreNotify(int32_t slotId, const HANDLE &handler, int what) override; 144 void UnRegisterCoreNotify(int32_t slotId, const HANDLE &observerCallBack, int what) override; 145 // Ims Switch 146 int32_t SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue) override; 147 int32_t QueryImsSwitch(int32_t, int32_t &imsSwitchValue) override; 148 int32_t RegisterSimAccountCallback( 149 const int32_t tokenId, const sptr<SimAccountCallback> &callback) override; 150 int32_t UnregisterSimAccountCallback(const int32_t tokenId) override; 151 152 bool IsSetActiveSimInProgress(int32_t slotId) override; 153 bool IsSetPrimarySlotIdInProgress() override; 154 int32_t GetSimIO(int32_t slotId, int32_t command, int32_t fileId, 155 const std::string &data, const std::string &path, SimAuthenticationResponse &response) override; 156 157 private: 158 bool IsValidSlotId(int32_t slotId); 159 template<class N> 160 bool IsValidSlotId(int32_t slotId, std::vector<N> vec); 161 bool IsValidAuthType(AuthType authType); 162 bool IsValidSlotIdForDefault(int32_t slotId); 163 void InitMultiSimObject(); 164 void InitSingleSimObject(); 165 void InitBaseManager(int32_t slotId); 166 bool HasSimCardInner(int32_t slotId); 167 168 private: 169 std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr; 170 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager_; 171 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager_; 172 std::vector<std::shared_ptr<Telephony::SimSmsManager>> simSmsManager_; 173 std::vector<std::shared_ptr<Telephony::SimAccountManager>> simAccountManager_; 174 std::vector<std::shared_ptr<Telephony::IccDiallingNumbersManager>> iccDiallingNumbersManager_; 175 std::vector<std::shared_ptr<Telephony::StkManager>> stkManager_; 176 std::shared_ptr<MultiSimController> multiSimController_ = nullptr; 177 std::shared_ptr<MultiSimMonitor> multiSimMonitor_ = nullptr; 178 std::shared_ptr<AppExecFwk::EventRunner> controllerRunner_ = nullptr; 179 std::shared_ptr<AppExecFwk::EventRunner> monitorRunner_; 180 int32_t slotCount_ = SLOT_ID_ZERO; 181 int32_t dsdsMode_ = DSDS_MODE_V2; 182 }; 183 } // namespace Telephony 184 } // namespace OHOS 185 #endif // OHOS_SIM_MANAGER_H 186