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_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_MGR_HELPER_H 17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_MGR_HELPER_H 18 19 #include "background_task_subscriber.h" 20 #include "efficiency_resource_info.h" 21 #include "bgtaskmgr_inner_errors.h" 22 23 namespace OHOS { 24 namespace BackgroundTaskMgr { 25 class BackgroundTaskMgrHelper { 26 public: 27 /** 28 * @brief Request service to keep running background 29 * 30 * @param taskParam Request params. 31 * @return ERR_OK if success, else fail. 32 */ 33 static ErrCode RequestStartBackgroundRunning(ContinuousTaskParam &taskParam); 34 35 /** 36 * @brief Request service to update running background 37 * 38 * @param taskParam Request params. 39 * @return ERR_OK if success, else fail. 40 */ 41 static ErrCode RequestUpdateBackgroundRunning(ContinuousTaskParam &taskParam); 42 43 /** 44 * @brief Request service to keep or stop running background for inner ability. 45 * 46 * @param taskParam Request params. 47 * @return ERR_OK if success, else fail. 48 */ 49 static ErrCode RequestBackgroundRunningForInner(const ContinuousTaskParamForInner &taskParam); 50 51 /** 52 * @brief Request service to stop running background 53 * 54 * @param abilityName Ability name of the requester ability 55 * @param abilityToken Ability token to mark an unique running ability instance 56 * @param abilityId Ability identity 57 * @return ERR_OK if success, else fail. 58 */ 59 static ErrCode RequestStopBackgroundRunning(const std::string &abilityName, 60 const sptr<IRemoteObject> &abilityToken, int32_t abilityId = -1); 61 62 /** 63 * @brief Subscribes background task event. 64 * 65 * @param subscriber Subscriber token. 66 * @return ERR_OK if success, else fail. 67 */ 68 static ErrCode SubscribeBackgroundTask(const BackgroundTaskSubscriber &subscriber); 69 70 /** 71 * @brief Unsubscribes background task event. 72 * 73 * @param subscriber Subscriber token. 74 * @return ERR_OK if success, else fail. 75 */ 76 static ErrCode UnsubscribeBackgroundTask(const BackgroundTaskSubscriber &subscriber); 77 78 /** 79 * @brief Get transient task applications. 80 * @param list transient task apps. 81 * @return Returns ERR_OK if success, else failure. 82 */ 83 static ErrCode GetTransientTaskApps(std::vector<std::shared_ptr<TransientTaskAppInfo>> &list); 84 85 /** 86 * @brief Pause transient task time by uid for inner ability. 87 * @param uid app uid. 88 * @return Returns ERR_OK if success, else failure. 89 */ 90 static ErrCode PauseTransientTaskTimeForInner(int32_t uid); 91 92 /** 93 * @brief Start transient task time by uid for inner ability. 94 * @param uid app uid. 95 * @return Returns ERR_OK if success, else failure. 96 */ 97 static ErrCode StartTransientTaskTimeForInner(int32_t uid); 98 99 /** 100 * @brief Get all continuous task running infos. 101 * @param list continuous task infos. 102 * @return Returns ERR_OK if success, else failure. 103 */ 104 static ErrCode GetContinuousTaskApps(std::vector<std::shared_ptr<ContinuousTaskCallbackInfo>> &list); 105 106 /** 107 * @brief Get all effficiency resources running infos. 108 * @param appList EFficiency Resources infos of apps. 109 * @param procList EFficiency Resources infos of processes. 110 * @return Returns ERR_OK on success, others on failure. 111 */ 112 static ErrCode GetEfficiencyResourcesInfos(std::vector<std::shared_ptr<ResourceCallbackInfo>> &appList, 113 std::vector<std::shared_ptr<ResourceCallbackInfo>> &procList); 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 static ErrCode ApplyEfficiencyResources(const EfficiencyResourceInfo &resourceInfo); 122 123 /** 124 * @brief Reset all efficiency resources. 125 * 126 * @return ERR_OK if success, else fail. 127 */ 128 static ErrCode ResetAllEfficiencyResources(); 129 130 /** 131 * @brief Request stop continuous task. 132 * @param uid app uid. 133 * @param pid app pid. 134 * @param taskType continuous task type. 135 * @return Returns ERR_OK if success, else failure. 136 */ 137 static ErrCode StopContinuousTask(int32_t uid, int32_t pid, uint32_t taskType, const std::string &key); 138 139 /** 140 * @brief Set background task config. 141 * @param configData config param. 142 * @param sourceType data source. 143 * @return Returns ERR_OK if success, else failure. 144 */ 145 static ErrCode SetBgTaskConfig(const std::string &configData, int32_t sourceType); 146 }; 147 } // namespace BackgroundTaskMgr 148 } // namespace OHOS 149 #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_MGR_HELPER_H