• 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 stop running background.
78      *
79      * @param abilityName Ability name of the requester ability.
80      * @param abilityToken Ability token to mark an unique running ability instance.
81      * @return ERR_OK if success, else fail.
82      */
83     virtual ErrCode StopBackgroundRunning(const std::string &abilityName, const sptr<IRemoteObject> &abilityToken) = 0;
84 
85     /**
86      * @brief Subscribes background task event.
87      *
88      * @param subscriber Subscriber token.
89      * @return ERR_OK if success, else fail.
90      */
91     virtual ErrCode SubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber> &subscriber) = 0;
92 
93     /**
94      * @brief Unsubscribes background task event.
95      *
96      * @param subscriber Subscriber token.
97      * @return ERR_OK if success, else fail.
98      */
99     virtual ErrCode UnsubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber> &subscriber) = 0;
100 
101     /**
102      * @brief Get transient task applications.
103      * @param list transient task apps.
104      * @return Returns ERR_OK if success, else failure.
105      */
106     virtual ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list) = 0;
107 
108     /**
109      * @brief Get all continuous task running infos.
110      * @param list continuous task infos.
111      * @return Returns ERR_OK if success, else failure.
112      */
113     virtual ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list) = 0;
114 
115     /**
116      * @brief Apply or unapply efficiency resources.
117      *
118      * @param resourceInfo Request params.
119      * @return Returns ERR_OK on success, others on failure.
120      */
121     virtual ErrCode ApplyEfficiencyResources(const sptr<EfficiencyResourceInfo> &resourceInfo) = 0;
122 
123     /**
124      * @brief Reset all efficiency resources apply.
125      *
126      * @return ERR_OK if success, else fail.
127      */
128     virtual ErrCode ResetAllEfficiencyResources() = 0;
129 
130     /**
131      * @brief Get all effficiency resources running infos.
132      * @param appList EFficiency Resources infos of apps.
133      * @param procList  EFficiency Resources infos of processes.
134      * @return Returns ERR_OK on success, others on failure.
135      */
136     virtual ErrCode GetEfficiencyResourcesInfos(std::vector<std::shared_ptr<ResourceCallbackInfo>> &appList,
137         std::vector<std::shared_ptr<ResourceCallbackInfo>> &procList) = 0;
138 
139     /**
140      * @brief Request stop continuous task.
141      * @param uid app uid.
142      * @param pid app pid.
143      * @param taskType continuous task type.
144      * @return Returns ERR_OK if success, else failure.
145      */
146     virtual ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType) = 0;
147 
148 public:
149     DECLARE_INTERFACE_DESCRIPTOR(u"ohos.resourceschedule.IBackgroundTaskMgr");
150 
151 protected:
152     enum InterfaceId : uint32_t {
153         REQUEST_SUSPEND_DELAY = MIN_TRANSACTION_ID,
154         CANCEL_SUSPEND_DELAY,
155         GET_REMAINING_DELAY_TIME,
156         START_BACKGROUND_RUNNING,
157         STOP_BACKGROUND_RUNNING,
158         SUBSCRIBE_BACKGROUND_TASK,
159         UNSUBSCRIBE_BACKGROUND_TASK,
160         GET_TRANSIENT_TASK_APPS,
161         GET_CONTINUOUS_TASK_APPS,
162         APPLY_EFFICIENCY_RESOURCES,
163         RESET_ALL_EFFICIENCY_RESOURCES,
164         GET_EFFICIENCY_RESOURCES_INFOS,
165         STOP_CONTINUOUS_TASK,
166     };
167 };
168 }  // namespace BackgroundTaskMgr
169 }  // namespace OHOS
170 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_INCLUDE_IBACKGROUND_TASK_MGR_H
171