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 "setprogressbar_fuzzer.h" 17 #include "notification_request.h" 18 #include <fuzzer/FuzzedDataProvider.h> 19 20 namespace OHOS { 21 namespace { 22 constexpr uint8_t SLOT_TYPE_NUM = 5; 23 } DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)24 bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp) 25 { 26 std::string stringData = fdp->ConsumeRandomLengthString(); 27 int32_t notificationId = fdp->ConsumeIntegral<int32_t>(); 28 Notification::NotificationRequest request(notificationId); 29 bool enabled = fdp->ConsumeBool(); 30 request.SetIsAgentNotification(enabled); 31 std::shared_ptr<Notification::MessageUser> messageUser = nullptr; 32 request.AddMessageUser(messageUser); 33 request.IsAlertOneTime(); 34 uint64_t deletedTime = 1; 35 request.SetAutoDeletedTime(deletedTime); 36 request.GetAutoDeletedTime(); 37 std::shared_ptr<Media::PixelMap> icon = nullptr; 38 request.SetLittleIcon(icon); 39 request.SetBigIcon(icon); 40 request.GetClassification(); 41 request.GetColor(); 42 request.IsColorEnabled(); 43 request.IsCountdownTimer(); 44 request.GetGroupAlertType(); 45 request.IsGroupOverview(); 46 request.GetGroupName(); 47 request.IsOnlyLocal(); 48 request.SetOnlyLocal(enabled); 49 request.SetSettingsText(stringData); 50 request.GetSettingsText(); 51 request.GetCreateTime(); 52 request.IsShowStopwatch(); 53 request.SetShowStopwatch(enabled); 54 uint8_t type = fdp->ConsumeIntegral<uint8_t>() % SLOT_TYPE_NUM; 55 Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); 56 request.SetSlotType(slotType); 57 request.GetSlotType(); 58 request.SetSortingKey(stringData); 59 request.GetSortingKey(); 60 request.SetStatusBarText(stringData); 61 request.GetStatusBarText(); 62 return request.IsTapDismissed(); 63 } 64 } 65 66 /* Fuzzer entry point */ LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 68 { 69 /* Run your code on data */ 70 FuzzedDataProvider fdp(data, size); 71 OHOS::DoSomethingInterestingWithMyAPI(&fdp); 72 return 0; 73 } 74