• 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 #include "continuous_task_callback_info.h"
17 #include "string_ex.h"
18 #include "continuous_task_log.h"
19 #include "ipc_util.h"
20 
21 namespace OHOS {
22 namespace BackgroundTaskMgr {
ContinuousTaskCallbackInfo()23 ContinuousTaskCallbackInfo::ContinuousTaskCallbackInfo() {}
24 
GetTypeId() const25 uint32_t ContinuousTaskCallbackInfo::GetTypeId() const
26 {
27     return typeId_;
28 }
29 
GetTypeIds() const30 const std::vector<uint32_t>& ContinuousTaskCallbackInfo::GetTypeIds() const
31 {
32     return typeIds_;
33 }
34 
IsBatchApi() const35 bool ContinuousTaskCallbackInfo::IsBatchApi() const
36 {
37     return isBatchApi_;
38 }
39 
GetAbilityId() const40 int32_t ContinuousTaskCallbackInfo::GetAbilityId() const
41 {
42     return abilityId_;
43 }
44 
GetCreatorUid() const45 int32_t ContinuousTaskCallbackInfo::GetCreatorUid() const
46 {
47     return creatorUid_;
48 }
49 
GetCreatorPid() const50 pid_t ContinuousTaskCallbackInfo::GetCreatorPid() const
51 {
52     return creatorPid_;
53 }
54 
GetAbilityName() const55 std::string ContinuousTaskCallbackInfo::GetAbilityName() const
56 {
57     return abilityName_;
58 }
59 
IsFromWebview() const60 bool ContinuousTaskCallbackInfo::IsFromWebview() const
61 {
62     return isFromWebview_;
63 }
64 
GetTokenId() const65 uint64_t ContinuousTaskCallbackInfo::GetTokenId() const
66 {
67     return tokenId_;
68 }
69 
SetContinuousTaskId(const int32_t id)70 void ContinuousTaskCallbackInfo::SetContinuousTaskId(const int32_t id)
71 {
72     continuousTaskId_ = id;
73 }
74 
SetCancelReason(const int32_t reason)75 void ContinuousTaskCallbackInfo::SetCancelReason(const int32_t reason)
76 {
77     cancelReason_ = reason;
78 }
79 
SetSuspendReason(const int32_t suspendReason)80 void ContinuousTaskCallbackInfo::SetSuspendReason(const int32_t suspendReason)
81 {
82     suspendReason_ = suspendReason;
83 }
84 
SetSuspendState(const bool suspendState)85 void ContinuousTaskCallbackInfo::SetSuspendState(const bool suspendState)
86 {
87     suspendState_ = suspendState;
88 }
89 
GetContinuousTaskId() const90 int32_t ContinuousTaskCallbackInfo::GetContinuousTaskId() const
91 {
92     return continuousTaskId_;
93 }
94 
GetCancelReason() const95 int32_t ContinuousTaskCallbackInfo::GetCancelReason() const
96 {
97     return cancelReason_;
98 }
99 
GetSuspendReason() const100 int32_t ContinuousTaskCallbackInfo::GetSuspendReason() const
101 {
102     return suspendReason_;
103 }
104 
GetSuspendState() const105 bool ContinuousTaskCallbackInfo::GetSuspendState() const
106 {
107     return suspendState_;
108 }
109 
Marshalling(Parcel & parcel) const110 bool ContinuousTaskCallbackInfo::Marshalling(Parcel &parcel) const
111 {
112     WRITE_PARCEL_WITH_RET(parcel, Uint32, typeId_, false);
113     WRITE_PARCEL_WITH_RET(parcel, Int32, creatorUid_, false);
114     WRITE_PARCEL_WITH_RET(parcel, Int32, creatorPid_, false);
115     WRITE_PARCEL_WITH_RET(parcel, Bool, isFromWebview_, false);
116     std::u16string u16AbilityName = Str8ToStr16(abilityName_);
117     WRITE_PARCEL_WITH_RET(parcel, String16, u16AbilityName, false);
118     WRITE_PARCEL_WITH_RET(parcel, Bool, isBatchApi_, false);
119     WRITE_PARCEL_WITH_RET(parcel, UInt32Vector, typeIds_, false);
120     WRITE_PARCEL_WITH_RET(parcel, Int32, abilityId_, false);
121     WRITE_PARCEL_WITH_RET(parcel, Uint64, tokenId_, false);
122     WRITE_PARCEL_WITH_RET(parcel, Int32, continuousTaskId_, false);
123     WRITE_PARCEL_WITH_RET(parcel, Int32, cancelReason_, false);
124     WRITE_PARCEL_WITH_RET(parcel, Bool, suspendState_, false);
125     WRITE_PARCEL_WITH_RET(parcel, Int32, suspendReason_, false);
126     return true;
127 }
128 
Unmarshalling(Parcel & parcel)129 ContinuousTaskCallbackInfo *ContinuousTaskCallbackInfo::Unmarshalling(Parcel &parcel)
130 {
131     auto object = new (std::nothrow) ContinuousTaskCallbackInfo();
132     if ((object != nullptr) && !object->ReadFromParcel(parcel)) {
133         delete object;
134         object = nullptr;
135     }
136 
137     return object;
138 }
139 
ReadFromParcel(Parcel & parcel)140 bool ContinuousTaskCallbackInfo::ReadFromParcel(Parcel &parcel)
141 {
142     READ_PARCEL_WITH_RET(parcel, Uint32, typeId_, false);
143     READ_PARCEL_WITH_RET(parcel, Int32, creatorUid_, false);
144     READ_PARCEL_WITH_RET(parcel, Int32, creatorPid_, false);
145     READ_PARCEL_WITH_RET(parcel, Bool, isFromWebview_, false);
146     std::u16string u16AbilityName;
147     READ_PARCEL_WITH_RET(parcel, String16, u16AbilityName, false);
148     abilityName_ = Str16ToStr8(u16AbilityName);
149     READ_PARCEL_WITH_RET(parcel, Bool, isBatchApi_, false);
150     READ_PARCEL_WITH_RET(parcel, UInt32Vector, (&typeIds_), false);
151     READ_PARCEL_WITH_RET(parcel, Int32, abilityId_, false);
152     READ_PARCEL_WITH_RET(parcel, Uint64, tokenId_, false);
153     READ_PARCEL_WITH_RET(parcel, Int32, continuousTaskId_, false);
154     READ_PARCEL_WITH_RET(parcel, Int32, cancelReason_, false);
155     READ_PARCEL_WITH_RET(parcel, Bool, suspendState_, false);
156     READ_PARCEL_WITH_RET(parcel, Int32, suspendReason_, false);
157     return true;
158 }
159 }  // namespace BackgroundTaskMgr
160 }  // namespace OHOS