• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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_MGR_HELPER_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_MGR_HELPER_H
18 
19 #include "background_task_subscriber.h"
20 #include "efficiency_resource_info.h"
21 #include "bgtaskmgr_inner_errors.h"
22 
23 namespace OHOS {
24 namespace BackgroundTaskMgr {
25 class BackgroundTaskMgrHelper {
26 public:
27     /**
28      * @brief Request service to keep running background
29      *
30      * @param taskParam Request params.
31      * @return ERR_OK if success, else fail.
32      */
33     static ErrCode RequestStartBackgroundRunning(ContinuousTaskParam &taskParam);
34 
35     /**
36      * @brief Request service to update running background
37      *
38      * @param taskParam Request params.
39      * @return ERR_OK if success, else fail.
40      */
41     static ErrCode RequestUpdateBackgroundRunning(ContinuousTaskParam &taskParam);
42 
43     /**
44      * @brief Request service to keep or stop running background for inner ability.
45      *
46      * @param taskParam Request params.
47      * @return ERR_OK if success, else fail.
48      */
49     static ErrCode RequestBackgroundRunningForInner(const ContinuousTaskParamForInner &taskParam);
50 
51     /**
52      * @brief Request service to get continuous task info by uid for inner ability.
53      *
54      * @param uid app uid.
55      * @param list continuous task info list.
56      * @return ERR_OK if success, else fail.
57      */
58     static ErrCode RequestGetContinuousTasksByUidForInner(int32_t uid,
59         std::vector<std::shared_ptr<ContinuousTaskInfo>> &list);
60 
61     /**
62      * @brief Request service to get all continuous task info.
63      *
64      * @param list continuous task info list.
65      * @return ERR_OK if success, else fail.
66      */
67     static ErrCode RequestGetAllContinuousTasks(std::vector<std::shared_ptr<ContinuousTaskInfo>> &list);
68 
69     /**
70      * @brief Request service to get all continuous task info.
71      *
72      * @param list continuous task info list.
73      * @param includeSuspended whether include suspended continuous task.
74      * @return ERR_OK if success, else fail.
75      */
76     static ErrCode RequestGetAllContinuousTasks(
77         std::vector<std::shared_ptr<ContinuousTaskInfo>> &list, bool includeSuspended);
78 
79     /**
80      * @brief Request service to stop running background
81      *
82      * @param abilityName Ability name of the requester ability
83      * @param abilityToken Ability token to mark an unique running ability instance
84      * @param abilityId Ability identity
85      * @return ERR_OK if success, else fail.
86      */
87     static ErrCode RequestStopBackgroundRunning(const std::string &abilityName,
88         const sptr<IRemoteObject> &abilityToken, int32_t abilityId = -1);
89 
90     /**
91      * @brief Subscribes background task event.
92      *
93      * @param subscriber Subscriber token.
94      * @return ERR_OK if success, else fail.
95      */
96     static ErrCode SubscribeBackgroundTask(const BackgroundTaskSubscriber &subscriber);
97 
98     /**
99      * @brief Unsubscribes background task event.
100      *
101      * @param subscriber Subscriber token.
102      * @return ERR_OK if success, else fail.
103      */
104     static ErrCode UnsubscribeBackgroundTask(const BackgroundTaskSubscriber &subscriber);
105 
106     /**
107      * @brief Get transient task applications.
108      * @param list transient task apps.
109      * @return Returns ERR_OK if success, else failure.
110      */
111     static ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list);
112 
113     /**
114      * @brief Pause transient task time by uid for inner ability.
115      * @param uid app uid.
116      * @return Returns ERR_OK if success, else failure.
117      */
118     static ErrCode PauseTransientTaskTimeForInner(int32_t uid);
119 
120     /**
121      * @brief Start transient task time by uid for inner ability.
122      * @param uid app uid.
123      * @return Returns ERR_OK if success, else failure.
124      */
125     static ErrCode StartTransientTaskTimeForInner(int32_t uid);
126 
127     /**
128      * @brief Get all continuous task running infos.
129      * @param list continuous task infos.
130      * @return Returns ERR_OK if success, else failure.
131      */
132     static ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list);
133 
134     /**
135      * @brief Get all effficiency resources running infos.
136      * @param appList EFficiency Resources infos of apps.
137      * @param procList  EFficiency Resources infos of processes.
138      * @return Returns ERR_OK on success, others on failure.
139      */
140     static ErrCode GetEfficiencyResourcesInfos(std::vector<std::shared_ptr<ResourceCallbackInfo>> &appList,
141         std::vector<std::shared_ptr<ResourceCallbackInfo>> &procList);
142 
143     /**
144      * @brief Apply or unapply efficiency resources.
145      *
146      * @param resourceInfo Request params.
147      * @return Returns ERR_OK on success, others on failure.
148      */
149     static ErrCode ApplyEfficiencyResources(const EfficiencyResourceInfo &resourceInfo);
150 
151     /**
152      * @brief Reset all efficiency resources.
153      *
154      * @return ERR_OK if success, else fail.
155      */
156     static ErrCode ResetAllEfficiencyResources();
157 
158     /**
159      * @brief Request stop continuous task.
160      * @param uid app uid.
161      * @param pid app pid.
162      * @param taskType continuous task type.
163      * @param key continuous task key.
164      * @return Returns ERR_OK if success, else failure.
165      */
166     static ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key);
167 
168     /**
169      * @brief Request suspend continuous task.
170      * @param uid app uid.
171      * @param pid app pid.
172      * @param reason continuous task suspend reason.
173      * @param key continuous task key.
174      * @return Returns ERR_OK if success, else failure.
175      */
176     static ErrCode SuspendContinuousTask(int32_t uid, int32_t pid, int32_t reason, const std::string &key);
177 
178     /**
179      * @brief Request active continuous task.
180      * @param uid app uid.
181      * @param pid app pid.
182      * @param key continuous task key.
183      * @return Returns ERR_OK if success, else failure.
184      */
185     static ErrCode ActiveContinuousTask(int32_t uid, int32_t pid, const std::string &key);
186 
187     /**
188      * @brief AVsession notify update notification.
189      * @param uid app uid.
190      * @param pid app pid.
191      * @param isPublish isPublish notification.
192      * @return Returns ERR_OK if success, else failure.
193      */
194     static ErrCode AVSessionNotifyUpdateNotification(int32_t uid, int32_t pid, bool isPublish = false);
195 
196     /**
197      * @brief Set background task config.
198      * @param configData config param.
199      * @param sourceType data source.
200      * @return Returns ERR_OK if success, else failure.
201      */
202     static ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType);
203 };
204 }  // namespace BackgroundTaskMgr
205 }  // namespace OHOS
206 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_MGR_HELPER_H