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_MULTI_SIM_CONTROLLER_H 17 #define OHOS_MULTI_SIM_CONTROLLER_H 18 19 #include <list> 20 21 #include "i_network_search.h" 22 #include "if_system_ability_manager.h" 23 #include "radio_protocol_controller.h" 24 #include "rdb_sim_helper.h" 25 #include "sim_constant.h" 26 #include "sim_data.h" 27 #include "sim_file_manager.h" 28 #include "sim_rdb_helper.h" 29 #include "sim_state_manager.h" 30 #include "telephony_errors.h" 31 #include "want.h" 32 33 namespace OHOS { 34 namespace Telephony { 35 class MultiSimController { 36 public: 37 MultiSimController(std::shared_ptr<Telephony::ITelRilManager> telRilManager, 38 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager, 39 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager, 40 const std::shared_ptr<AppExecFwk::EventRunner> &runner); 41 virtual ~MultiSimController(); 42 43 void Init(); 44 bool InitData(int32_t slotId); 45 void SetNetworkSearchManager(std::shared_ptr<INetworkSearch> networkSearchManager); 46 bool RefreshActiveIccAccountInfoList(); 47 int32_t GetDefaultVoiceSlotId(); 48 int32_t SetDefaultVoiceSlotId(int32_t slotId); 49 int32_t GetDefaultSmsSlotId(); 50 int32_t SetDefaultSmsSlotId(int32_t slotId); 51 int32_t GetSimAccountInfo(int32_t slotId, IccAccountInfo &info); 52 int32_t GetDefaultCellularDataSlotId(); 53 int32_t SetDefaultCellularDataSlotId(int32_t slotId); 54 int32_t GetPrimarySlotId(); 55 int32_t SetPrimarySlotId(int32_t slotId); 56 int32_t GetShowNumber(int32_t slotId, std::u16string &showNumber); 57 int32_t SetShowNumber(int32_t slotId, std::u16string Number, bool force = false); 58 int32_t GetShowName(int32_t slotId, std::u16string &showName); 59 int32_t SetShowName(int32_t slotId, std::u16string name, bool force = false); 60 bool IsSimActive(int32_t slotId); 61 bool IsSimActivatable(int32_t slotId); 62 int32_t SetActiveSim(int32_t slotId, int32_t enable, bool force = false); 63 bool SetActiveSimToRil(int32_t slotId, int32_t type, int32_t enable); 64 bool ForgetAllData(); 65 bool ForgetAllData(int32_t slotId); 66 int32_t GetSlotId(int32_t simId); 67 int32_t SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue); 68 int32_t QueryImsSwitch(int32_t slotId, int32_t &imsSwitchValue); 69 bool GetListFromDataBase(); 70 int32_t GetActiveSimAccountInfoList(std::vector<IccAccountInfo> &iccAccountInfoList); 71 int32_t GetRadioProtocolTech(int32_t slotId); 72 void GetRadioProtocol(int32_t slotId); 73 74 private: 75 bool IsValidData(int32_t slotId); 76 int32_t GetFirstActivedSlotId(); 77 bool InitShowName(int slotId); 78 bool InitShowNumber(int slotId); 79 bool InitActive(int slotId); 80 bool InitIccId(int slotId); 81 int32_t UpdateDataByIccId(int slotId, const std::string &newIccId); 82 int32_t InsertData(int slotId, const std::string &newIccId); 83 void SortCache(); 84 std::u16string GetIccId(int32_t slotId); 85 bool SetIccId(int32_t slotId, std::u16string iccId); 86 int32_t GetDefaultCellularDataSlotIdUnit(); 87 bool AnnounceDefaultMainSlotIdChanged(int32_t slotId); 88 bool AnnounceDefaultVoiceSlotIdChanged(int32_t slotId); 89 bool AnnounceDefaultSmsSlotIdChanged(int32_t slotId); 90 bool AnnounceDefaultCellularDataSlotIdChanged(int32_t slotId); 91 bool PublishSimFileEvent(const AAFwk::Want &want, int eventCode, const std::string &eventData); 92 93 private: 94 int32_t maxCount_ = 0; 95 bool ready_ = false; 96 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager_; 97 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager_; 98 std::unique_ptr<SimRdbHelper> simDbHelper_ = nullptr; 99 std::shared_ptr<INetworkSearch> networkSearchManager_ = nullptr; 100 IccAccountInfo iccAccountInfo_; 101 std::vector<IccAccountInfo> iccAccountInfoList_; 102 std::vector<SimRdbInfo> localCacheInfo_; 103 std::mutex mutex_; 104 std::shared_ptr<RadioProtocolController> radioProtocolController_ = nullptr; 105 }; 106 } // namespace Telephony 107 } // namespace OHOS 108 #endif // OHOS_MULTI_SIM_CONTROLLER_H 109