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_FRAMEWORKS_INCLUDE_IBACKGROUND_TASK_MGR_H
17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_INCLUDE_IBACKGROUND_TASK_MGR_H
18 
19 #include <string>
20 
21 #include <ipc_types.h>
22 #include <iremote_broker.h>
23 #include <nocopyable.h>
24 
25 #include "bgtaskmgr_inner_errors.h"
26 #include "config_data_source_type.h"
27 #include "continuous_task_param.h"
28 #include "delay_suspend_info.h"
29 #include "iexpired_callback.h"
30 #include "ibackground_task_subscriber.h"
31 #include "want_agent.h"
32 #include "efficiency_resource_info.h"
33 
34 namespace OHOS {
35 namespace BackgroundTaskMgr {
36 class IBackgroundTaskMgr : public IRemoteBroker {
37 public:
38     IBackgroundTaskMgr() = default;
39     ~IBackgroundTaskMgr() override = default;
40     DISALLOW_COPY_AND_MOVE(IBackgroundTaskMgr);
41 
42     /**
43      * @brief Request delay suspend for background task.
44      *
45      * @param reason Reason of requesting delay suspend.
46      * @param delayInfo Info of background which request delay suspend.
47      * @return ERR_OK if success, else fail.
48      */
49     virtual ErrCode RequestSuspendDelay(const std::u16string& reason,
50         const sptr<IExpiredCallback>& callback, std::shared_ptr<DelaySuspendInfo> &delayInfo) = 0;
51 
52     /**
53      * @brief Cancel delay suspend of background task.
54      *
55      * @param requestId Id of the requested background task.
56      * @return ERR_OK if success, else fail.
57      */
58     virtual ErrCode CancelSuspendDelay(int32_t requestId) = 0;
59 
60     /**
61      * @brief Get the time remaining before the background tasks enter the suspended state.
62      *
63      * @param requestId Id of the requested background task.
64      * @param delayTime Remaining time.
65      * @return ERR_OK if success, else fail.
66      */
67     virtual ErrCode GetRemainingDelayTime(int32_t requestId, int32_t &delayTime) = 0;
68 
69     /**
70      * @brief Request service to keep running background.
71      *
72      * @param taskParam Request params.
73      * @return ERR_OK if success, else fail.
74      */
75     virtual ErrCode StartBackgroundRunning(const sptr<ContinuousTaskParam> &taskParam) = 0;
76 
77     /**
78      * @brief Request service to update running background.
79      *
80      * @param taskParam Request params.
81      * @return ERR_OK if success, else fail.
82      */
83     virtual ErrCode UpdateBackgroundRunning(const sptr<ContinuousTaskParam> &taskParam) = 0;
84 
85     /**
86      * @brief Request service to keep or stop running background for inner ability.
87      *
88      * @param taskParam Request params.
89      * @return ERR_OK if success, else fail.
90      */
91     virtual ErrCode RequestBackgroundRunningForInner(const sptr<ContinuousTaskParamForInner> &taskParam) = 0;
92 
93     /**
94      * @brief Request service to stop running background.
95      *
96      * @param abilityName Ability name of the requester ability.
97      * @param abilityToken Ability token to mark an unique running ability instance.
98      * @param abilityId Ability identity.
99      * @return ERR_OK if success, else fail.
100      */
101     virtual ErrCode StopBackgroundRunning(const std::string &abilityName, const sptr<IRemoteObject> &abilityToken,
102         int32_t abilityId) = 0;
103 
104     /**
105      * @brief Subscribes background task event.
106      *
107      * @param subscriber Subscriber token.
108      * @return ERR_OK if success, else fail.
109      */
110     virtual ErrCode SubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber> &subscriber) = 0;
111 
112     /**
113      * @brief Unsubscribes background task event.
114      *
115      * @param subscriber Subscriber token.
116      * @return ERR_OK if success, else fail.
117      */
118     virtual ErrCode UnsubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber> &subscriber) = 0;
119 
120     /**
121      * @brief Get transient task applications.
122      * @param list transient task apps.
123      * @return Returns ERR_OK if success, else failure.
124      */
125     virtual ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list) = 0;
126 
127     /**
128      * @brief Pause transient task time by uid for inner ability.
129      * @param uid app uid.
130      * @return Returns ERR_OK if success, else failure.
131      */
132     virtual ErrCode PauseTransientTaskTimeForInner(int32_t uid) = 0;
133 
134     /**
135      * @brief Start transient task time by uid for inner ability.
136      * @param uid app uid.
137      * @return Returns ERR_OK if success, else failure.
138      */
139     virtual ErrCode StartTransientTaskTimeForInner(int32_t uid) = 0;
140 
141     /**
142      * @brief Get all continuous task running infos.
143      * @param list continuous task infos.
144      * @return Returns ERR_OK if success, else failure.
145      */
146     virtual ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list) = 0;
147 
148     /**
149      * @brief Apply or unapply efficiency resources.
150      *
151      * @param resourceInfo Request params.
152      * @return Returns ERR_OK on success, others on failure.
153      */
154     virtual ErrCode ApplyEfficiencyResources(const sptr<EfficiencyResourceInfo> &resourceInfo) = 0;
155 
156     /**
157      * @brief Reset all efficiency resources apply.
158      *
159      * @return ERR_OK if success, else fail.
160      */
161     virtual ErrCode ResetAllEfficiencyResources() = 0;
162 
163     /**
164      * @brief Get all effficiency resources running infos.
165      * @param appList EFficiency Resources infos of apps.
166      * @param procList  EFficiency Resources infos of processes.
167      * @return Returns ERR_OK on success, others on failure.
168      */
169     virtual ErrCode GetEfficiencyResourcesInfos(std::vector<std::shared_ptr<ResourceCallbackInfo>> &appList,
170         std::vector<std::shared_ptr<ResourceCallbackInfo>> &procList) = 0;
171 
172     /**
173      * @brief Request stop continuous task.
174      * @param uid app uid.
175      * @param pid app pid.
176      * @param taskType continuous task type.
177      * @param key continuous task key.
178      * @return Returns ERR_OK if success, else failure.
179      */
180     virtual ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key) = 0;
181 
182     /**
183      * @brief Set background task config.
184      * @param configData config param.
185      * @param sourceType data source.
186      * @return Returns ERR_OK if success, else failure.
187      */
188     virtual ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType) = 0;
189 
190 public:
191     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IBackgroundTaskMgr");
192 };
193 }  // namespace BackgroundTaskMgr
194 }  // namespace OHOS
195 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_INCLUDE_IBACKGROUND_TASK_MGR_H
196 
197