• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 Get the cancel reason.
108      *
109      * @return The reason.
110      */
111     void SetContinuousTaskId(const int32_t id);
112 
113     /**
114      * @brief Set the cancel reasion.
115      *
116      * @param reason The the cancel reasion.
117      */
118     int32_t GetCancelReason() const;
119 
120     /**
121      * @brief Set the continuous task id.
122      *
123      * @param id The continuous task id.
124      */
125     void SetCancelReason(const int32_t reason);
126 
127     /**
128      * @brief Marshals a purpose into a parcel.
129      *
130      * @param parcel Indicates the parcel object for marshalling.
131      * @return True if success, else false.
132      */
133     bool Marshalling(Parcel &parcel) const override;
134     static ContinuousTaskCallbackInfo *Unmarshalling(Parcel &parcel);
135 
136 private:
137     bool ReadFromParcel(Parcel &parcel);
138 
139 private:
140     uint32_t typeId_ {0};
141     int32_t creatorUid_ {0};
142     pid_t creatorPid_ {0};
143     std::string abilityName_ {""};
144     bool isFromWebview_ {false};
145     bool isBatchApi_ {false};
146     std::vector<uint32_t> typeIds_ {};
147     int32_t abilityId_ {-1};
148     uint64_t tokenId_ {0};
149     int32_t continuousTaskId_ {-1};
150     int32_t cancelReason_ {-1};
151 };
152 }  // namespace BackgroundTaskMgr
153 }  // namespace OHOS
154 #endif  // FOUNDATION_RESOURCESCHEDULE_BACKGROUND_TASK_MGR_INTERFACES_INNERKITS_INCLUDE_LONGTIME_TASK_EVENT_DATA_H