• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 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_policy_callback_test.h"
17 
18 #include <iostream>
19 
20 #include "net_mgr_log_wrapper.h"
21 #include "net_policy_constants.h"
22 
23 namespace OHOS {
24 namespace NetManagerStandard {
25 NetPolicyCallbackTest::NetPolicyCallbackTest() = default;
26 
27 NetPolicyCallbackTest::~NetPolicyCallbackTest() = default;
28 
NotifyAll()29 void NetPolicyCallbackTest::NotifyAll()
30 {
31     std::unique_lock<std::mutex> callbackLock(callbackMutex_);
32     cv_.notify_all();
33 }
34 
WaitFor(int32_t timeoutSecond)35 void NetPolicyCallbackTest::WaitFor(int32_t timeoutSecond)
36 {
37     std::unique_lock<std::mutex> callbackLock(callbackMutex_);
38     cv_.wait_for(callbackLock, std::chrono::seconds(timeoutSecond));
39 }
40 
NetUidPolicyChange(uint32_t uid,uint32_t policy)41 int32_t NetPolicyCallbackTest::NetUidPolicyChange(uint32_t uid, uint32_t policy)
42 {
43     std::cout << "unittest NetUidPolicyChange, uid:" << uid << "policy:" << policy << std::endl;
44     uid_ = uid;
45     uidPolicy_ = policy;
46     NotifyAll();
47 
48     return 0;
49 }
50 
NetUidRuleChange(uint32_t uid,uint32_t rule)51 int32_t NetPolicyCallbackTest::NetUidRuleChange(uint32_t uid, uint32_t rule)
52 {
53     std::cout << "unittest NetUidRuleChange, uid:" << uid << "rule:" << rule << std::endl;
54     uid_ = uid;
55     rule_ = rule;
56     NotifyAll();
57 
58     return 0;
59 }
60 
NetBackgroundPolicyChange(bool isBackgroundPolicyAllow)61 int32_t NetPolicyCallbackTest::NetBackgroundPolicyChange(bool isBackgroundPolicyAllow)
62 {
63     std::cout << "unittest NetBackgroundPolicyChange, isBackgroundPolicyAllow:" << isBackgroundPolicyAllow << std::endl;
64     isBackgroundPolicyAllow_ = isBackgroundPolicyAllow;
65     NotifyAll();
66 
67     return 0;
68 }
69 
NetQuotaPolicyChange(const std::vector<NetQuotaPolicy> & quotaPolicies)70 int32_t NetPolicyCallbackTest::NetQuotaPolicyChange(const std::vector<NetQuotaPolicy> &quotaPolicies)
71 {
72     std::cout << "unittest NetQuotaPolicyChange, quotaPolicies.size:" << quotaPolicies.size() << std::endl;
73     quotaPoliciesSize_ = quotaPolicies.size();
74     NotifyAll();
75     return 0;
76 }
77 
NetMeteredIfacesChange(std::vector<std::string> & ifaces)78 int32_t NetPolicyCallbackTest::NetMeteredIfacesChange(std::vector<std::string> &ifaces)
79 {
80     NotifyAll();
81     return 0;
82 }
83 } // namespace NetManagerStandard
84 } // namespace OHOS
85