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