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 "if_system_ability_manager.h" 22 #include "radio_protocol_controller.h" 23 #include "sim_constant.h" 24 #include "sim_file_manager.h" 25 #include "sim_rdb_helper.h" 26 #include "sim_state_manager.h" 27 #include "telephony_errors.h" 28 #include "want.h" 29 30 namespace OHOS { 31 namespace Telephony { 32 class MultiSimController { 33 public: 34 MultiSimController(std::shared_ptr<Telephony::ITelRilManager> telRilManager, 35 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager, 36 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager); 37 virtual ~MultiSimController(); 38 39 void Init(); 40 bool InitData(int32_t slotId); 41 int32_t GetDefaultVoiceSlotId(); 42 int32_t SetDefaultVoiceSlotId(int32_t slotId); 43 int32_t GetDefaultSmsSlotId(); 44 int32_t SetDefaultSmsSlotId(int32_t slotId); 45 int32_t GetSimAccountInfo(int32_t slotId, bool denied, IccAccountInfo &info); 46 int32_t GetDefaultCellularDataSlotId(); 47 int32_t SetDefaultCellularDataSlotId(int32_t slotId); 48 int32_t GetPrimarySlotId(); 49 int32_t SetPrimarySlotId(int32_t slotId); 50 int32_t GetShowNumber(int32_t slotId, std::u16string &showNumber); 51 int32_t SetShowNumber(int32_t slotId, std::u16string Number, bool force = false); 52 int32_t SetShowNumberToDB(int32_t slotId, std::u16string Number); 53 int32_t GetShowName(int32_t slotId, std::u16string &showName); 54 int32_t SetShowName(int32_t slotId, std::u16string name, bool force = false); 55 int32_t GetSimTelephoneNumber(int32_t slotId, std::u16string &telephoneNumber); 56 bool IsSimActive(int32_t slotId); 57 int32_t SetActiveSim(int32_t slotId, int32_t enable, bool force = false); 58 bool SetActiveSimToRil(int32_t slotId, int32_t type, int32_t enable); 59 bool ForgetAllData(); 60 bool ForgetAllData(int32_t slotId); 61 int32_t GetSlotId(int32_t simId); 62 int32_t SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue); 63 int32_t QueryImsSwitch(int32_t slotId, int32_t &imsSwitchValue); 64 bool GetListFromDataBase(); 65 int32_t GetActiveSimAccountInfoList(bool denied, std::vector<IccAccountInfo> &iccAccountInfoList); 66 int32_t GetRadioProtocolTech(int32_t slotId); 67 void GetRadioProtocol(int32_t slotId); 68 bool InitShowName(int slotId); 69 void ReCheckPrimary(); 70 71 public: 72 int32_t unInitModemSlotId_ = INVALID_VALUE; 73 74 private: 75 bool IsValidData(int32_t slotId); 76 int32_t GetFirstActivedSlotId(); 77 bool InitShowNumber(int slotId); 78 bool InitActive(int slotId); 79 bool InitIccId(int slotId); 80 int32_t UpdateDataByIccId(int slotId, const std::string &newIccId); 81 int32_t InsertData(int slotId, const std::string &newIccId); 82 void SortCache(); 83 void SavePrimarySlotIdInfo(int32_t slotId); 84 void SaveDefaultCellularDataSlotIdInfo(int32_t slotId); 85 bool AnnouncePrimarySimIdChanged(int32_t simId); 86 bool AnnounceDefaultVoiceSimIdChanged(int32_t simId); 87 bool AnnounceDefaultSmsSimIdChanged(int32_t simId); 88 bool AnnounceDefaultCellularDataSimIdChanged(int32_t simId); 89 bool PublishSimFileEvent(const AAFwk::Want &want, int eventCode, const std::string &eventData); 90 bool RefreshActiveIccAccountInfoList(); 91 std::string EncryptIccId(const std::string iccid); 92 void CheckIfNeedSwitchMainSlotId(); 93 bool IsValidSlotId(int32_t slotId); 94 bool InitPrimary(); 95 bool IsAllCardsReady(); 96 bool IsAllCardsLoaded(); 97 void SendMainCardBroadCast(int32_t slotId); 98 void SendDefaultCellularDataBroadCast(int32_t slotId); 99 void InitMainCardSlotId(); 100 void PublishSetPrimaryEvent(bool setDone); 101 int32_t GetTargetDefaultSimId(int32_t slotId, int &simId); 102 size_t GetLocalCacheSize(); 103 int32_t GetTargetSimId(int32_t slotId, int &simId); 104 int32_t GetTargetIccId(int32_t slotId, std::string &iccId); 105 bool IsAllModemInitDone(); 106 107 private: 108 int32_t maxCount_ = 0; 109 int32_t primarySimId_ = 0; 110 int32_t defaultSmsSimId_ = 0; 111 int32_t defaultCellularSimId_ = 0; 112 int32_t defaultVoiceSimId_ = 0; 113 int32_t lastPrimarySlotId_ = 0; 114 int32_t lastCellularDataSlotId_ = 0; 115 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager_; 116 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager_; 117 std::unique_ptr<SimRdbHelper> simDbHelper_ = nullptr; 118 IccAccountInfo iccAccountInfo_; 119 std::vector<IccAccountInfo> iccAccountInfoList_; 120 std::vector<SimRdbInfo> localCacheInfo_; 121 std::mutex mutex_; 122 std::shared_ptr<RadioProtocolController> radioProtocolController_ = nullptr; 123 }; 124 } // namespace Telephony 125 } // namespace OHOS 126 #endif // OHOS_MULTI_SIM_CONTROLLER_H 127