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