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
GetContinuousTaskId() const80 int32_t ContinuousTaskCallbackInfo::GetContinuousTaskId() const
81 {
82 return continuousTaskId_;
83 }
84
GetCancelReason() const85 int32_t ContinuousTaskCallbackInfo::GetCancelReason() const
86 {
87 return cancelReason_;
88 }
89
Marshalling(Parcel & parcel) const90 bool ContinuousTaskCallbackInfo::Marshalling(Parcel &parcel) const
91 {
92 WRITE_PARCEL_WITH_RET(parcel, Uint32, typeId_, false);
93 WRITE_PARCEL_WITH_RET(parcel, Int32, creatorUid_, false);
94 WRITE_PARCEL_WITH_RET(parcel, Int32, creatorPid_, false);
95 WRITE_PARCEL_WITH_RET(parcel, Bool, isFromWebview_, false);
96 std::u16string u16AbilityName = Str8ToStr16(abilityName_);
97 WRITE_PARCEL_WITH_RET(parcel, String16, u16AbilityName, false);
98 WRITE_PARCEL_WITH_RET(parcel, Bool, isBatchApi_, false);
99 WRITE_PARCEL_WITH_RET(parcel, UInt32Vector, typeIds_, false);
100 WRITE_PARCEL_WITH_RET(parcel, Int32, abilityId_, false);
101 WRITE_PARCEL_WITH_RET(parcel, Uint64, tokenId_, false);
102 WRITE_PARCEL_WITH_RET(parcel, Int32, continuousTaskId_, false);
103 WRITE_PARCEL_WITH_RET(parcel, Int32, cancelReason_, false);
104 return true;
105 }
106
Unmarshalling(Parcel & parcel)107 ContinuousTaskCallbackInfo *ContinuousTaskCallbackInfo::Unmarshalling(Parcel &parcel)
108 {
109 auto object = new (std::nothrow) ContinuousTaskCallbackInfo();
110 if ((object != nullptr) && !object->ReadFromParcel(parcel)) {
111 delete object;
112 object = nullptr;
113 }
114
115 return object;
116 }
117
ReadFromParcel(Parcel & parcel)118 bool ContinuousTaskCallbackInfo::ReadFromParcel(Parcel &parcel)
119 {
120 READ_PARCEL_WITH_RET(parcel, Uint32, typeId_, false);
121 READ_PARCEL_WITH_RET(parcel, Int32, creatorUid_, false);
122 READ_PARCEL_WITH_RET(parcel, Int32, creatorPid_, false);
123 READ_PARCEL_WITH_RET(parcel, Bool, isFromWebview_, false);
124 std::u16string u16AbilityName;
125 READ_PARCEL_WITH_RET(parcel, String16, u16AbilityName, false);
126 abilityName_ = Str16ToStr8(u16AbilityName);
127 READ_PARCEL_WITH_RET(parcel, Bool, isBatchApi_, false);
128 READ_PARCEL_WITH_RET(parcel, UInt32Vector, (&typeIds_), false);
129 READ_PARCEL_WITH_RET(parcel, Int32, abilityId_, false);
130 READ_PARCEL_WITH_RET(parcel, Uint64, tokenId_, false);
131 READ_PARCEL_WITH_RET(parcel, Int32, continuousTaskId_, false);
132 READ_PARCEL_WITH_RET(parcel, Int32, cancelReason_, false);
133 return true;
134 }
135 } // namespace BackgroundTaskMgr
136 } // namespace OHOS