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 NET_POLICY_CALLBACK_TEST_H 17 #define NET_POLICY_CALLBACK_TEST_H 18 19 #include <mutex> 20 #include <condition_variable> 21 22 #include "net_policy_callback_stub.h" 23 #include "net_policy_cellular_policy.h" 24 #include "net_policy_constants.h" 25 26 namespace OHOS { 27 namespace NetManagerStandard { 28 class NetPolicyCallbackTest : public NetPolicyCallbackStub { 29 public: 30 NetPolicyCallbackTest(); 31 virtual ~NetPolicyCallbackTest() override; 32 int32_t NetUidPolicyChanged(uint32_t uid, NetUidPolicy policy) override; 33 int32_t NetCellularPolicyChanged(const std::vector<NetPolicyCellularPolicy> &cellularPolicies) override; 34 int32_t NetStrategySwitch(const std::string &simId, bool enable) override; 35 int32_t NetBackgroundPolicyChanged(bool isBackgroundPolicyAllow) override; 36 void WaitFor(int32_t timeoutSecond); 37 GetPolicy()38 NetUidPolicy GetPolicy() const 39 { 40 return uidPolicy_; 41 } GetUid()42 uint32_t GetUid() const 43 { 44 return uid_; 45 } 46 private: 47 void NotifyAll(); 48 NetUidPolicy uidPolicy_ = NetUidPolicy::NET_POLICY_NONE; 49 uint32_t uid_ = 0; 50 bool isBackgroundPolicyAllow_ = true; 51 std::mutex callbackMutex_; 52 std::condition_variable cv_; 53 }; 54 } // namespace NetManagerStandard 55 } // namespace OHOS 56 #endif // NET_POLICY_CALLBACK_TEST_H 57