1b1b8bc3fSopenharmony_ci/* 2b1b8bc3fSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 3b1b8bc3fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4b1b8bc3fSopenharmony_ci * you may not use this file except in compliance with the License. 5b1b8bc3fSopenharmony_ci * You may obtain a copy of the License at 6b1b8bc3fSopenharmony_ci * 7b1b8bc3fSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8b1b8bc3fSopenharmony_ci * 9b1b8bc3fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10b1b8bc3fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11b1b8bc3fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12b1b8bc3fSopenharmony_ci * See the License for the specific language governing permissions and 13b1b8bc3fSopenharmony_ci * limitations under the License. 14b1b8bc3fSopenharmony_ci */ 15b1b8bc3fSopenharmony_ci 16b1b8bc3fSopenharmony_ci#ifndef NET_POLICY_CALLBACK_H 17b1b8bc3fSopenharmony_ci#define NET_POLICY_CALLBACK_H 18b1b8bc3fSopenharmony_ci 19b1b8bc3fSopenharmony_ci#include <mutex> 20b1b8bc3fSopenharmony_ci#include <string> 21b1b8bc3fSopenharmony_ci#include <vector> 22b1b8bc3fSopenharmony_ci 23b1b8bc3fSopenharmony_ci#include "singleton.h" 24b1b8bc3fSopenharmony_ci 25b1b8bc3fSopenharmony_ci#include "ffrt.h" 26b1b8bc3fSopenharmony_ci#include "event_handler.h" 27b1b8bc3fSopenharmony_ci#include "i_net_policy_callback.h" 28b1b8bc3fSopenharmony_ci#include "net_quota_policy.h" 29b1b8bc3fSopenharmony_ci 30b1b8bc3fSopenharmony_cinamespace OHOS { 31b1b8bc3fSopenharmony_cinamespace NetManagerStandard { 32b1b8bc3fSopenharmony_ciclass NetPolicyCallback : public std::enable_shared_from_this<NetPolicyCallback> { 33b1b8bc3fSopenharmony_ci DECLARE_DELAYED_SINGLETON(NetPolicyCallback); 34b1b8bc3fSopenharmony_ci 35b1b8bc3fSopenharmony_cipublic: 36b1b8bc3fSopenharmony_ci /** 37b1b8bc3fSopenharmony_ci * Register net policy callback. 38b1b8bc3fSopenharmony_ci * @param callback Interface type pointer. 39b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 40b1b8bc3fSopenharmony_ci */ 41b1b8bc3fSopenharmony_ci int32_t RegisterNetPolicyCallbackAsync(const sptr<INetPolicyCallback> &callback); 42b1b8bc3fSopenharmony_ci 43b1b8bc3fSopenharmony_ci /** 44b1b8bc3fSopenharmony_ci * Unregister net policy callback. 45b1b8bc3fSopenharmony_ci * @param callback Interface type pointer. 46b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 47b1b8bc3fSopenharmony_ci */ 48b1b8bc3fSopenharmony_ci int32_t UnregisterNetPolicyCallbackAsync(const sptr<INetPolicyCallback> &callback); 49b1b8bc3fSopenharmony_ci 50b1b8bc3fSopenharmony_ci /** 51b1b8bc3fSopenharmony_ci * Notify this uid's policy is changed. 52b1b8bc3fSopenharmony_ci * @param uid The UID of application. 53b1b8bc3fSopenharmony_ci * @param policy See {@link NetUidPolicy}. 54b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 55b1b8bc3fSopenharmony_ci */ 56b1b8bc3fSopenharmony_ci int32_t NotifyNetUidPolicyChangeAsync(uint32_t uid, uint32_t policy); 57b1b8bc3fSopenharmony_ci 58b1b8bc3fSopenharmony_ci /** 59b1b8bc3fSopenharmony_ci * Notify this uid's rule is changed. 60b1b8bc3fSopenharmony_ci * @param uid The UID of application. 61b1b8bc3fSopenharmony_ci * @param rule See {@link NetUidRule}. 62b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 63b1b8bc3fSopenharmony_ci */ 64b1b8bc3fSopenharmony_ci int32_t NotifyNetUidRuleChangeAsync(uint32_t uid, uint32_t rule); 65b1b8bc3fSopenharmony_ci 66b1b8bc3fSopenharmony_ci /** 67b1b8bc3fSopenharmony_ci * Notify the quota policy is changed. 68b1b8bc3fSopenharmony_ci * @param quotaPolicies The struct vector of quotaPolicies. 69b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 70b1b8bc3fSopenharmony_ci */ 71b1b8bc3fSopenharmony_ci int32_t NotifyNetQuotaPolicyChangeAsync(const std::vector<NetQuotaPolicy> "aPolicies); 72b1b8bc3fSopenharmony_ci 73b1b8bc3fSopenharmony_ci /** 74b1b8bc3fSopenharmony_ci * Notify when metered ifaces is changed. 75b1b8bc3fSopenharmony_ci * @param ifaces The string vector of ifaces. 76b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 77b1b8bc3fSopenharmony_ci */ 78b1b8bc3fSopenharmony_ci int32_t NotifyNetMeteredIfacesChangeAsync(std::vector<std::string> &ifaces); 79b1b8bc3fSopenharmony_ci 80b1b8bc3fSopenharmony_ci /** 81b1b8bc3fSopenharmony_ci * Notify when background policy is changed. 82b1b8bc3fSopenharmony_ci * @param isAllow When isAllow is true,it means background policy is true, 83b1b8bc3fSopenharmony_ci * when isAllow is false,it means background policy is false. 84b1b8bc3fSopenharmony_ci * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 85b1b8bc3fSopenharmony_ci */ 86b1b8bc3fSopenharmony_ci int32_t NotifyNetBackgroundPolicyChangeAsync(bool isAllowed); 87b1b8bc3fSopenharmony_ci 88b1b8bc3fSopenharmony_ciprivate: 89b1b8bc3fSopenharmony_ci int32_t RegisterNetPolicyCallback(const sptr<INetPolicyCallback> &callback); 90b1b8bc3fSopenharmony_ci int32_t UnregisterNetPolicyCallback(const sptr<INetPolicyCallback> &callback); 91b1b8bc3fSopenharmony_ci int32_t NotifyNetUidPolicyChange(uint32_t uid, uint32_t policy); 92b1b8bc3fSopenharmony_ci int32_t NotifyNetUidRuleChange(uint32_t uid, uint32_t rule); 93b1b8bc3fSopenharmony_ci int32_t NotifyNetQuotaPolicyChange(const std::vector<NetQuotaPolicy> "aPolicies); 94b1b8bc3fSopenharmony_ci int32_t NotifyNetMeteredIfacesChange(std::vector<std::string> &ifaces); 95b1b8bc3fSopenharmony_ci int32_t NotifyNetBackgroundPolicyChange(bool isAllowed); 96b1b8bc3fSopenharmony_ci 97b1b8bc3fSopenharmony_ciprivate: 98b1b8bc3fSopenharmony_ci std::vector<sptr<INetPolicyCallback>> callbacks_; 99b1b8bc3fSopenharmony_ci std::shared_ptr<ffrt::queue> netPolicyCallbackFfrtQueue_ = nullptr; 100b1b8bc3fSopenharmony_ci}; 101b1b8bc3fSopenharmony_ci} // namespace NetManagerStandard 102b1b8bc3fSopenharmony_ci} // namespace OHOS 103b1b8bc3fSopenharmony_ci#endif // NET_POLICY_CALLBACK_H