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 "ansmanagerstubannextwo_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 MessageParcel datas;
32 MessageParcel reply;
33 ansManagerStub.HandleGetEnabledForBundleSlot(datas, reply);
34 ansManagerStub.HandleDistributedSetEnabledWithoutApp(datas, reply);
35 ansManagerStub.HandleDistributedGetEnabledWithoutApp(datas, reply);
36 std::string stringData(data);
37 sptr<Notification::NotificationRequest> notification = new Notification::NotificationRequest();
38 ansManagerStub.Publish(stringData, notification);
39 int notificationId = 1;
40 ansManagerStub.Cancel(notificationId, stringData, 0);
41 ansManagerStub.CancelAll(0);
42 int32_t notificationIds = static_cast<int32_t>(GetU32Data(data));
43 int32_t userId = static_cast<int32_t>(GetU32Data(data));
44 ansManagerStub.CancelAsBundle(notificationIds, stringData, userId);
45 uint8_t type = *data % SLOT_TYPE_NUM;
46 Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type);
47 ansManagerStub.AddSlotByType(slotType);
48 sptr<Notification::NotificationSlot> slot = new Notification::NotificationSlot();
49 std::vector<sptr<Notification::NotificationSlot>> slots;
50 slots.emplace_back(slot);
51 ansManagerStub.AddSlots(slots);
52 ansManagerStub.RemoveSlotByType(slotType);
53 ansManagerStub.RemoveAllSlots();
54 ansManagerStub.GetSlotByType(slotType, slot);
55 ansManagerStub.GetSlots(slots);
56 sptr<Notification::NotificationBundleOption> bundleOption = new Notification::NotificationBundleOption();
57 uint64_t num = 1;
58 ansManagerStub.GetSlotNumAsBundle(bundleOption, num);
59 sptr<Notification::NotificationRequest> notificationer = new Notification::NotificationRequest();
60 std::vector<sptr<Notification::NotificationRequest>> notifications;
61 notifications.emplace_back(notificationer);
62 ansManagerStub.GetActiveNotifications(notifications, 0);
63 ansManagerStub.GetActiveNotificationNums(num);
64 sptr<Notification::Notification> notificatione = new Notification::Notification();
65 std::vector<sptr<Notification::Notification>> notificationes;
66 notificationes.emplace_back(notificatione);
67 ansManagerStub.GetAllActiveNotifications(notificationes);
68 std::vector<std::string> key;
69 key.emplace_back(stringData);
70 ansManagerStub.GetSpecialActiveNotifications(key, notificationes);
71 ansManagerStub.SetNotificationAgent(stringData);
72 ansManagerStub.GetNotificationAgent(stringData);
73 bool canPublish = *data % ENABLE;
74 ansManagerStub.CanPublishAsBundle(stringData, canPublish);
75 ansManagerStub.PublishAsBundle(notificationer, stringData);
76 ansManagerStub.SetNotificationBadgeNum(notificationId);
77 ansManagerStub.GetBundleImportance(notificationId);
78 ansManagerStub.HasNotificationPolicyAccessPermission(canPublish);
79 return true;
80 }
81 }
82
83 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)84 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
85 {
86 /* Run your code on data */
87 char *ch = ParseData(data, size);
88 if (ch != nullptr && size >= GetU32Size()) {
89 OHOS::DoSomethingInterestingWithMyAPI(ch, size);
90 free(ch);
91 ch = nullptr;
92 }
93 return 0;
94 }
95