• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "net_policy_callback_test.h"
17 #include "net_policy_constants.h"
18 #include "net_mgr_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
NetPolicyCallbackTest()22 NetPolicyCallbackTest::NetPolicyCallbackTest() {}
23 
~NetPolicyCallbackTest()24 NetPolicyCallbackTest::~NetPolicyCallbackTest() {}
25 
NotifyAll()26 void NetPolicyCallbackTest::NotifyAll()
27 {
28     std::unique_lock<std::mutex> callbackLock(callbackMutex_);
29     cv_.notify_all();
30 }
31 
WaitFor(int32_t timeoutSecond)32 void NetPolicyCallbackTest::WaitFor(int32_t timeoutSecond)
33 {
34     std::unique_lock<std::mutex> callbackLock(callbackMutex_);
35     cv_.wait_for(callbackLock, std::chrono::seconds(timeoutSecond));
36 }
37 
NetUidPolicyChanged(uint32_t uid,NetUidPolicy policy)38 int32_t NetPolicyCallbackTest::NetUidPolicyChanged(uint32_t uid, NetUidPolicy policy)
39 {
40     NETMGR_LOG_D("unittest NetUidPolicyChanged, uid:[%{public}d], policy:[%{public}d]",
41         uid, static_cast<uint32_t>(policy));
42 
43     uid_ = uid;
44     uidPolicy_ = policy;
45     NotifyAll();
46 
47     return 0;
48 }
49 
NetBackgroundPolicyChanged(bool isBackgroundPolicyAllow)50 int32_t NetPolicyCallbackTest::NetBackgroundPolicyChanged(bool isBackgroundPolicyAllow)
51 {
52     NETMGR_LOG_D("unittest NetBackgroundPolicyChanged, isBackgroundPolicyAllow:[%{public}d]",
53         isBackgroundPolicyAllow);
54 
55     isBackgroundPolicyAllow_ = isBackgroundPolicyAllow;
56     NotifyAll();
57 
58     return 0;
59 }
60 
NetCellularPolicyChanged(const std::vector<NetPolicyCellularPolicy> & cellularPolicies)61 int32_t NetPolicyCallbackTest::NetCellularPolicyChanged(const std::vector<NetPolicyCellularPolicy> &cellularPolicies)
62 {
63     NETMGR_LOG_D("unittest NetCellularPolicyChanged, cellularPolicies.size:[%{public}d]",
64         cellularPolicies.size());
65 
66     return 0;
67 }
68 
NetStrategySwitch(const std::string & simId,bool enable)69 int32_t NetPolicyCallbackTest::NetStrategySwitch(const std::string &simId, bool enable)
70 {
71     NETMGR_LOG_D("unittest NetStrategySwitch, simId:[%{public}s], enable:[%{public}d]",
72         simId.c_str(), static_cast<uint32_t>(enable));
73 
74     return 0;
75 }
76 } // namespace NetManagerStandard
77 } // namespace OHOS
78