• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 #include "net_manager_constants.h"
17 #include "netmgr_ext_log_wrapper.h"
18 #include "wearable_distributed_net_static_configuration.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
22 
WearableDistributedNetStaticConfiguration()23 WearableDistributedNetStaticConfiguration::WearableDistributedNetStaticConfiguration()
24 {
25     netCaps_.insert(NET_CAPABILITY_INTERNET);
26     netCaps_.insert(NET_CAPABILITY_NOT_VPN);
27 }
28 
29 WearableDistributedNetStaticConfiguration::~WearableDistributedNetStaticConfiguration() = default;
30 
SetNetLinkInfo(NetLinkInfo & linkInfo)31 int32_t WearableDistributedNetStaticConfiguration::SetNetLinkInfo(NetLinkInfo &linkInfo)
32 {
33     linkInfo.Initialize();
34     int32_t result = CreateNetLinkInfo(linkInfo);
35     if (result != NETMANAGER_EXT_SUCCESS) {
36         NETMGR_EXT_LOG_E("SetNetLinkInfo SetInterfaceDummy failed, result: [%{public}d]", result);
37         return result;
38     }
39     return NETMANAGER_EXT_SUCCESS;
40 }
41 
GetNetLinkInfo(NetLinkInfo & linkInfo)42 int32_t WearableDistributedNetStaticConfiguration::GetNetLinkInfo(NetLinkInfo &linkInfo)
43 {
44     int32_t result = SetNetLinkInfo(linkInfo);
45     if (result != NETMANAGER_EXT_SUCCESS) {
46         NETMGR_EXT_LOG_E("GetNetLinkInfo SetNetLinkInfo failed, result: [%{public}d]", result);
47         return result;
48     }
49     return NETMANAGER_EXT_SUCCESS;
50 }
51 
GetNetSupplierInfo(NetSupplierInfo & supplierInfo)52 void WearableDistributedNetStaticConfiguration::GetNetSupplierInfo(NetSupplierInfo &supplierInfo)
53 {
54     SetNetSupplierInfo(supplierInfo);
55 }
56 
EnableWearableDistributedNetForward(const int32_t tcpPortId,const int32_t udpPortId)57 int32_t WearableDistributedNetStaticConfiguration::EnableWearableDistributedNetForward(const int32_t tcpPortId,
58                                                                                        const int32_t udpPortId)
59 {
60     int32_t ret = wearableDistributedNetForward_.EnableWearableDistributedNetForward(tcpPortId, udpPortId);
61     if (ret != NETMANAGER_SUCCESS) {
62         NETMGR_EXT_LOG_E("Wearable Distributed Net Static Configuration Enable Forward failed, ret: [%{public}d]", ret);
63         return ret;
64     }
65     return NETMANAGER_SUCCESS;
66 }
67 
DisableWearableDistributedNetForward()68 int32_t WearableDistributedNetStaticConfiguration::DisableWearableDistributedNetForward()
69 {
70     int32_t ret = wearableDistributedNetForward_.DisableWearableDistributedNetForward();
71     if (ret != NETMANAGER_SUCCESS) {
72         NETMGR_EXT_LOG_E("WearableDistributedNetStaticConfiguration Disable Forward failed, ret: [%{public}d]", ret);
73         return ret;
74     }
75     return NETMANAGER_SUCCESS;
76 }
77 
SetNetMetered(const bool isMetered)78 void WearableDistributedNetStaticConfiguration::SetNetMetered(const bool isMetered)
79 {
80     auto it = netCaps_.find(NET_CAPABILITY_NOT_METERED);
81     if (isMetered && it != netCaps_.end()) {
82         netCaps_.erase(it);
83     }
84     if (!isMetered && it == netCaps_.end()) {
85         netCaps_.insert(NET_CAPABILITY_NOT_METERED);
86     }
87 }
88 
GetNetCaps(const bool isMetered)89 std::set<NetCap> WearableDistributedNetStaticConfiguration::GetNetCaps(const bool isMetered)
90 {
91     SetNetMetered(isMetered);
92     return netCaps_;
93 }
94 } // namespace NetManagerStandard
95 } // namespace OHOS
96