• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "marshalling_helper.h"
17 
18 #include <securec.h>
19 #include <iremote_broker.h>
20 #include <iservice_registry.h>
21 
22 #include "ability_context.h"
23 #include "ability_context_impl.h"
24 #include "js_runtime.h"
25 #include <want.h>
26 #include "window.h"
27 #include "window_accessibility_controller.h"
28 #include "window_impl.h"
29 #include "window_manager.h"
30 #include "window_extension_connection.h"
31 #include "window_adapter.h"
32 #include "wm_common.h"
33 #include "window_option.h"
34 
35 using namespace OHOS::Rosen;
36 
37 namespace OHOS {
38 namespace {
39     constexpr size_t DATA_MIN_SIZE = 2;
40     constexpr size_t DATA_MAX_SIZE = 1024;
41 }
42 class FocusChangedListener : public IFocusChangedListener {
43 public:
OnFocused(const sptr<FocusChangeInfo> & focusChangeInfo)44     virtual void OnFocused(const sptr<FocusChangeInfo>& focusChangeInfo) override
45     {
46     }
47 
OnUnfocused(const sptr<FocusChangeInfo> & focusChangeInfo)48     virtual void OnUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo) override
49     {
50     }
51 };
52 
53 class SystemBarChangedListener : public ISystemBarChangedListener {
54 public:
OnSystemBarPropertyChange(DisplayId displayId,const SystemBarRegionTints & tints)55     virtual void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) override
56     {
57     }
58 };
59 
60 class VisibilityChangedListener : public IVisibilityChangedListener {
61 public:
OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>> & windowVisibilityInfo)62     virtual void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) override
63     {
64     }
65 };
66 
67 class WindowUpdateListener : public IWindowUpdateListener {
68 public:
OnWindowUpdate(const std::vector<sptr<AccessibilityWindowInfo>> & infos,WindowUpdateType type)69     virtual void OnWindowUpdate(const std::vector<sptr<AccessibilityWindowInfo>>& infos, WindowUpdateType type) override
70     {
71     }
72 };
73 
74 class ExtensionCallback : public IWindowExtensionCallback {
75 public:
OnWindowReady(const std::shared_ptr<Rosen::RSSurfaceNode> & rsSurfaceNode)76     void OnWindowReady(const std::shared_ptr<Rosen::RSSurfaceNode>& rsSurfaceNode) override
77     {
78     }
OnExtensionDisconnected()79     void OnExtensionDisconnected() override
80     {
81     }
OnKeyEvent(const std::shared_ptr<MMI::KeyEvent> & event)82     void OnKeyEvent(const std::shared_ptr<MMI::KeyEvent>& event) override
83     {
84     }
OnPointerEvent(const std::shared_ptr<MMI::PointerEvent> & event)85     void OnPointerEvent(const std::shared_ptr<MMI::PointerEvent>& event) override
86     {
87     }
OnBackPress()88     void OnBackPress() override
89     {
90     }
91 };
92 
93 class OccupiedAreaChangeListener : public IOccupiedAreaChangeListener {
94 public:
OnSizeChange(const sptr<OccupiedAreaChangeInfo> & info,const std::shared_ptr<RSTransaction> & rsTransaction=nullptr)95     void OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info,
96         const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override
97     {
98     }
99 };
100 
101 class TouchOutsideListener : public ITouchOutsideListener {
102 public:
OnTouchOutside() const103     void OnTouchOutside() const override
104     {
105     }
106 };
107 
108 class WindowVisibilityChangeListener : public IWindowVisibilityChangedListener {
109 public:
OnWindowVisibilityChangedCallback(const bool isVisisble)110     void OnWindowVisibilityChangedCallback(const bool isVisisble) override
111     {
112     }
113 };
114 
115 class WindowNoInteractionListener : public IWindowNoInteractionListener {
116 public:
OnWindowNoInteractionCallback()117     void OnWindowNoInteractionCallback() override
118     {
119     }
120 };
121 
122 class AnimationTransitionController : public IAnimationTransitionController {
123 public:
AnimationForShown()124     void AnimationForShown() override
125     {
126     }
127 
AnimationForHidden()128     void AnimationForHidden() override
129     {
130     }
131 };
132 
133 class ScreenshotListener : public IScreenshotListener {
134 public:
OnScreenshot()135     void OnScreenshot() override
136     {
137     }
138 };
139 
140 class DialogTargetTouchListener : public IDialogTargetTouchListener {
141 public:
OnDialogTargetTouch() const142     void OnDialogTargetTouch() const override
143     {
144     }
145 };
146 
147 class DialogDeathRecipientListener : public IDialogDeathRecipientListener {
148 public:
OnDialogDeathRecipient() const149     void OnDialogDeathRecipient() const override
150     {
151     }
152 };
153 
154 class WindowDragListener : public IWindowDragListener {
155 public:
OnDrag(int32_t x,int32_t y,DragEvent event)156     void OnDrag(int32_t x, int32_t y, DragEvent event) override
157     {
158     }
159 };
160 
161 class DisplayMoveListener : public IDisplayMoveListener {
162 public:
OnDisplayMove(DisplayId from,DisplayId to)163     void OnDisplayMove(DisplayId from, DisplayId to) override
164     {
165     }
166 };
167 
168 class AceAbilityHandler : public IAceAbilityHandler {
169 public:
SetBackgroundColor(uint32_t color)170     void SetBackgroundColor(uint32_t color) override
171     {
172     }
173 
GetBackgroundColor()174     virtual uint32_t GetBackgroundColor() override
175     {
176         return 0xffffffff;
177     }
178 };
179 
180 class WindowLifeCycle : public IWindowLifeCycle {
181 public:
AfterForeground()182     void AfterForeground() override
183     {
184     }
185 
AfterBackground()186     void AfterBackground() override
187     {
188     }
189 
AfterFocused()190     void AfterFocused() override
191     {
192     }
193 
AfterUnfocused()194     void AfterUnfocused() override
195     {
196     }
197 
ForegroundFailed(int32_t ret)198     void ForegroundFailed(int32_t ret) override
199     {
200     }
201 
BackgroundFailed(int32_t ret)202     void BackgroundFailed(int32_t ret) override
203     {
204     }
205 
AfterActive()206     void AfterActive() override
207     {
208     }
209 
AfterInactive()210     void AfterInactive()  override
211     {
212     }
213 
AfterResumed()214     void AfterResumed() override
215     {
216     }
217 
AfterPaused()218     void AfterPaused()  override
219     {
220     }
221 };
222 
223 template<class T>
GetObject(T & object,const uint8_t * data,size_t size)224 size_t GetObject(T& object, const uint8_t* data, size_t size)
225 {
226     size_t objectSize = sizeof(object);
227     if (objectSize > size) {
228         return 0;
229     }
230     return memcpy_s(&object, objectSize, data, objectSize) == EOK ? objectSize : 0;
231 }
232 
233 /* 调用该接口后, 需要释放内存 */
CopyDataToString(const uint8_t * data,size_t size)234 char *CopyDataToString(const uint8_t* data, size_t size)
235 {
236     if (size > DATA_MAX_SIZE) {
237         return nullptr;
238     }
239     char *string = (char *)malloc(size);
240     if (string == nullptr) {
241         std::cout << "malloc failed." << std::endl;
242         return nullptr;
243     }
244 
245     if (memcpy_s(string, size, data, size) != EOK) {
246         std::cout << "copy failed." << std::endl;
247         free(string);
248         return nullptr;
249     }
250     return string;
251 }
252 
DoSomethingInterestingWithMyAPI1(const uint8_t * data,size_t size)253 bool DoSomethingInterestingWithMyAPI1(const uint8_t* data, size_t size)
254 {
255     if (data == nullptr || size < DATA_MIN_SIZE) {
256         return false;
257     }
258     std::string name = "WindowFuzzTest1";
259     sptr<WindowOption> option = nullptr;
260     sptr<Window> window = new Window();
261     if (window == nullptr) {
262         return false;
263     }
264     size_t startPos = 0;
265     sptr<IOccupiedAreaChangeListener> iOccupiedAreaChangeListener = new IOccupiedAreaChangeListener();
266     OHOS::Rosen::Rect rect_ = {0, 0, 0, 0};
267     window->RegisterOccupiedAreaChangeListener(iOccupiedAreaChangeListener);
268     int32_t safeHeight = 80;
269     startPos += GetObject<int32_t>(safeHeight, data + startPos, size - startPos);
270     sptr<OHOS::Rosen::OccupiedAreaChangeInfo> info = new OccupiedAreaChangeInfo(
271         OccupiedAreaType::TYPE_INPUT, rect_, safeHeight);
272     iOccupiedAreaChangeListener->OnSizeChange(info, nullptr);
273     window->UnregisterOccupiedAreaChangeListener(iOccupiedAreaChangeListener);
274     sptr<IVisibilityChangedListener> visibilityChangedListener = new VisibilityChangedListener();
275     std::vector<sptr<WindowVisibilityInfo>> infos;
276     visibilityChangedListener->OnWindowVisibilityChanged(infos);
277     return true;
278 }
279 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)280 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
281 {
282     if (data == nullptr || size < DATA_MIN_SIZE) {
283         return false;
284     }
285     std::string name = "WindowFuzzTest";
286     sptr<WindowOption> option = nullptr;
287     sptr<Window> window = new Window();
288     if (window == nullptr) {
289         return false;
290     }
291     std::string windowName = "window test";
292     window->Find(windowName);
293     size_t startPos = 0;
294     std::shared_ptr<AbilityRuntime::Context> context;
295     window->GetTopWindowWithContext(context);
296     uint32_t mainWinId = 1;
297     startPos += GetObject<uint32_t>(mainWinId, data + startPos, size - startPos);
298     window->GetTopWindowWithId(mainWinId);
299     uint32_t parentId = 1;
300     startPos += GetObject<uint32_t>(parentId, data + startPos, size - startPos);
301     window->GetSubWindow(parentId);
302     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
303     window->UpdateConfigurationForAll(configuration);
304     window->Show(0);
305     window->SetRequestedOrientation(static_cast<Orientation>(data[0]));
306     window->Hide(0);
307     window->Destroy();
308     sptr<IFocusChangedListener> focusChangedListener = new FocusChangedListener();
309     sptr<FocusChangeInfo> focusChangeInfo = new FocusChangeInfo();
310     focusChangedListener->OnFocused(focusChangeInfo);
311     focusChangedListener->OnUnfocused(focusChangeInfo);
312     sptr<IDispatchInputEventListener> iDispatchInputEventListener = new IDispatchInputEventListener();
313     std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
314     std::shared_ptr<MMI::PointerEvent> pointerEvent = nullptr;
315     std::shared_ptr<MMI::AxisEvent> axisEvent = nullptr;
316     iDispatchInputEventListener->OnDispatchPointerEvent(pointerEvent);
317     iDispatchInputEventListener->OnDispatchKeyEvent(keyEvent);
318     std::shared_ptr<IInputEventConsumer> iInputEventConsumer = std::make_shared<IInputEventConsumer>();
319     iInputEventConsumer->OnInputEvent(keyEvent);
320     iInputEventConsumer->OnInputEvent(pointerEvent);
321     iInputEventConsumer->OnInputEvent(axisEvent);
322     DoSomethingInterestingWithMyAPI1(data, size);
323     return true;
324 }
325 
CheckWindowImplFunctionsPart1(sptr<Window> window,const uint8_t * data,size_t size)326 void CheckWindowImplFunctionsPart1(sptr<Window> window, const uint8_t* data, size_t size)
327 {
328     size_t startPos = 0;
329 
330     bool boolVal = false;
331     startPos += GetObject(boolVal, data + startPos, size - startPos);
332     window->SetFocusable(boolVal);
333     window->IsFocused();
334     startPos += GetObject(boolVal, data + startPos, size - startPos);
335     window->SetTouchable(boolVal);
336     window->SetResizeByDragEnabled(boolVal);
337     window->SetRaiseByClickEnabled(boolVal);
338     window->HideNonSystemFloatingWindows(boolVal);
339     window->SetSingleFrameComposerEnabled(boolVal);
340 
341     WindowType windowType;
342     WindowMode windowMode;
343     startPos += GetObject(windowType, data + startPos, size - startPos);
344     startPos += GetObject(windowMode, data + startPos, size - startPos);
345     window->SetWindowType(windowType);
346     window->SetWindowMode(windowMode);
347 
348     float alpha;
349     startPos += GetObject(alpha, data + startPos, size - startPos);
350     window->SetAlpha(alpha);
351 
352     Transform transForm;
353     startPos += GetObject(transForm, data + startPos, size - startPos);
354     window->SetTransform(transForm);
355 
356     WindowFlag windowFlag;
357     startPos += GetObject(windowFlag, data + startPos, size - startPos);
358     window->AddWindowFlag(windowFlag);
359     startPos += GetObject(windowFlag, data + startPos, size - startPos);
360     window->RemoveWindowFlag(windowFlag);
361 
362     SystemBarProperty systemBarProperty;
363     startPos += GetObject(windowType, data + startPos, size - startPos);
364     startPos += GetObject(systemBarProperty, data + startPos, size - startPos);
365     window->SetSystemBarProperty(windowType, systemBarProperty);
366 
367     SystemBarProperty systemBarProperty1;
368     startPos += GetObject(windowType, data + startPos, size - startPos);
369     startPos += GetObject(systemBarProperty1, data + startPos, size - startPos);
370     window->SetSpecificBarProperty(windowType, systemBarProperty1);
371 
372     startPos += GetObject(boolVal, data + startPos, size - startPos);
373     window->SetLayoutFullScreen(boolVal);
374 
375     startPos += GetObject(boolVal, data + startPos, size - startPos);
376     window->SetFullScreen(boolVal);
377 
378     startPos += GetObject(boolVal, data + startPos, size - startPos);
379     window->UpdateSurfaceNodeAfterCustomAnimation(boolVal);
380 
381     float grayScale;
382     startPos += GetObject(grayScale, data + startPos, size - startPos);
383     window->SetGrayScale(grayScale);
384 }
385 
CheckWindowImplFunctionsPart2(sptr<WindowImpl> window,const uint8_t * data,size_t size)386 void CheckWindowImplFunctionsPart2(sptr<WindowImpl> window, const uint8_t* data, size_t size)
387 {
388     size_t startPos = 0;
389 
390     int32_t posX;
391     int32_t posY;
392     startPos += GetObject(posX, data + startPos, size - startPos);
393     startPos += GetObject(posY, data + startPos, size - startPos);
394     window->MoveTo(posX, posY);
395 
396     uint32_t width;
397     uint32_t hight;
398     startPos += GetObject(width, data + startPos, size - startPos);
399     startPos += GetObject(hight, data + startPos, size - startPos);
400     window->Resize(width, hight);
401 
402     bool boolVal = false;
403     startPos += GetObject(boolVal, data + startPos, size - startPos);
404     window->SetKeepScreenOn(boolVal);
405 
406     startPos += GetObject(boolVal, data + startPos, size - startPos);
407     window->SetTurnScreenOn(boolVal);
408 
409     startPos += GetObject(boolVal, data + startPos, size - startPos);
410     window->SetTransparent(boolVal);
411 
412     startPos += GetObject(boolVal, data + startPos, size - startPos);
413     window->SetBrightness(boolVal);
414 
415     int32_t windowId;
416     startPos += GetObject(windowId, data + startPos, size - startPos);
417     window->SetCallingWindow(windowId);
418 
419     startPos += GetObject(boolVal, data + startPos, size - startPos);
420     window->SetPrivacyMode(boolVal);
421 
422     startPos += GetObject(boolVal, data + startPos, size - startPos);
423     window->SetSystemPrivacyMode(boolVal);
424 
425     startPos += GetObject(boolVal, data + startPos, size - startPos);
426     window->SetSnapshotSkip(boolVal);
427 }
428 
CheckWindowImplFunctionsPart3(sptr<WindowImpl> window,const uint8_t * data,size_t size)429 void CheckWindowImplFunctionsPart3(sptr<WindowImpl> window, const uint8_t* data, size_t size)
430 {
431     size_t startPos = 0;
432     float floatVal;
433     startPos += GetObject(floatVal, data + startPos, size - startPos);
434     window->SetCornerRadius(floatVal);
435 
436     startPos += GetObject(floatVal, data + startPos, size - startPos);
437     window->SetShadowRadius(floatVal);
438 
439     startPos += GetObject(floatVal, data + startPos, size - startPos);
440     window->SetShadowOffsetX(floatVal);
441     startPos += GetObject(floatVal, data + startPos, size - startPos);
442     window->SetShadowOffsetY(floatVal);
443     startPos += GetObject(floatVal, data + startPos, size - startPos);
444     window->SetBlur(floatVal);
445     startPos += GetObject(floatVal, data + startPos, size - startPos);
446     window->SetBackdropBlur(floatVal);
447 
448     WindowBlurStyle blurStyle;
449     startPos += GetObject(blurStyle, data + startPos, size - startPos);
450     window->SetBackdropBlurStyle(blurStyle);
451 
452     bool boolVal;
453     OHOS::Rosen::Rect rect;
454     WindowSizeChangeReason reason;
455     startPos += GetObject(boolVal, data + startPos, size - startPos);
456     startPos += GetObject(rect, data + startPos, size - startPos);
457     startPos += GetObject(reason, data + startPos, size - startPos);
458     window->UpdateRect(rect, boolVal, reason);
459 
460     WindowMode mode;
461     startPos += GetObject(mode, data + startPos, size - startPos);
462     window->UpdateMode(mode);
463 
464     uint32_t windowModeSupportType;
465     startPos += GetObject(windowModeSupportType, data + startPos, size - startPos);
466     window->UpdateWindowModeSupportType(windowModeSupportType);
467 
468     WindowState windowState;
469     startPos += GetObject(windowState, data + startPos, size - startPos);
470     window->UpdateWindowState(windowState);
471 
472     PointInfo point;
473     DragEvent event;
474     startPos += GetObject(point, data + startPos, size - startPos);
475     startPos += GetObject(event, data + startPos, size - startPos);
476     window->UpdateDragEvent(point, event);
477 
478     DisplayId displayId[2];
479     startPos += GetObject(displayId[0], data + startPos, size - startPos);
480     startPos += GetObject(displayId[1], data + startPos, size - startPos);
481     window->UpdateDisplayId(displayId[0], displayId[1]);
482 }
483 
CheckWindowImplFunctionsPart4(sptr<WindowImpl> window,const uint8_t * data,size_t size)484 void CheckWindowImplFunctionsPart4(sptr<WindowImpl> window, const uint8_t* data, size_t size)
485 {
486     size_t startPos = 0;
487 
488     bool boolVal;
489     startPos += GetObject(boolVal, data + startPos, size - startPos);
490     window->UpdateActiveStatus(boolVal);
491 
492     Transform trans;
493     startPos += GetObject(trans, data + startPos, size - startPos);
494     startPos += GetObject(boolVal, data + startPos, size - startPos);
495     window->UpdateZoomTransform(trans, boolVal);
496 
497     startPos += GetObject(boolVal, data + startPos, size - startPos);
498     window->SetNeedRemoveWindowInputChannel(boolVal);
499     window->SetRequestedOrientation(static_cast<Orientation>(data[0]));
500 
501     startPos += GetObject(boolVal, data + startPos, size - startPos);
502     window->SetImmersiveModeEnabledState(boolVal);
503 
504     std::vector<OHOS::Rosen::Rect> rectVector;
505     OHOS::Rosen::Rect rect;
506     startPos += GetObject(rect, data + startPos, size - startPos);
507     rectVector.emplace_back(rect);
508     window->SetTouchHotAreas(rectVector);
509     window->GetRequestedTouchHotAreas(rectVector);
510     rectVector.clear();
511 
512     ColorSpace colorSpace;
513     startPos += GetObject(colorSpace, data + startPos, size - startPos);
514     window->SetColorSpace(colorSpace);
515 
516     int32_t level;
517     startPos += GetObject(level, data + startPos, size - startPos);
518     window->NotifyMemoryLevel(level);
519 
520     uint32_t mode;
521     startPos += GetObject(mode, data + startPos, size - startPos);
522     window->RestoreSplitWindowMode(mode);
523 }
524 
CheckWindowImplFunctionsPart5(sptr<WindowImpl> window,const uint8_t * data,size_t size)525 void CheckWindowImplFunctionsPart5(sptr<WindowImpl> window, const uint8_t* data, size_t size)
526 {
527     size_t startPos = 0;
528 
529     OHOS::Rosen::Rect rect;
530     WindowSizeChangeReason reason;
531     startPos += GetObject(rect, data + startPos, size - startPos);
532     startPos += GetObject(reason, data + startPos, size - startPos);
533     window->NotifySizeChange(rect, reason);
534 
535     DisplayId displayId[2];
536     startPos += GetObject(displayId[0], data + startPos, size - startPos);
537     startPos += GetObject(displayId[1], data + startPos, size - startPos);
538     window->NotifyDisplayMoveChange(displayId[0], displayId[1]);
539 
540     WindowMode mode;
541     startPos += GetObject(mode, data + startPos, size - startPos);
542     window->NotifyModeChange(mode);
543 
544     PointInfo point;
545     DragEvent dragEvent;
546     startPos += GetObject(point, data + startPos, size - startPos);
547     startPos += GetObject(dragEvent, data + startPos, size - startPos);
548     window->NotifyDragEvent(point, dragEvent);
549 
550     int32_t posX;
551     int32_t posY;
552     int32_t pointId;
553     int32_t sourceType;
554     startPos += GetObject(posX, data + startPos, size - startPos);
555     startPos += GetObject(posY, data + startPos, size - startPos);
556     startPos += GetObject(pointId, data + startPos, size - startPos);
557     startPos += GetObject(sourceType, data + startPos, size - startPos);
558     window->EndMoveOrDragWindow(posX, posY, pointId, sourceType);
559 
560     bool boolVal;
561     startPos += GetObject(boolVal, data + startPos, size - startPos);
562     window->AdjustWindowAnimationFlag(boolVal);
563 
564     PropertyChangeAction action;
565     startPos += GetObject(action, data + startPos, size - startPos);
566     window->UpdateProperty(action);
567 
568     uint32_t uinte32Val;
569     startPos += GetObject(uinte32Val, data + startPos, size - startPos);
570     window->SetBackgroundColor(uinte32Val);
571 
572     LifeCycleEvent lifeCycleEvent;
573     OHOS::Rosen::WMError errCode;
574     startPos += GetObject(lifeCycleEvent, data + startPos, size - startPos);
575     startPos += GetObject(errCode, data + startPos, size - startPos);
576     window->RecordLifeCycleExceptionEvent(lifeCycleEvent, errCode);
577     window->TransferLifeCycleEventToString(lifeCycleEvent);
578 
579     startPos += GetObject(rect, data + startPos, size - startPos);
580     window->GetSystemAlarmWindowDefaultSize(rect);
581     window->HandleModeChangeHotZones(posX, posY);
582 }
583 
CheckWindowImplFunctionsPart6(sptr<WindowImpl> window,const uint8_t * data,size_t size)584 void CheckWindowImplFunctionsPart6(sptr<WindowImpl> window, const uint8_t* data, size_t size)
585 {
586     size_t startPos = 0;
587 
588     TransitionReason reason;
589     startPos += GetObject(reason, data + startPos, size - startPos);
590     window->NotifyWindowTransition(reason);
591 
592     WindowType type;
593     startPos += GetObject(type, data + startPos, size - startPos);
594     window->CheckCameraFloatingWindowMultiCreated(type);
595 
596     uint32_t uint32Val[2];
597     startPos += GetObject(uint32Val[0], data + startPos, size - startPos);
598     startPos += GetObject(uint32Val[1], data + startPos, size - startPos);
599     window->SetWindowModeSupportType(uint32Val[0]);
600 
601     float floatVal;
602     startPos += GetObject(floatVal, data + startPos, size - startPos);
603     window->CalculateStartRectExceptHotZone(floatVal);
604 
605     Transform transform;
606     startPos += GetObject(transform, data + startPos, size - startPos);
607     window->TransformSurfaceNode(transform);
608 
609     window->WindowCreateCheck(uint32Val[0]);
610     window->CalculatePointerDirection(uint32Val[0], uint32Val[1]);
611     sptr<IWindowChangeListener> iWindowChangeListener = new IWindowChangeListener();
612     std::shared_ptr<RSTransaction> rstransaction;
613     OHOS::Rosen::Rect rect_ = {0, 0, 0, 0};
614     iWindowChangeListener->OnSizeChange(rect_, WindowSizeChangeReason::UNDEFINED, rstransaction);
615     sptr<IWindowExtensionCallback> iWindowExtensionCallback = new ExtensionCallback();
616     std::shared_ptr<Rosen::RSSurfaceNode> rsSurfaceNode = nullptr;
617     std::shared_ptr<MMI::KeyEvent> keyEvent = nullptr;
618     iWindowExtensionCallback->OnWindowReady(rsSurfaceNode);
619     iWindowExtensionCallback->OnExtensionDisconnected();
620     iWindowExtensionCallback->OnKeyEvent(keyEvent);
621     std::shared_ptr<MMI::PointerEvent> pointerEvent = MMI::PointerEvent::Create();
622     iWindowExtensionCallback->OnPointerEvent(pointerEvent);
623     iWindowExtensionCallback->OnBackPress();
624 }
625 
CheckShadowColor(sptr<WindowImpl> window,const uint8_t * data,size_t size)626 void CheckShadowColor(sptr<WindowImpl> window, const uint8_t* data, size_t size)
627 {
628     char *str = CopyDataToString(data, size);
629     if (str == nullptr) {
630         return;
631     }
632     std::string color(str, size);
633     window->SetShadowColor(color);
634     free(str);
635     return;
636 }
637 
CheckWindowImplFunctionsPart7(sptr<WindowImpl> window,const uint8_t * data,size_t size)638 void CheckWindowImplFunctionsPart7(sptr<WindowImpl> window, const uint8_t* data, size_t size)
639 {
640     size_t startPos = 0;
641     NotifyNativeWinDestroyFunc func = [](std::string) {};
642     window->RegisterWindowDestroyedListener(func);
643 
644     sptr<IOccupiedAreaChangeListener> occupiedAreaChangeListener = new OccupiedAreaChangeListener();
645     window->RegisterOccupiedAreaChangeListener(occupiedAreaChangeListener);
646     window->UnregisterOccupiedAreaChangeListener(occupiedAreaChangeListener);
647     sptr<ITouchOutsideListener> touchOutsideListener = new TouchOutsideListener();
648     window->RegisterTouchOutsideListener(touchOutsideListener);
649     window->UnregisterTouchOutsideListener(touchOutsideListener);
650     sptr<IAnimationTransitionController> animationTransitionController = new AnimationTransitionController();
651     window->RegisterAnimationTransitionController(animationTransitionController);
652     sptr<IScreenshotListener> screenshotListener = new IScreenshotListener();
653     window->RegisterScreenshotListener(screenshotListener);
654     window->UnregisterScreenshotListener(screenshotListener);
655     sptr<IDialogTargetTouchListener> dialogTargetTouchListener = new DialogTargetTouchListener();
656     window->RegisterDialogTargetTouchListener(dialogTargetTouchListener);
657     window->UnregisterDialogTargetTouchListener(dialogTargetTouchListener);
658     sptr<IDialogDeathRecipientListener> dialogDeathRecipientListener = new DialogDeathRecipientListener();
659     window->RegisterDialogDeathRecipientListener(dialogDeathRecipientListener);
660     window->UnregisterDialogDeathRecipientListener(dialogDeathRecipientListener);
661     sptr<IAceAbilityHandler> aceAbilityHandler = new AceAbilityHandler();
662     window->SetAceAbilityHandler(aceAbilityHandler);
663     uint32_t windowModeSupportType;
664     startPos += GetObject<uint32_t>(windowModeSupportType, data + startPos, size - startPos);
665     window->SetRequestWindowModeSupportType(windowModeSupportType);
666     float ratio;
667     startPos += GetObject<float>(ratio, data + startPos, size - startPos);
668     window->SetAspectRatio(ratio);
669     AvoidAreaType avoidAreaType = AvoidAreaType::TYPE_SYSTEM;
670     AvoidArea avoidArea;
671     startPos += GetObject<AvoidAreaType>(avoidAreaType, data + startPos, size - startPos);
672     startPos += GetObject<OHOS::Rosen::Rect>(avoidArea.topRect_, data + startPos, size - startPos);
673     startPos += GetObject<OHOS::Rosen::Rect>(avoidArea.leftRect_, data + startPos, size - startPos);
674     startPos += GetObject<OHOS::Rosen::Rect>(avoidArea.rightRect_, data + startPos, size - startPos);
675     startPos += GetObject<OHOS::Rosen::Rect>(avoidArea.bottomRect_, data + startPos, size - startPos);
676     window->GetAvoidAreaByType(avoidAreaType, avoidArea);
677     WindowGravity gravity = WindowGravity::WINDOW_GRAVITY_FLOAT;
678     uint32_t invalidGravityPercent = 0;
679     startPos += GetObject<WindowGravity>(gravity, data + startPos, size - startPos);
680     startPos += GetObject<uint32_t>(invalidGravityPercent, data + startPos, size - startPos);
681     window->SetWindowGravity(gravity, invalidGravityPercent);
682     sptr<IRemoteObject> targetToken;
683     window->BindDialogTarget(targetToken);
684     CheckShadowColor(window, data, size);
685 }
686 
CheckWindowImplFunctionsPart8(sptr<WindowImpl> window,const uint8_t * data,size_t size)687 void CheckWindowImplFunctionsPart8(sptr<WindowImpl> window, const uint8_t* data, size_t size)
688 {
689     size_t startPos = 0;
690     std::vector<std::string> params{"-h"};
691     std::vector<std::string> info{""};
692     window->DumpInfo(params, info);
693     params.push_back("");
694     window->DumpInfo(params, info);
695 
696     auto keyEvent = MMI::KeyEvent::Create();
697     window->ConsumeKeyEvent(keyEvent);
698     keyEvent->SetKeyCode(MMI::KeyEvent::KEYCODE_BACK);
699     keyEvent->SetKeyAction(MMI::KeyEvent::KEY_ACTION_UP);
700     window->ConsumeKeyEvent(keyEvent);
701 
702     auto pointerEvent = MMI::PointerEvent::Create();
703     MMI::PointerEvent::PointerItem item;
704     int32_t pointerId = 0;
705     startPos += GetObject<int32_t>(pointerId, data + startPos, size - startPos);
706     pointerEvent->SetPointerId(pointerId);
707     pointerEvent->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_DOWN);
708     window->ConsumePointerEvent(pointerEvent);
709     item.SetPointerId(pointerId);
710     item.SetDisplayX(15); // 15 : position x
711     item.SetDisplayY(15); // 15 : position y
712     pointerEvent->AddPointerItem(item);
713     window->ConsumePointerEvent(pointerEvent);
714     int32_t x = 5;
715     int32_t y = 5;
716     startPos += GetObject<int32_t>(x, data + startPos, size - startPos);
717     startPos += GetObject<int32_t>(y, data + startPos, size - startPos);
718     item.SetDisplayX(x); // 5 : position x
719     item.SetDisplayY(y); // 5 : position y
720     pointerEvent->UpdatePointerItem(pointerId, item);
721     window->ConsumePointerEvent(pointerEvent);
722 }
723 
CheckWindowImplFunctionsPart9(sptr<WindowImpl> window,const uint8_t * data,size_t size)724 void CheckWindowImplFunctionsPart9(sptr<WindowImpl> window, const uint8_t* data, size_t size)
725 {
726     if (data == nullptr || size < DATA_MIN_SIZE) {
727         return;
728     }
729     std::shared_ptr<IInputEventConsumer> iInputEventConsumer = std::make_shared<IInputEventConsumer>();
730     window->SetInputEventConsumer(iInputEventConsumer);
731     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
732     window->UpdateConfiguration(configuration);
733     sptr<IWindowLifeCycle> windowLifeCycleListener = new IWindowLifeCycle();
734     window->RegisterLifeCycleListener(windowLifeCycleListener);
735     window->UnregisterLifeCycleListener(windowLifeCycleListener);
736     sptr<IWindowChangeListener> windowChangeListener = new IWindowChangeListener();
737     window->RegisterWindowChangeListener(sptr<IWindowChangeListener>(windowChangeListener));
738     window->UnregisterWindowChangeListener(sptr<IWindowChangeListener>(windowChangeListener));
739     sptr<IAvoidAreaChangedListener> avoidAreaChangedListener = new IAvoidAreaChangedListener();
740     window->RegisterAvoidAreaChangeListener(avoidAreaChangedListener);
741     window->UnregisterAvoidAreaChangeListener(avoidAreaChangedListener);
742     sptr<IWindowDragListener> windowDragListener = new WindowDragListener();
743     window->RegisterDragListener(windowDragListener);
744     window->UnregisterDragListener(windowDragListener);
745     sptr<IDisplayMoveListener> displayMoveListener = new DisplayMoveListener();
746     window->RegisterDisplayMoveListener(displayMoveListener);
747     window->UnregisterDisplayMoveListener(displayMoveListener);
748     sptr<IWindowVisibilityChangedListener> visibilityChangeListener = new WindowVisibilityChangeListener();
749     window->RegisterWindowVisibilityChangeListener(visibilityChangeListener);
750     window->UnregisterWindowVisibilityChangeListener(visibilityChangeListener);
751     AAFwk::Want want;
752     std::stringstream ss;
753     for (size_t i = 0; i < size; ++i) {
754         ss << data[i];
755     }
756     want.SetParam("__startParams", ss.str());
757     window->OnNewWant(want);
758 }
759 
WindowImplFuzzTest(const uint8_t * data,size_t size)760 void WindowImplFuzzTest(const uint8_t* data, size_t size)
761 {
762     std::string name = "WindowFuzzTest";
763     sptr<OHOS::Rosen::WindowOption> option = new OHOS::Rosen::WindowOption();
764     option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
765     sptr<OHOS::Rosen::WindowImpl> window = new(std::nothrow) OHOS::Rosen::WindowImpl(option);
766     if (window == nullptr) {
767         return;
768     }
769     std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext =
770         std::make_shared<AbilityRuntime::AbilityContextImpl>();
771     window->Create(option->GetParentId(), abilityContext);
772 
773     size_t startPos = 0;
774     uint32_t reason = 0;
775     bool withAnimation = false;
776     startPos += GetObject(reason, data + startPos, size - startPos);
777     startPos += GetObject(withAnimation, data + startPos, size - startPos);
778     window->Show(reason, withAnimation);
779     std::shared_ptr<AbilityRuntime::Context> context;
780     window->GetTopWindowWithContext(context);
781 
782     OHOS::CheckWindowImplFunctionsPart1(window, data, size);
783     OHOS::CheckWindowImplFunctionsPart2(window, data, size);
784     OHOS::CheckWindowImplFunctionsPart3(window, data, size);
785     OHOS::CheckWindowImplFunctionsPart4(window, data, size);
786     OHOS::CheckWindowImplFunctionsPart5(window, data, size);
787     OHOS::CheckWindowImplFunctionsPart6(window, data, size);
788     OHOS::CheckWindowImplFunctionsPart7(window, data, size);
789     OHOS::CheckWindowImplFunctionsPart8(window, data, size);
790     OHOS::CheckWindowImplFunctionsPart9(window, data, size);
791 
792     window->Hide(reason, withAnimation);
793     window->Destroy();
794 }
795 
WindowImplFuzzTest01(const uint8_t * data,size_t size)796 void WindowImplFuzzTest01(const uint8_t* data, size_t size)
797 {
798     std::string name = "WindowFuzzTest01";
799     sptr<OHOS::Rosen::WindowOption> option = new OHOS::Rosen::WindowOption();
800     sptr<OHOS::Rosen::WindowImpl> window = new(std::nothrow) OHOS::Rosen::WindowImpl(option);
801     if (window == nullptr) {
802         return;
803     }
804     sptr<IWindowUpdateListener> windowUpdateListener = new WindowUpdateListener();
805     std::vector<sptr<AccessibilityWindowInfo>> accessibilityWindowInfo;
806     WindowUpdateType type = Rosen::WindowUpdateType::WINDOW_UPDATE_ADDED;
807     windowUpdateListener->OnWindowUpdate(accessibilityWindowInfo, type);
808     std::string windowName = "test1";
809     window->Find(windowName);
810     size_t startPos = 0;
811     uint32_t mainWinId = 1;
812     startPos += GetObject<uint32_t>(mainWinId, data + startPos, size - startPos);
813     window->GetTopWindowWithId(mainWinId);
814     uint32_t parentId = 1;
815     startPos += GetObject<uint32_t>(parentId, data + startPos, size - startPos);
816     window->GetSubWindow(parentId);
817     std::shared_ptr<AppExecFwk::Configuration> configuration = std::make_shared<AppExecFwk::Configuration>();
818     window->UpdateConfigurationForAll(configuration);
819     int32_t x;
820     int32_t y;
821     float scale;
822     startPos += GetObject<int32_t>(x, data + startPos, size - startPos);
823     startPos += GetObject<int32_t>(y, data + startPos, size - startPos);
824     startPos += GetObject<float>(scale, data + startPos, size - startPos);
825     WindowAccessibilityController::GetInstance().SetAnchorAndScale(x, y, scale);
826     int32_t deltaX;
827     int32_t deltaY;
828     startPos += GetObject<int32_t>(deltaX, data + startPos, size - startPos);
829     startPos += GetObject<int32_t>(deltaY, data + startPos, size - startPos);
830     WindowAccessibilityController::GetInstance().SetAnchorOffset(deltaX, deltaY);
831     sptr<WindowExtensionConnection> connection = new(std::nothrow)WindowExtensionConnection();
832     if (connection == nullptr) {
833         return;
834     }
835     AppExecFwk::ElementName element;
836     element.SetBundleName("com.test.windowextension");
837     element.SetAbilityName("WindowExtAbility");
838     Rosen::Rect rect {100, 100, 60, 60};
839     uint32_t uid = 100;
840     uint32_t windowId = INVALID_WINDOW_ID;
841     startPos += GetObject<uint32_t>(uid, data + startPos, size - startPos);
842     startPos += GetObject<uint32_t>(windowId, data + startPos, size - startPos);
843     connection->ConnectExtension(element, rect, uid, windowId, nullptr);
844     connection->SetBounds(rect);
845 }
846 } // namespace.OHOS
847 
848 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)849 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
850 {
851     /* Run your code on data */
852     OHOS::DoSomethingInterestingWithMyAPI(data, size);
853     OHOS::WindowImplFuzzTest(data, size);
854     OHOS::WindowImplFuzzTest01(data, size);
855     return 0;
856 }