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