• 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_NOTIFY_WINDOW_SYSTEM_BAR_PROPERTY_CHANGE: {
53             // LCOV_EXCL_START
54             uint32_t type = 0;
55             if (!data.ReadUint32(type) ||
56                 type < static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_BASE) ||
57                 type > static_cast<uint32_t>(WindowType::ABOVE_APP_SYSTEM_WINDOW_END)) {
58                 TLOGE(WmsLogTag::WMS_IMMS, "read type failed");
59                 return ERR_INVALID_DATA;
60             }
61             bool enable = false;
62             if (!data.ReadBool(enable)) {
63                 TLOGE(WmsLogTag::WMS_IMMS, "read enable failed");
64                 return ERR_INVALID_DATA;
65             }
66             uint32_t backgroundColor = 0;
67             if (!data.ReadUint32(backgroundColor)) {
68                 TLOGE(WmsLogTag::WMS_IMMS, "read backgroundColor failed");
69                 return ERR_INVALID_DATA;
70             }
71             uint32_t contentColor = 0;
72             if (!data.ReadUint32(contentColor)) {
73                 TLOGE(WmsLogTag::WMS_IMMS, "read contentColor failed");
74                 return ERR_INVALID_DATA;
75             }
76             bool enableAnimation = false;
77             if (!data.ReadBool(enableAnimation)) {
78                 TLOGE(WmsLogTag::WMS_IMMS, "read enableAnimation failed");
79                 return ERR_INVALID_DATA;
80             }
81             uint32_t settingFlag = 0;
82             uint32_t MAX_SETTINGFLAG = 7;
83             if (!data.ReadUint32(settingFlag) ||
84                 settingFlag < static_cast<uint32_t>(SystemBarSettingFlag::DEFAULT_SETTING) ||
85                 settingFlag > MAX_SETTINGFLAG) {
86                 TLOGE(WmsLogTag::WMS_IMMS, "read settingFlag failed");
87                 return ERR_INVALID_DATA;
88             }
89             SystemBarProperty systemBarProperty = { enable, backgroundColor,
90                 contentColor, enableAnimation, static_cast<SystemBarSettingFlag>(settingFlag) };
91             NotifyWindowSystemBarPropertyChange(static_cast<WindowType>(type), systemBarProperty);
92             break;
93             // LCOV_EXCL_STOP
94         }
95         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_MODE_TYPE: {
96             uint8_t typeId = 0;
97             if (!data.ReadUint8(typeId) ||
98                 typeId < static_cast<uint8_t>(WindowModeType::WINDOW_MODE_SPLIT_FLOATING) ||
99                 typeId > static_cast<uint8_t>(WindowModeType::WINDOW_MODE_OTHER)) {
100                 TLOGE(WmsLogTag::WMS_LIFE, "read WindowModeType failed");
101                 return ERR_INVALID_DATA;
102             }
103             WindowModeType type = static_cast<WindowModeType>(typeId);
104             UpdateWindowModeTypeInfo(type);
105             break;
106         }
107         case WindowManagerAgentMsg::TRANS_ID_UPDATE_SYSTEM_BAR_PROPS: {
108             DisplayId displayId = 0;
109             if (!data.ReadUint64(displayId)) {
110                 return ERR_INVALID_DATA;
111             }
112             SystemBarRegionTints tints;
113             bool res = MarshallingHelper::UnmarshallingVectorObj<SystemBarRegionTint>(data, tints,
114                 [](Parcel& parcel, SystemBarRegionTint& tint) {
115                     uint32_t type;
116                     SystemBarProperty prop;
117                     Rect region;
118                     bool res = parcel.ReadUint32(type) && parcel.ReadBool(prop.enable_) &&
119                         parcel.ReadUint32(prop.backgroundColor_) && parcel.ReadUint32(prop.contentColor_) &&
120                         parcel.ReadInt32(region.posX_) && parcel.ReadInt32(region.posY_) &&
121                         parcel.ReadUint32(region.width_) && parcel.ReadUint32(region.height_);
122                     tint.type_ = static_cast<WindowType>(type);
123                     tint.prop_ = prop;
124                     tint.region_ = region;
125                     return res;
126                 }
127             );
128             if (!res) {
129                 WLOGFE("fail to read SystemBarRegionTints.");
130                 break;
131             }
132             UpdateSystemBarRegionTints(displayId, tints);
133             break;
134         }
135         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STATUS: {
136             std::vector<sptr<AccessibilityWindowInfo>> infos;
137             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<AccessibilityWindowInfo>(data, infos)) {
138                 WLOGFE("read accessibility window infos failed");
139                 return ERR_INVALID_DATA;
140             }
141             int32_t typeId = 0;
142             if (!data.ReadInt32(typeId) ||
143                 typeId < static_cast<int32_t>(WindowUpdateType::WINDOW_UPDATE_ADDED) ||
144                 typeId > static_cast<int32_t>(WindowUpdateType::WINDOW_UPDATE_ALL)) {
145                 TLOGE(WmsLogTag::WMS_LIFE, "read WindowUpdateType failed");
146                 return ERR_INVALID_DATA;
147             }
148             WindowUpdateType type = static_cast<WindowUpdateType>(typeId);
149             NotifyAccessibilityWindowInfo(infos, type);
150             break;
151         }
152         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_VISIBILITY: {
153             std::vector<sptr<WindowVisibilityInfo>> infos;
154             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowVisibilityInfo>(data, infos)) {
155                 WLOGFE("fail to read WindowVisibilityInfo.");
156                 break;
157             }
158             UpdateWindowVisibilityInfo(infos);
159             break;
160         }
161         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_DRAWING_STATE: {
162             std::vector<sptr<WindowDrawingContentInfo>> infos;
163             if (!MarshallingHelper::UnmarshallingVectorParcelableObj<WindowDrawingContentInfo>(data, infos)) {
164                 WLOGFE("fail to read WindowDrawingContentInfo.");
165                 break;
166             }
167             UpdateWindowDrawingContentInfo(infos);
168             break;
169         }
170         case WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_FLOAT: {
171             uint32_t accessTokenId = data.ReadUint32();
172             bool isShowing = data.ReadBool();
173             UpdateCameraFloatWindowStatus(accessTokenId, isShowing);
174             break;
175         }
176         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WATER_MARK_FLAG: {
177             bool showWaterMark = data.ReadBool();
178             NotifyWaterMarkFlagChangedResult(showWaterMark);
179             break;
180         }
181         case WindowManagerAgentMsg::TRANS_ID_UPDATE_VISIBLE_WINDOW_NUM: {
182             std::vector<VisibleWindowNumInfo> visibleWindowNumInfo;
183             bool res = MarshallingHelper::UnmarshallingVectorObj<VisibleWindowNumInfo>(
184                 data, visibleWindowNumInfo, [](Parcel& parcel, VisibleWindowNumInfo& num) {
185                     uint32_t displayId = -1;
186                     uint32_t visibleWindowNum = -1;
187                     bool res = parcel.ReadUint32(displayId) && parcel.ReadUint32(visibleWindowNum);
188                     num.displayId = displayId;
189                     num.visibleWindowNum = visibleWindowNum;
190                     return res;
191                 }
192             );
193             if (!res) {
194                 WLOGFE("fail to read VisibleWindowNumInfo.");
195                 break;
196             }
197             UpdateVisibleWindowNum(visibleWindowNumInfo);
198             break;
199         }
200         case WindowManagerAgentMsg::TRANS_ID_UPDATE_GESTURE_NAVIGATION_ENABLED: {
201             bool enbale = data.ReadBool();
202             NotifyGestureNavigationEnabledResult(enbale);
203             break;
204         }
205         case WindowManagerAgentMsg::TRANS_ID_UPDATE_CAMERA_WINDOW_STATUS: {
206             uint32_t accessTokenId = data.ReadUint32();
207             bool isShowing = data.ReadBool();
208             UpdateCameraWindowStatus(accessTokenId, isShowing);
209             break;
210         }
211         case WindowManagerAgentMsg::TRANS_ID_UPDATE_WINDOW_STYLE_TYPE: {
212             uint8_t typeId = 0;
213             if (!data.ReadUint8(typeId) ||
214                 typeId < static_cast<uint8_t>(WindowStyleType::WINDOW_STYLE_DEFAULT) ||
215                 typeId > static_cast<uint8_t>(WindowStyleType::WINDOW_STYLE_FREE_MULTI_WINDOW)) {
216                 TLOGE(WmsLogTag::WMS_LIFE, "read WindowStyleType failed");
217                 return ERR_INVALID_DATA;
218             }
219             WindowStyleType type = static_cast<WindowStyleType>(typeId);
220             NotifyWindowStyleChange(type);
221             break;
222         }
223         case WindowManagerAgentMsg::TRANS_ID_NOTIFY_WINDOW_PID_VISIBILITY: {
224             sptr<WindowPidVisibilityInfo> info = data.ReadParcelable<WindowPidVisibilityInfo>();
225             if (info == nullptr) {
226                 TLOGE(WmsLogTag::WMS_LIFE, "windowPidVisibilityInfo is null.");
227                 return ERR_INVALID_DATA;
228             }
229             NotifyWindowPidVisibilityChanged(info);
230             break;
231         }
232         case WindowManagerAgentMsg::TRANS_ID_UPDATE_PIP_WINDOW_STATE_CHANGED: {
233             std::string bundleName = data.ReadString();
234             bool isForeground = data.ReadBool();
235             UpdatePiPWindowStateChanged(bundleName, isForeground);
236             break;
237         }
238         case WindowManagerAgentMsg::TRANS_ID_NOTIFY_CALLING_DISPLAY_CHANGE: {
239             sptr<CallingWindowInfo> callingWindowInfo = data.ReadParcelable<CallingWindowInfo>();
240             if (callingWindowInfo == nullptr) {
241                 TLOGE(WmsLogTag::WMS_KEYBOARD, "callingWindowInfo is nullptr!");
242                 return ERR_INVALID_VALUE;
243             }
244             NotifyCallingWindowDisplayChanged(*callingWindowInfo);
245             break;
246         }
247         case WindowManagerAgentMsg::TRANS_ID_NOTIFY_WINDOW_PROPERTY_CHANGE: {
248             uint32_t propertyDirtyFlags = 0;
249             if (!data.ReadUint32(propertyDirtyFlags)) {
250                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read propertyDirtyFlags failed");
251                 return ERR_INVALID_DATA;
252             }
253 
254             std::vector<std::unordered_map<WindowInfoKey, WindowChangeInfoType>> windowInfoList;
255             if (!ReadWindowInfoList(data, windowInfoList)) {
256                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "fail to read windowInfoList.");
257                 return ERR_INVALID_DATA;
258             }
259             NotifyWindowPropertyChange(propertyDirtyFlags, windowInfoList);
260             break;
261         }
262         default:
263             WLOGFW("unknown transaction code %{public}d", code);
264             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
265     }
266     return ERR_NONE;
267 }
268 
269 // LCOV_EXCL_START
ReadWindowInfoList(MessageParcel & data,std::vector<std::unordered_map<WindowInfoKey,WindowChangeInfoType>> & windowInfoList)270 bool WindowManagerAgentStub::ReadWindowInfoList(MessageParcel& data,
271     std::vector<std::unordered_map<WindowInfoKey, WindowChangeInfoType>>& windowInfoList)
272 {
273     uint32_t windowInfoListLength = 0;
274     if (!data.ReadUint32(windowInfoListLength)) {
275         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read windowInfoListLength failed");
276         return false;
277     }
278     size_t windowInfoListSize = static_cast<size_t>(windowInfoListLength);
279 
280     for (size_t i = 0; i < windowInfoListSize; i++) {
281         uint32_t windowInfoLength = 0;
282         if (!data.ReadUint32(windowInfoLength)) {
283             TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read windowInfoLength failed");
284             return false;
285         }
286         size_t windowInfoSize = static_cast<size_t>(windowInfoLength);
287         std::unordered_map<WindowInfoKey, WindowChangeInfoType> windowInfo;
288         for (size_t j = 0; j < windowInfoSize; j++) {
289             if (!ReadWindowInfo(data, windowInfo)) {
290                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "fail to read windowInfo.");
291                 return false;
292             }
293         }
294         windowInfoList.emplace_back(windowInfo);
295     }
296     return true;
297 }
298 
ReadWindowInfo(MessageParcel & data,std::unordered_map<WindowInfoKey,WindowChangeInfoType> & windowInfo)299 bool WindowManagerAgentStub::ReadWindowInfo(MessageParcel& data,
300     std::unordered_map<WindowInfoKey, WindowChangeInfoType>& windowInfo)
301 {
302     int32_t windowInfoKeyValue = 0;
303     if (!data.ReadInt32(windowInfoKeyValue)) {
304         TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read windowInfoKeyValue failed");
305         return false;
306     }
307 
308     WindowInfoKey windowInfoKey = static_cast<WindowInfoKey>(windowInfoKeyValue);
309     switch (windowInfoKey) {
310         case WindowInfoKey::WINDOW_ID : {
311             uint32_t value = 0;
312             if (!data.ReadUint32(value)) {
313                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read uint32_t failed");
314                 return false;
315             }
316             windowInfo[windowInfoKey] = value;
317             break;
318         }
319         case WindowInfoKey::BUNDLE_NAME :
320         case WindowInfoKey::ABILITY_NAME : {
321             std::string value;
322             if (!data.ReadString(value)) {
323                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read string failed");
324                 return false;
325             }
326             windowInfo[windowInfoKey] = value;
327             break;
328         }
329         case WindowInfoKey::APP_INDEX : {
330             int32_t value = 0;
331             if (!data.ReadInt32(value)) {
332                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read int32_t failed");
333                 return false;
334             }
335             windowInfo[windowInfoKey] = value;
336             break;
337         }
338         case WindowInfoKey::VISIBILITY_STATE : {
339             uint32_t value = 0;
340             if (!data.ReadUint32(value)) {
341                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read WindowVisibilityState failed");
342                 return false;
343             }
344             windowInfo[windowInfoKey] = static_cast<WindowVisibilityState>(value);
345             break;
346         }
347         case WindowInfoKey::WINDOW_MODE : {
348             uint32_t value = 0;
349             if (!data.ReadUint32(value)) {
350                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read WindowMode failed");
351                 return false;
352             }
353             windowInfo[windowInfoKey] = static_cast<WindowMode>(value);
354             break;
355         }
356         case WindowInfoKey::DISPLAY_ID : {
357             uint64_t value = 0;
358             if (!data.ReadUint64(value)) {
359                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read uint64_t failed");
360                 return false;
361             }
362             windowInfo[windowInfoKey] = value;
363             break;
364         }
365         case WindowInfoKey::WINDOW_RECT : {
366             Rect rect = Rect::EMPTY_RECT;
367             if (!data.ReadInt32(rect.posX_) || !data.ReadInt32(rect.posY_) ||
368                 !data.ReadUint32(rect.width_) || !data.ReadUint32(rect.height_)) {
369                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read Rect failed");
370                 return false;
371             }
372             windowInfo[windowInfoKey] = rect;
373             break;
374         }
375         case WindowInfoKey::FLOATING_SCALE : {
376             float value = 0.f;
377             if (!data.ReadFloat(value)) {
378                 TLOGE(WmsLogTag::WMS_ATTRIBUTE, "read float failed");
379                 return false;
380             }
381             windowInfo[windowInfoKey] = value;
382             break;
383         }
384         default : {
385             TLOGE(WmsLogTag::WMS_ATTRIBUTE, "unknown WindowInfoKey");
386             return false;
387         }
388     }
389     return true;
390 }
391 // LCOV_EXCL_STOP
392 } // namespace Rosen
393 } // namespace OHOS
394