• 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         sptr<Notification::NotificationBundleOption> bundleOption = new Notification::NotificationBundleOption();
33         int notificationId = 1;
34         std::string stringData(data);
35         int32_t removeReason = static_cast<int32_t>(GetU32Data(data));
36         ansManagerStub.RemoveNotification(bundleOption, notificationId, stringData, removeReason);
37         ansManagerStub.RemoveAllNotifications(bundleOption);
38         ansManagerStub.Delete(stringData, removeReason);
39         ansManagerStub.DeleteByBundle(bundleOption);
40         ansManagerStub.DeleteAll();
41         sptr<Notification::NotificationSlot> slot = new Notification::NotificationSlot();
42         std::vector<sptr<Notification::NotificationSlot>> slots;
43         slots.emplace_back(slot);
44         ansManagerStub.GetSlotsByBundle(bundleOption, slots);
45         ansManagerStub.SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, allow);
46         ansManagerStub.SetShowBadgeEnabledForBundle(bundleOption, allow);
47         ansManagerStub.GetShowBadgeEnabledForBundle(bundleOption, allow);
48         ansManagerStub.GetShowBadgeEnabled(allow);
49         ansManagerStub.IsAllowedNotify(allow);
50         ansManagerStub.IsAllowedNotifySelf(allow);
51         ansManagerStub.IsSpecialBundleAllowedNotify(bundleOption, allow);
52         ansManagerStub.CancelGroup(stringData);
53         ansManagerStub.RemoveGroupByBundle(bundleOption, stringData);
54         ansManagerStub.DoesSupportDoNotDisturbMode(allow);
55         ansManagerStub.IsDistributedEnabled(allow);
56         ansManagerStub.EnableDistributed(allow);
57         ansManagerStub.EnableDistributedByBundle(bundleOption, allow);
58         ansManagerStub.EnableDistributedSelf(allow);
59         ansManagerStub.IsDistributedEnableByBundle(bundleOption, allow);
60         int32_t remindType = static_cast<int32_t>(*data % SLOT_TYPE_NUM);
61         Notification::NotificationConstant::RemindType remind =
62             Notification::NotificationConstant::RemindType(remindType);
63         ansManagerStub.GetDeviceRemindType(remind);
64         sptr<Notification::NotificationRequest> request = new Notification::NotificationRequest();
65         ansManagerStub.PublishContinuousTaskNotification(request);
66         ansManagerStub.CancelContinuousTaskNotification(stringData, removeReason);
67         ansManagerStub.CancelReminder(removeReason);
68         return ansManagerStub.CancelAllReminders();
69     }
70 }
71 
72 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)73 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
74 {
75     /* Run your code on data */
76     char *ch = ParseData(data, size);
77     if (ch != nullptr && size >= GetU32Size()) {
78         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
79         free(ch);
80         ch = nullptr;
81     }
82     return 0;
83 }
84