1 /*
2  * Copyright (c) 2023 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 <refbase.h>
17 #include <iremote_object.h>
18 
19 
20 #include "window_manager.h"
21 #include "wm_common.h"
22 
23 namespace OHOS {
24 namespace Rosen {
Marshalling(Parcel & parcel) const25 bool AccessibilityWindowInfo::Marshalling(Parcel& parcel) const
26 {
27     auto touchHotAreas = touchHotAreas_;
28     bool res = parcel.WriteInt32(wid_) && parcel.WriteInt32(innerWid_) && parcel.WriteInt32(uiNodeId_) &&
29         parcel.WriteUint32(windowRect_.width_) &&
30         parcel.WriteUint32(windowRect_.height_) && parcel.WriteInt32(windowRect_.posX_) &&
31         parcel.WriteInt32(windowRect_.posY_) && parcel.WriteBool(focused_) && parcel.WriteBool(isDecorEnable_) &&
32         parcel.WriteUint64(displayId_) && parcel.WriteUint32(layer_) && parcel.WriteFloat(scaleVal_) &&
33         parcel.WriteFloat(scaleX_) && parcel.WriteFloat(scaleY_) &&
34         parcel.WriteUint32(static_cast<uint32_t>(mode_)) && parcel.WriteUint32(static_cast<uint32_t>(type_)) &&
35         parcel.WriteString(bundleName_) && parcel.WriteUint32(touchHotAreas.size());
36     if (!res) {
37         return false;
38     }
39 
40     for (const auto& rect : touchHotAreas) {
41         res = parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
42             parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_);
43         if (!res) {
44             return false;
45         }
46     }
47     return res;
48 }
49 
Unmarshalling(Parcel & parcel)50 AccessibilityWindowInfo* AccessibilityWindowInfo::Unmarshalling(Parcel& parcel)
51 {
52     auto info = new (std::nothrow) AccessibilityWindowInfo();
53     if (info == nullptr) {
54         return nullptr;
55     }
56     bool res = parcel.ReadInt32(info->wid_) && parcel.ReadInt32(info->innerWid_) && parcel.ReadInt32(info->uiNodeId_) &&
57         parcel.ReadUint32(info->windowRect_.width_) &&
58         parcel.ReadUint32(info->windowRect_.height_) && parcel.ReadInt32(info->windowRect_.posX_) &&
59         parcel.ReadInt32(info->windowRect_.posY_) && parcel.ReadBool(info->focused_) &&
60         parcel.ReadBool(info->isDecorEnable_) && parcel.ReadUint64(info->displayId_) &&
61         parcel.ReadUint32(info->layer_) && parcel.ReadFloat(info->scaleVal_) &&
62         parcel.ReadFloat(info->scaleX_) && parcel.ReadFloat(info->scaleY_);
63     if (!res) {
64         delete info;
65         return nullptr;
66     }
67     info->mode_ = static_cast<WindowMode>(parcel.ReadUint32());
68     info->type_ = static_cast<WindowType>(parcel.ReadUint32());
69     info->bundleName_ = parcel.ReadString();
70     size_t touchHotAreasCnt = parcel.ReadUint32();
71     constexpr size_t touchHotAreasCntMax = 10000;
72     if (touchHotAreasCnt <= touchHotAreasCntMax) {
73         for (size_t i = 0; i < touchHotAreasCnt; i++) {
74             info->touchHotAreas_.push_back({.posX_ = parcel.ReadInt32(), .posY_ = parcel.ReadInt32(),
75                                            .width_ = parcel.ReadUint32(), .height_ = parcel.ReadUint32()});
76         }
77     }
78     return info;
79 }
80 }
81 }