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_SUBSCRIBER_H 17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_SUBSCRIBER_H 18 19 #include <iremote_broker.h> 20 21 #include "ibackground_task_mgr.h" 22 #include "background_task_subscriber_stub.h" 23 24 namespace OHOS { 25 namespace BackgroundTaskMgr { 26 class BackgroundTaskSubscriber { 27 public: 28 /** 29 * Default constructor used to create a instance. 30 */ 31 BackgroundTaskSubscriber(); 32 33 /** 34 * Default destructor. 35 */ 36 virtual ~BackgroundTaskSubscriber(); 37 38 /** 39 * Called back when the subscriber is connected to Background Task Manager Service. 40 * @deprecated 41 */ 42 virtual void OnConnected(); 43 44 /** 45 * Called back when the subscriber is disconnected from Background Task Manager Service. 46 * @deprecated 47 */ 48 virtual void OnDisconnected(); 49 50 /** 51 * Called back when a transient task start. 52 * 53 * @param info Transient task app info. 54 **/ 55 virtual void OnTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info); 56 57 /** 58 * Called back when a transient task end. 59 * 60 * @param info Transient task app info. 61 **/ 62 virtual void OnTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info); 63 64 /** 65 * Called back when a transient task err. 66 * 67 * @param info Transient task app info. 68 **/ 69 virtual void OnTransientTaskErr(const std::shared_ptr<TransientTaskAppInfo>& info); 70 71 /** 72 * Called back when the app has transient task. 73 * 74 * @param info App info of transient task. 75 **/ 76 virtual void OnAppTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info); 77 78 /** 79 * Called back when the app does not have transient task. 80 * 81 * @param info App info transient task . 82 **/ 83 virtual void OnAppTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info); 84 85 /** 86 * Called back when a continuous task start. 87 * 88 * @param info Transient task app info. 89 **/ 90 virtual void OnContinuousTaskStart(const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo); 91 92 /** 93 * Called back when a continuous task update. 94 * 95 * @param info Transient task app info. 96 **/ 97 virtual void OnContinuousTaskUpdate(const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo); 98 99 /** 100 * Called back when a continuous task end. 101 * 102 * @param info Transient task app info. 103 **/ 104 virtual void OnContinuousTaskStop(const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo); 105 106 /** 107 * Called back when the app does not have continuous task. 108 * 109 * @param uid App uid. 110 **/ 111 virtual void OnAppContinuousTaskStop(int32_t uid); 112 113 /** 114 * Called back when the Background Task Manager Service has died. 115 */ 116 virtual void OnRemoteDied(const wptr<IRemoteObject> &object); 117 118 /** 119 * @brief Apply or unapply efficiency resources of App. 120 * 121 * @param resourceInfo Request params. 122 */ 123 virtual void OnAppEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo); 124 125 /** 126 * @brief Called back when the efficiency resources of App reset. 127 * 128 * @param resourceInfo Request params. 129 */ 130 virtual void OnAppEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo); 131 132 /** 133 * @brief Apply or unapply efficiency resources of process. 134 * 135 * @param resourceInfo Request params. 136 */ 137 virtual void OnProcEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo); 138 139 /** 140 * @brief Called back when the efficiency resources of process reset. 141 * 142 * @param resourceInfo Request params. 143 */ 144 virtual void OnProcEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo); 145 146 private: 147 class BackgroundTaskSubscriberImpl final : public BackgroundTaskSubscriberStub { 148 public: 149 explicit BackgroundTaskSubscriberImpl(BackgroundTaskSubscriber &subscriber); ~BackgroundTaskSubscriberImpl()150 ~BackgroundTaskSubscriberImpl() {} 151 152 /** 153 * @brief Called back when the subscriber is connected to Background Task Manager Service. 154 */ 155 void OnConnected() override; 156 157 /** 158 * @brief Called back when the subscriber is disconnected from Background Task Manager Service. 159 */ 160 void OnDisconnected() override; 161 162 /** 163 * @brief Called back when a transient task start. 164 * 165 * @param info Transient task app info. 166 */ 167 void OnTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info) override; 168 169 /** 170 * Called back when the app has transient task. 171 * 172 * @param info App info of transient task. 173 **/ 174 void OnAppTransientTaskStart(const std::shared_ptr<TransientTaskAppInfo>& info) override; 175 176 /** 177 * Called back when the app does not have transient task. 178 * 179 * @param info App info transient task . 180 **/ 181 void OnAppTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info) override; 182 183 /** 184 * @brief Called back when a transient task end. 185 * 186 * @param info Transient task app info. 187 */ 188 void OnTransientTaskEnd(const std::shared_ptr<TransientTaskAppInfo>& info) override; 189 190 /** 191 * @brief Called back when a transient task err. 192 * 193 * @param info Transient task app info. 194 */ 195 void OnTransientTaskErr(const std::shared_ptr<TransientTaskAppInfo>& info) override; 196 197 /** 198 * @brief Called back when a continuous task start. 199 * 200 * @param continuousTaskCallbackInfo Continuous task app info. 201 */ 202 void OnContinuousTaskStart( 203 const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override; 204 /** 205 * @brief Called back when a continuous task update. 206 * 207 * @param continuousTaskCallbackInfo Continuous task app info. 208 */ 209 void OnContinuousTaskUpdate( 210 const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override; 211 212 /** 213 * @brief Called back when a continuous task stop. 214 * 215 * @param continuousTaskCallbackInfo Continuous task app info. 216 */ 217 void OnContinuousTaskStop( 218 const std::shared_ptr<ContinuousTaskCallbackInfo> &continuousTaskCallbackInfo) override; 219 220 /** 221 * Called back when the app does not have continuous task. 222 * 223 * @param uid App uid. 224 */ 225 void OnAppContinuousTaskStop(int32_t uid) override; 226 227 /** 228 * @brief Apply or unapply efficiency resources of App. 229 * 230 * @param resourceInfo Request params. 231 */ 232 void OnAppEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override; 233 234 /** 235 * @brief Called back when the efficiency resources of App reset. 236 * 237 * @param resourceInfo Request params. 238 */ 239 void OnAppEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override; 240 241 /** 242 * @brief Apply or unapply efficiency resources of process. 243 * 244 * @param resourceInfo Request params. 245 */ 246 void OnProcEfficiencyResourcesApply(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override; 247 248 /** 249 * @brief Called back when the efficiency resources of process reset. 250 * 251 * @param resourceInfo Request params. 252 */ 253 void OnProcEfficiencyResourcesReset(const std::shared_ptr<ResourceCallbackInfo> &resourceInfo) override; 254 255 public: 256 BackgroundTaskSubscriber &subscriber_; 257 sptr<IBackgroundTaskMgr> proxy_ {nullptr}; 258 std::mutex mutex_ {}; 259 }; 260 261 private: 262 const sptr<BackgroundTaskSubscriberImpl> GetImpl() const; 263 264 private: 265 sptr<BackgroundTaskSubscriberImpl> impl_ {nullptr}; 266 267 friend class BackgroundTaskManager; 268 }; 269 } // namespace BackgroundTaskMgr 270 } // namespace OHOS 271 #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_BACKGROUND_TASK_SUBSCRIBER_H