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