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