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 
19 namespace OHOS {
20     namespace {
21         constexpr uint8_t ENABLE = 2;
22         constexpr uint8_t SLOT_TYPE_NUM = 5;
23     }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)24     bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
25     {
26         std::string stringData(data);
27         int32_t notificationId = static_cast<int32_t>(GetU32Data(data));
28         Notification::NotificationRequest request(notificationId);
29         bool enabled = *data % ENABLE;
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 = *data % 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)67 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
68 {
69     /* Run your code on data */
70     char *ch = ParseData(data, size);
71     if (ch != nullptr && size >= GetU32Size()) {
72         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
73         free(ch);
74         ch = nullptr;
75     }
76     return 0;
77 }
78