1 /*
2 * Copyright (c) 2025 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 "notification_operation_info.h"
17
18 #include "ans_log_wrapper.h"
19 #include "message_user.h" // for MessageUser
20 #include "nlohmann/json.hpp" // for json, basic_json<>:...
21 #include "notification_json_convert.h" // for NotificationJsonCon...
22 #include "parcel.h" // for Parcel
23 #include "uri.h" // for Uri
24
25 namespace OHOS {
26 namespace Notification {
27
GetActionName() const28 std::string NotificationOperationInfo::GetActionName() const
29 {
30 return actionName_;
31 }
32
SetActionName(const std::string & actionName)33 void NotificationOperationInfo::SetActionName(const std::string& actionName)
34 {
35 actionName_ = actionName;
36 }
37
GetUserInput() const38 std::string NotificationOperationInfo::GetUserInput() const
39 {
40 return userInput_;
41 }
42
SetUserInput(const std::string & userInput)43 void NotificationOperationInfo::SetUserInput(const std::string& userInput)
44 {
45 userInput_ = userInput;
46 }
47
GetHashCode() const48 std::string NotificationOperationInfo::GetHashCode() const
49 {
50 return hashCode_;
51 }
52
SetHashCode(const std::string & hashCode)53 void NotificationOperationInfo::SetHashCode(const std::string& hashCode)
54 {
55 hashCode_ = hashCode;
56 }
57
GetEventId() const58 std::string NotificationOperationInfo::GetEventId() const
59 {
60 return eventId_;
61 }
62
SetEventId(const std::string & eventId)63 void NotificationOperationInfo::SetEventId(const std::string& eventId)
64 {
65 eventId_ = eventId;
66 }
67
GetOperationType() const68 OperationType NotificationOperationInfo::GetOperationType() const
69 {
70 return operationType_;
71 }
72
SetOperationType(const OperationType & operationType)73 void NotificationOperationInfo::SetOperationType(const OperationType& operationType)
74 {
75 operationType_ = operationType;
76 }
77
GetBtnIndex() const78 int32_t NotificationOperationInfo::GetBtnIndex() const
79 {
80 return btnIndex_;
81 }
82
SetBtnIndex(const int32_t btnIndex)83 void NotificationOperationInfo::SetBtnIndex(const int32_t btnIndex)
84 {
85 btnIndex_ = btnIndex;
86 }
87
GetJumpType() const88 int32_t NotificationOperationInfo::GetJumpType() const
89 {
90 return jumpType_;
91 }
92
SetJumpType(const int32_t jumpType)93 void NotificationOperationInfo::SetJumpType(const int32_t jumpType)
94 {
95 jumpType_ = jumpType;
96 }
97
GetNotificationUdid() const98 std::string NotificationOperationInfo::GetNotificationUdid() const
99 {
100 return notificationUdid_;
101 }
102
SetNotificationUdid(const std::string & udid)103 void NotificationOperationInfo::SetNotificationUdid(const std::string& udid)
104 {
105 notificationUdid_ = udid;
106 }
107
Dump()108 std::string NotificationOperationInfo::Dump()
109 {
110 return "NotificationOperationInfo{ "
111 "hashCode = " + hashCode_ +
112 ", eventId = " + eventId_ +
113 ", actionName = " + actionName_ +
114 ", operationType = " + std::to_string(static_cast<int32_t>(operationType_)) +
115 ", btnIndex = " + std::to_string(btnIndex_) +
116 ", jumpType = " + std::to_string(jumpType_) +
117 " }";
118 }
119
Marshalling(Parcel & parcel) const120 bool NotificationOperationInfo::Marshalling(Parcel &parcel) const
121 {
122 if (!parcel.WriteString(actionName_)) {
123 ANS_LOGE("Failed to write actionName");
124 return false;
125 }
126
127 if (!parcel.WriteString(userInput_)) {
128 ANS_LOGE("Failed to write userInput");
129 return false;
130 }
131
132 if (!parcel.WriteString(hashCode_)) {
133 ANS_LOGE("Failed to write hashCode");
134 return false;
135 }
136
137 if (!parcel.WriteString(eventId_)) {
138 ANS_LOGE("Failed to write eventId");
139 return false;
140 }
141
142 if (!parcel.WriteInt32(static_cast<int32_t>(operationType_))) {
143 ANS_LOGE("Failed to write operationType");
144 return false;
145 }
146
147 if (!parcel.WriteInt32(btnIndex_)) {
148 ANS_LOGE("Failed to write btnIndex");
149 return false;
150 }
151
152 if (!parcel.WriteInt32(jumpType_)) {
153 ANS_LOGE("Failed to write jumpType");
154 return false;
155 }
156
157 if (!parcel.WriteString(notificationUdid_)) {
158 ANS_LOGE("Failed to write notificationUdid");
159 return false;
160 }
161
162 return true;
163 }
164
ReadFromParcel(Parcel & parcel)165 bool NotificationOperationInfo::ReadFromParcel(Parcel &parcel)
166 {
167 if (!parcel.ReadString(actionName_)) {
168 ANS_LOGE("Failed to read actionName");
169 return false;
170 }
171
172 if (!parcel.ReadString(userInput_)) {
173 ANS_LOGE("Failed to read userInput");
174 return false;
175 }
176
177 if (!parcel.ReadString(hashCode_)) {
178 ANS_LOGE("Failed to read hashCode");
179 return false;
180 }
181
182 if (!parcel.ReadString(eventId_)) {
183 ANS_LOGE("Failed to read eventId");
184 return false;
185 }
186
187 operationType_ = static_cast<OperationType>(parcel.ReadInt32());
188
189 btnIndex_ = parcel.ReadInt32();
190
191 jumpType_ = parcel.ReadInt32();
192
193 if (!parcel.ReadString(notificationUdid_)) {
194 ANS_LOGE("Failed to read notificationUdid");
195 return false;
196 }
197
198 return true;
199 }
200
Unmarshalling(Parcel & parcel)201 NotificationOperationInfo *NotificationOperationInfo::Unmarshalling(Parcel &parcel)
202 {
203 auto operationInfo = new (std::nothrow) NotificationOperationInfo();
204 if (operationInfo && !operationInfo->ReadFromParcel(parcel)) {
205 delete operationInfo;
206 operationInfo = nullptr;
207 }
208
209 return operationInfo;
210 }
211
212 } // namespace Notification
213 } // namespace OHOS
214