1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "answerrequest_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #include "addcellularcalltoken_fuzzer.h"
22 #include "cellular_call_connection_ims.h"
23 #include "system_ability_definition.h"
24 
25 using namespace OHOS::Telephony;
26 namespace OHOS {
27 constexpr int32_t SLOT_NUM = 2;
28 constexpr int32_t VEDIO_STATE_NUM = 2;
29 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)30 void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
31 {
32     if (data == nullptr || size == 0) {
33         return;
34     }
35 
36     auto cellularCallConnectionIMS = std::shared_ptr<CellularCallConnectionIMS>();
37     std::string phoneNum(reinterpret_cast<const char *>(data), size);
38     std::string msg(reinterpret_cast<const char *>(data), size);
39     int32_t slotId = static_cast<int32_t>(size % SLOT_NUM);
40     int32_t videoState = static_cast<int32_t>(size % VEDIO_STATE_NUM);
41     int32_t index = static_cast<int32_t>(size);
42     std::vector<std::string> numberList;
43     numberList.push_back(phoneNum);
44     cellularCallConnectionIMS->HangUpRequest(slotId, phoneNum, index);
45     cellularCallConnectionIMS->AnswerRequest(slotId, phoneNum, videoState, index);
46     cellularCallConnectionIMS->RejectRequest(slotId, phoneNum, index);
47     cellularCallConnectionIMS->HoldCallRequest(slotId);
48     cellularCallConnectionIMS->UnHoldCallRequest(slotId);
49     cellularCallConnectionIMS->InviteToConferenceRequest(slotId, numberList);
50     cellularCallConnectionIMS->KickOutFromConferenceRequest(slotId, index);
51     cellularCallConnectionIMS->StartRttRequest(slotId, msg);
52     cellularCallConnectionIMS->StopRttRequest(slotId);
53     return;
54 }
55 } // namespace OHOS
56 
57 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)58 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
59 {
60     OHOS::AddCellularCallTokenFuzzer token;
61     /* Run your code on data */
62     OHOS::DoSomethingInterestingWithMyAPI(data, size);
63     return 0;
64 }
65