• 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_subscriber_stub.h"
19 #include "ans_subscriber_local_live_view_stub.h"
20 #undef private
21 #undef protected
22 #include "ans_permission_def.h"
23 #include "anssubscriberstub_fuzzer.h"
24 #include "notification_request.h"
25 #include <fuzzer/FuzzedDataProvider.h>
26 
27 namespace OHOS {
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)28     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp)
29     {
30         Notification::AnsSubscriberStub ansSubscriberStub;
31         Notification::AnsSubscriberLocalLiveViewStub ansSubscriberLocalLiveViewStub;
32         uint32_t code = fdp->ConsumeIntegral<uint32_t>();
33         MessageParcel datas;
34         MessageParcel reply;
35         MessageOption flags;
36         // test OnRemoteRequest function
37         ansSubscriberStub.OnRemoteRequest(code, datas, reply, flags);
38         // test HandleOnConnected function
39         ansSubscriberStub.HandleOnConnected(datas, reply);
40         // test HandleOnDisconnected function
41         ansSubscriberStub.HandleOnDisconnected(datas, reply);
42         // test HandleOnConsumedMap function
43         ansSubscriberStub.HandleOnConsumedMap(datas, reply);
44         // test HandleOnCanceledMap function
45         ansSubscriberStub.HandleOnCanceledMap(datas, reply);
46         // test HandleOnUpdated function
47         ansSubscriberStub.HandleOnUpdated(datas, reply);
48         // test HandleOnDoNotDisturbDateChange function
49         ansSubscriberStub.HandleOnDoNotDisturbDateChange(datas, reply);
50         // test HandleOnEnabledNotificationChanged function
51         ansSubscriberStub.HandleOnEnabledNotificationChanged(datas, reply);
52         // test HandleOnApplicationInfoNeedChanged function
53         ansSubscriberStub.HandleOnApplicationInfoNeedChanged(datas, reply);
54         // test HandleOnResponse function
55         ansSubscriberStub.HandleOnResponse(datas, reply);
56         // test OnConnected function
57         ansSubscriberStub.OnConnected();
58         // test OnDisconnected function
59         ansSubscriberStub.OnDisconnected();
60         // test OnConsumed function
61         sptr<Notification::Notification> notification = new Notification::Notification();
62         sptr<Notification::NotificationSortingMap> notificationMap = new Notification::NotificationSortingMap();
63         ansSubscriberStub.OnConsumed(notification, notificationMap);
64         // test OnCanceled function
65         int32_t deleteReason = 1;
66         ansSubscriberStub.OnCanceled(notification, notificationMap, deleteReason);
67         ansSubscriberStub.OnApplicationInfoNeedChanged("com.test.demo");
68         sptr<Notification::NotificationOperationInfo> operationInfo = new Notification::NotificationOperationInfo();
69         ansSubscriberStub.OnOperationResponse(operationInfo);
70         // test OnUpdated function
71         ansSubscriberStub.OnUpdated(notificationMap);
72         // test OnDoNotDisturbDateChange function
73         sptr<Notification::NotificationDoNotDisturbDate> date = new Notification::NotificationDoNotDisturbDate();
74         ansSubscriberStub.OnDoNotDisturbDateChange(date);
75         // test OnEnabledNotificationChanged function
76         sptr<Notification::EnabledNotificationCallbackData> callbackData = new Notification::EnabledNotificationCallbackData();
77         // test HandleOnBadgeEnabledChanged function
78         ansSubscriberStub.HandleOnBadgeEnabledChanged(datas, reply);
79         // test HandleOnResponse function
80         ansSubscriberLocalLiveViewStub.HandleOnResponse(datas, reply);
81         // test HandleOnConsumedListMap function
82         ansSubscriberStub.HandleOnConsumedListMap(datas, reply);
83         // test HandleOnDisconnected function
84         ansSubscriberLocalLiveViewStub.HandleOnDisconnected(datas, reply);
85         // test HandleOnBadgeChanged function
86         ansSubscriberStub.HandleOnBadgeChanged(datas, reply);
87         // test HandleOnCanceledListMap function
88         ansSubscriberStub.HandleOnCanceledListMap(datas, reply);
89         // test HandleOnConnected function
90         ansSubscriberLocalLiveViewStub.HandleOnConnected(datas, reply);
91         return true;
92     }
93 }
94 
95 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)96 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
97 {
98     /* Run your code on data */
99     std::vector<std::string> requestPermission = {
100         OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER,
101         OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER,
102         OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION
103     };
104     SystemHapTokenGet(requestPermission);
105     FuzzedDataProvider fdp(data, size);
106     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
107     return 0;
108 }
109