• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "zidl/window_stub.h"
17 #include <vector>
18 #include "ipc_skeleton.h"
19 #include "window_manager_hilog.h"
20 #include "wm_common.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace {
25     constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowStub"};
26     const uint32_t MAX_AVOID_NUM = 4;
27 }
28 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int WindowStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31     if (data.ReadInterfaceToken() != GetDescriptor()) {
32         WLOGFE("InterfaceToken check failed");
33         return -1;
34     }
35     switch (code) {
36         case TRANS_ID_UPDATE_WINDOW_RECT: {
37             struct Rect rect { data.ReadInt32(), data.ReadInt32(), data.ReadUint32(), data.ReadUint32() };
38             WindowSizeChangeReason reason = static_cast<WindowSizeChangeReason>(data.ReadUint32());
39             UpdateWindowRect(rect, reason);
40             break;
41         }
42         case TRANS_ID_UPDATE_WINDOW_MODE: {
43             WindowMode mode = static_cast<WindowMode>(data.ReadUint32());
44             UpdateWindowMode(mode);
45             break;
46         }
47         case TRANS_ID_UPDATE_FOCUS_STATUS: {
48             bool focused = data.ReadBool();
49             UpdateFocusStatus(focused);
50             break;
51         }
52         case TRANS_ID_UPDATE_AVOID_AREA: {
53             std::vector<Rect> avoidArea;
54             uint32_t len = data.ReadUint32();
55             if (len != MAX_AVOID_NUM) {
56                 WLOGFE("Read len fail. AvoidArea size != 4");
57                 return -1;
58             }
59             avoidArea.resize(len);
60             if (avoidArea.size() < len) {
61                 WLOGE("Fail to resize avoidArea.");
62                 return -1;
63             }
64 
65             bool readVectorRes = true;
66             for (uint32_t i = 0; i < len; ++i) {
67                 readVectorRes = data.ReadInt32(avoidArea[i].posX_) && data.ReadInt32(avoidArea[i].posY_) &&
68                     data.ReadUint32(avoidArea[i].width_) && data.ReadUint32(avoidArea[i].height_);
69                 if (!readVectorRes) {
70                     WLOGE("Fail to ReadInt32. index:%{public}u, nums:%{public}u", i, len);
71                     return -1;
72                 }
73             }
74             UpdateAvoidArea(avoidArea);
75             break;
76         }
77         case TRANS_ID_UPDATE_WINDOW_STATE: {
78             UpdateWindowState(static_cast<WindowState>(data.ReadUint32()));
79             break;
80         }
81         case TRANS_ID_UPDATE_DRAG_EVENT: {
82             PointInfo point;
83             point.x = data.ReadInt32();
84             point.y = data.ReadInt32();
85             DragEvent event = static_cast<DragEvent> (data.ReadUint32());
86             UpdateWindowDragInfo(point, event);
87             break;
88         }
89         case TRANS_ID_UPDATE_DISPLAY_ID: {
90             UpdateDisplayId(data.ReadUint64(), data.ReadUint64());
91             break;
92         }
93         case TRANS_ID_UPDATE_OCCUPIED_AREA: {
94             sptr<OccupiedAreaChangeInfo> info = data.ReadParcelable<OccupiedAreaChangeInfo>();
95             UpdateOccupiedAreaChangeInfo(info);
96             break;
97         }
98         case TRANS_ID_UPDATE_ACTIVE_STATUS: {
99             bool isActive = data.ReadBool();
100             UpdateActiveStatus(isActive);
101             break;
102         }
103         default:
104             break;
105     }
106     return 0;
107 }
108 } // namespace Rosen
109 } // namespace OHOS
110