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_LONGTIME_TASK_EVENT_DATA_H 17 #define FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_LONGTIME_TASK_EVENT_DATA_H 18 19 #include <cstdint> 20 #include <sys/types.h> 21 #include <string> 22 #include "parcel.h" 23 24 namespace OHOS { 25 namespace BackgroundTaskMgr { 26 class ContinuousTaskCallbackInfo : public Parcelable { 27 public: 28 ContinuousTaskCallbackInfo(); 29 ContinuousTaskCallbackInfo(uint32_t typeId, int32_t creatorUid, 30 pid_t creatorPid, std::string abilityName, bool isFromWebview = false, bool isBatchApi = false, 31 const std::vector<uint32_t> &typeIds = {}, int32_t abilityId = -1, uint64_t tokenId = 0) typeId_(typeId)32 : typeId_(typeId), creatorUid_(creatorUid), creatorPid_(creatorPid), abilityName_(abilityName), 33 isFromWebview_(isFromWebview), isBatchApi_(isBatchApi), typeIds_(typeIds), abilityId_(abilityId), 34 tokenId_(tokenId) {} 35 36 /** 37 * @brief Get the id of type. 38 * 39 * @return The id of type. 40 */ 41 uint32_t GetTypeId() const; 42 43 /** 44 * @brief Get the uid of notification creator. 45 * 46 * @return The uid of the notification creator. 47 */ 48 int32_t GetCreatorUid() const; 49 50 /** 51 * @brief Get the pid of notification creator. 52 * 53 * @return The pid of the notification creator. 54 */ 55 pid_t GetCreatorPid() const; 56 57 /** 58 * @brief Get the name of ability. 59 * 60 * @return The name of ability. 61 */ 62 std::string GetAbilityName() const; 63 64 /** 65 * @brief Judge whether this ability come from webview. 66 * 67 * @return True if success, else false. 68 */ 69 bool IsFromWebview() const; 70 71 /** 72 * @brief Get the id of types. 73 * 74 * @return The id of types. 75 */ 76 const std::vector<uint32_t>& GetTypeIds() const; 77 78 /** 79 * @brief Get the batch api flag. 80 * 81 * @return The flag of batch api. 82 */ 83 bool IsBatchApi() const; 84 85 /** 86 * @brief Get the id of ability. 87 * 88 * @return The id of ability. 89 */ 90 int32_t GetAbilityId() const; 91 92 /** 93 * @brief Get the tokenId. 94 * 95 * @return The tokenId. 96 */ 97 uint64_t GetTokenId() const; 98 99 /** 100 * @brief Get the continuous task id. 101 * 102 * @return The id. 103 */ 104 int32_t GetContinuousTaskId() const; 105 106 /** 107 * @brief Set the continuous task id. 108 * 109 * @param id The continuous task id. 110 */ 111 void SetContinuousTaskId(const int32_t id); 112 113 /** 114 * @brief Get the cancel reason. 115 * 116 * @return The cancel reason. 117 */ 118 int32_t GetCancelReason() const; 119 120 /** 121 * @brief Set the cancel reasond. 122 * 123 * @param reason The cancel reason. 124 */ 125 void SetCancelReason(const int32_t reason); 126 127 /** 128 * @brief Get the suspend reason. 129 * 130 * @return The suspend reason. 131 */ 132 int32_t GetSuspendReason() const; 133 134 /** 135 * @brief Set the suspend reason. 136 * 137 * @param suspendReason The suspend reason. 138 */ 139 void SetSuspendReason(const int32_t suspendReason); 140 141 /** 142 * @brief Get the suspend state. 143 * 144 * @return The suspend state. 145 */ 146 bool GetSuspendState() const; 147 148 /** 149 * @brief Set the suspend state. 150 * 151 * @param suspendState The suspend state. 152 */ 153 void SetSuspendState(const bool suspendState); 154 155 /** 156 * @brief Marshals a purpose into a parcel. 157 * 158 * @param parcel Indicates the parcel object for marshalling. 159 * @return True if success, else false. 160 */ 161 bool Marshalling(Parcel &parcel) const override; 162 static ContinuousTaskCallbackInfo *Unmarshalling(Parcel &parcel); 163 164 private: 165 bool ReadFromParcel(Parcel &parcel); 166 167 private: 168 uint32_t typeId_ {0}; 169 int32_t creatorUid_ {0}; 170 pid_t creatorPid_ {0}; 171 std::string abilityName_ {""}; 172 bool isFromWebview_ {false}; 173 bool isBatchApi_ {false}; 174 std::vector<uint32_t> typeIds_ {}; 175 int32_t abilityId_ {-1}; 176 uint64_t tokenId_ {0}; 177 int32_t continuousTaskId_ {-1}; 178 int32_t cancelReason_ {-1}; 179 bool suspendState_ {false}; 180 int32_t suspendReason_ {-1}; 181 }; 182 } // namespace BackgroundTaskMgr 183 } // namespace OHOS 184 #endif // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_LONGTIME_TASK_EVENT_DATA_H