• 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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_AGING_MGR_H
16 #define FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_AGING_MGR_H
17 
18 #include <map>
19 #include <mutex>
20 #include <vector>
21 
22 #include "aging/aging_constants.h"
23 #include "aging/aging_handler_chain.h"
24 #include "aging/aging_request.h"
25 #include "bundle_active_client.h"
26 #include "bundle_data_mgr.h"
27 #include "serial_queue.h"
28 #include "singleton.h"
29 
30 namespace OHOS {
31 namespace AppExecFwk {
32 class BundleAgingMgr : public std::enable_shared_from_this<BundleAgingMgr> {
33 public:
34     enum AgingTriggertype {
35         PREIOD = 0,
36         FREE_INSTALL = 1,
37         UPDATE_REMOVABLE_FLAG = 2,
38     };
39 
40 public:
41     BundleAgingMgr();
42     ~BundleAgingMgr();
43 
44 public:
45     void Start(AgingTriggertype type);
46     void InitAgingtTimer();
47 
48 private:
49     void InitAgingHandlerChain();
50     void Process(const std::shared_ptr<BundleDataMgr> &dataMgr);
51     bool CheckPrerequisite(AgingTriggertype type) const;
52     void InitAgingTimerInterval();
53     void InitAgingBatteryThresold();
54     bool InitAgingRequest();
55     bool ResetRequest();
56     bool IsReachStartAgingThreshold();
57     bool QueryBundleStatsInfoByInterval(std::vector<DeviceUsageStats::BundleActivePackageStats> &results);
58     void ScheduleLoopTask();
59 
60 private:
61     std::mutex mutex_;
62     bool running_ = false;
63     AgingHandlerChain chain_;
64     AgingRequest request_;
65     int64_t agingTimerInterval_ = AgingConstants::DEFAULT_AGING_TIMER_INTERVAL;
66     int64_t agingBatteryThresold_ = AgingConstants::DEFAULT_AGING_BATTERY_THRESHOLD;
67     std::shared_ptr<SerialQueue> serialQueue_;
68 
69 private:
70     static const uint32_t EVENT_AGING_NOW = 1;
71 };
72 }  //  namespace AppExecFwk
73 }  //  namespace OHOS
74 #endif  //  FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_AGING_MGR_H