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 #ifdef RESOURCESCHEDULE_BGTASKMGR_ENABLE 16 #include "scheduler_bg_task_subscriber.h" 17 #include "resource_type.h" 18 #include "resource_callback_info.h" 19 #include "work_scheduler_service.h" 20 #include "work_sched_hilog.h" 21 22 namespace OHOS { 23 namespace WorkScheduler { 24 using namespace OHOS::BackgroundTaskMgr; OnProcEfficiencyResourcesApply(const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> & resourceInfo)25void SchedulerBgTaskSubscriber::OnProcEfficiencyResourcesApply( 26 const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> &resourceInfo) 27 { 28 WS_HILOGD("OnProcEfficiencyResourcesApply called"); 29 if (!resourceInfo || (resourceInfo->GetResourceNumber() & BackgroundTaskMgr::ResourceType::WORK_SCHEDULER) == 0) { 30 WS_HILOGD("called with null efficiency callback info"); 31 return; 32 } 33 int32_t uid = resourceInfo->GetUid(); 34 DelayedSingleton<WorkSchedulerService>::GetInstance()->UpdateEffiResApplyInfo(uid, true); 35 } 36 OnProcEfficiencyResourcesReset(const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> & resourceInfo)37void SchedulerBgTaskSubscriber::OnProcEfficiencyResourcesReset( 38 const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> &resourceInfo) 39 { 40 WS_HILOGD("OnProcEfficiencyResourcesReset called"); 41 if (!resourceInfo || (resourceInfo->GetResourceNumber() & BackgroundTaskMgr::ResourceType::WORK_SCHEDULER) == 0) { 42 WS_HILOGD("called with null efficiency callback info"); 43 return; 44 } 45 int32_t uid = resourceInfo->GetUid(); 46 DelayedSingleton<WorkSchedulerService>::GetInstance()->UpdateEffiResApplyInfo(uid, false); 47 } 48 OnAppEfficiencyResourcesApply(const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> & resourceInfo)49void SchedulerBgTaskSubscriber::OnAppEfficiencyResourcesApply( 50 const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> &resourceInfo) 51 { 52 OnProcEfficiencyResourcesApply(resourceInfo); 53 } 54 OnAppEfficiencyResourcesReset(const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> & resourceInfo)55void SchedulerBgTaskSubscriber::OnAppEfficiencyResourcesReset( 56 const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> &resourceInfo) 57 { 58 OnProcEfficiencyResourcesReset(resourceInfo); 59 } 60 OnRemoteDied(const wptr<IRemoteObject> & object)61void SchedulerBgTaskSubscriber::OnRemoteDied(const wptr<IRemoteObject> &object) 62 { 63 WS_HILOGE("called"); 64 } 65 } // namespace Memory 66 } // namespace OHOS 67 #endif