• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define private public
17 #define protected public
18 #include "ans_manager_stub.h"
19 #undef private
20 #undef protected
21 #include "ansmanagerstubannexthree_fuzzer.h"
22 
23 namespace OHOS {
24     namespace {
25         constexpr uint8_t ENABLE = 2;
26         constexpr uint8_t SLOT_TYPE_NUM = 5;
27     }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)28     bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
29     {
30         Notification::AnsManagerStub ansManagerStub;
31         bool allow = *data % ENABLE;
32         ansManagerStub.GetPrivateNotificationsAllowed(allow);
33         sptr<Notification::NotificationBundleOption> bundleOption = new Notification::NotificationBundleOption();
34         int notificationId = 1;
35         std::string stringData(data);
36         int32_t removeReason = static_cast<int32_t>(GetU32Data(data));
37         ansManagerStub.RemoveNotification(bundleOption, notificationId, stringData, removeReason);
38         ansManagerStub.RemoveAllNotifications(bundleOption);
39         ansManagerStub.Delete(stringData, removeReason);
40         ansManagerStub.DeleteByBundle(bundleOption);
41         ansManagerStub.DeleteAll();
42         sptr<Notification::NotificationSlot> slot = new Notification::NotificationSlot();
43         std::vector<sptr<Notification::NotificationSlot>> slots;
44         slots.emplace_back(slot);
45         ansManagerStub.GetSlotsByBundle(bundleOption, slots);
46         ansManagerStub.SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, allow);
47         ansManagerStub.SetShowBadgeEnabledForBundle(bundleOption, allow);
48         ansManagerStub.GetShowBadgeEnabledForBundle(bundleOption, allow);
49         ansManagerStub.GetShowBadgeEnabled(allow);
50         ansManagerStub.AreNotificationsSuspended(allow);
51         sptr<Notification::NotificationSortingMap> sortingMap = new Notification::NotificationSortingMap();
52         ansManagerStub.GetCurrentAppSorting(sortingMap);
53         ansManagerStub.IsAllowedNotify(allow);
54         ansManagerStub.IsAllowedNotifySelf(allow);
55         ansManagerStub.IsSpecialBundleAllowedNotify(bundleOption, allow);
56         ansManagerStub.CancelGroup(stringData);
57         ansManagerStub.RemoveGroupByBundle(bundleOption, stringData);
58         ansManagerStub.DoesSupportDoNotDisturbMode(allow);
59         ansManagerStub.IsDistributedEnabled(allow);
60         ansManagerStub.EnableDistributed(allow);
61         ansManagerStub.EnableDistributedByBundle(bundleOption, allow);
62         ansManagerStub.EnableDistributedSelf(allow);
63         ansManagerStub.IsDistributedEnableByBundle(bundleOption, allow);
64         int32_t remindType = static_cast<int32_t>(*data % SLOT_TYPE_NUM);
65         Notification::NotificationConstant::RemindType remind =
66             Notification::NotificationConstant::RemindType(remindType);
67         ansManagerStub.GetDeviceRemindType(remind);
68         sptr<Notification::NotificationRequest> request = new Notification::NotificationRequest();
69         ansManagerStub.PublishContinuousTaskNotification(request);
70         ansManagerStub.CancelContinuousTaskNotification(stringData, removeReason);
71         ansManagerStub.CancelReminder(removeReason);
72         return ansManagerStub.CancelAllReminders();
73     }
74 }
75 
76 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)77 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
78 {
79     /* Run your code on data */
80     char *ch = ParseData(data, size);
81     if (ch != nullptr && size >= GetU32Size()) {
82         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
83         free(ch);
84         ch = nullptr;
85     }
86     return 0;
87 }
88