• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             uint8_t typeId = 0;
54             if (!data.ReadUint8(typeId) ||
55                 typeId < static_cast<uint8_t>(WindowModeType::WINDOW_MODE_SPLIT_FLOATING) ||
56                 typeId > static_cast<uint8_t>(WindowModeType::WINDOW_MODE_OTHER)) {
57                 TLOGE(WmsLogTag::WMS_LIFE, "read WindowModeType failed");
58                 return ERR_INVALID_DATA;
59             }
60             WindowModeType type = static_cast<WindowModeType>(typeId);
61             UpdateWindowModeTypeInfo(type);
62             break;
63         }
64         case WindowManagerAgentMsg::TRANS_ID_UPDATE_SYSTEM_BAR_PROPS: {
65             DisplayId displayId = 0;
66             if (!data.ReadUint64(displayId)) {
67                 return ERR_INVALID_DATA;
68             }
69             SystemBarRegionTints tints;
70             bool res = MarshallingHelper::UnmarshallingVectorObj<SystemBarRegionTint>(data, tints,
71                 [](Parcel& parcel, SystemBarRegionTint& tint) {
72                     uint32_t type;
73                     SystemBarProperty prop;
74                     Rect region;
75                     bool res = parcel.ReadUint32(type) && parcel.ReadBool(prop.enable_) &&
76                         parcel.ReadUint32(prop.backgroundColor_) && parcel.ReadUint32(prop.contentColor_) &&
77                         parcel.ReadInt32(region.posX_) && parcel.ReadInt32(region.posY_) &&
78                         parcel.ReadUint32(region.width_) && parcel.ReadUint32(region.height_);
79                     tint.type_ = static_cast<WindowType>(type);
80                     tint.prop_ = prop;
81                     tint.region_ = region;
82                     return res;
83                 }
84             );
85             if (!res) {
86                 WLOGFE("fail to read SystemBarRegionTints.");
87                 break;
88             }
89             UpdateSystemBarRegionTints(displayId, tints);
90             break;
91         }
92         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STATUS: {
93             std::vector<sptr<AccessibilityWindowInfo>> infos;
94             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(data, infos)) {
95                 WLOGFE("read accessibility window infos failed");
96                 return ERR_INVALID_DATA;
97             }
98             int32_t typeId = 0;
99             if (!data.ReadInt32(typeId) ||
100                 typeId < static_cast<int32_t>(WindowUpdateType::WINDOW_UPDATE_ADDED) ||
101                 typeId > static_cast<int32_t>(WindowUpdateType::WINDOW_UPDATE_ALL)) {
102                 TLOGE(WmsLogTag::WMS_LIFE, "read WindowUpdateType failed");
103                 return ERR_INVALID_DATA;
104             }
105             WindowUpdateType type = static_cast<WindowUpdateType>(typeId);
106             NotifyAccessibilityWindowInfo(infos, type);
107             break;
108         }
109         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_VISIBILITY: {
110             std::vector<sptr<WindowVisibilityInfo>> infos;
111             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(data, infos)) {
112                 WLOGFE("fail to read WindowVisibilityInfo.");
113                 break;
114             }
115             UpdateWindowVisibilityInfo(infos);
116             break;
117         }
118         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_DRAWING_STATE: {
119             std::vector<sptr<WindowDrawingContentInfo>> infos;
120             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowDrawingContentInfo>(data, infos)) {
121                 WLOGFE("fail to read WindowDrawingContentInfo.");
122                 break;
123             }
124             UpdateWindowDrawingContentInfo(infos);
125             break;
126         }
127         case WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT: {
128             uint32_t accessTokenId = data.ReadUint32();
129             bool isShowing = data.ReadBool();
130             UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
131             break;
132         }
133         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WATER_MARK_FLAG: {
134             bool showWaterMark = data.ReadBool();
135             NotifyWaterMarkFlagChangedResult(showWaterMark);
136             break;
137         }
138         case WindowManagerAgentMsg::TRANS_ID_UPDATE_VISIBLE_WINDOW_NUM: {
139             std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
140             bool res = MarshallingHelper::UnmarshallingVectorObj<VisibleWindowNumInfo>(
141                 data, visibleWindowNumInfo, [](Parcel& parcel, VisibleWindowNumInfo& num) {
142                     uint32_t displayId = -1;
143                     uint32_t visibleWindowNum = -1;
144                     bool res = parcel.ReadUint32(displayId) && parcel.ReadUint32(visibleWindowNum);
145                     num.displayId = displayId;
146                     num.visibleWindowNum = visibleWindowNum;
147                     return res;
148                 }
149             );
150             if (!res) {
151                 WLOGFE("fail to read VisibleWindowNumInfo.");
152                 break;
153             }
154             UpdateVisibleWindowNum(visibleWindowNumInfo);
155             break;
156         }
157         case WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED: {
158             bool enbale = data.ReadBool();
159             NotifyGestureNavigationEnabledResult(enbale);
160             break;
161         }
162         case WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS: {
163             uint32_t accessTokenId = data.ReadUint32();
164             bool isShowing = data.ReadBool();
165             UpdateCameraWindowStatus(accessTokenId, isShowing);
166             break;
167         }
168         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STYLE_TYPE: {
169             uint8_t typeId = 0;
170             if (!data.ReadUint8(typeId) ||
171                 typeId < static_cast<uint8_t>(WindowStyleType::WINDOW_STYLE_DEFAULT) ||
172                 typeId > static_cast<uint8_t>(WindowStyleType::WINDOW_STYLE_FREE_MULTI_WINDOW)) {
173                 TLOGE(WmsLogTag::WMS_LIFE, "read WindowStyleType failed");
174                 return ERR_INVALID_DATA;
175             }
176             WindowStyleType type = static_cast<WindowStyleType>(typeId);
177             NotifyWindowStyleChange(type);
178             break;
179         }
180         case WindowManagerAgentMsg::TRANS_ID_NOTIFY_WINDOW_PID_VISIBILITY: {
181             sptr<WindowPidVisibilityInfo> info = data.ReadParcelable<WindowPidVisibilityInfo>();
182             if (info == nullptr) {
183                 TLOGE(WmsLogTag::WMS_LIFE, "windowPidVisibilityInfo is null.");
184                 return ERR_INVALID_DATA;
185             }
186             NotifyWindowPidVisibilityChanged(info);
187             break;
188         }
189         case WindowManagerAgentMsg::TRANS_ID_UPDATE_PIP_WINDOW_STATE_CHANGED: {
190             std::string bundleName = data.ReadString();
191             bool isForeground = data.ReadBool();
192             UpdatePiPWindowStateChanged(bundleName, isForeground);
193             break;
194         }
195         case WindowManagerAgentMsg::TRANS_ID_NOTIFY_CALLING_DISPLAY_CHANGE: {
196             sptr<CallingWindowInfo> callingWindowInfo = data.ReadParcelable<CallingWindowInfo>();
197             if (callingWindowInfo == nullptr) {
198                 TLOGE(WmsLogTag::WMS_KEYBOARD, "callingWindowInfo is nullptr!");
199                 return ERR_INVALID_VALUE;
200             }
201             NotifyCallingWindowDisplayChanged(*callingWindowInfo);
202             break;
203         }
204         default:
205             WLOGFW("unknown transaction code %{public}d", code);
206             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
207     }
208     return ERR_NONE;
209 }
210 } // namespace Rosen
211 } // namespace OHOS
212