1e1c44949Sopenharmony_ci/* 2e1c44949Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License. 5e1c44949Sopenharmony_ci * You may obtain a copy of the License at 6e1c44949Sopenharmony_ci * 7e1c44949Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e1c44949Sopenharmony_ci * 9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and 13e1c44949Sopenharmony_ci * limitations under the License. 14e1c44949Sopenharmony_ci */ 15e1c44949Sopenharmony_ci 16e1c44949Sopenharmony_ci#include "callnotification_fuzzer.h" 17e1c44949Sopenharmony_ci 18e1c44949Sopenharmony_ci#include <cstddef> 19e1c44949Sopenharmony_ci#include <cstdint> 20e1c44949Sopenharmony_ci#include <securec.h> 21e1c44949Sopenharmony_ci#define private public 22e1c44949Sopenharmony_ci#include "addcalltoken_fuzzer.h" 23e1c44949Sopenharmony_ci#include "call_data_base_helper.h" 24e1c44949Sopenharmony_ci#include "cs_call.h" 25e1c44949Sopenharmony_ci#include "incoming_call_notification.h" 26e1c44949Sopenharmony_ci#include "incoming_call_wake_up.h" 27e1c44949Sopenharmony_ci#include "missed_call_notification.h" 28e1c44949Sopenharmony_ci#include "proximity_sensor.h" 29e1c44949Sopenharmony_ci#include "reject_call_sms.h" 30e1c44949Sopenharmony_ci#include "status_bar.h" 31e1c44949Sopenharmony_ci#include "wired_headset.h" 32e1c44949Sopenharmony_ci 33e1c44949Sopenharmony_ciusing namespace OHOS::Telephony; 34e1c44949Sopenharmony_cinamespace OHOS { 35e1c44949Sopenharmony_ciconstexpr int32_t CALL_STATE_NUM = 8; 36e1c44949Sopenharmony_ciconstexpr int32_t BOOL_NUM = 2; 37e1c44949Sopenharmony_ci 38e1c44949Sopenharmony_civoid IncomingCallNotificationFunc(const uint8_t *data, size_t size) 39e1c44949Sopenharmony_ci{ 40e1c44949Sopenharmony_ci if (!IsServiceInited()) { 41e1c44949Sopenharmony_ci return; 42e1c44949Sopenharmony_ci } 43e1c44949Sopenharmony_ci 44e1c44949Sopenharmony_ci std::shared_ptr<IncomingCallNotification> notification = std::make_shared<IncomingCallNotification>(); 45e1c44949Sopenharmony_ci DialParaInfo paraInfo; 46e1c44949Sopenharmony_ci sptr<CallBase> callObjectPtr = std::make_unique<CSCall>(paraInfo).release(); 47e1c44949Sopenharmony_ci TelCallState priorState = static_cast<TelCallState>(size % CALL_STATE_NUM); 48e1c44949Sopenharmony_ci TelCallState nextState = static_cast<TelCallState>(size % CALL_STATE_NUM); 49e1c44949Sopenharmony_ci std::string message(reinterpret_cast<const char *>(data), size); 50e1c44949Sopenharmony_ci DisconnectedDetails details; 51e1c44949Sopenharmony_ci 52e1c44949Sopenharmony_ci notification->NewCallCreated(callObjectPtr); 53e1c44949Sopenharmony_ci notification->CallStateUpdated(callObjectPtr, priorState, nextState); 54e1c44949Sopenharmony_ci notification->IncomingCallActivated(callObjectPtr); 55e1c44949Sopenharmony_ci notification->IncomingCallHungUp(callObjectPtr, true, message); 56e1c44949Sopenharmony_ci notification->CallDestroyed(details); 57e1c44949Sopenharmony_ci notification->PublishIncomingCallNotification(callObjectPtr); 58e1c44949Sopenharmony_ci notification->CancelIncomingCallNotification(); 59e1c44949Sopenharmony_ci notification->IsFullScreen(); 60e1c44949Sopenharmony_ci} 61e1c44949Sopenharmony_ci 62e1c44949Sopenharmony_civoid IncomingCallWakeupFunc(const uint8_t *data, size_t size) 63e1c44949Sopenharmony_ci{ 64e1c44949Sopenharmony_ci if (!IsServiceInited()) { 65e1c44949Sopenharmony_ci return; 66e1c44949Sopenharmony_ci } 67e1c44949Sopenharmony_ci 68e1c44949Sopenharmony_ci std::shared_ptr<IncomingCallWakeup> notification = std::make_shared<IncomingCallWakeup>(); 69e1c44949Sopenharmony_ci DialParaInfo paraInfo; 70e1c44949Sopenharmony_ci sptr<CallBase> callObjectPtr = std::make_unique<CSCall>(paraInfo).release(); 71e1c44949Sopenharmony_ci TelCallState priorState = static_cast<TelCallState>(size % CALL_STATE_NUM); 72e1c44949Sopenharmony_ci TelCallState nextState = static_cast<TelCallState>(size % CALL_STATE_NUM); 73e1c44949Sopenharmony_ci std::string message(reinterpret_cast<const char *>(data), size); 74e1c44949Sopenharmony_ci DisconnectedDetails details; 75e1c44949Sopenharmony_ci 76e1c44949Sopenharmony_ci notification->NewCallCreated(callObjectPtr); 77e1c44949Sopenharmony_ci notification->WakeupDevice(callObjectPtr); 78e1c44949Sopenharmony_ci notification->IsPowerAbilityExist(); 79e1c44949Sopenharmony_ci notification->CallDestroyed(details); 80e1c44949Sopenharmony_ci notification->IncomingCallActivated(callObjectPtr); 81e1c44949Sopenharmony_ci notification->IncomingCallHungUp(callObjectPtr, true, message); 82e1c44949Sopenharmony_ci notification->CallStateUpdated(callObjectPtr, priorState, nextState); 83e1c44949Sopenharmony_ci} 84e1c44949Sopenharmony_ci 85e1c44949Sopenharmony_civoid ProximitySensorFunc(const uint8_t *data, size_t size) 86e1c44949Sopenharmony_ci{ 87e1c44949Sopenharmony_ci if (!IsServiceInited()) { 88e1c44949Sopenharmony_ci return; 89e1c44949Sopenharmony_ci } 90e1c44949Sopenharmony_ci 91e1c44949Sopenharmony_ci std::shared_ptr<ProximitySensor> notification = std::make_shared<ProximitySensor>(); 92e1c44949Sopenharmony_ci DialParaInfo paraInfo; 93e1c44949Sopenharmony_ci sptr<CallBase> callObjectPtr = std::make_unique<CSCall>(paraInfo).release(); 94e1c44949Sopenharmony_ci TelCallState priorState = static_cast<TelCallState>(size % CALL_STATE_NUM); 95e1c44949Sopenharmony_ci TelCallState nextState = static_cast<TelCallState>(size % CALL_STATE_NUM); 96e1c44949Sopenharmony_ci std::string message(reinterpret_cast<const char *>(data), size); 97e1c44949Sopenharmony_ci DisconnectedDetails details; 98e1c44949Sopenharmony_ci 99e1c44949Sopenharmony_ci notification->CallDestroyed(details); 100e1c44949Sopenharmony_ci notification->NewCallCreated(callObjectPtr); 101e1c44949Sopenharmony_ci notification->IncomingCallActivated(callObjectPtr); 102e1c44949Sopenharmony_ci notification->IncomingCallHungUp(callObjectPtr, true, message); 103e1c44949Sopenharmony_ci notification->CallStateUpdated(callObjectPtr, priorState, nextState); 104e1c44949Sopenharmony_ci} 105e1c44949Sopenharmony_ci 106e1c44949Sopenharmony_civoid StatusBarFunc(const uint8_t *data, size_t size) 107e1c44949Sopenharmony_ci{ 108e1c44949Sopenharmony_ci if (!IsServiceInited()) { 109e1c44949Sopenharmony_ci return; 110e1c44949Sopenharmony_ci } 111e1c44949Sopenharmony_ci 112e1c44949Sopenharmony_ci std::shared_ptr<StatusBar> notification = std::make_shared<StatusBar>(); 113e1c44949Sopenharmony_ci DialParaInfo paraInfo; 114e1c44949Sopenharmony_ci sptr<CallBase> callObjectPtr = std::make_unique<CSCall>(paraInfo).release(); 115e1c44949Sopenharmony_ci TelCallState priorState = static_cast<TelCallState>(size % CALL_STATE_NUM); 116e1c44949Sopenharmony_ci TelCallState nextState = static_cast<TelCallState>(size % CALL_STATE_NUM); 117e1c44949Sopenharmony_ci std::string message(reinterpret_cast<const char *>(data), size); 118e1c44949Sopenharmony_ci DisconnectedDetails details; 119e1c44949Sopenharmony_ci int32_t isDisplayMute = static_cast<int32_t>(size % BOOL_NUM); 120e1c44949Sopenharmony_ci 121e1c44949Sopenharmony_ci notification->UpdateMuteIcon(isDisplayMute); 122e1c44949Sopenharmony_ci notification->UpdateSpeakerphoneIcon(isDisplayMute); 123e1c44949Sopenharmony_ci notification->NewCallCreated(callObjectPtr); 124e1c44949Sopenharmony_ci notification->CallDestroyed(details); 125e1c44949Sopenharmony_ci notification->IncomingCallActivated(callObjectPtr); 126e1c44949Sopenharmony_ci notification->IncomingCallHungUp(callObjectPtr, true, message); 127e1c44949Sopenharmony_ci notification->CallStateUpdated(callObjectPtr, priorState, nextState); 128e1c44949Sopenharmony_ci} 129e1c44949Sopenharmony_ci 130e1c44949Sopenharmony_civoid WiredHeadsetHandlerFunc(const uint8_t *data, size_t size) 131e1c44949Sopenharmony_ci{ 132e1c44949Sopenharmony_ci if (!IsServiceInited()) { 133e1c44949Sopenharmony_ci return; 134e1c44949Sopenharmony_ci } 135e1c44949Sopenharmony_ci 136e1c44949Sopenharmony_ci std::shared_ptr<WiredHeadset> notification = std::make_shared<WiredHeadset>(); 137e1c44949Sopenharmony_ci DialParaInfo paraInfo; 138e1c44949Sopenharmony_ci sptr<CallBase> callObjectPtr = std::make_unique<CSCall>(paraInfo).release(); 139e1c44949Sopenharmony_ci TelCallState priorState = static_cast<TelCallState>(size % CALL_STATE_NUM); 140e1c44949Sopenharmony_ci TelCallState nextState = static_cast<TelCallState>(size % CALL_STATE_NUM); 141e1c44949Sopenharmony_ci std::string message(reinterpret_cast<const char *>(data), size); 142e1c44949Sopenharmony_ci DisconnectedDetails details; 143e1c44949Sopenharmony_ci 144e1c44949Sopenharmony_ci notification->Init(); 145e1c44949Sopenharmony_ci notification->NewCallCreated(callObjectPtr); 146e1c44949Sopenharmony_ci notification->CallDestroyed(details); 147e1c44949Sopenharmony_ci notification->IncomingCallActivated(callObjectPtr); 148e1c44949Sopenharmony_ci notification->IncomingCallHungUp(callObjectPtr, true, message); 149e1c44949Sopenharmony_ci notification->CallStateUpdated(callObjectPtr, priorState, nextState); 150e1c44949Sopenharmony_ci} 151e1c44949Sopenharmony_ci 152e1c44949Sopenharmony_civoid CallDataRdbObserverFunc(const uint8_t *data, size_t size) 153e1c44949Sopenharmony_ci{ 154e1c44949Sopenharmony_ci if (!IsServiceInited()) { 155e1c44949Sopenharmony_ci return; 156e1c44949Sopenharmony_ci } 157e1c44949Sopenharmony_ci 158e1c44949Sopenharmony_ci std::string message(reinterpret_cast<const char *>(data), size); 159e1c44949Sopenharmony_ci std::shared_ptr<CallDataBaseHelper> callDataBaseHelper = DelayedSingleton<CallDataBaseHelper>::GetInstance(); 160e1c44949Sopenharmony_ci DataShare::DataShareValuesBucket values; 161e1c44949Sopenharmony_ci DataShare::DataSharePredicates predicates; 162e1c44949Sopenharmony_ci DialParaInfo paraInfo; 163e1c44949Sopenharmony_ci sptr<CallBase> callObjectPtr = std::make_unique<CSCall>(paraInfo).release(); 164e1c44949Sopenharmony_ci ContactInfo contactInfo; 165e1c44949Sopenharmony_ci contactInfo.name = message; 166e1c44949Sopenharmony_ci contactInfo.number = message; 167e1c44949Sopenharmony_ci int32_t length = message.length() > FILE_PATH_MAX_LEN ? FILE_PATH_MAX_LEN : message.length(); 168e1c44949Sopenharmony_ci if (memcpy_s(contactInfo.ringtonePath, FILE_PATH_MAX_LEN, message.c_str(), length) != EOK) { 169e1c44949Sopenharmony_ci return; 170e1c44949Sopenharmony_ci } 171e1c44949Sopenharmony_ci 172e1c44949Sopenharmony_ci callDataBaseHelper->UnRegisterObserver(); 173e1c44949Sopenharmony_ci callDataBaseHelper->Insert(values); 174e1c44949Sopenharmony_ci callDataBaseHelper->Query(contactInfo, predicates); 175e1c44949Sopenharmony_ci callDataBaseHelper->Delete(predicates); 176e1c44949Sopenharmony_ci} 177e1c44949Sopenharmony_ci 178e1c44949Sopenharmony_civoid MissedCallNotificationFunc(const uint8_t *data, size_t size) 179e1c44949Sopenharmony_ci{ 180e1c44949Sopenharmony_ci if (!IsServiceInited()) { 181e1c44949Sopenharmony_ci return; 182e1c44949Sopenharmony_ci } 183e1c44949Sopenharmony_ci 184e1c44949Sopenharmony_ci std::shared_ptr<MissedCallNotification> notification = std::make_shared<MissedCallNotification>(); 185e1c44949Sopenharmony_ci DialParaInfo paraInfo; 186e1c44949Sopenharmony_ci sptr<CallBase> callObjectPtr = std::make_unique<CSCall>(paraInfo).release(); 187e1c44949Sopenharmony_ci TelCallState priorState = static_cast<TelCallState>(size % CALL_STATE_NUM); 188e1c44949Sopenharmony_ci TelCallState nextState = static_cast<TelCallState>(size % CALL_STATE_NUM); 189e1c44949Sopenharmony_ci std::string message(reinterpret_cast<const char *>(data), size); 190e1c44949Sopenharmony_ci DisconnectedDetails details; 191e1c44949Sopenharmony_ci 192e1c44949Sopenharmony_ci notification->NewCallCreated(callObjectPtr); 193e1c44949Sopenharmony_ci notification->PublishMissedCallEvent(callObjectPtr); 194e1c44949Sopenharmony_ci notification->PublishMissedCallNotification(callObjectPtr); 195e1c44949Sopenharmony_ci notification->CancelMissedCallsNotification(static_cast<int32_t>(size)); 196e1c44949Sopenharmony_ci notification->CallDestroyed(details); 197e1c44949Sopenharmony_ci notification->IncomingCallActivated(callObjectPtr); 198e1c44949Sopenharmony_ci notification->IncomingCallHungUp(callObjectPtr, true, message); 199e1c44949Sopenharmony_ci notification->CallStateUpdated(callObjectPtr, priorState, nextState); 200e1c44949Sopenharmony_ci} 201e1c44949Sopenharmony_ci 202e1c44949Sopenharmony_civoid RejectCallSmsFunc(const uint8_t *data, size_t size) 203e1c44949Sopenharmony_ci{ 204e1c44949Sopenharmony_ci if (!IsServiceInited()) { 205e1c44949Sopenharmony_ci return; 206e1c44949Sopenharmony_ci } 207e1c44949Sopenharmony_ci 208e1c44949Sopenharmony_ci std::shared_ptr<RejectCallSms> notification = std::make_shared<RejectCallSms>(); 209e1c44949Sopenharmony_ci DialParaInfo paraInfo; 210e1c44949Sopenharmony_ci int32_t slotId = static_cast<int32_t>(size % 2); 211e1c44949Sopenharmony_ci sptr<CallBase> callObjectPtr = std::make_unique<CSCall>(paraInfo).release(); 212e1c44949Sopenharmony_ci TelCallState priorState = static_cast<TelCallState>(size % CALL_STATE_NUM); 213e1c44949Sopenharmony_ci TelCallState nextState = static_cast<TelCallState>(size % CALL_STATE_NUM); 214e1c44949Sopenharmony_ci std::string message(reinterpret_cast<const char *>(data), size); 215e1c44949Sopenharmony_ci std::string desAddr(reinterpret_cast<const char *>(data), size); 216e1c44949Sopenharmony_ci std::u16string desAddrU16 = Str8ToStr16(desAddr); 217e1c44949Sopenharmony_ci std::u16string messageU16 = Str8ToStr16(message); 218e1c44949Sopenharmony_ci DisconnectedDetails details; 219e1c44949Sopenharmony_ci 220e1c44949Sopenharmony_ci notification->NewCallCreated(callObjectPtr); 221e1c44949Sopenharmony_ci notification->SendMessage(slotId, desAddrU16, messageU16); 222e1c44949Sopenharmony_ci notification->CallDestroyed(details); 223e1c44949Sopenharmony_ci notification->IncomingCallActivated(callObjectPtr); 224e1c44949Sopenharmony_ci notification->IncomingCallHungUp(callObjectPtr, true, message); 225e1c44949Sopenharmony_ci notification->CallStateUpdated(callObjectPtr, priorState, nextState); 226e1c44949Sopenharmony_ci} 227e1c44949Sopenharmony_ci 228e1c44949Sopenharmony_civoid DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) 229e1c44949Sopenharmony_ci{ 230e1c44949Sopenharmony_ci if (data == nullptr || size == 0) { 231e1c44949Sopenharmony_ci return; 232e1c44949Sopenharmony_ci } 233e1c44949Sopenharmony_ci 234e1c44949Sopenharmony_ci IncomingCallNotificationFunc(data, size); 235e1c44949Sopenharmony_ci IncomingCallWakeupFunc(data, size); 236e1c44949Sopenharmony_ci ProximitySensorFunc(data, size); 237e1c44949Sopenharmony_ci StatusBarFunc(data, size); 238e1c44949Sopenharmony_ci WiredHeadsetHandlerFunc(data, size); 239e1c44949Sopenharmony_ci CallDataRdbObserverFunc(data, size); 240e1c44949Sopenharmony_ci MissedCallNotificationFunc(data, size); 241e1c44949Sopenharmony_ci RejectCallSmsFunc(data, size); 242e1c44949Sopenharmony_ci} 243e1c44949Sopenharmony_ci} // namespace OHOS 244e1c44949Sopenharmony_ci 245e1c44949Sopenharmony_ci/* Fuzzer entry point */ 246e1c44949Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 247e1c44949Sopenharmony_ci{ 248e1c44949Sopenharmony_ci OHOS::AddCallTokenFuzzer token; 249e1c44949Sopenharmony_ci /* Run your code on data */ 250e1c44949Sopenharmony_ci OHOS::DoSomethingInterestingWithMyAPI(data, size); 251e1c44949Sopenharmony_ci return 0; 252e1c44949Sopenharmony_ci} 253