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