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 "accessibility_event_info_parcel.h"
17 #include "hilog_wrapper.h"
18 #include "parcel_util.h"
19
20 namespace OHOS {
21 namespace Accessibility {
AccessibilityEventInfoParcel(const AccessibilityEventInfo & eventInfo)22 AccessibilityEventInfoParcel::AccessibilityEventInfoParcel(const AccessibilityEventInfo &eventInfo)
23 {
24 HILOG_DEBUG();
25 HILOG_DEBUG("bundleName is [%{public}s]", bundleName_.c_str());
26 HILOG_DEBUG("notificationContent is [%{public}s]", notificationContent_.c_str());
27
28 AccessibilityEventInfo *self = this;
29 *self = eventInfo;
30 }
31
ReadFromParcelFirstPart(Parcel & parcel)32 bool AccessibilityEventInfoParcel::ReadFromParcelFirstPart(Parcel &parcel)
33 {
34 uint32_t eventType = TYPE_VIEW_INVALID;
35 uint32_t gestureType = GESTURE_INVALID;
36 int32_t triggerAction = ACCESSIBILITY_ACTION_INVALID;
37 int32_t textMoveStep = STEP_CHARACTER;
38 int32_t windowContentChangeTypes = CONTENT_CHANGE_TYPE_INVALID;
39 int32_t windowChangeTypes = WINDOW_UPDATE_INVALID;
40 int32_t category = CATEGORY_INVALID;
41 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, eventType);
42 eventType_ = static_cast<EventType>(eventType);
43 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, gestureType);
44 gestureType_ = static_cast<GestureType>(gestureType);
45 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName_);
46 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, triggerAction);
47 triggerAction_ = static_cast<ActionType>(triggerAction);
48 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, timeStamp_);
49 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, textMoveStep);
50 textMoveStep_ = static_cast<TextMoveUnit>(textMoveStep);
51 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowContentChangeTypes);
52 windowContentChangeTypes_ = static_cast<WindowsContentChangeTypes>(windowContentChangeTypes);
53 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowChangeTypes);
54 windowChangeTypes_ = static_cast<WindowUpdateType>(windowChangeTypes);
55 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, category);
56 category_ = static_cast<NotificationCategory>(category);
57 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pageId_);
58 return true;
59 }
60
ReadFromParcelSecondPart(Parcel & parcel)61 bool AccessibilityEventInfoParcel::ReadFromParcelSecondPart(Parcel &parcel)
62 {
63 int32_t componentId = 0;
64 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, componentId);
65 SetSource(componentId);
66 int32_t windowId = 0;
67 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId);
68 SetWindowId(windowId);
69 int32_t currentIndex = 0;
70 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, currentIndex);
71 SetCurrentIndex(currentIndex);
72 int32_t beginIndex = 0;
73 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, beginIndex);
74 SetBeginIndex(beginIndex);
75 int32_t endIndex = 0;
76 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, endIndex);
77 SetEndIndex(endIndex);
78 int32_t contentSize = 0;
79 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, contentSize);
80 std::string content;
81 ContainerSecurityVerify(parcel, contentSize, contents_.max_size());
82 for (auto i = 0 ; i < contentSize; i++) {
83 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, content);
84 AddContent(content);
85 }
86 std::string componentType;
87 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, componentType);
88 SetComponentType(componentType);
89 std::string description;
90 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, description);
91 SetDescription(description);
92 std::string beforeText;
93 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, beforeText);
94 SetBeforeText(beforeText);
95 std::string latestConent;
96 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, latestConent);
97 SetLatestContent(latestConent);
98 int32_t elementId = 0;
99 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, elementId);
100
101 int32_t itemCounts = 0;
102 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, itemCounts);
103 SetItemCounts(itemCounts);
104 return true;
105 }
106
ReadFromParcel(Parcel & parcel)107 bool AccessibilityEventInfoParcel::ReadFromParcel(Parcel &parcel)
108 {
109 HILOG_DEBUG();
110 if (!ReadFromParcelFirstPart(parcel)) {
111 return false;
112 }
113 if (!ReadFromParcelSecondPart(parcel)) {
114 return false;
115 }
116 return true;
117 }
118
Marshalling(Parcel & parcel) const119 bool AccessibilityEventInfoParcel::Marshalling(Parcel &parcel) const
120 {
121 HILOG_DEBUG();
122 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, static_cast<uint32_t>(eventType_));
123 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, static_cast<uint32_t>(gestureType_));
124 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, bundleName_);
125 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(triggerAction_));
126 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int64, parcel, timeStamp_);
127 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(textMoveStep_));
128 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(windowContentChangeTypes_));
129 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(windowChangeTypes_));
130 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(category_));
131 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, pageId_);
132
133 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetViewId());
134 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetWindowId());
135 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetCurrentIndex());
136 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetBeginIndex());
137 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetEndIndex());
138 auto contentList = GetContentList();
139 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, contentList.size());
140 for (auto &content : contentList) {
141 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, content);
142 }
143 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, GetComponentType());
144 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, GetDescription());
145 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, GetBeforeText());
146 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String, parcel, GetLatestContent());
147 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetAccessibilityId());
148 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, GetItemCounts());
149 return true;
150 }
151
Unmarshalling(Parcel & parcel)152 sptr<AccessibilityEventInfoParcel> AccessibilityEventInfoParcel::Unmarshalling(Parcel& parcel)
153 {
154 HILOG_DEBUG();
155 sptr<AccessibilityEventInfoParcel> accessibilityEventInfo = new(std::nothrow) AccessibilityEventInfoParcel();
156 if (!accessibilityEventInfo) {
157 HILOG_ERROR("Failed to create accessibilityEventInfo.");
158 return nullptr;
159 }
160 if (!accessibilityEventInfo->ReadFromParcel(parcel)) {
161 HILOG_ERROR("read from parcel failed");
162 return nullptr;
163 }
164 return accessibilityEventInfo;
165 }
166 } // namespace Accessibility
167 } // namespace OHOS