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 "ansmanagerstubannex_fuzzer.h"
22 
23 namespace OHOS {
DoSomethingInterestingWithMyAPI(const char * data,size_t size)24     bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
25     {
26         Notification::AnsManagerStub ansManagerStub;
27         MessageParcel datas;
28         MessageParcel reply;
29         ansManagerStub.HandleDelete(datas, reply);
30         ansManagerStub.HandleDeleteByBundle(datas, reply);
31         ansManagerStub.HandleDeleteAll(datas, reply);
32         ansManagerStub.HandleGetSlotsByBundle(datas, reply);
33         ansManagerStub.HandleUpdateSlots(datas, reply);
34         ansManagerStub.HandleRequestEnableNotification(datas, reply);
35         ansManagerStub.HandleSetNotificationsEnabledForBundle(datas, reply);
36         ansManagerStub.HandleSetNotificationsEnabledForAllBundles(datas, reply);
37         ansManagerStub.HandleSetNotificationsEnabledForSpecialBundle(datas, reply);
38         ansManagerStub.HandleSetShowBadgeEnabledForBundle(datas, reply);
39         ansManagerStub.HandleGetShowBadgeEnabledForBundle(datas, reply);
40         ansManagerStub.HandleGetShowBadgeEnabled(datas, reply);
41         ansManagerStub.HandleSubscribe(datas, reply);
42         ansManagerStub.HandleUnsubscribe(datas, reply);
43         ansManagerStub.HandleIsAllowedNotify(datas, reply);
44         ansManagerStub.HandleIsAllowedNotifySelf(datas, reply);
45         ansManagerStub.HandleIsSpecialBundleAllowedNotify(datas, reply);
46         ansManagerStub.HandleCancelGroup(datas, reply);
47         ansManagerStub.HandleRemoveGroupByBundle(datas, reply);
48         ansManagerStub.HandleIsDistributedEnabled(datas, reply);
49         ansManagerStub.HandleEnableDistributed(datas, reply);
50         ansManagerStub.HandleEnableDistributedByBundle(datas, reply);
51         ansManagerStub.HandleEnableDistributedSelf(datas, reply);
52         ansManagerStub.HandleIsDistributedEnableByBundle(datas, reply);
53         ansManagerStub.HandleGetDeviceRemindType(datas, reply);
54         ansManagerStub.HandleShellDump(datas, reply);
55         ansManagerStub.HandlePublishReminder(datas, reply);
56         ansManagerStub.HandleCancelReminder(datas, reply);
57         ansManagerStub.HandleCancelAllReminders(datas, reply);
58         ansManagerStub.HandleGetValidReminders(datas, reply);
59         ansManagerStub.HandleAddExcludeDate(datas, reply);
60         ansManagerStub.HandleDelExcludeDates(datas, reply);
61         ansManagerStub.HandleGetExcludeDates(datas, reply);
62         ansManagerStub.HandleIsSupportTemplate(datas, reply);
63         ansManagerStub.HandleIsSpecialUserAllowedNotifyByUser(datas, reply);
64         ansManagerStub.HandleSetNotificationsEnabledByUser(datas, reply);
65         ansManagerStub.HandleDeleteAllByUser(datas, reply);
66         ansManagerStub.HandleSetDoNotDisturbDateByUser(datas, reply);
67         ansManagerStub.HandleGetDoNotDisturbDateByUser(datas, reply);
68         return ansManagerStub.HandleSetEnabledForBundleSlot(datas, reply);
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