• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 const int32_t SUBSCRIBE_BACKGROUND_TASK_TRY = 5;
28 const int32_t REPOLL_TIME_MICRO_SECONDS = 1000000;
29 class BackgroundTaskObserver : public BackgroundTaskMgr::BackgroundTaskSubscriber,
30                                public std::enable_shared_from_this<BackgroundTaskObserver> {
31 public:
32     BackgroundTaskObserver();
33     virtual ~BackgroundTaskObserver();
34     bool IsBackgroundTaskUid(const int uid);
35 
36     void GetContinuousTaskApps();
37 
38 private:
39     void OnContinuousTaskStart(const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>
40         &continuousTaskCallbackInfo);
41 
42     void OnContinuousTaskStop(const std::shared_ptr<BackgroundTaskMgr::ContinuousTaskCallbackInfo>
43         &continuousTaskCallbackInfo);
44 
45     sptr<AppExecFwk::IAppMgr> GetAppManager();
46 
47 private:
48     std::list<int> bgTaskUids_;
49     std::mutex bgTaskMutex_;
50     sptr<OHOS::AppExecFwk::IAppMgr> appManager_ = nullptr;
51 };
52 }  // namespace AAFwk
53 }  // namespace OHOS
54 #endif
55 #endif  // OHOS_ABILITY_RUNTIME_BACKGROUND_TASK_OBSERVER_H
56