• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 "rsrenderserviceconnection_fuzzer.h"
17 
18 #include <climits>
19 #include <cstddef>
20 #include <cstdint>
21 #include <cstdio>
22 #include <cstdlib>
23 #include <fcntl.h>
24 #include <unistd.h>
25 #include <unordered_map>
26 
27 #include "accesstoken_kit.h"
28 #ifdef SUPPORT_ACCESS_TOKEN
29 #include "nativetoken_kit.h"
30 #include "token_setproc.h"
31 #endif
32 #include "ipc_object_proxy.h"
33 #include "ipc_object_stub.h"
34 #include "iremote_object.h"
35 #include "message_parcel.h"
36 #include "securec.h"
37 
38 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
39 #include "ipc_callbacks/pointer_render/pointer_luminance_callback_stub.h"
40 #endif
41 #include "ipc_callbacks/rs_occlusion_change_callback_stub.h"
42 #include "ipc_callbacks/rs_first_frame_commit_callback_stub.h"
43 #include "pipeline/main_thread/rs_render_service.h"
44 #include "pipeline/main_thread/rs_render_service_connection.h"
45 #include "platform/ohos/rs_render_service_connect_hub.cpp"
46 #include "screen_manager/rs_screen_manager.h"
47 #include "transaction/rs_render_service_client.h"
48 #include "transaction/rs_render_service_connection_stub.h"
49 #include "transaction/rs_transaction_proxy.h"
50 
51 namespace OHOS {
52 namespace Rosen {
53 constexpr size_t SCREEN_WIDTH = 100;
54 constexpr size_t SCREEN_HEIGHT = 100;
55 sptr<RSIRenderServiceConnection> rsConn_ = nullptr;
56 namespace {
57 const uint8_t* g_data = nullptr;
58 size_t g_size = 0;
59 size_t g_pos;
60 
61 template<class T>
GetData()62 T GetData()
63 {
64     T object {};
65     size_t objectSize = sizeof(object);
66     if (g_data == nullptr || objectSize > g_size - g_pos) {
67         return object;
68     }
69     errno_t ret = memcpy_s(&object, objectSize, g_data + g_pos, objectSize);
70     if (ret != EOK) {
71         return {};
72     }
73     g_pos += objectSize;
74     return object;
75 }
76 
77 template<>
GetData()78 std::string GetData()
79 {
80     size_t objectSize = GetData<uint8_t>();
81     std::string object(objectSize, '\0');
82     if (g_data == nullptr || objectSize > g_size - g_pos) {
83         return object;
84     }
85     object.assign(reinterpret_cast<const char*>(g_data + g_pos), objectSize);
86     g_pos += objectSize;
87     return object;
88 }
89 } // namespace
90 
Init(const uint8_t * data,size_t size)91 bool Init(const uint8_t* data, size_t size)
92 {
93     if (data == nullptr) {
94         return false;
95     }
96 
97     g_data = data;
98     g_size = size;
99     g_pos = 0;
100 
101     rsConn_ = RSRenderServiceConnectHub::GetRenderService();
102     if (rsConn_ == nullptr) {
103         return false;
104     }
105     return true;
106 }
107 
DoRegisterApplicationAgent()108 bool DoRegisterApplicationAgent()
109 {
110     if (rsConn_ == nullptr) {
111         return false;
112     }
113 
114     uint32_t pid = GetData<uint32_t>();
115     MessageParcel message;
116     auto remoteObject = message.ReadRemoteObject();
117     sptr<IApplicationAgent> app = iface_cast<IApplicationAgent>(remoteObject);
118     rsConn_->RegisterApplicationAgent(pid, app);
119     return true;
120 }
121 
DoCommitTransaction()122 bool DoCommitTransaction()
123 {
124     if (rsConn_ == nullptr) {
125         return false;
126     }
127 
128     auto transactionData = std::make_unique<RSTransactionData>();
129     rsConn_->CommitTransaction(transactionData);
130     return true;
131 }
132 
133 class DerivedSyncTask : public RSSyncTask {
134 public:
135     using RSSyncTask::RSSyncTask;
CheckHeader(Parcel & parcel) const136     bool CheckHeader(Parcel& parcel) const override
137     {
138         return true;
139     }
ReadFromParcel(Parcel & parcel)140     bool ReadFromParcel(Parcel& parcel) override
141     {
142         return true;
143     }
Marshalling(Parcel & parcel) const144     bool Marshalling(Parcel& parcel) const override
145     {
146         return true;
147     }
Process(RSContext & context)148     void Process(RSContext& context) override {}
149 };
DoExecuteSynchronousTask()150 bool DoExecuteSynchronousTask()
151 {
152     if (rsConn_ == nullptr) {
153         return false;
154     }
155 
156     uint64_t timeoutNS = GetData<uint64_t>();
157     auto task = std::make_shared<DerivedSyncTask>(timeoutNS);
158     rsConn_->ExecuteSynchronousTask(task);
159     return true;
160 }
161 
DoGetMemoryGraphic()162 bool DoGetMemoryGraphic()
163 {
164     if (rsConn_ == nullptr) {
165         return false;
166     }
167 
168     int pid = GetData<int>();
169     MemoryGraphic memoryGraphic;
170     rsConn_->GetMemoryGraphic(pid, memoryGraphic);
171     return true;
172 }
173 
DoGetMemoryGraphics()174 bool DoGetMemoryGraphics()
175 {
176     if (rsConn_ == nullptr) {
177         return false;
178     }
179 
180     std::vector<MemoryGraphic> memoryGraphics;
181     rsConn_->GetMemoryGraphics(memoryGraphics);
182     return true;
183 }
184 
DoCreateNodeAndSurface()185 bool DoCreateNodeAndSurface()
186 {
187     if (rsConn_ == nullptr) {
188         return false;
189     }
190     RSSurfaceRenderNodeConfig config = { .id = 0, .name = "test" };
191     bool success;
192     rsConn_->CreateNode(config, success);
193     sptr<Surface> surface = nullptr;
194     rsConn_->CreateNodeAndSurface(config, surface);
195     return true;
196 }
197 
DoGetScreenBacklight()198 bool DoGetScreenBacklight()
199 {
200     if (rsConn_ == nullptr) {
201         return false;
202     }
203     ScreenId id = GetData<uint64_t>();
204     uint32_t setLevel = GetData<uint32_t>();
205     rsConn_->SetScreenBacklight(id, setLevel);
206     int32_t getLevel = GetData<int32_t>();
207     rsConn_->GetScreenBacklight(id, getLevel);
208     return true;
209 }
210 
DoGetScreenType()211 bool DoGetScreenType()
212 {
213     if (rsConn_ == nullptr) {
214         return false;
215     }
216     ScreenId id = GetData<uint64_t>();
217     uint32_t level = GetData<uint32_t>();
218     RSScreenType type = (RSScreenType)level;
219     rsConn_->GetScreenType(id, type);
220     return true;
221 }
222 
DoRegisterBufferAvailableListener()223 bool DoRegisterBufferAvailableListener()
224 {
225     if (rsConn_ == nullptr) {
226         return false;
227     }
228     uint64_t id = GetData<uint64_t>();
229     bool isFromRenderThread = GetData<bool>();
230     sptr<RSIBufferAvailableCallback> cb = nullptr;
231     rsConn_->RegisterBufferAvailableListener(id, cb, isFromRenderThread);
232     return true;
233 }
234 
DoSetScreenSkipFrameInterval()235 bool DoSetScreenSkipFrameInterval()
236 {
237     if (rsConn_ == nullptr) {
238         return false;
239     }
240     ScreenId id = GetData<uint64_t>();
241     uint32_t skipFrameInterval = GetData<uint32_t>();
242     int32_t resCode;
243     rsConn_->SetScreenSkipFrameInterval(id, skipFrameInterval, resCode);
244     return true;
245 }
246 
DoSetPhysicalScreenResolution()247 bool DoSetPhysicalScreenResolution()
248 {
249     if (rsConn_ == nullptr) {
250         return false;
251     }
252     ScreenId id = GetData<uint64_t>();
253     rsConn_->SetPhysicalScreenResolution(id, SCREEN_WIDTH, SCREEN_HEIGHT);
254     return true;
255 }
256 
DoSetVirtualScreenResolution()257 bool DoSetVirtualScreenResolution()
258 {
259     if (rsConn_ == nullptr) {
260         return false;
261     }
262     ScreenId id = GetData<uint64_t>();
263     rsConn_->SetVirtualScreenResolution(id, SCREEN_WIDTH, SCREEN_HEIGHT);
264     rsConn_->GetVirtualScreenResolution(id);
265     return true;
266 }
267 
DoGetScreenSupportedColorGamuts()268 bool DoGetScreenSupportedColorGamuts()
269 {
270     if (rsConn_ == nullptr) {
271         return false;
272     }
273     std::vector<ScreenColorGamut> mode;
274     ScreenId id = GetData<uint64_t>();
275     uint32_t screenCol = GetData<uint32_t>();
276     mode.push_back((ScreenColorGamut)screenCol);
277     rsConn_->GetScreenSupportedColorGamuts(id, mode);
278     std::vector<ScreenHDRMetadataKey> keys;
279     keys.push_back((ScreenHDRMetadataKey)screenCol);
280     rsConn_->GetScreenSupportedMetaDataKeys(id, keys);
281     return true;
282 }
283 
DoGetScreenSupportedModes()284 bool DoGetScreenSupportedModes()
285 {
286     if (rsConn_ == nullptr) {
287         return false;
288     }
289     ScreenId id = GetData<uint64_t>();
290     rsConn_->GetScreenSupportedModes(id);
291     return true;
292 }
293 
DoGetScreenColorGamut()294 bool DoGetScreenColorGamut()
295 {
296     if (rsConn_ == nullptr) {
297         return false;
298     }
299     ScreenId id = GetData<uint64_t>();
300     int32_t modeIdx = GetData<int32_t>();
301     rsConn_->SetScreenColorGamut(id, modeIdx);
302     uint32_t mod = GetData<uint32_t>();
303     ScreenColorGamut mode = (ScreenColorGamut)mod;
304     rsConn_->GetScreenColorGamut(id, mode);
305     return true;
306 }
307 
DoSetScreenPowerStatus()308 bool DoSetScreenPowerStatus()
309 {
310     if (rsConn_ == nullptr) {
311         return false;
312     }
313     ScreenId id = GetData<uint64_t>();
314     uint32_t status = GetData<uint32_t>();
315     rsConn_->SetScreenPowerStatus(id, static_cast<ScreenPowerStatus>(status));
316     rsConn_->GetScreenPowerStatus(id, status);
317     return true;
318 }
319 
DoSetScreenGamutMap()320 bool DoSetScreenGamutMap()
321 {
322     if (rsConn_ == nullptr) {
323         return false;
324     }
325     ScreenId id = GetData<uint64_t>();
326     uint32_t mapMode = GetData<uint32_t>();
327     ScreenGamutMap mode = (ScreenGamutMap)mapMode;
328     rsConn_->SetScreenGamutMap(id, mode);
329     rsConn_->GetScreenGamutMap(id, mode);
330     return true;
331 }
332 
DoSetAppWindowNum()333 bool DoSetAppWindowNum()
334 {
335     if (rsConn_ == nullptr) {
336         return false;
337     }
338     uint32_t num = GetData<uint32_t>();
339     rsConn_->SetAppWindowNum(num);
340     return true;
341 }
342 
DoCreateVirtualScreen()343 bool DoCreateVirtualScreen()
344 {
345     if (rsConn_ == nullptr) {
346         return false;
347     }
348     ScreenId id = GetData<uint64_t>();
349     int32_t flags = GetData<int32_t>();
350     sptr<IConsumerSurface> cSurface = IConsumerSurface::Create("DisplayNode");
351     sptr<IBufferProducer> bp = cSurface->GetProducer();
352     sptr<Surface> pSurface = Surface::CreateSurfaceAsProducer(bp);
353     rsConn_->CreateVirtualScreen("name", SCREEN_WIDTH, SCREEN_HEIGHT, pSurface, id, flags);
354     rsConn_->SetVirtualScreenSurface(id, pSurface);
355     rsConn_->RemoveVirtualScreen(id);
356     return true;
357 }
358 
359 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
DoSetPointerColorInversionConfig()360 bool DoSetPointerColorInversionConfig()
361 {
362     if (rsConn_ == nullptr) {
363         return false;
364     }
365     float darkBuffer = GetData<float>();
366     float brightBuffer = GetData<float>();
367     int64_t interval = GetData<int64_t>();
368     int32_t rangeSize = GetData<int32_t>();
369     rsConn_->SetPointerColorInversionConfig(darkBuffer, brightBuffer, interval, rangeSize);
370     return true;
371 }
372 
DoSetPointerColorInversionEnabled()373 bool DoSetPointerColorInversionEnabled()
374 {
375     if (rsConn_ == nullptr) {
376         return false;
377     }
378     bool enable = GetData<bool>();
379     rsConn_->SetPointerColorInversionEnabled(enable);
380     return true;
381 }
382 
383 class CustomPointerLuminanceChangeCallback : public RSPointerLuminanceChangeCallbackStub {
384 public:
CustomPointerLuminanceChangeCallback(const PointerLuminanceChangeCallback & callback)385     explicit CustomPointerLuminanceChangeCallback(const PointerLuminanceChangeCallback &callback) : cb_(callback) {}
~CustomPointerLuminanceChangeCallback()386     ~CustomPointerLuminanceChangeCallback() override {};
387 
OnPointerLuminanceChanged(int32_t brightness)388     void OnPointerLuminanceChanged(int32_t brightness) override
389     {
390         if (cb_ != nullptr) {
391             cb_(brightness);
392         }
393     }
394 
395 private:
396     PointerLuminanceChangeCallback cb_;
397 };
398 
DoRegisterPointerLuminanceChangeCallback()399 bool DoRegisterPointerLuminanceChangeCallback()
400 {
401     if (rsConn_ == nullptr) {
402         return false;
403     }
404     PointerLuminanceChangeCallback callback = [](int32_t brightness) {};
405     sptr<CustomPointerLuminanceChangeCallback> cb = new CustomPointerLuminanceChangeCallback(callback);
406     rsConn_->RegisterPointerLuminanceChangeCallback(cb);
407     return true;
408 }
409 
DoUnRegisterPointerLuminanceChangeCallback()410 bool DoUnRegisterPointerLuminanceChangeCallback()
411 {
412     if (rsConn_ == nullptr) {
413         return false;
414     }
415     rsConn_->UnRegisterPointerLuminanceChangeCallback();
416     return true;
417 }
418 #endif
419 
DoSetScreenActiveMode()420 bool DoSetScreenActiveMode()
421 {
422     if (rsConn_ == nullptr) {
423         return false;
424     }
425     ScreenId id = GetData<uint64_t>();
426     uint32_t modeId = GetData<uint32_t>();
427     rsConn_->SetScreenActiveMode(id, modeId);
428     RSScreenModeInfo screenModeInfo;
429     rsConn_->GetScreenActiveMode(id, screenModeInfo);
430     return true;
431 }
432 
DoSetScreenActiveRect()433 bool DoSetScreenActiveRect()
434 {
435     if (rsConn_ == nullptr) {
436         return false;
437     }
438     ScreenId id = GetData<uint64_t>();
439     int32_t x = GetData<int32_t>();
440     int32_t y = GetData<int32_t>();
441     int32_t w = GetData<int32_t>();
442     int32_t h = GetData<int32_t>();
443     Rect activeRect {
444         .x = x,
445         .y = y,
446         .w = w,
447         .h = h
448     };
449     uint32_t repCode;
450     rsConn_->SetScreenActiveRect(id, activeRect, repCode);
451     return true;
452 }
453 
DoSetRefreshRateMode()454 bool DoSetRefreshRateMode()
455 {
456     if (rsConn_ == nullptr) {
457         return false;
458     }
459     int32_t refreshRateMode = GetData<int32_t>();
460     rsConn_->SetRefreshRateMode(refreshRateMode);
461     return true;
462 }
463 
DoCreateVSyncConnection()464 bool DoCreateVSyncConnection()
465 {
466     if (rsConn_ == nullptr) {
467         return false;
468     }
469     uint64_t id = GetData<uint64_t>();
470     sptr<VSyncIConnectionToken> token = new IRemoteStub<VSyncIConnectionToken>();
471     sptr<IVSyncConnection> conn = nullptr;
472     VSyncConnParam vsyncConnParam = {id, 0, false};
473     rsConn_->CreateVSyncConnection(conn, "test", token, vsyncConnParam);
474     return true;
475 }
476 
DoSetScreenRefreshRate()477 bool DoSetScreenRefreshRate()
478 {
479     if (rsConn_ == nullptr) {
480         return false;
481     }
482     ScreenId id = GetData<uint64_t>();
483     int32_t sceneId = GetData<int32_t>();
484     int32_t rate = GetData<int32_t>();
485     bool enabled = GetData<bool>();
486     int32_t type = GetData<int32_t>();
487     rsConn_->SetScreenRefreshRate(id, sceneId, rate);
488     rsConn_->GetScreenCurrentRefreshRate(id);
489     rsConn_->GetScreenSupportedRefreshRates(id);
490     rsConn_->GetCurrentRefreshRateMode();
491     rsConn_->GetShowRefreshRateEnabled(enabled);
492     rsConn_->SetShowRefreshRateEnabled(enabled, type);
493     rsConn_->GetRealtimeRefreshRate(id);
494     return true;
495 }
496 
DoGetBitmap()497 bool DoGetBitmap()
498 {
499     if (rsConn_ == nullptr) {
500         return false;
501     }
502     Drawing::Bitmap bm;
503     NodeId id = GetData<uint64_t>();
504     bool success;
505     rsConn_->GetBitmap(id, bm, success);
506     return true;
507 }
508 
DoGetScreenCapability()509 bool DoGetScreenCapability()
510 {
511     if (rsConn_ == nullptr) {
512         return false;
513     }
514     ScreenId id = GetData<uint64_t>();
515     rsConn_->GetScreenCapability(id);
516     return true;
517 }
518 
DoGetScreenData()519 bool DoGetScreenData()
520 {
521     if (rsConn_ == nullptr) {
522         return false;
523     }
524     ScreenId id = GetData<uint64_t>();
525     rsConn_->GetScreenData(id);
526     return true;
527 }
528 
DoGetScreenHDRCapability()529 bool DoGetScreenHDRCapability()
530 {
531     if (rsConn_ == nullptr) {
532         return false;
533     }
534     ScreenId id = GetData<uint64_t>();
535     RSScreenHDRCapability screenHDRCapability;
536     rsConn_->GetScreenHDRCapability(id, screenHDRCapability);
537     return true;
538 }
539 
540 class CustomOcclusionChangeCallback : public RSOcclusionChangeCallbackStub {
541 public:
CustomOcclusionChangeCallback(const OcclusionChangeCallback & callback)542     explicit CustomOcclusionChangeCallback(const OcclusionChangeCallback& callback) : cb_(callback) {}
~CustomOcclusionChangeCallback()543     ~CustomOcclusionChangeCallback() override {};
544 
OnOcclusionVisibleChanged(std::shared_ptr<RSOcclusionData> occlusionData)545     void OnOcclusionVisibleChanged(std::shared_ptr<RSOcclusionData> occlusionData) override
546     {
547         if (cb_ != nullptr) {
548             cb_(occlusionData);
549         }
550     }
551 
552 private:
553     OcclusionChangeCallback cb_;
554 };
555 
DoRegisterOcclusionChangeCallback()556 bool DoRegisterOcclusionChangeCallback()
557 {
558     if (rsConn_ == nullptr) {
559         return false;
560     }
561     OcclusionChangeCallback callback = [](std::shared_ptr<RSOcclusionData> data) {};
562     sptr<CustomOcclusionChangeCallback> cb = new CustomOcclusionChangeCallback(callback);
563     int32_t repCode = GetData<int32_t>();
564     rsConn_->RegisterOcclusionChangeCallback(cb, repCode);
565     return true;
566 }
567 
DoShowWatermark()568 bool DoShowWatermark()
569 {
570 #ifdef SUPPORT_ACCESS_TOKEN
571     if (rsConn_ == nullptr) {
572         return false;
573     }
574     const char *perms[1];
575     perms[0] = "ohos.permission.UPDATE_CONFIGURATION";
576     NativeTokenInfoParams infoInstance = {
577         .dcapsNum = 0,
578         .permsNum = 1,
579         .aclsNum = 0,
580         .dcaps = NULL,
581         .perms = perms,
582         .acls = NULL,
583         .processName = "DoShowWatermark",
584         .aplStr = "system_core",
585     };
586     uint64_t tokenId = GetAccessTokenId(&infoInstance);
587     SetSelfTokenID(tokenId);
588     Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
589     bool isShow = GetData<bool>();
590     std::shared_ptr<Media::PixelMap> pixelMap1;
591     rsConn_->ShowWatermark(pixelMap1, isShow);
592 #endif
593     return true;
594 }
595 
DoTakeSurfaceCapture()596 bool DoTakeSurfaceCapture()
597 {
598     if (rsConn_ == nullptr) {
599         return false;
600     }
601     uint64_t nodeId = GetData<uint64_t>();
602     sptr<RSISurfaceCaptureCallback> callback = nullptr;
603     RSSurfaceCaptureConfig captureConfig;
604     captureConfig.scaleX = GetData<float>();
605     captureConfig.scaleY = GetData<float>();
606     captureConfig.useDma = GetData<bool>();
607     captureConfig.useCurWindow = GetData<bool>();
608     uint8_t type = GetData<uint8_t>();
609     captureConfig.captureType = (SurfaceCaptureType)type;
610     captureConfig.isSync = GetData<bool>();
611     uint8_t listSize = GetData<uint8_t>();
612     for (uint8_t i = 0; i < listSize; ++i) {
613         uint64_t listNodeId = GetData<uint64_t>();
614         captureConfig.blackList.push_back(listNodeId);
615     }
616     captureConfig.mainScreenRect.left_ = GetData<float>();
617     captureConfig.mainScreenRect.top_ = GetData<float>();
618     captureConfig.mainScreenRect.right_ = GetData<float>();
619     captureConfig.mainScreenRect.bottom_ = GetData<float>();
620 
621     rsConn_->TakeSurfaceCapture(nodeId, callback, captureConfig);
622     return true;
623 }
624 
DoSetHwcNodeBounds()625 bool DoSetHwcNodeBounds()
626 {
627     if (rsConn_ == nullptr) {
628         return false;
629     }
630     uint64_t nodeId = GetData<uint64_t>();
631     float positionX = GetData<float>();
632     float positionY = GetData<float>();
633     float positionZ = GetData<float>();
634     float positionW = GetData<float>();
635     rsConn_->SetHwcNodeBounds(nodeId, positionX, positionY, positionZ, positionW);
636     return true;
637 }
638 
DoSetScreenChangeCallback()639 bool DoSetScreenChangeCallback()
640 {
641     if (rsConn_ == nullptr) {
642         return false;
643     }
644     sptr<RSIScreenChangeCallback> callback = nullptr;
645     rsConn_->SetScreenChangeCallback(callback);
646     return true;
647 }
648 
DoSetScreenSwitchingNotifyCallback()649 bool DoSetScreenSwitchingNotifyCallback()
650 {
651     if (rsConn_ == nullptr) {
652         return false;
653     }
654     sptr<RSIScreenSwitchingNotifyCallback> callback = nullptr;
655     rsConn_->SetScreenSwitchingNotifyCallback(callback);
656     return true;
657 }
658 
DoSetFocusAppInfo()659 bool DoSetFocusAppInfo()
660 {
661     if (rsConn_ == nullptr) {
662         return false;
663     }
664 
665     int32_t pid = GetData<int32_t>();
666     int32_t uid = GetData<int32_t>();
667     std::string bundleName = GetData<std::string>();
668     std::string abilityName = GetData<std::string>();
669     uint64_t focusNodeId = GetData<uint64_t>();
670     FocusAppInfo info = {
671         .pid = pid,
672         .uid = uid,
673         .bundleName = bundleName,
674         .abilityName = abilityName,
675         .focusNodeId = focusNodeId};
676     int32_t repCode = GetData<int32_t>();
677     rsConn_->SetFocusAppInfo(info, repCode);
678     return true;
679 }
680 
DoSetAncoForceDoDirect()681 bool DoSetAncoForceDoDirect()
682 {
683     if (rsConn_ == nullptr) {
684         return false;
685     }
686 
687     bool direct = GetData<bool>();
688     bool res;
689     rsConn_->SetAncoForceDoDirect(direct, res);
690     return true;
691 }
692 
DoGetActiveDirtyRegionInfo()693 bool DoGetActiveDirtyRegionInfo()
694 {
695     if (rsConn_ == nullptr) {
696         return false;
697     }
698 
699     rsConn_->GetActiveDirtyRegionInfo();
700     return true;
701 }
702 
DoGetGlobalDirtyRegionInfo()703 bool DoGetGlobalDirtyRegionInfo()
704 {
705     if (rsConn_ == nullptr) {
706         return false;
707     }
708 
709     rsConn_->GetGlobalDirtyRegionInfo();
710     return true;
711 }
712 
DoNotifySoftVsyncRateDiscountEvent()713 bool DoNotifySoftVsyncRateDiscountEvent()
714 {
715     if (rsConn_ == nullptr) {
716         return false;
717     }
718     uint32_t pid = GetData<uint32_t>();
719     std::string name = GetData<std::string>();
720     uint32_t rateDiscount = GetData<uint32_t>();
721     bool result = rsConn_->NotifySoftVsyncRateDiscountEvent(pid, name, rateDiscount);
722     return result;
723 }
724 
DoGetLayerComposeInfo()725 bool DoGetLayerComposeInfo()
726 {
727     if (rsConn_ == nullptr) {
728         return false;
729     }
730 
731     rsConn_->GetLayerComposeInfo();
732     return true;
733 }
734 
DoGetHwcDisabledReasonInfo()735 bool DoGetHwcDisabledReasonInfo()
736 {
737     if (rsConn_ == nullptr) {
738         return false;
739     }
740 
741     rsConn_->GetHwcDisabledReasonInfo();
742     return true;
743 }
744 
DoGetUniRenderEnabled()745 bool DoGetUniRenderEnabled()
746 {
747     if (rsConn_ == nullptr) {
748         return false;
749     }
750     bool enable;
751     rsConn_->GetUniRenderEnabled(enable);
752     return true;
753 }
754 
DoCreateNode1()755 bool DoCreateNode1()
756 {
757     if (rsConn_ == nullptr) {
758         return false;
759     }
760     RSDisplayNodeConfig displayNodeConfig;
761     displayNodeConfig.screenId = GetData<uint64_t>();
762     displayNodeConfig.isMirrored = GetData<bool>();
763     displayNodeConfig.mirrorNodeId = GetData<uint64_t>();
764     displayNodeConfig.isSync = GetData<bool>();
765     uint64_t nodeId = GetData<uint64_t>();
766     bool success;
767     rsConn_->CreateNode(displayNodeConfig, nodeId, success);
768     return true;
769 }
770 
DoCreateNode2()771 bool DoCreateNode2()
772 {
773     if (rsConn_ == nullptr) {
774         return false;
775     }
776     RSSurfaceRenderNodeConfig config;
777     config.id = GetData<uint64_t>();
778     config.name = GetData<std::string>();
779     bool success;
780     rsConn_->CreateNode(config, success);
781     return true;
782 }
783 
DoGetDefaultScreenId()784 bool DoGetDefaultScreenId()
785 {
786     if (rsConn_ == nullptr) {
787         return false;
788     }
789     uint64_t screenId = GetData<uint64_t>();
790     rsConn_->GetDefaultScreenId(screenId);
791     return true;
792 }
793 
DoGetActiveScreenId()794 bool DoGetActiveScreenId()
795 {
796     if (rsConn_ == nullptr) {
797         return false;
798     }
799     uint64_t screenId = GetData<uint64_t>();
800     rsConn_->GetActiveScreenId(screenId);
801     return true;
802 }
803 
DoGetAllScreenIds()804 bool DoGetAllScreenIds()
805 {
806     if (rsConn_ == nullptr) {
807         return false;
808     }
809     rsConn_->GetAllScreenIds();
810     return true;
811 }
812 
DoGetTotalAppMemSize()813 bool DoGetTotalAppMemSize()
814 {
815     if (rsConn_ == nullptr) {
816         return false;
817     }
818     float cpuMemSize = GetData<float>();
819     float gpuMemSize = GetData<float>();
820     rsConn_->GetTotalAppMemSize(cpuMemSize, gpuMemSize);
821     return true;
822 }
823 
DoSetVirtualScreenAutoRotation()824 bool DoSetVirtualScreenAutoRotation()
825 {
826     if (rsConn_ == nullptr) {
827         return false;
828     }
829     ScreenId screenId = GetData<ScreenId>();
830     bool isAutoRotation = GetData<bool>();
831     rsConn_->SetVirtualScreenAutoRotation(screenId, isAutoRotation);
832     return true;
833 }
834 
DoSetVirtualScreenBlackList()835 bool DoSetVirtualScreenBlackList()
836 {
837     if (rsConn_ == nullptr) {
838         return false;
839     }
840     uint64_t id = GetData<uint64_t>();
841     uint64_t nodeId = GetData<uint64_t>();
842     std::vector<uint64_t> blackListVector;
843     blackListVector.push_back(nodeId);
844     rsConn_->SetVirtualScreenBlackList(id, blackListVector);
845     return true;
846 }
847 
DoAddVirtualScreenBlackList()848 bool DoAddVirtualScreenBlackList()
849 {
850     if (rsConn_ == nullptr) {
851         return false;
852     }
853     uint64_t id = GetData<uint64_t>();
854     std::vector<NodeId> blackListVector;
855     uint8_t listSize = GetData<uint8_t>();
856     for (uint8_t i = 0; i < listSize; ++i) {
857         NodeId nodeId = GetData<NodeId>();
858         blackListVector.push_back(nodeId);
859     }
860     int32_t repCode = 0;
861     rsConn_->AddVirtualScreenBlackList(id, blackListVector, repCode);
862     return true;
863 }
864 
DoRemoveVirtualScreenBlackList()865 bool DoRemoveVirtualScreenBlackList()
866 {
867     if (rsConn_ == nullptr) {
868         return false;
869     }
870     uint64_t id = GetData<uint64_t>();
871     std::vector<NodeId> blackListVector;
872     uint8_t listSize = GetData<uint8_t>();
873     for (uint8_t i = 0; i < listSize; ++i) {
874         NodeId nodeId = GetData<NodeId>();
875         blackListVector.push_back(nodeId);
876     }
877     int32_t repCode = 0;
878     rsConn_->RemoveVirtualScreenBlackList(id, blackListVector, repCode);
879     return true;
880 }
881 
DoSetVirtualScreenSecurityExemptionList()882 bool DoSetVirtualScreenSecurityExemptionList()
883 {
884     if (rsConn_ == nullptr) {
885         return false;
886     }
887     uint64_t id = GetData<uint64_t>();
888     uint64_t nodeId = GetData<uint64_t>();
889     std::vector<uint64_t> securityExemptionList;
890     securityExemptionList.push_back(nodeId);
891     rsConn_->SetVirtualScreenSecurityExemptionList(id, securityExemptionList);
892     return true;
893 }
894 
DoSetCastScreenEnableSkipWindow()895 bool DoSetCastScreenEnableSkipWindow()
896 {
897     if (rsConn_ == nullptr) {
898         return false;
899     }
900     uint64_t id = GetData<uint64_t>();
901     bool enable = GetData<bool>();
902     rsConn_->SetCastScreenEnableSkipWindow(id, enable);
903     return true;
904 }
905 
DoSyncFrameRateRange()906 bool DoSyncFrameRateRange()
907 {
908     if (rsConn_ == nullptr) {
909         return false;
910     }
911     uint64_t id = GetData<uint64_t>();
912     FrameRateRange range;
913     int32_t animatorExpectedFrameRate = GetData<int32_t>();
914     rsConn_->SyncFrameRateRange(id, range, animatorExpectedFrameRate);
915     return true;
916 }
917 
DoUnregisterFrameRateLinker()918 bool DoUnregisterFrameRateLinker()
919 {
920     if (rsConn_ == nullptr) {
921         return false;
922     }
923     uint64_t id = GetData<uint64_t>();
924     rsConn_->UnregisterFrameRateLinker(id);
925     return true;
926 }
927 
DoMarkPowerOffNeedProcessOneFrame()928 bool DoMarkPowerOffNeedProcessOneFrame()
929 {
930     if (rsConn_ == nullptr) {
931         return false;
932     }
933     rsConn_->MarkPowerOffNeedProcessOneFrame();
934     return true;
935 }
936 
DoDisablePowerOffRenderControl()937 bool DoDisablePowerOffRenderControl()
938 {
939     if (rsConn_ == nullptr) {
940         return false;
941     }
942     uint64_t id = GetData<uint64_t>();
943     rsConn_->DisablePowerOffRenderControl(id);
944     return true;
945 }
946 
DoSetScreenCorrection()947 bool DoSetScreenCorrection()
948 {
949     if (rsConn_ == nullptr) {
950         return false;
951     }
952     uint64_t id = GetData<uint64_t>();
953     uint32_t screenRotation = GetData<uint32_t>();
954     rsConn_->SetScreenCorrection(id, static_cast<ScreenRotation>(screenRotation));
955     return true;
956 }
957 
DoSetVirtualMirrorScreenCanvasRotation()958 bool DoSetVirtualMirrorScreenCanvasRotation()
959 {
960     if (rsConn_ == nullptr) {
961         return false;
962     }
963     uint64_t id = GetData<uint64_t>();
964     bool canvasRotation = GetData<bool>();
965     rsConn_->SetVirtualMirrorScreenCanvasRotation(id, canvasRotation);
966     return true;
967 }
968 
DoSetVirtualMirrorScreenScaleMode()969 bool DoSetVirtualMirrorScreenScaleMode()
970 {
971     if (rsConn_ == nullptr) {
972         return false;
973     }
974     uint64_t id = GetData<uint64_t>();
975     uint32_t scaleMode = GetData<uint32_t>();
976     rsConn_->SetVirtualMirrorScreenScaleMode(id, static_cast<ScreenScaleMode>(scaleMode));
977     return true;
978 }
979 
DoSetGlobalDarkColorMode()980 bool DoSetGlobalDarkColorMode()
981 {
982     if (rsConn_ == nullptr) {
983         return false;
984     }
985     bool isDark = GetData<bool>();
986     rsConn_->SetGlobalDarkColorMode(isDark);
987     return true;
988 }
989 
DoSetPixelFormat()990 bool DoSetPixelFormat()
991 {
992     if (rsConn_ == nullptr) {
993         return false;
994     }
995     uint64_t id = GetData<uint64_t>();
996     uint32_t pixelFormat = GetData<uint32_t>();
997     int32_t resCode;
998     rsConn_->SetPixelFormat(id, static_cast<GraphicPixelFormat>(pixelFormat), resCode);
999     GraphicPixelFormat pixelFormat1;
1000     rsConn_->GetPixelFormat(id, pixelFormat1, resCode);
1001     return true;
1002 }
1003 
DOGetScreenSupportedHDRFormats()1004 bool DOGetScreenSupportedHDRFormats()
1005 {
1006     if (rsConn_ == nullptr) {
1007         return false;
1008     }
1009     uint64_t id = GetData<uint64_t>();
1010     int32_t modeIdx = GetData<int32_t>();
1011     int32_t resCode;
1012     rsConn_->SetScreenHDRFormat(id, modeIdx, resCode);
1013     ScreenHDRFormat hdrFormat;
1014     rsConn_->GetScreenHDRFormat(id, hdrFormat, resCode);
1015     std::vector<ScreenHDRFormat> hdrFormats;
1016     rsConn_->GetScreenSupportedHDRFormats(id, hdrFormats, resCode);
1017     return true;
1018 }
1019 
DOGetScreenSupportedColorSpaces()1020 bool DOGetScreenSupportedColorSpaces()
1021 {
1022     if (rsConn_ == nullptr) {
1023         return false;
1024     }
1025     uint64_t id = GetData<uint64_t>();
1026     uint32_t colorSpace = GetData<uint32_t>();
1027     int32_t resCode;
1028     rsConn_->SetScreenColorSpace(id, static_cast<GraphicCM_ColorSpaceType>(colorSpace), resCode);
1029     std::vector<GraphicCM_ColorSpaceType> colorSpaces;
1030     rsConn_->GetScreenSupportedColorSpaces(id, colorSpaces, resCode);
1031     return true;
1032 }
1033 
DOSetVirtualScreenRefreshRate()1034 bool DOSetVirtualScreenRefreshRate()
1035 {
1036     if (rsConn_ == nullptr) {
1037         return false;
1038     }
1039     uint64_t id = GetData<uint64_t>();
1040     uint32_t maxRefreshRate = GetData<uint32_t>();
1041     uint32_t actualRefreshRate = GetData<uint32_t>();
1042     int32_t resCode;
1043     rsConn_->SetVirtualScreenRefreshRate(id, maxRefreshRate, actualRefreshRate, resCode);
1044     return true;
1045 }
1046 
DOSetSystemAnimatedScenes()1047 bool DOSetSystemAnimatedScenes()
1048 {
1049     if (rsConn_ == nullptr) {
1050         return false;
1051     }
1052     uint32_t systemAnimatedScenes = GetData<uint32_t>();
1053     bool success = GetData<bool>();
1054     rsConn_->SetSystemAnimatedScenes(static_cast<SystemAnimatedScenes>(systemAnimatedScenes), false, success);
1055     return true;
1056 }
1057 
DOResizeVirtualScreen()1058 bool DOResizeVirtualScreen()
1059 {
1060     if (rsConn_ == nullptr) {
1061         return false;
1062     }
1063     uint64_t id = GetData<uint64_t>();
1064     uint32_t width = GetData<uint32_t>();
1065     uint32_t height = GetData<uint32_t>();
1066     rsConn_->ResizeVirtualScreen(id, width, height);
1067     return true;
1068 }
1069 
DOReportJankStats()1070 bool DOReportJankStats()
1071 {
1072     if (rsConn_ == nullptr) {
1073         return false;
1074     }
1075     rsConn_->ReportJankStats();
1076     return true;
1077 }
1078 
DOReportEventResponse()1079 bool DOReportEventResponse()
1080 {
1081     if (rsConn_ == nullptr) {
1082         return false;
1083     }
1084     DataBaseRs info;
1085     info.appPid = GetData<int32_t>();
1086     info.eventType = GetData<int32_t>();
1087     info.versionCode = GetData<int32_t>();
1088     info.uniqueId = GetData<int64_t>();
1089     info.inputTime = GetData<int64_t>();
1090     info.beginVsyncTime = GetData<int64_t>();
1091     info.endVsyncTime = GetData<int64_t>();
1092     info.isDisplayAnimator = GetData<bool>();
1093     info.sceneId = GetData<std::string>();
1094     info.versionName = GetData<std::string>();
1095     info.bundleName = GetData<std::string>();
1096     info.processName = GetData<std::string>();
1097     info.abilityName = GetData<std::string>();
1098     info.pageUrl = GetData<std::string>();
1099     info.sourceType = GetData<std::string>();
1100     info.note = GetData<std::string>();
1101     rsConn_->ReportEventJankFrame(info);
1102     rsConn_->ReportEventResponse(info);
1103     return true;
1104 }
1105 
DOReportEventComplete()1106 bool DOReportEventComplete()
1107 {
1108     if (rsConn_ == nullptr) {
1109         return false;
1110     }
1111     DataBaseRs info;
1112     info.appPid = GetData<int32_t>();
1113     info.eventType = GetData<int32_t>();
1114     info.versionCode = GetData<int32_t>();
1115     info.uniqueId = GetData<int64_t>();
1116     info.inputTime = GetData<int64_t>();
1117     info.beginVsyncTime = GetData<int64_t>();
1118     info.endVsyncTime = GetData<int64_t>();
1119     info.isDisplayAnimator = GetData<bool>();
1120     info.sceneId = GetData<std::string>();
1121     info.versionName = GetData<std::string>();
1122     info.bundleName = GetData<std::string>();
1123     info.processName = GetData<std::string>();
1124     info.abilityName = GetData<std::string>();
1125     info.pageUrl = GetData<std::string>();
1126     info.sourceType = GetData<std::string>();
1127     info.note = GetData<std::string>();
1128     rsConn_->ReportEventJankFrame(info);
1129     rsConn_->ReportEventComplete(info);
1130     return true;
1131 }
1132 
DOReportEventJankFrame()1133 bool DOReportEventJankFrame()
1134 {
1135     if (rsConn_ == nullptr) {
1136         return false;
1137     }
1138     DataBaseRs info;
1139     info.appPid = GetData<int32_t>();
1140     info.eventType = GetData<int32_t>();
1141     info.versionCode = GetData<int32_t>();
1142     info.uniqueId = GetData<int64_t>();
1143     info.inputTime = GetData<int64_t>();
1144     info.beginVsyncTime = GetData<int64_t>();
1145     info.endVsyncTime = GetData<int64_t>();
1146     info.isDisplayAnimator = GetData<bool>();
1147     info.sceneId = GetData<std::string>();
1148     info.versionName = GetData<std::string>();
1149     info.bundleName = GetData<std::string>();
1150     info.processName = GetData<std::string>();
1151     info.abilityName = GetData<std::string>();
1152     info.pageUrl = GetData<std::string>();
1153     info.sourceType = GetData<std::string>();
1154     info.note = GetData<std::string>();
1155     rsConn_->ReportEventJankFrame(info);
1156     return true;
1157 }
1158 
DOReportGameStateData()1159 bool DOReportGameStateData()
1160 {
1161     if (rsConn_ == nullptr) {
1162         return false;
1163     }
1164     GameStateData info;
1165     info.pid = GetData<int32_t>();
1166     info.uid = GetData<int32_t>();
1167     info.state = GetData<int32_t>();
1168     info.renderTid = GetData<int32_t>();
1169     info.bundleName = GetData<std::string>();
1170     rsConn_->ReportGameStateData(info);
1171     return true;
1172 }
1173 
DOSetHidePrivacyContent()1174 bool DOSetHidePrivacyContent()
1175 {
1176     if (rsConn_ == nullptr) {
1177         return false;
1178     }
1179     uint32_t id = GetData<uint32_t>();
1180     bool needHidePrivacyContent = GetData<bool>();
1181     uint32_t resCode;
1182     rsConn_->SetHidePrivacyContent(id, needHidePrivacyContent, resCode);
1183     return true;
1184 }
1185 
DONotifyLightFactorStatus()1186 bool DONotifyLightFactorStatus()
1187 {
1188     if (rsConn_ == nullptr) {
1189         return false;
1190     }
1191     int32_t lightFactorStatus = GetData<int32_t>();
1192     rsConn_->NotifyLightFactorStatus(lightFactorStatus);
1193     return true;
1194 }
1195 
DONotifyPackageEvent()1196 bool DONotifyPackageEvent()
1197 {
1198     if (rsConn_ == nullptr) {
1199         return false;
1200     }
1201     uint32_t listSize = GetData<uint32_t>();
1202     std::string package = GetData<std::string>();
1203     std::vector<std::string> packageList;
1204     packageList.push_back(package);
1205     rsConn_->NotifyPackageEvent(listSize, packageList);
1206     return true;
1207 }
1208 
1209 
DONotifyAppStrategyConfigChangeEvent()1210 bool DONotifyAppStrategyConfigChangeEvent()
1211 {
1212     if (rsConn_ == nullptr) {
1213         return false;
1214     }
1215     std::string pkgName = GetData<std::string>();
1216     uint32_t listSize = GetData<uint32_t>();
1217     std::string configKey = GetData<std::string>();
1218     std::string configValue = GetData<std::string>();
1219     std::vector<std::pair<std::string, std::string>> newConfig;
1220     newConfig.push_back(make_pair(configKey, configValue));
1221     rsConn_->NotifyAppStrategyConfigChangeEvent(pkgName, listSize, newConfig);
1222     return true;
1223 }
1224 
DONotifyRefreshRateEvent()1225 bool DONotifyRefreshRateEvent()
1226 {
1227     if (rsConn_ == nullptr) {
1228         return false;
1229     }
1230     EventInfo eventInfo;
1231     eventInfo.eventName = GetData<std::string>();
1232     eventInfo.eventStatus = GetData<bool>();
1233     eventInfo.minRefreshRate = GetData<uint32_t>();
1234     eventInfo.maxRefreshRate = GetData<uint32_t>();
1235     eventInfo.description = GetData<std::string>();
1236     rsConn_->NotifyRefreshRateEvent(eventInfo);
1237     return true;
1238 }
1239 
DONotifyTouchEvent()1240 bool DONotifyTouchEvent()
1241 {
1242     if (rsConn_ == nullptr) {
1243         return false;
1244     }
1245     int32_t touchStatus = GetData<int32_t>();
1246     int32_t touchCnt = GetData<int32_t>();
1247     rsConn_->NotifyTouchEvent(touchStatus, touchCnt);
1248     return true;
1249 }
1250 
DONotifyDynamicModeEvent()1251 bool DONotifyDynamicModeEvent()
1252 {
1253     if (rsConn_ == nullptr) {
1254         return false;
1255     }
1256     bool enableDynamicMode = GetData<bool>();
1257     rsConn_->NotifyDynamicModeEvent(enableDynamicMode);
1258     return true;
1259 }
1260 
DONotifyHgmConfigEvent()1261 bool DONotifyHgmConfigEvent()
1262 {
1263     if (rsConn_ == nullptr) {
1264         return false;
1265     }
1266     std::string eventName = GetData<std::string>();
1267     bool state = GetData<bool>();
1268     rsConn_->NotifyHgmConfigEvent(eventName, state);
1269     return true;
1270 }
1271 
DONotifyXComponentExpectedFrameRate()1272 bool DONotifyXComponentExpectedFrameRate()
1273 {
1274     if (rsConn_ == nullptr) {
1275         return false;
1276     }
1277     std::string id = GetData<std::string>();
1278     int32_t expectedFrameRate = GetData<int32_t>();
1279     rsConn_->NotifyXComponentExpectedFrameRate(id, expectedFrameRate);
1280     return true;
1281 }
1282 
DOSetCacheEnabledForRotation()1283 bool DOSetCacheEnabledForRotation()
1284 {
1285     if (rsConn_ == nullptr) {
1286         return false;
1287     }
1288     bool isEnabled = GetData<bool>();
1289     rsConn_->SetCacheEnabledForRotation(isEnabled);
1290     return true;
1291 }
1292 
DOSetOnRemoteDiedCallback()1293 bool DOSetOnRemoteDiedCallback()
1294 {
1295     if (rsConn_ == nullptr) {
1296         return false;
1297     }
1298     OnRemoteDiedCallback callback;
1299     rsConn_->SetOnRemoteDiedCallback(callback);
1300     return true;
1301 }
1302 
DOSetVmaCacheStatus()1303 bool DOSetVmaCacheStatus()
1304 {
1305     if (rsConn_ == nullptr) {
1306         return false;
1307     }
1308     bool flag = GetData<bool>();
1309     rsConn_->SetVmaCacheStatus(flag);
1310     return true;
1311 }
1312 
1313 #ifdef TP_FEATURE_ENABLE
DOSetTpFeatureConfig()1314 bool DOSetTpFeatureConfig()
1315 {
1316     if (rsConn_ == nullptr) {
1317         return false;
1318     }
1319     int32_t feature = GetData<int32_t>();
1320     char config = GetData<char>();
1321     auto tpFeatureConfigType = static_cast<TpFeatureConfigType>(GetData<uint8_t>());
1322     rsConn_->SetTpFeatureConfig(feature, &config, tpFeatureConfigType);
1323     return true;
1324 }
1325 #endif
1326 
DOSetVirtualScreenUsingStatus()1327 bool DOSetVirtualScreenUsingStatus()
1328 {
1329     if (rsConn_ == nullptr) {
1330         return false;
1331     }
1332     bool isVirtualScreenUsingStatus = GetData<bool>();
1333     rsConn_->SetVirtualScreenUsingStatus(isVirtualScreenUsingStatus);
1334     return true;
1335 }
1336 
DOSetCurtainScreenUsingStatus()1337 bool DOSetCurtainScreenUsingStatus()
1338 {
1339     if (rsConn_ == nullptr) {
1340         return false;
1341     }
1342     bool isCurtainScreenOn = GetData<bool>();
1343     rsConn_->SetCurtainScreenUsingStatus(isCurtainScreenOn);
1344     return true;
1345 }
1346 
DOSetVirtualScreenStatus()1347 bool DOSetVirtualScreenStatus()
1348 {
1349     if (rsConn_ == nullptr) {
1350         return false;
1351     }
1352     uint64_t id = GetData<uint64_t>();
1353     uint64_t screenStatus = GetData<uint64_t>();
1354     bool success;
1355     rsConn_->SetVirtualScreenStatus(id, static_cast<VirtualScreenStatus>(screenStatus), success);
1356     return true;
1357 }
1358 
DOSetLayerTop()1359 bool DOSetLayerTop()
1360 {
1361     if (rsConn_ == nullptr) {
1362         return false;
1363     }
1364     std::string nodeIdStr = GetData<std::string>();
1365     bool isTop = GetData<bool>();
1366     rsConn_->SetLayerTop(nodeIdStr, isTop);
1367     return true;
1368 }
1369 
DoSetForceRefresh()1370 bool DoSetForceRefresh()
1371 {
1372     if (rsConn_ == nullptr) {
1373         return false;
1374     }
1375     std::string nodeIdStr = GetData<std::string>();
1376     bool isForceRefresh = GetData<bool>();
1377     rsConn_->SetForceRefresh(nodeIdStr, isForceRefresh);
1378     return true;
1379 }
1380 
DOSetFreeMultiWindowStatus()1381 bool DOSetFreeMultiWindowStatus()
1382 {
1383     if (rsConn_ == nullptr) {
1384         return false;
1385     }
1386 
1387     bool enable = GetData<bool>();
1388     rsConn_->SetFreeMultiWindowStatus(enable);
1389     return true;
1390 }
1391 
DoNotifySoftVsyncEvent()1392 bool DoNotifySoftVsyncEvent()
1393 {
1394     auto rsConn  = RSRenderServiceConnectHub::GetRenderService();
1395     if (rsConn == nullptr) {
1396         return false;
1397     }
1398     uint32_t pid = GetData<uint32_t>();
1399     uint32_t rateDiscount = GetData<uint32_t>();
1400     rsConn->NotifySoftVsyncEvent(pid, rateDiscount);
1401     return true;
1402 }
1403 
DoCreatePixelMapFromSurface()1404 bool DoCreatePixelMapFromSurface()
1405 {
1406     sptr<IConsumerSurface> cSurface = IConsumerSurface::Create("FuzzTest");
1407     sptr<IBufferProducer> bp = cSurface->GetProducer();
1408     sptr<Surface> pSurface = Surface::CreateSurfaceAsProducer(bp);
1409     if (pSurface == nullptr) {
1410         return false;
1411     }
1412 
1413     auto srcRect = Rect {
1414         .x = GetData<int32_t>(),
1415         .y = GetData<int32_t>(),
1416         .w = GetData<int32_t>(),
1417         .h = GetData<int32_t>(),
1418     };
1419     std::shared_ptr<Media::PixelMap> pixelMap = nullptr;
1420     rsConn_->CreatePixelMapFromSurface(pSurface, srcRect, pixelMap);
1421     return true;
1422 }
1423 
1424 #ifdef RS_ENABLE_OVERLAY_DISPLAY
DoSetOverlayDisplayMode()1425 bool DoSetOverlayDisplayMode()
1426 {
1427     if (rsConn_ == nullptr) {
1428         return false;
1429     }
1430     int32_t mode = GetData<int32_t>();
1431     rsConn_->SetOverlayDisplayMode(mode);
1432     return true;
1433 }
1434 #endif
1435 
DoSetBehindWindowFilterEnabled()1436 bool DoSetBehindWindowFilterEnabled()
1437 {
1438     if (rsConn_ == nullptr) {
1439         return false;
1440     }
1441     bool enabled = GetData<bool>();
1442     rsConn_->SetBehindWindowFilterEnabled(enabled);
1443     return true;
1444 }
1445 
DoGetBehindWindowFilterEnabled()1446 bool DoGetBehindWindowFilterEnabled()
1447 {
1448     if (rsConn_ == nullptr) {
1449         return false;
1450     }
1451     bool res = true;
1452     rsConn_->GetBehindWindowFilterEnabled(res);
1453     return true;
1454 }
1455 
DoProfilerServiceOpenFile()1456 bool DoProfilerServiceOpenFile()
1457 {
1458     if (rsConn_ == nullptr) {
1459         return false;
1460     }
1461     int32_t fd = 0;
1462     HrpServiceDirInfo dirInfo{HrpServiceDir::HRP_SERVICE_DIR_UNKNOWN, "", ""};
1463     rsConn_->ProfilerServiceOpenFile(dirInfo, "", 0, fd);
1464     return true;
1465 }
1466 
DoProfilerServicePopulateFiles()1467 bool DoProfilerServicePopulateFiles()
1468 {
1469     if (rsConn_ == nullptr) {
1470         return false;
1471     }
1472     std::vector<HrpServiceFileInfo> outFiles;
1473     HrpServiceDirInfo dirInfo{HrpServiceDir::HRP_SERVICE_DIR_UNKNOWN, "", ""};
1474     rsConn_->ProfilerServicePopulateFiles(dirInfo, 0, outFiles);
1475     return true;
1476 }
1477 
DoProfilerIsSecureScreen()1478 bool DoProfilerIsSecureScreen()
1479 {
1480     if (rsConn_ == nullptr) {
1481         return false;
1482     }
1483     rsConn_->ProfilerIsSecureScreen();
1484     return true;
1485 }
1486 
1487 class CustomFirstFrameCommitCallback : public RSFirstFrameCommitCallbackStub {
1488 public:
CustomFirstFrameCommitCallback(const FirstFrameCommitCallback & callback)1489     explicit CustomFirstFrameCommitCallback(const FirstFrameCommitCallback& callback) : cb_(callback) {}
~CustomFirstFrameCommitCallback()1490     ~CustomFirstFrameCommitCallback() override {};
1491 
OnFirstFrameCommit(uint64_t screenId,int64_t timestamp)1492     void OnFirstFrameCommit(uint64_t screenId, int64_t timestamp) override
1493     {
1494         if (cb_ != nullptr) {
1495             cb_(screenId, timestamp);
1496         }
1497     }
1498 
1499 private:
1500     FirstFrameCommitCallback cb_;
1501 };
1502 
DoRegisterFirstFrameCommitCallback()1503 bool DoRegisterFirstFrameCommitCallback()
1504 {
1505     if (rsConn_ == nullptr) {
1506         return false;
1507     }
1508     FirstFrameCommitCallback callback = [](uint64_t screenId, int64_t timestamp) {};
1509     sptr<CustomFirstFrameCommitCallback> cb = new CustomFirstFrameCommitCallback(callback);
1510     rsConn_->RegisterFirstFrameCommitCallback(cb);
1511     return true;
1512 }
1513 
DoClearUifirstCache()1514 bool DoClearUifirstCache()
1515 {
1516     if (rsConn_ == nullptr) {
1517         return false;
1518     }
1519 
1520     NodeId id = GetData<NodeId>();
1521     rsConn_->ClearUifirstCache(id);
1522     return true;
1523 }
1524 
DoTaskSurfaceCaptureWithAllWindows()1525 bool DoTaskSurfaceCaptureWithAllWindows()
1526 {
1527     if (rsConn_ == nullptr) {
1528         return false;
1529     }
1530     NodeId nodeId = GetData<NodeId>();
1531     bool checkDrmAndSurfaceLock = GetData<bool>();
1532     sptr<RSISurfaceCaptureCallback> callback = nullptr;
1533     RSSurfaceCaptureConfig captureConfig;
1534     rsConn_->TaskSurfaceCaptureWithAllWindows(nodeId, callback, captureConfig, checkDrmAndSurfaceLock);
1535     return true;
1536 }
1537 
DoFreezeScreen()1538 bool DoFreezeScreen()
1539 {
1540     if (rsConn_ == nullptr) {
1541         return false;
1542     }
1543     NodeId nodeId = GetData<NodeId>();
1544     bool isFreeze = GetData<bool>();
1545     rsConn_->FreezeScreen(nodeId, isFreeze);
1546     return true;
1547 }
1548 
DoFuzzerTest1()1549 void DoFuzzerTest1()
1550 {
1551     DoRegisterApplicationAgent();
1552     DoCommitTransaction();
1553     DoExecuteSynchronousTask();
1554     DoGetMemoryGraphic();
1555     DoCreateNodeAndSurface();
1556     DoGetScreenBacklight();
1557     DoGetScreenType();
1558     DoRegisterBufferAvailableListener();
1559     DoSetScreenSkipFrameInterval();
1560     DoSetPhysicalScreenResolution();
1561     DoSetVirtualScreenResolution();
1562     DoGetScreenSupportedColorGamuts();
1563     DoGetScreenSupportedModes();
1564     DoGetScreenColorGamut();
1565     DoSetScreenPowerStatus();
1566     DoSetScreenGamutMap();
1567     DoSetAppWindowNum();
1568     DoCreateVirtualScreen();
1569 #ifdef OHOS_BUILD_ENABLE_MAGICCURSOR
1570     DoSetPointerColorInversionConfig();
1571     DoSetPointerColorInversionEnabled();
1572     DoRegisterPointerLuminanceChangeCallback();
1573     DoUnRegisterPointerLuminanceChangeCallback();
1574 #endif
1575     DoSetScreenActiveMode();
1576     DoSetScreenActiveRect();
1577     DoSetRefreshRateMode();
1578     DoCreateVSyncConnection();
1579     DoSetScreenRefreshRate();
1580     DoGetBitmap();
1581     DoGetScreenCapability();
1582     DoGetScreenData();
1583     DoGetScreenHDRCapability();
1584     DoRegisterOcclusionChangeCallback();
1585 #ifdef SUPPORT_ACCESS_TOKEN
1586     DoShowWatermark();
1587 #endif
1588     DoTakeSurfaceCapture();
1589     DoSetHwcNodeBounds();
1590     DoSetScreenChangeCallback();
1591     DoSetScreenSwitchingNotifyCallback();
1592     DoSetFocusAppInfo();
1593     DoSetAncoForceDoDirect();
1594     DoGetActiveDirtyRegionInfo();
1595     DoGetGlobalDirtyRegionInfo();
1596     DoGetLayerComposeInfo();
1597     DoGetHwcDisabledReasonInfo();
1598 }
1599 
DoFuzzerTest2()1600 void DoFuzzerTest2()
1601 {
1602     DoGetUniRenderEnabled();
1603     DoCreateNode1();
1604     DoCreateNode2();
1605     DoGetDefaultScreenId();
1606     DoGetActiveScreenId();
1607     DoGetAllScreenIds();
1608     DoGetMemoryGraphics();
1609     DoGetTotalAppMemSize();
1610     DoSetVirtualScreenBlackList();
1611     DoAddVirtualScreenBlackList();
1612     DoRemoveVirtualScreenBlackList();
1613     DoSetVirtualScreenSecurityExemptionList();
1614     DoSetCastScreenEnableSkipWindow();
1615     DoSyncFrameRateRange();
1616     DoUnregisterFrameRateLinker();
1617     DoMarkPowerOffNeedProcessOneFrame();
1618     DoDisablePowerOffRenderControl();
1619     DoSetScreenCorrection();
1620     DoSetVirtualMirrorScreenCanvasRotation();
1621     DoSetVirtualMirrorScreenScaleMode();
1622     DoSetGlobalDarkColorMode();
1623     DoSetPixelFormat();
1624     DOGetScreenSupportedHDRFormats();
1625     DOGetScreenSupportedColorSpaces();
1626     DOSetVirtualScreenRefreshRate();
1627     DOSetSystemAnimatedScenes();
1628     DOResizeVirtualScreen();
1629     DOReportJankStats();
1630     DOReportEventResponse();
1631     DOReportEventComplete();
1632     DOReportEventJankFrame();
1633     DOReportGameStateData();
1634     DOSetHidePrivacyContent();
1635     DONotifyLightFactorStatus();
1636     DONotifyPackageEvent();
1637     DONotifyAppStrategyConfigChangeEvent();
1638     DONotifyRefreshRateEvent();
1639     DONotifyTouchEvent();
1640     DONotifyDynamicModeEvent();
1641     DOSetCacheEnabledForRotation();
1642     DOSetOnRemoteDiedCallback();
1643     DOSetVmaCacheStatus();
1644 #ifdef TP_FEATURE_ENABLE
1645     DOSetTpFeatureConfig();
1646 #endif
1647     DOSetVirtualScreenUsingStatus();
1648     DOSetCurtainScreenUsingStatus();
1649     DOSetVirtualScreenStatus();
1650     DOSetLayerTop();
1651     DoSetForceRefresh();
1652     DOSetFreeMultiWindowStatus();
1653 }
1654 
DoFuzzerTest3()1655 void DoFuzzerTest3()
1656 {
1657     DoNotifySoftVsyncEvent();
1658     DONotifyHgmConfigEvent();
1659     DONotifyXComponentExpectedFrameRate();
1660     DoCreatePixelMapFromSurface();
1661 #ifdef RS_ENABLE_OVERLAY_DISPLAY
1662     DoSetOverlayDisplayMode();
1663 #endif
1664     DoRegisterFirstFrameCommitCallback();
1665     DoNotifySoftVsyncRateDiscountEvent();
1666     DoSetBehindWindowFilterEnabled();
1667     DoGetBehindWindowFilterEnabled();
1668     DoSetVirtualScreenAutoRotation();
1669     DoProfilerServiceOpenFile();
1670     DoProfilerServicePopulateFiles();
1671     DoProfilerIsSecureScreen();
1672     DoClearUifirstCache();
1673     DoTaskSurfaceCaptureWithAllWindows();
1674     DoFreezeScreen();
1675 }
1676 } // namespace Rosen
1677 } // namespace OHOS
1678 
1679 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)1680 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
1681 {
1682     if (!OHOS::Rosen::Init(data, size)) {
1683         return 0;
1684     }
1685     /* Run your code on data */
1686     OHOS::Rosen::DoFuzzerTest1();
1687     OHOS::Rosen::DoFuzzerTest2();
1688     OHOS::Rosen::DoFuzzerTest3();
1689     return 0;
1690 }