1 /*
2  * Copyright (c) 2021-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 "zidl/window_manager_agent_stub.h"
17 #include "ipc_skeleton.h"
18 #include "marshalling_helper.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, "WindowManagerAgentStub"};
26 }
27 
OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)28 int WindowManagerAgentStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
29     MessageParcel& reply, MessageOption& option)
30 {
31     WLOGFD("code is %{public}u", code);
32     if (data.ReadInterfaceToken() != GetDescriptor()) {
33         WLOGFE("InterfaceToken check failed");
34         return ERR_TRANSACTION_FAILED;
35     }
36     WindowManagerAgentMsg msgId = static_cast<WindowManagerAgentMsg>(code);
37     switch (msgId) {
38         case WindowManagerAgentMsg::TRANS_ID_UPDATE_FOCUS: {
39             sptr<FocusChangeInfo> info = data.ReadParcelable<FocusChangeInfo>();
40             if (info == nullptr) {
41                 WLOGFE("FocusChangeInfo is null");
42                 return ERR_INVALID_DATA;
43             }
44             bool focused = false;
45             if (!data.ReadBool(focused)) {
46                 TLOGE(WmsLogTag::WMS_FOCUS, "read focused failed");
47                 return ERR_INVALID_DATA;
48             }
49             UpdateFocusChangeInfo(info, focused);
50             break;
51         }
52         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_MODE_TYPE: {
53             WindowModeType type = static_cast<WindowModeType>(data.ReadUint8());
54             UpdateWindowModeTypeInfo(type);
55             break;
56         }
57         case WindowManagerAgentMsg::TRANS_ID_UPDATE_SYSTEM_BAR_PROPS: {
58             DisplayId displayId = 0;
59             if (!data.ReadUint64(displayId)) {
60                 return ERR_INVALID_DATA;
61             }
62             SystemBarRegionTints tints;
63             bool res = MarshallingHelper::UnmarshallingVectorObj<SystemBarRegionTint>(data, tints,
64                 [](Parcel& parcel, SystemBarRegionTint& tint) {
65                     uint32_t type;
66                     SystemBarProperty prop;
67                     Rect region;
68                     bool res = parcel.ReadUint32(type) && parcel.ReadBool(prop.enable_) &&
69                         parcel.ReadUint32(prop.backgroundColor_) && parcel.ReadUint32(prop.contentColor_) &&
70                         parcel.ReadInt32(region.posX_) && parcel.ReadInt32(region.posY_) &&
71                         parcel.ReadUint32(region.width_) && parcel.ReadUint32(region.height_);
72                     tint.type_ = static_cast<WindowType>(type);
73                     tint.prop_ = prop;
74                     tint.region_ = region;
75                     return res;
76                 }
77             );
78             if (!res) {
79                 WLOGFE("fail to read SystemBarRegionTints.");
80                 break;
81             }
82             UpdateSystemBarRegionTints(displayId, tints);
83             break;
84         }
85         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STATUS: {
86             std::vector<sptr<AccessibilityWindowInfo>> infos;
87             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(data, infos)) {
88                 WLOGFE("read accessibility window infos failed");
89                 return ERR_INVALID_DATA;
90             }
91             WindowUpdateType type = static_cast<WindowUpdateType>(data.ReadUint32());
92             NotifyAccessibilityWindowInfo(infos, type);
93             break;
94         }
95         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_VISIBILITY: {
96             std::vector<sptr<WindowVisibilityInfo>> infos;
97             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(data, infos)) {
98                 WLOGFE("fail to read WindowVisibilityInfo.");
99                 break;
100             }
101             UpdateWindowVisibilityInfo(infos);
102             break;
103         }
104         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_DRAWING_STATE: {
105             std::vector<sptr<WindowDrawingContentInfo>> infos;
106             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowDrawingContentInfo>(data, infos)) {
107                 WLOGFE("fail to read WindowDrawingContentInfo.");
108                 break;
109             }
110             UpdateWindowDrawingContentInfo(infos);
111             break;
112         }
113         case WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT: {
114             uint32_t accessTokenId = data.ReadUint32();
115             bool isShowing = data.ReadBool();
116             UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
117             break;
118         }
119         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WATER_MARK_FLAG: {
120             bool showWaterMark = data.ReadBool();
121             NotifyWaterMarkFlagChangedResult(showWaterMark);
122             break;
123         }
124         case WindowManagerAgentMsg::TRANS_ID_UPDATE_VISIBLE_WINDOW_NUM: {
125             std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
126             bool res = MarshallingHelper::UnmarshallingVectorObj<VisibleWindowNumInfo>(
127                 data, visibleWindowNumInfo, [](Parcel& parcel, VisibleWindowNumInfo& num) {
128                     uint32_t displayId = -1;
129                     uint32_t visibleWindowNum = -1;
130                     bool res = parcel.ReadUint32(displayId) && parcel.ReadUint32(visibleWindowNum);
131                     num.displayId = displayId;
132                     num.visibleWindowNum = visibleWindowNum;
133                     return res;
134                 }
135             );
136             if (!res) {
137                 WLOGFE("fail to read VisibleWindowNumInfo.");
138                 break;
139             }
140             UpdateVisibleWindowNum(visibleWindowNumInfo);
141             break;
142         }
143         case WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED: {
144             bool enbale = data.ReadBool();
145             NotifyGestureNavigationEnabledResult(enbale);
146             break;
147         }
148         case WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS: {
149             uint32_t accessTokenId = data.ReadUint32();
150             bool isShowing = data.ReadBool();
151             UpdateCameraWindowStatus(accessTokenId, isShowing);
152             break;
153         }
154         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STYLE_TYPE: {
155             WindowStyleType type = static_cast<WindowStyleType>(data.ReadUint8());
156             NotifyWindowStyleChange(type);
157             break;
158         }
159         case WindowManagerAgentMsg::TRANS_ID_NOTIFY_WINDOW_PID_VISIBILITY: {
160             sptr<WindowPidVisibilityInfo> info = data.ReadParcelable<WindowPidVisibilityInfo>();
161             if (info == nullptr) {
162                 TLOGE(WmsLogTag::WMS_LIFE, "windowPidVisibilityInfo is null.");
163                 return ERR_INVALID_DATA;
164             }
165             NotifyWindowPidVisibilityChanged(info);
166             break;
167         }
168         case WindowManagerAgentMsg::TRANS_ID_UPDATE_PIP_WINDOW_STATE_CHANGED: {
169             std::string bundleName = data.ReadString();
170             bool isForeground = data.ReadBool();
171             UpdatePiPWindowStateChanged(bundleName, isForeground);
172             break;
173         }
174         default:
175             WLOGFW("unknown transaction code %{public}d", code);
176             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
177     }
178     return ERR_NONE;
179 }
180 } // namespace Rosen
181 } // namespace OHOS
182