• 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_window_info_parcel.h"
17 #include "accessibility_element_info_parcel.h"
18 #include "hilog_wrapper.h"
19 #include "parcel_util.h"
20 
21 namespace OHOS {
22 namespace Accessibility {
23 
24 namespace {
25     constexpr int32_t TOUCH_HOT_AREA_MAX_SIZE = 1024;
26 }
27 
AccessibilityWindowInfoParcel(const AccessibilityWindowInfo & accessibilityWindowInfo)28 AccessibilityWindowInfoParcel::AccessibilityWindowInfoParcel(const AccessibilityWindowInfo &accessibilityWindowInfo)
29     : AccessibilityWindowInfo(accessibilityWindowInfo)
30 {
31 }
32 
33 // LCOV_EXCL_START
ReadFromParcel(Parcel & parcel)34 bool AccessibilityWindowInfoParcel::ReadFromParcel(Parcel &parcel)
35 {
36     int32_t accessibilityWindowType = TYPE_WINDOW_INVALID;
37     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, accessibilityWindowType);
38     accessibilityWindowType_ = static_cast<AccessibilityWindowType>(accessibilityWindowType);
39     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, windowType_);
40     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, windowMode_);
41     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowLayer_);
42     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId_);
43     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, active_);
44     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, focused_);
45     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityFocused_);
46     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDecorEnable_);
47     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, mainWindowId_);
48     sptr<RectParcel> boundsInScreen = parcel.ReadStrongParcelable<RectParcel>();
49     if (boundsInScreen == nullptr) {
50         HILOG_ERROR("ReadStrongParcelable boundsInScreen failed.");
51         return false;
52     }
53     boundsInScreen_ = *boundsInScreen;
54 
55     int32_t touchHotAreasSize = 0;
56     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, touchHotAreasSize);
57     if (touchHotAreasSize > TOUCH_HOT_AREA_MAX_SIZE) {
58         return false;
59     }
60     std::vector<Rect> touchHotAreas {};
61     for (int i = 0; i < touchHotAreasSize; i++) {
62         sptr<RectParcel> hotAreaRectParcel = parcel.ReadStrongParcelable<RectParcel>();
63         if (hotAreaRectParcel == nullptr) {
64             HILOG_ERROR("ReadStrongParcelable hotAreaRect failed.");
65             return false;
66         }
67         touchHotAreas.push_back(*hotAreaRectParcel);
68     }
69     touchHotAreas_ = touchHotAreas;
70     READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint64, parcel, displayId_);
71 
72     return true;
73 }
74 // LCOV_EXCL_STOP
75 
Marshalling(Parcel & parcel) const76 bool AccessibilityWindowInfoParcel::Marshalling(Parcel &parcel) const
77 {
78     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(accessibilityWindowType_));
79     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, windowType_);
80     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint32, parcel, windowMode_);
81     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowLayer_);
82     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, windowId_);
83     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, active_);
84     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, focused_);
85     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, accessibilityFocused_);
86     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isDecorEnable_);
87     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, mainWindowId_);
88     RectParcel rectParcel(boundsInScreen_);
89     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &rectParcel);
90     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, touchHotAreas_.size());
91     for (const auto &hotArea : touchHotAreas_) {
92         RectParcel hotAreaRectParcel(hotArea);
93         WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Parcelable, parcel, &hotAreaRectParcel);
94     }
95     WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Uint64, parcel, displayId_);
96 
97     return true;
98 };
99 
100 // LCOV_EXCL_START
Unmarshalling(Parcel & parcel)101 sptr<AccessibilityWindowInfoParcel> AccessibilityWindowInfoParcel::Unmarshalling(Parcel &parcel)
102 {
103     sptr<AccessibilityWindowInfoParcel> info = new(std::nothrow) AccessibilityWindowInfoParcel();
104     if (info == nullptr) {
105         HILOG_ERROR("Failed to create info.");
106         return nullptr;
107     }
108     if (!info->ReadFromParcel(parcel)) {
109         HILOG_ERROR("ReadFromParcel failed.");
110         info = nullptr;
111         return nullptr;
112     }
113     return info;
114 }
115 // LCOV_EXCL_STOP
116 } // namespace Accessibility
117 } // namespace OHOS