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 #ifndef NET_POLICY_CALLBACK_TEST_H 17 #define NET_POLICY_CALLBACK_TEST_H 18 19 #include <condition_variable> 20 #include <mutex> 21 22 #include "net_policy_callback_stub.h" 23 #include "net_policy_constants.h" 24 #include "net_quota_policy.h" 25 26 namespace OHOS { 27 namespace NetManagerStandard { 28 class NetPolicyCallbackTest : public NetPolicyCallbackStub { 29 public: 30 NetPolicyCallbackTest(); 31 ~NetPolicyCallbackTest() override; 32 int32_t NetUidPolicyChange(uint32_t uid, uint32_t policy) override; 33 int32_t NetUidRuleChange(uint32_t uid, uint32_t rule) override; 34 int32_t NetQuotaPolicyChange(const std::vector<NetQuotaPolicy> "aPolicies) override; 35 int32_t NetMeteredIfacesChange(std::vector<std::string> &ifaces) override; 36 int32_t NetBackgroundPolicyChange(bool isBackgroundPolicyAllow) override; 37 void WaitFor(int32_t timeoutSecond); 38 GetPolicy()39 uint32_t GetPolicy() const 40 { 41 return uidPolicy_; 42 } GetUid()43 uint32_t GetUid() const 44 { 45 return uid_; 46 } 47 GetRule()48 uint32_t GetRule() const 49 { 50 return rule_; 51 } 52 GetBackgroundPolicy()53 bool GetBackgroundPolicy() const 54 { 55 return isBackgroundPolicyAllow_; 56 } 57 GetQuotaPoliciesSize()58 uint32_t GetQuotaPoliciesSize() const 59 { 60 return quotaPoliciesSize_; 61 } 62 63 private: 64 void NotifyAll(); 65 uint32_t uidPolicy_ = 0; 66 uint32_t uid_ = 0; 67 uint32_t rule_ = 1 << 7; 68 bool isBackgroundPolicyAllow_ = true; 69 std::mutex callbackMutex_; 70 std::condition_variable cv_; 71 72 uint32_t quotaPoliciesSize_ = 0; 73 }; 74 } // namespace NetManagerStandard 75 } // namespace OHOS 76 #endif // NET_POLICY_CALLBACK_TEST_H 77