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_ABILITY_RUNTIME_BACKGROUND_TASK_OBSERVER_H 17 #define OHOS_ABILITY_RUNTIME_BACKGROUND_TASK_OBSERVER_H 18 19 #ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE 20 #include "background_task_mgr_helper.h" 21 #include "background_task_subscriber.h" 22 #include "iremote_object.h" 23 #include "app_mgr_interface.h" 24 25 namespace OHOS { 26 namespace AAFwk { 27 class BackgroundTaskObserver : public BackgroundTaskMgr::BackgroundTaskSubscriber, 28 public std::enable_shared_from_this<BackgroundTaskObserver> { 29 public: 30 BackgroundTaskObserver(); 31 virtual ~BackgroundTaskObserver(); 32 bool IsBackgroundTaskUid(const int uid); 33 bool IsEfficiencyResourcesTaskUid(const int uid); 34 35 void GetContinuousTaskApps(); 36 void GetEfficiencyResourcesTaskApps(); 37 38 private: 39 void OnContinuousTaskStart(const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo> 40 &continuousTaskCallbackInfo) override; 41 42 void OnContinuousTaskStop(const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo> 43 &continuousTaskCallbackInfo) override; 44 45 void OnAppEfficiencyResourcesApply( 46 const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> &resourceInfo) override; 47 48 void OnAppEfficiencyResourcesReset( 49 const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> &resourceInfo) override; 50 51 void OnProcEfficiencyResourcesApply( 52 const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> &resourceInfo) override; 53 54 void OnProcEfficiencyResourcesReset( 55 const std::shared_ptr<BackgroundTaskMgr::ResourceCallbackInfo> &resourceInfo) override; 56 57 sptr<AppExecFwk::IAppMgr> GetAppManager(); 58 59 private: 60 std::list<int> bgTaskUids_; 61 std::mutex bgTaskMutex_; 62 std::list<int> efficiencyUids_; 63 std::mutex efficiencyMutex_; 64 sptr<OHOS::AppExecFwk::IAppMgr> appManager_ = nullptr; 65 }; 66 } // namespace AAFwk 67 } // namespace OHOS 68 #endif 69 #endif // OHOS_ABILITY_RUNTIME_BACKGROUND_TASK_OBSERVER_H 70