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 16 #ifndef OHOS_MEMORY_MEMMGR_RECALIM_STRATEGY_MANAGER_H 17 #define OHOS_MEMORY_MEMMGR_RECALIM_STRATEGY_MANAGER_H 18 19 #include "single_instance.h" 20 #include "event_handler.h" 21 #include "memcg_mgr.h" 22 #include "reclaim_param.h" 23 24 namespace OHOS { 25 namespace Memory { 26 class ReclaimStrategyManager { 27 DECLARE_SINGLE_INSTANCE_BASE(ReclaimStrategyManager); 28 29 public: 30 bool Init(); 31 void NotifyAppStateChanged(std::shared_ptr<ReclaimParam> reclaimPara); 32 void NotifyAccountDied(int accountId); 33 void NotifyAccountPriorityChanged(int accountId, int priority); 34 Initailized()35 inline bool Initailized() 36 { 37 return initialized_; 38 }; 39 40 private: 41 bool initialized_ = false; 42 std::shared_ptr<AppExecFwk::EventHandler> handler_; 43 44 ReclaimStrategyManager(); 45 bool GetEventHandler_(); 46 void InitProcessBeforeMemmgr(); 47 48 // handle app and os user event 49 bool HandleAppStateChanged_(std::shared_ptr<ReclaimParam> reclaimPara); 50 bool HandleProcessCreate_(std::shared_ptr<ReclaimParam> reclaimPara); 51 bool HandleAccountDied_(int accountId); 52 bool HandleAccountPriorityChanged_(int accountId, int priority); 53 54 // get param for config_mgr 55 bool GetReclaimRatiosByScore_(int score, ReclaimRatios& ratios); 56 void GetValidScore_(int& priority); 57 }; 58 } // namespace Memory 59 } // namespace OHOS 60 #endif // OHOS_MEMORY_MEMMGR_RECALIM_STRATEGY_MANAGER_H 61