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_CONSTANTS_H 17 #define NET_POLICY_CONSTANTS_H 18 19 #include <climits> 20 21 #include "net_manager_constants.h" 22 23 namespace OHOS { 24 namespace NetManagerStandard { 25 static constexpr int64_t DATA_USAGE_UNKNOWN = -1; 26 static constexpr int64_t DATA_USAGE_UNLIMITED = LONG_MAX; 27 static constexpr int64_t REMIND_NEVER = -1; 28 constexpr const char *QUOTA_POLICY_NO_PERIOD = "--"; 29 30 enum NetPolicyResultCode { 31 POLICY_ERR_INVALID_UID = 2104002, 32 POLICY_ERR_INVALID_POLICY = 2104003, 33 POLICY_ERR_INVALID_QUOTA_POLICY = 2104004, 34 POLICY_ERR_QUOTA_POLICY_NOT_EXIST = 2104005, 35 }; 36 37 enum NetUidPolicy { 38 /* Default net policy. */ 39 NET_POLICY_NONE = 0, 40 /* Reject on metered networks when app in background. */ 41 NET_POLICY_ALLOW_METERED_BACKGROUND = 1 << 0, 42 /* Allow on metered networks when app in background. */ 43 NET_POLICY_REJECT_METERED_BACKGROUND = 1 << 1, 44 }; 45 46 enum NetUidRule { 47 /* Default uid rule */ 48 NET_RULE_NONE = 0, 49 /* Allow traffic on metered networks while app is foreground. */ 50 NET_RULE_ALLOW_METERED_FOREGROUND = 1 << 0, 51 /* Allow traffic on metered network. */ 52 NET_RULE_ALLOW_METERED = 1 << 1, 53 /* Reject traffic on metered network. */ 54 NET_RULE_REJECT_METERED = 1 << 2, 55 /* Allow traffic on all network (metered or non-metered). */ 56 NET_RULE_ALLOW_ALL = 1 << 5, 57 /* Reject traffic on all network. */ 58 NET_RULE_REJECT_ALL = 1 << 6, 59 }; 60 61 enum NetBackgroundPolicy { 62 /* Default value. */ 63 NET_BACKGROUND_POLICY_NONE = 0, 64 /* Apps can use metered networks on background. */ 65 NET_BACKGROUND_POLICY_ENABLE = 1, 66 /* Apps can't use metered networks on background. */ 67 NET_BACKGROUND_POLICY_DISABLE = 2, 68 /* Only apps in allowedlist can use metered networks on background. */ 69 NET_BACKGROUND_POLICY_TRUSTLIST = 3, 70 }; 71 72 enum PolicyTransCondition { 73 POLICY_TRANS_CONDITION_UID_POLICY_NONE = 1 << 0, 74 POLICY_TRANS_CONDITION_ALLOW_METERED_BACKGROUND = 1 << 1, 75 POLICY_TRANS_CONDITION_REJECT_METERED_BACKGROUND = 1 << 2, 76 POLICY_TRANS_CONDITION_FOREGROUND = 1 << 3, 77 POLICY_TRANS_CONDITION_BACKGROUND_RESTRICT = 1 << 4, 78 POLICY_TRANS_CONDITION_IDLE_ALLOWEDLIST = 1 << 5, 79 POLICY_TRANS_CONDITION_IDLE_MODE = 1 << 6, 80 POLICY_TRANS_CONDITION_POWERSAVE_ALLOWEDLIST = 1 << 7, 81 POLICY_TRANS_CONDITION_POWERSAVE_MODE = 1 << 8, 82 POLICY_TRANS_CONDITION_ADMIN_RESTRICT = 1 << 9, 83 }; 84 85 enum LimitAction { 86 /* Default action, do nothing. */ 87 LIMIT_ACTION_NONE = -1, 88 /* Access is disabled, when quota policy hit the limit */ 89 LIMIT_ACTION_ACCESS_DISABLED = 0, 90 /* The user is billed automatically, when quota policy hit the limit */ 91 LIMIT_ACTION_ALERT_ONLY = 1, 92 }; 93 94 enum RemindType { 95 /* Warning remind. */ 96 REMIND_TYPE_WARNING = 1, 97 /* Limit remind. */ 98 REMIND_TYPE_LIMIT = 2, 99 }; 100 } // namespace NetManagerStandard 101 } // namespace OHOS 102 #endif // NET_POLICY_CONSTANTS_H 103