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 <cstdint>
17 #include <fuzzer/FuzzedDataProvider.h>
18 #define private public
19 #define protected public
20 #include "ans_manager_stub.h"
21 #undef private
22 #undef protected
23 #include "ansmanagerstubannextwo_fuzzer.h"
24
25 namespace OHOS {
26 namespace {
27 constexpr uint8_t SLOT_TYPE_NUM = 5;
28 }
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fuzzData)29 bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData)
30 {
31 Notification::AnsManagerStub ansManagerStub;
32 MessageParcel datas;
33 MessageParcel reply;
34 ansManagerStub.HandleGetEnabledForBundleSlot(datas, reply);
35 ansManagerStub.HandleDistributedSetEnabledWithoutApp(datas, reply);
36 ansManagerStub.HandleDistributedGetEnabledWithoutApp(datas, reply);
37 std::string stringData = fuzzData->ConsumeRandomLengthString();
38 sptr<Notification::NotificationRequest> notification = new Notification::NotificationRequest();
39 ansManagerStub.Publish(stringData, notification);
40 int notificationId = 1;
41 ansManagerStub.Cancel(notificationId, stringData, "");
42 ansManagerStub.CancelAll("");
43 int32_t notificationIds = fuzzData->ConsumeIntegral<int32_t>();
44 int32_t userId = fuzzData->ConsumeIntegral<int32_t>();
45 ansManagerStub.CancelAsBundle(notificationIds, stringData, userId);
46 uint8_t type = fuzzData->ConsumeIntegral<uint8_t>() % SLOT_TYPE_NUM;
47 Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type);
48 ansManagerStub.AddSlotByType(slotType);
49 sptr<Notification::NotificationSlot> slot = new Notification::NotificationSlot();
50 std::vector<sptr<Notification::NotificationSlot>> slots;
51 slots.emplace_back(slot);
52 ansManagerStub.AddSlots(slots);
53 ansManagerStub.RemoveSlotByType(slotType);
54 ansManagerStub.RemoveAllSlots();
55 ansManagerStub.GetSlotByType(slotType, slot);
56 ansManagerStub.GetSlots(slots);
57 sptr<Notification::NotificationBundleOption> bundleOption = new Notification::NotificationBundleOption();
58 uint64_t num = 1;
59 ansManagerStub.GetSlotNumAsBundle(bundleOption, num);
60 sptr<Notification::NotificationRequest> notificationer = new Notification::NotificationRequest();
61 std::vector<sptr<Notification::NotificationRequest>> notifications;
62 notifications.emplace_back(notificationer);
63 ansManagerStub.GetActiveNotifications(notifications, "");
64 ansManagerStub.GetActiveNotificationNums(num);
65 sptr<Notification::Notification> notificatione = new Notification::Notification();
66 std::vector<sptr<Notification::Notification>> notificationes;
67 notificationes.emplace_back(notificatione);
68 ansManagerStub.GetAllActiveNotifications(notificationes);
69 std::vector<std::string> key;
70 key.emplace_back(stringData);
71 ansManagerStub.GetSpecialActiveNotifications(key, notificationes);
72 bool canPublish = fuzzData->ConsumeBool();
73 ansManagerStub.CanPublishAsBundle(stringData, canPublish);
74 ansManagerStub.PublishAsBundle(notificationer, stringData);
75 ansManagerStub.SetNotificationBadgeNum(notificationId);
76 ansManagerStub.GetBundleImportance(notificationId);
77 ansManagerStub.HasNotificationPolicyAccessPermission(canPublish);
78 return true;
79 }
80 }
81
82 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)83 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
84 {
85 /* Run your code on data */
86 FuzzedDataProvider fdp(data, size);
87 OHOS::DoSomethingInterestingWithMyAPI(&fdp);
88 return 0;
89 }
90