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 class SimManager : public ISimManager { 35 public: 36 explicit SimManager(std::shared_ptr<ITelRilManager> telRilManager); 37 virtual ~SimManager(); 38 // Init 39 bool OnInit(int32_t slotCount) override; 40 void SetNetworkSearchManager(std::shared_ptr<INetworkSearch> networkSearchManager) override; 41 // SimState 42 int32_t HasSimCard(int32_t slotId, bool &hasSimCard) override; 43 int32_t GetSimState(int32_t slotId, SimState &simState) override; 44 int32_t GetCardType(int32_t slotId, CardType &cardType) override; 45 int32_t UnlockPin(int32_t slotId, const std::string &pin, LockStatusResponse &response) override; 46 int32_t UnlockPuk( 47 int32_t slotId, const std::string &newPin, const std::string &puk, LockStatusResponse &response) override; 48 int32_t AlterPin( 49 int32_t slotId, const std::string &newPin, const std::string &oldPin, LockStatusResponse &response) override; 50 int32_t SetLockState(int32_t slotId, const LockInfo &options, LockStatusResponse &response) override; 51 int32_t GetLockState(int32_t slotId, LockType lockType, LockState &lockState) override; 52 int32_t RefreshSimState(int32_t slotId) override; 53 int32_t UnlockPin2(int32_t slotId, const std::string &pin2, LockStatusResponse &response) override; 54 int32_t UnlockPuk2( 55 int32_t slotId, const std::string &newPin2, const std::string &puk2, LockStatusResponse &response) override; 56 int32_t AlterPin2( 57 int32_t slotId, const std::string &newPin2, const std::string &oldPin2, LockStatusResponse &response) override; 58 int32_t UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo, LockStatusResponse &response) override; 59 // SimAccount 60 bool IsSimActive(int32_t slotId) override; 61 int32_t SetActiveSim(int32_t slotId, int32_t enable) override; 62 int32_t GetSimAccountInfo(int32_t slotId, IccAccountInfo &info) override; 63 int32_t SetDefaultVoiceSlotId(int32_t slotId) override; 64 int32_t SetDefaultSmsSlotId(int32_t slotId) override; 65 int32_t SetDefaultCellularDataSlotId(int32_t slotId) override; 66 int32_t SetPrimarySlotId(int32_t slotId) override; 67 int32_t SetShowNumber(int32_t slotId, const std::u16string &number) override; 68 int32_t SetShowName(int32_t slotId, const std::u16string &name) override; 69 int32_t GetDefaultVoiceSlotId() override; 70 int32_t GetDefaultSmsSlotId() override; 71 int32_t GetDefaultCellularDataSlotId() override; 72 int32_t GetPrimarySlotId(int32_t &slotId) override; 73 int32_t GetShowNumber(int32_t slotId, std::u16string &showNumber) override; 74 int32_t GetShowName(int32_t slotId, std::u16string &showName) override; 75 int32_t GetSlotId(int32_t simId) override; 76 int32_t GetSimId(int32_t slotId) override; 77 int32_t GetActiveSimAccountInfoList(std::vector<IccAccountInfo> &iccAccountInfoList) override; 78 int32_t GetOperatorConfigs(int32_t slotId, OperatorConfig &poc) override; 79 int32_t HasOperatorPrivileges(const int32_t slotId, bool &hasOperatorPrivileges) override; 80 int32_t SimAuthentication(int32_t slotId, const std::string &aid, const std::string &authData, 81 SimAuthenticationResponse &response) override; 82 int32_t GetRadioProtocolTech(int32_t slotId) override; 83 void GetRadioProtocol(int32_t slotId) override; 84 // STK 85 int32_t SendEnvelopeCmd(int32_t slotId, const std::string &cmd) override; 86 int32_t SendTerminalResponseCmd(int32_t slotId, const std::string &cmd) override; 87 int32_t SendCallSetupRequestResult(int32_t slotId, bool accept) override; 88 // SimFile 89 int32_t GetSimOperatorNumeric(int32_t slotId, std::u16string &operatorNumeric) override; 90 int32_t GetISOCountryCodeForSim(int32_t slotId, std::u16string &countryCode) override; 91 int32_t GetSimSpn(int32_t slotId, std::u16string &spn) override; 92 std::u16string GetSimEons(int32_t slotId, const std::string &plmn, int32_t lac, bool longNameRequired) override; 93 int32_t GetSimIccId(int32_t slotId, std::u16string &iccId) override; 94 int32_t GetIMSI(int32_t slotId, std::u16string &imsi) override; 95 std::u16string GetLocaleFromDefaultSim(int32_t slotId) override; 96 int32_t GetSimGid1(int32_t slotId, std::u16string &gid1) override; 97 std::u16string GetSimGid2(int32_t slotId) override; 98 int32_t GetOpName(int32_t slotId, std::u16string &opname) override; 99 int32_t GetOpKey(int32_t slotId, std::u16string &opkey) override; 100 int32_t GetOpKeyExt(int32_t slotId, std::u16string &opkeyExt) override; 101 int32_t GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber) override; 102 std::u16string GetSimTeleNumberIdentifier(const int32_t slotId) override; 103 int32_t GetVoiceMailIdentifier(int32_t slotId, std::u16string &voiceMailIdentifier) override; 104 int32_t GetVoiceMailNumber(int32_t slotId, std::u16string &voiceMailNumber) override; 105 std::u16string GetSimIst(int32_t slotId) override; 106 int ObtainSpnCondition(int32_t slotId, bool roaming, std::string operatorNum) override; 107 int32_t SetVoiceMailInfo(int32_t slotId, const std::u16string &mailName, const std::u16string &mailNumber) override; 108 // SimSms 109 int32_t AddSmsToIcc(int32_t slotId, int status, std::string &pdu, std::string &smsc) override; 110 int32_t UpdateSmsIcc( 111 int32_t slotId, int index, int status, std::string &pduData, std::string &smsc) override; 112 int32_t DelSmsIcc(int32_t slotId, int index) override; 113 std::vector<std::string> ObtainAllSmsOfIcc(int32_t slotId) override; 114 // IccDiallingNumbers 115 int32_t QueryIccDiallingNumbers( 116 int slotId, int type, std::vector<std::shared_ptr<DiallingNumbersInfo>> &result) override; 117 int32_t AddIccDiallingNumbers( 118 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override; 119 int32_t DelIccDiallingNumbers( 120 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override; 121 int32_t UpdateIccDiallingNumbers( 122 int slotId, int type, const std::shared_ptr<DiallingNumbersInfo> &diallingNumber) override; 123 // Event register 124 void RegisterCoreNotify(int32_t slotId, const HANDLE &handler, int what) override; 125 void UnRegisterCoreNotify(int32_t slotId, const HANDLE &observerCallBack, int what) override; 126 // Ims Switch 127 int32_t SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue) override; 128 int32_t QueryImsSwitch(int32_t, int32_t &imsSwitchValue) override; 129 int32_t RegisterSimAccountCallback( 130 const std::string &bundleName, const sptr<SimAccountCallback> &callback) override; 131 int32_t UnregisterSimAccountCallback(const std::string &bundleName) override; 132 133 private: 134 bool IsValidSlotId(int32_t slotId); 135 bool IsValidSlotIdForDefault(int32_t slotId); 136 void InitMultiSimObject(); 137 void InitSingleSimObject(); 138 bool HasSimCardInner(int32_t slotId); 139 140 private: 141 std::shared_ptr<Telephony::ITelRilManager> telRilManager_ = nullptr; 142 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager_; 143 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager_; 144 std::vector<std::shared_ptr<Telephony::SimSmsManager>> simSmsManager_; 145 std::vector<std::shared_ptr<Telephony::SimAccountManager>> simAccountManager_; 146 std::vector<std::shared_ptr<Telephony::IccDiallingNumbersManager>> iccDiallingNumbersManager_; 147 std::vector<std::shared_ptr<Telephony::StkManager>> stkManager_; 148 std::shared_ptr<MultiSimController> multiSimController_ = nullptr; 149 std::shared_ptr<MultiSimMonitor> multiSimMonitor_ = nullptr; 150 std::shared_ptr<AppExecFwk::EventRunner> controllerRunner_ = nullptr; 151 std::shared_ptr<AppExecFwk::EventRunner> monitorRunner_; 152 int32_t slotCount_ = SLOT_ID_ZERO; 153 }; 154 } // namespace Telephony 155 } // namespace OHOS 156 #endif // OHOS_SIM_MANAGER_H 157