1 /* 2 * Copyright (c) 2021-2023 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 I_NET_POLICY_SERVICE_H 17 #define I_NET_POLICY_SERVICE_H 18 19 #include "iremote_broker.h" 20 21 #include "i_net_policy_callback.h" 22 #include "net_policy_constants.h" 23 #include "net_quota_policy.h" 24 #include "policy_ipc_interface_code.h" 25 26 namespace OHOS { 27 namespace NetManagerStandard { 28 class INetPolicyService : public IRemoteBroker { 29 public: 30 DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NetManagerStandard.INetPolicyService"); 31 32 public: 33 /** 34 * Set the network policy for the specified UID. 35 * 36 * @param uid The specified UID of app. 37 * @param policy The network policy for application. 38 * For details, see {@link NetUidPolicy}. 39 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 40 */ 41 virtual int32_t SetPolicyByUid(uint32_t uid, uint32_t policy) = 0; 42 43 /** 44 * Get the network policy of the specified UID. 45 * 46 * @param uid The specified UID of app. 47 * @param policy Return this uid's policy. 48 * For details, see {@link NetUidPolicy}. 49 * int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 50 */ 51 virtual int32_t GetPolicyByUid(uint32_t uid, uint32_t &policy) = 0; 52 53 /** 54 * Get the application UIDs of the specified policy. 55 * 56 * @param policy the network policy of the current UID of application. 57 * For details, see {@link NetUidPolicy}. 58 * @param uids The list of UIDs 59 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 60 */ 61 virtual int32_t GetUidsByPolicy(uint32_t policy, std::vector<uint32_t> &uids) = 0; 62 63 /** 64 * Get the status whether the specified uid app can access the metered network or non-metered network. 65 * 66 * @param uid The specified UID of application. 67 * @param metered Indicates metered network or non-metered network. 68 * @param isAllowed True means it's allowed to access the network. 69 * False means it's not allowed to access the network. 70 * @return Returns it's allowed or not to access the network. 71 */ 72 virtual int32_t IsUidNetAllowed(uint32_t uid, bool metered, bool &isAllowed) = 0; 73 74 /** 75 * Get the status whether the specified uid app can access the specified iface network. 76 * 77 * @param uid The specified UID of application. 78 * @param ifaceName Iface name. 79 * @param isAllowed True means it's allowed to access the network. 80 * False means it's not allowed to access the network. 81 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 82 */ 83 virtual int32_t IsUidNetAllowed(uint32_t uid, const std::string &ifaceName, bool &isAllowed) = 0; 84 85 /** 86 * Register network policy change callback. 87 * 88 * @param callback The callback of INetPolicyCallback interface. 89 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 90 */ 91 virtual int32_t RegisterNetPolicyCallback(const sptr<INetPolicyCallback> &callback) = 0; 92 93 /** 94 * Unregister network policy change callback. 95 * 96 * @param callback The callback of INetPolicyCallback interface. 97 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 98 */ 99 virtual int32_t UnregisterNetPolicyCallback(const sptr<INetPolicyCallback> &callback) = 0; 100 101 /** 102 * Set network policies. 103 * 104 * @param quotaPolicies The list of network quota policy, {@link NetQuotaPolicy}. 105 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 106 */ 107 virtual int32_t SetNetQuotaPolicies(const std::vector<NetQuotaPolicy> "aPolicies) = 0; 108 109 /** 110 * Get network policies. 111 * 112 * @param quotaPolicies The list of network quota policy, {@link NetQuotaPolicy}. 113 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 114 */ 115 virtual int32_t GetNetQuotaPolicies(std::vector<NetQuotaPolicy> "aPolicies) = 0; 116 117 /** 118 * Update the limit or warning remind time of quota policy. 119 * 120 * @param netType {@link NetBearType}. 121 * @param simId Specify the matched simId of quota policy when netType is cellular. 122 * @param remindType {@link RemindType}. 123 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 124 */ 125 virtual int32_t UpdateRemindPolicy(int32_t netType, const std::string &simId, uint32_t remindType) = 0; 126 127 /** 128 * Set the UID into device idle allow list. 129 * 130 * @param uid The specified UID of application. 131 * @param isAllowed The UID is into allow list or not. 132 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 133 */ 134 virtual int32_t SetDeviceIdleTrustlist(const std::vector<uint32_t> &uids, bool isAllowed) = 0; 135 136 /** 137 * Get the allow list of UID in device idle mode. 138 * 139 * @param uids The list of UIDs 140 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 141 */ 142 virtual int32_t GetDeviceIdleTrustlist(std::vector<uint32_t> &uids) = 0; 143 144 /** 145 * Process network policy in device idle mode. 146 * 147 * @param enable Device idle mode is open or not. 148 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 149 */ 150 virtual int32_t SetDeviceIdlePolicy(bool enable) = 0; 151 152 /** 153 * Reset network policies\rules\quota policies\firewall rules. 154 * 155 * @param simId Specify the matched simId of quota policy. 156 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 157 */ 158 virtual int32_t ResetPolicies(const std::string &simId) = 0; 159 160 /** 161 * Control if apps can use data on background. 162 * 163 * @param isAllowed Allow apps to use data on background. 164 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 165 */ 166 virtual int32_t SetBackgroundPolicy(bool isAllowed) = 0; 167 168 /** 169 * Get the status if apps can use data on background. 170 * 171 * @param backgroundPolicy True is allowed to use data on background. 172 * False is not allowed to use data on background. 173 * @return int32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 174 */ 175 virtual int32_t GetBackgroundPolicy(bool &backgroundPolicy) = 0; 176 177 /** 178 * Get the background network restriction policy for the specified uid. 179 * 180 * @param uid The specified UID of application. 181 * @param backgroundPolicyOfUid The specified UID of backgroundPolicy. 182 * For details, see {@link NetBackgroundPolicy}. 183 * @return uint32_t Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 184 */ 185 virtual int32_t GetBackgroundPolicyByUid(uint32_t uid, uint32_t &backgroundPolicyOfUid) = 0; 186 187 /** 188 * Get the Power Save Allowed List object 189 * 190 * @param uids The list of UIDs 191 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 192 */ 193 virtual int32_t GetPowerSaveTrustlist(std::vector<uint32_t> &uids) = 0; 194 195 /** 196 * Set the Power Save Allowed List object 197 * 198 * @param uid The specified UID of application. 199 * @param isAllowed The UID is into allow list or not. 200 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 201 */ 202 virtual int32_t SetPowerSaveTrustlist(const std::vector<uint32_t> &uids, bool isAllowed) = 0; 203 204 /** 205 * Set the Power Save Policy object 206 * 207 * @param enable Power save mode is open or not. 208 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 209 */ 210 virtual int32_t SetPowerSavePolicy(bool enable) = 0; 211 212 /** 213 * Check if you have permission 214 * 215 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 216 */ 217 virtual int32_t CheckPermission() = 0; 218 219 /** 220 * factory reset net policies 221 * 222 * @return Returns 0 success. Otherwise fail, {@link NetPolicyResultCode}. 223 */ 224 virtual int32_t FactoryResetPolicies() = 0; 225 }; 226 } // namespace NetManagerStandard 227 } // namespace OHOS 228 #endif // I_NET_POLICY_SERVICE_H 229