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