1 /* 2 * Copyright (c) 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 #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 "event_handler.h" 28 #include "singleton.h" 29 30 namespace OHOS { 31 namespace AppExecFwk { 32 class BundleAgingMgr : public EventHandler { 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 void InitAgingRunner(); 48 49 private: 50 void InitAgingHandlerChain(); 51 void Process(const std::shared_ptr<BundleDataMgr> &dataMgr); 52 void ProcessEvent(const InnerEvent::Pointer &event) override; 53 bool CheckPrerequisite(AgingTriggertype type) const; 54 bool ReInitAgingRequest(const std::shared_ptr<BundleDataMgr> &dataMgr); 55 int AgingQueryFormStatistics(std::vector<DeviceUsageStats::BundleActiveModuleRecord>& results, 56 const std::shared_ptr<BundleDataMgr> &dataMgr); 57 void InitAgingTimerInterval(); 58 void InitAgingBatteryThresold(); 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 68 private: 69 static const uint32_t EVENT_AGING_NOW = 1; 70 }; 71 } // namespace AppExecFwk 72 } // namespace OHOS 73 #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_BUNDLE_AGING_MGR_H