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 keep or stop running background for inner ability. 71 * 72 * @param taskParam Request params. 73 * @return ERR_OK if success, else fail. 74 */ 75 ErrCode RequestBackgroundRunningForInner(const sptr<ContinuousTaskParamForInner> &taskParam) override; 76 77 /** 78 * @brief Request service to stop running background. 79 * 80 * @param abilityName Ability name of the requester ability. 81 * @param abilityToken Ability token to mark an unique running ability instance. 82 * @return ERR_OK if success, else fail. 83 */ 84 ErrCode StopBackgroundRunning(const std::string &abilityName, const sptr<IRemoteObject> &abilityToken) override; 85 86 /** 87 * @brief Subscribes background task event. 88 * 89 * @param subscriber Subscriber token. 90 * @return ERR_OK if success, else fail. 91 */ 92 ErrCode SubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber>& subscriber) override; 93 94 /** 95 * @brief Unsubscribes background task event. 96 * 97 * @param subscriber Subscriber token. 98 * @return ERR_OK if success, else fail. 99 */ 100 ErrCode UnsubscribeBackgroundTask(const sptr<IBackgroundTaskSubscriber>& subscriber) override; 101 102 /** 103 * @brief Get transient task applications. 104 * @param list transient task apps. 105 * @return Returns ERR_OK if success, else failure. 106 */ 107 ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list) override; 108 109 /** 110 * @brief Get all continuous task running infos. 111 * @param list continuous task infos. 112 * @return Returns ERR_OK if success, else failure. 113 */ 114 ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list) override; 115 116 /** 117 * @brief Apply or unapply efficiency resources. 118 * 119 * @param resourceInfo Request params. 120 * @return Returns ERR_OK on success, others on failure. 121 */ 122 ErrCode ApplyEfficiencyResources(const sptr<EfficiencyResourceInfo> &resourceInfo) override; 123 124 /** 125 * @brief Reset all efficiency resources. 126 * 127 * @return ERR_OK if success, else fail. 128 */ 129 ErrCode ResetAllEfficiencyResources() override; 130 131 /** 132 * @brief Get all effficiency resources running infos. 133 * @param appList EFficiency Resources infos of apps. 134 * @param procList EFficiency Resources infos of processes. 135 * @return Returns ERR_OK on success, others on failure. 136 */ 137 ErrCode GetEfficiencyResourcesInfos(std::vector<std::shared_ptr<ResourceCallbackInfo>> &appList, 138 std::vector<std::shared_ptr<ResourceCallbackInfo>> &procList) override; 139 140 /** 141 * @brief Request stop continuous task. 142 * @param uid app uid. 143 * @param pid app pid. 144 * @param taskType continuous task type. 145 * @return Returns ERR_OK if success, else failure. 146 */ 147 ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType) override; 148 149 private: 150 ErrCode InnerTransact(uint32_t code, MessageOption &flags, MessageParcel &data, MessageParcel &reply); 151 152 static inline BrokerDelegator<BackgroundTaskMgrProxy> delegator_; 153 }; 154 } // namespace BackgroundTaskMgr 155 } // namespace OHOS 156 #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_FRAMEWORKS_INCLUDE_BACKGROUND_TASK_MGR_PROXY_H 157