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