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