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