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 void Init(); 41 void UnRegisterHandler(); 42 NetWorkType GetNetWorkType(); 43 bool IsImsNetDomain() const; 44 void GetRadioState(); 45 int32_t GetVoiceServiceState() const; 46 std::optional<int32_t> NetworkRegister( 47 const std::function<void(bool isImsNetDomain, int32_t serviceState)> &callback); 48 std::optional<int32_t> NetworkRegister( 49 const std::function<void(bool isImsNetDomain, int32_t serviceState)> &&callback); 50 void NetworkUnregister(int32_t id); 51 52 protected: 53 void HandlerRadioState(const AppExecFwk::InnerEvent::Pointer &event); 54 void RegisterHandler(); 55 56 private: 57 int32_t GetId(); 58 void GetImsRegState(); 59 bool IsCtSimCard(); 60 61 private: 62 int32_t slotId_; 63 enum NetWorkType netWorkType_ = NetWorkType::NET_TYPE_UNKNOWN; 64 bool isImsNetDomain_ = false; 65 int32_t voiceServiceState_ = static_cast<int32_t>(RegServiceState::REG_STATE_UNKNOWN); 66 std::map<int32_t, const std::function<void(bool isImsNetDomain, int32_t serviceState)>> callbackMap_; 67 int32_t id_ = 0; 68 sptr<ImsRegInfoCallback> callback_ = nullptr; 69 }; 70 } // namespace Telephony 71 } // namespace OHOS 72 #endif // SMS_NETWORK_POLICY_MANAGER_H 73