• 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 FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_SUBSCRIBER_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_SUBSCRIBER_H
18 
19 #include <iremote_broker.h>
20 
21 #include "ibackground_task_mgr.h"
22 #include "background_task_subscriber_stub.h"
23 
24 namespace OHOS {
25 namespace BackgroundTaskMgr {
26 class BackgroundTaskSubscriber {
27 public:
28     /**
29      * Default constructor used to create a instance.
30      */
31     BackgroundTaskSubscriber();
32 
33     /**
34      * Default destructor.
35      */
36     virtual ~BackgroundTaskSubscriber();
37 
38     /**
39      * Called back when the subscriber is connected to Background Task Manager Service.
40      */
41     virtual void OnConnected();
42 
43     /**
44      * Called back when the subscriber is disconnected from Background Task Manager Service.
45      */
46     virtual void OnDisconnected();
47 
48     /**
49      * Called back when a transient task start.
50      *
51      * @param info Transient task app info.
52      **/
53     virtual void OnTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info);
54 
55     /**
56      * Called back when a transient task end.
57      *
58      * @param info Transient task app info.
59      **/
60     virtual void OnTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info);
61 
62     /**
63      * Called back when the app has transient task.
64      *
65      * @param info App info of transient task.
66      **/
67     virtual void OnAppTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info);
68 
69     /**
70      * Called back when the app does not have transient task.
71      *
72      * @param info App info transient task .
73      **/
74     virtual void OnAppTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info);
75 
76     /**
77      * Called back when a continuous task start.
78      *
79      * @param info Transient task app info.
80      **/
81     virtual void OnContinuousTaskStart(const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo);
82 
83     /**
84      * Called back when a continuous task end.
85      *
86      * @param info Transient task app info.
87      **/
88     virtual void OnContinuousTaskStop(const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo);
89 
90     /**
91      * Called back when the app does not have continuous task.
92      *
93      * @param uid App uid.
94      **/
95     virtual void OnAppContinuousTaskStop(int32_t uid);
96 
97     /**
98      * Called back when the Background Task Manager Service has died.
99      */
100     virtual void OnRemoteDied(const wptr<IRemoteObject> &object);
101 
102     /**
103      * @brief Apply or unapply efficiency resources of App.
104      *
105      * @param resourceInfo Request params.
106      */
107     virtual void OnAppEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo);
108 
109     /**
110      * @brief Called back when the efficiency resources of App reset.
111      *
112      * @param resourceInfo Request params.
113      */
114     virtual void OnAppEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo);
115 
116     /**
117      * @brief Apply or unapply efficiency resources of process.
118      *
119      * @param resourceInfo Request params.
120      */
121     virtual void OnProcEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo);
122 
123     /**
124      * @brief Called back when the efficiency resources of process reset.
125      *
126      * @param resourceInfo Request params.
127      */
128     virtual void OnProcEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo);
129 
130 private:
131     class BackgroundTaskSubscriberImpl final : public BackgroundTaskSubscriberStub {
132     public:
133         explicit BackgroundTaskSubscriberImpl(BackgroundTaskSubscriber &subscriber);
~BackgroundTaskSubscriberImpl()134         ~BackgroundTaskSubscriberImpl() {}
135 
136         /**
137          * @brief Called back when the subscriber is connected to Background Task Manager Service.
138          */
139         void OnConnected() override;
140 
141         /**
142          * @brief Called back when the subscriber is disconnected from Background Task Manager Service.
143          */
144         void OnDisconnected() override;
145 
146         /**
147          * @brief Called back when a transient task start.
148          *
149          * @param info Transient task app info.
150          */
151         void OnTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info) override;
152 
153         /**
154          * Called back when the app has transient task.
155          *
156          * @param info App info of transient task.
157          **/
158         void OnAppTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info) override;
159 
160         /**
161          * Called back when the app does not have transient task.
162          *
163          * @param info App info transient task .
164          **/
165         void OnAppTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info) override;
166 
167         /**
168          * @brief Called back when a transient task end.
169          *
170          * @param info Transient task app info.
171          */
172         void OnTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info) override;
173 
174         /**
175          * @brief Called back when a continuous task start.
176          *
177          * @param continuousTaskCallbackInfo Continuous task app info.
178          */
179         void OnContinuousTaskStart(
180             const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override;
181 
182         /**
183          * @brief Called back when a continuous task stop.
184          *
185          * @param continuousTaskCallbackInfo Continuous task app info.
186          */
187         void OnContinuousTaskStop(
188             const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override;
189 
190         /**
191          * Called back when the app does not have continuous task.
192          *
193          * @param uid App uid.
194          */
195         void OnAppContinuousTaskStop(int32_t uid) override;
196 
197         /**
198          * @brief Get managed proxy of background tasks.
199          *
200          * @return True if success, else false.
201          */
202         bool GetBackgroundTaskMgrProxy();
203 
204         /**
205          * @brief Apply or unapply efficiency resources of App.
206          *
207          * @param resourceInfo Request params.
208          */
209         void OnAppEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override;
210 
211         /**
212          * @brief Called back when the efficiency resources of App reset.
213          *
214          * @param resourceInfo Request params.
215          */
216         void OnAppEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override;
217 
218         /**
219          * @brief Apply or unapply efficiency resources of process.
220          *
221          * @param resourceInfo Request params.
222          */
223         void OnProcEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override;
224 
225         /**
226          * @brief Called back when the efficiency resources of process reset.
227          *
228          * @param resourceInfo Request params.
229          */
230         void OnProcEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override;
231 
232     public:
233         BackgroundTaskSubscriber &subscriber_;
234         sptr<IBackgroundTaskMgr> proxy_ {nullptr};
235         std::mutex mutex_ {};
236     };
237 
238 private:
239     const sptr<BackgroundTaskSubscriberImpl> GetImpl() const;
240 
241 private:
242     sptr<BackgroundTaskSubscriberImpl> impl_ {nullptr};
243 
244     friend class BackgroundTaskManager;
245 };
246 }  // namespace BackgroundTaskMgr
247 }  // namespace OHOS
248 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_SUBSCRIBER_H