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 SMS_NETWORK_POLICY_MANAGER_H 17 #define SMS_NETWORK_POLICY_MANAGER_H 18 19 #include <functional> 20 #include <map> 21 #include <optional> 22 23 #include "event_handler.h" 24 #include "event_runner.h" 25 #include "ims_reg_state_callback_stub.h" 26 #include "network_state.h" 27 #include "sms_common.h" 28 29 namespace OHOS { 30 namespace Telephony { 31 enum NotificationType { 32 NOTIFICATION_TYPE_IMS = 600, 33 }; 34 35 class SmsNetworkPolicyManager : public AppExecFwk::EventHandler { 36 public: 37 SmsNetworkPolicyManager(const std::shared_ptr<AppExecFwk::EventRunner> &runner, int32_t slotId); 38 virtual ~SmsNetworkPolicyManager() = default; 39 virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 40 int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported); 41 int32_t GetImsShortMessageFormat(std::u16string &format); 42 void Init(); 43 void UnRegisterHandler(); 44 NetWorkType GetNetWorkType(); 45 bool IsImsNetDomain() const; 46 void GetRadioState(); 47 int32_t GetVoiceServiceState() const; 48 std::optional<int32_t> NetworkRegister( 49 const std::function<void(bool isImsNetDomain, int32_t serviceState)> &callback); 50 std::optional<int32_t> NetworkRegister( 51 const std::function<void(bool isImsNetDomain, int32_t serviceState)> &&callback); 52 void NetworkUnregister(int32_t id); 53 54 protected: 55 void HandlerRadioState(const AppExecFwk::InnerEvent::Pointer &event); 56 void RegisterHandler(); 57 58 private: 59 int32_t GetId(); 60 void GetImsRegState(); 61 bool IsCtSimCard(); 62 63 private: 64 int32_t slotId_; 65 enum NetWorkType netWorkType_ = NetWorkType::NET_TYPE_UNKNOWN; 66 bool isImsNetDomain_ = false; 67 int32_t voiceServiceState_ = static_cast<int32_t>(RegServiceState::REG_STATE_UNKNOWN); 68 std::map<int32_t, const std::function<void(bool isImsNetDomain, int32_t serviceState)>> callbackMap_; 69 int32_t id_ = 0; 70 sptr<ImsRegInfoCallback> callback_ = nullptr; 71 }; 72 } // namespace Telephony 73 } // namespace OHOS 74 #endif // SMS_NETWORK_POLICY_MANAGER_H 75