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 "imsclient_fuzzer.h"
17d95e75fdSopenharmony_ci
18d95e75fdSopenharmony_ci#include <cstddef>
19d95e75fdSopenharmony_ci#include <cstdint>
20d95e75fdSopenharmony_ci#define private public
21d95e75fdSopenharmony_ci#include "addcellularcalltoken_fuzzer.h"
22d95e75fdSopenharmony_ci#include "cellular_call_service.h"
23d95e75fdSopenharmony_ci#include "ims_call_client.h"
24d95e75fdSopenharmony_ci#include "ims_call_proxy.h"
25d95e75fdSopenharmony_ci#include "securec.h"
26d95e75fdSopenharmony_ci#include "surface_utils.h"
27d95e75fdSopenharmony_ci#include "system_ability_definition.h"
28d95e75fdSopenharmony_ci
29d95e75fdSopenharmony_ciusing namespace OHOS::Telephony;
30d95e75fdSopenharmony_cinamespace OHOS {
31d95e75fdSopenharmony_cistatic bool g_isInited = false;
32d95e75fdSopenharmony_ciconstexpr int32_t SERVICE_STATE_RUNNING = 1;
33d95e75fdSopenharmony_ciconstexpr int32_t IMS_CONFIG_ITEM_NUM = 2;
34d95e75fdSopenharmony_cienum {
35d95e75fdSopenharmony_ci    NUM_ONE = 1,
36d95e75fdSopenharmony_ci    NUM_TWO,
37d95e75fdSopenharmony_ci    NUM_THREE,
38d95e75fdSopenharmony_ci    NUM_FOUR,
39d95e75fdSopenharmony_ci    NUM_FIVE,
40d95e75fdSopenharmony_ci    NUM_SIX,
41d95e75fdSopenharmony_ci    NUM_SEVEN,
42d95e75fdSopenharmony_ci    NUM_EIGHT,
43d95e75fdSopenharmony_ci};
44d95e75fdSopenharmony_ci
45d95e75fdSopenharmony_cibool IsServiceInited()
46d95e75fdSopenharmony_ci{
47d95e75fdSopenharmony_ci    auto service = DelayedSingleton<CellularCallService>::GetInstance();
48d95e75fdSopenharmony_ci    if (service == nullptr) {
49d95e75fdSopenharmony_ci        return g_isInited;
50d95e75fdSopenharmony_ci    }
51d95e75fdSopenharmony_ci    if (service->GetServiceRunningState() != SERVICE_STATE_RUNNING) {
52d95e75fdSopenharmony_ci        service->OnStart();
53d95e75fdSopenharmony_ci    }
54d95e75fdSopenharmony_ci    if (!g_isInited && service->GetServiceRunningState() == SERVICE_STATE_RUNNING) {
55d95e75fdSopenharmony_ci        g_isInited = true;
56d95e75fdSopenharmony_ci    }
57d95e75fdSopenharmony_ci    return g_isInited;
58d95e75fdSopenharmony_ci}
59d95e75fdSopenharmony_ci
60d95e75fdSopenharmony_civoid TestImsCallClientWithCallInfo(
61d95e75fdSopenharmony_ci    const uint8_t *data, size_t size, const std::shared_ptr<ImsCallClient> &imsCallClient)
62d95e75fdSopenharmony_ci{
63d95e75fdSopenharmony_ci    ImsCallInfo callInfo;
64d95e75fdSopenharmony_ci    if (memset_s(&callInfo, sizeof(struct ImsCallInfo), 0x00, sizeof(struct ImsCallInfo)) != EOK) {
65d95e75fdSopenharmony_ci        return;
66d95e75fdSopenharmony_ci    }
67d95e75fdSopenharmony_ci    size_t length = std::min(static_cast<size_t>(sizeof(callInfo.phoneNum) - 1), size);
68d95e75fdSopenharmony_ci    std::string number(reinterpret_cast<const char *>(data), length);
69d95e75fdSopenharmony_ci    int32_t mode = static_cast<int32_t>(size % NUM_TWO);
70d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
71d95e75fdSopenharmony_ci    int32_t videoState = static_cast<int32_t>(size % NUM_THREE);
72d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_THREE);
73d95e75fdSopenharmony_ci    const char *cDtmfCode = number.c_str();
74d95e75fdSopenharmony_ci    if (strcpy_s(callInfo.phoneNum, sizeof(callInfo.phoneNum), number.c_str()) != EOK) {
75d95e75fdSopenharmony_ci        return;
76d95e75fdSopenharmony_ci    }
77d95e75fdSopenharmony_ci    callInfo.slotId = slotId;
78d95e75fdSopenharmony_ci    callInfo.videoState = videoState;
79d95e75fdSopenharmony_ci    callInfo.index = index;
80d95e75fdSopenharmony_ci    std::vector<std::string> numberList;
81d95e75fdSopenharmony_ci    numberList.push_back(number);
82d95e75fdSopenharmony_ci    imsCallClient->Dial(callInfo, static_cast<CLIRMode>(mode));
83d95e75fdSopenharmony_ci    imsCallClient->HangUp(callInfo);
84d95e75fdSopenharmony_ci    imsCallClient->Answer(callInfo);
85d95e75fdSopenharmony_ci    imsCallClient->Reject(callInfo);
86d95e75fdSopenharmony_ci    imsCallClient->RejectWithReason(callInfo, ImsRejectReason::USER_DECLINE);
87d95e75fdSopenharmony_ci    imsCallClient->InviteToConference(slotId, numberList);
88d95e75fdSopenharmony_ci    imsCallClient->KickOutFromConference(slotId, index);
89d95e75fdSopenharmony_ci    imsCallClient->StartDtmf(slotId, *cDtmfCode, index);
90d95e75fdSopenharmony_ci    imsCallClient->SendDtmf(slotId, *cDtmfCode, index);
91d95e75fdSopenharmony_ci    imsCallClient->StopDtmf(slotId, index);
92d95e75fdSopenharmony_ci    imsCallClient->StartRtt(slotId, number);
93d95e75fdSopenharmony_ci    imsCallClient->StopRtt(slotId);
94d95e75fdSopenharmony_ci    imsCallClient->SetDomainPreferenceMode(slotId, mode);
95d95e75fdSopenharmony_ci    imsCallClient->GetDomainPreferenceMode(slotId);
96d95e75fdSopenharmony_ci    imsCallClient->SetImsSwitchStatus(slotId, mode);
97d95e75fdSopenharmony_ci    imsCallClient->GetImsSwitchStatus(slotId);
98d95e75fdSopenharmony_ci    imsCallClient->SetMute(slotId, mode);
99d95e75fdSopenharmony_ci    imsCallClient->GetMute(slotId);
100d95e75fdSopenharmony_ci}
101d95e75fdSopenharmony_ci
102d95e75fdSopenharmony_civoid TestImsCallClientWithSlotAndType(
103d95e75fdSopenharmony_ci    const uint8_t *data, size_t size, const std::shared_ptr<ImsCallClient> &imsCallClient)
104d95e75fdSopenharmony_ci{
105d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
106d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_EIGHT);
107d95e75fdSopenharmony_ci    int32_t callType = static_cast<int32_t>(size % NUM_TWO);
108d95e75fdSopenharmony_ci    std::string info(reinterpret_cast<const char *>(data), size);
109d95e75fdSopenharmony_ci    int32_t mode = static_cast<int32_t>(size % NUM_SIX);
110d95e75fdSopenharmony_ci    imsCallClient->HoldCall(slotId, callType);
111d95e75fdSopenharmony_ci    imsCallClient->UnHoldCall(slotId, callType);
112d95e75fdSopenharmony_ci    imsCallClient->SwitchCall(slotId, callType);
113d95e75fdSopenharmony_ci    imsCallClient->CombineConference(slotId);
114d95e75fdSopenharmony_ci    imsCallClient->GetImsCallsDataRequest(slotId, callType);
115d95e75fdSopenharmony_ci    imsCallClient->GetLastCallFailReason(slotId);
116d95e75fdSopenharmony_ci    imsCallClient->ControlCamera(slotId, index, info);
117d95e75fdSopenharmony_ci    imsCallClient->SetPausePicture(slotId, index, info);
118d95e75fdSopenharmony_ci    int len = static_cast<int>(info.length());
119d95e75fdSopenharmony_ci    std::string subSurfaceId = info;
120d95e75fdSopenharmony_ci    if (len >= 1) {
121d95e75fdSopenharmony_ci        subSurfaceId = info.substr(0, 1);
122d95e75fdSopenharmony_ci    }
123d95e75fdSopenharmony_ci    if (subSurfaceId.empty() || subSurfaceId[0] < '0' || subSurfaceId[0] > '9') {
124d95e75fdSopenharmony_ci        subSurfaceId = "";
125d95e75fdSopenharmony_ci        imsCallClient->SetPreviewWindow(slotId, index, subSurfaceId, nullptr);
126d95e75fdSopenharmony_ci        imsCallClient->SetDisplayWindow(slotId, index, subSurfaceId, nullptr);
127d95e75fdSopenharmony_ci    } else {
128d95e75fdSopenharmony_ci        uint64_t tmpSurfaceId = std::stoull(subSurfaceId);
129d95e75fdSopenharmony_ci        auto surface = SurfaceUtils::GetInstance()->GetSurface(tmpSurfaceId);
130d95e75fdSopenharmony_ci        imsCallClient->SetPreviewWindow(slotId, index, subSurfaceId, surface);
131d95e75fdSopenharmony_ci        imsCallClient->SetDisplayWindow(slotId, index, subSurfaceId, surface);
132d95e75fdSopenharmony_ci    }
133d95e75fdSopenharmony_ci    imsCallClient->SetDeviceDirection(slotId, index, mode);
134d95e75fdSopenharmony_ci    imsCallClient->SetCameraZoom(mode);
135d95e75fdSopenharmony_ci    ImsCapabilityList imsCapabilityList;
136d95e75fdSopenharmony_ci    ImsCapability capbility;
137d95e75fdSopenharmony_ci    capbility.enable = mode;
138d95e75fdSopenharmony_ci    capbility.imsCapabilityType = static_cast<ImsCapabilityType>(callType);
139d95e75fdSopenharmony_ci    capbility.imsRadioTech = static_cast<ImsRegTech>(callType);
140d95e75fdSopenharmony_ci    imsCapabilityList.imsCapabilities.push_back(capbility);
141d95e75fdSopenharmony_ci    imsCallClient->UpdateImsCapabilities(slotId, imsCapabilityList);
142d95e75fdSopenharmony_ci}
143d95e75fdSopenharmony_ci
144d95e75fdSopenharmony_civoid TestImsCallClientWithSettingFunction(
145d95e75fdSopenharmony_ci    const uint8_t *data, size_t size, const std::shared_ptr<ImsCallClient> &imsCallClient)
146d95e75fdSopenharmony_ci{
147d95e75fdSopenharmony_ci    CallTransferInfo transferInfo;
148d95e75fdSopenharmony_ci    if (memset_s(&transferInfo, sizeof(struct CallTransferInfo), 0x00, sizeof(struct CallTransferInfo)) != EOK) {
149d95e75fdSopenharmony_ci        return;
150d95e75fdSopenharmony_ci    }
151d95e75fdSopenharmony_ci    size_t length = std::min(static_cast<size_t>(sizeof(transferInfo.transferNum) - 1), size);
152d95e75fdSopenharmony_ci    std::string number(reinterpret_cast<const char *>(data), length);
153d95e75fdSopenharmony_ci    int32_t mode = static_cast<int32_t>(size % NUM_TWO);
154d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
155d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_THREE);
156d95e75fdSopenharmony_ci    int32_t item = static_cast<int32_t>(size % IMS_CONFIG_ITEM_NUM);
157d95e75fdSopenharmony_ci    int32_t value = static_cast<int32_t>(size % NUM_FOUR);
158d95e75fdSopenharmony_ci    int32_t type = static_cast<int32_t>(size % NUM_FOUR);
159d95e75fdSopenharmony_ci    imsCallClient->SetImsConfig(static_cast<ImsConfigItem>(item), number);
160d95e75fdSopenharmony_ci    imsCallClient->SetImsConfig(static_cast<ImsConfigItem>(item), value);
161d95e75fdSopenharmony_ci    imsCallClient->GetImsConfig(static_cast<ImsConfigItem>(item));
162d95e75fdSopenharmony_ci    imsCallClient->SetImsFeatureValue(static_cast<FeatureType>(type), value);
163d95e75fdSopenharmony_ci    imsCallClient->GetImsFeatureValue(static_cast<FeatureType>(type), value);
164d95e75fdSopenharmony_ci    imsCallClient->SetClip(slotId, mode, index);
165d95e75fdSopenharmony_ci    imsCallClient->GetClip(slotId, index);
166d95e75fdSopenharmony_ci    imsCallClient->SetClir(slotId, mode, index);
167d95e75fdSopenharmony_ci    imsCallClient->GetClir(slotId, index);
168d95e75fdSopenharmony_ci    imsCallClient->SetCallWaiting(slotId, mode, type, index);
169d95e75fdSopenharmony_ci    imsCallClient->GetCallWaiting(slotId, index);
170d95e75fdSopenharmony_ci    imsCallClient->SetColr(slotId, mode, index);
171d95e75fdSopenharmony_ci    imsCallClient->GetColr(slotId, index);
172d95e75fdSopenharmony_ci    imsCallClient->SetColp(slotId, mode, index);
173d95e75fdSopenharmony_ci    imsCallClient->GetColp(slotId, index);
174d95e75fdSopenharmony_ci    if (strcpy_s(transferInfo.transferNum, sizeof(transferInfo.transferNum), number.c_str()) != EOK) {
175d95e75fdSopenharmony_ci        return;
176d95e75fdSopenharmony_ci    }
177d95e75fdSopenharmony_ci    transferInfo.settingType = static_cast<CallTransferSettingType>(type);
178d95e75fdSopenharmony_ci    transferInfo.type = static_cast<CallTransferType>(type);
179d95e75fdSopenharmony_ci    imsCallClient->SetCallTransfer(slotId, transferInfo, type, index);
180d95e75fdSopenharmony_ci    imsCallClient->GetCallTransfer(slotId, type, index);
181d95e75fdSopenharmony_ci    imsCallClient->SetCallRestriction(slotId, number, mode, number, index);
182d95e75fdSopenharmony_ci    imsCallClient->GetCallRestriction(slotId, number, index);
183d95e75fdSopenharmony_ci}
184d95e75fdSopenharmony_ci
185d95e75fdSopenharmony_civoid TestImsCallClientWithCallMediaModeRequest(
186d95e75fdSopenharmony_ci    const uint8_t *data, size_t size, const std::shared_ptr<ImsCallClient> &imsCallClient)
187d95e75fdSopenharmony_ci{
188d95e75fdSopenharmony_ci    ImsCallInfo callInfo;
189d95e75fdSopenharmony_ci    if (memset_s(&callInfo, sizeof(struct ImsCallInfo), 0x00, sizeof(struct ImsCallInfo)) != EOK) {
190d95e75fdSopenharmony_ci        return;
191d95e75fdSopenharmony_ci    }
192d95e75fdSopenharmony_ci    size_t length = std::min(static_cast<size_t>(sizeof(callInfo.phoneNum) - 1), size);
193d95e75fdSopenharmony_ci    std::string number(reinterpret_cast<const char *>(data), length);
194d95e75fdSopenharmony_ci    callInfo.slotId = static_cast<int32_t>(size % NUM_TWO);
195d95e75fdSopenharmony_ci    callInfo.videoState = static_cast<int32_t>(size % NUM_TWO);
196d95e75fdSopenharmony_ci    callInfo.index = static_cast<int32_t>(size % NUM_EIGHT);
197d95e75fdSopenharmony_ci    if (strcpy_s(callInfo.phoneNum, sizeof(callInfo.phoneNum), number.c_str()) != EOK) {
198d95e75fdSopenharmony_ci        return;
199d95e75fdSopenharmony_ci    }
200d95e75fdSopenharmony_ci    ImsCallType callMode = static_cast<ImsCallType>(static_cast<int32_t>(size % NUM_SIX));
201d95e75fdSopenharmony_ci    imsCallClient->SendUpdateCallMediaModeRequest(callInfo, callMode);
202d95e75fdSopenharmony_ci}
203d95e75fdSopenharmony_ci
204d95e75fdSopenharmony_civoid TestImsCallClientWithCallMediaModeResponse(
205d95e75fdSopenharmony_ci    const uint8_t *data, size_t size, const std::shared_ptr<ImsCallClient> &imsCallClient)
206d95e75fdSopenharmony_ci{
207d95e75fdSopenharmony_ci    ImsCallInfo callInfo;
208d95e75fdSopenharmony_ci    if (memset_s(&callInfo, sizeof(struct ImsCallInfo), 0x00, sizeof(struct ImsCallInfo)) != EOK) {
209d95e75fdSopenharmony_ci        return;
210d95e75fdSopenharmony_ci    }
211d95e75fdSopenharmony_ci    size_t length = std::min(static_cast<size_t>(sizeof(callInfo.phoneNum) - 1), size);
212d95e75fdSopenharmony_ci    std::string number(reinterpret_cast<const char *>(data), length);
213d95e75fdSopenharmony_ci    callInfo.slotId = static_cast<int32_t>(size % NUM_TWO);
214d95e75fdSopenharmony_ci    callInfo.videoState = static_cast<int32_t>(size % NUM_TWO);
215d95e75fdSopenharmony_ci    callInfo.index = static_cast<int32_t>(size % NUM_EIGHT);
216d95e75fdSopenharmony_ci    if (strcpy_s(callInfo.phoneNum, sizeof(callInfo.phoneNum), number.c_str()) != EOK) {
217d95e75fdSopenharmony_ci        return;
218d95e75fdSopenharmony_ci    }
219d95e75fdSopenharmony_ci    ImsCallType callMode = static_cast<ImsCallType>(static_cast<int32_t>(size % NUM_SIX));
220d95e75fdSopenharmony_ci    imsCallClient->SendUpdateCallMediaModeResponse(callInfo, callMode);
221d95e75fdSopenharmony_ci}
222d95e75fdSopenharmony_ci
223d95e75fdSopenharmony_civoid TestImsCallClientWithCancelCallUpgrade(
224d95e75fdSopenharmony_ci    const uint8_t *data, size_t size, const std::shared_ptr<ImsCallClient> &imsCallClient)
225d95e75fdSopenharmony_ci{
226d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
227d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_EIGHT);
228d95e75fdSopenharmony_ci    imsCallClient->CancelCallUpgrade(slotId, index);
229d95e75fdSopenharmony_ci}
230d95e75fdSopenharmony_ci
231d95e75fdSopenharmony_civoid TestImsCallClientWithRequestCameraCapabilities(
232d95e75fdSopenharmony_ci    const uint8_t *data, size_t size, const std::shared_ptr<ImsCallClient> &imsCallClient)
233d95e75fdSopenharmony_ci{
234d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
235d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_EIGHT);
236d95e75fdSopenharmony_ci    imsCallClient->RequestCameraCapabilities(slotId, index);
237d95e75fdSopenharmony_ci}
238d95e75fdSopenharmony_ci
239d95e75fdSopenharmony_civoid TestImsCallProxyWithCallInfo(const uint8_t *data, size_t size, const sptr<ImsCallInterface> &proxy)
240d95e75fdSopenharmony_ci{
241d95e75fdSopenharmony_ci    ImsCallInfo callInfo;
242d95e75fdSopenharmony_ci    if (memset_s(&callInfo, sizeof(struct ImsCallInfo), 0x00, sizeof(struct ImsCallInfo)) != EOK) {
243d95e75fdSopenharmony_ci        return;
244d95e75fdSopenharmony_ci    }
245d95e75fdSopenharmony_ci    size_t length = std::min(static_cast<size_t>(sizeof(callInfo.phoneNum) - 1), size);
246d95e75fdSopenharmony_ci    std::string number(reinterpret_cast<const char *>(data), length);
247d95e75fdSopenharmony_ci    int32_t mode = static_cast<int32_t>(size % NUM_TWO);
248d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
249d95e75fdSopenharmony_ci    int32_t videoState = static_cast<int32_t>(size % NUM_THREE);
250d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_THREE);
251d95e75fdSopenharmony_ci    const char *cDtmfCode = number.c_str();
252d95e75fdSopenharmony_ci    if (strcpy_s(callInfo.phoneNum, sizeof(callInfo.phoneNum), number.c_str()) != EOK) {
253d95e75fdSopenharmony_ci        return;
254d95e75fdSopenharmony_ci    }
255d95e75fdSopenharmony_ci    callInfo.slotId = slotId;
256d95e75fdSopenharmony_ci    callInfo.videoState = videoState;
257d95e75fdSopenharmony_ci    callInfo.index = index;
258d95e75fdSopenharmony_ci    std::vector<std::string> numberList;
259d95e75fdSopenharmony_ci    numberList.push_back(number);
260d95e75fdSopenharmony_ci    proxy->Dial(callInfo, static_cast<CLIRMode>(mode));
261d95e75fdSopenharmony_ci    proxy->HangUp(callInfo);
262d95e75fdSopenharmony_ci    proxy->Answer(callInfo);
263d95e75fdSopenharmony_ci    proxy->RejectWithReason(callInfo, ImsRejectReason::USER_DECLINE);
264d95e75fdSopenharmony_ci    proxy->InviteToConference(slotId, numberList);
265d95e75fdSopenharmony_ci    proxy->KickOutFromConference(slotId, index);
266d95e75fdSopenharmony_ci    proxy->StartDtmf(slotId, *cDtmfCode, index);
267d95e75fdSopenharmony_ci    proxy->SendDtmf(slotId, *cDtmfCode, index);
268d95e75fdSopenharmony_ci    proxy->StopDtmf(slotId, index);
269d95e75fdSopenharmony_ci    proxy->StartRtt(slotId, number);
270d95e75fdSopenharmony_ci    proxy->StopRtt(slotId);
271d95e75fdSopenharmony_ci    proxy->SetDomainPreferenceMode(slotId, mode);
272d95e75fdSopenharmony_ci    proxy->GetDomainPreferenceMode(slotId);
273d95e75fdSopenharmony_ci    proxy->SetImsSwitchStatus(slotId, mode);
274d95e75fdSopenharmony_ci    proxy->GetImsSwitchStatus(slotId);
275d95e75fdSopenharmony_ci    proxy->SetMute(slotId, mode);
276d95e75fdSopenharmony_ci    proxy->GetMute(slotId);
277d95e75fdSopenharmony_ci}
278d95e75fdSopenharmony_ci
279d95e75fdSopenharmony_civoid TestImsCallProxyWithSlotAndType(const uint8_t *data, size_t size, const sptr<ImsCallInterface> &proxy)
280d95e75fdSopenharmony_ci{
281d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
282d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_EIGHT);
283d95e75fdSopenharmony_ci    int32_t callType = static_cast<int32_t>(size % NUM_TWO);
284d95e75fdSopenharmony_ci    std::string info(reinterpret_cast<const char *>(data), size);
285d95e75fdSopenharmony_ci    int32_t mode = static_cast<int32_t>(size % NUM_SIX);
286d95e75fdSopenharmony_ci    proxy->HoldCall(slotId, callType);
287d95e75fdSopenharmony_ci    proxy->UnHoldCall(slotId, callType);
288d95e75fdSopenharmony_ci    proxy->SwitchCall(slotId, callType);
289d95e75fdSopenharmony_ci    proxy->CombineConference(slotId);
290d95e75fdSopenharmony_ci    proxy->GetImsCallsDataRequest(slotId, callType);
291d95e75fdSopenharmony_ci    proxy->GetLastCallFailReason(slotId);
292d95e75fdSopenharmony_ci    proxy->ControlCamera(slotId, index, info);
293d95e75fdSopenharmony_ci    proxy->SetPausePicture(slotId, index, info);
294d95e75fdSopenharmony_ci    int len = static_cast<int>(info.length());
295d95e75fdSopenharmony_ci    std::string subSurfaceId = info;
296d95e75fdSopenharmony_ci    if (len >= 1) {
297d95e75fdSopenharmony_ci        subSurfaceId = info.substr(0, 1);
298d95e75fdSopenharmony_ci    }
299d95e75fdSopenharmony_ci    if (subSurfaceId.empty() || subSurfaceId[0] < '0' || subSurfaceId[0] > '9') {
300d95e75fdSopenharmony_ci        subSurfaceId = "";
301d95e75fdSopenharmony_ci        proxy->SetPreviewWindow(slotId, index, subSurfaceId, nullptr);
302d95e75fdSopenharmony_ci        proxy->SetDisplayWindow(slotId, index, subSurfaceId, nullptr);
303d95e75fdSopenharmony_ci    } else {
304d95e75fdSopenharmony_ci        uint64_t tmpSurfaceId = std::stoull(subSurfaceId);
305d95e75fdSopenharmony_ci        auto surface = SurfaceUtils::GetInstance()->GetSurface(tmpSurfaceId);
306d95e75fdSopenharmony_ci        proxy->SetPreviewWindow(slotId, index, subSurfaceId, surface);
307d95e75fdSopenharmony_ci        proxy->SetDisplayWindow(slotId, index, subSurfaceId, surface);
308d95e75fdSopenharmony_ci    }
309d95e75fdSopenharmony_ci    proxy->SetDeviceDirection(slotId, index, mode);
310d95e75fdSopenharmony_ci    proxy->SetCameraZoom(mode);
311d95e75fdSopenharmony_ci    ImsCapabilityList imsCapabilityList;
312d95e75fdSopenharmony_ci    ImsCapability capbility;
313d95e75fdSopenharmony_ci    capbility.enable = mode;
314d95e75fdSopenharmony_ci    capbility.imsCapabilityType = static_cast<ImsCapabilityType>(callType);
315d95e75fdSopenharmony_ci    capbility.imsRadioTech = static_cast<ImsRegTech>(callType);
316d95e75fdSopenharmony_ci    imsCapabilityList.imsCapabilities.push_back(capbility);
317d95e75fdSopenharmony_ci    proxy->UpdateImsCapabilities(slotId, imsCapabilityList);
318d95e75fdSopenharmony_ci}
319d95e75fdSopenharmony_ci
320d95e75fdSopenharmony_civoid TestImsCallProxyWithSettingFunction(const uint8_t *data, size_t size, const sptr<ImsCallInterface> &proxy)
321d95e75fdSopenharmony_ci{
322d95e75fdSopenharmony_ci    CallTransferInfo transferInfo;
323d95e75fdSopenharmony_ci    if (memset_s(&transferInfo, sizeof(struct CallTransferInfo), 0x00, sizeof(struct CallTransferInfo)) != EOK) {
324d95e75fdSopenharmony_ci        return;
325d95e75fdSopenharmony_ci    }
326d95e75fdSopenharmony_ci    size_t length = std::min(static_cast<size_t>(sizeof(transferInfo.transferNum) - 1), size);
327d95e75fdSopenharmony_ci    std::string number(reinterpret_cast<const char *>(data), length);
328d95e75fdSopenharmony_ci    int32_t mode = static_cast<int32_t>(size % NUM_TWO);
329d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
330d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_THREE);
331d95e75fdSopenharmony_ci    int32_t item = static_cast<int32_t>(size % IMS_CONFIG_ITEM_NUM);
332d95e75fdSopenharmony_ci    int32_t value = static_cast<int32_t>(size % NUM_FOUR);
333d95e75fdSopenharmony_ci    int32_t type = static_cast<int32_t>(size % NUM_FOUR);
334d95e75fdSopenharmony_ci    proxy->SetImsConfig(static_cast<ImsConfigItem>(item), number);
335d95e75fdSopenharmony_ci    proxy->SetImsConfig(static_cast<ImsConfigItem>(item), value);
336d95e75fdSopenharmony_ci    proxy->GetImsConfig(static_cast<ImsConfigItem>(item));
337d95e75fdSopenharmony_ci    proxy->SetImsFeatureValue(static_cast<FeatureType>(type), value);
338d95e75fdSopenharmony_ci    proxy->GetImsFeatureValue(static_cast<FeatureType>(type), value);
339d95e75fdSopenharmony_ci    proxy->SetClip(slotId, mode, index);
340d95e75fdSopenharmony_ci    proxy->GetClip(slotId, index);
341d95e75fdSopenharmony_ci    proxy->SetClir(slotId, mode, index);
342d95e75fdSopenharmony_ci    proxy->GetClir(slotId, index);
343d95e75fdSopenharmony_ci    proxy->SetCallWaiting(slotId, mode, type, index);
344d95e75fdSopenharmony_ci    proxy->GetCallWaiting(slotId, index);
345d95e75fdSopenharmony_ci    proxy->SetColr(slotId, mode, index);
346d95e75fdSopenharmony_ci    proxy->GetColr(slotId, index);
347d95e75fdSopenharmony_ci    proxy->SetColp(slotId, mode, index);
348d95e75fdSopenharmony_ci    proxy->GetColp(slotId, index);
349d95e75fdSopenharmony_ci    if (strcpy_s(transferInfo.transferNum, sizeof(transferInfo.transferNum), number.c_str()) != EOK) {
350d95e75fdSopenharmony_ci        return;
351d95e75fdSopenharmony_ci    }
352d95e75fdSopenharmony_ci    transferInfo.settingType = static_cast<CallTransferSettingType>(type);
353d95e75fdSopenharmony_ci    transferInfo.type = static_cast<CallTransferType>(type);
354d95e75fdSopenharmony_ci    proxy->SetCallTransfer(slotId, transferInfo, type, index);
355d95e75fdSopenharmony_ci    proxy->GetCallTransfer(slotId, type, index);
356d95e75fdSopenharmony_ci    proxy->SetCallRestriction(slotId, number, mode, number, index);
357d95e75fdSopenharmony_ci    proxy->GetCallRestriction(slotId, number, index);
358d95e75fdSopenharmony_ci}
359d95e75fdSopenharmony_ci
360d95e75fdSopenharmony_civoid TestImsCallProxyWithCallMediaModeRequest(const uint8_t *data, size_t size, const sptr<ImsCallInterface> &proxy)
361d95e75fdSopenharmony_ci{
362d95e75fdSopenharmony_ci    ImsCallInfo callInfo;
363d95e75fdSopenharmony_ci    if (memset_s(&callInfo, sizeof(struct ImsCallInfo), 0x00, sizeof(struct ImsCallInfo)) != EOK) {
364d95e75fdSopenharmony_ci        return;
365d95e75fdSopenharmony_ci    }
366d95e75fdSopenharmony_ci    size_t length = std::min(static_cast<size_t>(sizeof(callInfo.phoneNum) - 1), size);
367d95e75fdSopenharmony_ci    std::string number(reinterpret_cast<const char *>(data), length);
368d95e75fdSopenharmony_ci    callInfo.slotId = static_cast<int32_t>(size % NUM_TWO);
369d95e75fdSopenharmony_ci    callInfo.videoState = static_cast<int32_t>(size % NUM_TWO);
370d95e75fdSopenharmony_ci    callInfo.index = static_cast<int32_t>(size % NUM_EIGHT);
371d95e75fdSopenharmony_ci    if (strcpy_s(callInfo.phoneNum, sizeof(callInfo.phoneNum), number.c_str()) != EOK) {
372d95e75fdSopenharmony_ci        return;
373d95e75fdSopenharmony_ci    }
374d95e75fdSopenharmony_ci    ImsCallType callType = static_cast<ImsCallType>(static_cast<int32_t>(size % NUM_SIX));
375d95e75fdSopenharmony_ci    proxy->SendUpdateCallMediaModeRequest(callInfo, callType);
376d95e75fdSopenharmony_ci}
377d95e75fdSopenharmony_ci
378d95e75fdSopenharmony_civoid TestImsCallProxyWithCallMediaModeResponse(const uint8_t *data, size_t size, const sptr<ImsCallInterface> &proxy)
379d95e75fdSopenharmony_ci{
380d95e75fdSopenharmony_ci    ImsCallInfo callInfo;
381d95e75fdSopenharmony_ci    if (memset_s(&callInfo, sizeof(struct ImsCallInfo), 0x00, sizeof(struct ImsCallInfo)) != EOK) {
382d95e75fdSopenharmony_ci        return;
383d95e75fdSopenharmony_ci    }
384d95e75fdSopenharmony_ci    size_t length = std::min(static_cast<size_t>(sizeof(callInfo.phoneNum) - 1), size);
385d95e75fdSopenharmony_ci    std::string number(reinterpret_cast<const char *>(data), length);
386d95e75fdSopenharmony_ci    callInfo.slotId = static_cast<int32_t>(size % NUM_TWO);
387d95e75fdSopenharmony_ci    callInfo.videoState = static_cast<int32_t>(size % NUM_TWO);
388d95e75fdSopenharmony_ci    callInfo.index = static_cast<int32_t>(size % NUM_EIGHT);
389d95e75fdSopenharmony_ci    if (strcpy_s(callInfo.phoneNum, sizeof(callInfo.phoneNum), number.c_str()) != EOK) {
390d95e75fdSopenharmony_ci        return;
391d95e75fdSopenharmony_ci    }
392d95e75fdSopenharmony_ci    ImsCallType callType = static_cast<ImsCallType>(static_cast<int32_t>(size % NUM_SIX));
393d95e75fdSopenharmony_ci    proxy->SendUpdateCallMediaModeResponse(callInfo, callType);
394d95e75fdSopenharmony_ci}
395d95e75fdSopenharmony_ci
396d95e75fdSopenharmony_civoid TestImsCallProxyWithCancelCallUpgrade(const uint8_t *data, size_t size, const sptr<ImsCallInterface> &proxy)
397d95e75fdSopenharmony_ci{
398d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
399d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_EIGHT);
400d95e75fdSopenharmony_ci    proxy->CancelCallUpgrade(slotId, index);
401d95e75fdSopenharmony_ci}
402d95e75fdSopenharmony_ci
403d95e75fdSopenharmony_civoid TestImsCallProxyWithRequestCameraCapabilities(
404d95e75fdSopenharmony_ci    const uint8_t *data, size_t size, const sptr<ImsCallInterface> &proxy)
405d95e75fdSopenharmony_ci{
406d95e75fdSopenharmony_ci    int32_t slotId = static_cast<int32_t>(size % NUM_TWO);
407d95e75fdSopenharmony_ci    int32_t index = static_cast<int32_t>(size % NUM_EIGHT);
408d95e75fdSopenharmony_ci    proxy->RequestCameraCapabilities(slotId, index);
409d95e75fdSopenharmony_ci}
410d95e75fdSopenharmony_ci
411d95e75fdSopenharmony_civoid DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
412d95e75fdSopenharmony_ci{
413d95e75fdSopenharmony_ci    if (data == nullptr || size == 0) {
414d95e75fdSopenharmony_ci        return;
415d95e75fdSopenharmony_ci    }
416d95e75fdSopenharmony_ci    auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
417d95e75fdSopenharmony_ci    if (imsCallClient == nullptr) {
418d95e75fdSopenharmony_ci        return;
419d95e75fdSopenharmony_ci    }
420d95e75fdSopenharmony_ci    if (!IsServiceInited()) {
421d95e75fdSopenharmony_ci        return;
422d95e75fdSopenharmony_ci    }
423d95e75fdSopenharmony_ci    TestImsCallClientWithCallInfo(data, size, imsCallClient);
424d95e75fdSopenharmony_ci    TestImsCallClientWithSlotAndType(data, size, imsCallClient);
425d95e75fdSopenharmony_ci    TestImsCallClientWithSettingFunction(data, size, imsCallClient);
426d95e75fdSopenharmony_ci    TestImsCallClientWithCallMediaModeRequest(data, size, imsCallClient);
427d95e75fdSopenharmony_ci    TestImsCallClientWithCallMediaModeResponse(data, size, imsCallClient);
428d95e75fdSopenharmony_ci    TestImsCallClientWithCancelCallUpgrade(data, size, imsCallClient);
429d95e75fdSopenharmony_ci    TestImsCallClientWithRequestCameraCapabilities(data, size, imsCallClient);
430d95e75fdSopenharmony_ci
431d95e75fdSopenharmony_ci    auto managerPtr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
432d95e75fdSopenharmony_ci    if (managerPtr == nullptr) {
433d95e75fdSopenharmony_ci        return;
434d95e75fdSopenharmony_ci    }
435d95e75fdSopenharmony_ci    auto remoteObjectPtr = managerPtr->CheckSystemAbility(TELEPHONY_IMS_SYS_ABILITY_ID);
436d95e75fdSopenharmony_ci    if (remoteObjectPtr == nullptr) {
437d95e75fdSopenharmony_ci        return;
438d95e75fdSopenharmony_ci    }
439d95e75fdSopenharmony_ci    sptr<ImsCallInterface> proxy = iface_cast<ImsCallInterface>(remoteObjectPtr);
440d95e75fdSopenharmony_ci    if (proxy == nullptr) {
441d95e75fdSopenharmony_ci        return;
442d95e75fdSopenharmony_ci    }
443d95e75fdSopenharmony_ci    TestImsCallProxyWithCallInfo(data, size, proxy);
444d95e75fdSopenharmony_ci    TestImsCallProxyWithSlotAndType(data, size, proxy);
445d95e75fdSopenharmony_ci    TestImsCallProxyWithSettingFunction(data, size, proxy);
446d95e75fdSopenharmony_ci    TestImsCallProxyWithCallMediaModeRequest(data, size, proxy);
447d95e75fdSopenharmony_ci    TestImsCallProxyWithCallMediaModeResponse(data, size, proxy);
448d95e75fdSopenharmony_ci    TestImsCallProxyWithCancelCallUpgrade(data, size, proxy);
449d95e75fdSopenharmony_ci    TestImsCallProxyWithRequestCameraCapabilities(data, size, proxy);
450d95e75fdSopenharmony_ci    proxy.clear();
451d95e75fdSopenharmony_ci    proxy = nullptr;
452d95e75fdSopenharmony_ci}
453d95e75fdSopenharmony_ci} // namespace OHOS
454d95e75fdSopenharmony_ci
455d95e75fdSopenharmony_ci/* Fuzzer entry point */
456d95e75fdSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
457d95e75fdSopenharmony_ci{
458d95e75fdSopenharmony_ci    OHOS::AddCellularCallTokenFuzzer token;
459d95e75fdSopenharmony_ci    /* Run your code on data */
460d95e75fdSopenharmony_ci    OHOS::DoSomethingInterestingWithMyAPI(data, size);
461d95e75fdSopenharmony_ci    return 0;
462d95e75fdSopenharmony_ci}
463