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 "memmgr_log.h" 17 #include "default_multi_account_strategy.h" 18 #include "reclaim_priority_constants.h" 19 20 namespace OHOS { 21 namespace Memory { 22 namespace { 23 const std::string TAG = "DefaultMultiAccountStrategy"; 24 } 25 SetAccountPriority(std::shared_ptr<AccountPriorityInfo> accountInfo)26bool DefaultMultiAccountStrategy::SetAccountPriority(std::shared_ptr<AccountPriorityInfo> accountInfo) 27 { 28 if (accountInfo == nullptr) { 29 HILOGI("Set the account priority failed because the accountInfo is null."); 30 return false; 31 } 32 33 int priority; 34 if (accountInfo->GetIsActived()) { 35 priority = static_cast<int>(DefaultMultiAccountPriority::HIGH_PRIORITY); 36 } else { 37 priority = static_cast<int>(DefaultMultiAccountPriority::LOW_PRIORITY); 38 } 39 40 accountInfo->SetPriority(priority); 41 return true; 42 } 43 RecalcBundlePriority(std::shared_ptr<AccountPriorityInfo> accountInfo,int bundlePriority)44int DefaultMultiAccountStrategy::RecalcBundlePriority(std::shared_ptr<AccountPriorityInfo> accountInfo, 45 int bundlePriority) 46 { 47 if (accountInfo == nullptr) { 48 return RECLAIM_PRIORITY_MAX; 49 } 50 51 return accountInfo->GetPriority() + bundlePriority; 52 } 53 } // namespace Memory 54 } // namespace OHOS