• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_AGING_REQUEST_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_AGING_REQUEST_H
18 
19 #include <vector>
20 #include <set>
21 
22 #include "aging_bundle_info.h"
23 #include "aging_util.h"
24 
25 namespace OHOS {
26 namespace AppExecFwk {
27 enum class AgingCleanType {
28     CLEAN_CACHE = 0,
29     CLEAN_OTHERS,
30 };
31 
32 class AgingRequest {
33 public:
34     AgingRequest();
35     bool IsReachStartAgingThreshold() const;
36     bool IsReachEndAgingThreshold() const;
37     size_t SortAgingBundles();
38     void ResetRequest();
39     void Dump();
40     void AddAgingBundle(AgingBundleInfo &bundleInfo);
41 
GetAgingBundles()42     const std::vector<AgingBundleInfo> &GetAgingBundles() const
43     {
44         return agingBundles_;
45     };
46 
UpdateTotalDataBytesAfterUninstalled(const int64_t dataBytes)47     void UpdateTotalDataBytesAfterUninstalled(const int64_t dataBytes)
48     {
49         tatalDataBytes_ -= dataBytes;
50     };
51 
GetTotalDataBytes()52     int64_t GetTotalDataBytes() const
53     {
54         return tatalDataBytes_;
55     };
56 
SetTotalDataBytes(const int64_t allBundleDataBytes)57     void SetTotalDataBytes(const int64_t allBundleDataBytes)
58     {
59         tatalDataBytes_ = allBundleDataBytes;
60     };
61 
SetAgingCleanType(const AgingCleanType agingCleanType)62     void SetAgingCleanType(const AgingCleanType agingCleanType)
63     {
64         agingCleanType_ = agingCleanType;
65     };
66 
GetAgingCleanType()67     AgingCleanType GetAgingCleanType() const
68     {
69         return agingCleanType_;
70     };
71 
GetTotalDataBytesThreshold()72     static int64_t GetTotalDataBytesThreshold()
73     {
74         return totalDataBytesThreshold_;
75     };
76 
GetOneDayTimeMs()77     static int64_t GetOneDayTimeMs()
78     {
79         return oneDayTimeMs_;
80     };
81 
82 private:
83     void InitAgingPolicySystemParameters();
84     void InitAgingDatasizeThreshold();
85     void InitAgingOneDayTimeMs();
86 
87     std::vector<AgingBundleInfo> agingBundles_;
88     int64_t tatalDataBytes_ = 0;
89     AgingCleanType agingCleanType_ = AgingCleanType::CLEAN_CACHE;
90 
91     static int64_t totalDataBytesThreshold_;
92     static int64_t oneDayTimeMs_;
93 };
94 }  //  namespace AppExecFwk
95 }  //  namespace OHOS
96 
97 #endif  //  FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_AGING_REQUEST_H
98