1 /* 2 * Copyright (C) 2021 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_FILE_MANAGER_H 17 #define OHOS_SIM_FILE_MANAGER_H 18 19 #include "common_event_subscriber.h" 20 #include "event_handler.h" 21 #include "event_runner.h" 22 #include "tel_ril_modem_parcel.h" 23 #include "i_tel_ril_manager.h" 24 #include "isim_file.h" 25 #include "isim_file_controller.h" 26 #include "ruim_file.h" 27 #include "ruim_file_controller.h" 28 #include "sim_file.h" 29 #include "sim_file_controller.h" 30 #include "system_ability_status_change_stub.h" 31 #include "isim_file.h" 32 #include "isim_file_controller.h" 33 #include "csim_file_controller.h" 34 #include "telephony_log_wrapper.h" 35 #include "usim_file_controller.h" 36 37 namespace OHOS { 38 namespace Telephony { 39 class SimFileManager : public TelEventHandler, public EventFwk::CommonEventSubscriber { 40 public: 41 using HANDLE = std::shared_ptr<AppExecFwk::EventHandler>; 42 SimFileManager( 43 const EventFwk::CommonEventSubscribeInfo &sp, std::weak_ptr<Telephony::ITelRilManager> telRilManager, 44 std::weak_ptr<Telephony::SimStateManager> state); 45 virtual ~SimFileManager(); 46 void Init(int slotId); 47 void ClearData(); 48 std::u16string GetSimOperatorNumeric(); 49 std::u16string GetISOCountryCodeForSim(); 50 std::u16string GetSimSpn(); 51 std::u16string GetSimEons(const std::string &plmn, int32_t lac, bool longNameRequired); 52 std::u16string GetSimIccId(); 53 std::u16string GetSimDecIccId(); 54 std::u16string GetIMSI(); 55 std::u16string GetMCC(); 56 std::u16string GetMNC(); 57 std::u16string GetLocaleFromDefaultSim(); 58 std::u16string GetSimGid1(); 59 std::u16string GetSimGid2(); 60 std::u16string GetSimTelephoneNumber(); 61 std::u16string GetSimTeleNumberIdentifier(); 62 std::u16string GetSimIst(); 63 std::u16string GetVoiceMailIdentifier(); 64 std::u16string GetVoiceMailNumber(); 65 int32_t GetVoiceMailCount(); 66 bool SetVoiceMailCount(int32_t voiceMailCount); 67 bool SetVoiceCallForwarding(bool enable, const std::string &number); 68 std::u16string GetOpName(); 69 std::u16string GetOpKey(); 70 std::u16string GetOpKeyExt(); 71 void SetOpName(const std::string &opName); 72 void SetOpKey(const std::string &opKey); 73 void SetOpKeyExt(const std::string &opKeyExt); 74 int ObtainSpnCondition(bool roaming, const std::string &operatorNum); 75 void RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what); 76 void UnRegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &observerCallBack, int what); 77 void SetImsi(std::string imsi); 78 std::shared_ptr<IccFile> GetIccFile(); 79 std::shared_ptr<IccFileController> GetIccFileController(); 80 std::shared_ptr<IccDiallingNumbersHandler> ObtainDiallingNumberHandler(); 81 bool SetVoiceMailInfo(const std::u16string &mailName, const std::u16string &mailNumber); 82 bool SetSimTelephoneNumber(const std::u16string &alphaTag, const std::u16string &phoneNumber); 83 bool HasSimCard(); 84 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 85 void OnReceiveEvent(const EventFwk::CommonEventData &data) override; 86 void DeleteOperatorCache(); 87 void UpdateOpkeyConfig(); 88 bool IsCTSimCard(); 89 static std::shared_ptr<SimFileManager> CreateInstance( 90 std::weak_ptr<Telephony::ITelRilManager> ril, std::weak_ptr<SimStateManager> simState); 91 enum class HandleRunningState { STATE_NOT_START, STATE_RUNNING }; 92 enum class IccType { ICC_TYPE_CDMA, ICC_TYPE_GSM, ICC_TYPE_IMS, ICC_TYPE_USIM }; 93 94 protected: 95 std::weak_ptr<Telephony::ITelRilManager> telRilManager_; 96 std::shared_ptr<IccFileController> fileController_ = nullptr; 97 std::shared_ptr<IccFile> simFile_ = nullptr; 98 std::shared_ptr<IccDiallingNumbersHandler> diallingNumberHandler_ = nullptr; 99 HandleRunningState stateRecord_ = HandleRunningState::STATE_NOT_START; 100 HandleRunningState stateHandler_ = HandleRunningState::STATE_NOT_START; 101 std::weak_ptr<Telephony::SimStateManager> simStateManager_; 102 int slotId_ = 0; 103 IccType iccType_ = IccType::ICC_TYPE_USIM; 104 std::map<IccType, std::shared_ptr<IccFile>> iccFileCache_; 105 std::map<IccType, std::shared_ptr<IccFileController>> iccFileControllerCache_; 106 107 private: 108 bool InitDiallingNumberHandler(); 109 IccType GetIccTypeByCardType(CardType type); 110 IccType GetIccTypeByTech(const std::shared_ptr<VoiceRadioTechnology> &tech); 111 bool InitSimFile(IccType type); 112 bool InitIccFileController(IccType type); 113 void ChangeSimFileByCardType(IccType type); 114 bool IsValidType(IccType type); 115 bool IsCTCardType(CardType type); 116 bool IsCTIccId(std::string iccId); 117 std::string opName_; 118 std::string opKey_; 119 std::string opKeyExt_; 120 121 const std::string VM_NUMBER_KEY = "persist.telephony.voicemail.gsm"; 122 const std::string VM_NUMBER_CDMA_KEY = "persist.telephony.voicemail.cdma"; 123 void SetVoiceMailParamGsm(const std::u16string mailNumber, bool isSavedIccRecords); 124 void SetVoiceMailParamCdma(const std::u16string mailNumber); 125 std::string GetVoiceMailNumberKey(); 126 std::string GetVoiceMailNumberCdmaKey(); 127 std::string GetVoiceMailNumberFromParam(); 128 void SetVoiceMailSimImsiParam(std::string imsi); 129 void StoreVoiceMailNumber(const std::u16string mailNumber, bool isSavedIccRecoeds); 130 std::string GetVoiceMailSimImsiFromParam(); 131 void HandleSimRecordsLoaded(); 132 void HandleSimIccidLoaded(std::string iccid); 133 bool IsPhoneTypeGsm(int32_t slotId); 134 std::string EncryptImsi(const std::string imsi); 135 bool IsEncryptImsiEmpty(const std::string encryptImsi); 136 sptr<ISystemAbilityStatusChange> statusChangeListener_ = nullptr; 137 }; 138 } // namespace Telephony 139 } // namespace OHOS 140 #endif // OHOS_SIM_FILE_MANAGER_H 141