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 #include "mem_mgr_service.h" 17 #include "memmgr_log.h" 18 #include "system_ability_definition.h" 19 #include "mem_mgr_event_center.h" 20 #include "reclaim_priority_manager.h" 21 #include "reclaim_strategy_manager.h" 22 #include "multi_account_manager.h" 23 24 #include <unistd.h> 25 26 namespace OHOS { 27 namespace Memory { 28 namespace { 29 const std::string TAG = "MemMgrService"; 30 } 31 32 IMPLEMENT_SINGLE_INSTANCE(MemMgrService); 33 const bool REGISTER_RESULT = SystemAbility::MakeAndRegisterAbility(&MemMgrService::GetInstance()); 34 MemMgrService()35MemMgrService::MemMgrService() : SystemAbility(MEMORY_MANAGER_SA_ID, true) 36 { 37 } 38 Init()39bool MemMgrService::Init() 40 { 41 // init reclaim priority manager 42 if (!ReclaimPriorityManager::GetInstance().Init()) { 43 HILOGE("ReclaimPriorityManager init failed"); 44 return false; 45 } 46 47 // init multiple account manager 48 MultiAccountManager::GetInstance().Init(); 49 50 // init reclaim strategy manager 51 if (!ReclaimStrategyManager::GetInstance().Init()) { 52 HILOGE("ReclaimStrategyManager init failed"); 53 return false; 54 } 55 56 // init event center, then managers above can work by event trigger 57 if (!MemMgrEventCenter::GetInstance().Init()) { 58 HILOGE("MemMgrEventCenter init failed"); 59 return false; 60 } 61 HILOGI("init successed"); 62 return true; 63 } 64 OnStart()65void MemMgrService::OnStart() 66 { 67 HILOGI("called"); 68 if (!Init()) { 69 HILOGE("init failed"); 70 return; 71 } 72 } 73 OnStop()74void MemMgrService::OnStop() 75 { 76 HILOGI("called"); 77 } 78 } // namespace Memory 79 } // namespace OHOS 80