• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 <iremote_broker.h>
17 
18 #include "session_manager.h"
19 #include "sessionstubanimation_fuzzer.h"
20 #include "window_scene_session_impl.h"
21 #include "window_option.h"
22 #include "zidl/session_ipc_interface_code.h"
23 #include "zidl/session_proxy.h"
24 #include "zidl/session_stage_ipc_interface_code.h"
25 #include "zidl/session_stage_stub.h"
26 
27 using namespace OHOS::Rosen;
28 
29 namespace OHOS {
30 namespace {
31 constexpr size_t DATA_MIN_SIZE = 2;
32 }
33 
SessionStubAnimationTest(sptr<Session> sessionStub,MessageParcel & parcel)34 void SessionStubAnimationTest(sptr<Session> sessionStub, MessageParcel& parcel)
35 {
36     MessageParcel reply;
37     MessageOption option;
38 
39     parcel.RewindRead(0);
40     sessionStub->OnRemoteRequest(static_cast<uint32_t>
41         (Rosen::SessionInterfaceCode::TRANS_ID_GET_TARGET_ORIENTATION_CONFIG_INFO),
42         parcel, reply, option);
43     parcel.RewindRead(0);
44     sessionStub->OnRemoteRequest(static_cast<uint32_t>
45         (Rosen::SessionInterfaceCode::TRANS_ID_UPDATE_ROTATION_CHANGE),
46         parcel, reply, option);
47     parcel.RewindRead(0);
48     sessionStub->OnRemoteRequest(static_cast<uint32_t>
49         (Rosen::SessionInterfaceCode::TRANS_ID_SET_WINDOW_SHADOWS),
50         parcel, reply, option);
51     parcel.RewindRead(0);
52     sessionStub->OnRemoteRequest(static_cast<uint32_t>
53         (Rosen::SessionInterfaceCode::TRANS_ID_SET_FRAMERECT_FOR_PARTIAL_ZOOMIN),
54         parcel, reply, option);
55     parcel.RewindRead(0);
56     sessionStub->OnRemoteRequest(static_cast<uint32_t>
57         (Rosen::SessionInterfaceCode::TRANS_ID_SET_WINDOW_TRANSITION_ANIMATION),
58         parcel, reply, option);
59 }
60 
SessionStageStubAnimationTest(sptr<WindowSessionImpl> stageStub,MessageParcel & parcel)61 void SessionStageStubAnimationTest(sptr<WindowSessionImpl> stageStub, MessageParcel& parcel)
62 {
63     MessageParcel reply;
64     MessageOption option;
65 
66     parcel.RewindRead(0);
67     stageStub->OnRemoteRequest(static_cast<uint32_t>
68         (Rosen::SessionStageInterfaceCode::TRANS_ID_SET_CURRENT_ROTATION),
69         parcel, reply, option);
70     parcel.RewindRead(0);
71     stageStub->OnRemoteRequest(static_cast<uint32_t>
72         (Rosen::SessionStageInterfaceCode::TRANS_ID_NOTIFY_ROTATION_PROPERTY),
73         parcel, reply, option);
74     parcel.RewindRead(0);
75     stageStub->OnRemoteRequest(static_cast<uint32_t>
76         (Rosen::SessionStageInterfaceCode::TRANS_ID_NOTIFY_ROTATION_CHANGE),
77         parcel, reply, option);
78 }
79 
DoSomethingInterestingWithMyAPI1(const uint8_t * data,size_t size)80 bool DoSomethingInterestingWithMyAPI1(const uint8_t* data, size_t size)
81 {
82     if (data == nullptr || size < DATA_MIN_SIZE) {
83         return false;
84     }
85 
86     MessageParcel parcel;
87     parcel.WriteInterfaceToken(SessionStub::GetDescriptor());
88     parcel.WriteBuffer(data, size);
89 
90     SessionInfo info;
91     info.abilityName_ = "stubAnimationFuzzTest";
92     info.bundleName_ = "stubAnimationFuzzTest";
93     sptr<Session> sessionStub = new (std::nothrow) Session(info);
94     if (sessionStub == nullptr) {
95         return false;
96     }
97 
98     SessionStubAnimationTest(sessionStub, parcel);
99     return true;
100 }
101 
DoSomethingInterestingWithMyAPI2(const uint8_t * data,size_t size)102 bool DoSomethingInterestingWithMyAPI2(const uint8_t* data, size_t size)
103 {
104     if (data == nullptr || size < DATA_MIN_SIZE) {
105         return false;
106     }
107 
108     MessageParcel parcel;
109     parcel.WriteInterfaceToken(SessionStageStub::GetDescriptor());
110     parcel.WriteBuffer(data, size);
111 
112     sptr<WindowOption> windowOption = new (std::nothrow) WindowOption();
113     if (windowOption == nullptr) {
114         return false;
115     }
116     sptr<WindowSessionImpl> stageStub = new (std::nothrow) WindowSessionImpl(windowOption);
117     if (stageStub == nullptr) {
118         return false;
119     }
120 
121     SessionStageStubAnimationTest(stageStub, parcel);
122     return true;
123 }
124 } // namespace.OHOS
125 
126 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)127 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
128 {
129     /* Run your code on data */
130     OHOS::DoSomethingInterestingWithMyAPI1(data, size);
131     OHOS::DoSomethingInterestingWithMyAPI2(data, size);
132     return 0;
133 }