1ba5c3796Sopenharmony_ci/* 2ba5c3796Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3ba5c3796Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4ba5c3796Sopenharmony_ci * you may not use this file except in compliance with the License. 5ba5c3796Sopenharmony_ci * You may obtain a copy of the License at 6ba5c3796Sopenharmony_ci * 7ba5c3796Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8ba5c3796Sopenharmony_ci * 9ba5c3796Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10ba5c3796Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11ba5c3796Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12ba5c3796Sopenharmony_ci * See the License for the specific language governing permissions and 13ba5c3796Sopenharmony_ci * limitations under the License. 14ba5c3796Sopenharmony_ci */ 15ba5c3796Sopenharmony_ci 16ba5c3796Sopenharmony_ci#include "bg_task_observer.h" 17ba5c3796Sopenharmony_ci#include "memmgr_log.h" 18ba5c3796Sopenharmony_ci#include "reclaim_priority_manager.h" 19ba5c3796Sopenharmony_ci 20ba5c3796Sopenharmony_cinamespace OHOS { 21ba5c3796Sopenharmony_cinamespace Memory { 22ba5c3796Sopenharmony_cinamespace { 23ba5c3796Sopenharmony_ciconst std::string TAG = "BgTaskObserver"; 24ba5c3796Sopenharmony_ci} 25ba5c3796Sopenharmony_ci 26ba5c3796Sopenharmony_civoid BgTaskObserver::OnTransientTaskStart( 27ba5c3796Sopenharmony_ci const std::shared_ptr<BackgroundTaskMgr::TransientTaskAppInfo>& ttInfo) 28ba5c3796Sopenharmony_ci{ 29ba5c3796Sopenharmony_ci if (ttInfo == nullptr) { 30ba5c3796Sopenharmony_ci HILOGE("called with null TransientTaskAppInfo"); 31ba5c3796Sopenharmony_ci return; 32ba5c3796Sopenharmony_ci } 33ba5c3796Sopenharmony_ci std::string pkgName = ttInfo->GetPackageName(); 34ba5c3796Sopenharmony_ci int uid = ttInfo->GetUid(); 35ba5c3796Sopenharmony_ci int pid = ttInfo->GetPid(); 36ba5c3796Sopenharmony_ci HILOGD("called, pkg=%{public}s, uid=%{public}d, pid=%{public}d", pkgName.c_str(), uid, pid); 37ba5c3796Sopenharmony_ci 38ba5c3796Sopenharmony_ci ReclaimPriorityManager::GetInstance().UpdateReclaimPriority( 39ba5c3796Sopenharmony_ci SingleRequest({pid, uid, pkgName}, AppStateUpdateReason::SUSPEND_DELAY_START)); 40ba5c3796Sopenharmony_ci} 41ba5c3796Sopenharmony_ci 42ba5c3796Sopenharmony_civoid BgTaskObserver::OnTransientTaskEnd( 43ba5c3796Sopenharmony_ci const std::shared_ptr<BackgroundTaskMgr::TransientTaskAppInfo>& ttInfo) 44ba5c3796Sopenharmony_ci{ 45ba5c3796Sopenharmony_ci if (ttInfo == nullptr) { 46ba5c3796Sopenharmony_ci HILOGE("called with null TransientTaskAppInfo"); 47ba5c3796Sopenharmony_ci return; 48ba5c3796Sopenharmony_ci } 49ba5c3796Sopenharmony_ci std::string pkgName = ttInfo->GetPackageName(); 50ba5c3796Sopenharmony_ci int uid = ttInfo->GetUid(); 51ba5c3796Sopenharmony_ci int pid = ttInfo->GetPid(); 52ba5c3796Sopenharmony_ci HILOGD("called, pkg=%{public}s, uid=%{public}d, pid=%{public}d", pkgName.c_str(), uid, pid); 53ba5c3796Sopenharmony_ci 54ba5c3796Sopenharmony_ci ReclaimPriorityManager::GetInstance().UpdateReclaimPriority( 55ba5c3796Sopenharmony_ci SingleRequest({pid, uid, pkgName}, AppStateUpdateReason::SUSPEND_DELAY_END)); 56ba5c3796Sopenharmony_ci} 57ba5c3796Sopenharmony_ci 58ba5c3796Sopenharmony_civoid BgTaskObserver::OnContinuousTaskStart( 59ba5c3796Sopenharmony_ci const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>& ctInfo) 60ba5c3796Sopenharmony_ci{ 61ba5c3796Sopenharmony_ci if (ctInfo == nullptr) { 62ba5c3796Sopenharmony_ci HILOGE("called with null ContinuousTaskCallbackInfo"); 63ba5c3796Sopenharmony_ci return; 64ba5c3796Sopenharmony_ci } 65ba5c3796Sopenharmony_ci int32_t type = ctInfo->GetTypeId(); 66ba5c3796Sopenharmony_ci uid_t uid = ctInfo->GetCreatorUid(); 67ba5c3796Sopenharmony_ci pid_t pid = ctInfo->GetCreatorPid(); 68ba5c3796Sopenharmony_ci std::string abilityName = ctInfo->GetAbilityName(); 69ba5c3796Sopenharmony_ci HILOGD("called, abilityName=%{public}s, type=%{public}d uid=%{public}d, pid=%{public}d", 70ba5c3796Sopenharmony_ci abilityName.c_str(), type, uid, pid); 71ba5c3796Sopenharmony_ci 72ba5c3796Sopenharmony_ci ReclaimPriorityManager::GetInstance().UpdateReclaimPriority( 73ba5c3796Sopenharmony_ci SingleRequest({pid, uid, abilityName}, AppStateUpdateReason::BACKGROUND_RUNNING_START)); 74ba5c3796Sopenharmony_ci} 75ba5c3796Sopenharmony_ci 76ba5c3796Sopenharmony_civoid BgTaskObserver::OnContinuousTaskStop( 77ba5c3796Sopenharmony_ci const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>& ctInfo) 78ba5c3796Sopenharmony_ci{ 79ba5c3796Sopenharmony_ci if (ctInfo == nullptr) { 80ba5c3796Sopenharmony_ci HILOGE("called with null ContinuousTaskCallbackInfo"); 81ba5c3796Sopenharmony_ci return; 82ba5c3796Sopenharmony_ci } 83ba5c3796Sopenharmony_ci int32_t type = ctInfo->GetTypeId(); 84ba5c3796Sopenharmony_ci uid_t uid = ctInfo->GetCreatorUid(); 85ba5c3796Sopenharmony_ci pid_t pid = ctInfo->GetCreatorPid(); 86ba5c3796Sopenharmony_ci std::string abilityName = ctInfo->GetAbilityName(); 87ba5c3796Sopenharmony_ci HILOGD("called, abilityName=%{public}s, type=%{public}d uid=%{public}d, pid=%{public}d", 88ba5c3796Sopenharmony_ci abilityName.c_str(), type, uid, pid); 89ba5c3796Sopenharmony_ci 90ba5c3796Sopenharmony_ci ReclaimPriorityManager::GetInstance().UpdateReclaimPriority( 91ba5c3796Sopenharmony_ci SingleRequest({pid, uid, abilityName}, AppStateUpdateReason::BACKGROUND_RUNNING_END)); 92ba5c3796Sopenharmony_ci} 93ba5c3796Sopenharmony_ci 94ba5c3796Sopenharmony_civoid BgTaskObserver::OnRemoteDied(const wptr<IRemoteObject> &object) 95ba5c3796Sopenharmony_ci{ 96ba5c3796Sopenharmony_ci HILOGE("called"); 97ba5c3796Sopenharmony_ci} 98ba5c3796Sopenharmony_ci} // namespace Memory 99ba5c3796Sopenharmony_ci} // namespace OHOS 100