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_H 17 #define NET_POLICY_CALLBACK_H 18 19 #include <string> 20 #include <vector> 21 22 #include "singleton.h" 23 24 #include "i_net_policy_callback.h" 25 #include "net_quota_policy.h" 26 27 namespace OHOS { 28 namespace NetManagerStandard { 29 class NetPolicyCallback : public std::enable_shared_from_this<NetPolicyCallback> { 30 DECLARE_DELAYED_SINGLETON(NetPolicyCallback); 31 32 public: 33 /** 34 * Register net policy callback. 35 * @param callback Interface type pointer. 36 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 37 */ 38 int32_t RegisterNetPolicyCallback(const sptr<INetPolicyCallback> &callback); 39 40 /** 41 * Unregister net policy callback. 42 * @param callback Interface type pointer. 43 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 44 */ 45 int32_t UnregisterNetPolicyCallback(const sptr<INetPolicyCallback> &callback); 46 47 /** 48 * Notify this uid's policy is changed. 49 * @param uid The UID of application. 50 * @param policy See {@link NetUidPolicy}. 51 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 52 */ 53 int32_t NotifyNetUidPolicyChange(uint32_t uid, uint32_t policy); 54 55 /** 56 * Notify this uid's rule is changed. 57 * @param uid The UID of application. 58 * @param rule See {@link NetUidRule}. 59 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 60 */ 61 int32_t NotifyNetUidRuleChange(uint32_t uid, uint32_t rule); 62 63 /** 64 * Notify the quota policy is changed. 65 * @param quotaPolicies The struct vector of quotaPolicies. 66 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 67 */ 68 int32_t NotifyNetQuotaPolicyChange(const std::vector<NetQuotaPolicy> "aPolicies); 69 70 /** 71 * Notify when metered ifaces is changed. 72 * @param ifaces The string vector of ifaces. 73 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 74 */ 75 int32_t NotifyNetMeteredIfacesChange(std::vector<std::string> &ifaces); 76 77 /** 78 * Notify when background policy is changed. 79 * @param isAllow When isAllow is true,it means background policy is true, 80 * when isAllow is false,it means background policy is false. 81 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 82 */ 83 int32_t NotifyNetBackgroundPolicyChange(bool isAllowed); 84 85 private: 86 std::vector<sptr<INetPolicyCallback>> callbacks_; 87 std::mutex callbackMutex_; 88 }; 89 } // namespace NetManagerStandard 90 } // namespace OHOS 91 #endif // NET_POLICY_CALLBACK_H