1d95e75fdSopenharmony_ci/*
2d95e75fdSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
3d95e75fdSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4d95e75fdSopenharmony_ci * you may not use this file except in compliance with the License.
5d95e75fdSopenharmony_ci * You may obtain a copy of the License at
6d95e75fdSopenharmony_ci *
7d95e75fdSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8d95e75fdSopenharmony_ci *
9d95e75fdSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10d95e75fdSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11d95e75fdSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d95e75fdSopenharmony_ci * See the License for the specific language governing permissions and
13d95e75fdSopenharmony_ci * limitations under the License.
14d95e75fdSopenharmony_ci */
15d95e75fdSopenharmony_ci
16d95e75fdSopenharmony_ci#include "getcallrestriction_fuzzer.h"
17d95e75fdSopenharmony_ci
18d95e75fdSopenharmony_ci#include <cstddef>
19d95e75fdSopenharmony_ci#include <cstdint>
20d95e75fdSopenharmony_ci#include <fuzzer/FuzzedDataProvider.h>
21d95e75fdSopenharmony_ci#define private public
22d95e75fdSopenharmony_ci#include "addcellularcalltoken_fuzzer.h"
23d95e75fdSopenharmony_ci#include "cellular_call_service.h"
24d95e75fdSopenharmony_ci#include "securec.h"
25d95e75fdSopenharmony_ci#include "system_ability_definition.h"
26d95e75fdSopenharmony_ci
27d95e75fdSopenharmony_ciusing namespace OHOS::Telephony;
28d95e75fdSopenharmony_cinamespace OHOS {
29d95e75fdSopenharmony_cistatic bool g_isInited = false;
30d95e75fdSopenharmony_ciconstexpr int32_t SLOT_NUM = 2;
31d95e75fdSopenharmony_ciconstexpr int32_t VEDIO_STATE_NUM = 2;
32d95e75fdSopenharmony_ciconstexpr int32_t BOOL_NUM = 2;
33d95e75fdSopenharmony_ciconstexpr int32_t OFFSET_SIZE = 11;
34d95e75fdSopenharmony_ciconstexpr size_t MAX_NUMBER_LEN = 99;
35d95e75fdSopenharmony_ci
36d95e75fdSopenharmony_cibool IsServiceInited()
37d95e75fdSopenharmony_ci{
38d95e75fdSopenharmony_ci    if (!g_isInited) {
39d95e75fdSopenharmony_ci        DelayedSingleton<CellularCallService>::GetInstance()->OnStart();
40d95e75fdSopenharmony_ci    }
41d95e75fdSopenharmony_ci    if (!g_isInited && (static_cast<int32_t>(DelayedSingleton<CellularCallService>::GetInstance()->state_) ==
42d95e75fdSopenharmony_ci                           static_cast<int32_t>(ServiceRunningState::STATE_RUNNING))) {
43d95e75fdSopenharmony_ci        g_isInited = true;
44d95e75fdSopenharmony_ci    }
45d95e75fdSopenharmony_ci    return g_isInited;
46d95e75fdSopenharmony_ci}
47d95e75fdSopenharmony_ci
48d95e75fdSopenharmony_civoid OnRemoteRequest(const uint8_t *data, size_t size)
49d95e75fdSopenharmony_ci{
50d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
51d95e75fdSopenharmony_ci        return;
52d95e75fdSopenharmony_ci    }
53d95e75fdSopenharmony_ci
54d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
55d95e75fdSopenharmony_ci    if (!dataMessageParcel.WriteInterfaceToken(CellularCallStub::GetDescriptor())) {
56d95e75fdSopenharmony_ci        return;
57d95e75fdSopenharmony_ci    }
58d95e75fdSopenharmony_ci    int32_t maxSize = static_cast<int32_t>(size) + OFFSET_SIZE;
59d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(maxSize);
60d95e75fdSopenharmony_ci    dataMessageParcel.WriteBuffer(data, size);
61d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
62d95e75fdSopenharmony_ci    uint32_t code = static_cast<uint32_t>(size);
63d95e75fdSopenharmony_ci    MessageParcel reply;
64d95e75fdSopenharmony_ci    MessageOption option;
65d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnRemoteRequest(code, dataMessageParcel, reply, option);
66d95e75fdSopenharmony_ci}
67d95e75fdSopenharmony_ci
68d95e75fdSopenharmony_civoid UnRegisterCallManagerCallBack(const uint8_t *data, size_t size)
69d95e75fdSopenharmony_ci{
70d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
71d95e75fdSopenharmony_ci        return;
72d95e75fdSopenharmony_ci    }
73d95e75fdSopenharmony_ci
74d95e75fdSopenharmony_ci    int32_t maxSize = static_cast<int32_t>(size);
75d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
76d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(maxSize);
77d95e75fdSopenharmony_ci    dataMessageParcel.WriteBuffer(data, size);
78d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
79d95e75fdSopenharmony_ci    MessageParcel reply;
80d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnUnRegisterCallBackInner(dataMessageParcel, reply);
81d95e75fdSopenharmony_ci}
82d95e75fdSopenharmony_ci
83d95e75fdSopenharmony_civoid IsEmergencyPhoneNumber(const uint8_t *data, size_t size)
84d95e75fdSopenharmony_ci{
85d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
86d95e75fdSopenharmony_ci        return;
87d95e75fdSopenharmony_ci    }
88d95e75fdSopenharmony_ci
89d95e75fdSopenharmony_ci    int32_t errorCode = static_cast<int32_t>(size);
90d95e75fdSopenharmony_ci    std::string phoneNum(reinterpret_cast<const char *>(data), size);
91d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
92d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(errorCode);
93d95e75fdSopenharmony_ci    dataMessageParcel.WriteString(phoneNum);
94d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
95d95e75fdSopenharmony_ci    MessageParcel reply;
96d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnIsEmergencyPhoneNumberInner(dataMessageParcel, reply);
97d95e75fdSopenharmony_ci}
98d95e75fdSopenharmony_ci
99d95e75fdSopenharmony_civoid HangUpAllConnection(const uint8_t *data, size_t size)
100d95e75fdSopenharmony_ci{
101d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
102d95e75fdSopenharmony_ci        return;
103d95e75fdSopenharmony_ci    }
104d95e75fdSopenharmony_ci
105d95e75fdSopenharmony_ci    int32_t maxSize = static_cast<int32_t>(size);
106d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
107d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(maxSize);
108d95e75fdSopenharmony_ci    dataMessageParcel.WriteBuffer(data, size);
109d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
110d95e75fdSopenharmony_ci    MessageParcel reply;
111d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnHangUpAllConnectionInner(dataMessageParcel, reply);
112d95e75fdSopenharmony_ci}
113d95e75fdSopenharmony_ci
114d95e75fdSopenharmony_civoid SetReadyToCall(const uint8_t *data, size_t size)
115d95e75fdSopenharmony_ci{
116d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
117d95e75fdSopenharmony_ci        return;
118d95e75fdSopenharmony_ci    }
119d95e75fdSopenharmony_ci
120d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size);
121d95e75fdSopenharmony_ci    int32_t callType = static_cast<int32_t>(size % SLOT_NUM);
122d95e75fdSopenharmony_ci    bool isReadyToCall = static_cast<bool>(size % SLOT_NUM);
123d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
124d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(slotId);
125d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(callType);
126d95e75fdSopenharmony_ci    dataMessageParcel.WriteBool(isReadyToCall);
127d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
128d95e75fdSopenharmony_ci    MessageParcel reply;
129d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnSetReadyToCallInner(dataMessageParcel, reply);
130d95e75fdSopenharmony_ci}
131d95e75fdSopenharmony_ci
132d95e75fdSopenharmony_civoid StartRtt(const uint8_t *data, size_t size)
133d95e75fdSopenharmony_ci{
134d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
135d95e75fdSopenharmony_ci        return;
136d95e75fdSopenharmony_ci    }
137d95e75fdSopenharmony_ci
138d95e75fdSopenharmony_ci    std::string msg(reinterpret_cast<const char *>(data), size);
139d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
140d95e75fdSopenharmony_ci    dataMessageParcel.WriteString(msg);
141d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
142d95e75fdSopenharmony_ci    MessageParcel reply;
143d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnStartRttInner(dataMessageParcel, reply);
144d95e75fdSopenharmony_ci}
145d95e75fdSopenharmony_ci
146d95e75fdSopenharmony_civoid StopRtt(const uint8_t *data, size_t size)
147d95e75fdSopenharmony_ci{
148d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
149d95e75fdSopenharmony_ci        return;
150d95e75fdSopenharmony_ci    }
151d95e75fdSopenharmony_ci
152d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
153d95e75fdSopenharmony_ci    dataMessageParcel.WriteBuffer(data, size);
154d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
155d95e75fdSopenharmony_ci    MessageParcel reply;
156d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnStopRttInner(dataMessageParcel, reply);
157d95e75fdSopenharmony_ci}
158d95e75fdSopenharmony_ci
159d95e75fdSopenharmony_civoid GetCallTransferInfo(const uint8_t *data, size_t size)
160d95e75fdSopenharmony_ci{
161d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
162d95e75fdSopenharmony_ci        return;
163d95e75fdSopenharmony_ci    }
164d95e75fdSopenharmony_ci
165d95e75fdSopenharmony_ci    int32_t type = static_cast<int32_t>(size);
166d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
167d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(type);
168d95e75fdSopenharmony_ci    dataMessageParcel.WriteBuffer(data, size);
169d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
170d95e75fdSopenharmony_ci    MessageParcel reply;
171d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnGetCallTransferInner(dataMessageParcel, reply);
172d95e75fdSopenharmony_ci}
173d95e75fdSopenharmony_ci
174d95e75fdSopenharmony_civoid GetCallWaiting(const uint8_t *data, size_t size)
175d95e75fdSopenharmony_ci{
176d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
177d95e75fdSopenharmony_ci        return;
178d95e75fdSopenharmony_ci    }
179d95e75fdSopenharmony_ci
180d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
181d95e75fdSopenharmony_ci    dataMessageParcel.WriteBuffer(data, size);
182d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
183d95e75fdSopenharmony_ci    MessageParcel reply;
184d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnGetCallWaitingInner(dataMessageParcel, reply);
185d95e75fdSopenharmony_ci}
186d95e75fdSopenharmony_ci
187d95e75fdSopenharmony_civoid SetCallWaiting(const uint8_t *data, size_t size)
188d95e75fdSopenharmony_ci{
189d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
190d95e75fdSopenharmony_ci        return;
191d95e75fdSopenharmony_ci    }
192d95e75fdSopenharmony_ci
193d95e75fdSopenharmony_ci    int32_t activate = static_cast<int32_t>(size % BOOL_NUM);
194d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
195d95e75fdSopenharmony_ci    dataMessageParcel.WriteBool(activate);
196d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
197d95e75fdSopenharmony_ci    MessageParcel reply;
198d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnSetCallWaitingInner(dataMessageParcel, reply);
199d95e75fdSopenharmony_ci}
200d95e75fdSopenharmony_ci
201d95e75fdSopenharmony_civoid GetCallRestriction(const uint8_t *data, size_t size)
202d95e75fdSopenharmony_ci{
203d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
204d95e75fdSopenharmony_ci        return;
205d95e75fdSopenharmony_ci    }
206d95e75fdSopenharmony_ci
207d95e75fdSopenharmony_ci    int32_t facType = static_cast<int32_t>(size);
208d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
209d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(facType);
210d95e75fdSopenharmony_ci    dataMessageParcel.WriteBuffer(data, size);
211d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
212d95e75fdSopenharmony_ci    MessageParcel reply;
213d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnGetCallRestrictionInner(dataMessageParcel, reply);
214d95e75fdSopenharmony_ci}
215d95e75fdSopenharmony_ci
216d95e75fdSopenharmony_civoid SetCallRestrictionPassword(const uint8_t *data, size_t size)
217d95e75fdSopenharmony_ci{
218d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
219d95e75fdSopenharmony_ci        return;
220d95e75fdSopenharmony_ci    }
221d95e75fdSopenharmony_ci
222d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % SLOT_NUM);
223d95e75fdSopenharmony_ci    int32_t facType = static_cast<int32_t>(size);
224d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
225d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(slotId);
226d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(facType);
227d95e75fdSopenharmony_ci    dataMessageParcel.WriteBuffer(data, size);
228d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
229d95e75fdSopenharmony_ci    MessageParcel reply;
230d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnSetCallRestrictionPasswordInner(dataMessageParcel, reply);
231d95e75fdSopenharmony_ci}
232d95e75fdSopenharmony_ci
233d95e75fdSopenharmony_civoid Dial(const uint8_t *data, size_t size)
234d95e75fdSopenharmony_ci{
235d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
236d95e75fdSopenharmony_ci        return;
237d95e75fdSopenharmony_ci    }
238d95e75fdSopenharmony_ci
239d95e75fdSopenharmony_ci    int32_t maxSize = static_cast<int32_t>(size);
240d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % SLOT_NUM);
241d95e75fdSopenharmony_ci    int32_t callId = static_cast<int32_t>(size);
242d95e75fdSopenharmony_ci    int32_t accountId = static_cast<int32_t>(size);
243d95e75fdSopenharmony_ci    int32_t videoState = static_cast<int32_t>(size % VEDIO_STATE_NUM);
244d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size);
245d95e75fdSopenharmony_ci    std::string telNum = "000000000";
246d95e75fdSopenharmony_ci    std::string tempNum(reinterpret_cast<const char *>(data), size);
247d95e75fdSopenharmony_ci    if (strlen(tempNum.c_str()) <= MAX_NUMBER_LEN) {
248d95e75fdSopenharmony_ci        telNum = tempNum;
249d95e75fdSopenharmony_ci    }
250d95e75fdSopenharmony_ci    size_t length = strlen(telNum.c_str()) + 1;
251d95e75fdSopenharmony_ci    CellularCallInfo callInfo;
252d95e75fdSopenharmony_ci    callInfo.slotId = slotId;
253d95e75fdSopenharmony_ci    callInfo.callId = callId;
254d95e75fdSopenharmony_ci    callInfo.accountId = accountId;
255d95e75fdSopenharmony_ci    callInfo.videoState = videoState;
256d95e75fdSopenharmony_ci    callInfo.index = index;
257d95e75fdSopenharmony_ci    if (strcpy_s(callInfo.phoneNum, length, telNum.c_str()) != EOK) {
258d95e75fdSopenharmony_ci        return;
259d95e75fdSopenharmony_ci    }
260d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
261d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(maxSize);
262d95e75fdSopenharmony_ci    dataMessageParcel.WriteRawData(static_cast<const void *>(&callInfo), sizeof(CellularCallInfo));
263d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
264d95e75fdSopenharmony_ci    MessageParcel reply;
265d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnDialInner(dataMessageParcel, reply);
266d95e75fdSopenharmony_ci}
267d95e75fdSopenharmony_ci
268d95e75fdSopenharmony_civoid InviteToConference(const uint8_t *data, size_t size)
269d95e75fdSopenharmony_ci{
270d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
271d95e75fdSopenharmony_ci        return;
272d95e75fdSopenharmony_ci    }
273d95e75fdSopenharmony_ci
274d95e75fdSopenharmony_ci    std::string number(reinterpret_cast<const char *>(data), size);
275d95e75fdSopenharmony_ci    std::vector<std::string> numberList;
276d95e75fdSopenharmony_ci    numberList.push_back(number);
277d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
278d95e75fdSopenharmony_ci    dataMessageParcel.WriteStringVector(numberList);
279d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
280d95e75fdSopenharmony_ci    MessageParcel reply;
281d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnInviteToConferenceInner(dataMessageParcel, reply);
282d95e75fdSopenharmony_ci}
283d95e75fdSopenharmony_ci
284d95e75fdSopenharmony_civoid KickOutFromConference(const uint8_t *data, size_t size)
285d95e75fdSopenharmony_ci{
286d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
287d95e75fdSopenharmony_ci        return;
288d95e75fdSopenharmony_ci    }
289d95e75fdSopenharmony_ci
290d95e75fdSopenharmony_ci    int32_t maxSize = static_cast<int32_t>(size);
291d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % SLOT_NUM);
292d95e75fdSopenharmony_ci    int32_t callId = static_cast<int32_t>(size);
293d95e75fdSopenharmony_ci    int32_t accountId = static_cast<int32_t>(size);
294d95e75fdSopenharmony_ci    int32_t videoState = static_cast<int32_t>(size % VEDIO_STATE_NUM);
295d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size);
296d95e75fdSopenharmony_ci    std::string telNum = "000000000";
297d95e75fdSopenharmony_ci    std::string tempNum(reinterpret_cast<const char *>(data), size);
298d95e75fdSopenharmony_ci    if (strlen(tempNum.c_str()) <= MAX_NUMBER_LEN) {
299d95e75fdSopenharmony_ci        telNum = tempNum;
300d95e75fdSopenharmony_ci    }
301d95e75fdSopenharmony_ci    size_t length = strlen(telNum.c_str()) + 1;
302d95e75fdSopenharmony_ci    CellularCallInfo callInfo;
303d95e75fdSopenharmony_ci    callInfo.slotId = slotId;
304d95e75fdSopenharmony_ci    callInfo.callId = callId;
305d95e75fdSopenharmony_ci    callInfo.accountId = accountId;
306d95e75fdSopenharmony_ci    callInfo.videoState = videoState;
307d95e75fdSopenharmony_ci    callInfo.index = index;
308d95e75fdSopenharmony_ci    if (strcpy_s(callInfo.phoneNum, length, telNum.c_str()) != EOK) {
309d95e75fdSopenharmony_ci        return;
310d95e75fdSopenharmony_ci    }
311d95e75fdSopenharmony_ci    MessageParcel dataMessageParcel;
312d95e75fdSopenharmony_ci    dataMessageParcel.WriteInt32(maxSize);
313d95e75fdSopenharmony_ci    dataMessageParcel.WriteRawData(static_cast<const void *>(&callInfo), sizeof(CellularCallInfo));
314d95e75fdSopenharmony_ci    dataMessageParcel.RewindRead(0);
315d95e75fdSopenharmony_ci    MessageParcel reply;
316d95e75fdSopenharmony_ci    DelayedSingleton<CellularCallService>::GetInstance()->OnKickOutFromConferenceInner(dataMessageParcel, reply);
317d95e75fdSopenharmony_ci}
318d95e75fdSopenharmony_ci
319d95e75fdSopenharmony_civoid doFuzzCellularCallService_1(const uint8_t *data, size_t size)
320d95e75fdSopenharmony_ci{
321d95e75fdSopenharmony_ci    auto cellularCallService = DelayedSingleton<CellularCallService>::GetInstance();
322d95e75fdSopenharmony_ci    cellularCallService->OnStart();
323d95e75fdSopenharmony_ci    FuzzedDataProvider fdp(data, size);
324d95e75fdSopenharmony_ci    uint32_t code = fdp.ConsumeIntegralInRange<uint32_t>(1, 20);
325d95e75fdSopenharmony_ci    if (fdp.remaining_bytes() == 0) {
326d95e75fdSopenharmony_ci        return;
327d95e75fdSopenharmony_ci    }
328d95e75fdSopenharmony_ci    std::u16string service_token = u"OHOS.Telephony.CellularCallInterface";
329d95e75fdSopenharmony_ci    MessageOption option;
330d95e75fdSopenharmony_ci    MessageParcel dataParcel;
331d95e75fdSopenharmony_ci    MessageParcel replyParcel;
332d95e75fdSopenharmony_ci    std::vector<uint8_t> subData =
333d95e75fdSopenharmony_ci        fdp.ConsumeBytes<uint8_t>(fdp.ConsumeIntegralInRange<size_t>(0, fdp.remaining_bytes()));
334d95e75fdSopenharmony_ci    dataParcel.WriteInterfaceToken(service_token);
335d95e75fdSopenharmony_ci    dataParcel.WriteBuffer(subData.data(), subData.size());
336d95e75fdSopenharmony_ci    cellularCallService->OnRemoteRequest(code, dataParcel, replyParcel, option);
337d95e75fdSopenharmony_ci}
338d95e75fdSopenharmony_ci
339d95e75fdSopenharmony_civoid doFuzzCellularCallService_2(const uint8_t *data, size_t size)
340d95e75fdSopenharmony_ci{
341d95e75fdSopenharmony_ci    auto cellularCallService = DelayedSingleton<CellularCallService>::GetInstance();
342d95e75fdSopenharmony_ci    cellularCallService->OnStart();
343d95e75fdSopenharmony_ci    FuzzedDataProvider fdp(data, size);
344d95e75fdSopenharmony_ci    uint32_t code = fdp.ConsumeIntegralInRange<uint32_t>(100, 105);
345d95e75fdSopenharmony_ci    if (fdp.remaining_bytes() == 0) {
346d95e75fdSopenharmony_ci        return;
347d95e75fdSopenharmony_ci    }
348d95e75fdSopenharmony_ci    std::u16string service_token = u"OHOS.Telephony.CellularCallInterface";
349d95e75fdSopenharmony_ci    MessageOption option;
350d95e75fdSopenharmony_ci    MessageParcel dataParcel;
351d95e75fdSopenharmony_ci    MessageParcel replyParcel;
352d95e75fdSopenharmony_ci    std::vector<uint8_t> subData =
353d95e75fdSopenharmony_ci        fdp.ConsumeBytes<uint8_t>(fdp.ConsumeIntegralInRange<size_t>(0, fdp.remaining_bytes()));
354d95e75fdSopenharmony_ci    dataParcel.WriteInterfaceToken(service_token);
355d95e75fdSopenharmony_ci    dataParcel.WriteBuffer(subData.data(), subData.size());
356d95e75fdSopenharmony_ci    cellularCallService->OnRemoteRequest(code, dataParcel, replyParcel, option);
357d95e75fdSopenharmony_ci}
358d95e75fdSopenharmony_ci
359d95e75fdSopenharmony_civoid doFuzzCellularCallService_3(const uint8_t *data, size_t size)
360d95e75fdSopenharmony_ci{
361d95e75fdSopenharmony_ci    auto cellularCallService = DelayedSingleton<CellularCallService>::GetInstance();
362d95e75fdSopenharmony_ci    cellularCallService->OnStart();
363d95e75fdSopenharmony_ci    FuzzedDataProvider fdp(data, size);
364d95e75fdSopenharmony_ci    uint32_t code = fdp.ConsumeIntegralInRange<uint32_t>(200, 208);
365d95e75fdSopenharmony_ci    if (fdp.remaining_bytes() == 0) {
366d95e75fdSopenharmony_ci        return;
367d95e75fdSopenharmony_ci    }
368d95e75fdSopenharmony_ci    std::u16string service_token = u"OHOS.Telephony.CellularCallInterface";
369d95e75fdSopenharmony_ci    MessageOption option;
370d95e75fdSopenharmony_ci    MessageParcel dataParcel;
371d95e75fdSopenharmony_ci    MessageParcel replyParcel;
372d95e75fdSopenharmony_ci    std::vector<uint8_t> subData =
373d95e75fdSopenharmony_ci        fdp.ConsumeBytes<uint8_t>(fdp.ConsumeIntegralInRange<size_t>(0, fdp.remaining_bytes()));
374d95e75fdSopenharmony_ci    dataParcel.WriteInterfaceToken(service_token);
375d95e75fdSopenharmony_ci    dataParcel.WriteBuffer(subData.data(), subData.size());
376d95e75fdSopenharmony_ci    cellularCallService->OnRemoteRequest(code, dataParcel, replyParcel, option);
377d95e75fdSopenharmony_ci}
378d95e75fdSopenharmony_ci
379d95e75fdSopenharmony_civoid doFuzzCellularCallService_4(const uint8_t *data, size_t size)
380d95e75fdSopenharmony_ci{
381d95e75fdSopenharmony_ci    auto cellularCallService = DelayedSingleton<CellularCallService>::GetInstance();
382d95e75fdSopenharmony_ci    cellularCallService->OnStart();
383d95e75fdSopenharmony_ci    FuzzedDataProvider fdp(data, size);
384d95e75fdSopenharmony_ci    uint32_t code = fdp.ConsumeIntegralInRange<uint32_t>(300, 312);
385d95e75fdSopenharmony_ci    if (fdp.remaining_bytes() == 0) {
386d95e75fdSopenharmony_ci        return;
387d95e75fdSopenharmony_ci    }
388d95e75fdSopenharmony_ci    std::u16string service_token = u"OHOS.Telephony.CellularCallInterface";
389d95e75fdSopenharmony_ci    MessageOption option;
390d95e75fdSopenharmony_ci    MessageParcel dataParcel;
391d95e75fdSopenharmony_ci    MessageParcel replyParcel;
392d95e75fdSopenharmony_ci    std::vector<uint8_t> subData =
393d95e75fdSopenharmony_ci        fdp.ConsumeBytes<uint8_t>(fdp.ConsumeIntegralInRange<size_t>(0, fdp.remaining_bytes()));
394d95e75fdSopenharmony_ci    dataParcel.WriteInterfaceToken(service_token);
395d95e75fdSopenharmony_ci    dataParcel.WriteBuffer(subData.data(), subData.size());
396d95e75fdSopenharmony_ci    cellularCallService->OnRemoteRequest(code, dataParcel, replyParcel, option);
397d95e75fdSopenharmony_ci}
398d95e75fdSopenharmony_ci
399d95e75fdSopenharmony_civoid doFuzzCellularCallService_5(const uint8_t *data, size_t size)
400d95e75fdSopenharmony_ci{
401d95e75fdSopenharmony_ci    auto cellularCallService = DelayedSingleton<CellularCallService>::GetInstance();
402d95e75fdSopenharmony_ci    cellularCallService->OnStart();
403d95e75fdSopenharmony_ci    FuzzedDataProvider fdp(data, size);
404d95e75fdSopenharmony_ci    uint32_t code = fdp.ConsumeIntegralInRange<uint32_t>(400, 407);
405d95e75fdSopenharmony_ci    if (fdp.remaining_bytes() == 0) {
406d95e75fdSopenharmony_ci        return;
407d95e75fdSopenharmony_ci    }
408d95e75fdSopenharmony_ci    std::u16string service_token = u"OHOS.Telephony.CellularCallInterface";
409d95e75fdSopenharmony_ci    MessageOption option;
410d95e75fdSopenharmony_ci    MessageParcel dataParcel;
411d95e75fdSopenharmony_ci    MessageParcel replyParcel;
412d95e75fdSopenharmony_ci    std::vector<uint8_t> subData =
413d95e75fdSopenharmony_ci        fdp.ConsumeBytes<uint8_t>(fdp.ConsumeIntegralInRange<size_t>(0, fdp.remaining_bytes()));
414d95e75fdSopenharmony_ci    dataParcel.WriteInterfaceToken(service_token);
415d95e75fdSopenharmony_ci    dataParcel.WriteBuffer(subData.data(), subData.size());
416d95e75fdSopenharmony_ci    cellularCallService->OnRemoteRequest(code, dataParcel, replyParcel, option);
417d95e75fdSopenharmony_ci}
418d95e75fdSopenharmony_ci
419d95e75fdSopenharmony_civoid DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
420d95e75fdSopenharmony_ci{
421d95e75fdSopenharmony_ci    if (data == nullptr || size == 0) {
422d95e75fdSopenharmony_ci        return;
423d95e75fdSopenharmony_ci    }
424d95e75fdSopenharmony_ci
425d95e75fdSopenharmony_ci    OnRemoteRequest(data, size);
426d95e75fdSopenharmony_ci    UnRegisterCallManagerCallBack(data, size);
427d95e75fdSopenharmony_ci    IsEmergencyPhoneNumber(data, size);
428d95e75fdSopenharmony_ci    HangUpAllConnection(data, size);
429d95e75fdSopenharmony_ci    SetReadyToCall(data, size);
430d95e75fdSopenharmony_ci    StartRtt(data, size);
431d95e75fdSopenharmony_ci    StopRtt(data, size);
432d95e75fdSopenharmony_ci    GetCallTransferInfo(data, size);
433d95e75fdSopenharmony_ci    GetCallWaiting(data, size);
434d95e75fdSopenharmony_ci    SetCallWaiting(data, size);
435d95e75fdSopenharmony_ci    GetCallRestriction(data, size);
436d95e75fdSopenharmony_ci    SetCallRestrictionPassword(data, size);
437d95e75fdSopenharmony_ci    Dial(data, size);
438d95e75fdSopenharmony_ci    InviteToConference(data, size);
439d95e75fdSopenharmony_ci    KickOutFromConference(data, size);
440d95e75fdSopenharmony_ci    doFuzzCellularCallService_1(data, size);
441d95e75fdSopenharmony_ci    doFuzzCellularCallService_2(data, size);
442d95e75fdSopenharmony_ci    doFuzzCellularCallService_3(data, size);
443d95e75fdSopenharmony_ci    doFuzzCellularCallService_4(data, size);
444d95e75fdSopenharmony_ci    doFuzzCellularCallService_5(data, size);
445d95e75fdSopenharmony_ci    return;
446d95e75fdSopenharmony_ci}
447d95e75fdSopenharmony_ci} // namespace OHOS
448d95e75fdSopenharmony_ci
449d95e75fdSopenharmony_ci/* Fuzzer entry point */
450d95e75fdSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
451d95e75fdSopenharmony_ci{
452d95e75fdSopenharmony_ci    OHOS::AddCellularCallTokenFuzzer token;
453d95e75fdSopenharmony_ci    /* Run your code on data */
454d95e75fdSopenharmony_ci    OHOS::DoSomethingInterestingWithMyAPI(data, size);
455d95e75fdSopenharmony_ci    return 0;
456d95e75fdSopenharmony_ci}
457