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_QUOTA_POLICY_H 17 #define NET_POLICY_QUOTA_POLICY_H 18 19 #include <string> 20 21 #include "parcel.h" 22 23 #include "net_all_capabilities.h" 24 #include "net_policy_constants.h" 25 26 namespace OHOS { 27 namespace NetManagerStandard { 28 static constexpr const char *PERIOD_DAY = "D"; 29 static constexpr const char *PERIOD_MONTH = "M"; 30 static constexpr const char *PERIOD_YEAR = "Y"; 31 static constexpr int32_t PERIOD_START = 1; 32 static constexpr int32_t DAY_MAX = 31; 33 static constexpr int32_t MONTH_MAX = 12; 34 static constexpr int32_t YEAR_MAX = 366; 35 static constexpr int32_t PERIOD_DURATION_SIZE = 2; 36 static constexpr int32_t QUOTA_POLICY_MAX_SIZE = 100; 37 38 struct NetQuotaPolicy : public Parcelable { 39 /* See {@link NetBearType} */ 40 int32_t netType = NET_CAPABILITY_INTERNAL_DEFAULT; 41 /* The ID of the target card, valid when netType is BEARER_CELLULAR */ 42 std::string iccid; 43 /* To specify the identity of network, such as different WLAN */ 44 std::string ident; 45 // @deprecated 46 int64_t periodStartTime = -1; 47 /* The period and the start time for quota policy, default: "M1" */ 48 std::string periodDuration = (PERIOD_MONTH + std::to_string(PERIOD_START)); 49 // @deprecated 50 std::string title; 51 // @deprecated 52 std::string summary; 53 /* The warning threshold of traffic, default: DATA_USAGE_UNKNOWN */ 54 int64_t warningBytes = DATA_USAGE_UNKNOWN; 55 /* The limit threshold of traffic, default: DATA_USAGE_UNKNOWN */ 56 int64_t limitBytes = DATA_USAGE_UNKNOWN; 57 /* The updated wall time that last warning remind, default: REMIND_NEVER */ 58 int64_t lastWarningRemind = REMIND_NEVER; 59 /* The updated wall time that last limit remind, default: REMIND_NEVER */ 60 int64_t lastLimitRemind = REMIND_NEVER; 61 /* Is metered network or not */ 62 bool metered = false; 63 // @deprecated 64 int32_t source = -1; 65 /* The action while the used bytes reach the limit, see {@link LimitAction} */ 66 int32_t limitAction = LimitAction::LIMIT_ACTION_NONE; 67 // @deprecated 68 int64_t usedBytes = -1; 69 // @deprecated 70 int64_t usedTimeDuration = -1; 71 // @deprecated 72 std::string possessor; 73 74 virtual bool Marshalling(Parcel &parcel) const override; 75 static bool Marshalling(Parcel &parcel, const NetQuotaPolicy "aPolicy); 76 static bool Marshalling(Parcel &parcel, const std::vector<NetQuotaPolicy> "aPolicies); 77 static bool Unmarshalling(Parcel &parcel, NetQuotaPolicy "aPolicy); 78 static bool Unmarshalling(Parcel &parcel, std::vector<NetQuotaPolicy> "aPolicies); 79 /** 80 * Get the period start, transform the periodDuration to wall time. 81 * 82 * @return int64_t The wall time.of the period start. 83 */ 84 int64_t GetPeriodStart(); 85 86 /** 87 * To judge the quota is over the warning threshold. 88 * 89 * @param totalQuota The total quota used. 90 * @return true Over the warning threshold. 91 * @return false 92 */ 93 bool IsOverWarning(int64_t totalQuota) const; 94 95 /** 96 * To judge the quota is over the limit threshold. 97 * 98 * @param totalQuota The total quota used. 99 * @return true Over the limit threshold. 100 * @return false Not over. 101 */ 102 bool IsOverLimit(int64_t totalQuota) const; 103 104 /** 105 * Reset the quota policy to default. 106 * 107 */ 108 void Reset(); 109 }; 110 } // namespace NetManagerStandard 111 } // namespace OHOS 112 #endif // NET_POLICY_QUOTA_POLICY_H 113